CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/L1TriggerConfig/L1ScalesProducers/src/L1CaloInputScalesGenerator.cc

Go to the documentation of this file.
00001 #include "L1TriggerConfig/L1ScalesProducers/interface/L1CaloInputScalesGenerator.h"
00002 
00003 // system include files
00004 #include <memory>
00005 #include <iostream>
00006 using std::cout;
00007 using std::endl;
00008 #include <iomanip>
00009 using std::setprecision;
00010 #include <fstream>
00011 using std::ofstream;
00012 
00013 
00014 // user include files
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
00024 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
00025 #include "CalibCalorimetry/EcalTPGTools/interface/EcalTPGScale.h"
00026 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00027 
00028 
00029 //
00030 // constants, enums and typedefs
00031 //
00032 
00033 //
00034 // static data member definitions
00035 //
00036 
00037 //
00038 // constructors and destructor
00039 //
00040 L1CaloInputScalesGenerator::L1CaloInputScalesGenerator(const edm::ParameterSet& iConfig)
00041 
00042 {
00043    //now do what ever initialization is needed
00044 
00045 }
00046 
00047 
00048 L1CaloInputScalesGenerator::~L1CaloInputScalesGenerator()
00049 {
00050  
00051    // do anything here that needs to be done at desctruction time
00052    // (e.g. close files, deallocate resources etc.)
00053 
00054 }
00055 
00056 
00057 //
00058 // member functions
00059 //
00060 
00061 // ------------ method called to for each event  ------------
00062 void
00063 L1CaloInputScalesGenerator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00064 {
00065    using namespace edm;
00066 
00067 
00068    ESHandle<CaloTPGTranscoder> caloTPGTranscoder;
00069    iSetup.get<CaloTPGRecord>().get(caloTPGTranscoder);
00070    
00071    EcalTPGScale* ecalTPGScale = new EcalTPGScale();
00072    ecalTPGScale->setEventSetup(iSetup);
00073 
00074    double output; 
00075    ofstream scalesFile("L1CaloInputScales_cfi.py");
00076 
00077 
00078    // Write the ecal scales, positive eta
00079 
00080    scalesFile << "import FWCore.ParameterSet.Config as cms\n" <<endl;
00081 
00082    scalesFile << "L1CaloInputScalesProducer =cms.ESProducer(\"L1CaloInputScalesProducer\"," << endl;
00083    scalesFile << "L1EcalEtThresholdsPositiveEta = cms.vdouble(" << endl; 
00084 
00085 
00086    //Python does not support arrays over 255 entries so we neeed ton accomodate it by creating new array after 255 entries
00087    int nEntries = 0;
00088 
00089 
00090 
00091    // loop over ietas, barrel
00092    for (unsigned short absIeta = 1; absIeta <= 28; absIeta++)
00093      {
00094        EcalSubdetector subdet = ( absIeta <= 17 ) ? EcalBarrel : EcalEndcap ;
00095        // 8 bits of input energy
00096        for (unsigned short input = 0; input <= 0xFF; input++)
00097          {
00098            output = ecalTPGScale->getTPGInGeV( (unsigned int) input, 
00099                                               EcalTrigTowerDetId(1, subdet,
00100                                                                  absIeta, 1));
00101            scalesFile << setprecision (8) << output;
00102            nEntries++;
00103 
00104            if (absIeta == 28 && input == 0xFF)
00105              {
00106                scalesFile << "),";
00107              }
00108            else if(nEntries>254)
00109              {
00110                scalesFile <<")+cms.vdouble(";
00111                nEntries=0;
00112              }
00113            else
00114              {
00115                scalesFile << ", ";
00116              }
00117          }
00118        scalesFile << endl;
00119      }
00120 
00121    // Write the ecal scales, negative eta
00122 
00123    scalesFile << endl << "\tL1EcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
00124 
00125    nEntries=0;
00126    // loop over ietas, barrel first
00127    for (unsigned short absIeta = 1; absIeta <= 28; absIeta++)
00128      {
00129        EcalSubdetector subdet = ( absIeta <= 17 ) ? EcalBarrel : EcalEndcap ;
00130        // 8 bits of input energy
00131        for (unsigned short input = 0; input <= 0xFF; input++)
00132          {
00133            // negative eta
00134            output = ecalTPGScale->
00135              getTPGInGeV( (unsigned int) input, EcalTrigTowerDetId(-1, subdet,
00136                                                            absIeta, 2));
00137            scalesFile << setprecision (8) << output;
00138            nEntries++;
00139 
00140 
00141 
00142            if (absIeta == 28 && input == 0xFF)
00143              {
00144                scalesFile << "),";
00145              }
00146            else if(nEntries>254)
00147              {
00148                scalesFile <<")+cms.vdouble(";
00149                nEntries=0;
00150              }
00151            else
00152              {
00153                scalesFile << ", ";
00154              }
00155          }
00156        scalesFile << endl;
00157      }
00158 
00159    // Write the hcal scales (Positive Eta)
00160 
00161      scalesFile << endl << "\tL1HcalEtThresholdsPositiveEta = cms.vdouble(" << endl;
00162 
00163    // loop over ietas
00164 
00165      nEntries=0;
00166    for (unsigned short absIeta = 1; absIeta <= 32; absIeta++)
00167      {
00168        for (unsigned short input = 0; input <= 0xFF; input++)
00169          {
00170            output = caloTPGTranscoder->hcaletValue(absIeta, input); 
00171            scalesFile << setprecision (8) << output ;
00172            nEntries++;
00173 
00174 
00175            if (absIeta == 32 && input == 0xFF)
00176              {
00177                scalesFile << "),";
00178              }
00179            else if(nEntries>254)
00180              {
00181                scalesFile <<")+cms.vdouble(";
00182                nEntries=0;
00183              }
00184            else
00185              {
00186                scalesFile << ", ";
00187              }
00188          }
00189        scalesFile << endl;
00190      }
00191 
00192    // Write the hcal scales (Negative Eta)
00193 
00194      scalesFile << endl << "\tL1HcalEtThresholdsNegativeEta = cms.vdouble(" << endl;
00195 
00196      nEntries=0;  
00197    // loop over ietas
00198    for (unsigned short absIeta = 1; absIeta <= 32; absIeta++)
00199      {
00200        for (unsigned short input = 0; input <= 0xFF; input++)
00201          {
00202            output = caloTPGTranscoder->hcaletValue(-absIeta, input); 
00203            scalesFile << setprecision (8) << output ;
00204            nEntries++;
00205 
00206 
00207            if (absIeta == 32 && input == 0xFF)
00208              {
00209                scalesFile << ")";
00210              }
00211            else if(nEntries>254)
00212              {
00213                scalesFile <<")+cms.vdouble(";
00214                nEntries=0;
00215              }
00216            else 
00217              {
00218                scalesFile << ", ";
00219              }
00220          }
00221        scalesFile << endl;
00222      }
00223 
00224 
00225    scalesFile << ")" << endl;
00226 
00227    scalesFile.close();
00228 }
00229 
00230 
00231 // ------------ method called once each job just before starting event loop  ------------
00232 void 
00233 L1CaloInputScalesGenerator::beginJob()
00234 {
00235 }
00236 
00237 // ------------ method called once each job just after ending the event loop  ------------
00238 void 
00239 L1CaloInputScalesGenerator::endJob() {
00240 }
00241