CMS 3D CMS Logo

DTT0Correction.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  */
4 
5 #include "DTT0Correction.h"
6 
11 
15 
18 
20 
23 
24 #include <iostream>
25 #include <fstream>
26 
27 using namespace edm;
28 using namespace std;
29 
31  correctionAlgo_{DTT0CorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
32  pset.getParameter<ParameterSet>("correctionAlgoConfig"))}
33 {
34  LogVerbatim("Calibration") << "[DTT0Correction] Constructor called" << endl;
35 }
36 
38  LogVerbatim("Calibration") << "[DTT0Correction] Destructor called" << endl;
39 }
40 
42  // Get t0 record from DB
43  ESHandle<DTT0> t0H;
44  setup.get<DTT0Rcd>().get(t0H);
45  t0Map_ = &*t0H;
46  LogVerbatim("Calibration") << "[DTT0Correction]: T0 version: " << t0H->version() << endl;
47 
48  // Get geometry from Event Setup
49  setup.get<MuonGeometryRecord>().get(muonGeom_);
50 
51  // Pass EventSetup to correction Algo
52  correctionAlgo_->setES(setup);
53 }
54 
56  // Create the object to be written to DB
57  DTT0* t0NewMap = new DTT0();
58 
59  // Loop over all channels
60  for(vector<const DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
61  sl != muonGeom_->superLayers().end(); ++sl) {
62  for(vector<const DTLayer*>::const_iterator layer = (*sl)->layers().begin();
63  layer != (*sl)->layers().end(); ++layer) {
64  // Access layer topology
65  const DTTopology& dtTopo = (*layer)->specificTopology();
66  const int firstWire = dtTopo.firstChannel();
67  const int lastWire = dtTopo.lastChannel();
68  //const int nWires = dtTopo.channels();
69 
70  //Loop on wires
71  for(int wire = firstWire; wire <= lastWire; ++wire){
72  DTWireId wireId((*layer)->id(),wire);
73 
74  // Get old value from DB
75  float t0Mean,t0RMS;
76  int status = t0Map_->get(wireId,t0Mean,t0RMS,DTTimeUnits::counts);
77 
78  // Compute new t0 for this wire
79  try{
80  dtCalibration::DTT0Data t0Corr = correctionAlgo_->correction( wireId );
81  float t0MeanNew = t0Corr.mean;
82  float t0RMSNew = t0Corr.rms;
83  t0NewMap->set(wireId,t0MeanNew,t0RMSNew,DTTimeUnits::counts);
84 
85  LogVerbatim("Calibration") << "New t0 for: " << wireId
86  << " mean from " << t0Mean << " to " << t0MeanNew
87  << " rms from " << t0RMS << " to " << t0RMSNew << endl;
88  } catch(cms::Exception& e){
89  LogError("Calibration") << e.explainSelf();
90  // Set db to the old value, if it was there in the first place
91  if(!status){
92  t0NewMap->set(wireId,t0Mean,t0RMS,DTTimeUnits::counts);
93  LogVerbatim("Calibration") << "Keep old t0 for: " << wireId
94  << " mean " << t0Mean
95  << " rms " << t0RMS << endl;
96  }
97  continue;
98  }
99  } // End of loop on wires
100  } // End of loop on layers
101  } // End of loop on superlayers
102 
103  //Write object to DB
104  LogVerbatim("Calibration") << "[DTT0Correction]: Writing t0 object to DB!" << endl;
105  string record = "DTT0Rcd";
106  DTCalibDBUtils::writeToDB<DTT0>(record, t0NewMap);
107 }
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
const DTT0 * t0Map_
T getParameter(std::string const &) const
void endJob() override
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual std::string explainSelf() const
Definition: Exception.cc:108
std::unique_ptr< dtCalibration::DTT0BaseCorrection > correctionAlgo_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
~DTT0Correction() override
Destructor.
edm::ESHandle< DTGeometry > muonGeom_
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
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:78
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:80
Definition: DTT0.h:53
DTT0Correction(const edm::ParameterSet &pset)
Constructor.
Definition: DTT0Rcd.h:9
HLT enums.
T get() const
Definition: EventSetup.h:71
const std::string & version() const
access version
Definition: DTT0.cc:118
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:45
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:107