CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
DTT0CalibrationRMS Class Reference

#include <DTT0CalibrationRMS.h>

Inheritance diagram for DTT0CalibrationRMS:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &eventSetup) override
 Fill the maps with t0 (by channel) More...
 
 DTT0CalibrationRMS (const edm::ParameterSet &pset)
 Constructor. More...
 
void endJob () override
 Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularity. More...
 
 ~DTT0CalibrationRMS () override
 Destructor. More...
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const noexcept
 
bool wantsStreamRuns () const noexcept
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

std::string getHistoName (const DTWireId &wId) const
 
std::string getHistoName (const DTLayerId &lId) const
 

Private Attributes

std::vector< std::string > cellsWithHistos
 
bool correctByChamberMean_
 
bool debug
 
edm::EDGetTokenT< DTDigiCollectiondigiToken
 
edm::ESHandle< DTGeometrydtGeom
 
const edm::ESGetToken< DTGeometry, MuonGeometryRecorddtGeomToken_
 
unsigned int eventsForLayerT0
 
unsigned int eventsForWireT0
 
TH1D * hT0SectorHisto
 
std::map< DTWireId, double > mK
 
std::map< DTWireId, double > mK_ref
 
std::map< DTWireId, int > nDigiPerWire
 
std::map< DTWireId, int > nDigiPerWire_ref
 
unsigned int nevents
 
std::map< DTWireId, double > qK
 
unsigned int rejectDigiFromPeak
 
int selSector
 
int selWheel
 
std::map< DTWireId, double > theAbsoluteT0PerWire
 
std::string theCalibSector
 
std::string theCalibWheel
 
TFile * theFile
 
std::map< DTLayerId, TH1I * > theHistoLayerMap
 
std::map< DTWireId, TH1I * > theHistoWireMap
 
std::map< DTWireId, TH1I * > theHistoWireMap_ref
 
TFile * theOutputFile
 
std::map< DTWireId, double > theRelativeT0PerWire
 
std::map< std::string, double > theSigmaT0LayerMap
 
std::map< DTWireId, double > theSigmaT0PerWire
 
std::map< std::string, double > theT0LayerMap
 
double tpPeakWidth
 
std::vector< DTWireIdwireIdWithHistos
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Analyzer class computes the mean and RMS of t0 from pulses. Those values are written in the DB with cell granularity. The mean value for each channel is normalized to a reference time common to all the sector. The t0 of wires in odd layers are corrected for the relative difference between odd and even layers

Definition at line 28 of file DTT0CalibrationRMS.h.

Constructor & Destructor Documentation

◆ DTT0CalibrationRMS()

DTT0CalibrationRMS::DTT0CalibrationRMS ( const edm::ParameterSet pset)

Constructor.

Definition at line 27 of file DTT0CalibrationRMS.cc.

References cellsWithHistos, correctByChamberMean_, debug, digiToken, eventsForLayerT0, eventsForWireT0, hT0SectorHisto, nano_mu_digi_cff::layer, nevents, muonDTDigis_cfi::pset, rejectDigiFromPeak, CSCSkim_cfi::rootFileName, nano_mu_digi_cff::sector, selSector, selWheel, relativeConstraints::station, theCalibSector, theCalibWheel, theFile, tpPeakWidth, makeMuonMisalignmentScenario::wheel, nano_mu_digi_cff::wire, and wireIdWithHistos.

