Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /CalibMuon/CSCCalibration/test/Compare_template.txt is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //
0003 // Package:    Compare
0004 // Class:      Compare
0005 // 
0006 /**\class Compare Compare.cc CalibMuon/Compare/src/Compare.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Thomas Nummy,Bld. 32 Room 4-C21,+41227671337,
0015 //         Created:  Thu Oct 29 13:55:15 CET 2009
0016 //
0017 //
0018 //////////////////////////////////READ THIS FIRST//////////////////////////////////////////////////////////
0019 //////////////////"std::bad_alloc exception caught in cmsRun" ERROR when you have text inside the .dat///// 
0020 /////////////////files ---->Check them first before running this code!/////////////////////////////////////
0021 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
0022 
0023 // system include files
0024 #include <memory>
0025 #include <string>
0026 #include <iostream>
0027 #include <fstream>
0028 #include <vector>
0029 #include <iostream>
0030 
0031 // user include files
0032 #include "FWCore/Framework/interface/Frameworkfwd.h"
0033 #include "FWCore/Framework/interface/EDAnalyzer.h"
0034 
0035 #include "FWCore/Framework/interface/Event.h"
0036 #include "FWCore/Framework/interface/MakerMacros.h"
0037 
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 //
0040 // class decleration
0041 //
0042 
0043 class Compare : public edm::EDAnalyzer {
0044    public:
0045       explicit Compare(const edm::ParameterSet&);
0046       ~Compare();
0047 
0048 
0049    private:
0050       virtual void beginJob() ;
0051       virtual void analyze(const edm::Event&, const edm::EventSetup&);
0052       virtual void endJob() ;
0053 
0054       // ----------member data ---------------------------
0055 };
0056 
0057 //
0058 // constants, enums and typedefs
0059 //
0060 
0061 //
0062 // static data member definitions
0063 //
0064 
0065 //
0066 // constructors and destructor
0067 //
0068 Compare::Compare(const edm::ParameterSet& iConfig)
0069 
0070 {
0071    //now do what ever initialization is needed
0072  /*
0073 
0074 
0075  */
0076 
0077   //=========== Compare Pedestals =================
0078   std::cout<<"Comparing PEDESTALS, please wait!"<<std::endl;
0079 
0080   const int MAX_SIZE = 252288;
0081 
0082   int old_index;
0083   float old_ped, old_rms;
0084   std::vector<int> old_index_id;
0085   std::vector<float> old_peds;
0086   int new_index;
0087   float new_ped,new_rms;
0088   std::vector<int> new_index_id;
0089   std::vector<float> new_peds;
0090   std::vector<float> diffPeds;
0091   std::vector<float> diffGains;
0092   
0093   std::ifstream olddata; 
0094   olddata.open("old_dbpeds.dat",std::ios::in); 
0095   if(!olddata) {
0096     std::cerr <<"Error: old_dbpeds.dat -> no such file!"<< std::endl;
0097     exit(1);
0098   }
0099   
0100   while (!olddata.eof() ) { 
0101     olddata >> old_index >> old_ped >> old_rms ; 
0102     old_index_id.push_back(old_index);
0103     old_peds.push_back(old_ped);
0104   }
0105   olddata.close();
0106   
0107   std::ifstream newdata;
0108   std::ofstream myPedsFile("diff_Peds_FileName",std::ios::out);
0109   newdata.open("Peds_FileName",std::ios::in); 
0110   if(!newdata) {
0111     std::cerr <<"Error: Peds_FileName -> no such file!"<< std::endl;
0112     exit(1);
0113   }
0114   
0115   while (!newdata.eof() ) { 
0116     newdata >> new_index >> new_ped >> new_rms ; 
0117     new_index_id.push_back(new_index);
0118     new_peds.push_back(new_ped);
0119   }
0120   newdata.close();
0121 
0122   diffPeds.resize(MAX_SIZE);
0123   
0124   for(int i=0; i<MAX_SIZE;++i){
0125     for (unsigned int k=0;k<new_index_id.size()-1;++k){
0126       if(old_index_id[i] == new_index_id[k]){
0127         diffPeds[k]=(new_peds[k] - old_peds[i]/10.)/(old_peds[i]/10.);
0128         new_peds.erase(new_peds.begin());
0129         new_index_id.erase(new_index_id.begin());
0130         myPedsFile<<old_index_id[i]<<"  "<<diffPeds[k]<<std::endl;      
0131       }
0132     }
0133   }
0134   
0135   
0136   // ============= Compare Crosstalk ===================
0137   std::cout<<"Comparing CROSSTALK, please wait!"<<std::endl;
0138 
0139   old_index = 0;
0140   float old_xtalk_left, old_xtalk_right, old_int_left, old_int_right;
0141   old_index_id.clear();
0142   std::vector<float> old_Rxtalk;
0143   std::vector<float> old_Lxtalk;
0144   std::vector<float> old_Rint;
0145   std::vector<float> old_Lint;
0146   std::vector<float> diffXtalkR;
0147   std::vector<float> diffXtalkL;
0148   std::vector<float> diffIntR;
0149   std::vector<float> diffIntL;
0150   
0151   std::vector<float> myoldxtalkR;
0152   std::vector<float> myoldxtalkL;
0153   std::vector<float> myoldintR;
0154   std::vector<float> myoldintL;
0155 
0156   new_index = 0;
0157   float new_xtalk_left, new_xtalk_right, new_int_left, new_int_right;
0158   new_index_id.clear();
0159   std::vector<float> new_Rxtalk;
0160   std::vector<float> new_Lxtalk;
0161   std::vector<float> new_Rint;
0162   std::vector<float> new_Lint;
0163 
0164   int counter,counter1;
0165 
0166   std::ifstream olddata1; 
0167   olddata1.open("old_dbxtalk.dat",std::ios::in); 
0168   if(!olddata1) {
0169     std::cerr <<"Error: old_dbxtalk.dat -> no such file!"<< std::endl;
0170     exit(1);
0171   }
0172 
0173   while (!olddata1.eof() ) { 
0174     olddata1 >> old_index >> old_xtalk_left >> old_int_left >> old_xtalk_right >> old_int_right ;
0175     old_index_id.push_back(old_index);
0176     old_Rxtalk.push_back(old_xtalk_right);
0177     old_Rint.push_back(old_int_right); 
0178     old_Lxtalk.push_back(old_xtalk_left);  
0179     old_Lint.push_back(old_int_left);
0180   }
0181   olddata1.close();
0182 
0183   std::ifstream newdata1;
0184   std::ofstream myXtalkFile("diff_Xtalk_FileName",std::ios::out);
0185 
0186   newdata1.open("Xtalk_FileName",std::ios::in); 
0187   if(!newdata1) {
0188     std::cerr <<"Error: Xtalk_FileName  -> no such file!"<< std::endl;
0189     exit(1);
0190   }
0191 
0192   while (!newdata1.eof() ) { 
0193     newdata1 >> new_index >> new_xtalk_left >> new_int_left >> new_xtalk_right >> new_int_right ;
0194     new_index_id.push_back(new_index);
0195     new_Rxtalk.push_back(new_xtalk_right);
0196     new_Rint.push_back(new_int_right); 
0197     new_Lxtalk.push_back(new_xtalk_left);
0198     new_Lint.push_back(new_int_left);
0199   }
0200   newdata1.close();  
0201 
0202   diffXtalkR.resize(MAX_SIZE);
0203   diffXtalkL.resize(MAX_SIZE);
0204   diffIntR.resize(MAX_SIZE);
0205   diffIntL.resize(MAX_SIZE);
0206   myoldxtalkR.resize(MAX_SIZE);
0207   myoldxtalkL.resize(MAX_SIZE);
0208   myoldintR.resize(MAX_SIZE);
0209   myoldintR.resize(MAX_SIZE);
0210 
0211   for(int i=0; i<MAX_SIZE;++i){
0212     counter=old_index_id[i];  
0213     myoldxtalkR[i]=old_Rxtalk[i];
0214     myoldxtalkL[i]=old_Lxtalk[i];
0215     myoldintR[i]=old_Rint[i];
0216     myoldintR[i]=old_Lint[i];
0217 
0218     for (unsigned int k=0;k<new_index_id.size()-1;k++){
0219       counter1=new_index_id[k];
0220       if(counter == counter1){
0221 
0222         if ((abs(old_Rxtalk[i])/10000000.) > .000001) diffXtalkR[k]= (new_Rxtalk[k] -  old_Rxtalk[i]/10000000.)/(old_Rxtalk[i]/10000000.);
0223         if ((abs(old_Lxtalk[i])/10000000.) > .000001) diffXtalkL[k]= (new_Lxtalk[k] - old_Lxtalk[i]/10000000.)/(old_Lxtalk[i]/10000000.) ;
0224         if ((abs(old_Rint[i])/100000.) > .000001) diffIntR[k]=  (new_Rint[k] -  old_Rint[i]/100000.)/(old_Rint[i]/100000.);
0225         if ((abs(old_Lint[i])/100000.) > .000001) diffIntL[k]=  (new_Lint[k] - old_Lint[i]/100000.)/(old_Lint[i]/100000.) ;
0226         myXtalkFile<<counter<<"  "<<diffXtalkL[k]<<"  "<<diffIntL[k]<<"  "<<diffXtalkR[k]<<"  "<<diffIntR[k]<<"  "<<std::endl;  
0227       }
0228     }
0229   }
0230 
0231 
0232   // ================= Compare Gains ===============
0233   std::cout<<"Comparing GAINS, please wait!"<<std::endl;
0234 
0235   old_index=0;
0236   float old_slope;
0237   old_index_id.clear();
0238   std::vector<float> old_gains;
0239   std::vector<float> old_intercept;
0240   std::vector<float> old_chi;
0241 
0242   new_index=0;
0243   float new_slope,new_int, new_chi2;
0244   new_index_id.clear();
0245   std::vector<float> new_gains;
0246   std::vector<float> new_intercept;
0247   std::vector<float> new_chi;
0248  
0249   std::vector<float> myoldgains;
0250 
0251   counter=0;
0252   counter1=0;
0253   int old_nrlines=0;
0254   int new_nrlines=0;
0255 
0256   std::ifstream olddata2; 
0257   olddata2.open("old_dbgains.dat",std::ios::in); 
0258   if(!olddata2) {
0259     std::cerr <<"Error: old_dbgains.dat -> no such file!"<< std::endl;
0260     exit(1);
0261   }
0262   
0263   while (!olddata2.eof() ) { 
0264     olddata2 >> old_index >> old_slope; 
0265     old_index_id.push_back(old_index);
0266     old_gains.push_back(old_slope);
0267     old_nrlines++;
0268   }
0269   olddata2.close();
0270 
0271   std::ifstream newdata2;
0272   std::ofstream myGainsFile("diff_Gains_FileName",std::ios::out);
0273   newdata2.open("Gains_FileName",std::ios::in); 
0274   if(!newdata2) {
0275     std::cerr <<"Error: Gains_FileName -> no such file!"<< std::endl;
0276     exit(1);
0277   }
0278   
0279   while (!newdata2.eof() ) { 
0280     newdata2 >> new_index >> new_slope >> new_int >> new_chi2 ; 
0281     new_index_id.push_back(new_index);
0282     new_gains.push_back(new_slope);
0283     new_intercept.push_back(new_int);
0284     new_chi.push_back(new_chi2);
0285     new_nrlines++;
0286   }
0287   newdata2.close();
0288   diffGains.resize(MAX_SIZE);
0289   myoldgains.resize(MAX_SIZE);
0290   
0291   for(int i=0; i<MAX_SIZE;++i){
0292     counter=old_index_id[i];  
0293     myoldgains[i]=old_gains[i];
0294 
0295     for (unsigned int k=0;k<new_index_id.size()-1;k++){
0296       counter1=new_index_id[k];
0297       if(counter == counter1){
0298         diffGains[k]= (new_gains[k] - old_gains[i]/1000.)/(old_gains[i]/1000.);
0299         myGainsFile<<counter<<"  "<<diffGains[k]<<std::endl;    
0300       }
0301     }
0302   }
0303 
0304 
0305   //=================== Compare Noise Matrix ===============
0306   std::cout<<"Comparing NOISE MATRIX, please wait!"<<std::endl;
0307 
0308   old_index=0;
0309   float old_elem33, old_elem34,old_elem35,old_elem44,old_elem45,old_elem46,old_elem55,old_elem56;
0310   float old_elem57,old_elem66,old_elem67,old_elem77;
0311   old_index_id.clear();
0312   std::vector<float> old_el33;
0313   std::vector<float> old_el34;
0314   std::vector<float> old_el35;
0315   std::vector<float> old_el44;
0316   std::vector<float> old_el45;
0317   std::vector<float> old_el46;
0318   std::vector<float> old_el55;
0319   std::vector<float> old_el56;
0320   std::vector<float> old_el57;
0321   std::vector<float> old_el66;
0322   std::vector<float> old_el67;
0323   std::vector<float> old_el77;
0324 
0325   new_index=0;
0326   float new_elem33,new_elem34,new_elem35,new_elem44,new_elem45,new_elem46,new_elem55,new_elem56;
0327   float new_elem57,new_elem66,new_elem67,new_elem77;
0328   new_index_id.clear();
0329   std::vector<float> new_el33;
0330   std::vector<float> new_el34;
0331   std::vector<float> new_el35;
0332   std::vector<float> new_el44;
0333   std::vector<float> new_el45;
0334   std::vector<float> new_el46;
0335   std::vector<float> new_el55;
0336   std::vector<float> new_el56;
0337   std::vector<float> new_el57;
0338   std::vector<float> new_el66;
0339   std::vector<float> new_el67;
0340   std::vector<float> new_el77;
0341 
0342   //differences
0343   std::vector<float> diff_el33;
0344   std::vector<float> diff_el34;
0345   std::vector<float> diff_el35;
0346   std::vector<float> diff_el44;
0347   std::vector<float> diff_el45;
0348   std::vector<float> diff_el46;
0349   std::vector<float> diff_el55;
0350   std::vector<float> diff_el56;
0351   std::vector<float> diff_el57;
0352   std::vector<float> diff_el66;
0353   std::vector<float> diff_el67;
0354   std::vector<float> diff_el77;
0355 
0356   //old vectors
0357   std::vector<float> myoldel33;
0358   std::vector<float> myoldel34;
0359   std::vector<float> myoldel35;
0360   std::vector<float> myoldel44;
0361   std::vector<float> myoldel45;
0362   std::vector<float> myoldel46;
0363   std::vector<float> myoldel55;
0364   std::vector<float> myoldel56;
0365   std::vector<float> myoldel57;
0366   std::vector<float> myoldel66;
0367   std::vector<float> myoldel67;
0368   std::vector<float> myoldel77;
0369 
0370   counter=0;
0371   counter1=0;
0372   //old_nrlines=0;
0373   //new_nrlines=0;
0374   
0375   std::ifstream olddata3; 
0376   olddata3.open("old_dbmatrix.dat",std::ios::in); 
0377   if(!olddata3) {
0378     std::cerr <<"Error: old_dbmatrix.dat -> no such file!"<< std::endl;
0379     exit(1);
0380   }
0381   
0382   while (!olddata3.eof() ) { 
0383     olddata3 >> old_index >> old_elem33 >> old_elem34 >> old_elem44 >> old_elem35 >> old_elem45 >> old_elem55 >> old_elem46 >> old_elem56 >>old_elem66 >> old_elem57 >> old_elem67 >> old_elem77 ; 
0384     old_index_id.push_back(old_index);
0385     old_el33.push_back(old_elem33);
0386     old_el34.push_back(old_elem34);
0387     old_el35.push_back(old_elem35);
0388     old_el44.push_back(old_elem44);
0389     old_el45.push_back(old_elem45);
0390     old_el46.push_back(old_elem46);
0391     old_el55.push_back(old_elem55);
0392     old_el56.push_back(old_elem56);
0393     old_el57.push_back(old_elem57);
0394     old_el66.push_back(old_elem66);
0395     old_el67.push_back(old_elem67);
0396     old_el77.push_back(old_elem77);
0397     //old_nrlines++;
0398   }
0399   olddata3.close();
0400 
0401   std::ifstream newdata3;
0402   std::ofstream myMatrixFile("diff_Matrix_FileName",std::ios::out);
0403   newdata3.open("Matrix_FileName",std::ios::in); 
0404   if(!newdata3) {
0405     std::cerr <<"Error: Matrix_FileName -> no such file!"<< std::endl;
0406     exit(1);
0407   }
0408   
0409   while (!newdata3.eof() ) { 
0410     newdata3 >> new_index >> new_elem33 >> new_elem34 >> new_elem44 >> new_elem35 >> new_elem45 >> new_elem55 >> new_elem46 >> new_elem56 >>new_elem66 >> new_elem57 >> new_elem67 >> new_elem77; 
0411     new_index_id.push_back(new_index);
0412     new_el33.push_back(new_elem33);
0413     new_el34.push_back(new_elem34);
0414     new_el35.push_back(new_elem35);
0415     new_el44.push_back(new_elem44);
0416     new_el45.push_back(new_elem45);
0417     new_el46.push_back(new_elem46);
0418     new_el55.push_back(new_elem55);
0419     new_el56.push_back(new_elem56);
0420     new_el57.push_back(new_elem57);
0421     new_el66.push_back(new_elem66);
0422     new_el67.push_back(new_elem67);
0423     new_el77.push_back(new_elem77);
0424     //new_nrlines++;
0425   }
0426   newdata3.close();
0427 
0428   //resize
0429   diff_el33.resize(MAX_SIZE);
0430   diff_el34.resize(MAX_SIZE);
0431   diff_el35.resize(MAX_SIZE);
0432   diff_el44.resize(MAX_SIZE);
0433   diff_el45.resize(MAX_SIZE);
0434   diff_el46.resize(MAX_SIZE);
0435   diff_el55.resize(MAX_SIZE);
0436   diff_el56.resize(MAX_SIZE);
0437   diff_el57.resize(MAX_SIZE);
0438   diff_el66.resize(MAX_SIZE);
0439   diff_el67.resize(MAX_SIZE);
0440   diff_el77.resize(MAX_SIZE);
0441 
0442   myoldel33.resize(MAX_SIZE);
0443   myoldel34.resize(MAX_SIZE);
0444   myoldel35.resize(MAX_SIZE);
0445   myoldel44.resize(MAX_SIZE);
0446   myoldel45.resize(MAX_SIZE);
0447   myoldel46.resize(MAX_SIZE);
0448   myoldel55.resize(MAX_SIZE);
0449   myoldel56.resize(MAX_SIZE);
0450   myoldel57.resize(MAX_SIZE);
0451   myoldel66.resize(MAX_SIZE);
0452   myoldel67.resize(MAX_SIZE);
0453   myoldel77.resize(MAX_SIZE);
0454 
0455   for(int i=0; i<MAX_SIZE;++i){
0456     counter=old_index_id[i];  
0457     myoldel33[i]=old_el33[i];
0458     myoldel34[i]=old_el34[i];
0459     myoldel35[i]=old_el35[i];
0460     myoldel44[i]=old_el44[i];
0461     myoldel45[i]=old_el45[i];
0462     myoldel46[i]=old_el46[i];
0463     myoldel55[i]=old_el55[i];
0464     myoldel56[i]=old_el56[i];
0465     myoldel57[i]=old_el57[i];
0466     myoldel66[i]=old_el66[i];
0467     myoldel67[i]=old_el67[i];
0468     myoldel77[i]=old_el77[i];
0469     
0470     for (unsigned int k=0;k<new_index_id.size()-1;k++){
0471       counter1=new_index_id[k];
0472       if(counter == counter1){
0473 
0474         if (abs( old_el33[i]/1000. ) > .00000001)         diff_el33[k] = ( new_el33[k] - old_el33[i]/1000. )/( old_el33[i]/1000. ) ;
0475         if (abs( old_el34[i]/1000. ) > .00000001)         diff_el34[k] = ( new_el34[k] - old_el34[i]/1000. )/( old_el34[i]/1000. ) ;
0476         if (abs( old_el35[i]/1000. ) > .00000001)         diff_el35[k] = ( new_el35[k] - old_el35[i]/1000. )/( old_el35[i]/1000. ) ;
0477         if (abs( old_el44[i]/1000. ) > .00000001)         diff_el44[k] = ( new_el44[k] - old_el44[i]/1000. )/( old_el44[i]/1000. ) ;
0478         if (abs( old_el45[i]/1000. ) > .00000001)         diff_el45[k] = ( new_el45[k] - old_el45[i]/1000. )/( old_el45[i]/1000. ) ;
0479         if (abs( old_el46[i]/1000. ) > .00000001)         diff_el46[k] = ( new_el46[k] - old_el46[i]/1000. )/( old_el46[i]/1000. ) ;
0480         if (abs( old_el55[i]/1000. ) > .00000001)         diff_el55[k] = ( new_el55[k] - old_el55[i]/1000. )/( old_el55[i]/1000. ) ;
0481         if (abs( old_el56[i]/1000. ) > .00000001)         diff_el56[k] = ( new_el56[k] - old_el56[i]/1000. )/( old_el56[i]/1000. ) ;
0482         if (abs( old_el57[i]/1000. ) > .00000001)         diff_el57[k] = ( new_el57[k] - old_el57[i]/1000. )/( old_el57[i]/1000. ) ;
0483         if (abs( old_el66[i]/1000. ) > .00000001)         diff_el66[k] = ( new_el66[k] - old_el66[i]/1000. )/( old_el66[i]/1000. ) ;
0484         if (abs( old_el67[i]/1000. ) > .00000001)         diff_el67[k] = ( new_el67[k] - old_el67[i]/1000. )/( old_el67[i]/1000. ) ;
0485         if (abs( old_el77[i]/1000. ) > .00000001)         diff_el77[k] = ( new_el77[k] - old_el77[i]/1000. )/( old_el77[i]/1000. ) ;
0486         myMatrixFile<<counter<<"  "<<diff_el33[k]<<"  "<< diff_el34[k]<<"  "<<diff_el35[k]<<"  "<<diff_el44[k]<<"  "<<diff_el45[k]<<"  "<<diff_el46[k]<<"  "<<diff_el55[k]<<"  "<<diff_el56[k]<<"  "<<diff_el57[k]<<"  "<<diff_el66[k]<<"  "<<diff_el67[k]<<"  "<<diff_el77[k]<<"  "<<std::endl;        
0487       }
0488     }
0489   }
0490   std::cout<<"DONE with comparison!"<<std::endl; 
0491 }
0492 
0493 
0494 Compare::~Compare()
0495 {
0496  
0497    // do anything here that needs to be done at desctruction time
0498    // (e.g. close files, deallocate resources etc.)
0499 
0500 }
0501 
0502 
0503 //
0504 // member functions
0505 //
0506 
0507 // ------------ method called to for each event  ------------
0508 void
0509 Compare::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
0510 {
0511    using namespace edm;
0512 
0513 
0514 
0515 #ifdef THIS_IS_AN_EVENT_EXAMPLE
0516    Handle<ExampleData> pIn;
0517    iEvent.getByLabel("example",pIn);
0518 #endif
0519    
0520 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0521    ESHandle<SetupData> pSetup;
0522    iSetup.get<SetupRecord>().get(pSetup);
0523 #endif
0524 }
0525 
0526 
0527 // ------------ method called once each job just before starting event loop  ------------
0528 void 
0529 Compare::beginJob()
0530 {
0531 }
0532 
0533 // ------------ method called once each job just after ending the event loop  ------------
0534 void 
0535 Compare::endJob() {
0536 }
0537 
0538 //define this as a plug-in
0539 DEFINE_FWK_MODULE(Compare);