29 debug =
pset.getUntrackedParameter<
bool>(
"debug");
31 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS]Constructor called!";
34 digiToken = consumes<DTDigiCollection>(
pset.getUntrackedParameter<
string>(
"digiLabel"));
37 string rootFileName =
pset.getUntrackedParameter<
string>(
"rootFileName",
"DTT0PerLayer.root");
41 pset.getUntrackedParameter<
string>(
"calibWheel",
"All");
52 pset.getUntrackedParameter<
string>(
"calibSector",
"All");
61 vector<string> defaultCell;
62 defaultCell.push_back(
"None");
63 cellsWithHistos =
pset.getUntrackedParameter<vector<string> >(
"cellsWithHisto", defaultCell);
65 if ((*cell) !=
"None") {
88 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS]Destructor called!";
96 edm::LogVerbatim(
"DTCalibration") <<
"--- [DTT0CalibrationRMS] Analysing Event: #Run: " <<
event.id().run()
97 <<
" #Event: " <<
event.id().event();
108 for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
113 const DTLayerId layerId = (*dtLayerIt).first;
122 double t0 = (*digi).countsTDC();
129 if (hT0LayerHisto ==
nullptr) {
132 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
137 edm::LogVerbatim(
"DTCalibration") <<
" New T0 per Layer Histo: " << hT0LayerHisto->GetName();
143 if (hT0LayerHisto !=
nullptr) {
144 hT0LayerHisto->Fill(
t0);
151 const DTWireId wireId(layerId, (*digi).wire());
154 <<
" Wire: " << wireId <<
"\n time (TDC counts): " << (*digi).countsTDC();
162 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
171 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
184 hT0WireHisto->Fill(
t0);
201 if (hT0WireHisto_ref)
202 hT0WireHisto_ref->Fill(
t0);
235 edm::LogVerbatim(
"DTCalibration") <<
"Reading histogram " << (*lHisto).second->GetName() <<
" with mean " 236 << (*lHisto).second->GetMean() <<
" and RMS " << (*lHisto).second->GetRMS();
239 if ((*lHisto).second->GetRMS() < 5.0) {
242 "T0 from pulses per layer in sector",
267 theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
272 <<
"[DTT0CalibrationRMS]: All the t0 per layer are still uncorrect: trying with greater number of events";
277 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] t0 reference for this sector " 288 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMSPerLayer]Writing histos to file!";
295 (*wHisto).second->Write();
299 (*wHisto).second->Write();
303 (*lHisto).second->Write();
307 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Compute and store t0 and sigma per wire";
320 edm::LogVerbatim(
"DTCalibration") <<
"Wire " << (*wiret0).first <<
" has t0 " <<
t0 <<
"(absolute) " 326 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] ERROR: no digis in wire " << (*wiret0).first;
336 for (vector<const DTSuperLayer*>::const_iterator sl = superLayers.begin(); sl != superLayers.end(); sl++) {
338 double oddLayersMean = 0;
339 double evenLayersMean = 0;
340 double oddLayersDen = 0;
341 double evenLayersDen = 0;
345 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
347 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Superlayer " << (*sl)->id() <<
"layer " 348 << (*wiret0).first.layerId().layer() <<
" with " << (*wiret0).second;
349 if (((*wiret0).first.layerId().layer()) % 2) {
350 oddLayersMean = oddLayersMean + (*wiret0).second;
353 evenLayersMean = evenLayersMean + (*wiret0).second;
358 oddLayersMean = oddLayersMean / oddLayersDen;
359 evenLayersMean = evenLayersMean / evenLayersDen;
361 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Relative T0 mean for odd layers " << oddLayersMean
362 <<
" even layers" << evenLayersMean;
365 double oddLayersSigma = 0;
366 double evenLayersSigma = 0;
370 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
371 if (((*wiret0).first.layerId().layer()) % 2) {
372 oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
375 evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
379 oddLayersSigma = oddLayersSigma / oddLayersDen;
380 evenLayersSigma = evenLayersSigma / evenLayersDen;
381 oddLayersSigma =
sqrt(oddLayersSigma);
382 evenLayersSigma =
sqrt(evenLayersSigma);
385 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Relative T0 sigma for odd layers " << oddLayersSigma
386 <<
" even layers" << evenLayersSigma;
389 double oddLayersFinalMean = 0;
390 double evenLayersFinalMean = 0;
394 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
395 if (((*wiret0).first.layerId().layer()) % 2) {
396 if (
abs((*wiret0).second - oddLayersMean) < (2 * oddLayersSigma))
397 oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
399 if (
abs((*wiret0).second - evenLayersMean) < (2 * evenLayersSigma))
400 evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
404 oddLayersFinalMean = oddLayersFinalMean / oddLayersDen;
405 evenLayersFinalMean = evenLayersFinalMean / evenLayersDen;
407 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Final relative T0 mean for odd layers " 408 << oddLayersFinalMean <<
" even layers" << evenLayersFinalMean;
413 if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
415 if (((*wiret0).first.layerId().layer()) % 2)
416 t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
418 t0 = (*wiret0).second;
420 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS] Wire " << (*wiret0).first <<
" has t0 " 421 << (*wiret0).second <<
" (relative, after even-odd layer corrections) " 431 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS]Computing relative t0 wrt to chamber average";
433 map<DTChamberId, double> sumT0ByChamber;
434 map<DTChamberId, int> countT0ByChamber;
436 int channelId =
tzero->channelId;
453 int channelId =
tzero->channelId;
465 double t0rms = t0rms_f;
468 edm::LogVerbatim(
"DTCalibration") <<
"Changing t0 of wire " << wireId <<
" from " << t0mean_f <<
" to " << t0mean;
474 edm::LogVerbatim(
"DTCalibration") <<
"[DTT0CalibrationRMS]Writing values in DB!";
476 string t0Record =
"DTT0Rcd";
485 delete t0sWRTChamber;
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
Log< level::Info, true > LogVerbatim
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
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
static std::string to_string(const XMLCh *ch)
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)
edm::EDGetTokenT< DTDigiCollection > digiToken
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.