test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
DTCalibrationMap Class Reference

#include <DTCalibrationMap.h>

Public Types

typedef std::vector< float > CalibConsts
 
typedef std::map< Key,
CalibConsts >::const_iterator 
const_iterator
 
typedef DTWireId Key
 

Public Member Functions

void addCell (Key wireId, const CalibConsts &calibConst)
 
void cleanTheConsts ()
 
 DTCalibrationMap (const edm::ParameterSet &pset)
 Constructor. More...
 
const CalibConstsgetConsts (DTWireId wireId) const
 
float getField (DTWireId wireId, int field) const
 
Key getKey (DTWireId wireId) const
 
const_iterator keyAndConsts_begin () const
 
const_iterator keyAndConsts_end () const
 
float kFactor (DTWireId wireId) const
 Return the kfactor for a particular wire. More...
 
float meanVDrift (DTWireId wireId) const
 Return the mean drift velocity for a particular wire (cm/ns) More...
 
float sigma_meanVDrift (DTWireId wireId) const
 Return the sigma of the mean drift velocity for a particular wire (cm/ns) More...
 
float sigma_tTrig (DTWireId wireId) const
 Return the sigma of the t_trig (ns) for a particular wire. More...
 
float tTrig (DTWireId wireId) const
 Return the t_trig (ns) for a particular wire. More...
 
void writeConsts (const std::string &outputFileName) const
 
virtual ~DTCalibrationMap ()
 Destructor. More...
 

Private Types

enum  CalibGranularity { byChamber, bySL, byLayer, byWire }
 

Private Member Functions

bool checkGranularity (Key aKey) const
 
void readConsts (const std::string &inputFileName)
 

Private Attributes

std::string calibConstFileName
 
std::string calibConstGranularity
 
unsigned int nFields
 
CalibGranularity theGranularity
 
std::map< Key, CalibConststheMap
 

Detailed Description

Allow saving and retrieving of calibration constants to/from txt file. This was originally provided for backward compatibility with the ORCA MuBarDigiParameters file. Can be used to save an arbitrary number of constants with the needed granularity and to retrieve them back using the wireId. Current field allocation: fields for each key are allocated to: –First block: legacy descriptors– [0] ttrig [1] sigma_ttrig (obsolete) [2] kfactor (obsolete) [3] vdrift [4] sigma_vdrift (obsolete, was formerly hacked to include reoslution) [5] t0 [6] t0rms [7] noisy or dead flag [8-9] left for future usage –Second block (optional): free fields [10] Encoded information of free fields: (1000*version)+(100*type)+(number of fields); type is: ttrig=0, vdrift=1, uncertainties=3 [11-end] free fields

Author
G. Cerminara - INFN Torino

Definition at line 40 of file DTCalibrationMap.h.

Member Typedef Documentation

typedef std::vector<float> DTCalibrationMap::CalibConsts

Definition at line 65 of file DTCalibrationMap.h.

Definition at line 67 of file DTCalibrationMap.h.

Definition at line 66 of file DTCalibrationMap.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

DTCalibrationMap::DTCalibrationMap ( const edm::ParameterSet pset)

Constructor.

Definition at line 23 of file DTCalibrationMap.cc.

References MeasureLA_cff::byLayer, gather_cfg::cout, and edm::ParameterSet::getUntrackedParameter().

23  {
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") {
31  } else if(calibConstGranularity == "byLayer"){
33  } else if(calibConstGranularity == "bySL") {
35  } else {
37  if(!(calibConstGranularity == "byChamber")) {
38  cout << "[DTCalibrationMap]###Warning: Check parameter calibConstGranularity: "
39  << calibConstGranularity << " options not available!" << endl;
40  }
41  }
42  readConsts(calibConstFileName);
43 }
T getUntrackedParameter(std::string const &, T const &) const
CalibGranularity theGranularity
std::string calibConstGranularity
std::string calibConstFileName
unsigned int nFields
tuple cout
Definition: gather_cfg.py:145
void readConsts(const std::string &inputFileName)
DTCalibrationMap::~DTCalibrationMap ( )
virtual

Destructor.

Definition at line 47 of file DTCalibrationMap.cc.

47 {}

Member Function Documentation

void DTCalibrationMap::addCell ( Key  wireId,
const CalibConsts calibConst 
)

Definition at line 203 of file DTCalibrationMap.cc.

References Exception.

Referenced by DTVDriftCalibration::endJob().

203  {
204  if(!checkGranularity(theKey))
205  throw cms::Exception("addCell") << "DTCalibrationMap:" << endl
206  << "The added key is not compatible with the selected granularity"
207  << endl;
208 
209  theMap[theKey] = calibConst;
210 }
std::map< Key, CalibConsts > theMap
bool checkGranularity(Key aKey) const
bool DTCalibrationMap::checkGranularity ( Key  aKey) const
private

