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");
82 correctByChamberMean_ = pset.
getParameter<
bool>(
"correctByChamberMean");
88 cout <<
"[DTT0Calibration]Destructor called!" << endl;
96 cout <<
"--- [DTT0Calibration] Analysing Event: #Run: " << event.
id().
run()
97 <<
" #Event: " <<
event.id().event() << endl;
109 for (dtLayerIt = digis->begin();
110 dtLayerIt != digis->end();
116 const DTLayerId layerId = (*dtLayerIt).first;
129 digi != digiRange.second;
131 double t0 = (*digi).countsTDC();
134 if(
nevents < eventsForLayerT0){
136 TH1I *hT0LayerHisto = theHistoLayerMap[layerId];
138 if(hT0LayerHisto == 0){
141 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
142 200, t0-100, t0+100);
144 cout <<
" New T0 per Layer Histo: " << hT0LayerHisto->GetName() << endl;
145 theHistoLayerMap[layerId] = hT0LayerHisto;
150 if(hT0LayerHisto != 0) {
153 hT0LayerHisto->Fill(t0);
160 const DTWireId wireId(layerId, (*digi).wire());
162 cout <<
" Wire: " << wireId << endl
163 <<
" time (TDC counts): " << (*digi).countsTDC()<< endl;
167 vector<DTWireId>::iterator it_wire =
find(wireIdWithHistos.begin(),wireIdWithHistos.end(),wireId);
168 if(it_wire != wireIdWithHistos.end()){
169 if(theHistoWireMap.find(wireId) == theHistoWireMap.end()){
170 theHistoWireMap[wireId] =
new TH1I(
getHistoName(wireId).c_str(),
"T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",7000,0,7000);
171 if(
debug)
cout <<
" New T0 per wire Histo: " << (theHistoWireMap[wireId])->GetName() << endl;
173 if(theHistoWireMap_ref.find(wireId) == theHistoWireMap_ref.end()){
174 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);
175 if(
debug)
cout <<
" New T0 per wire Histo: " << (theHistoWireMap_ref[wireId])->GetName() << endl;
178 TH1I* hT0WireHisto = theHistoWireMap[wireId];
181 if(hT0WireHisto) hT0WireHisto->Fill(t0);
185 if(
abs(hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin()) - t0) > rejectDigiFromPeak){
187 cout<<
"digi skipped because t0 per sector "<<hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
192 if(
nevents< (eventsForLayerT0 + eventsForWireT0)){
194 if(it_wire != wireIdWithHistos.end()){
195 TH1I* hT0WireHisto_ref = theHistoWireMap_ref[wireId];
197 if(hT0WireHisto_ref) hT0WireHisto_ref->Fill(t0);
199 if(!nDigiPerWire_ref[wireId]){
202 nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
203 mK_ref[wireId] = mK_ref[wireId] + (t0-mK_ref[wireId])/nDigiPerWire_ref[wireId];
206 else if(
nevents>(eventsForLayerT0 + eventsForWireT0)){
207 if(
abs(t0-mK_ref[wireId]) > tpPeakWidth)
209 if(!nDigiPerWire[wireId]){
210 theAbsoluteT0PerWire[wireId] = 0;
214 nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
215 theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
217 qK[wireId] = qK[wireId] + ((nDigiPerWire[wireId]-1)*(t0-mK[wireId])*(t0-mK[wireId])/nDigiPerWire[wireId]);
218 mK[wireId] = mK[wireId] + (t0-mK[wireId])/nDigiPerWire[wireId];
225 if(
nevents == eventsForLayerT0){
226 for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
227 lHisto != theHistoLayerMap.end();
230 cout<<
"Reading histogram "<<(*lHisto).second->GetName()<<
" with mean "<<(*lHisto).second->GetMean()<<
" and RMS "<<(*lHisto).second->GetRMS();
233 if((*lHisto).second->GetRMS()<5.0){
234 if(hT0SectorHisto == 0){
235 hT0SectorHisto =
new TH1D(
"hT0AllLayerOfSector",
"T0 from pulses per layer in sector",
240 cout<<
" accepted"<<endl;
241 hT0SectorHisto->Fill((*lHisto).second->GetMean());
258 theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
259 theSigmaT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetRMS();
262 cout<<
"[DTT0Calibration]: All the t0 per layer are still uncorrect: trying with greater number of events"<<endl;
263 eventsForLayerT0 = eventsForLayerT0*2;
267 cout<<
"[DTT0Calibration] t0 reference for this sector "<<
268 hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
280 cout <<
"[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
283 hT0SectorHisto->Write();
284 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin();
285 wHisto != theHistoWireMap.end();
287 (*wHisto).second->Write();
289 for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap_ref.begin();
290 wHisto != theHistoWireMap_ref.end();
292 (*wHisto).second->Write();
294 for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
295 lHisto != theHistoLayerMap.end();
297 (*lHisto).second->Write();
301 cout <<
"[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
303 for(map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
304 wiret0 != theAbsoluteT0PerWire.end();
306 if(nDigiPerWire[(*wiret0).first]){
307 double t0 = (*wiret0).second/nDigiPerWire[(*wiret0).first];
309 theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
312 theSigmaT0PerWire[(*wiret0).first] =
sqrt(qK[(*wiret0).first]/nDigiPerWire[(*wiret0).first]);
314 cout <<
"Wire " << (*wiret0).first <<
" has t0 " << t0 <<
"(absolute) "
315 << theRelativeT0PerWire[(*wiret0).first] <<
"(relative)"
316 <<
" sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
321 cout<<
"[DTT0Calibration] ERROR: no digis in wire "<<(*wiret0).first<<endl;
326 if(correctByChamberMean_){
329 const vector<DTSuperLayer*> superLayers = dtGeom->superLayers();
331 for(vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
332 sl != superLayers.end(); sl++) {
336 double oddLayersMean=0;
337 double evenLayersMean=0;
338 double oddLayersDen=0;
339 double evenLayersDen=0;
340 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
341 wiret0 != theRelativeT0PerWire.end();
343 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
345 cout<<
"[DTT0Calibration] Superlayer "<<(*sl)->id()
346 <<
"layer " <<(*wiret0).first.layerId().layer()<<
" with "<<(*wiret0).second<<endl;
347 if(((*wiret0).first.layerId().layer()) % 2){
348 oddLayersMean = oddLayersMean + (*wiret0).second;
352 evenLayersMean = evenLayersMean + (*wiret0).second;
357 oddLayersMean = oddLayersMean/oddLayersDen;
358 evenLayersMean = evenLayersMean/evenLayersDen;
360 cout<<
"[DTT0Calibration] Relative T0 mean for odd layers "<<oddLayersMean<<
" even layers"<<evenLayersMean<<endl;
363 double oddLayersSigma=0;
364 double evenLayersSigma=0;
365 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
366 wiret0 != theRelativeT0PerWire.end();
368 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
369 if(((*wiret0).first.layerId().layer()) % 2){
370 oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
373 evenLayersSigma = evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
377 oddLayersSigma = oddLayersSigma/oddLayersDen;
378 evenLayersSigma = evenLayersSigma/evenLayersDen;
379 oddLayersSigma =
sqrt(oddLayersSigma);
380 evenLayersSigma =
sqrt(evenLayersSigma);
383 cout<<
"[DTT0Calibration] Relative T0 sigma for odd layers "<<oddLayersSigma<<
" even layers"<<evenLayersSigma<<endl;
386 double oddLayersFinalMean=0;
387 double evenLayersFinalMean=0;
388 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
389 wiret0 != theRelativeT0PerWire.end();
391 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
392 if(((*wiret0).first.layerId().layer()) % 2){
393 if(
abs((*wiret0).second - oddLayersMean) < (2*oddLayersSigma))
394 oddLayersFinalMean = oddLayersFinalMean + (*wiret0).second;
397 if(
abs((*wiret0).second - evenLayersMean) < (2*evenLayersSigma))
398 evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
402 oddLayersFinalMean = oddLayersFinalMean/oddLayersDen;
403 evenLayersFinalMean = evenLayersFinalMean/evenLayersDen;
405 cout<<
"[DTT0Calibration] Final relative T0 mean for odd layers "<<oddLayersFinalMean<<
" even layers"<<evenLayersFinalMean<<endl;
407 for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
408 wiret0 != theRelativeT0PerWire.end();
410 if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
412 if(((*wiret0).first.layerId().layer()) % 2)
413 t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
415 t0 = (*wiret0).second;
417 cout <<
"[DTT0Calibration] Wire " << (*wiret0).first <<
" has t0 " << (*wiret0).second
418 <<
" (relative, after even-odd layer corrections) "
419 <<
" sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
429 cout <<
"[DTT0Calibration]Computing relative t0 wrt to chamber average" << endl;
431 map<DTChamberId,double> sumT0ByChamber;
432 map<DTChamberId,int> countT0ByChamber;
435 int channelId =
tzero->channelId;
436 if ( channelId == 0 )
continue;
444 sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
446 countT0ByChamber[chamberId]++;
452 int channelId =
tzero->channelId;
453 if ( channelId == 0 )
continue;
462 double t0mean = t0mean_f - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
463 double t0rms = t0rms_f;
465 t0sWRTChamber->
set(wireId,
471 cout <<
"Changing t0 of wire " << wireId <<
" from " << t0mean_f
472 <<
" to " << t0mean << endl;
478 cout <<
"[DTT0Calibration]Writing values in DB!" << endl;
480 string t0Record =
"DTT0Rcd";
488 stringstream theStream;
491 theStream >> histoName;
497 stringstream theStream;
500 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)