28  // Get the debug parameter for verbose output
29  debug = pset.getUntrackedParameter<bool>("debug");
30  if (debug)
31  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS]Constructor called!";
32 
33  // Get the token to retrieve digis from the event
34  digiToken = consumes<DTDigiCollection>(pset.getUntrackedParameter<string>("digiLabel"));
35 
36  // The root file which contain the histos per layer
37  string rootFileName = pset.getUntrackedParameter<string>("rootFileName", "DTT0PerLayer.root");
38  theFile = new TFile(rootFileName.c_str(), "RECREATE");
39 
41  pset.getUntrackedParameter<string>("calibWheel", "All"); //FIXME amke a vector of integer instead of a string
42  if (theCalibWheel != "All") {
43  stringstream linestr;
44  int selWheel;
45  linestr << theCalibWheel;
46  linestr >> selWheel;
47  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMSPerLayer] chosen wheel " << selWheel;
48  }
49 
50  // Sector/s to calibrate
52  pset.getUntrackedParameter<string>("calibSector", "All"); //FIXME amke a vector of integer instead of a string
53  if (theCalibSector != "All") {
54  stringstream linestr;
55  int selSector;
56  linestr << theCalibSector;
57  linestr >> selSector;
58  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMSPerLayer] chosen sector " << selSector;
59  }
60 
61  vector<string> defaultCell;
62  defaultCell.push_back("None");
63  cellsWithHistos = pset.getUntrackedParameter<vector<string> >("cellsWithHisto", defaultCell);
64  for (vector<string>::const_iterator cell = cellsWithHistos.begin(); cell != cellsWithHistos.end(); ++cell) {
65  if ((*cell) != "None") {
66  stringstream linestr;
67  int wheel, sector, station, sl, layer, wire;
68  linestr << (*cell);
69  linestr >> wheel >> sector >> station >> sl >> layer >> wire;
71  }
72  }
73 
74  hT0SectorHisto = nullptr;
75 
76  nevents = 0;
77  eventsForLayerT0 = pset.getParameter<unsigned int>("eventsForLayerT0");
78  eventsForWireT0 = pset.getParameter<unsigned int>("eventsForWireT0");
79  rejectDigiFromPeak = pset.getParameter<unsigned int>("rejectDigiFromPeak");
80  tpPeakWidth = pset.getParameter<double>("tpPeakWidth");
81  //useReferenceWireInLayer_ = true;
82  correctByChamberMean_ = pset.getParameter<bool>("correctByChamberMean");
83 }
Log< level::Info, true > LogVerbatim
unsigned int rejectDigiFromPeak
std::vector< DTWireId > wireIdWithHistos
std::string theCalibSector
unsigned int eventsForWireT0
unsigned int eventsForLayerT0
edm::EDGetTokenT< DTDigiCollection > digiToken
std::vector< std::string > cellsWithHistos
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_

◆ ~DTT0CalibrationRMS()

DTT0CalibrationRMS::~DTT0CalibrationRMS ( )
override

Destructor.

Definition at line 86 of file DTT0CalibrationRMS.cc.

References debug, and theFile.

86  {
87  if (debug)
88  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS]Destructor called!";
89 
90  theFile->Close();
91 }
Log< level::Info, true > LogVerbatim

Member Function Documentation

◆ analyze()

void DTT0CalibrationRMS::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
overridevirtual

Fill the maps with t0 (by channel)

Perform the real analysis.

Implements edm::one::EDAnalyzerBase.

Definition at line 94 of file DTT0CalibrationRMS.cc.

References funct::abs(), DTSuperLayerId::chamberId(), debug, digiToken, dtGeom, dtGeomToken_, options_cfi::eventSetup, eventsForLayerT0, eventsForWireT0, spr::find(), getHistoName(), hT0SectorHisto, mK, mK_ref, nDigiPerWire, nDigiPerWire_ref, nevents, qK, rejectDigiFromPeak, DTChamberId::sector(), selSector, selWheel, DTLayerId::superlayerId(), FrontierCondition_GT_autoExpress_cfi::t0, theAbsoluteT0PerWire, theCalibSector, theCalibWheel, theFile, theHistoLayerMap, theHistoWireMap, theHistoWireMap_ref, theSigmaT0LayerMap, theT0LayerMap, tpPeakWidth, DTChamberId::wheel(), and wireIdWithHistos.

