CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CSCChipSpeedCorrectionDBConditions Class Reference

#include <CSCChipSpeedCorrectionDBConditions.h>

Inheritance diagram for CSCChipSpeedCorrectionDBConditions:
edm::ESProducer edm::EventSetupRecordIntervalFinder edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

Public Types

typedef std::unique_ptr< CSCDBChipSpeedCorrectionReturnType
 
- Public Types inherited from edm::eventsetup::DataProxyProvider
typedef std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
 
typedef std::vector< EventSetupRecordKeyKeys
 
typedef std::map< EventSetupRecordKey, KeyedProxiesRecordProxies
 

Public Member Functions

 CSCChipSpeedCorrectionDBConditions (const edm::ParameterSet &)
 
ReturnType produceDBChipSpeedCorrection (const CSCDBChipSpeedCorrectionRcd &)
 
 ~CSCChipSpeedCorrectionDBConditions () override
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
ESProxyIndex const * getTokenIndices (unsigned int iIndex) const
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &) final
 
 ~ESProducer ()(false) override
 
- Public Member Functions inherited from edm::ESProxyFactoryProducer
 ESProxyFactoryProducer ()
 
void newInterval (const eventsetup::EventSetupRecordKey &iRecordType, const ValidityInterval &iInterval) override
 overrides DataProxyProvider method More...
 
 ~ESProxyFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
 DataProxyProvider ()
 
const ComponentDescriptiondescription () const
 
bool isUsingRecord (const EventSetupRecordKey &) const
 
const KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey) const
 
void resetProxies (const EventSetupRecordKey &iRecordType)
 
void resetProxiesIfTransient (const EventSetupRecordKey &iRecordType)
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
const eventsetup::ComponentDescriptiondescriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
std::set< eventsetup::EventSetupRecordKeyfindingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder () noexcept(false)
 

Static Public Member Functions

static CSCDBChipSpeedCorrectionprefillDBChipSpeedCorrection (bool isForMC, std::string dataCorrFileName, float dataOffse)
 
- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Private Member Functions

void setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
 

Private Attributes

CSCDBChipSpeedCorrectioncndbChipCorr
 
std::string dataCorrFileName
 
float dataOffset
 
bool isForMC
 

Additional Inherited Members

- Protected Member Functions inherited from edm::ESProducer
 ESProducer (const ESProducer &)=delete
 
ESProducer const & operator= (const ESProducer &)=delete
 
template<typename T >
auto setWhatProduced (T *iThis, const es::Label &iLabel={})
 
template<typename T >
auto setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
auto setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
auto setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord >
auto setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord , typename TArg >
ESConsumesCollectorT< TRecord > setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
 
- Protected Member Functions inherited from edm::ESProxyFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const eventsetup::EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ProxyFactoryBase > iFactory, const std::string &iLabel=std::string())
 
void registerProxies (const eventsetup::EventSetupRecordKey &iRecord, KeyedProxies &aProxyList) override
 override DataProxyProvider method More...
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
void eraseAll (const EventSetupRecordKey &iRecordKey)
 deletes all the Proxies in aStream More...
 
void invalidateProxies (const EventSetupRecordKey &iRecordKey)
 
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &)
 
- Protected Member Functions inherited from edm::EventSetupRecordIntervalFinder
template<class T >
void findingRecord ()
 
void findingRecordWithKey (const eventsetup::EventSetupRecordKey &)
 

Detailed Description

Definition at line 21 of file CSCChipSpeedCorrectionDBConditions.h.

Member Typedef Documentation

Definition at line 30 of file CSCChipSpeedCorrectionDBConditions.h.

Constructor & Destructor Documentation

CSCChipSpeedCorrectionDBConditions::CSCChipSpeedCorrectionDBConditions ( const edm::ParameterSet iConfig)

Definition at line 8 of file CSCChipSpeedCorrectionDBConditions.cc.

References dataCorrFileName, dataOffset, edm::ParameterSet::getUntrackedParameter(), isForMC, produceDBChipSpeedCorrection(), edm::ESProducer::setWhatProduced(), and AlCaHLTBitMon_QueryRunRegistry::string.

8  {
9  // the following line is needed to tell the framework what
10  // data is being produced
11  isForMC = iConfig.getUntrackedParameter<bool>("isForMC", true);
12  dataCorrFileName = iConfig.getUntrackedParameter<std::string>("dataCorrFileName", "empty.txt");
13  dataOffset = 170.;
14  // added by Zhen (changed since 1_2_0)
16  findingRecord<CSCDBChipSpeedCorrectionRcd>();
17  // now do what ever other initialization is needed
18 }
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
T getUntrackedParameter(std::string const &, T const &) const
ReturnType produceDBChipSpeedCorrection(const CSCDBChipSpeedCorrectionRcd &)
CSCChipSpeedCorrectionDBConditions::~CSCChipSpeedCorrectionDBConditions ( )
override

