CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
DTT0CalibrationNew Class Reference

#include <DTT0CalibrationNew.h>

Inheritance diagram for DTT0CalibrationNew:
edm::EDAnalyzer

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &eventSetup)
 Fill the maps with t0 (by channel) More...
 
 DTT0CalibrationNew (const edm::ParameterSet &pset)
 Constructor. More...
 
void endJob ()
 Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularity. More...
 
virtual ~DTT0CalibrationNew ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

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
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

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

Date:
2008/09/01 13:29:28
Revision:
1.2
Author
S. Bolognesi - INFN Torino

Definition at line 31 of file DTT0CalibrationNew.h.

Constructor & Destructor Documentation

DTT0CalibrationNew::DTT0CalibrationNew ( const edm::ParameterSet pset)

Constructor.

Definition at line 36 of file DTT0CalibrationNew.cc.

References gather_cfg::cout, dtTTrigAnalyzer_cfg::dbLabel, debug, dtT0WireCalibration_cfg::digiLabel, dtT0WireCalibration_cfg::eventsForLayerT0, dtT0WireCalibration_cfg::eventsForWireT0, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), nevents, dtT0WireCalibration_cfg::rejectDigiFromPeak, dtT0WireCalibration_cfg::rootFileName, relativeConstraints::station, interactiveExample::theFile, and dtT0WireCalibration_cfg::tpPeakWidth.

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

Destructor.

Definition at line 98 of file DTT0CalibrationNew.cc.

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

98  {
99  if(debug)
100  cout << "[DTT0CalibrationNew]Destructor called!" << endl;
101 
102  delete spectrum;
103  theFile->Close();
104 }
tuple cout
Definition: gather_cfg.py:41

Member Function Documentation

void DTT0CalibrationNew::analyze ( const edm::Event event,
const edm::EventSetup eventSetup 
)
virtual

Fill the maps with t0 (by channel)

Perform the real analysis.

Implements edm::EDAnalyzer.

Definition at line 107 of file DTT0CalibrationNew.cc.

References abs, newFWLiteAna::bin, DTSuperLayerId::chamberId(), DTTimeUnits::counts, gather_cfg::cout, dtTTrigAnalyzer_cfg::dbLabel, debug, dtT0WireCalibration_cfg::digiLabel, edm::EventID::event(), dtT0WireCalibration_cfg::eventsForLayerT0, dtT0WireCalibration_cfg::eventsForWireT0, spr::find(), edm::EventSetup::get(), mergeVDriftHistosByStation::getHistoName(), edm::EventBase::id(), plotscripts::mean(), nevents, dtT0WireCalibration_cfg::rejectDigiFromPeak, edm::EventID::run(), DTChamberId::sector(), python.multivaluedict::sort(), DTLayerId::superlayerId(), interactiveExample::theFile, dtT0WireCalibration_cfg::tpPeakWidth, and DTChamberId::wheel().

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

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 401 of file DTT0CalibrationNew.cc.

References abs, DTT0::begin(), DTTimeUnits::counts, gather_cfg::cout, debug, DTT0::end(), DTT0::set(), mathSSE::sqrt(), interactiveExample::theFile, tzero, and DTCalibDBUtils::writeToDB().

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

Definition at line 595 of file DTT0CalibrationNew.cc.

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

595  {
596  string histoName;
597  stringstream theStream;
598  theStream << "Ch_" << wId.wheel() << "_" << wId.station() << "_" << wId.sector()
599  << "_SL" << wId.superlayer() << "_L" << wId.layer() << "_W"<< wId.wire() <<"_hT0Histo";
600  theStream >> histoName;
601  return histoName;
602 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
int wire() const
Return the wire number.
Definition: DTWireId.h:58
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:63
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
string DTT0CalibrationNew::getHistoName ( const DTLayerId lId) const
private

Definition at line 604 of file DTT0CalibrationNew.cc.

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

604  {
605  string histoName;
606  stringstream theStream;
607  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
608  << "_SL" << lId.superlayer() << "_L" << lId.layer() <<"_hT0Histo";
609  theStream >> histoName;
610  return histoName;
611 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:63
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47

Member Data Documentation

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

Definition at line 104 of file DTT0CalibrationNew.h.

std::string DTT0CalibrationNew::dbLabel
private

Definition at line 61 of file DTT0CalibrationNew.h.

bool DTT0CalibrationNew::debug
private

Definition at line 56 of file DTT0CalibrationNew.h.

std::string DTT0CalibrationNew::digiLabel
private

Definition at line 59 of file DTT0CalibrationNew.h.

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

Definition at line 127 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::eventsForLayerT0
private

Definition at line 71 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::eventsForWireT0
private

Definition at line 73 of file DTT0CalibrationNew.h.

TH1D* DTT0CalibrationNew::hT0SectorHisto
private

Definition at line 98 of file DTT0CalibrationNew.h.

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

Definition at line 112 of file DTT0CalibrationNew.h.

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

Definition at line 113 of file DTT0CalibrationNew.h.

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

Definition at line 110 of file DTT0CalibrationNew.h.

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

Definition at line 111 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::nevents
private

Definition at line 69 of file DTT0CalibrationNew.h.

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

Definition at line 114 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::rejectDigiFromPeak
private

Definition at line 85 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::retryForLayerT0
private

Definition at line 87 of file DTT0CalibrationNew.h.

int DTT0CalibrationNew::selSector
private

Definition at line 93 of file DTT0CalibrationNew.h.

int DTT0CalibrationNew::selWheel
private

Definition at line 91 of file DTT0CalibrationNew.h.

TSpectrum* DTT0CalibrationNew::spectrum
private

Definition at line 100 of file DTT0CalibrationNew.h.

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

Definition at line 107 of file DTT0CalibrationNew.h.

std::string DTT0CalibrationNew::theCalibSector
private

Definition at line 92 of file DTT0CalibrationNew.h.

std::string DTT0CalibrationNew::theCalibWheel
private

Definition at line 90 of file DTT0CalibrationNew.h.

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

Definition at line 123 of file DTT0CalibrationNew.h.

TFile* DTT0CalibrationNew::theFile
private

Definition at line 64 of file DTT0CalibrationNew.h.

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

Definition at line 96 of file DTT0CalibrationNew.h.

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

Definition at line 116 of file DTT0CalibrationNew.h.

TFile* DTT0CalibrationNew::theOutputFile
private

Definition at line 66 of file DTT0CalibrationNew.h.

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

Definition at line 124 of file DTT0CalibrationNew.h.

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

Definition at line 108 of file DTT0CalibrationNew.h.

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

Definition at line 119 of file DTT0CalibrationNew.h.

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

Definition at line 109 of file DTT0CalibrationNew.h.

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

Definition at line 122 of file DTT0CalibrationNew.h.

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

Definition at line 118 of file DTT0CalibrationNew.h.

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

Definition at line 120 of file DTT0CalibrationNew.h.

unsigned int DTT0CalibrationNew::timeBoxWidth
private

Definition at line 82 of file DTT0CalibrationNew.h.

double DTT0CalibrationNew::tpPeakWidth
private

Definition at line 76 of file DTT0CalibrationNew.h.

double DTT0CalibrationNew::tpPeakWidthPerLayer
private

Definition at line 79 of file DTT0CalibrationNew.h.

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

Definition at line 103 of file DTT0CalibrationNew.h.