94  {
95  if (debug || event.id().event() % 500 == 0)
96  edm::LogVerbatim("DTCalibration") << "--- [DTT0CalibrationRMS] Analysing Event: #Run: " << event.id().run()
97  << " #Event: " << event.id().event();
98  nevents++;
99 
100  // Get the digis from the event
101  const Handle<DTDigiCollection>& digis = event.getHandle(digiToken);
102 
103  // Get the DT Geometry
104  dtGeom = eventSetup.getHandle(dtGeomToken_);
105 
106  // Iterate through all digi collections ordered by LayerId
108  for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
109  // Get the iterators over the digis associated with this LayerId
110  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
111 
112  // Get the layerId
113  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
114 
115  if ((theCalibWheel != "All") && (layerId.superlayerId().chamberId().wheel() != selWheel))
116  continue;
117  if ((theCalibSector != "All") && (layerId.superlayerId().chamberId().sector() != selSector))
118  continue;
119 
120  // Loop over all digis in the given layer
121  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; ++digi) {
122  double t0 = (*digi).countsTDC();
123 
124  //Use first bunch of events to fill t0 per layer
125  if (nevents < eventsForLayerT0) {
126  //Get the per-layer histo from the map
127  TH1I* hT0LayerHisto = theHistoLayerMap[layerId];
128  //If it doesn't exist, book it
129  if (hT0LayerHisto == nullptr) {
130  theFile->cd();
131  hT0LayerHisto = new TH1I(getHistoName(layerId).c_str(),
132  "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
133  200,
134  t0 - 100,
135  t0 + 100);
136  if (debug)
137  edm::LogVerbatim("DTCalibration") << " New T0 per Layer Histo: " << hT0LayerHisto->GetName();
138  theHistoLayerMap[layerId] = hT0LayerHisto;
139  }
140 
141  //Fill the histos
142  theFile->cd();
143  if (hT0LayerHisto != nullptr) {
144  hT0LayerHisto->Fill(t0);
145  }
146  }
147 
148  //Use all the remaining events to compute t0 per wire
149  if (nevents > eventsForLayerT0) {
150  // Get the wireId
151  const DTWireId wireId(layerId, (*digi).wire());
152  if (debug) {
153  edm::LogVerbatim("DTCalibration")
154  << " Wire: " << wireId << "\n time (TDC counts): " << (*digi).countsTDC();
155  }
156 
157  //Fill the histos per wire for the chosen cells
158  vector<DTWireId>::iterator it_wire = find(wireIdWithHistos.begin(), wireIdWithHistos.end(), wireId);
159  if (it_wire != wireIdWithHistos.end()) {
160  if (theHistoWireMap.find(wireId) == theHistoWireMap.end()) {
161  theHistoWireMap[wireId] = new TH1I(getHistoName(wireId).c_str(),
162  "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
163  7000,
164  0,
165  7000);
166  if (debug)
167  edm::LogVerbatim("DTCalibration") << " New T0 per wire Histo: " << (theHistoWireMap[wireId])->GetName();
168  }
169  if (theHistoWireMap_ref.find(wireId) == theHistoWireMap_ref.end()) {
170  theHistoWireMap_ref[wireId] = new TH1I((getHistoName(wireId) + "_ref").c_str(),
171  "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
172  7000,
173  0,
174  7000);
175  if (debug)
176  edm::LogVerbatim("DTCalibration")
177  << " New T0 per wire Histo: " << (theHistoWireMap_ref[wireId])->GetName();
178  }
179 
180  TH1I* hT0WireHisto = theHistoWireMap[wireId];
181  //Fill the histos
182  theFile->cd();
183  if (hT0WireHisto)
184  hT0WireHisto->Fill(t0);
185  }
186 
187  //Check the tzero has reasonable value
188  if (abs(hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin()) - t0) > rejectDigiFromPeak) {
189  if (debug)
190  edm::LogVerbatim("DTCalibration") << "digi skipped because t0 per sector "
191  << hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
192  continue;
193  }
194 
195  //Use second bunch of events to compute a t0 reference per wire
197  //Fill reference wire histos
198  if (it_wire != wireIdWithHistos.end()) {
199  TH1I* hT0WireHisto_ref = theHistoWireMap_ref[wireId];
200  theFile->cd();
201  if (hT0WireHisto_ref)
202  hT0WireHisto_ref->Fill(t0);
203  }
204  if (!nDigiPerWire_ref[wireId]) {
205  mK_ref[wireId] = 0;
206  }
207  nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
208  mK_ref[wireId] = mK_ref[wireId] + (t0 - mK_ref[wireId]) / nDigiPerWire_ref[wireId];
209  }
210  //Use last all the remaining events to compute the mean and sigma t0 per wire
211  else if (nevents > (eventsForLayerT0 + eventsForWireT0)) {
212  if (abs(t0 - mK_ref[wireId]) > tpPeakWidth)
213  continue;
214  if (!nDigiPerWire[wireId]) {
215  theAbsoluteT0PerWire[wireId] = 0;
216  qK[wireId] = 0;
217  mK[wireId] = 0;
218  }
219  nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
220  theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
221  //theSigmaT0PerWire[wireId] = theSigmaT0PerWire[wireId] + (t0*t0);
222  qK[wireId] =
223  qK[wireId] + ((nDigiPerWire[wireId] - 1) * (t0 - mK[wireId]) * (t0 - mK[wireId]) / nDigiPerWire[wireId]);
224  mK[wireId] = mK[wireId] + (t0 - mK[wireId]) / nDigiPerWire[wireId];
225  }
226  } //end if(nevents>1000)
227  } //end loop on digi
228  } //end loop on layer
229 
230  //Use the t0 per layer histos to have an indication about the t0 position
231  if (nevents == eventsForLayerT0) {
232  for (map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin(); lHisto != theHistoLayerMap.end();
233  ++lHisto) {
234  if (debug)
235  edm::LogVerbatim("DTCalibration") << "Reading histogram " << (*lHisto).second->GetName() << " with mean "
236  << (*lHisto).second->GetMean() << " and RMS " << (*lHisto).second->GetRMS();
237 
238  //Take the mean as a first t0 estimation
239  if ((*lHisto).second->GetRMS() < 5.0) {
240  if (hT0SectorHisto == nullptr) {
241  hT0SectorHisto = new TH1D("hT0AllLayerOfSector",
242  "T0 from pulses per layer in sector",
243  //20, (*lHisto).second->GetMean()-100, (*lHisto).second->GetMean()+100);
244  700,
245  0,
246  7000);
247  }
248  if (debug)
249  edm::LogVerbatim("DTCalibration") << " accepted";
250  hT0SectorHisto->Fill((*lHisto).second->GetMean());
251  }
252  //Take the mean of noise + 400ns as a first t0 estimation
253  // if((*lHisto).second->GetRMS()>10.0 && ((*lHisto).second->GetRMS()<15.0)){
254  // double t0_estim = (*lHisto).second->GetMean() + 400;
255  // if(hT0SectorHisto == 0){
256  // hT0SectorHisto = new TH1D("hT0AllLayerOfSector","T0 from pulses per layer in sector",
257  // //20, t0_estim-100, t0_estim+100);
258  // 700, 0, 7000);
259  // }
260  // if(debug)
261  // edm::LogVerbatim("DTCalibration")<<" accepted + 400ns";
262  // hT0SectorHisto->Fill((*lHisto).second->GetMean() + 400);
263  // }
264  //if (debug)
265  // edm::LogVerbatim("DTCalibration");
266 
267  theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
268  theSigmaT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetRMS();
269  }
270  if (!hT0SectorHisto) {
271  edm::LogVerbatim("DTCalibration")
272  << "[DTT0CalibrationRMS]: All the t0 per layer are still uncorrect: trying with greater number of events";
274  return;
275  }
276  if (debug)
277  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] t0 reference for this sector "
278  << hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
279  }
280 }
Log< level::Info, true > LogVerbatim
std::map< DTWireId, double > theAbsoluteT0PerWire
std::map< DTWireId, double > qK
std::map< DTWireId, double > mK
std::map< DTWireId, int > nDigiPerWire
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)
Definition: FindCaloHit.cc:19
std::string theCalibSector
unsigned int eventsForWireT0
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.
unsigned int eventsForLayerT0
std::map< DTLayerId, TH1I * > theHistoLayerMap
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< DTDigiCollection > digiToken
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
int sector() const
Definition: DTChamberId.h:52
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
std::map< DTWireId, int > nDigiPerWire_ref
Definition: event.py:1

