CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCGainsConditions.cc
Go to the documentation of this file.
1 #include <fstream>
2 
4 
6 
7  float mean,min,minchi;
8  int seed;
9  int old_chamber_id,old_strip,new_chamber_id,new_strip;
10  float old_gainslope,old_intercpt, old_chisq;
11  std::vector<int> old_cham_id;
12  std::vector<int> old_strips;
13  std::vector<float> old_slope;
14  std::vector<float> old_intercept;
15  std::vector<float> old_chi2;
16  float new_gainslope,new_intercpt, new_chisq;
17  std::vector<int> new_cham_id;
18  std::vector<int> new_strips;
19  std::vector<float> new_slope;
20  std::vector<float> new_intercept;
21  std::vector<float> new_chi2;
22 
23  const CSCDetId& detId = CSCDetId();
24  CSCGains * cngains = new CSCGains();
25 
26  int max_istrip,id_layer,max_ring,max_cham;
27  unsigned int old_nrlines=0;
28  unsigned int new_nrlines=0;
29  seed = 10000;
30  srand(seed);
31  mean=6.8, min=-10.0, minchi=1.0;
32 
33  std::ifstream olddata;
34  olddata.open("old_gains.dat",std::ios::in);
35  if(!olddata) {
36  std::cerr <<"Error: old_gains.dat -> no such file!"<< std::endl;
37  exit(1);
38  }
39 
40  while (!olddata.eof() ) {
41  olddata >> old_chamber_id >> old_strip >> old_gainslope >> old_intercpt >> old_chisq ;
42  old_cham_id.push_back(old_chamber_id);
43  old_strips.push_back(old_strip);
44  old_slope.push_back(old_gainslope);
45  old_intercept.push_back(old_intercpt);
46  old_chi2.push_back(old_chisq);
47  old_nrlines++;
48  }
49  olddata.close();
50 
51  std::ifstream newdata;
52  newdata.open("new_gains.txt",std::ios::in);
53  if(!newdata) {
54  std::cerr <<"Error: new_gains.txt -> no such file!"<< std::endl;
55  exit(1);
56  }
57 
58  while (!newdata.eof() ) {
59  newdata >> new_chamber_id >> new_strip >> new_gainslope >> new_intercpt >> new_chisq ;
60  new_cham_id.push_back(new_chamber_id);
61  new_strips.push_back(new_strip);
62  new_slope.push_back(new_gainslope);
63  new_intercept.push_back(new_intercpt);
64  new_chi2.push_back(new_chisq);
65  new_nrlines++;
66  }
67  newdata.close();
68 
69 
70  //endcap=1 to 2,station=1 to 4, ring=1 to 4,chamber=1 to 36,layer=1 to 6
71  for(int iendcap=detId.minEndcapId(); iendcap<=detId.maxEndcapId(); iendcap++){
72  for(int istation=detId.minStationId() ; istation<=detId.maxStationId(); istation++){
73  max_ring=detId.maxRingId();
74  //station 4 ring 4 not there(36 chambers*2 missing)
75  //3 rings max this way of counting (ME1a & b)
76  if(istation==1) max_ring=3;
77  if(istation==2) max_ring=2;
78  if(istation==3) max_ring=2;
79  if(istation==4) max_ring=1;
80 
81  for(int iring=detId.minRingId(); iring<=max_ring; iring++){
82  max_istrip=80;
83  max_cham=detId.maxChamberId();
84  if(istation==1 && iring==1) max_cham=36;
85  if(istation==1 && iring==2) max_cham=36;
86  if(istation==1 && iring==3) max_cham=36;
87  if(istation==2 && iring==1) max_cham=18;
88  if(istation==2 && iring==2) max_cham=36;
89  if(istation==3 && iring==1) max_cham=18;
90  if(istation==3 && iring==2) max_cham=36;
91  if(istation==4 && iring==1) max_cham=18;
92 
93  for(int ichamber=detId.minChamberId(); ichamber<=max_cham; ichamber++){
94  for(int ilayer=detId.minLayerId(); ilayer<=detId.maxLayerId(); ilayer++){
95  //station 1 ring 3 has 64 strips per layer instead of 80
96  if(istation==1 && iring==3) max_istrip=64;
97 
98  std::vector<CSCGains::Item> itemvector;
99  itemvector.resize(max_istrip);
100  id_layer = 100000*iendcap + 10000*istation + 1000*iring + 10*ichamber + ilayer;
101 
102  for(int istrip=0;istrip<max_istrip;istrip++){
103  itemvector[istrip].gain_slope=((double)rand()/((double)(RAND_MAX)+(double)(1)))+mean;
104  itemvector[istrip].gain_intercept=((double)rand()/((double)(RAND_MAX)+(double)(1)))+min;
105  itemvector[istrip].gain_chi2=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
106  cngains->gains[id_layer]=itemvector;
107  }
108  }
109  }
110  }
111  }
112  }
113 
114  //overwrite fakes with old values from DB
115  int istrip = 0;
116  std::vector<CSCGains::Item> itemvector;
117  itemvector.resize(80);
118 
119  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
120  if(old_strips[mystrip]==0) istrip = 0;
121  itemvector[istrip].gain_slope=old_slope[mystrip];
122  itemvector[istrip].gain_intercept=old_intercept[mystrip];
123  itemvector[istrip].gain_chi2=old_chi2[mystrip];
124  cngains->gains[old_cham_id[mystrip]]=itemvector;
125  istrip++;
126  }
127 
128 
129  itemvector.resize(64);
130  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
131  if(old_strips[mystrip]==0) istrip = 0;
132  if(old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999){
133  itemvector[istrip].gain_slope=old_slope[mystrip];
134  itemvector[istrip].gain_intercept=old_intercept[mystrip];
135  itemvector[istrip].gain_chi2=old_chi2[mystrip];
136  cngains->gains[old_cham_id[mystrip]]=itemvector;
137  istrip++;
138  }
139  }
140 
141  itemvector.resize(64);
142  for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
143  if(old_strips[mystrip]==0) istrip = 0;
144  if(old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999){
145  itemvector[istrip].gain_slope=old_slope[mystrip];
146  itemvector[istrip].gain_intercept=old_intercept[mystrip];
147  itemvector[istrip].gain_chi2=old_chi2[mystrip];
148  cngains->gains[old_cham_id[mystrip]]=itemvector;
149  istrip++;
150  }
151  }
152 
153  //overwrite old values with ones from new runs
154  itemvector.resize(80);
155  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
156  if(new_strips[mystrip]==0) istrip = 0;
157  itemvector[istrip].gain_slope=new_slope[mystrip];
158  itemvector[istrip].gain_intercept=new_intercept[mystrip];
159  itemvector[istrip].gain_chi2=new_chi2[mystrip];
160  cngains->gains[new_cham_id[mystrip]]=itemvector;
161  istrip++;
162  }
163 
164  itemvector.resize(64);
165  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
166  if(new_strips[mystrip]==0) istrip = 0;
167  if(new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999){
168  itemvector[istrip].gain_slope=new_slope[mystrip];
169  itemvector[istrip].gain_intercept=new_intercept[mystrip];
170  itemvector[istrip].gain_chi2=new_chi2[mystrip];
171  cngains->gains[new_cham_id[mystrip]]=itemvector;
172  istrip++;
173  }
174  }
175 
176  itemvector.resize(64);
177  for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
178  if(new_strips[mystrip]==0) istrip = 0;
179  if(new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999){
180  itemvector[istrip].gain_slope=new_slope[mystrip];
181  itemvector[istrip].gain_intercept=new_intercept[mystrip];
182  itemvector[istrip].gain_chi2=new_chi2[mystrip];
183  cngains->gains[new_cham_id[mystrip]]=itemvector;
184  istrip++;
185  }
186  }
187  return cngains;
188 }
189 
190 
192 {
193  //the following line is needed to tell the framework what
194  // data is being produced
195  cnGains = prefillGains();
196  // added by Zhen (changed since 1_2_0)
198  findingRecord<CSCGainsRcd>();
199  //now do what ever other initialization is needed
200 }
201 
202 
204 {
205 
206  // do anything here that needs to be done at desctruction time
207  // (e.g. close files, deallocate resources etc.)
208  delete cnGains;
209 }
210 
211 
212 //
213 // member functions
214 //
215 
216 // ------------ method called to produce the data ------------
219 {
220  // Added by Zhen, need a new object so to not be deleted at exit
221  CSCGains* mydata=new CSCGains( *cnGains );
222 
223  return mydata;
224 
225 }
226 
228  edm::ValidityInterval & oValidity)
229  {
231 
232  }
static int minRingId()
Definition: CSCDetId.h:242
CSCGainsConditions(const edm::ParameterSet &)
GainsMap gains
Definition: CSCGains.h:22
static int minEndcapId()
Definition: CSCDetId.h:238
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
#define min(a, b)
Definition: mlp_lapack.h:161
static int maxStationId()
Definition: CSCDetId.h:241
static int maxRingId()
Definition: CSCDetId.h:243
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
static int minChamberId()
Definition: CSCDetId.h:244
static CSCGains * prefillGains()
static const IOVSyncValue & beginOfTime()
static int minStationId()
Definition: CSCDetId.h:240
static int maxEndcapId()
Definition: CSCDetId.h:239
static int minLayerId()
Definition: CSCDetId.h:246
static int maxChamberId()
Definition: CSCDetId.h:245
ReturnType produceGains(const CSCGainsRcd &)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
Signal rand(Signal arg)
Definition: vlib.cc:442
static int maxLayerId()
Definition: CSCDetId.h:247