61 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
63 theFitter = std::make_unique<DTTimeBoxFitter>();
65 theFitter->setVerbosity(1);
68 theFitter->setFitSigma(sigmaFit);
83 cout <<
"[DTTTrigCalibration]Constructor called!" << endl;
91 cout <<
"[DTTTrigCalibration]Destructor called!" << endl;
109 cout <<
"[DTTTrigCalibration] #Event: " <<
event.id().event() << endl;
116 if(checkNoisyChannels) {
122 theSync->setES(eventSetup);
125 vector<DTChamberId> badChambers;
129 for (dtLayerIt = digis->begin();
130 dtLayerIt != digis->end();
135 const DTLayerId layerId = (*dtLayerIt).first;
138 bool badChamber=
false;
141 cout<<
"----------- Layer "<<layerId<<
" -------------"<<endl;
144 for(vector<DTChamberId>::const_iterator
chamber = badChambers.begin();
chamber != badChambers.end(); ++
chamber){
150 if(badChamber)
continue;
153 if((digiRange.second - digiRange.first) > maxDigiPerLayer){
155 cout<<
"Layer "<<layerId<<
"has too many digis ("<<(digiRange.second - digiRange.first)<<
")"<<endl;
156 badChambers.push_back(chId);
161 TH1F *hTBox = theHistoMap[slId];
162 if(hTBox ==
nullptr) {
165 hTBox =
new TH1F(getTBoxName(slId).c_str(),
"Time box (ns)",
int(0.25*32.0*maxTDCCounts/25.0), 0, maxTDCCounts);
167 cout <<
" New Time Box: " << hTBox->GetName() << endl;
168 theHistoMap[slId] = hTBox;
170 TH1F *hO = theOccupancyMap[layerId];
174 hO =
new TH1F(getOccupancyName(layerId).c_str(),
"Occupancy", 100, 0, 100);
176 cout <<
" New Time Box: " << hO->GetName() << endl;
177 theOccupancyMap[layerId] = hO;
182 digi != digiRange.second;
184 const DTWireId wireId(layerId, (*digi).wire());
187 if(checkNoisyChannels) {
188 bool isNoisy =
false;
189 bool isFEMasked =
false;
190 bool isTDCMasked =
false;
191 bool isTrigMask =
false;
194 statusMap->
cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
197 cout <<
"Wire: " << wireId <<
" is noisy, skipping!" << endl;
204 const DTLayer* layer =
nullptr;
206 offset = theSync->offset(layer, wireId, glPt);
208 hTBox->Fill((*digi).time()-
offset);
210 cout <<
" Filling Time Box: " << hTBox->GetName() << endl;
211 cout <<
" offset (ns): " << offset << endl;
212 cout <<
" time(ns): " << (*digi).time()-offset<< endl;
214 hO->Fill((*digi).wire());
222 cout <<
"[DTTTrigCalibration]Writing histos to file!" << endl;
226 for(map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin();
227 slHisto != theHistoMap.end();
229 (*slHisto).second->Write();
231 for(map<DTLayerId, TH1F*>::const_iterator slHisto = theOccupancyMap.begin();
232 slHisto != theOccupancyMap.end();
234 (*slHisto).second->Write();
237 if(findTMeanAndSigma) {
242 for(map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin();
243 slHisto != theHistoMap.end();
245 pair<double, double> meanAndSigma = theFitter->fitTimeBox((*slHisto).second);
246 tTrig->
set((*slHisto).first,
253 cout <<
" SL: " << (*slHisto).first
254 <<
" mean = " << meanAndSigma.first
255 <<
" sigma = " << meanAndSigma.second << endl;
266 cout <<
"[DTTTrigCalibration]Writing ttrig object to DB!" << endl;
270 string tTrigRecord =
"DTTtrigRcd";
283 stringstream theStream;
286 theStream >> histoName;
292 stringstream theStream;
295 theStream >> histoName;
301 static const double convToNs = 25./32.;
303 ttrig != tTrig->
end(); ++ttrig) {
304 cout <<
"Wh: " << (*ttrig).first.wheelId
305 <<
" St: " << (*ttrig).first.stationId
306 <<
" Sc: " << (*ttrig).first.sectorId
307 <<
" Sl: " << (*ttrig).first.slId
308 <<
" TTrig mean (ns): " << (*ttrig).second.tTrig * convToNs
309 <<
" TTrig sigma (ns): " << (*ttrig).second.tTrms * convToNs<< endl;
316 TH1F* tTrig_YB1_Se10 =
new TH1F(
"tTrig_YB1_Se10",
"tTrig YB1_Se10",15,1,16);
317 TH1F* tTrig_YB2_Se10 =
new TH1F(
"tTrig_YB2_Se10",
"tTrig YB2_Se10",15,1,16);
318 TH1F* tTrig_YB2_Se11 =
new TH1F(
"tTrig_YB2_Se11",
"tTrig YB2_Se11",12,1,13);
320 static const double convToNs = 25./32.;
322 ttrig != tTrig->
end(); ++ttrig) {
327 if ((*ttrig).second.tTrig * convToNs > 0 &&
328 (*ttrig).second.tTrig * convToNs < 32000 ) {
329 tTrigValue = (*ttrig).second.tTrig * convToNs;
330 tTrmsValue = (*ttrig).second.tTrms * convToNs;
335 stringstream binLabelStream;
336 if ((*ttrig).first.sectorId != 14) {
337 binx = ((*ttrig).first.stationId-1)*3 + (*ttrig).first.slId;
338 binLabelStream <<
"MB"<<(*ttrig).first.stationId<<
"_SL"<<(*ttrig).first.slId;
341 binx = 12 + (*ttrig).first.slId;
342 binLabelStream <<
"MB14_SL"<<(*ttrig).first.slId;
344 binLabelStream >> binLabel;
346 if ((*ttrig).first.wheelId == 2) {
347 if ((*ttrig).first.sectorId == 10 || (*ttrig).first.sectorId == 14) {
348 tTrig_YB2_Se10->Fill( binx,tTrigValue);
349 tTrig_YB2_Se10->SetBinError( binx, tTrmsValue);
350 tTrig_YB2_Se10->GetXaxis()->SetBinLabel(binx,binLabel.c_str());
351 tTrig_YB2_Se10->GetYaxis()->SetTitle(
"ns");
354 tTrig_YB2_Se11->Fill( binx,tTrigValue);
355 tTrig_YB2_Se11->SetBinError( binx,tTrmsValue);
356 tTrig_YB2_Se11->GetXaxis()->SetBinLabel(binx,binLabel.c_str());
357 tTrig_YB2_Se11->GetYaxis()->SetTitle(
"ns");
361 tTrig_YB1_Se10->Fill( binx,tTrigValue);
362 tTrig_YB1_Se10->SetBinError( binx,tTrmsValue);
363 tTrig_YB1_Se10->GetXaxis()->SetBinLabel(binx,binLabel.c_str());
364 tTrig_YB1_Se10->GetYaxis()->SetTitle(
"ns");
368 tTrig_YB1_Se10->Write();
369 tTrig_YB2_Se10->Write();
370 tTrig_YB2_Se11->Write();
DTTTrigCalibration(const edm::ParameterSet &pset)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
int set(int wheelId, int stationId, int sectorId, int slId, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit)
DTChamberId chamberId() const
Return the corresponding ChamberId.
int layer() const
Return the layer number.
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Fill the time boxes.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
std::string getTBoxName(const DTSuperLayerId &slId) const
std::vector< std::pair< DTTtrigId, DTTtrigData > >::const_iterator const_iterator
Access methods to data.
~DTTTrigCalibration() override
Destructor.
void plotTTrig(const DTTtrig *tTrig) const
std::string getOccupancyName(const DTLayerId &slId) const
int superlayer() const
Return the superlayer number (deprecated method name)
std::vector< DigiType >::const_iterator const_iterator
int cellStatus(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, bool &noiseFlag, bool &feMask, bool &tdcMask, bool &trigMask, bool &deadFlag, bool &nohvFlag) const
get content
const_iterator begin() const
std::pair< const_iterator, const_iterator > Range
int station() const
Return the station number.
void dumpTTrigMap(const DTTtrig *tTrig) const
const_iterator end() const
int wheel() const
Return the wheel number.
void endJob() override
Fit the time box rising edge and write the resulting ttrig to the DB.
static void writeToDB(std::string record, T *payload)
T get(const Candidate &c)