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
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)
 Fill the maps with t0 (by channel) More...
 
 DTT0Calibration (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 ~DTT0Calibration ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

std::string getHistoName (const DTWireId &wId) const
 
std::string getHistoName (const DTLayerId &lId) const
 

Private Attributes

std::vector< std::string > cellsWithHistos
 
bool correctByChamberMean_
 
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
 
int selSector
 
int selWheel
 
std::map< DTWireId, double > theAbsoluteT0PerWire
 
std::string theCalibSector
 
std::string theCalibWheel
 
TFile * theFile
 
std::map< DTLayerId, TH1I * > theHistoLayerMap
 
std::map< DTWireId, TH1I * > theHistoWireMap
 
std::map< DTWireId, TH1I * > theHistoWireMap_ref
 
TFile * theOutputFile
 
std::map< DTWireId, double > theRelativeT0PerWire
 
std::map< std::string, double > theSigmaT0LayerMap
 
std::map< DTWireId, double > theSigmaT0PerWire
 
std::map< std::string, double > theT0LayerMap
 
double tpPeakWidth
 
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)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
CurrentProcessingContext const * currentContext () const
 
- 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

Date:
2012/04/10 17:55:08
Revision:
1.6
Author
S. Bolognesi - INFN Torino

Definition at line 30 of file DTT0Calibration.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 29 of file DTT0Calibration.cc.

References gather_cfg::cout, debug, dtTPAnalyzer_cfg::digiLabel, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), nevents, dtT0Analyzer_cfg::rootFileName, relativeConstraints::station, and interactiveExample::theFile.

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

Destructor.

Definition at line 86 of file DTT0Calibration.cc.

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

86  {
87  if(debug)
88  cout << "[DTT0Calibration]Destructor called!" << endl;
89 
90  theFile->Close();
91 }
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void DTT0Calibration::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 94 of file DTT0Calibration.cc.

References abs, DTSuperLayerId::chamberId(), gather_cfg::cout, debug, dtTPAnalyzer_cfg::digiLabel, edm::EventID::event(), spr::find(), edm::EventSetup::get(), mergeVDriftHistosByStation::getHistoName(), edm::EventBase::id(), nevents, edm::EventID::run(), DTChamberId::sector(), DTLayerId::superlayerId(), interactiveExample::theFile, and DTChamberId::wheel().

