42 debug =
pset.getUntrackedParameter<
bool>(
"debug");
49 findTMeanAndSigma =
pset.getUntrackedParameter<
bool>(
"fitAndWrite",
false);
52 maxTDCCounts = 5000 *
pset.getUntrackedParameter<
int>(
"tdcRescale", 1);
54 maxDigiPerLayer =
pset.getUntrackedParameter<
int>(
"maxDigiPerLayer", 10);
60 theFitter = std::make_unique<DTTimeBoxFitter>();
62 theFitter->setVerbosity(1);
64 double sigmaFit =
pset.getUntrackedParameter<
double>(
"sigmaTTrigFit", 10.);
65 theFitter->setFitSigma(sigmaFit);
67 doSubtractT0 =
pset.getUntrackedParameter<
bool>(
"doSubtractT0",
"false");
78 kFactor =
pset.getUntrackedParameter<
double>(
"kFactor", -0.7);
81 cout <<
"[DTTTrigCalibration]Constructor called!" << endl;
91 cout <<
"[DTTTrigCalibration]Destructor called!" << endl;
106 cout <<
"[DTTTrigCalibration] #Event: " <<
event.id().event() << endl;
115 statusMap =
eventSetup.getHandle(theStatusMapToken);
122 vector<DTChamberId> badChambers;
126 for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
130 const DTLayerId layerId = (*dtLayerIt).first;
133 bool badChamber =
false;
136 cout <<
"----------- Layer " << layerId <<
" -------------" << endl;
139 for (vector<DTChamberId>::const_iterator
chamber = badChambers.begin();
chamber != badChambers.end(); ++
chamber) {
149 if ((digiRange.second - digiRange.first) > maxDigiPerLayer) {
151 cout <<
"Layer " << layerId <<
"has too many digis (" << (digiRange.second - digiRange.first) <<
")" << endl;
152 badChambers.push_back(chId);
157 TH1F* hTBox = theHistoMap[slId];
158 if (hTBox ==
nullptr) {
162 new TH1F(getTBoxName(slId).c_str(),
"Time box (ns)",
int(0.25 * 32.0 * maxTDCCounts / 25.0), 0, maxTDCCounts);
164 cout <<
" New Time Box: " << hTBox->GetName() << endl;
165 theHistoMap[slId] = hTBox;
167 TH1F* hO = theOccupancyMap[layerId];
171 hO =
new TH1F(getOccupancyName(layerId).c_str(),
"Occupancy", 100, 0, 100);
173 cout <<
" New Time Box: " << hO->GetName() << endl;
174 theOccupancyMap[layerId] = hO;
179 const DTWireId wireId(layerId, (*digi).wire());
183 bool isNoisy =
false;
184 bool isFEMasked =
false;
185 bool isTDCMasked =
false;
186 bool isTrigMask =
false;
189 statusMap->
cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
192 cout <<
"Wire: " << wireId <<
" is noisy, skipping!" << endl;
203 hTBox->Fill((*digi).time() -
offset);
205 cout <<
" Filling Time Box: " << hTBox->GetName() << endl;
207 cout <<
" time(ns): " << (*digi).time() -
offset << endl;
209 hO->Fill((*digi).wire());
216 cout <<
"[DTTTrigCalibration]Writing histos to file!" << endl;
220 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
222 (*slHisto).second->Write();
224 for (map<DTLayerId, TH1F*>::const_iterator slHisto = theOccupancyMap.begin(); slHisto != theOccupancyMap.end();
226 (*slHisto).second->Write();
229 if (findTMeanAndSigma) {
234 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
236 pair<double, double> meanAndSigma = theFitter->fitTimeBox((*slHisto).second);
240 cout <<
" SL: " << (*slHisto).first <<
" mean = " << meanAndSigma.first <<
" sigma = " << meanAndSigma.second
252 cout <<
"[DTTTrigCalibration]Writing ttrig object to DB!" << endl;
255 string tTrigRecord =
"DTTtrigRcd";
264 stringstream theStream;
273 stringstream theStream;
275 <<
"_L" << slId.
layer() <<
"_Occupancy";
281 static const double convToNs = 25. / 32.;
283 cout <<
"Wh: " << (*ttrig).first.wheelId <<
" St: " << (*ttrig).first.stationId
284 <<
" Sc: " << (*ttrig).first.sectorId <<
" Sl: " << (*ttrig).first.slId
285 <<
" TTrig mean (ns): " << (*ttrig).second.tTrig * convToNs
286 <<
" TTrig sigma (ns): " << (*ttrig).second.tTrms * convToNs << endl;
291 TH1F* tTrig_YB1_Se10 =
new TH1F(
"tTrig_YB1_Se10",
"tTrig YB1_Se10", 15, 1, 16);
292 TH1F* tTrig_YB2_Se10 =
new TH1F(
"tTrig_YB2_Se10",
"tTrig YB2_Se10", 15, 1, 16);
293 TH1F* tTrig_YB2_Se11 =
new TH1F(
"tTrig_YB2_Se11",
"tTrig YB2_Se11", 12, 1, 13);
295 static const double convToNs = 25. / 32.;
298 float tTrigValue = 0;
299 float tTrmsValue = 0;
300 if ((*ttrig).second.tTrig * convToNs > 0 && (*ttrig).second.tTrig * convToNs < 32000) {
301 tTrigValue = (*ttrig).second.tTrig * convToNs;
302 tTrmsValue = (*ttrig).second.tTrms * convToNs;
307 stringstream binLabelStream;
308 if ((*ttrig).first.sectorId != 14) {
309 binx = ((*ttrig).first.stationId - 1) * 3 + (*ttrig).first.slId;
310 binLabelStream <<
"MB" << (*ttrig).first.stationId <<
"_SL" << (*ttrig).first.slId;
312 binx = 12 + (*ttrig).first.slId;
313 binLabelStream <<
"MB14_SL" << (*ttrig).first.slId;
315 binLabelStream >> binLabel;
317 if ((*ttrig).first.wheelId == 2) {
318 if ((*ttrig).first.sectorId == 10 || (*ttrig).first.sectorId == 14) {
319 tTrig_YB2_Se10->Fill(binx, tTrigValue);
320 tTrig_YB2_Se10->SetBinError(binx, tTrmsValue);
321 tTrig_YB2_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
322 tTrig_YB2_Se10->GetYaxis()->SetTitle(
"ns");
324 tTrig_YB2_Se11->Fill(binx, tTrigValue);
325 tTrig_YB2_Se11->SetBinError(binx, tTrmsValue);
326 tTrig_YB2_Se11->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
327 tTrig_YB2_Se11->GetYaxis()->SetTitle(
"ns");
330 tTrig_YB1_Se10->Fill(binx, tTrigValue);
331 tTrig_YB1_Se10->SetBinError(binx, tTrmsValue);
332 tTrig_YB1_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
333 tTrig_YB1_Se10->GetYaxis()->SetTitle(
"ns");
337 tTrig_YB1_Se10->Write();
338 tTrig_YB2_Se10->Write();
339 tTrig_YB2_Se11->Write();
int station() const
Return the station number.
DTTTrigCalibration(const edm::ParameterSet &pset)
Constructor.
std::vector< std::pair< DTTtrigId, DTTtrigData > >::const_iterator const_iterator
Access methods to data.
static void writeToDB(std::string record, const T &payload)
void dumpTTrigMap(const DTTtrig *tTrig) const
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Fill the time boxes.
constexpr std::array< uint8_t, layerIndexSize > layer
DTChamberId chamberId() const
Return the corresponding ChamberId.
void plotTTrig(const DTTtrig *tTrig) const
~DTTTrigCalibration() override
Destructor.
std::string getTBoxName(const DTSuperLayerId &slId) const
std::string getOccupancyName(const DTLayerId &slId) const
int superlayer() const
Return the superlayer number (deprecated method name)
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
int layer() const
Return the layer number.
int wheel() const
Return the wheel number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
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
void endJob() override
Fit the time box rising edge and write the resulting ttrig to the DB.