31 cout <<
"[DTT0Calibration]Constructor called!" << endl;
38 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
41 if(theCalibWheel !=
"All") {
44 linestr << theCalibWheel;
46 cout <<
"[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
51 if(theCalibSector !=
"All") {
54 linestr << theCalibSector;
56 cout <<
"[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
59 vector<string> defaultCell;
60 defaultCell.push_back(
"None");
62 for(vector<string>::const_iterator cell = cellsWithHistos.begin(); cell != cellsWithHistos.end(); cell++){
63 if((*cell) !=
"None"){
65 int wheel,sector,
station,sl,layer,wire;
67 linestr >> wheel >> sector >> station >> sl >> layer >> wire;
68 wireIdWithHistos.push_back(
DTWireId(wheel,station,sector,sl,layer,wire));
75 eventsForLayerT0 = pset.
getParameter<
unsigned int>(
"eventsForLayerT0");
76 eventsForWireT0 = pset.
getParameter<
unsigned int>(
"eventsForWireT0");
77 rejectDigiFromPeak = pset.
getParameter<
unsigned int>(
"rejectDigiFromPeak");
80 correctByChamberMean_ = pset.
getParameter<
bool>(
"correctByChamberMean");
86 cout <<
"[DTT0Calibration]Destructor called!" << endl;
94 cout <<
"--- [DTT0Calibration] Analysing Event: #Run: " << event.
id().
run()
95 <<
" #Event: " <<
event.id().event() << endl;
107 for (dtLayerIt = digis->begin();
108 dtLayerIt != digis->end();
114 const DTLayerId layerId = (*dtLayerIt).first;
127 digi != digiRange.second;
129 double t0 = (*digi).countsTDC();
132 if(
nevents < eventsForLayerT0){
134 TH1I *hT0LayerHisto = theHistoLayerMap[layerId];
136 if(hT0LayerHisto == 0){
139 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
140 200, t0-100, t0+100);
142 cout <<
" New T0 per Layer Histo: " << hT0LayerHisto->GetName() << endl;
143 theHistoLayerMap[layerId] = hT0LayerHisto;
148 if(hT0LayerHisto != 0) {
151 hT0LayerHisto->Fill(t0);
158 const DTWireId wireId(layerId, (*digi).wire());
160 cout <<
" Wire: " << wireId << endl
161 <<
" time (TDC counts): " << (*digi).countsTDC()<< endl;
165 vector<DTWireId>::iterator it_wire =
find(wireIdWithHistos.begin(),wireIdWithHistos.end(),wireId);
166 if(it_wire != wireIdWithHistos.end()){
167 if(theHistoWireMap.find(wireId) == theHistoWireMap.end()){
168 theHistoWireMap[wireId] =
new TH1I(
getHistoName(wireId).c_str(),
"T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",7000,0,7000);
169 if(
debug)
cout <<
" New T0 per wire Histo: " << (theHistoWireMap[wireId])->GetName() << endl;
171 if(theHistoWireMap_ref.find(wireId) == theHistoWireMap_ref.end()){
172 theHistoWireMap_ref[wireId] =
new TH1I((
getHistoName(wireId) +
"_ref").c_str(),
"T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",7000,0,7000);
173 if(
debug)
cout <<
" New T0 per wire Histo: " << (theHistoWireMap_ref[wireId])->GetName() << endl;
176 TH1I* hT0WireHisto = theHistoWireMap[wireId];
179 if(hT0WireHisto) hT0WireHisto->Fill(t0);
183 if(
abs(hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin()) - t0) > rejectDigiFromPeak){
185 cout<<
"digi skipped because t0 per sector "<<hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
190 if(
nevents< (eventsForLayerT0 + eventsForWireT0)){
192 if(it_wire != wireIdWithHistos.end()){
193 TH1I* hT0WireHisto_ref = theHistoWireMap_ref[wireId];
195 if(hT0WireHisto_ref) hT0WireHisto_ref->Fill(t0);
197 if(!nDigiPerWire_ref[wireId]){
200 nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
201 mK_ref[wireId] = mK_ref[wireId] + (t0-mK_ref[wireId])/nDigiPerWire_ref[wireId];
204 else if(
nevents>(eventsForLayerT0 + eventsForWireT0)){
205 if(
abs(t0-mK_ref[wireId]) > tpPeakWidth)
207 if(!nDigiPerWire[wireId]){
208 theAbsoluteT0PerWire[wireId] = 0;
212 nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
213 theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
215 qK[wireId] = qK[wireId] + ((nDigiPerWire[wireId]-1)*(t0-mK[wireId])*(t0-mK[wireId])/nDigiPerWire[wireId]);
216 mK[wireId] = mK[wireId] + (t0-mK[wireId])/nDigiPerWire[wireId];
223 if(
nevents == eventsForLayerT0){
224 for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
225 lHisto != theHistoLayerMap.end();
228 cout<<
"Reading histogram "<<(*lHisto).second->GetName()<<
" with mean "<<(*lHisto).second->GetMean()<<
" and RMS "<<(*lHisto).second->GetRMS();
231 if((*lHisto).second->GetRMS()<5.0){
232 if(hT0SectorHisto == 0){
233 hT0SectorHisto =
new TH1D(
"hT0AllLayerOfSector",
"T0 from pulses per layer in sector",
238 cout<<
" accepted"<<endl;
239 hT0SectorHisto->Fill((*lHisto).second->GetMean());
256 theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
257 theSigmaT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetRMS();
260 cout<<
"[DTT0Calibration]: All the t0 per layer are still uncorrect: trying with greater number of events"<<endl;
261 eventsForLayerT0 = eventsForLayerT0*2;
265 cout<<
"[DTT0Calibration] t0 reference for this sector "<<
266 hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
278 cout <<
"[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
281 hT0SectorHisto->Write();
282 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin();
283 wHisto != theHistoWireMap.end();
285 (*wHisto).second->Write();
287 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap_ref.begin();
288 wHisto != theHistoWireMap_ref.end();
290 (*wHisto).second->Write();
292 for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
293 lHisto != theHistoLayerMap.end();
295 (*lHisto).second->Write();
299 cout <<
"[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
301 for(map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
302 wiret0 != theAbsoluteT0PerWire.end();
304 if(nDigiPerWire[(*wiret0).first]){
305 double t0 = (*wiret0).second/nDigiPerWire[(*wiret0).first];
307 theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
310 theSigmaT0PerWire[(*wiret0).first] =
sqrt(qK[(*wiret0).first]/nDigiPerWire[(*wiret0).first]);
312 cout <<
"Wire " << (*wiret0).first <<
" has t0 " << t0 <<
"(absolute) "
313 << theRelativeT0PerWire[(*wiret0).first] <<
"(relative)"
314 <<
" sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
319 cout<<
"[DTT0Calibration] ERROR: no digis in wire "<<(*wiret0).first<<endl;
324 if(correctByChamberMean_){
327 const vector<DTSuperLayer*> superLayers = dtGeom->superLayers();
329 for(vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
330 sl != superLayers.end(); sl++) {
334 double oddLayersMean=0;
335 double evenLayersMean=0;
336 double oddLayersDen=0;
337 double evenLayersDen=0;
338 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
339 wiret0 != theRelativeT0PerWire.end();
341 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
343 cout<<
"[DTT0Calibration] Superlayer "<<(*sl)->id()
344 <<
"layer " <<(*wiret0).first.layerId().layer()<<
" with "<<(*wiret0).second<<endl;
345 if(((*wiret0).first.layerId().layer()) % 2){
346 oddLayersMean = oddLayersMean + (*wiret0).second;
350 evenLayersMean = evenLayersMean + (*wiret0).second;
355 oddLayersMean = oddLayersMean/oddLayersDen;
356 evenLayersMean = evenLayersMean/evenLayersDen;
358 cout<<
"[DTT0Calibration] Relative T0 mean for odd layers "<<oddLayersMean<<
" even layers"<<evenLayersMean<<endl;
361 double oddLayersSigma=0;
362 double evenLayersSigma=0;
363 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
364 wiret0 != theRelativeT0PerWire.end();
366 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
367 if(((*wiret0).first.layerId().layer()) % 2){
368 oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
371 evenLayersSigma = evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
375 oddLayersSigma = oddLayersSigma/oddLayersDen;
376 evenLayersSigma = evenLayersSigma/evenLayersDen;
377 oddLayersSigma =
sqrt(oddLayersSigma);
378 evenLayersSigma =
sqrt(evenLayersSigma);
381 cout<<
"[DTT0Calibration] Relative T0 sigma for odd layers "<<oddLayersSigma<<
" even layers"<<evenLayersSigma<<endl;
384 double oddLayersFinalMean=0;
385 double evenLayersFinalMean=0;
386 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
387 wiret0 != theRelativeT0PerWire.end();
389 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
390 if(((*wiret0).first.layerId().layer()) % 2){
391 if(
abs((*wiret0).second - oddLayersMean) < (2*oddLayersSigma))
392 oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
395 if(
abs((*wiret0).second - evenLayersMean) < (2*evenLayersSigma))
396 evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
400 oddLayersFinalMean = oddLayersFinalMean/oddLayersDen;
401 evenLayersFinalMean = evenLayersFinalMean/evenLayersDen;
403 cout<<
"[DTT0Calibration] Final relative T0 mean for odd layers "<<oddLayersFinalMean<<
" even layers"<<evenLayersFinalMean<<endl;
405 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
406 wiret0 != theRelativeT0PerWire.end();
408 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
410 if(((*wiret0).first.layerId().layer()) % 2)
411 t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
413 t0 = (*wiret0).second;
415 cout <<
"[DTT0Calibration] Wire " << (*wiret0).first <<
" has t0 " << (*wiret0).second
416 <<
" (relative, after even-odd layer corrections) "
417 <<
" sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
427 cout <<
"[DTT0Calibration]Computing relative t0 wrt to chamber average" << endl;
429 map<DTChamberId,double> sumT0ByChamber;
430 map<DTChamberId,int> countT0ByChamber;
433 int channelId =
tzero->channelId;
434 if ( channelId == 0 )
continue;
442 sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
444 countT0ByChamber[chamberId]++;
450 int channelId =
tzero->channelId;
451 if ( channelId == 0 )
continue;
460 double t0mean = t0mean_f - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
461 double t0rms = t0rms_f;
463 t0sWRTChamber->
set(wireId,
469 cout <<
"Changing t0 of wire " << wireId <<
" from " << t0mean_f
470 <<
" to " << t0mean << endl;
476 cout <<
"[DTT0Calibration]Writing values in DB!" << endl;
478 string t0Record =
"DTT0Rcd";
486 stringstream theStream;
489 theStream >> histoName;
495 stringstream theStream;
498 theStream >> histoName;
const_iterator begin() const
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::string getHistoName(const DTWireId &wId) const
int layer() const
Return the layer number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
virtual ~DTT0Calibration()
Destructor.
void endJob()
Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularit...
Abs< T >::type abs(const T &t)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int wire() const
Return the wire number.
const_iterator end() const
int superlayer() const
Return the superlayer number (deprecated method name)
std::vector< DTDigi >::const_iterator const_iterator
static const double tzero[3]
std::pair< const_iterator, const_iterator > Range
int station() const
Return the station number.
DTT0Calibration(const edm::ParameterSet &pset)
Constructor.
int wheel() const
Return the wheel number.
static void writeToDB(std::string record, T *payload)
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Fill the maps with t0 (by channel)