◆ endJob()

void DTT0CalibrationRMS::endJob ( void  )
overridevirtual

Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularity.

Loop on superlayer to correct between even-odd layers (2 different test pulse lines!)

Change t0 absolute reference -> from sector peak to chamber average

Write the t0 map into DB

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 282 of file DTT0CalibrationRMS.cc.

References funct::abs(), DTT0::begin(), DTSuperLayerId::chamberId(), correctByChamberMean_, DTTimeUnits::counts, debug, dtGeom, DTT0::end(), DTT0::get(), hT0SectorHisto, nDigiPerWire, qK, DTT0::set(), mathSSE::sqrt(), DTGeometry::superLayers(), FrontierCondition_GT_autoExpress_cfi::t0, theAbsoluteT0PerWire, theFile, theHistoLayerMap, theHistoWireMap, theHistoWireMap_ref, theRelativeT0PerWire, theSigmaT0PerWire, tzero, and DTCalibDBUtils::writeToDB().

Referenced by o2olib.O2ORunMgr::executeJob().

282  {
283  DTT0* t0sAbsolute = new DTT0();
284  DTT0* t0sRelative = new DTT0();
285  DTT0* t0sWRTChamber = new DTT0();
286 
287  //if(debug)
288  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMSPerLayer]Writing histos to file!";
289 
290  theFile->cd();
291  theFile->WriteTObject(hT0SectorHisto);
292  //hT0SectorHisto->Write();
293  for (map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin(); wHisto != theHistoWireMap.end();
294  ++wHisto) {
295  (*wHisto).second->Write();
296  }
297  for (map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap_ref.begin(); wHisto != theHistoWireMap_ref.end();
298  ++wHisto) {
299  (*wHisto).second->Write();
300  }
301  for (map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin(); lHisto != theHistoLayerMap.end();
302  ++lHisto) {
303  (*lHisto).second->Write();
304  }
305 
306  //if(debug)
307  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] Compute and store t0 and sigma per wire";
308 
309  for (map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
310  wiret0 != theAbsoluteT0PerWire.end();
311  ++wiret0) {
312  if (nDigiPerWire[(*wiret0).first]) {
313  double t0 = (*wiret0).second / nDigiPerWire[(*wiret0).first];
314 
315  theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
316 
317  //theSigmaT0PerWire[(*wiret0).first] = sqrt((theSigmaT0PerWire[(*wiret0).first] / nDigiPerWire[(*wiret0).first]) - t0*t0);
318  theSigmaT0PerWire[(*wiret0).first] = sqrt(qK[(*wiret0).first] / nDigiPerWire[(*wiret0).first]);
319 
320  edm::LogVerbatim("DTCalibration") << "Wire " << (*wiret0).first << " has t0 " << t0 << "(absolute) "
321  << theRelativeT0PerWire[(*wiret0).first] << "(relative)"
322  << " sigma " << theSigmaT0PerWire[(*wiret0).first];
323 
324  t0sAbsolute->set((*wiret0).first, t0, theSigmaT0PerWire[(*wiret0).first], DTTimeUnits::counts);
325  } else {
326  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] ERROR: no digis in wire " << (*wiret0).first;
327  abort();
328  }
329  }
330 
331  if (correctByChamberMean_) {
333  // Get all the sls from the setup
334  const vector<const DTSuperLayer*> superLayers = dtGeom->superLayers();
335  // Loop over all SLs
336  for (vector<const DTSuperLayer*>::const_iterator sl = superLayers.begin(); sl != superLayers.end(); sl++) {
337  //Compute mean for odd and even superlayers
338  double oddLayersMean = 0;
339  double evenLayersMean = 0;
340  double oddLayersDen = 0;
341  double evenLayersDen = 0;
342  for (map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
343  wiret0 != theRelativeT0PerWire.end();
344  ++wiret0) {
345  if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
346  if (debug)
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;
351  oddLayersDen++;
352  } else {
353  evenLayersMean = evenLayersMean + (*wiret0).second;
354  evenLayersDen++;
355  }
356  }
357  }
358  oddLayersMean = oddLayersMean / oddLayersDen;
359  evenLayersMean = evenLayersMean / evenLayersDen;
360  //if(debug && oddLayersMean)
361  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] Relative T0 mean for odd layers " << oddLayersMean
362  << " even layers" << evenLayersMean;
363 
364  //Compute sigma for odd and even superlayers
365  double oddLayersSigma = 0;
366  double evenLayersSigma = 0;
367  for (map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
368  wiret0 != theRelativeT0PerWire.end();
369  ++wiret0) {
370  if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
371  if (((*wiret0).first.layerId().layer()) % 2) {
372  oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
373  } else {
374  evenLayersSigma =
375  evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
376  }
377  }
378  }
379  oddLayersSigma = oddLayersSigma / oddLayersDen;
380  evenLayersSigma = evenLayersSigma / evenLayersDen;
381  oddLayersSigma = sqrt(oddLayersSigma);
382  evenLayersSigma = sqrt(evenLayersSigma);
383 
384  //if(debug && oddLayersMean)
385  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] Relative T0 sigma for odd layers " << oddLayersSigma
386  << " even layers" << evenLayersSigma;
387 
388  //Recompute the mean for odd and even superlayers discarding fluctations
389  double oddLayersFinalMean = 0;
390  double evenLayersFinalMean = 0;
391  for (map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
392  wiret0 != theRelativeT0PerWire.end();
393  ++wiret0) {
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;
398  } else {
399  if (abs((*wiret0).second - evenLayersMean) < (2 * evenLayersSigma))
400  evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
401  }
402  }
403  }
404  oddLayersFinalMean = oddLayersFinalMean / oddLayersDen;
405  evenLayersFinalMean = evenLayersFinalMean / evenLayersDen;
406  //if(debug && oddLayersMean)
407  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] Final relative T0 mean for odd layers "
408  << oddLayersFinalMean << " even layers" << evenLayersFinalMean;
409 
410  for (map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
411  wiret0 != theRelativeT0PerWire.end();
412  ++wiret0) {
413  if ((*wiret0).first.layerId().superlayerId() == (*sl)->id()) {
414  double t0 = -999;
415  if (((*wiret0).first.layerId().layer()) % 2)
416  t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
417  else
418  t0 = (*wiret0).second;
419 
420  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS] Wire " << (*wiret0).first << " has t0 "
421  << (*wiret0).second << " (relative, after even-odd layer corrections) "
422  << " sigma " << theSigmaT0PerWire[(*wiret0).first];
423 
424  //Store the results into DB
425  t0sRelative->set((*wiret0).first, t0, theSigmaT0PerWire[(*wiret0).first], DTTimeUnits::counts);
426  }
427  }
428  }
429 
431  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS]Computing relative t0 wrt to chamber average";
432  //Compute the reference for each chamber
433  map<DTChamberId, double> sumT0ByChamber;
434  map<DTChamberId, int> countT0ByChamber;
435  for (DTT0::const_iterator tzero = t0sRelative->begin(); tzero != t0sRelative->end(); ++tzero) {
436  int channelId = tzero->channelId;
437  if (channelId == 0)
438  continue;
439  DTWireId wireId(channelId);
440  DTChamberId chamberId(wireId.chamberId());
441  //sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + tzero->t0mean;
442  // @@@ better DTT0 usage
443  float t0mean_f;
444  float t0rms_f;
445  t0sRelative->get(wireId, t0mean_f, t0rms_f, DTTimeUnits::counts);
446  sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
447  // @@@ NEW DTT0 END
448  countT0ByChamber[chamberId]++;
449  }
450 
451  //Change reference for each wire and store the new t0s in the new map
452  for (DTT0::const_iterator tzero = t0sRelative->begin(); tzero != t0sRelative->end(); ++tzero) {
453  int channelId = tzero->channelId;
454  if (channelId == 0)
455  continue;
456  DTWireId wireId(channelId);
457  DTChamberId chamberId(wireId.chamberId());
458  //double t0mean = (tzero->t0mean) - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
459  //double t0rms = tzero->t0rms;
460  // @@@ better DTT0 usage
461  float t0mean_f;
462  float t0rms_f;
463  t0sRelative->get(wireId, t0mean_f, t0rms_f, DTTimeUnits::counts);
464  double t0mean = t0mean_f - (sumT0ByChamber[chamberId] / countT0ByChamber[chamberId]);
465  double t0rms = t0rms_f;
466  // @@@ NEW DTT0 END
467  t0sWRTChamber->set(wireId, t0mean, t0rms, DTTimeUnits::counts);
468  edm::LogVerbatim("DTCalibration") << "Changing t0 of wire " << wireId << " from " << t0mean_f << " to " << t0mean;
469  }
470  }
471 
473  if (debug)
474  edm::LogVerbatim("DTCalibration") << "[DTT0CalibrationRMS]Writing values in DB!";
475  // FIXME: to be read from cfg?
476  string t0Record = "DTT0Rcd";
477  // Write the t0 map to DB
479  DTCalibDBUtils::writeToDB(t0Record, t0sWRTChamber);
480  else
481  DTCalibDBUtils::writeToDB(t0Record, t0sAbsolute);
482 }
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
Definition: DTT0.cc:97
Log< level::Info, true > LogVerbatim
std::map< DTWireId, double > theAbsoluteT0PerWire
static void writeToDB(std::string record, const T &payload)
std::map< DTWireId, double > qK
std::map< DTWireId, int > nDigiPerWire
const_iterator end() const
Definition: DTT0.cc:147
edm::ESHandle< DTGeometry > dtGeom
std::map< DTWireId, TH1I * > theHistoWireMap
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:122
const_iterator begin() const
Definition: DTT0.cc:145
std::map< DTWireId, TH1I * > theHistoWireMap_ref
Definition: DTT0.h:48
T sqrt(T t)
Definition: SSEVec.h:23
std::map< DTLayerId, TH1I * > theHistoLayerMap
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< DTWireId, double > theSigmaT0PerWire
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:48
std::map< DTWireId, double > theRelativeT0PerWire
static const double tzero[3]
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:86

