41 debug =
pset.getUntrackedParameter<
bool>(
"debug");
48 findTMeanAndSigma =
pset.getUntrackedParameter<
bool>(
"fitAndWrite",
false);
51 maxTDCCounts = 5000 *
pset.getUntrackedParameter<
int>(
"tdcRescale", 1);
53 maxDigiPerLayer =
pset.getUntrackedParameter<
int>(
"maxDigiPerLayer", 10);
59 theFitter = std::make_unique<DTTimeBoxFitter>();
61 theFitter->setVerbosity(1);
63 double sigmaFit =
pset.getUntrackedParameter<
double>(
"sigmaTTrigFit", 10.);
64 theFitter->setFitSigma(sigmaFit);
66 doSubtractT0 =
pset.getUntrackedParameter<
bool>(
"doSubtractT0",
"false");
76 kFactor =
pset.getUntrackedParameter<
double>(
"kFactor", -0.7);
79 cout <<
"[DTTTrigCalibration]Constructor called!" << endl;
85 cout <<
"[DTTTrigCalibration]Destructor called!" << endl;
100 cout <<
"[DTTTrigCalibration] #Event: " <<
event.id().event() << endl;
113 theSync->setES(eventSetup);
116 vector<DTChamberId> badChambers;
120 for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
124 const DTLayerId layerId = (*dtLayerIt).first;
127 bool badChamber =
false;
130 cout <<
"----------- Layer " << layerId <<
" -------------" << endl;
133 for (vector<DTChamberId>::const_iterator
chamber = badChambers.begin();
chamber != badChambers.end(); ++
chamber) {
143 if ((digiRange.second - digiRange.first) > maxDigiPerLayer) {
145 cout <<
"Layer " << layerId <<
"has too many digis (" << (digiRange.second - digiRange.first) <<
")" << endl;
146 badChambers.push_back(chId);
151 TH1F* hTBox = theHistoMap[slId];
152 if (hTBox ==
nullptr) {
156 new TH1F(getTBoxName(slId).c_str(),
"Time box (ns)",
int(0.25 * 32.0 * maxTDCCounts / 25.0), 0, maxTDCCounts);
158 cout <<
" New Time Box: " << hTBox->GetName() << endl;
159 theHistoMap[slId] = hTBox;
161 TH1F* hO = theOccupancyMap[layerId];
165 hO =
new TH1F(getOccupancyName(layerId).c_str(),
"Occupancy", 100, 0, 100);
167 cout <<
" New Time Box: " << hO->GetName() << endl;
168 theOccupancyMap[layerId] = hO;
173 const DTWireId wireId(layerId, (*digi).wire());
177 bool isNoisy =
false;
178 bool isFEMasked =
false;
179 bool isTDCMasked =
false;
180 bool isTrigMask =
false;
183 statusMap->
cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
186 cout <<
"Wire: " << wireId <<
" is noisy, skipping!" << endl;
193 const DTLayer* layer =
nullptr;
195 offset = theSync->offset(layer, wireId, glPt);
197 hTBox->Fill((*digi).time() -
offset);
199 cout <<
" Filling Time Box: " << hTBox->GetName() << endl;
201 cout <<
" time(ns): " << (*digi).time() -
offset << endl;
203 hO->Fill((*digi).wire());
210 cout <<
"[DTTTrigCalibration]Writing histos to file!" << endl;
214 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
216 (*slHisto).second->Write();
218 for (map<DTLayerId, TH1F*>::const_iterator slHisto = theOccupancyMap.begin(); slHisto != theOccupancyMap.end();
220 (*slHisto).second->Write();
223 if (findTMeanAndSigma) {
228 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
230 pair<double, double> meanAndSigma = theFitter->fitTimeBox((*slHisto).second);
234 cout <<
" SL: " << (*slHisto).first <<
" mean = " << meanAndSigma.first <<
" sigma = " << meanAndSigma.second
246 cout <<
"[DTTTrigCalibration]Writing ttrig object to DB!" << endl;
249 string tTrigRecord =
"DTTtrigRcd";
258 stringstream theStream;
267 stringstream theStream;
269 <<
"_L" << slId.
layer() <<
"_Occupancy";
275 static const double convToNs = 25. / 32.;
277 cout <<
"Wh: " << (*ttrig).first.wheelId <<
" St: " << (*ttrig).first.stationId
278 <<
" Sc: " << (*ttrig).first.sectorId <<
" Sl: " << (*ttrig).first.slId
279 <<
" TTrig mean (ns): " << (*ttrig).second.tTrig * convToNs
280 <<
" TTrig sigma (ns): " << (*ttrig).second.tTrms * convToNs << endl;
285 TH1F* tTrig_YB1_Se10 =
new TH1F(
"tTrig_YB1_Se10",
"tTrig YB1_Se10", 15, 1, 16);
286 TH1F* tTrig_YB2_Se10 =
new TH1F(
"tTrig_YB2_Se10",
"tTrig YB2_Se10", 15, 1, 16);
287 TH1F* tTrig_YB2_Se11 =
new TH1F(
"tTrig_YB2_Se11",
"tTrig YB2_Se11", 12, 1, 13);
289 static const double convToNs = 25. / 32.;
292 float tTrigValue = 0;
293 float tTrmsValue = 0;
294 if ((*ttrig).second.tTrig * convToNs > 0 && (*ttrig).second.tTrig * convToNs < 32000) {
295 tTrigValue = (*ttrig).second.tTrig * convToNs;
296 tTrmsValue = (*ttrig).second.tTrms * convToNs;
301 stringstream binLabelStream;
302 if ((*ttrig).first.sectorId != 14) {
303 binx = ((*ttrig).first.stationId - 1) * 3 + (*ttrig).first.slId;
304 binLabelStream <<
"MB" << (*ttrig).first.stationId <<
"_SL" << (*ttrig).first.slId;
306 binx = 12 + (*ttrig).first.slId;
307 binLabelStream <<
"MB14_SL" << (*ttrig).first.slId;
309 binLabelStream >> binLabel;
311 if ((*ttrig).first.wheelId == 2) {
312 if ((*ttrig).first.sectorId == 10 || (*ttrig).first.sectorId == 14) {
313 tTrig_YB2_Se10->Fill(binx, tTrigValue);
314 tTrig_YB2_Se10->SetBinError(binx, tTrmsValue);
315 tTrig_YB2_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
316 tTrig_YB2_Se10->GetYaxis()->SetTitle(
"ns");
318 tTrig_YB2_Se11->Fill(binx, tTrigValue);
319 tTrig_YB2_Se11->SetBinError(binx, tTrmsValue);
320 tTrig_YB2_Se11->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
321 tTrig_YB2_Se11->GetYaxis()->SetTitle(
"ns");
324 tTrig_YB1_Se10->Fill(binx, tTrigValue);
325 tTrig_YB1_Se10->SetBinError(binx, tTrmsValue);
326 tTrig_YB1_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
327 tTrig_YB1_Se10->GetYaxis()->SetTitle(
"ns");
331 tTrig_YB1_Se10->Write();
332 tTrig_YB2_Se10->Write();
333 tTrig_YB2_Se11->Write();