94  {
95  if(debug || event.id().event() % 500==0)
96  cout << "--- [DTT0Calibration] Analysing Event: #Run: " << event.id().run()
97  << " #Event: " << event.id().event() << endl;
98  nevents++;
99 
100  // Get the digis from the event
102  event.getByLabel(digiLabel, digis);
103 
104  // Get the DT Geometry
105  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
106 
107  // Iterate through all digi collections ordered by LayerId
109  for (dtLayerIt = digis->begin();
110  dtLayerIt != digis->end();
111  ++dtLayerIt){
112  // Get the iterators over the digis associated with this LayerId
113  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
114 
115  // Get the layerId
116  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
117 
118  if((theCalibWheel != "All") && (layerId.superlayerId().chamberId().wheel() != selWheel))
119  continue;
120  if((theCalibSector != "All") && (layerId.superlayerId().chamberId().sector() != selSector))
121  continue;
122 
123  //if(debug) {
124  // cout << "Layer " << layerId<<" with "<<distance(digiRange.first, digiRange.second)<<" digi"<<endl;
125  //}
126 
127  // Loop over all digis in the given layer
128  for (DTDigiCollection::const_iterator digi = digiRange.first;
129  digi != digiRange.second;
130  digi++) {
131  double t0 = (*digi).countsTDC();
132 
133  //Use first bunch of events to fill t0 per layer
135  //Get the per-layer histo from the map
136  TH1I *hT0LayerHisto = theHistoLayerMap[layerId];
137  //If it doesn't exist, book it
138  if(hT0LayerHisto == 0){
139  theFile->cd();
140  hT0LayerHisto = new TH1I(getHistoName(layerId).c_str(),
141  "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
142  200, t0-100, t0+100);
143  if(debug)
144  cout << " New T0 per Layer Histo: " << hT0LayerHisto->GetName() << endl;
145  theHistoLayerMap[layerId] = hT0LayerHisto;
146  }
147 
148  //Fill the histos
149  theFile->cd();
150  if(hT0LayerHisto != 0) {
151  // if(debug)
152  // cout<<"Filling histo "<<hT0LayerHisto->GetName()<<" with digi "<<t0<<" TDC counts"<<endl;
153  hT0LayerHisto->Fill(t0);
154  }
155  }
156 
157  //Use all the remaining events to compute t0 per wire
159  // Get the wireId
160  const DTWireId wireId(layerId, (*digi).wire());
161  if(debug) {
162  cout << " Wire: " << wireId << endl
163  << " time (TDC counts): " << (*digi).countsTDC()<< endl;
164  }
165 
166  //Fill the histos per wire for the chosen cells
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;
172  }
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;
176  }
177 
178  TH1I* hT0WireHisto = theHistoWireMap[wireId];
179  //Fill the histos
180  theFile->cd();
181  if(hT0WireHisto) hT0WireHisto->Fill(t0);
182  }
183 
184  //Check the tzero has reasonable value
185  if(abs(hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin()) - t0) > rejectDigiFromPeak){
186  if(debug)
187  cout<<"digi skipped because t0 per sector "<<hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
188  continue;
189  }
190 
191  //Use second bunch of events to compute a t0 reference per wire
193  //Fill reference wire histos
194  if(it_wire != wireIdWithHistos.end()){
195  TH1I* hT0WireHisto_ref = theHistoWireMap_ref[wireId];
196  theFile->cd();
197  if(hT0WireHisto_ref) hT0WireHisto_ref->Fill(t0);
198  }
199  if(!nDigiPerWire_ref[wireId]){
200  mK_ref[wireId] = 0;
201  }
202  nDigiPerWire_ref[wireId] = nDigiPerWire_ref[wireId] + 1;
203  mK_ref[wireId] = mK_ref[wireId] + (t0-mK_ref[wireId])/nDigiPerWire_ref[wireId];
204  }
205  //Use last all the remaining events to compute the mean and sigma t0 per wire
207  if(abs(t0-mK_ref[wireId]) > tpPeakWidth)
208  continue;
209  if(!nDigiPerWire[wireId]){
210  theAbsoluteT0PerWire[wireId] = 0;
211  qK[wireId] = 0;
212  mK[wireId] = 0;
213  }
214  nDigiPerWire[wireId] = nDigiPerWire[wireId] + 1;
215  theAbsoluteT0PerWire[wireId] = theAbsoluteT0PerWire[wireId] + t0;
216  //theSigmaT0PerWire[wireId] = theSigmaT0PerWire[wireId] + (t0*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];
219  }
220  }//end if(nevents>1000)
221  }//end loop on digi
222  }//end loop on layer
223 
224  //Use the t0 per layer histos to have an indication about the t0 position
225  if(nevents == eventsForLayerT0){
226  for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
227  lHisto != theHistoLayerMap.end();
228  lHisto++){
229  if(debug)
230  cout<<"Reading histogram "<<(*lHisto).second->GetName()<<" with mean "<<(*lHisto).second->GetMean()<<" and RMS "<<(*lHisto).second->GetRMS();
231 
232  //Take the mean as a first t0 estimation
233  if((*lHisto).second->GetRMS()<5.0){
234  if(hT0SectorHisto == 0){
235  hT0SectorHisto = new TH1D("hT0AllLayerOfSector","T0 from pulses per layer in sector",
236  //20, (*lHisto).second->GetMean()-100, (*lHisto).second->GetMean()+100);
237  700, 0, 7000);
238  }
239  if(debug)
240  cout<<" accepted"<<endl;
241  hT0SectorHisto->Fill((*lHisto).second->GetMean());
242  }
243  //Take the mean of noise + 400ns as a first t0 estimation
244  // if((*lHisto).second->GetRMS()>10.0 && ((*lHisto).second->GetRMS()<15.0)){
245 // double t0_estim = (*lHisto).second->GetMean() + 400;
246 // if(hT0SectorHisto == 0){
247 // hT0SectorHisto = new TH1D("hT0AllLayerOfSector","T0 from pulses per layer in sector",
248 // //20, t0_estim-100, t0_estim+100);
249 // 700, 0, 7000);
250 // }
251 // if(debug)
252 // cout<<" accepted + 400ns"<<endl;
253 // hT0SectorHisto->Fill((*lHisto).second->GetMean() + 400);
254 // }
255  if(debug)
256  cout<<endl;
257 
258  theT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetMean();
259  theSigmaT0LayerMap[(*lHisto).second->GetName()] = (*lHisto).second->GetRMS();
260  }
261  if(!hT0SectorHisto){
262  cout<<"[DTT0Calibration]: All the t0 per layer are still uncorrect: trying with greater number of events"<<endl;
264  return;
265  }
266  if(debug)
267  cout<<"[DTT0Calibration] t0 reference for this sector "<<
268  hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin())<<endl;
269  }
270 }
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
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< DTWireId, int > nDigiPerWire
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
std::map< DTWireId, TH1I * > theHistoWireMap_ref
#define abs(x)
Definition: mlp_lapack.h:159
std::string getHistoName(const DTWireId &wId) const
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
edm::ESHandle< DTGeometry > dtGeom
std::map< DTWireId, double > mK
unsigned int eventsForLayerT0
unsigned int rejectDigiFromPeak
std::string theCalibSector
std::map< DTWireId, double > qK
std::map< std::string, double > theSigmaT0LayerMap
std::map< std::string, double > theT0LayerMap
std::map< DTWireId, double > mK_ref
std::string digiLabel
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
std::pair< const_iterator, const_iterator > Range
tuple cout
Definition: gather_cfg.py:121
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
unsigned int eventsForWireT0
std::map< DTWireId, int > nDigiPerWire_ref
void DTT0Calibration::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 273 of file DTT0Calibration.cc.

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

