CMS 3D CMS Logo

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

#include <DTT0Calibration.h>

Inheritance diagram for DTT0Calibration:
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...
 
 DTT0Calibration (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...
 
 ~DTT0Calibration () 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 final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const 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
 
bool wantsStreamRuns () const
 
 ~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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
bool registeredToConsumeMany (TypeID const &, 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::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

bool debug
 
edm::EDGetTokenT< DTDigiCollectiondigiToken
 
edm::ESHandle< DTGeometrydtGeom
 
const edm::ESGetToken< DTGeometry, MuonGeometryRecorddtGeomToken_
 
unsigned int eventsForLayerT0
 
unsigned int eventsForWireT0
 
TH1D hLayerPeaks
 
std::vector< DTLayerIdlayerIdWithWireHistos
 
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
 
TSpectrum spectrum
 
std::map< DTWireId, double > theAbsoluteT0PerWire
 
std::string theCalibSector
 
std::string theCalibWheel
 
std::map< DTChamberId, int > theCountT0ByChamber
 
TFile theFile
 
std::map< DTLayerId, TH1I > theHistoLayerMap
 
std::map< DTWireId, TH1I > theHistoWireMap
 
std::map< DTChamberId, double > theMeanT0ByChamber
 
std::map< DTChamberId, double > theRefT0ByChamber
 
std::map< DTWireId, double > theRelativeT0PerWire
 
std::map< DTChamberId, double > theSigmaT0ByChamber
 
std::map< std::string, double > theSigmaT0LayerMap
 
std::map< DTWireId, double > theSigmaT0PerWire
 
std::map< DTChamberId, double > theSumT0ByChamber
 
std::map< std::string, double > theT0LayerMap
 
std::map< DTLayerId, double > theTPPeakMap
 
double tpPeakWidth
 
double tpPeakWidthPerLayer
 
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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
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

Author
S. Bolognesi - INFN Torino

Definition at line 36 of file DTT0Calibration.h.

Constructor & Destructor Documentation

◆ DTT0Calibration()

DTT0Calibration::DTT0Calibration ( const edm::ParameterSet pset)

Constructor.

Definition at line 34 of file DTT0Calibration.cc.

References gather_cfg::cout, debug, phase1PixelTopology::layer, muonDTDigis_cfi::pset, selSector, selWheel, relativeConstraints::station, theCalibSector, theCalibWheel, makeMuonMisalignmentScenario::wheel, and wireIdWithHistos.

35  : debug(pset.getUntrackedParameter<bool>("debug")),
36  digiToken(consumes<DTDigiCollection>(pset.getUntrackedParameter<string>("digiLabel"))),
37  theFile(pset.getUntrackedParameter<string>("rootFileName", "DTT0PerLayer.root").c_str(), "RECREATE"),
38  nevents(0),
39  eventsForLayerT0(pset.getParameter<unsigned int>("eventsForLayerT0")),
40  eventsForWireT0(pset.getParameter<unsigned int>("eventsForWireT0")),
41  tpPeakWidth(pset.getParameter<double>("tpPeakWidth")),
42  tpPeakWidthPerLayer(pset.getParameter<double>("tpPeakWidthPerLayer")),
43  rejectDigiFromPeak(pset.getParameter<unsigned int>("rejectDigiFromPeak")),
44  hLayerPeaks("hLayerPeaks", "", 3000, 0, 3000),
45  spectrum(20),
47  // Get the debug parameter for verbose output
48  if (debug)
49  cout << "[DTT0Calibration]Constructor called!" << endl;
50 
52  pset.getUntrackedParameter<string>("calibWheel", "All"); //FIXME amke a vector of integer instead of a string
53  if (theCalibWheel != "All") {
54  stringstream linestr;
55  int selWheel;
56  linestr << theCalibWheel;
57  linestr >> selWheel;
58  cout << "[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
59  }
60 
61  // Sector/s to calibrate
63  pset.getUntrackedParameter<string>("calibSector", "All"); //FIXME amke a vector of integer instead of a string
64  if (theCalibSector != "All") {
65  stringstream linestr;
66  int selSector;
67  linestr << theCalibSector;
68  linestr >> selSector;
69  cout << "[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
70  }
71 
72  vector<string> defaultCell;
73  const auto& cellsWithHistos = pset.getUntrackedParameter<vector<string> >("cellsWithHisto", defaultCell);
74  for (const auto& cell : cellsWithHistos) {
75  stringstream linestr;
76  int wheel, sector, station, sl, layer, wire;
77  linestr << cell;
78  linestr >> wheel >> sector >> station >> sl >> layer >> wire;
79  wireIdWithHistos.push_back(DTWireId(wheel, station, sector, sl, layer, wire));
80  }
81 }
double tpPeakWidthPerLayer
unsigned int nevents
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
unsigned int eventsForLayerT0
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned int rejectDigiFromPeak
std::string theCalibSector
edm::EDGetTokenT< DTDigiCollection > digiToken
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
TSpectrum spectrum
unsigned int eventsForWireT0

◆ ~DTT0Calibration()

DTT0Calibration::~DTT0Calibration ( )
override

Destructor.

Definition at line 84 of file DTT0Calibration.cc.

References gather_cfg::cout, debug, and theFile.

84  {
85  if (debug)
86  cout << "[DTT0Calibration]Destructor called!" << endl;
87 
88  theFile.Close();
89 }

Member Function Documentation

◆ analyze()

void DTT0Calibration::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 92 of file DTT0Calibration.cc.

References funct::abs(), DTSuperLayerId::chamberId(), gather_cfg::cout, debug, digiToken, dtGeom, dtGeomToken_, options_cfi::eventSetup, eventsForLayerT0, eventsForWireT0, spr::find(), getHistoName(), gpuVertexFinder::hist, hLayerPeaks, layerIdWithWireHistos, mK, mK_ref, nDigiPerWire, nDigiPerWire_ref, nevents, or, qK, rejectDigiFromPeak, DTChamberId::sector(), selSector, selWheel, jetUpdater_cfi::sort, spectrum, DTLayerId::superlayerId(), FrontierCondition_GT_autoExpress_cfi::t0, theAbsoluteT0PerWire, theCalibSector, theCalibWheel, theHistoLayerMap, theHistoWireMap, theTPPeakMap, tpPeakWidth, tpPeakWidthPerLayer, DTChamberId::wheel(), and wireIdWithHistos.

92  {
93  nevents++;
94 
95  // Get the digis from the event
97  event.getByToken(digiToken, digis);
98 
99  // Get the DT Geometry
100  if (nevents == 1)
101  dtGeom = eventSetup.getHandle(dtGeomToken_);
102 
103  // Iterate through all digi collections ordered by LayerId
104  for (const auto& digis_per_layer : *digis) {
105  //std::cout << __LINE__ << std::endl;
106  // Get the iterators over the digis associated with this LayerId
107  const DTDigiCollection::Range& digiRange = digis_per_layer.second;
108 
109  // Get the layerId
110  const DTLayerId layerId = digis_per_layer.first;
111  //const DTChamberId chamberId = layerId.superlayerId().chamberId();
112 
113  if ((theCalibWheel != "All") && (layerId.superlayerId().chamberId().wheel() != selWheel))
114  continue;
115  if ((theCalibSector != "All") && (layerId.superlayerId().chamberId().sector() != selSector))
116  continue;
117 
118  // Loop over all digis in the given layer
119  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; ++digi) {
120  const double t0 = digi->countsTDC();
121  const DTWireId wireIdtmp(layerId, (*digi).wire());
122 
123  // Use first bunch of events to fill t0 per layer
124  if (nevents <= eventsForLayerT0) {
125  // If it doesn't exist, book it
126  if (not theHistoLayerMap.count(layerId)) {
127  theHistoLayerMap[layerId] = TH1I(getHistoName(layerId).c_str(),
128  "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
129  3000,
130  0,
131  3000);
132  if (debug)
133  cout << " New T0 per Layer Histo: " << theHistoLayerMap[layerId].GetName() << endl;
134  }
135  theHistoLayerMap[layerId].Fill(t0);
136  }
137 
138  // Use all the remaining events to compute t0 per wire
139  if (nevents > eventsForLayerT0) {
140  // Get the wireId
141  const DTWireId wireId(layerId, (*digi).wire());
142  if (debug) {
143  cout << " Wire: " << wireId << endl << " time (TDC counts): " << (*digi).countsTDC() << endl;
144  }
145 
146  //Fill the histos per wire for the chosen cells
147  if (std::find(layerIdWithWireHistos.begin(), layerIdWithWireHistos.end(), layerId) !=
149  std::find(wireIdWithHistos.begin(), wireIdWithHistos.end(), wireId) != wireIdWithHistos.end()) {
150  //If it doesn't exist, book it
151  if (theHistoWireMap.count(wireId) == 0) {
152  theHistoWireMap[wireId] = TH1I(getHistoName(wireId).c_str(),
153  "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
154  7000,
155  0,
156  7000);
157  if (debug)
158  cout << " New T0 per wire Histo: " << theHistoWireMap[wireId].GetName() << endl;
159  }
160  theHistoWireMap[wireId].Fill(t0);
161  }
162 
163  //Select per layer
164  if (fabs(theTPPeakMap[layerId] - t0) > rejectDigiFromPeak) {
165  if (debug)
166  cout << "digi skipped because t0 too far from peak " << theTPPeakMap[layerId] << endl;
167  continue;
168  }
169 
170  //Use second bunch of events to compute a t0 reference per wire
172  if (!nDigiPerWire_ref[wireId]) {
173  mK_ref[wireId] = 0;
174  }
175  nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
176  mK_ref[wireId] = mK_ref[wireId] + (t0 - mK_ref[wireId]) / nDigiPerWire_ref[wireId];
177  }
178  //Use last all the remaining events to compute the mean and sigma t0 per wire
179  else if (nevents > (eventsForLayerT0 + eventsForWireT0)) {
180  if (abs(t0 - mK_ref[wireId]) > tpPeakWidth)
181  continue;
182  if (!nDigiPerWire[wireId]) {
183  theAbsoluteT0PerWire[wireId] = 0;
184  qK[wireId] = 0;
185  mK[wireId] = 0;
186  }
187  nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
188  theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
189  qK[wireId] =
190  qK[wireId] + ((nDigiPerWire[wireId] - 1) * (t0 - mK[wireId]) * (t0 - mK[wireId]) / nDigiPerWire[wireId]);
191  mK[wireId] = mK[wireId] + (t0 - mK[wireId]) / nDigiPerWire[wireId];
192  }
193  } //end if(nevents>1000)
194  } //end loop on digi
195  } //end loop on layer
196 
197  //Use the t0 per layer histos to have an indication about the t0 position
198  if (nevents == eventsForLayerT0) {
199  for (const auto& lHisto : theHistoLayerMap) {
200  const auto& layerId = lHisto.first;
201  const auto& hist = lHisto.second;
202  if (debug)
203  cout << "Reading histogram " << hist.GetName() << " with mean " << hist.GetMean() << " and RMS "
204  << hist.GetRMS() << endl;
205 
206  //Find peaks
207  int npeaks = spectrum.Search(&hist, (tpPeakWidthPerLayer / 2.), "", 0.3);
208 
209  double* peaks = spectrum.GetPositionX();
210  //Put in a std::vector<float>
211  vector<double> peakMeans(peaks, peaks + npeaks);
212  //Sort the peaks in ascending order
213  sort(peakMeans.begin(), peakMeans.end());
214 
215  if (peakMeans.empty()) {
216  theTPPeakMap[layerId] = hist.GetMaximumBin();
217  std::cout << "No peaks found by peakfinder in layer " << layerId << ". Taking maximum bin at "
218  << theTPPeakMap[layerId] << ". Please check!" << std::endl;
219  layerIdWithWireHistos.push_back(layerId);
220  } else if (fabs(hist.GetXaxis()->FindBin(peakMeans.front()) - hist.GetXaxis()->FindBin(peakMeans.back())) <
222  theTPPeakMap[layerId] = peakMeans[peakMeans.size() / 2];
223  } else {
224  bool peak_set = false;
225  for (const auto& peak : peakMeans) {
226  // Skip if at low edge
227  if (peak - tpPeakWidthPerLayer <= 0)
228  continue;
229  // Get integral of peak
230  double sum = 0;
231  for (int ibin = peak - tpPeakWidthPerLayer; ibin < peak + tpPeakWidthPerLayer; ibin++) {
232  sum += hist.GetBinContent(ibin);
233  }
234  // Skip if peak too small
235  if (sum < hist.GetMaximum() / 2)
236  continue;
237 
238  // Passed all cuts
239  theTPPeakMap[layerId] = peak;
240  peak_set = true;
241  break;
242  }
243  if (peak_set) {
244  std::cout << "Peaks to far away from each other in layer " << layerId
245  << ". Maybe cross talk? Taking first good peak at " << theTPPeakMap[layerId] << ". Please check!"
246  << std::endl;
247  layerIdWithWireHistos.push_back(layerId);
248  } else {
249  theTPPeakMap[layerId] = hist.GetMaximumBin();
250  std::cout << "Peaks to far away from each other in layer " << layerId
251  << " and no good peak found. Taking maximum bin at " << theTPPeakMap[layerId] << ". Please check!"
252  << std::endl;
253  layerIdWithWireHistos.push_back(layerId);
254  }
255  }
256  if (peakMeans.size() > 5) {
257  std::cout << "Found more than 5 peaks in layer " << layerId << ". Please check!" << std::endl;
258  if (std::find(layerIdWithWireHistos.begin(), layerIdWithWireHistos.end(), layerId) ==
259  layerIdWithWireHistos.end())
260  layerIdWithWireHistos.push_back(layerId);
261  }
262  // Check for noise
263  int nspikes = 0;
264  for (int ibin = 0; ibin < hist.GetNbinsX(); ibin++) {
265  if (hist.GetBinContent(ibin + 1) > hist.GetMaximum() * 0.001)
266  nspikes++;
267  }
268  if (nspikes > 50) {
269  std::cout << "Found a lot of (>50) small spikes in layer " << layerId
270  << ". Please check if all wires are functioning as expected!" << std::endl;
271  if (std::find(layerIdWithWireHistos.begin(), layerIdWithWireHistos.end(), layerId) ==
272  layerIdWithWireHistos.end())
273  layerIdWithWireHistos.push_back(layerId);
274  }
275  hLayerPeaks.Fill(theTPPeakMap[layerId]);
276  }
277  }
278 }
std::vector< DTLayerId > layerIdWithWireHistos
double tpPeakWidthPerLayer
std::map< DTLayerId, TH1I > theHistoLayerMap
std::map< DTWireId, double > theAbsoluteT0PerWire
unsigned int nevents
std::string getHistoName(const DTWireId &wId) const
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
std::map< DTWireId, double > mK_ref
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::ESHandle< DTGeometry > dtGeom
unsigned int eventsForLayerT0
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::map< DTLayerId, double > theTPPeakMap
unsigned int rejectDigiFromPeak
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string theCalibSector
edm::EDGetTokenT< DTDigiCollection > digiToken
__shared__ Hist hist
std::map< DTWireId, int > nDigiPerWire
std::map< DTWireId, double > mK
std::map< DTWireId, int > nDigiPerWire_ref
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
int sector() const
Definition: DTChamberId.h:49
std::map< DTWireId, double > qK
std::map< DTWireId, TH1I > theHistoWireMap
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
TSpectrum spectrum
unsigned int eventsForWireT0

