Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef _CSCGAINSDBCONDITIONS_H
0002 #define _CSCGAINSDBCONDITIONS_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/CSCDBGains.h"
0017 #include "CondFormats/DataRecord/interface/CSCDBGainsRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019 
0020 class CSCGainsDBConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022   CSCGainsDBConditions(const edm::ParameterSet &);
0023   ~CSCGainsDBConditions() override;
0024 
0025   inline static CSCDBGains *prefillDBGains();
0026 
0027   typedef std::unique_ptr<CSCDBGains> ReturnType;
0028 
0029   ReturnType produceDBGains(const CSCDBGainsRcd &);
0030 
0031 private:
0032   // ----------member data ---------------------------
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034                       const edm::IOVSyncValue &,
0035                       edm::ValidityInterval &) override;
0036   CSCDBGains *cndbGains;
0037 };
0038 
0039 #include <fstream>
0040 #include <iostream>
0041 #include <vector>
0042 
0043 // to workaround plugin library
0044 inline CSCDBGains *CSCGainsDBConditions::prefillDBGains() {
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   CSCDBGains *cndbgains = new CSCDBGains();
0050 
0051   int db_index;
0052   float db_gainslope;  // db_intercpt, db_chisq;
0053   std::vector<int> db_index_id;
0054   std::vector<float> db_slope;
0055   std::vector<float> db_intercept;
0056   std::vector<float> db_chi2;
0057   int new_index;
0058   float new_gainslope, new_intercpt, new_chisq;
0059   std::vector<int> new_cham_id;
0060   std::vector<int> new_index_id;
0061   std::vector<int> new_strips;
0062   std::vector<float> new_slope;
0063   std::vector<float> new_intercept;
0064   std::vector<float> new_chi2;
0065 
0066   int counter;
0067 
0068   std::ifstream dbdata;
0069   dbdata.open("old_dbgains.dat", std::ios::in);
0070   if (!dbdata) {
0071     std::cerr << "Error: old_dbgains.dat -> no such file!" << std::endl;
0072     exit(1);
0073   }
0074 
0075   while (!dbdata.eof()) {
0076     dbdata >> db_index >> db_gainslope;
0077     db_index_id.push_back(db_index);
0078     db_slope.push_back(db_gainslope);
0079     // db_intercept.push_back(db_intercpt);
0080     // db_chi2.push_back(db_chisq);
0081   }
0082   dbdata.close();
0083 
0084   std::ifstream newdata;
0085   newdata.open("gains.dat", std::ios::in);
0086   if (!newdata) {
0087     std::cerr << "Error: gains.dat -> no such file!" << std::endl;
0088     exit(1);
0089   }
0090 
0091   while (!newdata.eof()) {
0092     newdata >> new_index >> new_gainslope >> new_intercpt >> new_chisq;
0093     new_index_id.push_back(new_index);
0094     new_slope.push_back(new_gainslope);
0095     new_intercept.push_back(new_intercpt);
0096     new_chi2.push_back(new_chisq);
0097   }
0098   newdata.close();
0099 
0100   CSCDBGains::GainContainer &itemvector = cndbgains->gains;
0101   itemvector.resize(MAX_SIZE);
0102   cndbgains->factor_gain = (short int)(FACTOR);
0103   std::cout << " myfactor " << cndbgains->factor_gain << std::endl;
0104 
0105   for (int i = 0; i < MAX_SIZE; ++i) {
0106     itemvector[i].gain_slope = int(db_slope[i] * FACTOR + 0.5);
0107   }
0108 
0109   for (int i = 0; i < MAX_SIZE; ++i) {
0110     counter = db_index_id[i];
0111     itemvector[i] = itemvector[counter];
0112     itemvector[i].gain_slope = int(db_slope[i]);
0113 
0114     for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
0115       if (counter == new_index_id[k]) {
0116         if ((short int)(fabs(new_slope[k] * FACTOR + 0.5)) < MAX_SHORT)
0117           itemvector[counter].gain_slope = int(new_slope[k] * FACTOR + 0.5);
0118         itemvector[i] = itemvector[counter];
0119       }
0120     }
0121     if (counter > 223968) {
0122       itemvector[counter].gain_slope = int(db_slope[i]);
0123       itemvector[i] = itemvector[counter];
0124     }
0125   }
0126   return cndbgains;
0127 }
0128 
0129 #endif