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::EDAnalyzer 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::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () 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
 
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::vector< ModuleDescription const * > &modules, 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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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
 
std::string dbLabel
 
bool debug
 
std::string digiLabel
 
edm::ESHandle< DTGeometrydtGeom
 
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
 
unsigned int retryForLayerT0
 
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
 
TFile * theOutputFile
 
std::map< DTChamberId, double > theRefT0ByChamber
 
std::map< DTWireId, double > theRelativeT0PerWire
 
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
 
unsigned int timeBoxWidth
 
double tpPeakWidth
 
double tpPeakWidthPerLayer
 
std::vector< DTWireIdwireIdWithHistos
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
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 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)
 

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 29 of file DTT0Calibration.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 31 of file DTT0Calibration.cc.

References gather_cfg::cout, RecoTauHPSTancTauProdcuer_cfi::dbLabel, debug, CastorSimpleReconstructor_cfi::digiLabel, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), DTAnalyzerDetailed_cfi::rootFileName, relativeConstraints::station, interactiveExample::theFile, and makeMuonMisalignmentScenario::wheel.

31  {
32  // Get the debug parameter for verbose output
33  debug = pset.getUntrackedParameter<bool>("debug");
34  if(debug)
35  cout << "[DTT0Calibration]Constructor called!" << endl;
36 
37  // Get the label to retrieve digis from the event
38  digiLabel = pset.getUntrackedParameter<string>("digiLabel");
39 
40  dbLabel = pset.getUntrackedParameter<string>("dbLabel", "");
41 
42  // The root file which contain the histos per layer
43  string rootFileName = pset.getUntrackedParameter<string>("rootFileName","DTT0PerLayer.root");
44  theFile = new TFile(rootFileName.c_str(), "RECREATE");
45 
46  theCalibWheel = pset.getUntrackedParameter<string>("calibWheel", "All"); //FIXME amke a vector of integer instead of a string
47  if(theCalibWheel != "All") {
48  stringstream linestr;
49  int selWheel;
50  linestr << theCalibWheel;
51  linestr >> selWheel;
52  cout << "[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
53  }
54 
55  // Sector/s to calibrate
56  theCalibSector = pset.getUntrackedParameter<string>("calibSector", "All"); //FIXME amke a vector of integer instead of a string
57  if(theCalibSector != "All") {
58  stringstream linestr;
59  int selSector;
60  linestr << theCalibSector;
61  linestr >> selSector;
62  cout << "[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
63  }
64 
65  vector<string> defaultCell;
66  defaultCell.push_back("None");
67  cellsWithHistos = pset.getUntrackedParameter<vector<string> >("cellsWithHisto", defaultCell);
68  for(vector<string>::const_iterator cell = cellsWithHistos.begin(); cell != cellsWithHistos.end(); ++cell){
69  if((*cell) != "None"){
70  stringstream linestr;
71  int wheel,sector,station,sl,layer,wire;
72  linestr << (*cell);
73  linestr >> wheel >> sector >> station >> sl >> layer >> wire;
74  wireIdWithHistos.push_back(DTWireId(wheel,station,sector,sl,layer,wire));
75  }
76  }
77 
78  hT0SectorHisto=nullptr;
79 
80  nevents=0;
81  eventsForLayerT0 = pset.getParameter<unsigned int>("eventsForLayerT0");
82  eventsForWireT0 = pset.getParameter<unsigned int>("eventsForWireT0");
83  tpPeakWidth = pset.getParameter<double>("tpPeakWidth");
84  tpPeakWidthPerLayer = pset.getParameter<double>("tpPeakWidthPerLayer");
85  timeBoxWidth = pset.getParameter<unsigned int>("timeBoxWidth");
86  rejectDigiFromPeak = pset.getParameter<unsigned int>("rejectDigiFromPeak");
87 
88  spectrum = new TSpectrum(5);
89  retryForLayerT0 = 0;
90 }
T getParameter(std::string const &) const
double tpPeakWidthPerLayer
T getUntrackedParameter(std::string const &, T const &) const
unsigned int nevents
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
unsigned int timeBoxWidth
unsigned int eventsForLayerT0
std::string dbLabel
unsigned int rejectDigiFromPeak
std::string theCalibSector
unsigned int retryForLayerT0
std::string digiLabel
std::vector< std::string > cellsWithHistos
TSpectrum * spectrum
unsigned int eventsForWireT0
DTT0Calibration::~DTT0Calibration ( )
override

Destructor.

