Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef _CSCNOISEMATRIXDBCONDITIONS_H
0002 #define _CSCNOISEMATRIXDBCONDITIONS_H
0003 
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/ESProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/SourceFactory.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include <cmath>
0014 #include <memory>
0015 
0016 #include "CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h"
0017 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019 
0020 class CSCNoiseMatrixDBConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022   CSCNoiseMatrixDBConditions(const edm::ParameterSet &);
0023   ~CSCNoiseMatrixDBConditions() override;
0024 
0025   inline static CSCDBNoiseMatrix *prefillDBNoiseMatrix();
0026 
0027   typedef std::unique_ptr<CSCDBNoiseMatrix> ReturnType;
0028 
0029   ReturnType produceDBNoiseMatrix(const CSCDBNoiseMatrixRcd &);
0030 
0031 private:
0032   // ----------member data ---------------------------
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034                       const edm::IOVSyncValue &,
0035                       edm::ValidityInterval &) override;
0036   CSCDBNoiseMatrix *cndbMatrix;
0037 };
0038 
0039 #include <fstream>
0040 #include <iostream>
0041 #include <vector>
0042 
0043 // to workaround plugin library
0044 inline CSCDBNoiseMatrix *CSCNoiseMatrixDBConditions::prefillDBNoiseMatrix() {
0045   // const int MAX_SIZE = 273024; //for ME1a unganged
0046   const int MAX_SIZE = 252288;
0047   const int FACTOR = 1000;
0048   const int MAX_SHORT = 32767;
0049 
0050   int new_index, db_index;
0051   float db_elm33, db_elm34, db_elm44, db_elm35, db_elm45, db_elm55;
0052   float db_elm46, db_elm56, db_elm66, db_elm57, db_elm67, db_elm77;
0053   std::vector<int> db_index_id;
0054   std::vector<float> db_elem33;
0055   std::vector<float> db_elem34;
0056   std::vector<float> db_elem44;
0057   std::vector<float> db_elem45;
0058   std::vector<float> db_elem35;
0059   std::vector<float> db_elem55;
0060   std::vector<float> db_elem46;
0061   std::vector<float> db_elem56;
0062   std::vector<float> db_elem66;
0063   std::vector<float> db_elem57;
0064   std::vector<float> db_elem67;
0065   std::vector<float> db_elem77;
0066 
0067   float new_elm33, new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
0068   float new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
0069   std::vector<int> new_cham_id;
0070   std::vector<int> new_index_id;
0071   std::vector<float> new_elem33;
0072   std::vector<float> new_elem34;
0073   std::vector<float> new_elem44;
0074   std::vector<float> new_elem45;
0075   std::vector<float> new_elem35;
0076   std::vector<float> new_elem55;
0077   std::vector<float> new_elem46;
0078   std::vector<float> new_elem56;
0079   std::vector<float> new_elem66;
0080   std::vector<float> new_elem57;
0081   std::vector<float> new_elem67;
0082   std::vector<float> new_elem77;
0083 
0084   CSCDBNoiseMatrix *cndbmatrix = new CSCDBNoiseMatrix();
0085 
0086   int counter;
0087   int db_nrlines = 0;
0088   int new_nrlines = 0;
0089 
0090   std::ifstream dbdata;
0091   dbdata.open("old_dbmatrix.dat", std::ios::in);
0092   if (!dbdata) {
0093     std::cerr << "Error: old_dbmatrix.dat -> no such file!" << std::endl;
0094     exit(1);
0095   }
0096 
0097   while (!dbdata.eof()) {
0098     dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >>
0099         db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77;
0100     db_index_id.push_back(db_index);
0101     db_elem33.push_back(db_elm33);
0102     db_elem34.push_back(db_elm34);
0103     db_elem35.push_back(db_elm35);
0104     db_elem44.push_back(db_elm44);
0105     db_elem45.push_back(db_elm45);
0106     db_elem46.push_back(db_elm46);
0107     db_elem55.push_back(db_elm55);
0108     db_elem56.push_back(db_elm56);
0109     db_elem57.push_back(db_elm57);
0110     db_elem66.push_back(db_elm66);
0111     db_elem67.push_back(db_elm67);
0112     db_elem77.push_back(db_elm77);
0113     db_nrlines++;
0114   }
0115   dbdata.close();
0116 
0117   std::ifstream newdata;
0118   newdata.open("matrix.dat", std::ios::in);
0119   if (!newdata) {
0120     std::cerr << "Error: matrix.dat -> no such file!" << std::endl;
0121     exit(1);
0122   }
0123 
0124   while (!newdata.eof()) {
0125     newdata >> new_index >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >>
0126         new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77;
0127     // new_cham_id.push_back(new_chamber_id);
0128     new_index_id.push_back(new_index);
0129     new_elem33.push_back(new_elm33);
0130     new_elem34.push_back(new_elm34);
0131     new_elem35.push_back(new_elm35);
0132     new_elem44.push_back(new_elm44);
0133     new_elem45.push_back(new_elm45);
0134     new_elem46.push_back(new_elm46);
0135     new_elem55.push_back(new_elm55);
0136     new_elem56.push_back(new_elm56);
0137     new_elem57.push_back(new_elm57);
0138     new_elem66.push_back(new_elm66);
0139     new_elem67.push_back(new_elm67);
0140     new_elem77.push_back(new_elm77);
0141     new_nrlines++;
0142   }
0143   newdata.close();
0144 
0145   CSCDBNoiseMatrix::NoiseMatrixContainer &itemvector = cndbmatrix->matrix;
0146   itemvector.resize(MAX_SIZE);
0147   cndbmatrix->factor_noise = int(FACTOR);
0148 
0149   for (int i = 0; i < MAX_SIZE; ++i) {
0150     itemvector[i].elem33 = (short int)(db_elem33[i] * FACTOR + 0.5);
0151     itemvector[i].elem34 = (short int)(db_elem34[i] * FACTOR + 0.5);
0152     itemvector[i].elem35 = (short int)(db_elem35[i] * FACTOR + 0.5);
0153     itemvector[i].elem44 = (short int)(db_elem44[i] * FACTOR + 0.5);
0154     itemvector[i].elem45 = (short int)(db_elem45[i] * FACTOR + 0.5);
0155     itemvector[i].elem46 = (short int)(db_elem46[i] * FACTOR + 0.5);
0156     itemvector[i].elem55 = (short int)(db_elem55[i] * FACTOR + 0.5);
0157     itemvector[i].elem56 = (short int)(db_elem56[i] * FACTOR + 0.5);
0158     itemvector[i].elem57 = (short int)(db_elem57[i] * FACTOR + 0.5);
0159     itemvector[i].elem66 = (short int)(db_elem66[i] * FACTOR + 0.5);
0160     itemvector[i].elem67 = (short int)(db_elem67[i] * FACTOR + 0.5);
0161     itemvector[i].elem77 = (short int)(db_elem77[i] * FACTOR + 0.5);
0162   }
0163 
0164   for (int i = 0; i < MAX_SIZE; ++i) {
0165     counter = db_index_id[i];
0166     itemvector[i] = itemvector[counter];
0167     itemvector[i].elem33 = int(db_elem33[i]);
0168     itemvector[i].elem34 = int(db_elem34[i]);
0169     itemvector[i].elem35 = int(db_elem35[i]);
0170     itemvector[i].elem44 = int(db_elem44[i]);
0171     itemvector[i].elem45 = int(db_elem45[i]);
0172     itemvector[i].elem46 = int(db_elem46[i]);
0173     itemvector[i].elem55 = int(db_elem55[i]);
0174     itemvector[i].elem56 = int(db_elem56[i]);
0175     itemvector[i].elem57 = int(db_elem57[i]);
0176     itemvector[i].elem66 = int(db_elem66[i]);
0177     itemvector[i].elem67 = int(db_elem67[i]);
0178     itemvector[i].elem77 = int(db_elem77[i]);
0179 
0180     for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
0181       if (counter == new_index_id[k]) {
0182         if ((short int)(fabs(new_elem33[k] * FACTOR + 0.5)) < MAX_SHORT)
0183           itemvector[counter].elem33 = int(new_elem33[k] * FACTOR + 0.5);
0184         if ((short int)(fabs(new_elem34[k] * FACTOR + 0.5)) < MAX_SHORT)
0185           itemvector[counter].elem34 = int(new_elem34[k] * FACTOR + 0.5);
0186         if ((short int)(fabs(new_elem35[k] * FACTOR + 0.5)) < MAX_SHORT)
0187           itemvector[counter].elem35 = int(new_elem35[k] * FACTOR + 0.5);
0188         if ((short int)(fabs(new_elem44[k] * FACTOR + 0.5)) < MAX_SHORT)
0189           itemvector[counter].elem44 = int(new_elem44[k] * FACTOR + 0.5);
0190         if ((short int)(fabs(new_elem45[k] * FACTOR + 0.5)) < MAX_SHORT)
0191           itemvector[counter].elem45 = int(new_elem45[k] * FACTOR + 0.5);
0192         if ((short int)(fabs(new_elem46[k] * FACTOR + 0.5)) < MAX_SHORT)
0193           itemvector[counter].elem46 = int(new_elem46[k] * FACTOR + 0.5);
0194         if ((short int)(fabs(new_elem55[k] * FACTOR + 0.5)) < MAX_SHORT)
0195           itemvector[counter].elem55 = int(new_elem55[k] * FACTOR + 0.5);
0196         if ((short int)(fabs(new_elem56[k] * FACTOR + 0.5)) < MAX_SHORT)
0197           itemvector[counter].elem56 = int(new_elem56[k] * FACTOR + 0.5);
0198         if ((short int)(fabs(new_elem57[k] * FACTOR + 0.5)) < MAX_SHORT)
0199           itemvector[counter].elem57 = int(new_elem57[k] * FACTOR + 0.5);
0200         if ((short int)(fabs(new_elem66[k] * FACTOR + 0.5)) < MAX_SHORT)
0201           itemvector[counter].elem66 = int(new_elem66[k] * FACTOR + 0.5);
0202         if ((short int)(fabs(new_elem67[k] * FACTOR + 0.5)) < MAX_SHORT)
0203           itemvector[counter].elem67 = int(new_elem67[k] * FACTOR + 0.5);
0204         if ((short int)(fabs(new_elem77[k] * FACTOR + 0.5)) < MAX_SHORT)
0205           itemvector[counter].elem77 = int(new_elem77[k] * FACTOR + 0.5);
0206         itemvector[i] = itemvector[counter];
0207       }
0208     }
0209 
0210     if (counter > 223968) {
0211       itemvector[counter].elem33 = int(db_elem33[i]);
0212       itemvector[counter].elem34 = int(db_elem34[i]);
0213       itemvector[counter].elem35 = int(db_elem35[i]);
0214       itemvector[counter].elem44 = int(db_elem44[i]);
0215       itemvector[counter].elem45 = int(db_elem45[i]);
0216       itemvector[counter].elem46 = int(db_elem46[i]);
0217       itemvector[counter].elem55 = int(db_elem55[i]);
0218       itemvector[counter].elem56 = int(db_elem56[i]);
0219       itemvector[counter].elem57 = int(db_elem57[i]);
0220       itemvector[counter].elem66 = int(db_elem66[i]);
0221       itemvector[counter].elem67 = int(db_elem67[i]);
0222       itemvector[counter].elem77 = int(db_elem77[i]);
0223       itemvector[i] = itemvector[counter];
0224     }
0225   }
0226 
0227   return cndbmatrix;
0228 }
0229 
0230 #endif