Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:36

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