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 is mainly 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. The first 5 fields for each key are allocated to ttri, sigma_ttrig, kfactor, vdrift and sigma_vdrift.

Date:
2008/12/09 22:43:38
Revision:
1.2
Author
G. Cerminara - INFN Torino

Definition at line 29 of file DTCalibrationMap.h.

Member Typedef Documentation

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

Definition at line 54 of file DTCalibrationMap.h.

Definition at line 56 of file DTCalibrationMap.h.

Definition at line 55 of file DTCalibrationMap.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Constructor.

Definition at line 25 of file DTCalibrationMap.cc.

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

25  {
26  nFields = pset.getUntrackedParameter<int>("nFields", 5);
27  calibConstFileName = pset.getUntrackedParameter<string>("calibConstFileName", "dummy.txt");
28  calibConstGranularity = pset.getUntrackedParameter<string>("calibConstGranularity","bySL");
29 
30  // Initialize correctly the enum which specify the granularity for the calibration
31  if(calibConstGranularity == "byWire") {
33  } else if(calibConstGranularity == "byLayer"){
35  } else if(calibConstGranularity == "bySL") {
37  } else {
39  if(!(calibConstGranularity == "byChamber")) {
40  cout << "[DTCalibrationMap]###Warning: Check parameter calibConstGranularity: "
41  << calibConstGranularity << " options not available!" << endl;
42  }
43  }
44  readConsts(calibConstFileName);
45 }
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:121
void readConsts(const std::string &inputFileName)
DTCalibrationMap::~DTCalibrationMap ( )
virtual

Destructor.

Definition at line 49 of file DTCalibrationMap.cc.

49 {}

Member Function Documentation

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

Definition at line 205 of file DTCalibrationMap.cc.

References edm::hlt::Exception.

Referenced by DTVDriftCalibration::endJob().

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

Definition at line 234 of file DTCalibrationMap.cc.

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

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

Definition at line 59 of file DTCalibrationMap.h.

References theMap.

59  {
60  theMap.clear();
61  }
std::map< Key, CalibConsts > theMap
const DTCalibrationMap::CalibConsts * DTCalibrationMap::getConsts ( DTWireId  wireId) const

Definition at line 105 of file DTCalibrationMap.cc.

Referenced by DTVDriftCalibration::endJob().

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

Definition at line 131 of file DTCalibrationMap.cc.

References edm::hlt::Exception.

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

Definition at line 90 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().

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

Definition at line 81 of file DTCalibrationMap.h.

References theMap.

81  {
82  return theMap.begin();
83  }
std::map< Key, CalibConsts > theMap
const_iterator DTCalibrationMap::keyAndConsts_end ( ) const
inline

Definition at line 85 of file DTCalibrationMap.h.

References theMap.

85  {
86  return theMap.end();
87  }
std::map< Key, CalibConsts > theMap
float DTCalibrationMap::kFactor ( DTWireId  wireId) const

Return the kfactor for a particular wire.

Definition at line 68 of file DTCalibrationMap.cc.

68  {
69  return getField(wireId, 2);
70 }
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 75 of file DTCalibrationMap.cc.

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

Definition at line 146 of file DTCalibrationMap.cc.

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

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

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

Definition at line 82 of file DTCalibrationMap.cc.

82  {
83  return getField(wireId, 4);
84 }
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 61 of file DTCalibrationMap.cc.

61  {
62  return getField(wireId, 1);
63 }
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 54 of file DTCalibrationMap.cc.

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

Definition at line 215 of file DTCalibrationMap.cc.

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

Referenced by DTVDriftCalibration::endJob().

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

Member Data Documentation

std::string DTCalibrationMap::calibConstFileName
private

Definition at line 111 of file DTCalibrationMap.h.

std::string DTCalibrationMap::calibConstGranularity
private

Definition at line 114 of file DTCalibrationMap.h.

unsigned int DTCalibrationMap::nFields
private

Definition at line 108 of file DTCalibrationMap.h.

CalibGranularity DTCalibrationMap::theGranularity
private

Definition at line 96 of file DTCalibrationMap.h.

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

Definition at line 117 of file DTCalibrationMap.h.

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