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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) 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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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

Author
S. Bolognesi - INFN Torino

Definition at line 28 of file DTT0Calibration.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 27 of file DTT0Calibration.cc.

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

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

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

84  {
85  if(debug)
86  cout << "[DTT0Calibration]Destructor called!" << endl;
87 
88  theFile->Close();
89 }
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 92 of file DTT0Calibration.cc.

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

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

References funct::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().

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

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

484  {
485  string histoName;
486  stringstream theStream;
487  theStream << "Ch_" << wId.wheel() << "_" << wId.station() << "_" << wId.sector()
488  << "_SL" << wId.superlayer() << "_L" << wId.layer() << "_W"<< wId.wire() <<"_hT0Histo";
489  theStream >> histoName;
490  return histoName;
491 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
int wire() const
Return the wire number.
Definition: DTWireId.h:56
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
string DTT0Calibration::getHistoName ( const DTLayerId lId) const
private

Definition at line 493 of file DTT0Calibration.cc.

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

493  {
494  string histoName;
495  stringstream theStream;
496  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
497  << "_SL" << lId.superlayer() << "_L" << lId.layer() <<"_hT0Histo";
498  theStream >> histoName;
499  return histoName;
500 }
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
int superlayer() const
Return the superlayer number (deprecated method name)
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45

Member Data Documentation

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

Definition at line 92 of file DTT0Calibration.h.

bool DTT0Calibration::correctByChamberMean_
private

Definition at line 77 of file DTT0Calibration.h.

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

Definition at line 56 of file DTT0Calibration.h.

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

Definition at line 111 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForLayerT0
private

Definition at line 66 of file DTT0Calibration.h.

unsigned int DTT0Calibration::eventsForWireT0
private

Definition at line 68 of file DTT0Calibration.h.

TH1D* DTT0Calibration::hT0SectorHisto
private

Definition at line 88 of file DTT0Calibration.h.

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

Definition at line 100 of file DTT0Calibration.h.

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

Definition at line 101 of file DTT0Calibration.h.

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

Definition at line 98 of file DTT0Calibration.h.

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

Definition at line 99 of file DTT0Calibration.h.

unsigned int DTT0Calibration::nevents
private

Definition at line 64 of file DTT0Calibration.h.

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

Definition at line 102 of file DTT0Calibration.h.

unsigned int DTT0Calibration::rejectDigiFromPeak
private

Definition at line 71 of file DTT0Calibration.h.

int DTT0Calibration::selSector
private

Definition at line 83 of file DTT0Calibration.h.

int DTT0Calibration::selWheel
private

Definition at line 81 of file DTT0Calibration.h.

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

Definition at line 95 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibSector
private

Definition at line 82 of file DTT0Calibration.h.

std::string DTT0Calibration::theCalibWheel
private

Definition at line 80 of file DTT0Calibration.h.

TFile* DTT0Calibration::theFile
private

Definition at line 59 of file DTT0Calibration.h.

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

Definition at line 86 of file DTT0Calibration.h.

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

Definition at line 104 of file DTT0Calibration.h.

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

Definition at line 105 of file DTT0Calibration.h.

TFile* DTT0Calibration::theOutputFile
private

Definition at line 61 of file DTT0Calibration.h.

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

Definition at line 96 of file DTT0Calibration.h.

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

Definition at line 108 of file DTT0Calibration.h.

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

Definition at line 97 of file DTT0Calibration.h.

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

Definition at line 107 of file DTT0Calibration.h.

double DTT0Calibration::tpPeakWidth
private

Definition at line 74 of file DTT0Calibration.h.

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

Definition at line 91 of file DTT0Calibration.h.