◆ endJob()

void DTT0Calibration::endJob ( void  )
overridevirtual

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

Write the t0 map into DB

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 280 of file DTT0Calibration.cc.

References funct::abs(), DTTimeUnits::counts, gather_cfg::cout, debug, dtGeom, first, hLayerPeaks, phase1PixelTopology::layer, SiStripPI::mean, compareTotals::means, nDigiPerWire, nevents, funct::pow(), qK, edm::second(), DTT0::set(), mathSSE::sqrt(), DTGeometry::superLayers(), FrontierCondition_GT_autoExpress_cfi::t0, theAbsoluteT0PerWire, theFile, theHistoLayerMap, theHistoWireMap, theRelativeT0PerWire, theSigmaT0PerWire, relativeConstraints::value, contentValuesCheck::values, and DTCalibDBUtils::writeToDB().

Referenced by o2olib.O2ORunMgr::executeJob().

280  {
281  std::cout << "Analyzed " << nevents << " events" << std::endl;
282 
283  DTT0* t0sWRTChamber = new DTT0();
284 
285  if (debug)
286  cout << "[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
287 
288  theFile.cd();
289  //hT0SectorHisto->Write();
290  hLayerPeaks.Write();
291  for (const auto& wHisto : theHistoWireMap) {
292  wHisto.second.Write();
293  }
294  for (const auto& lHisto : theHistoLayerMap) {
295  lHisto.second.Write();
296  }
297 
298  if (debug)
299  cout << "[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
300 
301  // Calculate uncertainties per wire (counting experiment)
302  for (auto& wiret0 : theAbsoluteT0PerWire) {
303  auto& wireId = wiret0.first;
304  if (nDigiPerWire[wireId] > 1)
305  theSigmaT0PerWire[wireId] = qK[wireId] / (nDigiPerWire[wireId] - 1);
306  else
307  theSigmaT0PerWire[wireId] = 999.; // Only one measurement: uncertainty -> infinity
308  // syst uncert
309  //theSigmaT0PerWire[wireId] += pow(0.5, 2));
310  // Every time the same measurement. Use Laplace estimator as estimation how propable it is to measure another value due to limited size of sample
311  if (theSigmaT0PerWire[wireId] == 0) {
312  theSigmaT0PerWire[wireId] += pow(1. / (nDigiPerWire[wireId] + 1), 2);
313  }
314  }
315 
316  // function to calculate unweighted means
317  auto unweighted_mean_function = [](const std::list<double>& values, const std::list<double>& sigmas) {
318  double mean = 0;
319  for (auto& value : values) {
320  mean += value;
321  }
322  mean /= values.size();
323 
324  double uncertainty = 0;
325  for (auto& value : values) {
326  uncertainty += pow(value - mean, 2);
327  }
328  uncertainty /= values.size();
329  uncertainty = sqrt(uncertainty);
330  return std::make_pair(mean, uncertainty);
331  };
332 
333  // correct for odd-even effect in each super layer
334  std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_even;
335  std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_odd;
336  for (const auto& superlayer : dtGeom->superLayers()) {
337  const auto superlayer_id = superlayer->id();
338  std::list<double> values_even;
339  std::list<double> sigmas_even;
340  std::list<double> values_odd;
341  std::list<double> sigmas_odd;
342 
343  for (const auto& wiret0 : theAbsoluteT0PerWire) {
344  const auto& wireId = wiret0.first;
345  if (wireId.layerId().superlayerId() == superlayer_id) {
346  const auto& t0 = wiret0.second / nDigiPerWire[wireId];
347  if (wireId.layerId().layer() % 2) {
348  values_odd.push_back(t0);
349  sigmas_odd.push_back(sqrt(theSigmaT0PerWire[wireId]));
350  } else {
351  values_even.push_back(t0);
352  sigmas_even.push_back(sqrt(theSigmaT0PerWire[wireId]));
353  }
354  }
355  }
356  // get mean and uncertainty
357  mean_sigma_even.emplace(superlayer_id, unweighted_mean_function(values_even, sigmas_even));
358  mean_sigma_odd.emplace(superlayer_id, unweighted_mean_function(values_odd, sigmas_odd));
359  }
360 
361  // filter outliers
362  for (const auto& superlayer : dtGeom->superLayers()) {
363  const auto superlayer_id = superlayer->id();
364  std::list<double> values_even;
365  std::list<double> sigmas_even;
366  std::list<double> values_odd;
367  std::list<double> sigmas_odd;
368 
369  for (const auto& wiret0 : theAbsoluteT0PerWire) {
370  const auto& wireId = wiret0.first;
371  if (wireId.layerId().superlayerId() == superlayer_id) {
372  const auto& t0 = wiret0.second / nDigiPerWire[wireId];
373  if (wireId.layerId().layer() % 2 and
374  abs(t0 - mean_sigma_odd[superlayer_id].first) < 2 * mean_sigma_odd[superlayer_id].second) {
375  values_odd.push_back(t0);
376  sigmas_odd.push_back(sqrt(theSigmaT0PerWire[wireId]));
377  } else {
378  if (abs(t0 - mean_sigma_even[superlayer_id].first) < 2 * mean_sigma_even[superlayer_id].second) {
379  values_even.push_back(t0);
380  sigmas_even.push_back(sqrt(theSigmaT0PerWire[wireId]));
381  }
382  }
383  }
384  }
385  // get mean and uncertainty
386  mean_sigma_even[superlayer_id] = unweighted_mean_function(values_even, sigmas_even);
387  mean_sigma_odd[superlayer_id] = unweighted_mean_function(values_odd, sigmas_odd);
388  }
389 
390  // apply correction
391  for (auto& wiret0 : theAbsoluteT0PerWire) {
392  const auto& wire_id = wiret0.first;
393  const auto& superlayer_id = wiret0.first.layerId().superlayerId();
394  const auto& layer = wiret0.first.layerId().layer();
395  auto& t0 = wiret0.second;
396  t0 /= nDigiPerWire[wire_id];
397  if (not layer % 2)
398  continue;
399  // t0 is reference. Changing it changes the map
400  t0 += mean_sigma_even[superlayer_id].first - mean_sigma_odd[superlayer_id].first;
401  theSigmaT0PerWire[wire_id] +=
402  pow(mean_sigma_odd[superlayer_id].second, 2) + pow(mean_sigma_even[superlayer_id].second, 2);
403  }
404 
405  // get chamber mean
406  std::map<DTChamberId, std::list<double> > values_per_chamber;
407  std::map<DTChamberId, std::list<double> > sigmas_per_chamber;
408  for (const auto& wire_t0 : theAbsoluteT0PerWire) {
409  const auto& wire_id = wire_t0.first;
410  const auto& chamber_id = wire_id.chamberId();
411  const auto& t0 = wire_t0.second;
412  values_per_chamber[chamber_id].push_back(t0);
413  sigmas_per_chamber[chamber_id].push_back(sqrt(theSigmaT0PerWire[wire_id]));
414  }
415 
416  std::map<DTChamberId, std::pair<double, double> > mean_per_chamber;
417  for (const auto& chamber_mean : values_per_chamber) {
418  const auto& chamber_id = chamber_mean.first;
419  const auto& means = chamber_mean.second;
420  const auto& sigmas = sigmas_per_chamber[chamber_id];
421  mean_per_chamber.emplace(chamber_id, unweighted_mean_function(means, sigmas));
422  }
423 
424  // calculate relative values
425  for (const auto& wire_t0 : theAbsoluteT0PerWire) {
426  const auto& wire_id = wire_t0.first;
427  const auto& chamber_id = wire_id.chamberId();
428  const auto& t0 = wire_t0.second;
429  theRelativeT0PerWire.emplace(wire_id, t0 - mean_per_chamber[chamber_id].first);
430  cout << "[DTT0Calibration] Wire " << wire_id << " has t0 " << theRelativeT0PerWire[wire_id]
431  << " (relative, after even-odd layer corrections) "
432  << " sigma " << sqrt(theSigmaT0PerWire[wire_id]) << endl;
433  }
434 
435  for (const auto& wire_t0 : theRelativeT0PerWire) {
436  const auto& wire_id = wire_t0.first;
437  const auto& t0 = wire_t0.second;
438  t0sWRTChamber->set(wire_id, t0, sqrt(theSigmaT0PerWire[wire_id]), DTTimeUnits::counts);
439  }
440 
442  if (debug)
443  cout << "[DTT0Calibration]Writing values in DB!" << endl;
444  // FIXME: to be read from cfg?
445  string t0Record = "DTT0Rcd";
446  // Write the t0 map to DB
447  DTCalibDBUtils::writeToDB(t0Record, t0sWRTChamber);
448  delete t0sWRTChamber;
449 }
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
std::map< DTLayerId, TH1I > theHistoLayerMap
std::map< DTWireId, double > theAbsoluteT0PerWire
static void writeToDB(std::string record, const T &payload)
unsigned int nevents
edm::ESHandle< DTGeometry > dtGeom
constexpr std::array< uint8_t, layerIndexSize > layer
U second(std::pair< T, U > const &p)
Definition: DTT0.h:48
std::map< DTWireId, double > theSigmaT0PerWire
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
std::map< DTWireId, int > nDigiPerWire
std::map< DTWireId, double > theRelativeT0PerWire
std::map< DTWireId, double > qK
std::map< DTWireId, TH1I > theHistoWireMap
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:86