Definition at line 20 of file CSCChipSpeedCorrectionDBConditions.cc.

20  {
21  // do anything here that needs to be done at desctruction time
22  // (e.g. close files, deallocate resources etc.)
23 }

Member Function Documentation

CSCDBChipSpeedCorrection * CSCChipSpeedCorrectionDBConditions::prefillDBChipSpeedCorrection ( bool  isForMC,
std::string  dataCorrFileName,
float  dataOffse 
)
inlinestatic

Definition at line 58 of file CSCChipSpeedCorrectionDBConditions.h.

References relativeConstraints::chamber, CSCDetId::chamber(), trackerTree::check(), CSCIndexer::chipIndex(), CSCDBChipSpeedCorrection::chipSpeedCorr, cndbChipCorr, CSCIndexer::detIdFromChamberIndex(), dt, CSCDetId::endcap(), makeMuonMisalignmentScenario::endcap, CSCDBChipSpeedCorrection::factor_speedCorr, groupFilesInBlocks::fin, mps_fire::i, createfilelist::int, relativeConstraints::ring, CSCDetId::ring(), relativeConstraints::station, CSCDetId::station(), and protons_cff::t.

Referenced by produceDBChipSpeedCorrection().

60  {
61  if (isMC)
62  printf("\n Generating fake DB constants for MC\n");
63  else {
64  printf("\n Reading chip corrections from file %s \n", filename.data());
65  printf("my data offset value is %f \n", dataOffset);
66  }
67 
68  CSCIndexer indexer;
69 
70  const int CHIP_FACTOR = 100;
71  const int MAX_SIZE = 15768;
72  const int MAX_SHORT = 32767;
74 
76  itemvector.resize(MAX_SIZE);
77  cndbChipCorr->factor_speedCorr = int(CHIP_FACTOR);
78 
79  // Fill chip corrections for MC is very simple
80  if (isMC) {
81  for (int i = 0; i < MAX_SIZE; i++) {
82  itemvector[i].speedCorr = 0;
83  }
84  return cndbChipCorr;
85  }
86 
87  // Filling for data takes a little more time
88  FILE *fin = fopen(filename.data(), "r");
89 
90  int serialChamber, endcap, station, ring, chamber, chip;
91  float t, dt;
92  int nPulses;
93 
94  std::vector<int> new_index_id;
95  std::vector<float> new_chipPulse;
96  double runningTotal = 0;
97  int numNonZero = 0;
98  while (!feof(fin)) {
99  // note space at end of format string to convert last \n
100  // int check = fscanf(fin,"%d %d %f %f \n",&serialChamber,&chip,&t,&dt);
101  int check = fscanf(fin,
102  "%d %d %d %d %d %d %f %f %d \n",
103  &serialChamber,
104  &endcap,
105  &station,
106  &ring,
107  &chamber,
108  &chip,
109  &t,
110  &dt,
111  &nPulses);
112  if (check != 9) {
113  printf("The input file format is not as expected\n");
114  assert(0);
115  }
116 
117  int serialChamber_safecopy = serialChamber;
118  // Now to map from S. Durkin's serialChamber index convention
119  // ME+1/1-ME+41 = 1 -234
120  // ME+4/2 = 235-270*
121  // ME-1/1-ME-41 = 271-504*
122  // ME-4/2 = 505-540
123  // To the convention used in /DataFormats/MuonDetId/interface/CSCIndexer.h
124  // ME+1/1-ME+41 = 1 -234
125  // ME+4/2 = 469-504*
126  // ME-1/1-ME-41 = 235-468*
127  // ME-4/2 = 505-540
128  // Only the chambers marked * need to be remapped
129 
130  if (serialChamber >= 235 && serialChamber <= 270)
131  serialChamber += 234;
132  else { // not in ME+4\2
133  if (serialChamber >= 271 && serialChamber <= 504)
134  serialChamber -= 36;
135  }
136 
137  CSCDetId chamberId = indexer.detIdFromChamberIndex(serialChamber);
138  // Now to map from S. Durkin's chip index convention 0-29 (with
139  // 4,9,14,19,24,29 unused in ME1/3) To the convention used in
140  // /DataFormats/MuonDetId/interface/CSCIndexer.h Layer 1-6 and chip 1-5 for
141  // all chambers except ME1/3 which is chip 1-4
142  int layer = (chip) / 5 + 1;
143  CSCDetId cscId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), layer);
144  // This should yield the same CSCDetId as decoding the chamber serial does
145  // If not, some debugging is needed
146  CSCDetId cscId_doubleCheck(endcap, station, ring, chamber, layer);
147  if (cscId != cscId_doubleCheck) {
148  printf("Why doesn't chamberSerial %d map to e: %d s: %d r: %d c: %d ? \n",
149  serialChamber_safecopy,
150  endcap,
151  station,
152  ring,
153  chamber);
154  assert(0);
155  }
156 
157  chip = (chip % 5) + 1;
158  // The file produced by Stan starts from the geometrical strip number stored
159  // in the CSCStripDigi When the strip digis are built, the conversion from
160  // electronics channel to geometrical strip (reversing ME+1/1a and, more
161  // importantly, ME-1/1b) is done before the digi is filled
162  // (EventFilter/CSCRawToDigi/src/CSCCFEBData.cc). Since we're filling an
163  // electronics channel database, I'll flip again ME-1/1b
164  if (endcap == 2 && station == 1 && ring == 1 && chip < 5) {
165  chip = 5 - chip; // change 1-4 to 4-1
166  }
167 
168  new_index_id.push_back(indexer.chipIndex(cscId, chip));
169  new_chipPulse.push_back(t);
170  if (t != 0) {
171  runningTotal += t;
172  numNonZero++;
173  }
174  }
175  fclose(fin);
176 
177  // Fill the chip corrections with zeros to start
178  for (int i = 0; i < MAX_SIZE; i++) {
179  itemvector[i].speedCorr = 0;
180  }
181 
182  for (unsigned int i = 0; i < new_index_id.size(); i++) {
183  if ((short int)(fabs((dataOffset - new_chipPulse[i]) * CHIP_FACTOR + 0.5)) < MAX_SHORT)
184  itemvector[new_index_id[i] - 1].speedCorr =
185  (short int)((dataOffset - new_chipPulse[i]) * CHIP_FACTOR + 0.5 * (dataOffset >= new_chipPulse[i]) -
186  0.5 * (dataOffset < new_chipPulse[i]));
187  // printf("i= %d \t new index id = %d \t corr = %f \n",i,new_index_id[i],
188  // new_chipPulse[i]);
189  }
190 
191  // For now, calculate the mean chip correction and use it for all chambers
192  // that don't have calibration pulse data (speedCorr ==0) or had values of
193  // zero (speedCorr == dataOffset) This should be a temporary fix until all
194  // chips that will read out in data have calibration information Since there
195  // is only a handful out of 15K chips with values more than 3 ns away from the
196  // average, this is probably very safe to first order
197  float ave = runningTotal / numNonZero;
198  for (int i = 0; i < MAX_SIZE; i++) {
199  if (itemvector[i].speedCorr == 0 || itemvector[i].speedCorr == (short int)(dataOffset * CHIP_FACTOR + 0.5))
200  itemvector[i].speedCorr =
201  (short int)((dataOffset - ave) * CHIP_FACTOR + 0.5 * (dataOffset >= ave) - 0.5 * (dataOffset < ave));
202  }
203 
204  return cndbChipCorr;
205 }
int chamber() const
Definition: CSCDetId.h:68
float dt
Definition: AMPTWrapper.h:126
int endcap() const
Definition: CSCDetId.h:93
CSCDetId detIdFromChamberIndex(IndexType ici) const
Definition: CSCIndexer.cc:62
int ring() const
Definition: CSCDetId.h:75
IndexType chipIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType ichip) const
Definition: CSCIndexer.h:237
std::vector< Item > ChipSpeedContainer
int station() const
Definition: CSCDetId.h:86
def check(config)
Definition: trackerTree.py:14
CSCChipSpeedCorrectionDBConditions::ReturnType CSCChipSpeedCorrectionDBConditions::produceDBChipSpeedCorrection ( const CSCDBChipSpeedCorrectionRcd iRecord)