◆ getHistoName() [1/2]

string DTT0CalibrationRMS::getHistoName ( const DTWireId wId) const
private

Definition at line 484 of file DTT0CalibrationRMS.cc.

References HltBtagPostValidation_cff::histoName, DTLayerId::layer(), DTChamberId::sector(), DTChamberId::station(), DTSuperLayerId::superlayer(), to_string(), DTChamberId::wheel(), and DTWireId::wire().

Referenced by analyze().

484  {
485  string histoName = "Ch_" + std::to_string(wId.wheel()) + "_" + std::to_string(wId.station()) + "_" +
486  std::to_string(wId.sector()) + "_SL" + std::to_string(wId.superlayer()) + "_L" +
487  std::to_string(wId.layer()) + "_W" + std::to_string(wId.wire()) + "_hT0Histo";
488  return histoName;
489 }
int station() const
Return the station number.
Definition: DTChamberId.h:45
int wire() const
Return the wire number.
Definition: DTWireId.h:45
static std::string to_string(const XMLCh *ch)
int superlayer() const
Return the superlayer number (deprecated method name)
int layer() const
Return the layer number.
Definition: DTLayerId.h:45
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
int sector() const
Definition: DTChamberId.h:52

◆ getHistoName() [2/2]

string DTT0CalibrationRMS::getHistoName ( const DTLayerId lId) const
private