273  {
274 
275  DTT0* t0sAbsolute = new DTT0();
276  DTT0* t0sRelative = new DTT0();
277  DTT0* t0sWRTChamber = new DTT0();
278 
279  //if(debug)
280  cout << "[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
281 
282  theFile->cd();
283  hT0SectorHisto->Write();
284  for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap.begin();
285  wHisto != theHistoWireMap.end();
286  wHisto++) {
287  (*wHisto).second->Write();
288  }
289  for(map<DTWireId, TH1I*>::const_iterator wHisto = theHistoWireMap_ref.begin();
290  wHisto != theHistoWireMap_ref.end();
291  wHisto++) {
292  (*wHisto).second->Write();
293  }
294  for(map<DTLayerId, TH1I*>::const_iterator lHisto = theHistoLayerMap.begin();
295  lHisto != theHistoLayerMap.end();
296  lHisto++) {
297  (*lHisto).second->Write();
298  }
299 
300  //if(debug)
301  cout << "[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
302 
303  for(map<DTWireId, double>::const_iterator wiret0 = theAbsoluteT0PerWire.begin();
304  wiret0 != theAbsoluteT0PerWire.end();
305  wiret0++){
306  if(nDigiPerWire[(*wiret0).first]){
307  double t0 = (*wiret0).second/nDigiPerWire[(*wiret0).first];
308 
309  theRelativeT0PerWire[(*wiret0).first] = t0 - hT0SectorHisto->GetBinCenter(hT0SectorHisto->GetMaximumBin());
310 
311  //theSigmaT0PerWire[(*wiret0).first] = sqrt((theSigmaT0PerWire[(*wiret0).first] / nDigiPerWire[(*wiret0).first]) - t0*t0);
312  theSigmaT0PerWire[(*wiret0).first] = sqrt(qK[(*wiret0).first]/nDigiPerWire[(*wiret0).first]);
313 
314  cout << "Wire " << (*wiret0).first << " has t0 " << t0 << "(absolute) "
315  << theRelativeT0PerWire[(*wiret0).first] << "(relative)"
316  << " sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
317 
318  t0sAbsolute->set((*wiret0).first, t0, theSigmaT0PerWire[(*wiret0).first],DTTimeUnits::counts);
319  }
320  else{
321  cout<<"[DTT0Calibration] ERROR: no digis in wire "<<(*wiret0).first<<endl;
322  abort();
323  }
324  }
325 
328  // Get all the sls from the setup
329  const vector<DTSuperLayer*> superLayers = dtGeom->superLayers();
330  // Loop over all SLs
331  for(vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
332  sl != superLayers.end(); sl++) {
333 
334 
335  //Compute mean for odd and even superlayers
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();
342  wiret0++){
343  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
344  if(debug)
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;
349  oddLayersDen++;
350  }
351  else{
352  evenLayersMean = evenLayersMean + (*wiret0).second;
353  evenLayersDen++;
354  }
355  }
356  }
357  oddLayersMean = oddLayersMean/oddLayersDen;
358  evenLayersMean = evenLayersMean/evenLayersDen;
359  //if(debug && oddLayersMean)
360  cout<<"[DTT0Calibration] Relative T0 mean for odd layers "<<oddLayersMean<<" even layers"<<evenLayersMean<<endl;
361 
362  //Compute sigma for odd and even superlayers
363  double oddLayersSigma=0;
364  double evenLayersSigma=0;
365  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
366  wiret0 != theRelativeT0PerWire.end();
367  wiret0++){
368  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
369  if(((*wiret0).first.layerId().layer()) % 2){
370  oddLayersSigma = oddLayersSigma + ((*wiret0).second - oddLayersMean) * ((*wiret0).second - oddLayersMean);
371  }
372  else{
373  evenLayersSigma = evenLayersSigma + ((*wiret0).second - evenLayersMean) * ((*wiret0).second - evenLayersMean);
374  }
375  }
376  }
377  oddLayersSigma = oddLayersSigma/oddLayersDen;
378  evenLayersSigma = evenLayersSigma/evenLayersDen;
379  oddLayersSigma = sqrt(oddLayersSigma);
380  evenLayersSigma = sqrt(evenLayersSigma);
381 
382  //if(debug && oddLayersMean)
383  cout<<"[DTT0Calibration] Relative T0 sigma for odd layers "<<oddLayersSigma<<" even layers"<<evenLayersSigma<<endl;
384 
385  //Recompute the mean for odd and even superlayers discarding fluctations
386  double oddLayersFinalMean=0;
387  double evenLayersFinalMean=0;
388  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
389  wiret0 != theRelativeT0PerWire.end();
390  wiret0++){
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;
395  }
396  else{
397  if(abs((*wiret0).second - evenLayersMean) < (2*evenLayersSigma))
398  evenLayersFinalMean = evenLayersFinalMean + (*wiret0).second;
399  }
400  }
401  }
402  oddLayersFinalMean = oddLayersFinalMean/oddLayersDen;
403  evenLayersFinalMean = evenLayersFinalMean/evenLayersDen;
404  //if(debug && oddLayersMean)
405  cout<<"[DTT0Calibration] Final relative T0 mean for odd layers "<<oddLayersFinalMean<<" even layers"<<evenLayersFinalMean<<endl;
406 
407  for(map<DTWireId, double>::const_iterator wiret0 = theRelativeT0PerWire.begin();
408  wiret0 != theRelativeT0PerWire.end();
409  wiret0++){
410  if((*wiret0).first.layerId().superlayerId() == (*sl)->id()){
411  double t0=-999;
412  if(((*wiret0).first.layerId().layer()) % 2)
413  t0 = (*wiret0).second + (evenLayersFinalMean - oddLayersFinalMean);
414  else
415  t0 = (*wiret0).second;
416 
417  cout << "[DTT0Calibration] Wire " << (*wiret0).first << " has t0 " << (*wiret0).second
418  << " (relative, after even-odd layer corrections) "
419  << " sigma " << theSigmaT0PerWire[(*wiret0).first] << endl;
420 
421  //Store the results into DB
422  t0sRelative->set((*wiret0).first, t0, theSigmaT0PerWire[(*wiret0).first],DTTimeUnits::counts);
423  }
424  }
425  }
426 
428  //if(debug)
429  cout << "[DTT0Calibration]Computing relative t0 wrt to chamber average" << endl;
430  //Compute the reference for each chamber
431  map<DTChamberId,double> sumT0ByChamber;
432  map<DTChamberId,int> countT0ByChamber;
433  for(DTT0::const_iterator tzero = t0sRelative->begin();
434  tzero != t0sRelative->end(); tzero++) {
435  int channelId = tzero->channelId;
436  if ( channelId == 0 ) continue;
437  DTWireId wireId(channelId);
438  DTChamberId chamberId(wireId.chamberId());
439  //sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + tzero->t0mean;
440  // @@@ better DTT0 usage
441  float t0mean_f;
442  float t0rms_f;
443  t0sRelative->get(wireId,t0mean_f,t0rms_f,DTTimeUnits::counts);
444  sumT0ByChamber[chamberId] = sumT0ByChamber[chamberId] + t0mean_f;
445  // @@@ NEW DTT0 END
446  countT0ByChamber[chamberId]++;
447  }
448 
449  //Change reference for each wire and store the new t0s in the new map
450  for(DTT0::const_iterator tzero = t0sRelative->begin();
451  tzero != t0sRelative->end(); tzero++) {
452  int channelId = tzero->channelId;
453  if ( channelId == 0 ) continue;
454  DTWireId wireId(channelId);
455  DTChamberId chamberId(wireId.chamberId());
456  //double t0mean = (tzero->t0mean) - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
457  //double t0rms = tzero->t0rms;
458  // @@@ better DTT0 usage
459  float t0mean_f;
460  float t0rms_f;
461  t0sRelative->get(wireId,t0mean_f,t0rms_f,DTTimeUnits::counts);
462  double t0mean = t0mean_f - (sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
463  double t0rms = t0rms_f;
464  // @@@ NEW DTT0 END
465  t0sWRTChamber->set(wireId,
466  t0mean,
467  t0rms,
469  //if(debug)
470  //cout<<"Chamber "<<chamberId<<" has reference "<<(sumT0ByChamber[chamberId]/countT0ByChamber[chamberId]);
471  cout << "Changing t0 of wire " << wireId << " from " << t0mean_f
472  << " to " << t0mean << endl;
473  }
474  }
475 
477  if(debug)
478  cout << "[DTT0Calibration]Writing values in DB!" << endl;
479  // FIXME: to be read from cfg?
480  string t0Record = "DTT0Rcd";
481  // Write the t0 map to DB
482  if( correctByChamberMean_ ) DTCalibDBUtils::writeToDB(t0Record, t0sWRTChamber);
483  else DTCalibDBUtils::writeToDB(t0Record, t0sAbsolute);
484 }
const_iterator begin() const
Definition: DTT0.cc:206
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
Definition: DTT0.cc:142
std::map< DTLayerId, TH1I * > theHistoLayerMap
std::map< DTWireId, double > theAbsoluteT0PerWire
std::map< DTWireId, TH1I * > theHistoWireMap
std::map< DTWireId, int > nDigiPerWire
std::map< DTWireId, TH1I * > theHistoWireMap_ref
#define abs(x)
Definition: mlp_lapack.h:159
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:69
std::vector< DTT0Data >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:139
Definition: DTT0.h:52
std::map< DTWireId, double > theRelativeT0PerWire
T sqrt(T t)
Definition: SSEVec.h:48
std::map< DTWireId, double > qK
const_iterator end() const
Definition: DTT0.cc:211
static const double tzero[3]
tuple cout
Definition: gather_cfg.py:121
static void writeToDB(std::string record, T *payload)
string DTT0Calibration::getHistoName ( const DTWireId wId) const
private