Definition at line 30 of file CSCChipSpeedCorrectionDBConditions.cc.

References dataCorrFileName, dataOffset, isForMC, and prefillDBChipSpeedCorrection().

Referenced by CSCChipSpeedCorrectionDBConditions().

31  {
32  // need a new object so to not be deleted at exit
35 }
static CSCDBChipSpeedCorrection * prefillDBChipSpeedCorrection(bool isForMC, std::string dataCorrFileName, float dataOffse)
std::unique_ptr< CSCDBChipSpeedCorrection > ReturnType
void CSCChipSpeedCorrectionDBConditions::setIntervalFor ( const edm::eventsetup::EventSetupRecordKey ,
const edm::IOVSyncValue ,
edm::ValidityInterval oValidity 
)
overrideprivatevirtual

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 37 of file CSCChipSpeedCorrectionDBConditions.cc.

References edm::IOVSyncValue::beginOfTime(), and edm::IOVSyncValue::endOfTime().

39  {
41 }
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88

Member Data Documentation

CSCDBChipSpeedCorrection* CSCChipSpeedCorrectionDBConditions::cndbChipCorr
private

Definition at line 39 of file CSCChipSpeedCorrectionDBConditions.h.

Referenced by prefillDBChipSpeedCorrection().

std::string CSCChipSpeedCorrectionDBConditions::dataCorrFileName
private
float CSCChipSpeedCorrectionDBConditions::dataOffset
private
bool CSCChipSpeedCorrectionDBConditions::isForMC
private