◆ getHistoName() [1/2]

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

Definition at line 451 of file DTT0Calibration.cc.

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

Referenced by analyze().

451  {
452  string histoName;
453  stringstream theStream;
454  theStream << "Ch_" << wId.wheel() << "_" << wId.station() << "_" << wId.sector() << "_SL" << wId.superlayer() << "_L"
455  << wId.layer() << "_W" << wId.wire() << "_hT0Histo";
456  theStream >> histoName;
457  return histoName;
458 }
int station() const
Return the station number.
Definition: DTChamberId.h:42
int wire() const
Return the wire number.
Definition: DTWireId.h:42
int superlayer() const
Return the superlayer number (deprecated method name)
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
int sector() const
Definition: DTChamberId.h:49

◆ getHistoName() [2/2]

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

Definition at line 460 of file DTT0Calibration.cc.

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

460  {
461  string histoName;
462  stringstream theStream;
463  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector() << "_SL" << lId.superlayer() << "_L"
464  << lId.layer() << "_hT0Histo";
465  theStream >> histoName;
466  return histoName;
467 }
int station() const
Return the station number.
Definition: DTChamberId.h:42
int superlayer() const
Return the superlayer number (deprecated method name)
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
int sector() const
Definition: DTChamberId.h:49

Member Data Documentation

