CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  : mTimeMapToken_(esConsumes<edm::Transition::BeginRun>()),
37  vDriftMapToken_(esConsumes<edm::Transition::BeginRun>()),
38  dtGeomToken_(esConsumes<edm::Transition::BeginRun>()),
39  granularity_(pset.getUntrackedParameter<string>("calibGranularity", "bySL")),
40  mTimeMap_(nullptr),
41  vDriftMap_(nullptr),
42  vDriftAlgo_{DTVDriftPluginFactory::get()->create(pset.getParameter<string>("vDriftAlgo"),
43  pset.getParameter<ParameterSet>("vDriftAlgoConfig"),
44  consumesCollector())} {
45  LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";
46 
47  if (granularity_ != "bySL")
48  throw cms::Exception("Configuration")
49  << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";
50 
51  readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB");
52  writeLegacyVDriftDB = pset.getParameter<bool>("writeLegacyVDriftDB");
53 }
54 
55 DTVDriftWriter::~DTVDriftWriter() { LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!"; }
56 
58  // Get the map of vdrift from the Setup
59  if (readLegacyVDriftDB) {
61  } else {
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 
73  // Pass EventSetup to concrete implementation
74  vDriftAlgo_->setES(setup);
75 }
76 
78  // Create the object to be written to DB
79  std::unique_ptr<DTMtime> mTimeNewMap;
80  std::unique_ptr<DTRecoConditions> vDriftNewMap;
81  if (writeLegacyVDriftDB) {
82  mTimeNewMap = std::make_unique<DTMtime>();
83  } else {
84  vDriftNewMap = std::make_unique<DTRecoConditions>();
85  vDriftNewMap->setFormulaExpr("[0]");
86  //vDriftNewMap->setFormulaExpr("[0]*(1-[1]*x)"); // add parametrization for dependency along Y
87  vDriftNewMap->setVersion(1);
88  }
89 
90  if (granularity_ == "bySL") {
91  // Get all the sls from the geometry
92  const vector<const DTSuperLayer*>& superLayers = dtGeom_->superLayers();
93  auto sl = superLayers.begin();
94  auto sl_end = superLayers.end();
95  for (; sl != sl_end; ++sl) {
96  DTSuperLayerId slId = (*sl)->id();
97 
98  // Compute vDrift
99  float vDriftNew = -1.;
100  float resolutionNew = -1;
101  try {
102  dtCalibration::DTVDriftData vDriftData = vDriftAlgo_->compute(slId);
103  vDriftNew = vDriftData.vdrift;
104  resolutionNew = vDriftData.resolution;
105  LogVerbatim("Calibration") << "vDrift for: " << slId << " Mean " << vDriftNew << " Resolution "
106  << resolutionNew;
107  } catch (cms::Exception& e) { // Failure to compute new value, fall back to old table
108  LogError("Calibration") << e.explainSelf();
109  if (readLegacyVDriftDB) { //...reading old db format...
110  int status = mTimeMap_->get(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns);
111  if (status == 0) { // not found; silently skip this SL
112  continue;
113  }
114  } else { //...reading new db format
115  try {
116  vDriftNew = vDriftMap_->get(DTWireId(slId.rawId()));
117  } catch (cms::Exception& e2) {
118  // not found; silently skip this SL
119  continue;
120  }
121  }
122  LogVerbatim("Calibration") << "Keep original vDrift for: " << slId << " Mean " << vDriftNew << " Resolution "
123  << resolutionNew;
124  }
125 
126  // Add value to the vdrift table
127  if (writeLegacyVDriftDB) {
128  mTimeNewMap->set(slId, vDriftNew, resolutionNew, DTVelocityUnits::cm_per_ns);
129  } else {
130  vector<double> params = {vDriftNew};
131  vDriftNewMap->set(DTWireId(slId.rawId()), params);
132  }
133  } // End of loop on superlayers
134  }
135 
136  // Write the vDrift object to DB
137  LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
138  if (writeLegacyVDriftDB) {
139  string record = "DTMtimeRcd";
140  DTCalibDBUtils::writeToDB<DTMtime>(record, *mTimeNewMap);
141  } else {
142  DTCalibDBUtils::writeToDB<DTRecoConditions>("DTRecoConditionsVdriftRcd", *vDriftNewMap);
143  }
144 }
const edm::ESGetToken< DTRecoConditions, DTRecoConditionsVdriftRcd > vDriftMapToken_
Log< level::Info, true > LogVerbatim
edm::ESHandle< DTGeometry > dtGeom_
int version() const
Version numer specifying the structure of the payload. See .cc file for details.
virtual std::string explainSelf() const
Definition: Exception.cc:108
const DTRecoConditions * vDriftMap_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
list status
Definition: mps_update.py:107
Log< level::Error, false > LogError
bool getData(T &iHolder) const
Definition: EventSetup.h:122
DTVDriftWriter(const edm::ParameterSet &pset)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Transition
Definition: Transition.h:12
const edm::ESGetToken< DTMtime, DTMtimeRcd > mTimeMapToken_
float get(const DTWireId &wireid, double *x=nullptr) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization whe...
~DTVDriftWriter() override
std::unique_ptr< dtCalibration::DTVDriftBaseAlgo > vDriftAlgo_
void endJob() override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:56
bool writeLegacyVDriftDB
const DTMtime * mTimeMap_
#define get
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
Definition: Run.h:45
std::string granularity_