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  vDriftAlgo_{DTVDriftPluginFactory::get()->create(pset.getParameter<string>("vDriftAlgo"),
36  pset.getParameter<ParameterSet>("vDriftAlgoConfig"))}
37  {
38 
39  LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";
40 
41  if(granularity_ != "bySL")
42  throw cms::Exception("Configuration") << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";
43 }
44 
46  LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!";
47 }
48 
50  // Get the map of ttrig from the Setup
51  ESHandle<DTMtime> mTime;
52  setup.get<DTMtimeRcd>().get(mTime);
53  mTimeMap_ = &*mTime;
54 
55  // Get geometry from Event Setup
56  setup.get<MuonGeometryRecord>().get(dtGeom_);
57  // Pass EventSetup to concrete implementation
58  vDriftAlgo_->setES(setup);
59 }
60 
62  // Create the object to be written to DB
63  DTMtime* mTimeNewMap = new DTMtime();
64 
65  if(granularity_ == "bySL") {
66  // Get all the sls from the geometry
67  const vector<const DTSuperLayer*>& superLayers = dtGeom_->superLayers();
68  auto sl = superLayers.begin();
69  auto sl_end = superLayers.end();
70  for(; sl != sl_end; ++sl){
71  DTSuperLayerId slId = (*sl)->id();
72  // Get original value from DB
73  float vDrift = 0., resolution = 0.;
74  // vdrift is cm/ns , resolution is cm
76 
77  // Compute vDrift
78  try{
79  dtCalibration::DTVDriftData vDriftData = vDriftAlgo_->compute(slId);
80  float vDriftNew = vDriftData.vdrift;
81  float resolutionNew = vDriftData.resolution;
82  // vdrift is cm/ns , resolution is cm
83  mTimeNewMap->set(slId,
84  vDriftNew,
85  resolutionNew,
87  LogVerbatim("Calibration") << "vDrift for: " << slId
88  << " Mean " << vDriftNew
89  << " Resolution " << resolutionNew;
90  } catch(cms::Exception& e){
91  LogError("Calibration") << e.explainSelf();
92  // Go back to original value in case of error
93  if(!status){
94  mTimeNewMap->set(slId,
95  vDrift,
96  resolution,
98  LogVerbatim("Calibration") << "Keep original vDrift for: " << slId
99  << " Mean " << vDrift
100  << " Resolution " << resolution;
101  }
102  }
103  } // End of loop on superlayers
104  }
105 
106  // Write the vDrift object to DB
107  LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
108  string record = "DTMtimeRcd";
109  DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap);
110 }
T getParameter(std::string const &) const
edm::ESHandle< DTGeometry > dtGeom_
JetCorrectorParameters::Record record
Definition: classes.h:7
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:108
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
DTVDriftWriter(const edm::ParameterSet &pset)
~DTVDriftWriter() override
std::unique_ptr< dtCalibration::DTVDriftBaseAlgo > vDriftAlgo_
void endJob() override
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:82
HLT enums.
T get() const
Definition: EventSetup.h:71
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:45
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:107
std::string granularity_