◆ debug

bool DTT0Calibration::debug
private

◆ digiToken

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

Definition at line 62 of file DTT0Calibration.h.

Referenced by analyze().

◆ dtGeom

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

Definition at line 124 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ dtGeomToken_

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

Definition at line 125 of file DTT0Calibration.h.

Referenced by analyze().

◆ eventsForLayerT0

unsigned int DTT0Calibration::eventsForLayerT0
private

Definition at line 70 of file DTT0Calibration.h.

Referenced by analyze().

◆ eventsForWireT0

unsigned int DTT0Calibration::eventsForWireT0
private

Definition at line 72 of file DTT0Calibration.h.

Referenced by analyze().

◆ hLayerPeaks

TH1D DTT0Calibration::hLayerPeaks
private

Definition at line 93 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ layerIdWithWireHistos

std::vector<DTLayerId> DTT0Calibration::layerIdWithWireHistos
private

Definition at line 99 of file DTT0Calibration.h.

Referenced by analyze().

◆ mK

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

Definition at line 107 of file DTT0Calibration.h.

Referenced by analyze().

◆ mK_ref

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

Definition at line 108 of file DTT0Calibration.h.

Referenced by analyze().

◆ nDigiPerWire

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

Definition at line 105 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ nDigiPerWire_ref

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

