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 ()
 
 ~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
template<typename T >
void setWhatProduced (T *iThis, const es::Label &iLabel=es::Label())
 
template<typename T >
void setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
void setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
void setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel=es::Label())
 
template<typename T , typename TReturn , typename TRecord >
void setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel=es::Label())
 
template<typename T , typename TReturn , typename TRecord , typename TArg >
void setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel=es::Label())
 
- 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 28 of file CSCChipSpeedCorrectionDBConditions.h.

Constructor & Destructor Documentation

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

Definition at line 9 of file CSCChipSpeedCorrectionDBConditions.cc.

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

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

Definition at line 24 of file CSCChipSpeedCorrectionDBConditions.cc.

25 {
26 
27  // do anything here that needs to be done at desctruction time
28  // (e.g. close files, deallocate resources etc.)
29 }

Member Function Documentation

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

Definition at line 56 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 lumiQTWidget::t.

Referenced by produceDBChipSpeedCorrection().

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

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 45 of file CSCChipSpeedCorrectionDBConditions.cc.

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

47 {
49 
50 }
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
static const IOVSyncValue & beginOfTime()

Member Data Documentation

CSCDBChipSpeedCorrection* CSCChipSpeedCorrectionDBConditions::cndbChipCorr
private

Definition at line 35 of file CSCChipSpeedCorrectionDBConditions.h.

Referenced by prefillDBChipSpeedCorrection().

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