Definition at line 491 of file DTT0CalibrationRMS.cc.

References HltBtagPostValidation_cff::histoName, DTLayerId::layer(), DTChamberId::sector(), DTChamberId::station(), DTSuperLayerId::superlayer(), to_string(), and DTChamberId::wheel().

491  {
492  string histoName = "Ch_" + std::to_string(lId.wheel()) + "_" + std::to_string(lId.station()) + "_" +
493  std::to_string(lId.sector()) + "_SL" + std::to_string(lId.superlayer()) + "_L" +
494  std::to_string(lId.layer()) + "_hT0Histo";
495  return histoName;
496 }
int station() const
Return the station number.
Definition: DTChamberId.h:45
static std::string to_string(const XMLCh *ch)
int superlayer() const
Return the superlayer number (deprecated method name)
int layer() const
Return the layer number.
Definition: DTLayerId.h:45
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
int sector() const
Definition: DTChamberId.h:52

Member Data Documentation

◆ cellsWithHistos

std::vector<std::string> DTT0CalibrationRMS::cellsWithHistos
private

Definition at line 90 of file DTT0CalibrationRMS.h.

Referenced by DTT0CalibrationRMS().

◆ correctByChamberMean_

bool DTT0CalibrationRMS::correctByChamberMean_
private

Definition at line 75 of file DTT0CalibrationRMS.h.