Definition at line 106 of file DTT0Calibration.h.

Referenced by analyze().

◆ nevents

unsigned int DTT0Calibration::nevents
private

Definition at line 68 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ qK

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

Definition at line 109 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ rejectDigiFromPeak

unsigned int DTT0Calibration::rejectDigiFromPeak
private

Definition at line 81 of file DTT0Calibration.h.

Referenced by analyze().

◆ selSector

int DTT0Calibration::selSector
private

Definition at line 87 of file DTT0Calibration.h.

Referenced by analyze(), and DTT0Calibration().

◆ selWheel

int DTT0Calibration::selWheel
private

Definition at line 85 of file DTT0Calibration.h.

Referenced by analyze(), and DTT0Calibration().

◆ spectrum

TSpectrum DTT0Calibration::spectrum
private

Definition at line 95 of file DTT0Calibration.h.

Referenced by analyze().

◆ theAbsoluteT0PerWire

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

Definition at line 102 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ theCalibSector

std::string DTT0Calibration::theCalibSector
private

Definition at line 86 of file DTT0Calibration.h.

Referenced by analyze(), and DTT0Calibration().

◆ theCalibWheel

std::string DTT0Calibration::theCalibWheel
private

Definition at line 84 of file DTT0Calibration.h.

Referenced by analyze(), and DTT0Calibration().