Definition at line 93 of file DTT0Calibration.cc.

References gather_cfg::cout, debug, and interactiveExample::theFile.

93  {
94  if(debug)
95  cout << "[DTT0Calibration]Destructor called!" << endl;
96 
97  delete spectrum;
98  theFile->Close();
99 }
TSpectrum * spectrum

Member Function Documentation

void DTT0Calibration::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
override

Fill the maps with t0 (by channel)

Perform the real analysis.

Definition at line 102 of file DTT0Calibration.cc.

References funct::abs(), stringResolutionProvider_cfi::bin, DTSuperLayerId::chamberId(), DTTimeUnits::counts, gather_cfg::cout, RecoTauHPSTancTauProdcuer_cfi::dbLabel, debug, CastorSimpleReconstructor_cfi::digiLabel, edm::EventID::event(), spr::find(), objects.autophobj::float, edm::EventSetup::get(), DTTtrig::get(), mergeVDriftHistosByStation::getHistoName(), edm::EventBase::id(), DTAnalyzerDetailed_cfi::kFactor, SiStripPI::mean, edm::EventID::run(), DTChamberId::sector(), DTLayerId::superlayerId(), cscNeutronWriter_cfi::t0, interactiveExample::theFile, and DTChamberId::wheel().

102  {
103  if(debug || event.id().event() % 500==0)
104  cout << "--- [DTT0Calibration] Analysing Event: #Run: " << event.id().run()
105  << " #Event: " << event.id().event() << endl;
106  nevents++;
107 
108  // Get the digis from the event
110  event.getByLabel(digiLabel, digis);
111 
112  // Get the DT Geometry
113  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
114 
115  // Get ttrig DB
116  edm::ESHandle<DTTtrig> tTrigMap;
117  eventSetup.get<DTTtrigRcd>().get(dbLabel,tTrigMap);
118 
119  // Iterate through all digi collections ordered by LayerId
121  for (dtLayerIt = digis->begin();
122  dtLayerIt != digis->end();
123  ++dtLayerIt){
124  // Get the iterators over the digis associated with this LayerId
125  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
126 
127  // Get the layerId
128  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
129  const DTChamberId chamberId = layerId.superlayerId().chamberId();
130 
131  if((theCalibWheel != "All") && (layerId.superlayerId().chamberId().wheel() != selWheel))
132  continue;
133  if((theCalibSector != "All") && (layerId.superlayerId().chamberId().sector() != selSector))
134  continue;
135 
136  //if(debug) {
137  // cout << "Layer " << layerId<<" with "<<distance(digiRange.first, digiRange.second)<<" digi"<<endl;
138  //}
139 
140  float tTrig,tTrigRMS, kFactor;
141  tTrigMap->get(layerId.superlayerId(), tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
142  if(debug&&(nevents <= 1)){
143  cout << " Superlayer: " << layerId.superlayerId() << endl
144  << " tTrig,tTrigRMS= " << tTrig << ", " << tTrigRMS << endl;
145  }
146 
147  // Loop over all digis in the given layer
148  for (DTDigiCollection::const_iterator digi = digiRange.first;
149  digi != digiRange.second;
150  ++digi) {
151  double t0 = (*digi).countsTDC();
152 
153  //Use first bunch of events to fill t0 per layer
155  //Get the per-layer histo from the map
156  TH1I *hT0LayerHisto = theHistoLayerMap[layerId];
157  //If it doesn't exist, book it
158  if(hT0LayerHisto == nullptr){
159  theFile->cd();
160  float hT0Min = tTrig - 2*tTrigRMS;
161  float hT0Max = hT0Min + timeBoxWidth;
162  hT0LayerHisto = new TH1I(getHistoName(layerId).c_str(),
163  "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
164  timeBoxWidth,hT0Min,hT0Max);
165  if(debug)
166  cout << " New T0 per Layer Histo: " << hT0LayerHisto->GetName() << endl;
167  theHistoLayerMap[layerId] = hT0LayerHisto;
168  }
169 
170  //Fill the histos
171  theFile->cd();
172  if(hT0LayerHisto != nullptr) {
173  // if(debug)
174  // cout<<"Filling histo "<<hT0LayerHisto->GetName()<<" with digi "<<t0<<" TDC counts"<<endl;
175  hT0LayerHisto->Fill(t0);
176  }
177  }
178 
179  //Use all the remaining events to compute t0 per wire
181  // Get the wireId
182  const DTWireId wireId(layerId, (*digi).wire());
183  if(debug) {
184  cout << " Wire: " << wireId << endl
185  << " time (TDC counts): " << (*digi).countsTDC()<< endl;
186  }
187 
188  //Fill the histos per wire for the chosen cells
189  vector<DTWireId>::iterator it = find(wireIdWithHistos.begin(),wireIdWithHistos.end(),wireId);
190  if (it!=wireIdWithHistos.end()){
191  //Get the per-wire histo from the map
192  TH1I *hT0WireHisto = theHistoWireMap[wireId];
193  //If it doesn't exist, book it
194  if(hT0WireHisto == nullptr){
195  theFile->cd();
196  hT0WireHisto = new TH1I(getHistoName(wireId).c_str(),"T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",7000,0,7000);
197  //hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())-100,
198  //hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())+100);
199  if(debug)
200  cout << " New T0 per wire Histo: " << hT0WireHisto->GetName() << endl;
201  theHistoWireMap[wireId] = hT0WireHisto;
202  }
203  //Fill the histos
204  theFile->cd();
205  if(hT0WireHisto != nullptr) {
206  //if(debug)
207  // cout<<"Filling histo "<<hT0WireHisto->GetName()<<" with digi "<<t0<<" TDC counts"<<endl;
208  hT0WireHisto->Fill(t0);
209  }
210  }
211 
212  //Check the tzero has reasonable value
213  //float hT0Min = tTrig - 2*tTrigRMS;
214  //float hT0Max = hT0Min + timeBoxWidth;
215  /*if(abs(hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin()) - t0) > rejectDigiFromPeak){
216  if(debug)
217  cout<<"digi skipped because t0 per sector "<<hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
218  continue;
219  }*/
220  /*if((t0 < hT0Min)||(t0 > hT0Max)){
221  if(debug)
222  cout<<"digi skipped because t0 outside of interval (" << hT0Min << "," << hT0Max << ")" <<endl;
223  continue;
224  }*/
225  //Select per layer
226  if(fabs(theTPPeakMap[layerId] - t0) > rejectDigiFromPeak){
227  if(debug)
228  cout<<"digi skipped because t0 too far from peak " << theTPPeakMap[layerId] << endl;
229  continue;
230  }
231 
232  //Find to ref. per chamber
233  theSumT0ByChamber[chamberId] = theSumT0ByChamber[chamberId] + t0;
234  theCountT0ByChamber[chamberId]++;
235 
236  //Use second bunch of events to compute a t0 reference per wire
238  if(!nDigiPerWire_ref[wireId]){
239  mK_ref[wireId] = 0;
240  }
241  nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
242  mK_ref[wireId] = mK_ref[wireId] + (t0-mK_ref[wireId])/nDigiPerWire_ref[wireId];
243  }
244  //Use last all the remaining events to compute the mean and sigma t0 per wire
246  if(abs(t0-mK_ref[wireId]) > tpPeakWidth)
247  continue;
248  if(!nDigiPerWire[wireId]){
249  theAbsoluteT0PerWire[wireId] = 0;
250  qK[wireId] = 0;
251  mK[wireId] = 0;
252  }
253  nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
254  theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
255  //theSigmaT0PerWire[wireId] = theSigmaT0PerWire[wireId] + (t0*t0);
256  qK[wireId] = qK[wireId] + ((nDigiPerWire[wireId]-1)*(t0-mK[wireId])*(t0-mK[wireId])/nDigiPerWire[wireId]);
257  mK[wireId] = mK[wireId] + (t0-mK[wireId])/nDigiPerWire[wireId];
258  }
259  }//end if(nevents>1000)
260  }//end loop on digi
261  }//end loop on layer
262 
263  //Use the t0 per layer histos to have an indication about the t0 position
264  if(nevents == eventsForLayerT0){
265  bool increaseEvtsForLayerT0 = false;
266  for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
267  lHisto != theHistoLayerMap.end();
268  ++lHisto){
269  if(debug)
270  cout<<"Reading histogram "<<(*lHisto).second->GetName()<<" with mean "<<(*lHisto).second->GetMean()<<" and RMS "<<(*lHisto).second->GetRMS() << endl;
271 
272  //Find peaks
273  //int npeaks = spectrum->Search((*lHisto).second,0.5,"goff");
274  //int npeaks = spectrum->Search((*lHisto).second,(tpPeakWidthPerLayer/2.),"goff",0.3);
275  int npeaks = spectrum->Search((*lHisto).second,(tpPeakWidthPerLayer/2.),"",0.3);
276 
277  double *peaks = spectrum->GetPositionX();
278  //Put in a std::vector<float>
279  vector<double> peakMeans(peaks,peaks + npeaks);
280  //Sort the peaks in ascending order
281  sort(peakMeans.begin(),peakMeans.end());
282 
283  //Find best peak -- preliminary criteria: find peak closest to center of time box
284  float tTrig,tTrigRMS, kFactor;
285  tTrigMap->get((*lHisto).first.superlayerId(), tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
286 
287  double timeBoxCenter = (2*tTrig + (float)timeBoxWidth)/2.;
288  double hMin = (*lHisto).second->GetXaxis()->GetXmin();
289  double hMax = (*lHisto).second->GetXaxis()->GetXmax();
290  vector<double>::const_iterator tpPeak = peakMeans.end();
291  for(vector<double>::const_iterator it = peakMeans.begin(); it != peakMeans.end(); ++it){
292  double mean = *it;
293 
294  int bin = (*lHisto).second->GetXaxis()->FindBin(mean);
295  double yp = (*lHisto).second->GetBinContent(bin);
296  if(debug) cout << "Peak : (" << mean << "," << yp << ")" << endl;
297 
298  //Find RMS
299  double previous_peak = (it == peakMeans.begin())?hMin:*(it - 1);
300  double next_peak = (it == (peakMeans.end()-1))?hMax:*(it + 1);
301 
302  double rangemin = mean - (mean - previous_peak)/8.;
303  double rangemax = mean + (next_peak - mean)/8.;
304  int binmin = (*lHisto).second->GetXaxis()->FindBin(rangemin);
305  int binmax = (*lHisto).second->GetXaxis()->FindBin(rangemax);
306  (*lHisto).second->GetXaxis()->SetRange(binmin,binmax);
307  //RMS estimate
308  double rms_seed = (*lHisto).second->GetRMS();
309 
310  /*rangemin = mean - 2*rms_seed;
311  rangemax = mean + 2*rms_seed;
312  if(debug) cout << "Seed for RMS, Fit min, Fit max: " << rms_seed << ", " << rangemin << ", " << rangemax << endl;
313  //Fit to gaussian
314  string funcname("fitFcn_");
315  funcname += (*lHisto).second->GetName();
316  if(debug) cout << "Fitting function " << funcname << endl;
317  TF1* func = new TF1(funcname.c_str(),"gaus",rangemin,rangemax);
318  func->SetParameters(yp,mean,rms_seed);
319  (*lHisto).second->Fit(func,"Q","",rangemin,rangemax);
320  float fitconst = func->GetParameter(0);
321  float fitmean = func->GetParameter(1);
322  float fitrms = func->GetParameter(2);
323  float chisquare = func->GetChisquare()/func->GetNDF();
324  if(debug) cout << "Gaussian fit constant,mean,RMS,chi2= " << fitconst << ", " << fitmean << ", " << fitrms << ", " << chisquare << endl;*/
325 
326  //Reject peaks with RMS larger than specified
327  //if(fitrms > tpPeakWidth) continue;
328  if(rms_seed > tpPeakWidthPerLayer) continue;
329 
330  if(fabs(mean - timeBoxCenter) < fabs(*tpPeak - timeBoxCenter)) tpPeak = it;
331  }
332  //Didn't find peak
333  /*if(tpPeak == peakMeans.end()){
334  if(retryForLayerT0 < 2){
335  increaseEvtsForLayerT0 = true;
336  retryForLayerT0++;
337  break;
338  }
339  }*/
340 
341  double selPeak = (tpPeak != peakMeans.end())?*tpPeak:(*lHisto).second->GetBinCenter((*lHisto).second->GetMaximumBin());
342  if(debug) cout << "Peak selected at " << selPeak << endl;
343 
344  theTPPeakMap[(*lHisto).first] = selPeak;
345 
346  //Take the mean as a first t0 estimation
347  /*if((*lHisto).second->GetRMS() < tpPeakWidth){
348  if(hT0SectorHisto == 0){
349  hT0SectorHisto = new TH1D("hT0AllLayerOfSector","T0 from pulses per layer in sector",
350  //20, (*lHisto).second->GetMean()-100, (*lHisto).second->GetMean()+100);
351  700, 0, 7000);
352  //300,3300,3600);
353  }
354  if(debug)
355  cout<<" accepted"<<endl;
356  //TH1I* aux_histo = (*lHisto).second;
357  //aux_histo->GetXaxis()->SetRangeUser(3300,3600);
358  hT0SectorHisto->Fill((*lHisto).second->GetMean());
359  //hT0SectorHisto->Fill(aux_histo->GetMean());
360  }
361  //Take the mean of noise + 400ns as a first t0 estimation
362  //if((*lHisto).second->GetRMS()>10.0 && ((*lHisto).second->GetRMS()<15.0)){
363  //double t0_estim = (*lHisto).second->GetMean() + 400;
364  //if(hT0SectorHisto == 0){
365  // hT0SectorHisto = new TH1D("hT0AllLayerOfSector","T0 from pulses per layer in sector",
366  // //20, t0_estim-100, t0_estim+100);
367  // 700, 0, 7000);
368  //}
369  //if(debug)
370  // cout<<" accepted + 400ns"<<endl;
371  //hT0SectorHisto->Fill((*lHisto).second->GetMean() + 400);
372  //}
373  if(debug)
374  cout<<endl;
375  theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
376  theSigmaT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetRMS();*/
377  }
378  /*if(!hT0SectorHisto){
379  cout<<"[DTT0Calibration]: All the t0 per layer are still uncorrect: trying with greater number of events"<<endl;
380  eventsForLayerT0 = eventsForLayerT0*2;
381  return;
382  }
383  if(debug)
384  cout<<"[DTT0Calibration] t0 reference for this sector "<<
385  hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;*/
386  if(increaseEvtsForLayerT0){
387  cout<<"[DTT0Calibration]: t0 per layer are still uncorrect: trying with greater number of events"<<endl;
389  return;
390  }
391  }
392 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
double tpPeakWidthPerLayer
std::map< DTLayerId, TH1I * > theHistoLayerMap
unsigned int nevents
std::map< DTWireId, double > theAbsoluteT0PerWire
std::map< DTWireId, TH1I * > theHistoWireMap
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::map< DTLayerId, double > theTPPeakMap
std::map< DTWireId, int > nDigiPerWire
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
unsigned int timeBoxWidth
std::map< DTChamberId, int > theCountT0ByChamber
std::string getHistoName(const DTWireId &wId) const
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
edm::ESHandle< DTGeometry > dtGeom
std::map< DTWireId, double > mK
unsigned int eventsForLayerT0
std::string dbLabel
unsigned int rejectDigiFromPeak
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string theCalibSector
std::map< DTWireId, double > qK
std::map< DTWireId, double > mK_ref
bin
set the eta bin as selection string.
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:85
std::string digiLabel
const T & get() const
Definition: EventSetup.h:59
std::vector< DTDigi >::const_iterator const_iterator
TSpectrum * spectrum
edm::EventID id() const
Definition: EventBase.h:60
std::map< DTChamberId, double > theSumT0ByChamber
int sector() const
Definition: DTChamberId.h:61
std::pair< const_iterator, const_iterator > Range
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
unsigned int eventsForWireT0
std::map< DTWireId, int > nDigiPerWire_ref
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.

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::EDAnalyzer.