Referenced by DTT0CalibrationRMS(), and endJob().

◆ debug

bool DTT0CalibrationRMS::debug
private

◆ digiToken

edm::EDGetTokenT<DTDigiCollection> DTT0CalibrationRMS::digiToken
private

Definition at line 54 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ dtGeom

edm::ESHandle<DTGeometry> DTT0CalibrationRMS::dtGeom
private

Definition at line 109 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ dtGeomToken_

const edm::ESGetToken<DTGeometry, MuonGeometryRecord> DTT0CalibrationRMS::dtGeomToken_
private

Definition at line 110 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ eventsForLayerT0

unsigned int DTT0CalibrationRMS::eventsForLayerT0
private

Definition at line 64 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ eventsForWireT0

unsigned int DTT0CalibrationRMS::eventsForWireT0
private

Definition at line 66 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ hT0SectorHisto

TH1D* DTT0CalibrationRMS::hT0SectorHisto
private

Definition at line 86 of file DTT0CalibrationRMS.h.

Referenced by analyze(), DTT0CalibrationRMS(), and endJob().

◆ mK

std::map<DTWireId, double> DTT0CalibrationRMS::mK
private

Definition at line 98 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ mK_ref

std::map<DTWireId, double> DTT0CalibrationRMS::mK_ref
private

