58 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
60 theFitter = std::make_unique<DTTimeBoxFitter>();
62 theFitter->setVerbosity(1);
65 theFitter->setFitSigma(sigmaFit);
81 cout <<
"[DTTTrigCalibration]Constructor called!" << endl;
83 if (checkNoisyChannels) {
91 cout <<
"[DTTTrigCalibration]Destructor called!" << endl;
106 cout <<
"[DTTTrigCalibration] #Event: " <<
event.id().event() << endl;
113 if (checkNoisyChannels) {
115 statusMap = eventSetup.
getHandle(theStatusMapToken);
119 theSync->setES(eventSetup);
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());
182 if (checkNoisyChannels) {
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;
201 offset = theSync->offset(layer, wireId, glPt);
203 hTBox->Fill((*digi).time() -
offset);
205 cout <<
" Filling Time Box: " << hTBox->GetName() << endl;
206 cout <<
" offset (ns): " << offset << 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);
237 tTrig->
set((*slHisto).first, meanAndSigma.first, meanAndSigma.second, kFactor,
DTTimeUnits::ns);
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;
267 theStream >> histoName;
273 stringstream theStream;
275 <<
"_L" << slId.
layer() <<
"_Occupancy";
276 theStream >> histoName;
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();
DTTTrigCalibration(const edm::ParameterSet &pset)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::pair< DTTtrigId, DTTtrigData > >::const_iterator const_iterator
Access methods to data.
static void writeToDB(std::string record, const T &payload)
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
constexpr std::array< uint8_t, layerIndexSize > layer
~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::pair< const_iterator, const_iterator > Range
const DTChamber * chamber() const
std::vector< DigiType >::const_iterator const_iterator
const_iterator begin() const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
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.