CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCChamberTimeCorrectionsValues.h
Go to the documentation of this file.
1 #ifndef _CSCCCHAMBERTIMECORRECTIONSVALUES_H
2 #define _CSCCCHAMBERTIMECORRECTIONSVALUES_H
3 
4 #include <memory>
14 
20 
22 
24  public:
27 
28  inline static CSCChamberTimeCorrections * prefill(bool isMC, float ME11offset, float nonME11offset);
29 
31 
33 
34  private:
35  // ----------member data ---------------------------
38 
39  //Flag for determining if this is for setting MC or data corrections
40  bool isForMC;
41  float ME11offsetMC;
45 
46 };
47 
48 #include<fstream>
49 #include<vector>
50 #include<iostream>
51 
52 // to workaround plugin library
53 inline CSCChamberTimeCorrections * CSCChamberTimeCorrectionsValues::prefill(bool isMC, float ME11offset, float nonME11offset)
54 {
55  if (isMC)
56  printf("\n Generating fake DB constants for MC\n");
57  else
58  printf("\n Getting chamber corrections from the cable data base and possibly other files \n");
59 
60  const int FACTOR=100;
61  const int MAX_SIZE = 540;
62  //const int MAX_SHORT= 32767;
63 
65 
66  int i; //i - chamber index.
67  int count=0;
68  std::string chamber_label, cfeb_rev, alct_rev;
69  float cfeb_length=0, alct_length=0, cfeb_tmb_skew_delay=0, cfeb_timing_corr=0;
70 
71  // Only the first 481 chambers have interesting cable lengths at present
72  // The rest of the chambers will be filled with zeros
73  chamberObj->factor_precision = FACTOR;
74 
75  chamberObj->chamberCorrections.resize(MAX_SIZE);
76  // fill the database with dummy values
77  for(i=1;i<=MAX_SIZE;++i){
78  chamberObj->chamberCorrections[i-1].cfeb_length=0;
79  chamberObj->chamberCorrections[i-1].cfeb_rev='X';
80  chamberObj->chamberCorrections[i-1].alct_length=0;
81  chamberObj->chamberCorrections[i-1].alct_rev='X';
82  chamberObj->chamberCorrections[i-1].cfeb_tmb_skew_delay=0;
83  chamberObj->chamberCorrections[i-1].cfeb_timing_corr=0;
84  chamberObj->chamberCorrections[i-1].cfeb_cable_delay=0;
85  chamberObj->chamberCorrections[i-1].anode_bx_offset=0;
86  }
87 
88 
89  // for MC there will is a different correction for each chamber type
90  if (isMC){
91  float OffsetByType;
92  float anodeOffset;
93  for(i=1;i<=MAX_SIZE;++i){
94  if (i<= 36 || (i>= 235 && i<=270)) { OffsetByType=172.; anodeOffset=6.18; }// 1/1
95  else if (i<= 72 || (i>= 271 && i<=306)) { OffsetByType=168.; anodeOffset=6.22; }// 1/2
96  else if (i<= 108 || (i>= 307 && i<=342)) { OffsetByType=177.; anodeOffset=6.19; }// 1/3
97  else if (i<= 126 || (i>= 343 && i<=360)) { OffsetByType=171.; anodeOffset=6.25; }// 2/1
98  else if (i<= 162 || (i>= 361 && i<=396)) { OffsetByType=175.; anodeOffset=6.21; }// 2/2
99  else if (i<= 180 || (i>= 397 && i<=414)) { OffsetByType=171.; anodeOffset=6.25; }// 3/1
100  else if (i<= 216 || (i>= 415 && i<=450)) { OffsetByType=175.; anodeOffset=6.20; }// 3/2
101  else if (i<= 234 || (i>= 451 && i<=468)) { OffsetByType=172.; anodeOffset=6.19; }// 4/1
102  else {OffsetByType=175; anodeOffset=6.21; }// 4/2
103 
104  chamberObj->chamberCorrections[i-1].cfeb_timing_corr=(short int)(-1*OffsetByType*FACTOR+0.5*(-1*OffsetByType>=0)-0.5*(-1*OffsetByType<0));
105  chamberObj->chamberCorrections[i-1].anode_bx_offset =(short int)(anodeOffset *FACTOR+0.5*(anodeOffset >=0)-0.5*(anodeOffset <0));
106  }
107 
108  return chamberObj;
109  }
110 
111  // ***************************************************************************
112  // Everything below this point is for setting the chamber corrections for data
113  // ***************************************************************************
114 
115  csccableread *cable = new csccableread ();
116  for(i=1;i<=MAX_SIZE;++i){
117  // the anode bx offset is 8.15 bx for chambers in 2/1, 3/1, and 4/1
118  // and 8.18 bx for all other chambers for early runs (8.20 for runs> 149357)
119  float anodeOffset;
120  if (i<= 36 || (i>= 235 && i<=270)) { anodeOffset=8.20; }// 1/1
121  else if (i<= 72 || (i>= 271 && i<=306)) { anodeOffset=8.20; }// 1/2
122  else if (i<= 108 || (i>= 307 && i<=342)) { anodeOffset=8.20; }// 1/3
123  else if (i<= 126 || (i>= 343 && i<=360)) { anodeOffset=8.15; }// 2/1
124  else if (i<= 162 || (i>= 361 && i<=396)) { anodeOffset=8.20; }// 2/2
125  else if (i<= 180 || (i>= 397 && i<=414)) { anodeOffset=8.15; }// 3/1
126  else if (i<= 216 || (i>= 415 && i<=450)) { anodeOffset=8.20; }// 3/2
127  else if (i<= 234 || (i>= 451 && i<=468)) { anodeOffset=8.15; }// 4/1
128  else {anodeOffset=8.20; }// 4/2
129 
130  // for data we will read in from Igor's database
131  cable->cable_read(i, &chamber_label, &cfeb_length, &cfeb_rev, &alct_length,
132  &alct_rev, &cfeb_tmb_skew_delay, &cfeb_timing_corr);
133  // If the read of the cable database is useful (if there is information for the chamber there)
134  // re-enter the information the cable object
135  if(!chamber_label.empty() && !(cfeb_length==0)){
136  chamberObj->chamberCorrections[i-1].cfeb_length=(short int)(cfeb_length*FACTOR+0.5);
137  chamberObj->chamberCorrections[i-1].cfeb_rev=cfeb_rev[0];
138  chamberObj->chamberCorrections[i-1].alct_length=(short int)(alct_length*FACTOR+0.5);
139  chamberObj->chamberCorrections[i-1].alct_rev=alct_rev[0];
140  chamberObj->chamberCorrections[i-1].cfeb_tmb_skew_delay=(short int)(cfeb_tmb_skew_delay*FACTOR+0.5);
141  chamberObj->chamberCorrections[i-1].cfeb_timing_corr=(short int)(cfeb_timing_corr*FACTOR+0.5);
142  chamberObj->chamberCorrections[i-1].cfeb_cable_delay=0;
143  chamberObj->chamberCorrections[i-1].anode_bx_offset=(short int)(anodeOffset*FACTOR+0.5);
144  }
145  count=count+1;
146  }
147 
148  //Read in the changes you want to make in the extra chamber variable cfeb_timing_corr
149  FILE *fin = fopen("/afs/cern.ch/user/d/deisher/public/TimingCorrections2009/ttcrx_delay_effects_23April_2010.txt","r");
150  int chamber;
151  float corr;
152  while (!feof(fin)){
153  //note space at end of format string to convert last \n
154  int check = fscanf(fin,"%d %f \n",&chamber,&corr);
155  if (check != 2){
156  printf("cfeb timing corr file has an unexpected format \n");
157  assert(0);
158  }
159  //printf("chamber %d corr %f \n",chamber,corr);
160  chamberObj->chamberCorrections[chamber-1].cfeb_timing_corr= (short int)(corr*FACTOR+0.5*(corr>=0)-0.5*(corr<0));
161  }
162  fclose(fin);
163 
164  // Remove the offsets inherent to ME11 and non ME11 chambers
165  for(i=1;i<=MAX_SIZE;++i){
166  float temp= float(chamberObj->chamberCorrections[i-1].cfeb_timing_corr)/FACTOR;
167  if (i<= 36 || (i>= 235 && i<=270))
168  chamberObj->chamberCorrections[i-1].cfeb_timing_corr=(short int)((temp-1*ME11offset)*FACTOR+0.5*(temp>=ME11offset)-0.5*(temp<ME11offset));
169  else
170  chamberObj->chamberCorrections[i-1].cfeb_timing_corr=(short int)((temp-1*nonME11offset)*FACTOR+0.5*(temp>=nonME11offset)-0.5*(temp<nonME11offset));
171  }
172 
173  //Read in the cfeb_cable_delay values (0 or 1) and don't use a precision correction factor
174  FILE *fdelay = fopen("/afs/cern.ch/user/d/deisher/public/TimingCorrections2009/cfeb_cable_delay_20100423_both.txt","r");
175  char label[1024];
176  int delay;
177  CSCIndexer indexer;
178  while (!feof(fdelay)){
179  //note space at end of format string to convert last \n
180  int check = fscanf(fdelay,"%1024s %d \n",label,&delay);
181  if (check != 2){
182  printf("cfeb cable delay file has an unexpected format \n");
183  assert(0);
184  }
185  int chamberSerial = 0;
186  int c_endcap = (label[2]=='+' ? 1 : 2);
187  int c_station = atoi(&label[3]);
188  int c_ring = atoi(&label[5]);
189  if (c_station ==1 && c_ring ==4)
190  c_ring =1;
191  int c_chamber = (label[7]=='0' ? atoi(&label[8]) : atoi(&label[7]));
192  chamberSerial = indexer.chamberIndex(c_endcap, c_station, c_ring, c_chamber);
193  //printf("chamberLabel %s (%d %d %d %d) chamberSerial %d delay %d \n",label,c_endcap,c_station, c_ring, c_chamber, chamberSerial,delay);
194  chamberObj->chamberCorrections[chamberSerial-1].cfeb_cable_delay= (short int)delay;
195  }
196  fclose(fdelay);
197 
198  //Read in a 2nd order correction for chamber offsets derived from data
199  FILE *foffset = fopen("/afs/cern.ch/user/d/deisher/public/TimingCorrections2009/offset_26July2010_codeOverhaul_slope012.txt","r");
200  float offset;
201  int iE,iS,iR,iC;
202  while (!feof(foffset)){
203  //note space at end of format string to convert last \n
204  int check = fscanf(foffset,"%d %d %d %d %f \n",&iE,&iS,&iR,&iC,&offset);
205  if (check != 5){
206  printf("offset file has an unexpected format \n");
207  assert(0);
208  }
209  int chamberSerial = 0;
210  if (iS ==1 && iR ==4)
211  iR =1;
212  chamberSerial = indexer.chamberIndex(iE,iS,iR,iC);
213  //printf("chamberLabel %s (%d %d %d %d) chamberSerial %d delay %d \n",label,c_endcap,c_station, c_ring, c_chamber, chamberSerial,delay);
214  float temp= float(chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr)/FACTOR;
215  chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr= (short int)((temp-offset)*FACTOR+0.5*(temp>=offset)-0.5*(temp<offset));
216  printf("Serial %d old corr %f change %f newcorr %f \n",chamberSerial,temp,offset,(float)chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr/FACTOR);
217  }
218  fclose(foffset);
219 
220  //Read in a 3rd order correction for chamber offsets derived from data
221  FILE *foffsetAgain = fopen("/afs/cern.ch/user/d/deisher/public/TimingCorrections2009/CathodeTimingCorrection_DB_12082010.txt","r");
222  while (!feof(foffsetAgain)){
223  //note space at end of format string to convert last \n
224  int check = fscanf(foffsetAgain,"%d %d %d %d %f \n",&iE,&iS,&iR,&iC,&offset);
225  if (check != 5){
226  printf("offsetAgain file has an unexpected format \n");
227  assert(0);
228  }
229  int chamberSerial = 0;
230  if (iS ==1 && iR ==4)
231  iR =1;
232  chamberSerial = indexer.chamberIndex(iE,iS,iR,iC);
233  //printf("chamberLabel %s (%d %d %d %d) chamberSerial %d delay %d \n",label,c_endcap,c_station, c_ring, c_chamber, chamberSerial,delay);
234  float temp= float(chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr)/FACTOR;
235  chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr= (short int)((temp-offset)*FACTOR+0.5*(temp>=offset)-0.5*(temp<offset));
236  printf("Serial %d old corr %f change %f newcorr %f \n",chamberSerial,temp,offset,(float)chamberObj->chamberCorrections[chamberSerial-1].cfeb_timing_corr/FACTOR);
237  }
238  fclose(foffsetAgain);
239 
240 
241 
242  return chamberObj;
243 }
244 
245 
246 #endif
int i
Definition: DBlmapReader.cc:9
IndexType chamberIndex(const CSCDetId &id) const
Definition: CSCIndexer.h:66
static CSCChamberTimeCorrections * prefill(bool isMC, float ME11offset, float nonME11offset)
void cable_read(int chamber_index, std::string *chamber_label, float *cfeb_length, std::string *cfeb_rev, float *alct_length, std::string *alct_rev, float *cfeb_tmb_skew_delay, float *cfeb_timing_corr)
Definition: CSCCableRead.cc:28
const CSCChamberTimeCorrections * ReturnType
CSCChamberTimeCorrectionsValues(const edm::ParameterSet &)
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
unsigned int offset(bool)
JetCorrectorParameters corr
Definition: classes.h:9
ReturnType produceChamberTimeCorrections(const CSCChamberTimeCorrectionsRcd &)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)