CMS 3D CMS Logo

DTCalibrationMap.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Cerminara - INFN Torino
6  */
7 
9 
12 
13 #include <iostream>
14 #include <fstream>
15 
16 #include <sstream>
17 #include <algorithm>
18 #include <iterator>
19 
20 using namespace std;
21 using namespace edm;
22 
24  nFields = pset.getUntrackedParameter<int>("nFields", 5);
25  calibConstFileName = pset.getUntrackedParameter<string>("calibConstFileName", "dummy.txt");
26  calibConstGranularity = pset.getUntrackedParameter<string>("calibConstGranularity", "bySL");
27 
28  // Initialize correctly the enum which specify the granularity for the calibration
29  if (calibConstGranularity == "byWire") {
30  theGranularity = byWire;
31  } else if (calibConstGranularity == "byLayer") {
32  theGranularity = byLayer;
33  } else if (calibConstGranularity == "bySL") {
34  theGranularity = bySL;
35  } else {
36  theGranularity = byChamber;
37  if (!(calibConstGranularity == "byChamber")) {
38  cout << "[DTCalibrationMap]###Warning: Check parameter calibConstGranularity: " << calibConstGranularity
39  << " options not available!" << endl;
40  }
41  }
42  readConsts(calibConstFileName);
43 }
44 
46 
47 // Return the t_trig (ns) for a particular wire
48 float DTCalibrationMap::tTrig(DTWireId wireId) const { return getField(wireId, 0); }
49 
50 // Return the sigma of the t_trig (ns) for a particular wire
51 float DTCalibrationMap::sigma_tTrig(DTWireId wireId) const { return getField(wireId, 1); }
52 
53 // Return the kfactor for a particular wire
54 float DTCalibrationMap::kFactor(DTWireId wireId) const { return getField(wireId, 2); }
55 
56 // Return the mean drift velocity for a particular wire (cm/ns)
57 float DTCalibrationMap::meanVDrift(DTWireId wireId) const { return getField(wireId, 3); }
58 
59 // Return the sigma of the mean drift velocity for a particular wire (cm/ns)
60 float DTCalibrationMap::sigma_meanVDrift(DTWireId wireId) const { return getField(wireId, 4); }
61 
62 // Get a key to read calibration constants for a particular wire
63 // with the given granularity
65  if (theGranularity == byChamber) {
66  return Key(wireId.chamberId(), 0, 0, 0);
67  } else if (theGranularity == bySL) {
68  return Key(wireId.superlayerId(), 0, 0);
69  } else if (theGranularity == byLayer) {
70  return Key(wireId.layerId(), 0);
71  } else {
72  return Key(wireId);
73  }
74 }
75 
76 // Get from the map the calibration constants for a particular key
78  // Create a cache
79  static pair<Key, CalibConsts> cache;
80 
81  // Get the key
82  Key theKey = getKey(wireId);
83 
84  // Check if the result is already cached
85  if (theKey == cache.first) {
86  return &(cache.second);
87  }
88 
89  // Look for the given key into the map
90  map<Key, CalibConsts>::const_iterator res = theMap.find(theKey);
91  if (res != theMap.end()) {
92  cache = (*res);
93  return &((*res).second);
94  } else {
95  return nullptr;
96  }
97 }
98 
99 // Get a particular number (field) between all the calibration
100 // constants available for a particluar wire
101 float DTCalibrationMap::getField(DTWireId wireId, int field) const {
102  const CalibConsts* cals = getConsts(wireId);
103  if (cals == nullptr) {
104  throw cms::Exception("NoCalibConsts") << "DTCalibrationMap:" << endl
105  << "No parameters for wire: " << wireId << endl
106  << "Check the " << calibConstFileName << " file!" << endl;
107  } else {
108  return (*(cals))[field];
109  }
110 }
111 
112 // Read the calibration consts from a file
114  ifstream file(inputFileName.c_str());
115  // Check if the file exists
116  if (!file) {
117  cout << "[DTCalibrationMap]***Warning: File: " << inputFileName << " not found in current directory!!!" << endl;
118  }
119 
120  string line;
121 
122  // The numbers to be read to build the key
123  int wheel_id = 0;
124  int station_id = 0;
125  int sector_id = 0;
126  int superlayer_id = 0;
127  int layer_id = 0;
128  int wire_id = 0;
129 
130  // Read all the lines
131  while (getline(file, line)) {
132  if (line.empty() || line[0] == '#')
133  continue; // Skip comments and empty lines
134  stringstream linestr;
135  linestr << line;
136 
137  pair<Key, CalibConsts> wireCalib;
138 
139  linestr >> wheel_id >> station_id >> sector_id >> superlayer_id >> layer_id >> wire_id;
140 
141  // Build the key
142  wireCalib.first = Key(wheel_id, station_id, sector_id, superlayer_id, layer_id, wire_id);
143 
144  if (!checkGranularity(wireCalib.first))
145  cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the selected granularity!"
146  << endl;
147 
148  // Read the calibration constants
149  copy(istream_iterator<float>(linestr), istream_iterator<float>(), back_inserter(wireCalib.second));
150 
151  if (wireCalib.second.size() < nFields) {
152  cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the number of fields!" << endl;
153  }
154 
155  theMap.insert(wireCalib);
156  }
157 }
158 
159 // Add to the map the calibration consts for a given key
160 void DTCalibrationMap::addCell(Key theKey, const CalibConsts& calibConst) {
161  if (!checkGranularity(theKey))
162  throw cms::Exception("addCell") << "DTCalibrationMap:" << endl
163  << "The added key is not compatible with the selected granularity" << endl;
164 
165  theMap[theKey] = calibConst;
166 }
167 
168 // Write the calibration consts to a file
170  ofstream out(outputFileName.c_str());
171  for (map<Key, CalibConsts>::const_iterator iter = theMap.begin(); iter != theMap.end(); ++iter) {
172  out << (*iter).first.wheel() << ' ' << (*iter).first.station() << ' ' << (*iter).first.sector() << ' '
173  << (*iter).first.superlayer() << ' ' << (*iter).first.layer() << ' ' << (*iter).first.wire() << ' ';
174  copy((*iter).second.begin(), (*iter).second.end(), ostream_iterator<float>(out, " "));
175  out << endl;
176  }
177 }
178 
179 // Check the consistency of a given key with the selected granularity
181  bool ret = true;
182 
183  // Check that the key is consistent with the given granularity
184  if (theGranularity == byChamber) {
185  if (aKey.superlayer() || aKey.layer() || aKey.wire()) {
186  ret = false;
187  }
188  } else if (theGranularity == bySL) {
189  if (aKey.layer() || aKey.wire()) {
190  ret = false;
191  }
192  } else if (theGranularity == byLayer) {
193  if (aKey.wire()) {
194  ret = false;
195  }
196  } else if (theGranularity == byWire) {
197  if (aKey.wire() == 0) {
198  ret = false;
199  }
200  }
201  return ret;
202 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
DTCalibrationMap::getField
float getField(DTWireId wireId, int field) const
Definition: DTCalibrationMap.cc:101
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DTCalibrationMap::kFactor
float kFactor(DTWireId wireId) const
Return the kfactor for a particular wire.
Definition: DTCalibrationMap.cc:54
DTCalibrationMap::sigma_tTrig
float sigma_tTrig(DTWireId wireId) const
Return the sigma of the t_trig (ns) for a particular wire.
Definition: DTCalibrationMap.cc:51
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
DTCalibrationMap.h
DTCalibrationMap::CalibConsts
std::vector< float > CalibConsts
Definition: DTCalibrationMap.h:62
InefficientDoubleROC.inputFileName
inputFileName
Definition: InefficientDoubleROC.py:437
DTCalibrationMap::DTCalibrationMap
DTCalibrationMap(const edm::ParameterSet &pset)
Constructor.
Definition: DTCalibrationMap.cc:23
DTWireId
Definition: DTWireId.h:12
DTCalibrationMap::getKey
Key getKey(DTWireId wireId) const
Definition: DTCalibrationMap.cc:64
reco_skim_cfg_mod.outputFileName
outputFileName
Definition: reco_skim_cfg_mod.py:15
DTCalibrationMap::~DTCalibrationMap
virtual ~DTCalibrationMap()
Destructor.
Definition: DTCalibrationMap.cc:45
CaloRecHitAuxSetter::getField
constexpr unsigned getField(const uint32_t u, const unsigned mask, const unsigned offset)
Definition: CaloRecHitAuxSetter.h:13
utilities.cache
def cache(function)
Definition: utilities.py:3
edm::ParameterSet
Definition: ParameterSet.h:47
DTCalibrationMap::meanVDrift
float meanVDrift(DTWireId wireId) const
Return the mean drift velocity for a particular wire (cm/ns)
Definition: DTCalibrationMap.cc:57
DTSuperLayerId::chamberId
DTChamberId chamberId() const
Return the corresponding ChamberId.
Definition: DTSuperLayerId.h:45
DTCalibrationMap::writeConsts
void writeConsts(const std::string &outputFileName) const
Definition: DTCalibrationMap.cc:169
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
res
Definition: Electron.h:6
DTCalibrationMap::sigma_meanVDrift
float sigma_meanVDrift(DTWireId wireId) const
Return the sigma of the mean drift velocity for a particular wire (cm/ns)
Definition: DTCalibrationMap.cc:60
DTCalibrationMap::getConsts
const CalibConsts * getConsts(DTWireId wireId) const
Definition: DTCalibrationMap.cc:77
std
Definition: JetResolutionObject.h:76
DTCalibrationMap::tTrig
float tTrig(DTWireId wireId) const
Return the t_trig (ns) for a particular wire.
Definition: DTCalibrationMap.cc:48
Exception
Definition: hltDiff.cc:246
DTLayerId::superlayerId
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
Exception.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
DTCalibrationMap::addCell
void addCell(Key wireId, const CalibConsts &calibConst)
Definition: DTCalibrationMap.cc:160
ParameterSet.h
DTCalibrationMap::checkGranularity
bool checkGranularity(Key aKey) const
Definition: DTCalibrationMap.cc:180
mps_splice.line
line
Definition: mps_splice.py:76
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
DTCalibrationMap::readConsts
void readConsts(const std::string &inputFileName)
Definition: DTCalibrationMap.cc:113
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27