Definition at line 394 of file DTT0Calibration.cc.

References funct::abs(), DTT0::begin(), relativeConstraints::chamber, DTSuperLayerId::chamberId(), DTTimeUnits::counts, gather_cfg::cout, debug, DTT0::end(), DTT0::get(), DTT0::set(), mathSSE::sqrt(), cscNeutronWriter_cfi::t0, interactiveExample::theFile, tzero, and DTCalibDBUtils::writeToDB().

Referenced by o2olib.O2ORunMgr::executeJob().

394  {
395 
396  DTT0* t0s = new DTT0();
397  DTT0* t0sWRTChamber = new DTT0();
398 
399  if(debug)
400  cout << "[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
401 
402  theFile->cd();
403  //hT0SectorHisto->Write();
404  for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin();
405  wHisto != theHistoWireMap.end();
406  ++wHisto) {
407  (*wHisto).second->Write();
408  }
409  for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
410  lHisto != theHistoLayerMap.end();
411  ++lHisto) {
412  (*lHisto).second->Write();
413  }
414 
415  if(debug)
416  cout << "[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
417 
418  for(map<DTChamberId,double>::const_iterator chamber = theSumT0ByChamber.begin();
419  chamber != theSumT0ByChamber.end();
420  ++chamber) theRefT0ByChamber[(*chamber).first] = theSumT0ByChamber[(*chamber).first]/((double)theCountT0ByChamber[(*chamber).first]);
421 
422  for(map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
423  wiret0 != theAbsoluteT0PerWire.end();
424  ++wiret0){
425  if(nDigiPerWire[(*wiret0).first]){
426  double t0 = (*wiret0).second/nDigiPerWire[(*wiret0).first];
427  DTChamberId chamberId = ((*wiret0).first).chamberId();
428  //theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
429  theRelativeT0PerWire[(*wiret0).first] = t0 - theRefT0ByChamber[chamberId];
430  cout<<"Wire "<<(*wiret0).first<<" has t0 "<<t0<<"(absolute) "<<theRelativeT0PerWire[(*wiret0).first]<<"(relative)";
431 
432  //theSigmaT0PerWire[(*wiret0).first] = sqrt((theSigmaT0PerWire[(*wiret0).first] / nDigiPerWire[(*wiret0).first]) - t0*t0);
433  theSigmaT0PerWire[(*wiret0).first] = sqrt(qK[(*wiret0).first]/nDigiPerWire[(*wiret0).first]);
434  cout<<" sigma "<<theSigmaT0PerWire[(*wiret0).first]<<endl;
435  }
436  else{
437  cout<<"[DTT0CalibrationNew] ERROR: no digis in wire "<<(*wiret0).first<<endl;
438  abort();
439  }
440  }
441 
443  // Get all the sls from the setup
444  const vector<const DTSuperLayer*> superLayers = dtGeom->superLayers();
445  // Loop over all SLs
446  for(vector<const DTSuperLayer*>::const_iterator sl = superLayers.begin();
447  sl != superLayers.end(); sl++) {
448 
449 
450  //Compute mean for odd and even superlayers
451  double oddLayersMean=0;
452  double evenLayersMean=0;
453  double oddLayersDen=0;
454  double evenLayersDen=0;
455  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
456  wiret0 != theRelativeT0PerWire.end();
457  ++wiret0){
458  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
459  if(debug)
460  cout<<"[DTT0Calibration] Superlayer "<<(*sl)->id()
461  <<"layer " <<(*wiret0).first.layerId().layer()<<" with "<<(*wiret0).second<<endl;
462  if(((*wiret0).first.layerId().layer()) % 2){
463  oddLayersMean = oddLayersMean + (*wiret0).second;
464  oddLayersDen++;
465  }
466  else{
467  evenLayersMean = evenLayersMean + (*wiret0).second;
468  evenLayersDen++;
469  }
470  }
471  }
472  oddLayersMean = oddLayersMean/oddLayersDen;
473  evenLayersMean = evenLayersMean/evenLayersDen;
474  if(debug && oddLayersMean)
475  cout<<"[DTT0Calibration] Relative T0 mean for odd layers "<<oddLayersMean<<" even layers"<<evenLayersMean<<endl;
476 
477  //Compute sigma for odd and even superlayers
478  double oddLayersSigma=0;
479  double evenLayersSigma=0;
480  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
481  wiret0 != theRelativeT0PerWire.end();
482  ++wiret0){
483  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
484  if(((*wiret0).first.layerId().layer()) % 2){
485  oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
486  }
487  else{
488  evenLayersSigma = evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
489  }
490  }
491  }
492  oddLayersSigma = oddLayersSigma/oddLayersDen;
493  evenLayersSigma = evenLayersSigma/evenLayersDen;
494  oddLayersSigma = sqrt(oddLayersSigma);
495  evenLayersSigma = sqrt(evenLayersSigma);
496 
497  if(debug && oddLayersMean)
498  cout<<"[DTT0Calibration] Relative T0 sigma for odd layers "<<oddLayersSigma<<" even layers"<<evenLayersSigma<<endl;
499 
500  //Recompute the mean for odd and even superlayers discarding fluctations
501  double oddLayersFinalMean=0;
502  double evenLayersFinalMean=0;
503  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
504  wiret0 != theRelativeT0PerWire.end();
505  ++wiret0){
506  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
507  if(((*wiret0).first.layerId().layer()) % 2){
508  if(abs((*wiret0).second - oddLayersMean) < (2*oddLayersSigma))
509  oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
510  }
511  else{
512  if(abs((*wiret0).second - evenLayersMean) < (2*evenLayersSigma))
513  evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
514  }
515  }
516  }
517  oddLayersFinalMean = oddLayersFinalMean/oddLayersDen;
518  evenLayersFinalMean = evenLayersFinalMean/evenLayersDen;
519  if(debug && oddLayersMean)
520  cout<<"[DTT0Calibration] Final relative T0 mean for odd layers "<<oddLayersFinalMean<<" even layers"<<evenLayersFinalMean<<endl;
521 
522  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
523  wiret0 != theRelativeT0PerWire.end();
524  ++wiret0){
525  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
526  double t0=-999;
527  if(((*wiret0).first.layerId().layer()) % 2)
528  t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
529  else
530  t0 = (*wiret0).second;
531 
532  cout<<"[DTT0Calibration] Wire "<<(*wiret0).first<<" has t0 "<<(*wiret0).second<<" (relative, after even-odd layer corrections) "
533  <<" sigma "<<theSigmaT0PerWire[(*wiret0).first]<<endl;
534  //Store the results into DB
535  t0s->set((*wiret0).first, t0, theSigmaT0PerWire[(*wiret0).first],DTTimeUnits::counts);
536  }
537  }
538  }
539 
541  if(debug)
542  cout << "[DTT0Calibration]Computing relative t0 wrt to chamber average" << endl;
543  //Compute the reference for each chamber
544  map<DTChamberId,double> sumT0ByChamber;
545  map<DTChamberId,int> countT0ByChamber;
546  for(DTT0::const_iterator tzero = t0s->begin();
547  tzero != t0s->end(); ++tzero) {
548 // @@@ NEW DTT0 FORMAT
549 // DTChamberId chamberId((*tzero).first.wheelId,
550 // (*tzero).first.stationId,
551 // (*tzero).first.sectorId);
552 // sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + (*tzero).second.t0mean;
553  int channelId = tzero->channelId;
554  if ( channelId == 0 ) continue;
555  DTWireId wireId(channelId);
556  DTChamberId chamberId(wireId.chamberId());
557  //sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + tzero->t0mean;
558 // @@@ better DTT0 usage
559  float t0mean_f;
560  float t0rms_f;
561  t0s->get(wireId,t0mean_f,t0rms_f,DTTimeUnits::counts);
562  sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
563 // @@@ NEW DTT0 END
564  countT0ByChamber[chamberId]++;
565  }
566 
567  //Change reference for each wire and store the new t0s in the new map
568  for(DTT0::const_iterator tzero = t0s->begin();
569  tzero != t0s->end(); ++tzero) {
570 // @@@ NEW DTT0 FORMAT
571 // DTChamberId chamberId((*tzero).first.wheelId,
572 // (*tzero).first.stationId,
573 // (*tzero).first.sectorId);
574 // double t0mean = ((*tzero).second.t0mean) - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
575 // double t0rms = (*tzero).second.t0rms;
576 // DTWireId wireId((*tzero).first.wheelId,
577 // (*tzero).first.stationId,
578 // (*tzero).first.sectorId,
579 // (*tzero).first.slId,
580 // (*tzero).first.layerId,
581 // (*tzero).first.cellId);
582  int channelId = tzero->channelId;
583  if ( channelId == 0 ) continue;
584  DTWireId wireId( channelId );
585  DTChamberId chamberId(wireId.chamberId());
586  //double t0mean = (tzero->t0mean) - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
587  //double t0rms = tzero->t0rms;
588 // @@@ better DTT0 usage
589  float t0mean_f;
590  float t0rms_f;
591  t0s->get(wireId,t0mean_f,t0rms_f,DTTimeUnits::counts);
592  double t0mean = t0mean_f - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
593  double t0rms = t0rms_f;
594 // @@@ NEW DTT0 END
595  t0sWRTChamber->set(wireId,
596  t0mean,
597  t0rms,
599  if(debug){
600  //cout<<"Chamber "<<chamberId<<" has reference "<<(sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
601 // cout<<"Changing t0 of wire "<<wireId<<" from "<<(*tzero).second.t0mean<<" to "<<t0mean<<endl;
602  cout<<"Changing t0 of wire "<<wireId<<" from "<<tzero->t0mean<<" to "<<t0mean<<endl;
603  }
604  }
605 
607  if(debug)
608  cout << "[DTT0Calibration]Writing values in DB!" << endl;
609  // FIXME: to be read from cfg?
610  string t0Record = "DTT0Rcd";
611  // Write the t0 map to DB
612  DTCalibDBUtils::writeToDB(t0Record, t0sWRTChamber);
613 }
const_iterator begin() const
Definition: DTT0.cc:204
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
Definition: DTT0.cc:140
std::map< DTLayerId, TH1I * > theHistoLayerMap
std::map< DTWireId, double > theAbsoluteT0PerWire
std::map< DTWireId, TH1I * > theHistoWireMap
std::map< DTChamberId, double > theRefT0ByChamber
std::map< DTWireId, int > nDigiPerWire
std::map< DTChamberId, int > theCountT0ByChamber
std::map< DTWireId, double > theSigmaT0PerWire
edm::ESHandle< DTGeometry > dtGeom
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:67
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:140
Definition: DTT0.h:53
std::map< DTWireId, double > theRelativeT0PerWire
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< DTWireId, double > qK
const_iterator end() const
Definition: DTT0.cc:209
std::map< DTChamberId, double > theSumT0ByChamber
static const double tzero[3]
static void writeToDB(std::string record, T *payload)
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:89
string DTT0Calibration::getHistoName ( const DTWireId wId) const
private