Definition at line 232 of file DTCalibrationMap.cc.

References MeasureLA_cff::byLayer, DTLayerId::layer(), runTheMatrix::ret, DTSuperLayerId::superlayer(), and DTWireId::wire().

232  {
233  bool ret = true;
234 
235  // Check that the key is consistent with the given granularity
236  if(theGranularity == byChamber) {
237  if(aKey.superlayer() || aKey.layer() || aKey.wire()) {
238  ret = false;
239  }
240  } else if(theGranularity == bySL) {
241  if(aKey.layer() || aKey.wire()) {
242  ret = false;
243  }
244  } else if(theGranularity == byLayer) {
245  if(aKey.wire()) {
246  ret = false;
247  }
248  } else if(theGranularity == byWire) {
249  if(aKey.wire() == 0) {
250  ret = false;
251  }
252  }
253  return ret;
254 }
tuple ret
prodAgent to be discontinued
CalibGranularity theGranularity
void DTCalibrationMap::cleanTheConsts ( )
inline

Definition at line 70 of file DTCalibrationMap.h.

References theMap.

70  {
71  theMap.clear();
72  }
std::map< Key, CalibConsts > theMap
const DTCalibrationMap::CalibConsts * DTCalibrationMap::getConsts ( DTWireId  wireId) const

Definition at line 103 of file DTCalibrationMap.cc.

References getKey().

Referenced by DTVDriftCalibration::endJob().

103  {
104  // Create a cache
105  static pair<Key, CalibConsts> cache;
106 
107  // Get the key
108  Key theKey = getKey(wireId);
109 
110  // Check if the result is already cached
111  if ( theKey == cache.first ) {
112  return &(cache.second);
113  }
114 
115  // Look for the given key into the map
116  map<Key, CalibConsts>::const_iterator res = theMap.find(theKey);
117  if (res != theMap.end()) {
118  cache = (*res);
119  return &((*res).second);
120  } else {
121  return 0;
122  }
123 }
Key getKey(DTWireId wireId) const
std::map< Key, CalibConsts > theMap
float DTCalibrationMap::getField ( DTWireId  wireId,
int  field 
) const

Definition at line 129 of file DTCalibrationMap.cc.

References Exception.

129  {
130  const CalibConsts* cals = getConsts(wireId);
131  if (cals == 0) {
132  throw cms::Exception("NoCalibConsts") << "DTCalibrationMap:" << endl
133  << "No parameters for wire: " << wireId << endl
134  << "Check the " << calibConstFileName << " file!" << endl;
135  } else {
136  return (*(cals))[field];
137  }
138 }
std::string calibConstFileName
std::vector< float > CalibConsts
const CalibConsts * getConsts(DTWireId wireId) const
DTCalibrationMap::Key DTCalibrationMap::getKey ( DTWireId  wireId) const

Definition at line 88 of file DTCalibrationMap.cc.

References MeasureLA_cff::byLayer, DTSuperLayerId::chamberId(), DTWireId::layerId(), and DTLayerId::superlayerId().

Referenced by DTVDriftCalibration::endJob(), MatrixToProcess.MatrixToProcess::getConfig(), MatrixToProcess.MatrixToProcess::getProcess(), MatrixToProcess.MatrixToProcess::identityTest(), and MatrixToProcess.MatrixToProcess::load().

88  {
89  if (theGranularity == byChamber){
90  return Key(wireId.chamberId(), 0, 0, 0);
91  } else if (theGranularity == bySL) {
92  return Key(wireId.superlayerId(), 0, 0);
93  } else if (theGranularity == byLayer) {
94  return Key(wireId.layerId(), 0);
95  } else {
96  return Key(wireId);
97  }
98 }
DTChamberId chamberId() const
Return the corresponding ChamberId.
CalibGranularity theGranularity
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
const_iterator DTCalibrationMap::keyAndConsts_begin ( ) const
inline

Definition at line 92 of file DTCalibrationMap.h.

References theMap.

92  {
93  return theMap.begin();
94  }
std::map< Key, CalibConsts > theMap
const_iterator DTCalibrationMap::keyAndConsts_end ( ) const
inline

Definition at line 96 of file DTCalibrationMap.h.

References theMap.

96  {
97  return theMap.end();
98  }
std::map< Key, CalibConsts > theMap
float DTCalibrationMap::kFactor ( DTWireId  wireId) const

Return the kfactor for a particular wire.

Definition at line 66 of file DTCalibrationMap.cc.

66  {
67  return getField(wireId, 2);
68 }
float getField(DTWireId wireId, int field) const
float DTCalibrationMap::meanVDrift ( DTWireId  wireId) const

