CMS 3D CMS Logo

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 37 of file DTCalibrationMap.h.

Member Typedef Documentation

◆ CalibConsts

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

Definition at line 62 of file DTCalibrationMap.h.

◆ const_iterator

Definition at line 64 of file DTCalibrationMap.h.

◆ Key

Definition at line 63 of file DTCalibrationMap.h.

Member Enumeration Documentation

◆ CalibGranularity

Constructor & Destructor Documentation

◆ DTCalibrationMap()

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

Constructor.

Definition at line 23 of file DTCalibrationMap.cc.

References gather_cfg::cout, and muonDTDigis_cfi::pset.

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: " << calibConstGranularity
39  << " options not available!" << endl;
40  }
41  }
43 }
CalibGranularity theGranularity
std::string calibConstGranularity
std::string calibConstFileName
unsigned int nFields
void readConsts(const std::string &inputFileName)

◆ ~DTCalibrationMap()

DTCalibrationMap::~DTCalibrationMap ( )
virtual

Destructor.

Definition at line 45 of file DTCalibrationMap.cc.

45 {}

Member Function Documentation

◆ addCell()

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

Definition at line 160 of file DTCalibrationMap.cc.

References Exception.

Referenced by DTVDriftCalibration::endJob().

160  {
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 }
std::map< Key, CalibConsts > theMap
bool checkGranularity(Key aKey) const

◆ checkGranularity()

bool DTCalibrationMap::checkGranularity ( Key  aKey) const
private

Definition at line 180 of file DTCalibrationMap.cc.

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

180  {
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 }
ret
prodAgent to be discontinued
CalibGranularity theGranularity

◆ cleanTheConsts()

void DTCalibrationMap::cleanTheConsts ( )
inline

Definition at line 67 of file DTCalibrationMap.h.

References theMap.

67 { theMap.clear(); }
std::map< Key, CalibConsts > theMap

◆ getConsts()

const DTCalibrationMap::CalibConsts * DTCalibrationMap::getConsts ( DTWireId  wireId) const

Definition at line 77 of file DTCalibrationMap.cc.

References utilities::cache().

Referenced by DTVDriftCalibration::endJob().

77  {
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 }
std::map< Key, CalibConsts > theMap
Definition: Electron.h:6
Key getKey(DTWireId wireId) const
def cache(function)
Definition: utilities.py:3

◆ getField()

float DTCalibrationMap::getField ( DTWireId  wireId,
int  field 
) const

Definition at line 101 of file DTCalibrationMap.cc.

References Exception.

101  {
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 }
std::string calibConstFileName
const CalibConsts * getConsts(DTWireId wireId) const
std::vector< float > CalibConsts

◆ getKey()

DTCalibrationMap::Key DTCalibrationMap::getKey ( DTWireId  wireId) const

Definition at line 64 of file DTCalibrationMap.cc.

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

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

64  {
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 }
CalibGranularity theGranularity
DTChamberId chamberId() const
Return the corresponding ChamberId.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:48

◆ keyAndConsts_begin()

const_iterator DTCalibrationMap::keyAndConsts_begin ( ) const
inline

Definition at line 86 of file DTCalibrationMap.h.

References theMap.

86 { return theMap.begin(); }
std::map< Key, CalibConsts > theMap

◆ keyAndConsts_end()

const_iterator DTCalibrationMap::keyAndConsts_end ( ) const
inline

Definition at line 88 of file DTCalibrationMap.h.

References theMap.

88 { return theMap.end(); }
std::map< Key, CalibConsts > theMap

◆ kFactor()

float DTCalibrationMap::kFactor ( DTWireId  wireId) const

Return the kfactor for a particular wire.

Definition at line 54 of file DTCalibrationMap.cc.

References CaloRecHitAuxSetter::getField().

54 { return getField(wireId, 2); }
float getField(DTWireId wireId, int field) const

◆ meanVDrift()

float DTCalibrationMap::meanVDrift ( DTWireId  wireId) const

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

Definition at line 57 of file DTCalibrationMap.cc.

References CaloRecHitAuxSetter::getField().

57 { return getField(wireId, 3); }
float getField(DTWireId wireId, int field) const

◆ readConsts()

void DTCalibrationMap::readConsts ( const std::string &  inputFileName)
private

Definition at line 113 of file DTCalibrationMap.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, geometryDiff::file, InefficientDoubleROC::inputFileName, and mps_splice::line.

113  {
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 }
std::map< Key, CalibConsts > theMap
unsigned int nFields
bool checkGranularity(Key aKey) const

◆ sigma_meanVDrift()

float DTCalibrationMap::sigma_meanVDrift ( DTWireId  wireId) const

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

Definition at line 60 of file DTCalibrationMap.cc.

References CaloRecHitAuxSetter::getField().

60 { return getField(wireId, 4); }
float getField(DTWireId wireId, int field) const

◆ sigma_tTrig()

float DTCalibrationMap::sigma_tTrig ( DTWireId  wireId) const

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

Definition at line 51 of file DTCalibrationMap.cc.

References CaloRecHitAuxSetter::getField().

51 { return getField(wireId, 1); }
float getField(DTWireId wireId, int field) const

◆ tTrig()

float DTCalibrationMap::tTrig ( DTWireId  wireId) const

Return the t_trig (ns) for a particular wire.

Definition at line 48 of file DTCalibrationMap.cc.

References CaloRecHitAuxSetter::getField().

48 { return getField(wireId, 0); }
float getField(DTWireId wireId, int field) const

◆ writeConsts()

void DTCalibrationMap::writeConsts ( const std::string &  outputFileName) const

Definition at line 169 of file DTCalibrationMap.cc.

References filterCSVwithJSON::copy, MillePedeFileConverter_cfg::out, and makeListRunsInFiles::outputFileName.

Referenced by DTVDriftCalibration::endJob().

169  {
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 }
std::map< Key, CalibConsts > theMap

Member Data Documentation

◆ calibConstFileName

std::string DTCalibrationMap::calibConstFileName
private

Definition at line 106 of file DTCalibrationMap.h.

◆ calibConstGranularity

std::string DTCalibrationMap::calibConstGranularity
private

Definition at line 109 of file DTCalibrationMap.h.

◆ nFields

unsigned int DTCalibrationMap::nFields
private

Definition at line 103 of file DTCalibrationMap.h.

◆ theGranularity

CalibGranularity DTCalibrationMap::theGranularity
private

Definition at line 94 of file DTCalibrationMap.h.

◆ theMap

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

Definition at line 112 of file DTCalibrationMap.h.

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