Definition at line 486 of file DTT0Calibration.cc.

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

486  {
487  string histoName;
488  stringstream theStream;
489  theStream << "Ch_" << wId.wheel() << "_" << wId.station() << "_" << wId.sector()
490  << "_SL" << wId.superlayer() << "_L" << wId.layer() << "_W"<< wId.wire() <<"_hT0Histo";
491  theStream >> histoName;
492  return histoName;
493 }
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 DTT0Calibration::getHistoName ( const DTLayerId lId) const
private

Definition at line 495 of file DTT0Calibration.cc.

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

495  {
496  string histoName;
497  stringstream theStream;
498  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
499  << "_SL" << lId.superlayer() << "_L" << lId.layer() <<"_hT0Histo";
500  theStream >> histoName;
501  return histoName;
502 }
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> DTT0Calibration::cellsWithHistos
private

Definition at line 94 of file DTT0Calibration.h.

bool DTT0Calibration::correctByChamberMean_
private

Definition at line 79 of file DTT0Calibration.h.

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

Definition at line 58 of file DTT0Calibration.h.

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

Definition at line 113 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForLayerT0
private

Definition at line 68 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForWireT0
private

Definition at line 70 of file DTT0Calibration.h.

TH1D* DTT0Calibration::hT0SectorHisto
private