Definition at line 99 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ nDigiPerWire

std::map<DTWireId, int> DTT0CalibrationRMS::nDigiPerWire
private

Definition at line 96 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ nDigiPerWire_ref

std::map<DTWireId, int> DTT0CalibrationRMS::nDigiPerWire_ref
private

Definition at line 97 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ nevents

unsigned int DTT0CalibrationRMS::nevents
private

Definition at line 62 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ qK

std::map<DTWireId, double> DTT0CalibrationRMS::qK
private

Definition at line 100 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ rejectDigiFromPeak

unsigned int DTT0CalibrationRMS::rejectDigiFromPeak
private

Definition at line 69 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ selSector

int DTT0CalibrationRMS::selSector
private

Definition at line 81 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ selWheel

int DTT0CalibrationRMS::selWheel
private

Definition at line 79 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ theAbsoluteT0PerWire

std::map<DTWireId, double> DTT0CalibrationRMS::theAbsoluteT0PerWire
private

Definition at line 93 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ theCalibSector

std::string DTT0CalibrationRMS::theCalibSector
private

Definition at line 80 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ theCalibWheel

std::string DTT0CalibrationRMS::theCalibWheel
private

Definition at line 78 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ theFile

TFile* DTT0CalibrationRMS::theFile
private

Definition at line 57 of file DTT0CalibrationRMS.h.

Referenced by analyze(), DTT0CalibrationRMS(), endJob(), and ~DTT0CalibrationRMS().

◆ theHistoLayerMap

std::map<DTLayerId, TH1I*> DTT0CalibrationRMS::theHistoLayerMap
private

Definition at line 84 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ theHistoWireMap

std::map<DTWireId, TH1I*> DTT0CalibrationRMS::theHistoWireMap
private

Definition at line 102 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ theHistoWireMap_ref

std::map<DTWireId, TH1I*> DTT0CalibrationRMS::theHistoWireMap_ref
private

Definition at line 103 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and endJob().

◆ theOutputFile

TFile* DTT0CalibrationRMS::theOutputFile
private

Definition at line 59 of file DTT0CalibrationRMS.h.

◆ theRelativeT0PerWire

std::map<DTWireId, double> DTT0CalibrationRMS::theRelativeT0PerWire
private

Definition at line 94 of file DTT0CalibrationRMS.h.

Referenced by endJob().

◆ theSigmaT0LayerMap

std::map<std::string, double> DTT0CalibrationRMS::theSigmaT0LayerMap
private

Definition at line 106 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ theSigmaT0PerWire

std::map<DTWireId, double> DTT0CalibrationRMS::theSigmaT0PerWire
private

Definition at line 95 of file DTT0CalibrationRMS.h.

Referenced by endJob().

◆ theT0LayerMap

std::map<std::string, double> DTT0CalibrationRMS::theT0LayerMap
private

Definition at line 105 of file DTT0CalibrationRMS.h.

Referenced by analyze().

◆ tpPeakWidth

double DTT0CalibrationRMS::tpPeakWidth
private

Definition at line 72 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().

◆ wireIdWithHistos

std::vector<DTWireId> DTT0CalibrationRMS::wireIdWithHistos
private

Definition at line 89 of file DTT0CalibrationRMS.h.

Referenced by analyze(), and DTT0CalibrationRMS().