Skip to content

Commit

Permalink
Merge pull request #2523 from wddgit/migrateToNewRandomService4
Browse files Browse the repository at this point in the history
New Random Number Generator -- Migrate Calibration Code to New Random Service Interface
  • Loading branch information
ktf committed Mar 4, 2014
2 parents eb873dc + 20dcb2b commit ed3706a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
95 changes: 50 additions & 45 deletions CalibMuon/DTCalibration/test/DBTools/FakeTTrig.cc
Expand Up @@ -10,6 +10,7 @@
// Framework
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "CalibMuon/DTCalibration/test/DBTools/DTCalibrationMap.h"
Expand All @@ -27,6 +28,8 @@
#include "CondFormats/DataRecord/interface/DTTtrigRcd.h"

//Random generator
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "CLHEP/Random/RandGaussQ.h"

Expand All @@ -40,8 +43,9 @@ using namespace edm;



FakeTTrig::FakeTTrig(const ParameterSet& pset) {

FakeTTrig::FakeTTrig(const ParameterSet& pset) :
dataBaseWriteWasDone(false) {

cout << "[FakeTTrig] Constructor called! " << endl;

// further configurable smearing
Expand All @@ -54,10 +58,7 @@ FakeTTrig::FakeTTrig(const ParameterSet& pset) {
throw cms::Exception("Configuration")
<< "RandomNumberGeneratorService for DTFakeTTrigDB missing in cfg file";
}
theGaussianDistribution = new CLHEP::RandGaussQ(rng->getEngine());

ps = pset;

}


Expand All @@ -74,52 +75,56 @@ void FakeTTrig::beginRun(const edm::Run&, const EventSetup& setup) {
setup.get<DTTtrigRcd>().get(dbLabel,tTrigMapRef);
}

void FakeTTrig::endJob() {

cout << "[FakeTTrig] entered into endJob! " << endl;
void FakeTTrig::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) {
if(!dataBaseWriteWasDone) {
dataBaseWriteWasDone = true;

cout << "[FakeTTrig] entered into beginLuminosityBlock! " << endl;

// Get the superlayers and layers list
vector<DTSuperLayer*> dtSupLylist = muonGeom->superLayers();
// Create the object to be written to DB
DTTtrig* tTrigMap = new DTTtrig();

for (vector<DTSuperLayer*>::const_iterator sl = dtSupLylist.begin();
sl != dtSupLylist.end(); sl++) {

// get the time of fly
double timeOfFly = tofComputation(*sl);
// get the time of wire propagation
double timeOfWirePropagation = wirePropComputation(*sl);
// get the gaussian smearing
double gaussianSmearing = theGaussianDistribution->fire(0.,smearing);
// get the fake tTrig pedestal
double pedestral = ps.getUntrackedParameter<double>("fakeTTrigPedestal", 500);

if ( ps.getUntrackedParameter<bool>("readDB", true) ){
tTrigMapRef->get((*sl)->id(), tTrigRef, tTrigRMSRef, kFactorRef, DTTimeUnits::ns );
// pedestral = tTrigRef;
pedestral = tTrigRef + kFactorRef*tTrigRMSRef ;
edm::Service<edm::RandomNumberGenerator> rng;
CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());

// Get the superlayers and layers list
vector<DTSuperLayer*> dtSupLylist = muonGeom->superLayers();
// Create the object to be written to DB
DTTtrig* tTrigMap = new DTTtrig();

for (vector<DTSuperLayer*>::const_iterator sl = dtSupLylist.begin();
sl != dtSupLylist.end(); sl++) {

// get the time of fly
double timeOfFly = tofComputation(*sl);
// get the time of wire propagation
double timeOfWirePropagation = wirePropComputation(*sl);
// get the gaussian smearing
double gaussianSmearing = CLHEP::RandGaussQ::shoot(engine, 0., smearing);
// get the fake tTrig pedestal
double pedestral = ps.getUntrackedParameter<double>("fakeTTrigPedestal", 500);

if ( ps.getUntrackedParameter<bool>("readDB", true) ){
tTrigMapRef->get((*sl)->id(), tTrigRef, tTrigRMSRef, kFactorRef, DTTimeUnits::ns );
// pedestral = tTrigRef;
pedestral = tTrigRef + kFactorRef*tTrigRMSRef ;
}

DTSuperLayerId slId = (*sl)->id();
// if the FakeTtrig has to be smeared with a Gaussian
double fakeTTrig = pedestral + timeOfFly + timeOfWirePropagation + gaussianSmearing;
// if the FakeTtrig is scaled of a number of bunch crossing
// double fakeTTrig = pedestral - 75.;
tTrigMap->set(slId, fakeTTrig, 0,0, DTTimeUnits::ns);
}

DTSuperLayerId slId = (*sl)->id();
// if the FakeTtrig has to be smeared with a Gaussian
double fakeTTrig = pedestral + timeOfFly + timeOfWirePropagation + gaussianSmearing;
// if the FakeTtrig is scaled of a number of bunch crossing
// double fakeTTrig = pedestral - 75.;
tTrigMap->set(slId, fakeTTrig, 0,0, DTTimeUnits::ns);

// Write the object in the DB
cout << "[FakeTTrig] Writing ttrig object to DB!" << endl;
string record = "DTTtrigRcd";
DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigMap);
}

// Write the object in the DB
cout << "[FakeTTrig] Writing ttrig object to DB!" << endl;
string record = "DTTtrigRcd";
DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigMap);

}



void FakeTTrig::endJob() {
cout << "[FakeTTrig] entered into endJob! " << endl;
}

double FakeTTrig::tofComputation(const DTSuperLayer* superlayer) {

Expand Down
9 changes: 2 additions & 7 deletions CalibMuon/DTCalibration/test/DBTools/FakeTTrig.h
Expand Up @@ -16,10 +16,6 @@
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

namespace CLHEP {
class RandGaussQ;
}

#include <string>
class DTGeometry;
class DTSuperLayer;
Expand All @@ -35,6 +31,7 @@ class FakeTTrig : public edm::EDAnalyzer {

// Operations
virtual void beginRun(const edm::Run& run, const edm::EventSetup& setup );
virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
virtual void analyze(const edm::Event& event, const edm::EventSetup& setup){}
virtual void endJob();

Expand All @@ -61,8 +58,6 @@ class FakeTTrig : public edm::EDAnalyzer {
// Get the tTrigMap
edm::ESHandle<DTTtrig> tTrigMapRef;

// the random generator
CLHEP::RandGaussQ* theGaussianDistribution;

bool dataBaseWriteWasDone;
};
#endif
7 changes: 3 additions & 4 deletions CalibMuon/DTCalibration/test/FakeTTrig_cfg.py
Expand Up @@ -36,10 +36,9 @@
#)

process.RandomNumberGeneratorService = cms.Service("RandomNumberGeneratorService",
moduleSeeds = cms.PSet(
FaketTrig = cms.untracked.uint32(563)
),
sourceSeed = cms.untracked.uint32(98765)
FaketTrig = cms.PSet(
initialSeed = cms.untracked.uint32(563)
)
)

process.PoolDBOutputService = cms.Service("PoolDBOutputService",
Expand Down

0 comments on commit ed3706a

Please sign in to comment.