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");
77 kFactor =
pset.getUntrackedParameter<
double>(
"kFactor", -0.7);
80 cout <<
"[DTTTrigCalibration]Constructor called!" << endl;
90 cout <<
"[DTTTrigCalibration]Destructor called!" << endl;
105 cout <<
"[DTTTrigCalibration] #Event: " <<
event.id().event() << endl;
113 statusMap =
eventSetup.getHandle(theStatusMapToken);
120 vector<DTChamberId> badChambers;
124 for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
128 const DTLayerId layerId = (*dtLayerIt).first;
131 bool badChamber =
false;
134 cout <<
"----------- Layer " << layerId <<
" -------------" << endl;
137 for (vector<DTChamberId>::const_iterator
chamber = badChambers.begin();
chamber != badChambers.end(); ++
chamber) {
147 if ((digiRange.second - digiRange.first) > maxDigiPerLayer) {
149 cout <<
"Layer " << layerId <<
"has too many digis (" << (digiRange.second - digiRange.first) <<
")" << endl;
150 badChambers.push_back(chId);
155 TH1F* hTBox = theHistoMap[slId];
156 if (hTBox ==
nullptr) {
160 new TH1F(getTBoxName(slId).c_str(),
"Time box (ns)",
int(0.25 * 32.0 * maxTDCCounts / 25.0), 0, maxTDCCounts);
162 cout <<
" New Time Box: " << hTBox->GetName() << endl;
163 theHistoMap[slId] = hTBox;
165 TH1F* hO = theOccupancyMap[layerId];
169 hO =
new TH1F(getOccupancyName(layerId).c_str(),
"Occupancy", 100, 0, 100);
171 cout <<
" New Time Box: " << hO->GetName() << endl;
172 theOccupancyMap[layerId] = hO;
177 const DTWireId wireId(layerId, (*digi).wire());
181 bool isNoisy =
false;
182 bool isFEMasked =
false;
183 bool isTDCMasked =
false;
184 bool isTrigMask =
false;
187 statusMap->
cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
190 cout <<
"Wire: " << wireId <<
" is noisy, skipping!" << endl;
201 hTBox->Fill((*digi).time() -
offset);
203 cout <<
" Filling Time Box: " << hTBox->GetName() << endl;
205 cout <<
" time(ns): " << (*digi).time() -
offset << endl;
207 hO->Fill((*digi).wire());
214 cout <<
"[DTTTrigCalibration]Writing histos to file!" << endl;
218 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
220 (*slHisto).second->Write();
222 for (map<DTLayerId, TH1F*>::const_iterator slHisto = theOccupancyMap.begin(); slHisto != theOccupancyMap.end();
224 (*slHisto).second->Write();
227 if (findTMeanAndSigma) {
232 for (map<DTSuperLayerId, TH1F*>::const_iterator slHisto = theHistoMap.begin(); slHisto != theHistoMap.end();
234 pair<double, double> meanAndSigma = theFitter->fitTimeBox((*slHisto).second);
238 cout <<
" SL: " << (*slHisto).first <<
" mean = " << meanAndSigma.first <<
" sigma = " << meanAndSigma.second
250 cout <<
"[DTTTrigCalibration]Writing ttrig object to DB!" << endl;
253 string tTrigRecord =
"DTTtrigRcd";
262 stringstream theStream;
271 stringstream theStream;
273 <<
"_L" << slId.
layer() <<
"_Occupancy";
279 static const double convToNs = 25. / 32.;
281 cout <<
"Wh: " << (*ttrig).first.wheelId <<
" St: " << (*ttrig).first.stationId
282 <<
" Sc: " << (*ttrig).first.sectorId <<
" Sl: " << (*ttrig).first.slId
283 <<
" TTrig mean (ns): " << (*ttrig).second.tTrig * convToNs
284 <<
" TTrig sigma (ns): " << (*ttrig).second.tTrms * convToNs << endl;
289 TH1F* tTrig_YB1_Se10 =
new TH1F(
"tTrig_YB1_Se10",
"tTrig YB1_Se10", 15, 1, 16);
290 TH1F* tTrig_YB2_Se10 =
new TH1F(
"tTrig_YB2_Se10",
"tTrig YB2_Se10", 15, 1, 16);
291 TH1F* tTrig_YB2_Se11 =
new TH1F(
"tTrig_YB2_Se11",
"tTrig YB2_Se11", 12, 1, 13);
293 static const double convToNs = 25. / 32.;
296 float tTrigValue = 0;
297 float tTrmsValue = 0;
298 if ((*ttrig).second.tTrig * convToNs > 0 && (*ttrig).second.tTrig * convToNs < 32000) {
299 tTrigValue = (*ttrig).second.tTrig * convToNs;
300 tTrmsValue = (*ttrig).second.tTrms * convToNs;
305 stringstream binLabelStream;
306 if ((*ttrig).first.sectorId != 14) {
307 binx = ((*ttrig).first.stationId - 1) * 3 + (*ttrig).first.slId;
308 binLabelStream <<
"MB" << (*ttrig).first.stationId <<
"_SL" << (*ttrig).first.slId;
310 binx = 12 + (*ttrig).first.slId;
311 binLabelStream <<
"MB14_SL" << (*ttrig).first.slId;
313 binLabelStream >> binLabel;
315 if ((*ttrig).first.wheelId == 2) {
316 if ((*ttrig).first.sectorId == 10 || (*ttrig).first.sectorId == 14) {
317 tTrig_YB2_Se10->Fill(binx, tTrigValue);
318 tTrig_YB2_Se10->SetBinError(binx, tTrmsValue);
319 tTrig_YB2_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
320 tTrig_YB2_Se10->GetYaxis()->SetTitle(
"ns");
322 tTrig_YB2_Se11->Fill(binx, tTrigValue);
323 tTrig_YB2_Se11->SetBinError(binx, tTrmsValue);
324 tTrig_YB2_Se11->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
325 tTrig_YB2_Se11->GetYaxis()->SetTitle(
"ns");
328 tTrig_YB1_Se10->Fill(binx, tTrigValue);
329 tTrig_YB1_Se10->SetBinError(binx, tTrmsValue);
330 tTrig_YB1_Se10->GetXaxis()->SetBinLabel(binx, binLabel.c_str());
331 tTrig_YB1_Se10->GetYaxis()->SetTitle(
"ns");
335 tTrig_YB1_Se10->Write();
336 tTrig_YB2_Se10->Write();
337 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.