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 
24 
28 
29 #include <string>
30 #include <vector>
31 
32 using namespace std;
33 using namespace edm;
34 
36  : granularity_(pset.getUntrackedParameter<string>("calibGranularity", "bySL")),
37  mTimeMap_(nullptr),
38  vDriftMap_(nullptr),
39  vDriftAlgo_{DTVDriftPluginFactory::get()->create(pset.getParameter<string>("vDriftAlgo"),
40  pset.getParameter<ParameterSet>("vDriftAlgoConfig"))} {
41  LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";
42 
43  if (granularity_ != "bySL")
44  throw cms::Exception("Configuration")
45  << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";
46 
47  readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB");
48  writeLegacyVDriftDB = pset.getParameter<bool>("writeLegacyVDriftDB");
49 }
50 
51 DTVDriftWriter::~DTVDriftWriter() { LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!"; }
52 
54  // Get the map of vdrift from the Setup
55  if (readLegacyVDriftDB) {
56  ESHandle<DTMtime> mTime;
57  setup.get<DTMtimeRcd>().get(mTime);
58  mTimeMap_ = &*mTime;
59  } else {
61  setup.get<DTRecoConditionsVdriftRcd>().get(hVdrift);
62  vDriftMap_ = &*hVdrift;
63  // Consistency check: no parametrization is implemented for the time being
64  int version = vDriftMap_->version();
65  if (version != 1) {
66  throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
67  }
68  }
69 
70  // Get geometry from Event Setup
72  // Pass EventSetup to concrete implementation
73  vDriftAlgo_->setES(setup);
74 }
75 
77  // Create the object to be written to DB
78  DTMtime* mTimeNewMap = nullptr;
79  DTRecoConditions* vDriftNewMap = nullptr;
80  if (writeLegacyVDriftDB) {
81  mTimeNewMap = new DTMtime();
82  } else {
83  vDriftNewMap = new DTRecoConditions();
84  vDriftNewMap->setFormulaExpr("[0]");
85  //vDriftNewMap->setFormulaExpr("[0]*(1-[1]*x)"); // add parametrization for dependency along Y
86  vDriftNewMap->setVersion(1);
87  }
88 
89  if (granularity_ == "bySL") {
90  // Get all the sls from the geometry
91  const vector<const DTSuperLayer*>& superLayers = dtGeom_->superLayers();
92  auto sl = superLayers.begin();
93  auto sl_end = superLayers.end();
94  for (; sl != sl_end; ++sl) {
95  DTSuperLayerId slId = (*sl)->id();
96 
97  // Compute vDrift
98  float vDriftNew = -1.;
99  float resolutionNew = -1;
100  try {
101  dtCalibration::DTVDriftData vDriftData = vDriftAlgo_->compute(slId);
102  vDriftNew = vDriftData.vdrift;
103  resolutionNew = vDriftData.resolution;
104  LogVerbatim("Calibration") << "vDrift for: " << slId << " Mean " << vDriftNew << " Resolution "
105  << resolutionNew;
106  } catch (cms::Exception& e) { // Failure to compute new value, fall back to old table
107  LogError("Calibration") << e.explainSelf();
108  if (readLegacyVDriftDB) { //...reading old db format...
109  int status = mTimeMap_->get(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns);
110  if (status == 0) { // not found; silently skip this SL
111  continue;
112  }
113  } else { //...reading new db format
114  try {
115  vDriftNew = vDriftMap_->get(DTWireId(slId.rawId()));
116  } catch (cms::Exception& e2) {
117  // not found; silently skip this SL
118  continue;
119  }
120  }
121  LogVerbatim("Calibration") << "Keep original vDrift for: " << slId << " Mean " << vDriftNew << " Resolution "
122  << resolutionNew;
123  }
124 
125  // Add value to the vdrift table
126  if (writeLegacyVDriftDB) {
127  mTimeNewMap->set(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns);
128  } else {
129  vector<double> params = {vDriftNew};
130  vDriftNewMap->set(DTWireId(slId.rawId()), params);
131  }
132  } // End of loop on superlayers
133  }
134 
135  // Write the vDrift object to DB
136  LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
137  if (writeLegacyVDriftDB) {
138  string record = "DTMtimeRcd";
139  DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap);
140  } else {
141  DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsVdriftRcd", vDriftNewMap);
142  }
143 }
DTRecoConditionsVdriftRcd
Definition: DTRecoConditionsVdriftRcd.h:5
DTRecoConditionsVdriftRcd.h
DTSuperLayerId
Definition: DTSuperLayerId.h:12
DTVDriftWriter::readLegacyVDriftDB
bool readLegacyVDriftDB
Definition: DTVDriftWriter.h:40
DTVDriftWriter::dtGeom_
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTVDriftWriter.h:43
DTVDriftWriter::mTimeMap_
const DTMtime * mTimeMap_
Definition: DTVDriftWriter.h:38
MessageLogger.h
DTMtime.h
DTVDriftWriter::DTVDriftWriter
DTVDriftWriter(const edm::ParameterSet &pset)
Definition: DTVDriftWriter.cc:35
ESHandle.h
mps_update.status
status
Definition: mps_update.py:69
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
dtCalibration::DTVDriftData::vdrift
double vdrift
Definition: DTVDriftBaseAlgo.h:23
DTVDriftWriter::endJob
void endJob() override
Definition: DTVDriftWriter.cc:76
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
DTMtime
Definition: DTMtime.h:68
DTMtime::set
int set(int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTTimeUnits::type unit)
Definition: DTMtime.cc:168
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTRecoConditions::get
float get(const DTWireId &wireid, double *x=nullptr) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization when...
Definition: DTRecoConditions.cc:42
DTVDriftWriter.h
DTRecoConditions::setFormulaExpr
void setFormulaExpr(const std::string &expr)
Set the expression representing the formula used for parametrization.
Definition: DTRecoConditions.h:50
DTRecoConditions::version
int version() const
Version numer specifying the structure of the payload. See .cc file for details.
Definition: DTRecoConditions.h:43
DTRecoConditions.h
dtCalibration::DTVDriftData::resolution
double resolution
Definition: DTVDriftBaseAlgo.h:24
DTVDriftWriter::vDriftAlgo_
std::unique_ptr< dtCalibration::DTVDriftBaseAlgo > vDriftAlgo_
Definition: DTVDriftWriter.h:45
DTWireId
Definition: DTWireId.h:12
edm::ESHandle< DTMtime >
DTVDriftPluginFactory.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTGeometry.h
DTRecoConditions::setVersion
void setVersion(int version)
Definition: DTRecoConditions.h:40
edm::ParameterSet
Definition: ParameterSet.h:47
DTVDriftWriter::vDriftMap_
const DTRecoConditions * vDriftMap_
Definition: DTVDriftWriter.h:39
DTVelocityUnits::cm_per_ns
Definition: DTVelocityUnits.h:32
DTMtimeRcd.h
DTVDriftWriter::writeLegacyVDriftDB
bool writeLegacyVDriftDB
Definition: DTVDriftWriter.h:41
DTCalibDBUtils.h
DTGeometry::superLayers
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:86
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
DTVDriftBaseAlgo.h
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
DTRecoConditions::set
void set(const DTWireId &wireid, const std::vector< double > &values)
Fill the payload.
Definition: DTRecoConditions.cc:78
Exception
Definition: hltDiff.cc:245
EventSetup.h
DTRecoConditions
Definition: DTRecoConditions.h:28
cms::Exception
Definition: Exception.h:70
ParameterSet.h
MuonGeometryRecord.h
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
dtCalibration::DTVDriftData
Definition: DTVDriftBaseAlgo.h:19
DTVDriftWriter::granularity_
std::string granularity_
Definition: DTVDriftWriter.h:36
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTMtime::get
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:56
DTSuperLayer.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
DTVDriftWriter::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
Definition: DTVDriftWriter.cc:53
DTVDriftWriter::~DTVDriftWriter
~DTVDriftWriter() override
Definition: DTVDriftWriter.cc:51
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DTMtimeRcd
Definition: DTMtimeRcd.h:5