CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

DTCalibrationMap Class Reference

#include <DTCalibrationMap.h>

List of all members.

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.
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.
float meanVDrift (DTWireId wireId) const
 Return the mean drift velocity for a particular wire (cm/ns)
float sigma_meanVDrift (DTWireId wireId) const
 Return the sigma of the mean drift velocity for a particular wire (cm/ns)
float sigma_tTrig (DTWireId wireId) const
 Return the sigma of the t_trig (ns) for a particular wire.
float tTrig (DTWireId wireId) const
 Return the t_trig (ns) for a particular wire.
void writeConsts (const std::string &outputFileName) const
virtual ~DTCalibrationMap ()
 Destructor.

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

Enumerator:
byChamber 
bySL 
byLayer 
byWire 

Definition at line 95 of file DTCalibrationMap.h.


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().

                                                           {
  nFields =  pset.getUntrackedParameter<int>("nFields", 5);
  calibConstFileName = pset.getUntrackedParameter<string>("calibConstFileName", "dummy.txt");
  calibConstGranularity = pset.getUntrackedParameter<string>("calibConstGranularity","bySL");

  // Initialize correctly the enum which specify the granularity for the calibration
  if(calibConstGranularity == "byWire") {
    theGranularity = byWire;
  } else if(calibConstGranularity == "byLayer"){
    theGranularity = byLayer;
  } else if(calibConstGranularity == "bySL") {
    theGranularity = bySL;
  } else {
    theGranularity = byChamber;
    if(!(calibConstGranularity == "byChamber")) {
      cout << "[DTCalibrationMap]###Warning: Check parameter calibConstGranularity: "
           << calibConstGranularity << " options not available!" << endl;
    }
  }
  readConsts(calibConstFileName);
}
DTCalibrationMap::~DTCalibrationMap ( ) [virtual]

Destructor.

Definition at line 49 of file DTCalibrationMap.cc.

{}

Member Function Documentation

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

Definition at line 205 of file DTCalibrationMap.cc.

References Exception.

Referenced by DTVDriftCalibration::endJob().

                                                                        {
  if(!checkGranularity(theKey))
    throw cms::Exception("addCell") << "DTCalibrationMap:" << endl
                                    << "The added key is not compatible with the selected granularity"
                                    << endl;

  theMap[theKey] = calibConst;
}
bool DTCalibrationMap::checkGranularity ( Key  aKey) const [private]

Definition at line 234 of file DTCalibrationMap.cc.

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

                                                      {
  bool ret = true;

  // Check that the key is consistent with the given granularity
  if(theGranularity == byChamber) {
    if(aKey.superlayer() || aKey.layer() || aKey.wire()) {
      ret = false;
    }
  } else if(theGranularity == bySL) {
    if(aKey.layer() || aKey.wire()) {
      ret = false;
    }
  } else if(theGranularity == byLayer) {
    if(aKey.wire()) {
      ret = false;
    }
  } else if(theGranularity == byWire) {
    if(aKey.wire() == 0) {
      ret = false;
    }
  } 
  return ret;
}
void DTCalibrationMap::cleanTheConsts ( ) [inline]

Definition at line 59 of file DTCalibrationMap.h.

References theMap.

                        {
    theMap.clear();
  }
const DTCalibrationMap::CalibConsts * DTCalibrationMap::getConsts ( DTWireId  wireId) const

Definition at line 105 of file DTCalibrationMap.cc.

Referenced by DTVDriftCalibration::endJob().

                                                                                    {
  // Create a cache
  static pair<Key, CalibConsts> cache;

  // Get the key
  Key theKey = getKey(wireId);

  // Check if the result is already cached
  if ( theKey == cache.first ) {
    return &(cache.second);
  }

  // Look for the given key into the map
  map<Key, CalibConsts>::const_iterator res = theMap.find(theKey);
  if (res != theMap.end()) {
    cache = (*res);
    return &((*res).second);
  } else {
    return 0;
  }
}
float DTCalibrationMap::getField ( DTWireId  wireId,
int  field 
) const