Return the mean drift velocity for a particular wire (cm/ns)

Definition at line 73 of file DTCalibrationMap.cc.

73  {
74  return getField(wireId, 3);
75 }
float getField(DTWireId wireId, int field) const
void DTCalibrationMap::readConsts ( const std::string &  inputFileName)
private

Definition at line 144 of file DTCalibrationMap.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, mergeVDriftHistosByStation::file, and geometryCSVtoXML::line.

144  {
145  ifstream file(inputFileName.c_str());
146  // Check if the file exists
147  if(!file) {
148  cout << "[DTCalibrationMap]***Warning: File: " << inputFileName
149  << " not found in current directory!!!" << endl;
150  }
151 
152  string line;
153 
154  // The numbers to be read to build the key
155  int wheel_id = 0;
156  int station_id = 0;
157  int sector_id = 0;
158  int superlayer_id = 0;
159  int layer_id = 0;
160  int wire_id = 0;
161 
162  // Read all the lines
163  while (getline(file,line)) {
164  if( line == "" || line[0] == '#' ) continue; // Skip comments and empty lines
165  stringstream linestr;
166  linestr << line;
167 
168  pair<Key, CalibConsts> wireCalib;
169 
170  linestr >> wheel_id
171  >> station_id
172  >> sector_id
173  >> superlayer_id
174  >> layer_id
175  >> wire_id;
176 
177  // Build the key
178  wireCalib.first = Key( wheel_id,
179  station_id,
180  sector_id,
181  superlayer_id,
182  layer_id,
183  wire_id);
184 
185  if(!checkGranularity(wireCalib.first))
186  cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the selected granularity!" << endl;
187 
188 
189  // Read the calibration constants
190  copy(istream_iterator<float>(linestr),
191  istream_iterator<float>(),
192  back_inserter(wireCalib.second));
193 
194  if(wireCalib.second.size() < nFields){
195  cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the number of fields!" << endl;
196  }
197 
198  theMap.insert(wireCalib);
199  }
200 }
std::map< Key, CalibConsts > theMap
bool checkGranularity(Key aKey) const
unsigned int nFields
tuple cout
Definition: gather_cfg.py:145
float DTCalibrationMap::sigma_meanVDrift ( DTWireId  wireId) const

Return the sigma of the mean drift velocity for a particular wire (cm/ns)

Definition at line 80 of file DTCalibrationMap.cc.

80  {
81  return getField(wireId, 4);
82 }
float getField(DTWireId wireId, int field) const
float DTCalibrationMap::sigma_tTrig ( DTWireId  wireId) const

Return the sigma of the t_trig (ns) for a particular wire.

Definition at line 59 of file DTCalibrationMap.cc.

59  {
60  return getField(wireId, 1);
61 }
float getField(DTWireId wireId, int field) const
float DTCalibrationMap::tTrig ( DTWireId  wireId) const

Return the t_trig (ns) for a particular wire.

Definition at line 52 of file DTCalibrationMap.cc.

52  {
53  return getField(wireId, 0);
54 }
float getField(DTWireId wireId, int field) const
void DTCalibrationMap::writeConsts ( const std::string &  outputFileName) const

Definition at line 213 of file DTCalibrationMap.cc.

References filterCSVwithJSON::copy, and GenerateHcalLaserBadRunList::out.

Referenced by DTVDriftCalibration::endJob().

213  {
214  ofstream out(outputFileName.c_str());
215  for(map<Key,CalibConsts>::const_iterator iter = theMap.begin();
216  iter != theMap.end() ; ++iter) {
217 
218  out << (*iter).first.wheel() << ' '
219  << (*iter).first.station() << ' '
220  << (*iter).first.sector() << ' '
221  << (*iter).first.superlayer() << ' '
222  << (*iter).first.layer() << ' '
223  << (*iter).first.wire() << ' ';
224  copy((*iter).second.begin(), (*iter).second.end(),
225  ostream_iterator<float>(out, " "));
226  out << endl;
227  }
228 }
std::map< Key, CalibConsts > theMap

Member Data Documentation

std::string DTCalibrationMap::calibConstFileName
private

Definition at line 122 of file DTCalibrationMap.h.

std::string DTCalibrationMap::calibConstGranularity
private

Definition at line 125 of file DTCalibrationMap.h.

unsigned int DTCalibrationMap::nFields
private

Definition at line 119 of file DTCalibrationMap.h.

CalibGranularity DTCalibrationMap::theGranularity
private

Definition at line 107 of file DTCalibrationMap.h.

std::map<Key, CalibConsts> DTCalibrationMap::theMap
private

Definition at line 128 of file DTCalibrationMap.h.

Referenced by cleanTheConsts(), keyAndConsts_begin(), and keyAndConsts_end().