Definition at line 615 of file DTT0Calibration.cc.

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

615  {
616  string histoName;
617  stringstream theStream;
618  theStream << "Ch_" << wId.wheel() << "_" << wId.station() << "_" << wId.sector()
619  << "_SL" << wId.superlayer() << "_L" << wId.layer() << "_W"<< wId.wire() <<"_hT0Histo";
620  theStream >> histoName;
621  return histoName;
622 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
int wire() const
Return the wire number.
Definition: DTWireId.h:56
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
string DTT0Calibration::getHistoName ( const DTLayerId lId) const
private

Definition at line 624 of file DTT0Calibration.cc.

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

624  {
625  string histoName;
626  stringstream theStream;
627  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
628  << "_SL" << lId.superlayer() << "_L" << lId.layer() <<"_hT0Histo";
629  theStream >> histoName;
630  return histoName;
631 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45

Member Data Documentation

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

Definition at line 102 of file DTT0Calibration.h.

std::string DTT0Calibration::dbLabel
private

Definition at line 59 of file DTT0Calibration.h.

bool DTT0Calibration::debug
private
std::string DTT0Calibration::digiLabel
private

Definition at line 57 of file DTT0Calibration.h.

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

Definition at line 125 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForLayerT0
private

Definition at line 69 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForWireT0
private

Definition at line 71 of file DTT0Calibration.h.

TH1D* DTT0Calibration::hT0SectorHisto
private

Definition at line 96 of file DTT0Calibration.h.

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

Definition at line 110 of file DTT0Calibration.h.

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

Definition at line 111 of file DTT0Calibration.h.

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

Definition at line 108 of file DTT0Calibration.h.

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

Definition at line 109 of file DTT0Calibration.h.

unsigned int DTT0Calibration::nevents
private

Definition at line 67 of file DTT0Calibration.h.

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

Definition at line 112 of file DTT0Calibration.h.

unsigned int DTT0Calibration::rejectDigiFromPeak
private

Definition at line 83 of file DTT0Calibration.h.

unsigned int DTT0Calibration::retryForLayerT0
private

Definition at line 85 of file DTT0Calibration.h.

int DTT0Calibration::selSector
private

Definition at line 91 of file DTT0Calibration.h.

int DTT0Calibration::selWheel
private

Definition at line 89 of file DTT0Calibration.h.

TSpectrum* DTT0Calibration::spectrum
private

Definition at line 98 of file DTT0Calibration.h.

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

Definition at line 105 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibSector
private

Definition at line 90 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibWheel
private

Definition at line 88 of file DTT0Calibration.h.

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

Definition at line 121 of file DTT0Calibration.h.

TFile* DTT0Calibration::theFile
private

Definition at line 62 of file DTT0Calibration.h.

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

Definition at line 94 of file DTT0Calibration.h.

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

Definition at line 114 of file DTT0Calibration.h.

TFile* DTT0Calibration::theOutputFile
private

Definition at line 64 of file DTT0Calibration.h.

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

Definition at line 122 of file DTT0Calibration.h.

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

Definition at line 106 of file DTT0Calibration.h.

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

Definition at line 117 of file DTT0Calibration.h.

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

Definition at line 107 of file DTT0Calibration.h.

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

Definition at line 120 of file DTT0Calibration.h.

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

Definition at line 116 of file DTT0Calibration.h.

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

Definition at line 118 of file DTT0Calibration.h.

unsigned int DTT0Calibration::timeBoxWidth
private

Definition at line 80 of file DTT0Calibration.h.

double DTT0Calibration::tpPeakWidth
private

Definition at line 74 of file DTT0Calibration.h.

double DTT0Calibration::tpPeakWidthPerLayer
private

Definition at line 77 of file DTT0Calibration.h.

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

Definition at line 101 of file DTT0Calibration.h.