CMS 3D CMS Logo

DTVDriftWriter.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * Author of original version: M. Giunta
6  * \author A. Vilela Pereira
7  */
8 
9 #include "DTVDriftWriter.h"
10 
15 
19 
22 
26 
27 #include <string>
28 #include <vector>
29 
30 using namespace std;
31 using namespace edm;
32 
34  granularity_( pset.getUntrackedParameter<string>("calibGranularity","bySL") ) {
35 
36  LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";
37 
38  if(granularity_ != "bySL")
39  throw cms::Exception("Configuration") << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";
40 
41  // Get the concrete algo from the factory
42  string algoName = pset.getParameter<string>("vDriftAlgo");
43  ParameterSet algoPSet = pset.getParameter<ParameterSet>("vDriftAlgoConfig");
44  vDriftAlgo_ = DTVDriftPluginFactory::get()->create(algoName,algoPSet);
45 }
46 
48  LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!";
49  delete vDriftAlgo_;
50 }
51 
53  // Get the map of ttrig from the Setup
54  ESHandle<DTMtime> mTime;
55  setup.get<DTMtimeRcd>().get(mTime);
56  mTimeMap_ = &*mTime;
57 
58  // Get geometry from Event Setup
59  setup.get<MuonGeometryRecord>().get(dtGeom_);
60  // Pass EventSetup to concrete implementation
61  vDriftAlgo_->setES(setup);
62 }
63 
65  // Create the object to be written to DB
66  DTMtime* mTimeNewMap = new DTMtime();
67 
68  if(granularity_ == "bySL") {
69  // Get all the sls from the geometry
70  const vector<const DTSuperLayer*>& superLayers = dtGeom_->superLayers();
71  auto sl = superLayers.begin();
72  auto sl_end = superLayers.end();
73  for(; sl != sl_end; ++sl){
74  DTSuperLayerId slId = (*sl)->id();
75  // Get original value from DB
76  float vDrift = 0., resolution = 0.;
77  // vdrift is cm/ns , resolution is cm
79 
80  // Compute vDrift
81  try{
83  float vDriftNew = vDriftData.vdrift;
84  float resolutionNew = vDriftData.resolution;
85  // vdrift is cm/ns , resolution is cm
86  mTimeNewMap->set(slId,
87  vDriftNew,
88  resolutionNew,
90  LogVerbatim("Calibration") << "vDrift for: " << slId
91  << " Mean " << vDriftNew
92  << " Resolution " << resolutionNew;
93  } catch(cms::Exception& e){
94  LogError("Calibration") << e.explainSelf();
95  // Go back to original value in case of error
96  if(!status){
97  mTimeNewMap->set(slId,
98  vDrift,
99  resolution,
101  LogVerbatim("Calibration") << "Keep original vDrift for: " << slId
102  << " Mean " << vDrift
103  << " Resolution " << resolution;
104  }
105  }
106  } // End of loop on superlayers
107  }
108 
109  // Write the vDrift object to DB
110  LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
111  string record = "DTMtimeRcd";
112  DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap);
113 }
T getParameter(std::string const &) const
edm::ESHandle< DTGeometry > dtGeom_
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual DTVDriftData compute(const DTSuperLayerId &)=0
int set(int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTTimeUnits::type unit)
Definition: DTMtime.cc:250
virtual std::string explainSelf() const
Definition: Exception.cc:146
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
DTVDriftWriter(const edm::ParameterSet &pset)
dtCalibration::DTVDriftBaseAlgo * vDriftAlgo_
~DTVDriftWriter() override
const T & get() const
Definition: EventSetup.h:58
void endJob() override
virtual void setES(const edm::EventSetup &setup)=0
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:82
HLT enums.
const DTMtime * mTimeMap_
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:89
std::string granularity_