◆ theCountT0ByChamber

std::map<DTChamberId, int> DTT0Calibration::theCountT0ByChamber
private

Definition at line 118 of file DTT0Calibration.h.

◆ theFile

TFile DTT0Calibration::theFile
private

Definition at line 65 of file DTT0Calibration.h.

Referenced by endJob(), and ~DTT0Calibration().

◆ theHistoLayerMap

std::map<DTLayerId, TH1I> DTT0Calibration::theHistoLayerMap
private

Definition at line 90 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ theHistoWireMap

std::map<DTWireId, TH1I> DTT0Calibration::theHistoWireMap
private

Definition at line 111 of file DTT0Calibration.h.

Referenced by analyze(), and endJob().

◆ theMeanT0ByChamber

std::map<DTChamberId, double> DTT0Calibration::theMeanT0ByChamber
private

Definition at line 120 of file DTT0Calibration.h.

◆ theRefT0ByChamber

std::map<DTChamberId, double> DTT0Calibration::theRefT0ByChamber
private

Definition at line 121 of file DTT0Calibration.h.

◆ theRelativeT0PerWire

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

Definition at line 103 of file DTT0Calibration.h.

Referenced by endJob().

◆ theSigmaT0ByChamber

std::map<DTChamberId, double> DTT0Calibration::theSigmaT0ByChamber
private

Definition at line 119 of file DTT0Calibration.h.

◆ theSigmaT0LayerMap

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

Definition at line 114 of file DTT0Calibration.h.

◆ theSigmaT0PerWire

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

Definition at line 104 of file DTT0Calibration.h.

Referenced by endJob().

◆ theSumT0ByChamber

std::map<DTChamberId, double> DTT0Calibration::theSumT0ByChamber
private

Definition at line 117 of file DTT0Calibration.h.

◆ theT0LayerMap

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

Definition at line 113 of file DTT0Calibration.h.

◆ theTPPeakMap

std::map<DTLayerId, double> DTT0Calibration::theTPPeakMap
private

Definition at line 115 of file DTT0Calibration.h.

Referenced by analyze().

◆ tpPeakWidth

double DTT0Calibration::tpPeakWidth
private

Definition at line 75 of file DTT0Calibration.h.

Referenced by analyze().

◆ tpPeakWidthPerLayer

double DTT0Calibration::tpPeakWidthPerLayer
private

Definition at line 78 of file DTT0Calibration.h.

Referenced by analyze().

◆ wireIdWithHistos

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

Definition at line 98 of file DTT0Calibration.h.

Referenced by analyze(), and DTT0Calibration().