CMS 3D CMS Logo

CSCGasGainCorrectionDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCGASGAINCORRECTIONDBCONDITIONS_H
2 #define _CSCGASGAINCORRECTIONDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
20 
22 public:
25 
27 
28  typedef std::unique_ptr<CSCDBGasGainCorrection> ReturnType;
29 
31 
32 private:
33  // ----------member data ---------------------------
35  const edm::IOVSyncValue &,
36  edm::ValidityInterval &) override;
37 
38  // Flag for determining if this is for setting MC or data corrections
39  bool isForMC;
40  // File for reading 55944 gas gain corrections. MC will be fake;
42 };
43 
47 
48 #include <fstream>
49 #include <iostream>
50 #include <vector>
51 
52 // to workaround plugin library
55  if (isMC)
56  printf("\n Generating fake DB constants for MC\n");
57  else {
58  printf("\n Reading gas gain corrections from file %s \n", filename.data());
59  }
60 
61  CSCIndexer indexer;
62 
63  const int MAX_SIZE = 55944;
64 
65  CSCDBGasGainCorrection *cndbGasGainCorr = new CSCDBGasGainCorrection();
66 
67  CSCDBGasGainCorrection::GasGainContainer &itemvector = cndbGasGainCorr->gasGainCorr;
68  itemvector.resize(MAX_SIZE);
69 
70  // Filling corrections for MC is very simple
71  if (isMC) {
72  for (int i = 0; i < MAX_SIZE; i++) {
73  itemvector[i].gainCorr = 1.;
74  }
75  return cndbGasGainCorr;
76  }
77 
78  struct gain_info {
79  int gas_gain_index;
80  int endcap;
81  int station;
82  int ring;
83  int chamber;
84  int layer;
85  int hvsegment;
86  int cfeb;
87  int nentries;
88  float mean;
89  float truncated_mean;
90  float gas_gain_correction;
91  } gains[MAX_SIZE];
92 
93  for (int j = 0; j < MAX_SIZE; j++) {
94  gains[j].gas_gain_index = -999;
95  gains[j].endcap = -999;
96  gains[j].station = -999;
97  gains[j].ring = -999;
98  gains[j].chamber = -999;
99  gains[j].layer = -999;
100  gains[j].hvsegment = -999;
101  gains[j].cfeb = -999;
102  gains[j].nentries = -999;
103  gains[j].mean = -999.;
104  gains[j].truncated_mean = -999.;
105  gains[j].gas_gain_correction = -999.;
106  }
107 
108  FILE *fin = fopen(filename.data(), "r");
109 
110  int linecounter = 0; // set the line counter to the first serial number in the file....
111 
112  while (!feof(fin)) {
113  // note space at end of format string to convert last \n
114  int check = fscanf(fin,
115  "%d %d %d %d %d %d %d %d %d %f %f %f \n",
116  &gains[linecounter].gas_gain_index,
117  &gains[linecounter].endcap,
118  &gains[linecounter].station,
119  &gains[linecounter].ring,
120  &gains[linecounter].chamber,
121  &gains[linecounter].layer,
122  &gains[linecounter].hvsegment,
123  &gains[linecounter].cfeb,
124  &gains[linecounter].nentries,
125  &gains[linecounter].mean,
126  &gains[linecounter].truncated_mean,
127  &gains[linecounter].gas_gain_correction);
128 
129  if (check != 12) {
130  printf("The input file format is not as expected\n");
131  assert(0);
132  }
133 
134  linecounter++;
135  }
136 
137  fclose(fin);
138 
139  if (linecounter == MAX_SIZE) {
140  std::cout << "Total number of gas gains read in = " << linecounter << std::endl;
141  } else {
142  std::cout << "ERROR: Total number of gas-gains read in = " << linecounter
143  << " while total number expected = " << MAX_SIZE << std::endl;
144  }
145 
146  // Fill the chip corrections with values from the file
147  for (int i = 0; i < MAX_SIZE; i++) {
148  itemvector[i].gainCorr = 0.;
149 
150  if (gains[i].gas_gain_correction > 0.) {
151  itemvector[i].gainCorr = gains[i].gas_gain_correction;
152  } else {
153  // if there is no value, this should be fixed...
154  std::cout << "ERROR: gas_gain_correction < 0 for index " << gains[i].gas_gain_index << std::endl;
155  }
156  }
157 
158  return cndbGasGainCorr;
159 }
160 
161 #endif
CSCGasGainCorrectionDBConditions(const edm::ParameterSet &)
std::unique_ptr< CSCDBGasGainCorrection > ReturnType
static CSCDBGasGainCorrection * prefillDBGasGainCorrection(bool isForMC, std::string dataCorrFileName)
ReturnType produceDBGasGainCorrection(const CSCDBGasGainCorrectionRcd &)
std::vector< Item > GasGainContainer
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
def check(config)
Definition: trackerTree.py:14