CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTT0Correction.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author A. Vilela Pereira
6  *
7  */
8 
9 #include "DTT0Correction.h"
10 
15 
19 
22 
24 
27 
28 #include <iostream>
29 #include <fstream>
30 
31 using namespace edm;
32 using namespace std;
33 
35 
36  LogVerbatim("Calibration") << "[DTT0Correction] Constructor called" << endl;
37 
38  // Get the concrete algo from the factory
39  string theAlgoName = pset.getParameter<string>("correctionAlgo");
40  correctionAlgo_ = DTT0CorrectionFactory::get()->create(theAlgoName,pset.getParameter<ParameterSet>("correctionAlgoConfig"));
41 }
42 
44  LogVerbatim("Calibration") << "[DTT0Correction] Destructor called" << endl;
45  delete correctionAlgo_;
46 }
47 
49  // Get t0 record from DB
50  ESHandle<DTT0> t0H;
51  setup.get<DTT0Rcd>().get(t0H);
52  t0Map_ = &*t0H;
53  LogVerbatim("Calibration") << "[DTT0Correction]: T0 version: " << t0H->version() << endl;
54 
55  // Get geometry from Event Setup
56  setup.get<MuonGeometryRecord>().get(muonGeom_);
57 
58  // Pass EventSetup to correction Algo
59  correctionAlgo_->setES(setup);
60 }
61 
63  // Create the object to be written to DB
64  DTT0* t0NewMap = new DTT0();
65 
66  // Loop over all channels
67  for(auto sl = muonGeom_->superLayers().begin();
68  sl != muonGeom_->superLayers().end(); ++sl) {
69  for(vector<const DTLayer*>::const_iterator layer = (*sl)->layers().begin();
70  layer != (*sl)->layers().end(); ++layer) {
71  // Access layer topology
72  const DTTopology& dtTopo = (*layer)->specificTopology();
73  const int firstWire = dtTopo.firstChannel();
74  const int lastWire = dtTopo.lastChannel();
75  //const int nWires = dtTopo.channels();
76 
77  //Loop on wires
78  for(int wire = firstWire; wire <= lastWire; ++wire){
79  DTWireId wireId((*layer)->id(),wire);
80 
81  // Get old value from DB
82  float t0Mean,t0RMS;
83  int status = t0Map_->get(wireId,t0Mean,t0RMS,DTTimeUnits::counts);
84 
85  // Compute new t0 for this wire
86  try{
87  dtCalibration::DTT0Data t0Corr = correctionAlgo_->correction( wireId );
88  float t0MeanNew = t0Corr.mean;
89  float t0RMSNew = t0Corr.rms;
90  t0NewMap->set(wireId,t0MeanNew,t0RMSNew,DTTimeUnits::counts);
91 
92  LogVerbatim("Calibration") << "New t0 for: " << wireId
93  << " mean from " << t0Mean << " to " << t0MeanNew
94  << " rms from " << t0RMS << " to " << t0RMSNew << endl;
95  } catch(cms::Exception& e){
96  LogError("Calibration") << e.explainSelf();
97  // Set db to the old value, if it was there in the first place
98  if(!status){
99  t0NewMap->set(wireId,t0Mean,t0RMS,DTTimeUnits::counts);
100  LogVerbatim("Calibration") << "Keep old t0 for: " << wireId
101  << " mean " << t0Mean
102  << " rms " << t0RMS << endl;
103  }
104  continue;
105  }
106  } // End of loop on wires
107  } // End of loop on layers
108  } // End of loop on superlayers
109 
110  //Write object to DB
111  LogVerbatim("Calibration") << "[DTT0Correction]: Writing t0 object to DB!" << endl;
112  string record = "DTT0Rcd";
113  DTCalibDBUtils::writeToDB<DTT0>(record, t0NewMap);
114 }
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
T getParameter(std::string const &) const
virtual void beginRun(const edm::Run &run, const edm::EventSetup &setup)
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual std::string explainSelf() const
Definition: Exception.cc:146
virtual void endJob()
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.
const T & get() const
Definition: EventSetup.h:56
Definition: DTT0Rcd.h:9
tuple status
Definition: ntuplemaker.py:245
virtual ~DTT0Correction()
Destructor.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43