Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:56:47

0001 #include "L1TriggerConfig/L1ScalesProducers/interface/L1CaloInputScalesGenerator.h"
0002 
0003 // system include files
0004 #include <memory>
0005 #include <iostream>
0006 using std::cout;
0007 using std::endl;
0008 #include <iomanip>
0009 using std::setprecision;
0010 #include <fstream>
0011 using std::ofstream;
0012 
0013 // user include files
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
0023 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
0024 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
0025 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0026 
0027 //
0028 // constants, enums and typedefs
0029 //
0030 
0031 //
0032 // static data member definitions
0033 //
0034 
0035 //
0036 // constructors and destructor
0037 //
0038 L1CaloInputScalesGenerator::L1CaloInputScalesGenerator(const edm::ParameterSet& iConfig)
0039     : transcoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()), tokens_(consumesCollector()) {
0040   //now do what ever initialization is needed
0041 }
0042 
0043 L1CaloInputScalesGenerator::~L1CaloInputScalesGenerator() {
0044   // do anything here that needs to be done at desctruction time
0045   // (e.g. close files, deallocate resources etc.)
0046 }
0047 
0048 //
0049 // member functions
0050 //
0051 
0052 // ------------ method called to for each event  ------------
0053 void L1CaloInputScalesGenerator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0054   using namespace edm;
0055 
0056   ESHandle<CaloTPGTranscoder> caloTPGTranscoder = iSetup.getHandle(transcoderToken_);
0057 
0058   EcalTPGScale ecalTPGScale(tokens_, iSetup);
0059 
0060   double output;
0061   ofstream scalesFile("L1CaloInputScales_cfi.py");
0062 
0063   // Write the ecal scales, positive eta
0064 
0065   scalesFile << "import FWCore.ParameterSet.Config as cms\n" << endl;
0066 
0067   scalesFile << "L1CaloInputScalesProducer =cms.ESProducer(\"L1CaloInputScalesProducer\"," << endl;
0068   scalesFile << "L1EcalEtThresholdsPositiveEta = cms.vdouble(" << endl;
0069 
0070   //Python does not support arrays over 255 entries so we neeed ton accomodate it by creating new array after 255 entries
0071   int nEntries = 0;
0072 
0073   // loop over ietas, barrel
0074   for (unsigned short absIeta = 1; absIeta <= 28; absIeta++) {
0075     EcalSubdetector subdet = (absIeta <= 17) ? EcalBarrel : EcalEndcap;
0076     // 8 bits of input energy
0077     for (unsigned short input = 0; input <= 0xFF; input++) {
0078       output = ecalTPGScale.getTPGInGeV((unsigned int)input, EcalTrigTowerDetId(1, subdet, absIeta, 1));
0079       scalesFile << setprecision(8) << output;
0080       nEntries++;
0081 
0082       if (absIeta == 28 && input == 0xFF) {
0083         scalesFile << "),";
0084       } else if (nEntries > 254) {
0085         scalesFile << ")+cms.vdouble(";
0086         nEntries = 0;
0087       } else {
0088         scalesFile << ", ";
0089       }
0090     }
0091     scalesFile << endl;
0092   }
0093 
0094   // Write the ecal scales, negative eta
0095 
0096   scalesFile << endl << "\tL1EcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
0097 
0098   nEntries = 0;
0099   // loop over ietas, barrel first
0100   for (unsigned short absIeta = 1; absIeta <= 28; absIeta++) {
0101     EcalSubdetector subdet = (absIeta <= 17) ? EcalBarrel : EcalEndcap;
0102     // 8 bits of input energy
0103     for (unsigned short input = 0; input <= 0xFF; input++) {
0104       // negative eta
0105       output = ecalTPGScale.getTPGInGeV((unsigned int)input, EcalTrigTowerDetId(-1, subdet, absIeta, 2));
0106       scalesFile << setprecision(8) << output;
0107       nEntries++;
0108 
0109       if (absIeta == 28 && input == 0xFF) {
0110         scalesFile << "),";
0111       } else if (nEntries > 254) {
0112         scalesFile << ")+cms.vdouble(";
0113         nEntries = 0;
0114       } else {
0115         scalesFile << ", ";
0116       }
0117     }
0118     scalesFile << endl;
0119   }
0120 
0121   // Write the hcal scales (Positive Eta)
0122 
0123   scalesFile << endl << "\tL1HcalEtThresholdsPositiveEta = cms.vdouble(" << endl;
0124 
0125   // loop over ietas
0126 
0127   nEntries = 0;
0128   for (unsigned short absIeta = 1; absIeta <= 32; absIeta++) {
0129     for (unsigned short input = 0; input <= 0xFF; input++) {
0130       output = caloTPGTranscoder->hcaletValue(absIeta, input);
0131       scalesFile << setprecision(8) << output;
0132       nEntries++;
0133 
0134       if (absIeta == 32 && input == 0xFF) {
0135         scalesFile << "),";
0136       } else if (nEntries > 254) {
0137         scalesFile << ")+cms.vdouble(";
0138         nEntries = 0;
0139       } else {
0140         scalesFile << ", ";
0141       }
0142     }
0143     scalesFile << endl;
0144   }
0145 
0146   // Write the hcal scales (Negative Eta)
0147 
0148   scalesFile << endl << "\tL1HcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
0149 
0150   nEntries = 0;
0151   // loop over ietas
0152   for (unsigned short absIeta = 1; absIeta <= 32; absIeta++) {
0153     for (unsigned short input = 0; input <= 0xFF; input++) {
0154       output = caloTPGTranscoder->hcaletValue(-absIeta, input);
0155       scalesFile << setprecision(8) << output;
0156       nEntries++;
0157 
0158       if (absIeta == 32 && input == 0xFF) {
0159         scalesFile << ")";
0160       } else if (nEntries > 254) {
0161         scalesFile << ")+cms.vdouble(";
0162         nEntries = 0;
0163       } else {
0164         scalesFile << ", ";
0165       }
0166     }
0167     scalesFile << endl;
0168   }
0169 
0170   scalesFile << ")" << endl;
0171 
0172   scalesFile.close();
0173 }
0174 
0175 // ------------ method called once each job just before starting event loop  ------------
0176 void L1CaloInputScalesGenerator::beginJob() {}
0177 
0178 // ------------ method called once each job just after ending the event loop  ------------
0179 void L1CaloInputScalesGenerator::endJob() {}