Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:21

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 
0088   std::ifstream dbdata;
0089   dbdata.open("old_dbmatrix.dat", std::ios::in);
0090   if (!dbdata) {
0091     std::cerr << "Error: old_dbmatrix.dat -> no such file!" << std::endl;
0092     exit(1);
0093   }
0094 
0095   while (!dbdata.eof()) {
0096     dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >>
0097         db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77;
0098     db_index_id.push_back(db_index);
0099     db_elem33.push_back(db_elm33);
0100     db_elem34.push_back(db_elm34);
0101     db_elem35.push_back(db_elm35);
0102     db_elem44.push_back(db_elm44);
0103     db_elem45.push_back(db_elm45);
0104     db_elem46.push_back(db_elm46);
0105     db_elem55.push_back(db_elm55);
0106     db_elem56.push_back(db_elm56);
0107     db_elem57.push_back(db_elm57);
0108     db_elem66.push_back(db_elm66);
0109     db_elem67.push_back(db_elm67);
0110     db_elem77.push_back(db_elm77);
0111   }
0112   dbdata.close();
0113 
0114   std::ifstream newdata;
0115   newdata.open("matrix.dat", std::ios::in);
0116   if (!newdata) {
0117     std::cerr << "Error: matrix.dat -> no such file!" << std::endl;
0118     exit(1);
0119   }
0120 
0121   while (!newdata.eof()) {
0122     newdata >> new_index >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >>
0123         new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77;
0124     // new_cham_id.push_back(new_chamber_id);
0125     new_index_id.push_back(new_index);
0126     new_elem33.push_back(new_elm33);
0127     new_elem34.push_back(new_elm34);
0128     new_elem35.push_back(new_elm35);
0129     new_elem44.push_back(new_elm44);
0130     new_elem45.push_back(new_elm45);
0131     new_elem46.push_back(new_elm46);
0132     new_elem55.push_back(new_elm55);
0133     new_elem56.push_back(new_elm56);
0134     new_elem57.push_back(new_elm57);
0135     new_elem66.push_back(new_elm66);
0136     new_elem67.push_back(new_elm67);
0137     new_elem77.push_back(new_elm77);
0138   }
0139   newdata.close();
0140 
0141   CSCDBNoiseMatrix::NoiseMatrixContainer &itemvector = cndbmatrix->matrix;
0142   itemvector.resize(MAX_SIZE);
0143   cndbmatrix->factor_noise = int(FACTOR);
0144 
0145   for (int i = 0; i < MAX_SIZE; ++i) {
0146     itemvector[i].elem33 = (short int)(db_elem33[i] * FACTOR + 0.5);
0147     itemvector[i].elem34 = (short int)(db_elem34[i] * FACTOR + 0.5);
0148     itemvector[i].elem35 = (short int)(db_elem35[i] * FACTOR + 0.5);
0149     itemvector[i].elem44 = (short int)(db_elem44[i] * FACTOR + 0.5);
0150     itemvector[i].elem45 = (short int)(db_elem45[i] * FACTOR + 0.5);
0151     itemvector[i].elem46 = (short int)(db_elem46[i] * FACTOR + 0.5);
0152     itemvector[i].elem55 = (short int)(db_elem55[i] * FACTOR + 0.5);
0153     itemvector[i].elem56 = (short int)(db_elem56[i] * FACTOR + 0.5);
0154     itemvector[i].elem57 = (short int)(db_elem57[i] * FACTOR + 0.5);
0155     itemvector[i].elem66 = (short int)(db_elem66[i] * FACTOR + 0.5);
0156     itemvector[i].elem67 = (short int)(db_elem67[i] * FACTOR + 0.5);
0157     itemvector[i].elem77 = (short int)(db_elem77[i] * FACTOR + 0.5);
0158   }
0159 
0160   for (int i = 0; i < MAX_SIZE; ++i) {
0161     counter = db_index_id[i];
0162     itemvector[i] = itemvector[counter];
0163     itemvector[i].elem33 = int(db_elem33[i]);
0164     itemvector[i].elem34 = int(db_elem34[i]);
0165     itemvector[i].elem35 = int(db_elem35[i]);
0166     itemvector[i].elem44 = int(db_elem44[i]);
0167     itemvector[i].elem45 = int(db_elem45[i]);
0168     itemvector[i].elem46 = int(db_elem46[i]);
0169     itemvector[i].elem55 = int(db_elem55[i]);
0170     itemvector[i].elem56 = int(db_elem56[i]);
0171     itemvector[i].elem57 = int(db_elem57[i]);
0172     itemvector[i].elem66 = int(db_elem66[i]);
0173     itemvector[i].elem67 = int(db_elem67[i]);
0174     itemvector[i].elem77 = int(db_elem77[i]);
0175 
0176     for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
0177       if (counter == new_index_id[k]) {
0178         if ((short int)(fabs(new_elem33[k] * FACTOR + 0.5)) < MAX_SHORT)
0179           itemvector[counter].elem33 = int(new_elem33[k] * FACTOR + 0.5);
0180         if ((short int)(fabs(new_elem34[k] * FACTOR + 0.5)) < MAX_SHORT)
0181           itemvector[counter].elem34 = int(new_elem34[k] * FACTOR + 0.5);
0182         if ((short int)(fabs(new_elem35[k] * FACTOR + 0.5)) < MAX_SHORT)
0183           itemvector[counter].elem35 = int(new_elem35[k] * FACTOR + 0.5);
0184         if ((short int)(fabs(new_elem44[k] * FACTOR + 0.5)) < MAX_SHORT)
0185           itemvector[counter].elem44 = int(new_elem44[k] * FACTOR + 0.5);
0186         if ((short int)(fabs(new_elem45[k] * FACTOR + 0.5)) < MAX_SHORT)
0187           itemvector[counter].elem45 = int(new_elem45[k] * FACTOR + 0.5);
0188         if ((short int)(fabs(new_elem46[k] * FACTOR + 0.5)) < MAX_SHORT)
0189           itemvector[counter].elem46 = int(new_elem46[k] * FACTOR + 0.5);
0190         if ((short int)(fabs(new_elem55[k] * FACTOR + 0.5)) < MAX_SHORT)
0191           itemvector[counter].elem55 = int(new_elem55[k] * FACTOR + 0.5);
0192         if ((short int)(fabs(new_elem56[k] * FACTOR + 0.5)) < MAX_SHORT)
0193           itemvector[counter].elem56 = int(new_elem56[k] * FACTOR + 0.5);
0194         if ((short int)(fabs(new_elem57[k] * FACTOR + 0.5)) < MAX_SHORT)
0195           itemvector[counter].elem57 = int(new_elem57[k] * FACTOR + 0.5);
0196         if ((short int)(fabs(new_elem66[k] * FACTOR + 0.5)) < MAX_SHORT)
0197           itemvector[counter].elem66 = int(new_elem66[k] * FACTOR + 0.5);
0198         if ((short int)(fabs(new_elem67[k] * FACTOR + 0.5)) < MAX_SHORT)
0199           itemvector[counter].elem67 = int(new_elem67[k] * FACTOR + 0.5);
0200         if ((short int)(fabs(new_elem77[k] * FACTOR + 0.5)) < MAX_SHORT)
0201           itemvector[counter].elem77 = int(new_elem77[k] * FACTOR + 0.5);
0202         itemvector[i] = itemvector[counter];
0203       }
0204     }
0205 
0206     if (counter > 223968) {
0207       itemvector[counter].elem33 = int(db_elem33[i]);
0208       itemvector[counter].elem34 = int(db_elem34[i]);
0209       itemvector[counter].elem35 = int(db_elem35[i]);
0210       itemvector[counter].elem44 = int(db_elem44[i]);
0211       itemvector[counter].elem45 = int(db_elem45[i]);
0212       itemvector[counter].elem46 = int(db_elem46[i]);
0213       itemvector[counter].elem55 = int(db_elem55[i]);
0214       itemvector[counter].elem56 = int(db_elem56[i]);
0215       itemvector[counter].elem57 = int(db_elem57[i]);
0216       itemvector[counter].elem66 = int(db_elem66[i]);
0217       itemvector[counter].elem67 = int(db_elem67[i]);
0218       itemvector[counter].elem77 = int(db_elem77[i]);
0219       itemvector[i] = itemvector[counter];
0220     }
0221   }
0222 
0223   return cndbmatrix;
0224 }
0225 
0226 #endif