33 cout <<
"[DTT0Calibration]Constructor called!" << endl;
40 theFile =
new TFile(rootFileName.c_str(),
"RECREATE");
43 if(theCalibWheel !=
"All") {
46 linestr << theCalibWheel;
48 cout <<
"[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
53 if(theCalibSector !=
"All") {
56 linestr << theCalibSector;
58 cout <<
"[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
61 vector<string> defaultCell;
62 defaultCell.push_back(
"None");
64 for(vector<string>::const_iterator cell = cellsWithHistos.begin(); cell != cellsWithHistos.end(); cell++){
65 if((*cell) !=
"None"){
67 int wheel,sector,
station,sl,layer,wire;
69 linestr >> wheel >> sector >> station >> sl >> layer >> wire;
70 wireIdWithHistos.push_back(
DTWireId(wheel,station,sector,sl,layer,wire));
77 eventsForLayerT0 = pset.
getParameter<
unsigned int>(
"eventsForLayerT0");
78 eventsForWireT0 = pset.
getParameter<
unsigned int>(
"eventsForWireT0");
79 rejectDigiFromPeak = pset.
getParameter<
unsigned int>(
"rejectDigiFromPeak");
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;
277 cout <<
"[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
280 hT0SectorHisto->Write();
281 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin();
282 wHisto != theHistoWireMap.end();
284 (*wHisto).second->Write();
286 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap_ref.begin();
287 wHisto != theHistoWireMap_ref.end();
289 (*wHisto).second->Write();
291 for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
292 lHisto != theHistoLayerMap.end();
294 (*lHisto).second->Write();
298 cout <<
"[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
300 for(map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
301 wiret0 != theAbsoluteT0PerWire.end();
303 if(nDigiPerWire[(*wiret0).first]){
304 double t0 = (*wiret0).second/nDigiPerWire[(*wiret0).first];
305 theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
306 cout<<
"Wire "<<(*wiret0).first<<
" has t0 "<<t0<<
"(absolute) "<<theRelativeT0PerWire[(*wiret0).first]<<
"(relative)";
309 theSigmaT0PerWire[(*wiret0).first] =
sqrt(qK[(*wiret0).first]/nDigiPerWire[(*wiret0).first]);
310 cout<<
" sigma "<<theSigmaT0PerWire[(*wiret0).first]<<endl;
313 cout<<
"[DTT0Calibration] ERROR: no digis in wire "<<(*wiret0).first<<endl;
320 const vector<DTSuperLayer*> superLayers = dtGeom->superLayers();
322 for(vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
323 sl != superLayers.end(); sl++) {
327 double oddLayersMean=0;
328 double evenLayersMean=0;
329 double oddLayersDen=0;
330 double evenLayersDen=0;
331 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
332 wiret0 != theRelativeT0PerWire.end();
334 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
336 cout<<
"[DTT0Calibration] Superlayer "<<(*sl)->id()
337 <<
"layer " <<(*wiret0).first.layerId().layer()<<
" with "<<(*wiret0).second<<endl;
338 if(((*wiret0).first.layerId().layer()) % 2){
339 oddLayersMean = oddLayersMean + (*wiret0).second;
343 evenLayersMean = evenLayersMean + (*wiret0).second;
348 oddLayersMean = oddLayersMean/oddLayersDen;
349 evenLayersMean = evenLayersMean/evenLayersDen;
350 if(
debug && oddLayersMean)
351 cout<<
"[DTT0Calibration] Relative T0 mean for odd layers "<<oddLayersMean<<
" even layers"<<evenLayersMean<<endl;
354 double oddLayersSigma=0;
355 double evenLayersSigma=0;
356 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
357 wiret0 != theRelativeT0PerWire.end();
359 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
360 if(((*wiret0).first.layerId().layer()) % 2){
361 oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
364 evenLayersSigma = evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
368 oddLayersSigma = oddLayersSigma/oddLayersDen;
369 evenLayersSigma = evenLayersSigma/evenLayersDen;
370 oddLayersSigma =
sqrt(oddLayersSigma);
371 evenLayersSigma =
sqrt(evenLayersSigma);
373 if(
debug && oddLayersMean)
374 cout<<
"[DTT0Calibration] Relative T0 sigma for odd layers "<<oddLayersSigma<<
" even layers"<<evenLayersSigma<<endl;
377 double oddLayersFinalMean=0;
378 double evenLayersFinalMean=0;
379 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
380 wiret0 != theRelativeT0PerWire.end();
382 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
383 if(((*wiret0).first.layerId().layer()) % 2){
384 if(
abs((*wiret0).second - oddLayersMean) < (2*oddLayersSigma))
385 oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
388 if(
abs((*wiret0).second - evenLayersMean) < (2*evenLayersSigma))
389 evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
393 oddLayersFinalMean = oddLayersFinalMean/oddLayersDen;
394 evenLayersFinalMean = evenLayersFinalMean/evenLayersDen;
395 if(
debug && oddLayersMean)
396 cout<<
"[DTT0Calibration] Final relative T0 mean for odd layers "<<oddLayersFinalMean<<
" even layers"<<evenLayersFinalMean<<endl;
398 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
399 wiret0 != theRelativeT0PerWire.end();
401 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
403 if(((*wiret0).first.layerId().layer()) % 2)
404 t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
406 t0 = (*wiret0).second;
408 cout<<
"[DTT0Calibration] Wire "<<(*wiret0).first<<
" has t0 "<<(*wiret0).second<<
" (relative, after even-odd layer corrections) "
409 <<
" sigma "<<theSigmaT0PerWire[(*wiret0).first]<<endl;
418 cout <<
"[DTT0Calibration]Computing relative t0 wrt to chamber average" << endl;
420 map<DTChamberId,double> sumT0ByChamber;
421 map<DTChamberId,int> countT0ByChamber;
429 int channelId =
tzero->channelId;
430 if ( channelId == 0 )
continue;
433 sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] +
tzero->t0mean;
438 sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
440 countT0ByChamber[chamberId]++;
458 int channelId =
tzero->channelId;
459 if ( channelId == 0 )
continue;
462 double t0mean = (
tzero->t0mean) - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
463 double t0rms =
tzero->t0rms;
468 t0mean = t0mean_f - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
471 t0sWRTChamber->
set(wireId,
478 cout<<
"Changing t0 of wire "<<wireId<<
" from "<<
tzero->t0mean<<
" to "<<t0mean<<endl;
484 cout <<
"[DTT0Calibration]Writing values in DB!" << endl;
486 string t0Record =
"DTT0Rcd";
493 stringstream theStream;
496 theStream >> histoName;
502 stringstream theStream;
505 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...
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< DigiType >::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)