CMS 3D CMS Logo

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