29 debug =
pset.getUntrackedParameter<
bool>(
"debug");
31 cout <<
"[DTT0CalibrationRMS]Constructor called!" << endl;
37 string rootFileName =
pset.getUntrackedParameter<
string>(
"rootFileName",
"DTT0PerLayer.root");
41 pset.getUntrackedParameter<
string>(
"calibWheel",
"All");
47 cout <<
"[DTT0CalibrationRMSPerLayer] chosen wheel " <<
selWheel << endl;
52 pset.getUntrackedParameter<
string>(
"calibSector",
"All");
58 cout <<
"[DTT0CalibrationRMSPerLayer] chosen sector " <<
selSector << endl;
61 vector<string> defaultCell;
62 defaultCell.push_back(
"None");
63 cellsWithHistos =
pset.getUntrackedParameter<vector<string> >(
"cellsWithHisto", defaultCell);
65 if ((*cell) !=
"None") {
88 cout <<
"[DTT0CalibrationRMS]Destructor called!" << endl;
96 cout <<
"--- [DTT0CalibrationRMS] Analysing Event: #Run: " <<
event.id().run() <<
" #Event: " <<
event.id().event()
109 for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
114 const DTLayerId layerId = (*dtLayerIt).first;
127 double t0 = (*digi).countsTDC();
134 if (hT0LayerHisto ==
nullptr) {
137 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
142 cout <<
" New T0 per Layer Histo: " << hT0LayerHisto->GetName() << endl;
148 if (hT0LayerHisto !=
nullptr) {
151 hT0LayerHisto->Fill(
t0);
158 const DTWireId wireId(layerId, (*digi).wire());
160 cout <<
" Wire: " << wireId << endl <<
" time (TDC counts): " << (*digi).countsTDC() << endl;
168 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
177 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
189 hT0WireHisto->Fill(
t0);
195 cout <<
"digi skipped because t0 per sector " 206 if (hT0WireHisto_ref)
207 hT0WireHisto_ref->Fill(
t0);
240 cout <<
"Reading histogram " << (*lHisto).second->GetName() <<
" with mean " << (*lHisto).second->GetMean()
241 <<
" and RMS " << (*lHisto).second->GetRMS();
244 if ((*lHisto).second->GetRMS() < 5.0) {
247 "T0 from pulses per layer in sector",
254 cout <<
" accepted" << endl;
272 theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
276 cout <<
"[DTT0CalibrationRMS]: All the t0 per layer are still uncorrect: trying with greater number of events" 282 cout <<
"[DTT0CalibrationRMS] t0 reference for this sector " 293 cout <<
"[DTT0CalibrationRMSPerLayer]Writing histos to file!" << endl;
300 (*wHisto).second->Write();
304 (*wHisto).second->Write();
308 (*lHisto).second->Write();
312 cout <<
"[DTT0CalibrationRMS] Compute and store t0 and sigma per wire" << endl;
331 cout <<
"[DTT0CalibrationRMS] ERROR: no digis in wire " << (*wiret0).first << endl;
341 for (vector<const DTSuperLayer*>::const_iterator sl = superLayers.begin(); sl != superLayers.end(); sl++) {
343 double oddLayersMean = 0;
344 double evenLayersMean = 0;
345 double oddLayersDen = 0;
346 double evenLayersDen = 0;
350 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
352 cout <<
"[DTT0CalibrationRMS] Superlayer " << (*sl)->id() <<
"layer " << (*wiret0).first.layerId().layer()
353 <<
" with " << (*wiret0).second << endl;
354 if (((*wiret0).first.layerId().layer()) % 2) {
355 oddLayersMean = oddLayersMean + (*wiret0).second;
358 evenLayersMean = evenLayersMean + (*wiret0).second;
363 oddLayersMean = oddLayersMean / oddLayersDen;
364 evenLayersMean = evenLayersMean / evenLayersDen;
366 cout <<
"[DTT0CalibrationRMS] Relative T0 mean for odd layers " << oddLayersMean <<
" even layers" 367 << evenLayersMean << endl;
370 double oddLayersSigma = 0;
371 double evenLayersSigma = 0;
375 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
376 if (((*wiret0).first.layerId().layer()) % 2) {
377 oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
380 evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
384 oddLayersSigma = oddLayersSigma / oddLayersDen;
385 evenLayersSigma = evenLayersSigma / evenLayersDen;
386 oddLayersSigma =
sqrt(oddLayersSigma);
387 evenLayersSigma =
sqrt(evenLayersSigma);
390 cout <<
"[DTT0CalibrationRMS] Relative T0 sigma for odd layers " << oddLayersSigma <<
" even layers" 391 << evenLayersSigma << endl;
394 double oddLayersFinalMean = 0;
395 double evenLayersFinalMean = 0;
399 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
400 if (((*wiret0).first.layerId().layer()) % 2) {
401 if (
abs((*wiret0).second - oddLayersMean) < (2 * oddLayersSigma))
402 oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
404 if (
abs((*wiret0).second - evenLayersMean) < (2 * evenLayersSigma))
405 evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
409 oddLayersFinalMean = oddLayersFinalMean / oddLayersDen;
410 evenLayersFinalMean = evenLayersFinalMean / evenLayersDen;
412 cout <<
"[DTT0CalibrationRMS] Final relative T0 mean for odd layers " << oddLayersFinalMean <<
" even layers" 413 << evenLayersFinalMean << endl;
418 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
420 if (((*wiret0).first.layerId().layer()) % 2)
421 t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
423 t0 = (*wiret0).second;
425 cout <<
"[DTT0CalibrationRMS] Wire " << (*wiret0).first <<
" has t0 " << (*wiret0).second
426 <<
" (relative, after even-odd layer corrections) " 437 cout <<
"[DTT0CalibrationRMS]Computing relative t0 wrt to chamber average" << endl;
439 map<DTChamberId, double> sumT0ByChamber;
440 map<DTChamberId, int> countT0ByChamber;
442 int channelId =
tzero->channelId;
452 sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
454 countT0ByChamber[chamberId]++;
459 int channelId =
tzero->channelId;
470 double t0mean = t0mean_f - (sumT0ByChamber[chamberId] / countT0ByChamber[chamberId]);
471 double t0rms = t0rms_f;
476 cout <<
"Changing t0 of wire " << wireId <<
" from " << t0mean_f <<
" to " << t0mean << endl;
482 cout <<
"[DTT0CalibrationRMS]Writing values in DB!" << endl;
484 string t0Record =
"DTT0Rcd";
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
int station() const
Return the station number.
std::map< DTWireId, double > theAbsoluteT0PerWire
static void writeToDB(std::string record, const T &payload)
void endJob() override
Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularit...
int wire() const
Return the wire number.
std::map< DTWireId, double > qK
std::map< DTWireId, double > mK
std::map< DTWireId, int > nDigiPerWire
const_iterator end() const
std::map< std::string, double > theSigmaT0LayerMap
std::string getHistoName(const DTWireId &wId) const
std::string to_string(const V &value)
edm::ESHandle< DTGeometry > dtGeom
std::map< DTWireId, TH1I * > theHistoWireMap
unsigned int rejectDigiFromPeak
std::vector< DTWireId > wireIdWithHistos
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string theCalibSector
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
unsigned int eventsForWireT0
constexpr std::array< uint8_t, layerIndexSize > layer
const_iterator begin() const
std::map< std::string, double > theT0LayerMap
std::map< DTWireId, TH1I * > theHistoWireMap_ref
std::map< DTWireId, double > mK_ref
DTChamberId chamberId() const
Return the corresponding ChamberId.
~DTT0CalibrationRMS() override
Destructor.
unsigned int eventsForLayerT0
std::map< DTLayerId, TH1I * > theHistoLayerMap
Abs< T >::type abs(const T &t)
std::map< DTWireId, double > theSigmaT0PerWire
int superlayer() const
Return the superlayer number (deprecated method name)
bool correctByChamberMean_
std::pair< const_iterator, const_iterator > Range
std::vector< std::string > cellsWithHistos
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
std::vector< DigiType >::const_iterator const_iterator
DTT0CalibrationRMS(const edm::ParameterSet &pset)
Constructor.
int layer() const
Return the layer number.
std::map< DTWireId, double > theRelativeT0PerWire
int wheel() const
Return the wheel number.
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
static const double tzero[3]
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Fill the maps with t0 (by channel)
std::string theCalibWheel
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
std::map< DTWireId, int > nDigiPerWire_ref
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.