Definition at line 131 of file DTCalibrationMap.cc.

References Exception.

                                                                 {
  const CalibConsts* cals = getConsts(wireId);
  if (cals == 0) {
    throw cms::Exception("NoCalibConsts") << "DTCalibrationMap:" << endl
                                                << "No parameters for wire: " << wireId << endl
                                                << "Check the " << calibConstFileName << " file!" << endl;
  } else {
    return (*(cals))[field];
  }
}
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().

                                                                  {
  if (theGranularity == byChamber){
    return Key(wireId.chamberId(), 0, 0, 0);
  } else if (theGranularity == bySL) {
    return Key(wireId.superlayerId(), 0, 0); 
  } else if (theGranularity == byLayer) {
    return Key(wireId.layerId(), 0);  
  } else {
    return Key(wireId);
  }
}
const_iterator DTCalibrationMap::keyAndConsts_begin ( ) const [inline]

Definition at line 81 of file DTCalibrationMap.h.

References theMap.

                                            {
    return theMap.begin();
  }
const_iterator DTCalibrationMap::keyAndConsts_end ( ) const [inline]

Definition at line 85 of file DTCalibrationMap.h.

References theMap.

                                          {
    return theMap.end();
  }
float DTCalibrationMap::kFactor ( DTWireId  wireId) const

Return the kfactor for a particular wire.

Definition at line 68 of file DTCalibrationMap.cc.

                                                     {
  return getField(wireId, 2);
}
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.

                                                        {
 return getField(wireId, 3);
}
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.

                                                             {
   ifstream file(inputFileName.c_str());
   // Check if the file exists
   if(!file) {
    cout << "[DTCalibrationMap]***Warning: File: " << inputFileName 
         << " not found in current directory!!!" << endl; 
   }

  string line;

  // The numbers to be read to build the key
  int wheel_id = 0;
  int station_id = 0;
  int sector_id = 0;
  int superlayer_id = 0;
  int layer_id = 0;
  int wire_id = 0;

  // Read all the lines
  while (getline(file,line)) {
    if( line == "" || line[0] == '#' ) continue; // Skip comments and empty lines
    stringstream linestr;
    linestr << line;

    pair<Key, CalibConsts> wireCalib;

    linestr >> wheel_id
            >> station_id
            >> sector_id
            >> superlayer_id
            >> layer_id
            >> wire_id;
    
    // Build the key
    wireCalib.first =  Key( wheel_id, 
                            station_id, 
                            sector_id, 
                            superlayer_id, 
                            layer_id, 
                            wire_id);

    if(!checkGranularity(wireCalib.first))
       cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the selected granularity!" << endl;


    // Read the calibration constants
    copy(istream_iterator<float>(linestr),
         istream_iterator<float>(),
         back_inserter(wireCalib.second));
    
    if(wireCalib.second.size() !=  nFields){
      cout << "[DTCalibrationMap]***Warning: the CalibConstFile is not consistent with the number of fields!" << endl;
    }
    
    theMap.insert(wireCalib);
  }
}
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.

                                                              {
 return getField(wireId, 4);
}
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.

                                                         {
 return getField(wireId, 1);
}
float DTCalibrationMap::tTrig ( DTWireId  wireId) const

Return the t_trig (ns) for a particular wire.

Definition at line 54 of file DTCalibrationMap.cc.

                                                   {
 return getField(wireId, 0);
}
void DTCalibrationMap::writeConsts ( const std::string &  outputFileName) const

Member Data Documentation

std::string DTCalibrationMap::calibConstFileName [private]

Definition at line 111 of file DTCalibrationMap.h.

Definition at line 114 of file DTCalibrationMap.h.

unsigned int DTCalibrationMap::nFields [private]

Definition at line 108 of file DTCalibrationMap.h.

Definition at line 96 of file DTCalibrationMap.h.

Definition at line 117 of file DTCalibrationMap.h.

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