Definition at line 90 of file DTT0Calibration.h.

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

Definition at line 102 of file DTT0Calibration.h.

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

Definition at line 103 of file DTT0Calibration.h.

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

Definition at line 100 of file DTT0Calibration.h.

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

Definition at line 101 of file DTT0Calibration.h.

unsigned int DTT0Calibration::nevents
private

Definition at line 66 of file DTT0Calibration.h.

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

Definition at line 104 of file DTT0Calibration.h.

unsigned int DTT0Calibration::rejectDigiFromPeak
private

Definition at line 73 of file DTT0Calibration.h.

int DTT0Calibration::selSector
private

Definition at line 85 of file DTT0Calibration.h.

int DTT0Calibration::selWheel
private

Definition at line 83 of file DTT0Calibration.h.

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

Definition at line 97 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibSector
private

Definition at line 84 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibWheel
private

Definition at line 82 of file DTT0Calibration.h.

TFile* DTT0Calibration::theFile
private

Definition at line 61 of file DTT0Calibration.h.

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

Definition at line 88 of file DTT0Calibration.h.

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

Definition at line 106 of file DTT0Calibration.h.

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

Definition at line 107 of file DTT0Calibration.h.

TFile* DTT0Calibration::theOutputFile
private

Definition at line 63 of file DTT0Calibration.h.

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

Definition at line 98 of file DTT0Calibration.h.

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

Definition at line 110 of file DTT0Calibration.h.

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

Definition at line 99 of file DTT0Calibration.h.

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

Definition at line 109 of file DTT0Calibration.h.

double DTT0Calibration::tpPeakWidth
private

Definition at line 76 of file DTT0Calibration.h.

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

Definition at line 93 of file DTT0Calibration.h.