#include "CalibMuon/DTCalibration/test/DBTools/DTCalibrationMap.h"0017 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h" 0018 0019 // Geometry 0020 #include "Geometry/Records/interface/MuonGeometryRecord.h" 0021 #include "Geometry/DTGeometry/interface/DTGeometry.h" 0022 #include "Geometry/DTGeometry/interface/DTSuperLayer.h" 0023 #include "DataFormats/GeometryVector/interface/GlobalPoint.h" 0024 #include "Geometry/DTGeometry/interface/DTTopology.h" 0025 0026 // Database 0027 #include "CondFormats/DTObjects/interface/DTTtrig.h" 0028 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h" 0029 0030 //Random generator 0031 #include "FWCore/ServiceRegistry/interface/Service.h" 0032 #include "FWCore/Utilities/interface/Exception.h" 0033 #include "FWCore/Utilities/interface/RandomNumberGenerator.h" 0034 #include "CLHEP/Random/RandGaussQ.h" 0035 0036 // DTDigitizer 0037 #include "CalibMuon/DTDigiSync/interface/DTTTrigSyncFactory.h" 0038 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h" 0039 0040 0041 using namespace std; 0042 using namespace edm; 0043 0044 0045 0046 FakeTTrig::FakeTTrig(const ParameterSet& pset) : 0047 dataBaseWriteWasDone(false) { 0048 0049 cout << "[FakeTTrig] Constructor called! " << endl; 0050 0051 // further configurable smearing 0052 smearing=pset.getUntrackedParameter<double>("smearing"); 0053 dbLabel = pset.getUntrackedParameter<string>("dbLabel", ""); 0054 0055 // get random engine 0056 edm::Service<edm::RandomNumberGenerator> rng; 0057 if ( ! rng.isAvailable()) { 0058 throw cms::Exception("Configuration") 0059 << "RandomNumberGeneratorService for DTFakeTTrigDB missing in cfg file"; 0060 } 0061 ps = pset; 0062 } 0063 0064 0065 FakeTTrig::~FakeTTrig(){ 0066 cout << "[FakeTTrig] Destructor called! " << endl; 0067 } 0068 0069 void FakeTTrig::beginRun(const edm::Run&, const EventSetup& setup) { 0070 cout << "[FakeTTrig] entered into beginRun! " << endl; 0071 setup.get<MuonGeometryRecord>().get(muonGeom); 0072 0073 // Get the tTrig reference map 0074 if (ps.getUntrackedParameter<bool>("readDB", true)) 0075 setup.get<DTTtrigRcd>().get(dbLabel,tTrigMapRef); 0076 } 0077 0078 void FakeTTrig::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) { 0079 if(!dataBaseWriteWasDone) { 0080 dataBaseWriteWasDone = true; 0081 0082 cout << "[FakeTTrig] entered into beginLuminosityBlock! " << endl; 0083 0084 edm::Service<edm::RandomNumberGenerator> rng; 0085 CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index()); 0086 0087 // Get the superlayers and layers list 0088 vector<const DTSuperLayer*> dtSupLylist = muonGeom->superLayers(); 0089 // Create the object to be written to DB 0090 DTTtrig* tTrigMap = new DTTtrig(); 0091 0092 for (auto sl = dtSupLylist.begin(); 0093 sl != dtSupLylist.end(); sl++) { 0094 0095 // get the time of fly 0096 double timeOfFly = tofComputation(*sl); 0097 // get the time of wire propagation 0098 double timeOfWirePropagation = wirePropComputation(*sl); 0099 // get the gaussian smearing 0100 double gaussianSmearing = CLHEP::RandGaussQ::shoot(engine, 0., smearing); 0101 // get the fake tTrig pedestal 0102 double pedestral = ps.getUntrackedParameter<double>("fakeTTrigPedestal", 500); 0103 0104 if ( ps.getUntrackedParameter<bool>("readDB", true) ){ 0105 tTrigMapRef->get((*sl)->id(), tTrigRef, tTrigRMSRef, kFactorRef, DTTimeUnits::ns ); 0106 // pedestral = tTrigRef; 0107 pedestral = tTrigRef + kFactorRef*tTrigRMSRef ; 0108 } 0109 0110 DTSuperLayerId slId = (*sl)->id(); 0111 // if the FakeTtrig has to be smeared with a Gaussian 0112 double fakeTTrig = pedestral + timeOfFly + timeOfWirePropagation + gaussianSmearing; 0113 // if the FakeTtrig is scaled of a number of bunch crossing 0114 // double fakeTTrig = pedestral - 75.; 0115 tTrigMap->set(slId, fakeTTrig, 0,0, DTTimeUnits::ns); 0116 } 0117 0118 // Write the object in the DB 0119 cout << "[FakeTTrig] Writing ttrig object to DB!" << endl; 0120 string record = "DTTtrigRcd"; 0121 DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigMap); 0122 } 0123 } 0124 0125 void FakeTTrig::endJob() { 0126 cout << "[FakeTTrig] entered into endJob! " << endl; 0127 } 0128 0129 double FakeTTrig::tofComputation(const DTSuperLayer* superlayer) { 0130 0131 double tof=0; 0132 const double cSpeed = 29.9792458; // cm/ns 0133 0134 if(ps.getUntrackedParameter<bool>("useTofCorrection", true)){ 0135 LocalPoint localPos(0,0,0); 0136 double flight = superlayer->surface().toGlobal(localPos).mag(); 0137 tof = flight/cSpeed; 0138 } 0139 0140 return tof; 0141 0142 } 0143 0144 0145 0146 double FakeTTrig::wirePropComputation(const DTSuperLayer* superlayer) { 0147 0148 double delay = 0; 0149 double theVPropWire = ps.getUntrackedParameter<double>("vPropWire", 24.4); // cm/ns 0150 0151 if(ps.getUntrackedParameter<bool>("useWirePropCorrection", true)){ 0152 DTLayerId lId = DTLayerId(superlayer->id(), 1); 0153 float halfL = superlayer->layer(lId)->specificTopology().cellLenght()/2; 0154 delay = halfL/theVPropWire; 0155 } 0156 0157 return delay; 0158 0159 } 0160