CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibMuon/CSCCalibration/plugins/CSCGainsConditions.cc

Go to the documentation of this file.
00001 #include <fstream>
00002 
00003 #include "CalibMuon/CSCCalibration/interface/CSCGainsConditions.h"
00004 
00005 CSCGains * CSCGainsConditions::prefillGains(){
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_gainslope,old_intercpt, old_chisq;
00011   std::vector<int> old_cham_id;
00012   std::vector<int> old_strips;
00013   std::vector<float> old_slope;
00014   std::vector<float> old_intercept;
00015   std::vector<float> old_chi2;
00016   float new_gainslope,new_intercpt, new_chisq;
00017   std::vector<int> new_cham_id;
00018   std::vector<int> new_strips;
00019   std::vector<float> new_slope;
00020   std::vector<float> new_intercept;
00021   std::vector<float> new_chi2;
00022 
00023   const CSCDetId& detId = CSCDetId();
00024   CSCGains * cngains = new CSCGains();
00025       
00026   int max_istrip,id_layer,max_ring,max_cham;
00027   unsigned int old_nrlines=0;
00028   unsigned int new_nrlines=0;
00029   seed = 10000; 
00030   srand(seed);
00031   mean=6.8, min=-10.0, minchi=1.0, M=1000;
00032 
00033   std::ifstream olddata; 
00034   olddata.open("old_gains.dat",std::ios::in); 
00035   if(!olddata) {
00036     std::cerr <<"Error: old_gains.dat -> no such file!"<< std::endl;
00037     exit(1);
00038   }
00039   
00040   while (!olddata.eof() ) { 
00041     olddata >> old_chamber_id >> old_strip >> old_gainslope >> old_intercpt >> old_chisq ; 
00042     old_cham_id.push_back(old_chamber_id);
00043     old_strips.push_back(old_strip);
00044     old_slope.push_back(old_gainslope);
00045     old_intercept.push_back(old_intercpt);
00046     old_chi2.push_back(old_chisq);
00047     old_nrlines++;
00048   }
00049   olddata.close();
00050 
00051   std::ifstream newdata;
00052   newdata.open("new_gains.txt",std::ios::in); 
00053   if(!newdata) {
00054     std::cerr <<"Error: new_gains.txt -> no such file!"<< std::endl;
00055     exit(1);
00056   }
00057   
00058   while (!newdata.eof() ) { 
00059     newdata >> new_chamber_id >> new_strip >> new_gainslope >> new_intercpt >> new_chisq ; 
00060     new_cham_id.push_back(new_chamber_id);
00061     new_strips.push_back(new_strip);
00062     new_slope.push_back(new_gainslope);
00063     new_intercept.push_back(new_intercpt);
00064     new_chi2.push_back(new_chisq);
00065     new_nrlines++;
00066   }
00067   newdata.close();
00068 
00069 
00070   //endcap=1 to 2,station=1 to 4, ring=1 to 4,chamber=1 to 36,layer=1 to 6 
00071   for(int iendcap=detId.minEndcapId(); iendcap<=detId.maxEndcapId(); iendcap++){
00072     for(int istation=detId.minStationId() ; istation<=detId.maxStationId(); istation++){
00073       max_ring=detId.maxRingId();
00074       //station 4 ring 4 not there(36 chambers*2 missing)
00075       //3 rings max this way of counting (ME1a & b)
00076       if(istation==1)    max_ring=3;
00077       if(istation==2)    max_ring=2;
00078       if(istation==3)    max_ring=2;
00079       if(istation==4)    max_ring=1;
00080       
00081       for(int iring=detId.minRingId(); iring<=max_ring; iring++){
00082         max_istrip=80;
00083         max_cham=detId.maxChamberId();  
00084         if(istation==1 && iring==1)    max_cham=36;
00085         if(istation==1 && iring==2)    max_cham=36;
00086         if(istation==1 && iring==3)    max_cham=36;
00087         if(istation==2 && iring==1)    max_cham=18;
00088         if(istation==2 && iring==2)    max_cham=36;
00089         if(istation==3 && iring==1)    max_cham=18;
00090         if(istation==3 && iring==2)    max_cham=36;
00091         if(istation==4 && iring==1)    max_cham=18;
00092         
00093         for(int ichamber=detId.minChamberId(); ichamber<=max_cham; ichamber++){
00094           for(int ilayer=detId.minLayerId(); ilayer<=detId.maxLayerId(); ilayer++){
00095             //station 1 ring 3 has 64 strips per layer instead of 80 
00096             if(istation==1 && iring==3)   max_istrip=64;
00097             
00098             std::vector<CSCGains::Item> itemvector;
00099             itemvector.resize(max_istrip);
00100             id_layer = 100000*iendcap + 10000*istation + 1000*iring + 10*ichamber + ilayer;
00101             
00102             for(int istrip=0;istrip<max_istrip;istrip++){
00103               itemvector[istrip].gain_slope=((double)rand()/((double)(RAND_MAX)+(double)(1)))+mean;
00104               itemvector[istrip].gain_intercept=((double)rand()/((double)(RAND_MAX)+(double)(1)))+min;
00105               itemvector[istrip].gain_chi2=((double)rand()/((double)(RAND_MAX)+(double)(1)))+minchi;
00106               cngains->gains[id_layer]=itemvector;
00107             }
00108           }
00109         }
00110       }
00111     }
00112   }
00113 
00114   //overwrite fakes with old values from DB
00115   int istrip = 0;
00116   std::vector<CSCGains::Item> itemvector;
00117   itemvector.resize(80);
00118   
00119   for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00120     if(old_strips[mystrip]==0) istrip = 0;
00121     itemvector[istrip].gain_slope=old_slope[mystrip];
00122     itemvector[istrip].gain_intercept=old_intercept[mystrip]; 
00123     itemvector[istrip].gain_chi2=old_chi2[mystrip];
00124     cngains->gains[old_cham_id[mystrip]]=itemvector;
00125     istrip++;
00126   }  
00127   
00128   
00129   itemvector.resize(64);
00130   for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00131     if(old_strips[mystrip]==0) istrip = 0;
00132     if(old_cham_id[mystrip] >= 113000 && old_cham_id[mystrip] <= 113999){
00133       itemvector[istrip].gain_slope=old_slope[mystrip];
00134       itemvector[istrip].gain_intercept=old_intercept[mystrip]; 
00135       itemvector[istrip].gain_chi2=old_chi2[mystrip];
00136       cngains->gains[old_cham_id[mystrip]]=itemvector;
00137       istrip++;
00138     }
00139   } 
00140   
00141   itemvector.resize(64);
00142   for(unsigned int mystrip=0; mystrip<old_nrlines-1; mystrip++){
00143     if(old_strips[mystrip]==0) istrip = 0;
00144     if(old_cham_id[mystrip] >= 213000 && old_cham_id[mystrip] <= 213999){
00145       itemvector[istrip].gain_slope=old_slope[mystrip];
00146       itemvector[istrip].gain_intercept=old_intercept[mystrip]; 
00147       itemvector[istrip].gain_chi2=old_chi2[mystrip];
00148       cngains->gains[old_cham_id[mystrip]]=itemvector;
00149       istrip++;
00150     }
00151   }   
00152   
00153   //overwrite old values with ones from new runs
00154   itemvector.resize(80);
00155   for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00156     if(new_strips[mystrip]==0) istrip = 0;
00157     itemvector[istrip].gain_slope=new_slope[mystrip];
00158     itemvector[istrip].gain_intercept=new_intercept[mystrip]; 
00159     itemvector[istrip].gain_chi2=new_chi2[mystrip];
00160     cngains->gains[new_cham_id[mystrip]]=itemvector;
00161     istrip++;
00162   }
00163     
00164   itemvector.resize(64);
00165   for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00166     if(new_strips[mystrip]==0) istrip = 0;
00167     if(new_cham_id[mystrip] >= 113000 && new_cham_id[mystrip] <= 113999){
00168       itemvector[istrip].gain_slope=new_slope[mystrip];
00169       itemvector[istrip].gain_intercept=new_intercept[mystrip]; 
00170       itemvector[istrip].gain_chi2=new_chi2[mystrip];
00171       cngains->gains[new_cham_id[mystrip]]=itemvector;
00172       istrip++;
00173     }
00174   } 
00175   
00176   itemvector.resize(64);
00177   for(unsigned int mystrip=0; mystrip<new_nrlines-1; mystrip++){
00178     if(new_strips[mystrip]==0) istrip = 0;
00179     if(new_cham_id[mystrip] >= 213000 && new_cham_id[mystrip] <= 213999){
00180       itemvector[istrip].gain_slope=new_slope[mystrip];
00181       itemvector[istrip].gain_intercept=new_intercept[mystrip]; 
00182       itemvector[istrip].gain_chi2=new_chi2[mystrip];
00183       cngains->gains[new_cham_id[mystrip]]=itemvector;
00184       istrip++;
00185     }
00186   } 
00187   return cngains;
00188 }
00189 
00190 
00191 CSCGainsConditions::CSCGainsConditions(const edm::ParameterSet& iConfig)
00192 {
00193   //the following line is needed to tell the framework what
00194   // data is being produced
00195   cnGains = prefillGains();
00196   // added by Zhen (changed since 1_2_0)
00197   setWhatProduced(this,&CSCGainsConditions::produceGains);
00198   findingRecord<CSCGainsRcd>();
00199   //now do what ever other initialization is needed
00200 }
00201 
00202 
00203 CSCGainsConditions::~CSCGainsConditions()
00204 {
00205  
00206    // do anything here that needs to be done at desctruction time
00207    // (e.g. close files, deallocate resources etc.)
00208   delete cnGains;
00209 }
00210 
00211 
00212 //
00213 // member functions
00214 //
00215 
00216 // ------------ method called to produce the data  ------------
00217 CSCGainsConditions::ReturnType
00218 CSCGainsConditions::produceGains(const CSCGainsRcd& iRecord)
00219 {
00220   // Added by Zhen, need a new object so to not be deleted at exit
00221   CSCGains* mydata=new CSCGains( *cnGains );
00222   
00223   return mydata;
00224   
00225 }
00226 
00227  void CSCGainsConditions::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&,
00228  edm::ValidityInterval & oValidity)
00229  {
00230  oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime());
00231  
00232  }