Go to the documentation of this file.00001 #include <fstream>
00002
00003 #include "CalibMuon/CSCCalibration/interface/CSCCrosstalkConditions.h"
00004
00005 CSCcrosstalk * CSCCrosstalkConditions::prefillCrosstalk() {
00006
00007 float mean,min,minchi;
00008 int seed;long int M;
00009 int old_chamber_id,old_strip,new_chamber_id,new_strip;
00010 float old_slope_right,old_slope_left,old_intercept_right;
00011 float old_intercept_left, old_chi2_right,old_chi2_left;
00012 std::vector<int> old_cham_id;
00013 std::vector<int> old_strips;
00014 std::vector<float> old_slope_r;
00015 std::vector<float> old_intercept_r;
00016 std::vector<float> old_chi2_r;
00017 std::vector<float> old_slope_l;
00018 std::vector<float> old_intercept_l;
00019 std::vector<float> old_chi2_l;
00020 float new_slope_right,new_slope_left,new_intercept_right;
00021 float new_intercept_left, new_chi2_right,new_chi2_left;
00022 std::vector<int> new_cham_id;
00023 std::vector<int> new_strips;
00024 std::vector<float> new_slope_r;
00025 std::vector<float> new_intercept_r;
00026 std::vector<float> new_chi2_r;
00027 std::vector<float> new_slope_l;
00028 std::vector<float> new_intercept_l;
00029 std::vector<float> new_chi2_l;
00030
00031
00032
00033 const CSCDetId& detId = CSCDetId();
00034 CSCcrosstalk * cncrosstalk = new CSCcrosstalk();
00035
00036 int max_istrip,id_layer,max_ring,max_cham;
00037 unsigned int old_nrlines=0;
00038 unsigned int new_nrlines=0;
00039 seed = 10000;
00040 srand(seed);
00041 mean=-0.0009, min=0.035, minchi=1.5, M=1000;
00042
00043
00044 std::ifstream olddata;
00045 olddata.open("old_xtalk.dat",std::ios::in);
00046 if(!olddata) {
00047 std::cerr <<"Error: old_xtalk.dat -> no such file!"<< std::endl;
00048 exit(1);
00049 }
00050
00051 while (!olddata.eof() ) {
00052 olddata >> old_chamber_id >> old_strip >> old_slope_right >> old_intercept_right >> old_chi2_right >> old_slope_left >> old_intercept_left >> old_chi2_left ;
00053 old_cham_id.push_back(old_chamber_id);
00054 old_strips.push_back(old_strip);
00055 old_slope_r.push_back(old_slope_right);
00056 old_slope_l.push_back(old_slope_left);
00057 old_intercept_r.push_back(old_intercept_right);
00058 old_intercept_l.push_back(old_intercept_left);
00059 old_chi2_r.push_back(old_chi2_right);
00060 old_chi2_l.push_back(old_chi2_left);
00061 old_nrlines++;
00062 }
00063 olddata.close();
00064
00065 std::ifstream newdata;
00066 newdata.open("new_xtalk.txt",std::ios::in);
00067 if(!newdata) {
00068 std::cerr <<"Error: new_xtalk.dat -> no such file!"<< std::endl;
00069 exit(1);
00070 }
00071
00072 while (!newdata.eof() ) {
00073 newdata >> new_chamber_id >> new_strip >> new_slope_right >> new_intercept_right >> new_chi2_right >> new_slope_left >> new_intercept_left >> new_chi2_left ;
00074 new_cham_id.push_back(new_chamber_id);
00075 new_strips.push_back(new_strip);
00076 new_slope_r.push_back(new_slope_right);
00077 new_slope_l.push_back(new_slope_left);
00078 new_intercept_r.push_back(new_intercept_right);
00079 new_intercept_l.push_back(new_intercept_left);
00080 new_chi2_r.push_back(new_chi2_right);
00081 new_chi2_l.push_back(new_chi2_left);
00082 new_nrlines++;
00083 }
00084 newdata.close();
00085
00086 for(int iendcap=detId.minEndcapId(); iendcap<=detId.maxEndcapId(); iendcap++){
00087 for(int istation=detId.minStationId() ; istation<=detId.maxStationId(); istation++){
00088 max_ring=detId.maxRingId();
00089
00090
00091 if(istation==1) max_ring=3;
00092 if(istation==2) max_ring=2;
00093 if(istation==3) max_ring=2;
00094 if(istation==4) max_ring=1;
00095
00096 for(int iring=detId.minRingId(); iring<=max_ring; iring++){
00097 max_istrip=80;
00098 max_cham=detId.maxChamberId();
00099 if(istation==1 && iring==1) max_cham=36;
00100 if(istation==1 && iring==2) max_cham=36;
00101 if(istation==1 && iring==3) max_cham=36;
00102 if(istation==2 && iring==1) max_cham=18;
00103 if(istation==2 && iring==2) max_cham=36;
00104 if(istation==3 && iring==1) max_cham=18;
00105 if(istation==3 && iring==2) max_cham=36;
00106 if(istation==4 && iring==1) max_cham=18;
00107
00108
00109 for(int ichamber=detId.minChamberId(); ichamber<=max_cham; ichamber++){
00110
00111 for(int ilayer=detId.minLayerId(); ilayer<=detId.maxLayerId(); ilayer++){
00112
00113 if(istation==1 && iring==3) max_istrip=64;
00114
00115 std::vector<CSCcrosstalk::Item> itemvector;
00116 itemvector.resize(max_istrip);
00117 id_layer = 100000*iendcap + 10000*istation + 1000*iring + 10*ichamber + ilayer;
00118
00119 for(int istrip=0;istrip<max_istrip;istrip++){
00120
00121 itemvector[istrip].xtalk_slope_right=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
00122 itemvector[istrip].xtalk_intercept_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
00123 itemvector[istrip].xtalk_chi2_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
00124 itemvector[istrip].xtalk_slope_left=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
00125 itemvector[istrip].xtalk_intercept_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
00126 itemvector[istrip].xtalk_chi2_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
00127 cncrosstalk->crosstalk[id_layer]=itemvector;
00128
00129 if(istrip==0){
00130 itemvector[istrip].xtalk_slope_right=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
00131 itemvector[istrip].xtalk_intercept_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
00132 itemvector[istrip].xtalk_chi2_right=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
00133 itemvector[istrip].xtalk_slope_left=0.0;
00134 itemvector[istrip].xtalk_intercept_left=0.0;
00135 itemvector[istrip].xtalk_chi2_left=0.0;
00136 cncrosstalk->crosstalk[id_layer]=itemvector;
00137 }
00138
00139 if(istrip==79){
00140 itemvector[istrip].xtalk_slope_right=0.0;
00141 itemvector[istrip].xtalk_intercept_right=0.0;
00142 itemvector[istrip].xtalk_chi2_right=0.0;
00143 itemvector[istrip].xtalk_slope_left=-((double)rand()/((double)(RAND_MAX)+(double)(1)))/10000+mean;
00144 itemvector[istrip].xtalk_intercept_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))/100+min;
00145 itemvector[istrip].xtalk_chi2_left=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
00146 cncrosstalk->crosstalk[id_layer]=itemvector;
00147 }
00148 }
00149 }
00150 }
00151 }
00152 }
00153
00154
00155 int istrip = 0;
00156 std::vector<CSCcrosstalk::Item> itemvector;
00157 itemvector.resize(80);
00158
00159 for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00160 if(old_strips[mystrip]==0) istrip = 0;
00161 itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
00162 itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
00163 itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
00164 itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
00165 itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
00166 itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
00167 cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
00168 istrip++;
00169 }
00170
00171
00172 itemvector.resize(64);
00173 for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00174 if(old_strips[mystrip]==0) istrip = 0;
00175 if(old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999){
00176 itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
00177 itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
00178 itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
00179 itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
00180 itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
00181 itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
00182 cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
00183 istrip++;
00184 }
00185 }
00186
00187 itemvector.resize(64);
00188 for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00189 if(old_strips[mystrip]==0) istrip = 0;
00190 if(old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999){
00191 itemvector[istrip].xtalk_slope_right=old_slope_r[mystrip];
00192 itemvector[istrip].xtalk_intercept_right=old_intercept_r[mystrip];
00193 itemvector[istrip].xtalk_chi2_right=old_chi2_r[mystrip];
00194 itemvector[istrip].xtalk_slope_left=old_slope_l[mystrip];
00195 itemvector[istrip].xtalk_intercept_left=old_intercept_l[mystrip];
00196 itemvector[istrip].xtalk_chi2_left=old_chi2_l[mystrip];
00197 cncrosstalk->crosstalk[old_cham_id[mystrip]]=itemvector;
00198 istrip++;
00199 }
00200 }
00201
00202
00203 itemvector.resize(80);
00204 for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00205 if(new_strips[mystrip]==0) istrip = 0;
00206 itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
00207 itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
00208 itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
00209 itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
00210 itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
00211 itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
00212 cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
00213 istrip++;
00214 }
00215
00216 itemvector.resize(64);
00217 for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00218 if(new_strips[mystrip]==0) istrip = 0;
00219 if(new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999){
00220 itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
00221 itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
00222 itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
00223 itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
00224 itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
00225 itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
00226 cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
00227 istrip++;
00228 }
00229 }
00230
00231 itemvector.resize(64);
00232 for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00233 if(new_strips[mystrip]==0) istrip = 0;
00234 if(new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999){
00235 itemvector[istrip].xtalk_slope_right=new_slope_r[mystrip];
00236 itemvector[istrip].xtalk_intercept_right=new_intercept_r[mystrip];
00237 itemvector[istrip].xtalk_chi2_right=new_chi2_r[mystrip];
00238 itemvector[istrip].xtalk_slope_left=new_slope_l[mystrip];
00239 itemvector[istrip].xtalk_intercept_left=new_intercept_l[mystrip];
00240 itemvector[istrip].xtalk_chi2_left=new_chi2_l[mystrip];
00241 cncrosstalk->crosstalk[new_cham_id[mystrip]]=itemvector;
00242 istrip++;
00243 }
00244 }
00245 }
00246
00247 return cncrosstalk;
00248
00249 }
00250
00251
00252 CSCCrosstalkConditions::CSCCrosstalkConditions(const edm::ParameterSet& iConfig)
00253 {
00254
00255
00256 cnCrosstalk = prefillCrosstalk();
00257
00258 setWhatProduced(this,&CSCCrosstalkConditions::produceCrosstalk);
00259 findingRecord<CSCcrosstalkRcd>();
00260
00261 }
00262
00263
00264 CSCCrosstalkConditions::~CSCCrosstalkConditions()
00265 {
00266
00267
00268
00269 delete cnCrosstalk;
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 CSCCrosstalkConditions::ReturnType
00279 CSCCrosstalkConditions::produceCrosstalk(const CSCcrosstalkRcd& iRecord)
00280 {
00281
00282 CSCcrosstalk* mydata=new CSCcrosstalk( *cnCrosstalk );
00283
00284 return mydata;
00285
00286 }
00287
00288 void CSCCrosstalkConditions::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&,
00289 edm::ValidityInterval & oValidity)
00290 {
00291 oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime());
00292
00293 }
00294
00295