CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/RegionalCaloTrigger/plugins/L1RCTInputProducer.cc

Go to the documentation of this file.
00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTInputProducer.h" 
00002 
00003 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00004 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00005 
00006 #include "CondFormats/L1TObjects/interface/L1CaloHcalScale.h"
00007 #include "CondFormats/DataRecord/interface/L1CaloHcalScaleRcd.h"
00008 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00009 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
00010 
00011 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00012 #include "CondFormats/DataRecord/interface/L1EmEtScaleRcd.h"
00013 
00014 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00015 #include "CondFormats/DataRecord/interface/L1RCTParametersRcd.h"
00016 
00017 #include "CondFormats/L1TObjects/interface/L1RCTChannelMask.h"
00018 #include "CondFormats/DataRecord/interface/L1RCTChannelMaskRcd.h"
00019 
00020 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCT.h"
00021 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h" 
00022 
00023 #include <vector>
00024 using std::vector;
00025 
00026 #include <iostream>
00027 using std::cout;
00028 using std::endl;
00029 
00030 L1RCTInputProducer::L1RCTInputProducer(const edm::ParameterSet& conf) : 
00031   rctLookupTables(new L1RCTLookupTables),
00032   rct(new L1RCT(rctLookupTables)),
00033   useEcal(conf.getParameter<bool>("useEcal")),
00034   useHcal(conf.getParameter<bool>("useHcal")),
00035   ecalDigisLabel(conf.getParameter<edm::InputTag>("ecalDigisLabel")),
00036   hcalDigisLabel(conf.getParameter<edm::InputTag>("hcalDigisLabel"))
00037 {
00038   produces<std::vector<unsigned short> >("rctCrate");
00039   produces<std::vector<unsigned short> >("rctCard");
00040   produces<std::vector<unsigned short> >("rctTower");
00041   produces<std::vector<unsigned int> >("rctEGammaET");
00042   produces<std::vector<bool> >("rctHoEFGVetoBit");
00043   produces<std::vector<unsigned int> >("rctJetMETET");
00044   produces<std::vector<bool> >("rctTowerActivityBit");
00045   produces<std::vector<bool> >("rctTowerMIPBit");
00046   produces<std::vector<unsigned short> >("rctHFCrate");
00047   produces<std::vector<unsigned short> >("rctHFRegion");
00048   produces<std::vector<unsigned int> >("rctHFET");
00049   produces<std::vector<bool> >("rctHFFG");
00050 }
00051 
00052 L1RCTInputProducer::~L1RCTInputProducer()
00053 {
00054   if(rct != 0) delete rct;
00055   if(rctLookupTables != 0) delete rctLookupTables;
00056 }
00057 
00058 
00059 
00060 void L1RCTInputProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup)
00061 {
00062 
00063   // Refresh configuration information every event
00064   // Hopefully, this does not take too much time
00065   // There should be a call back function in future to
00066   // handle changes in configuration
00067 
00068   edm::ESHandle<L1RCTParameters> rctParameters;
00069   eventSetup.get<L1RCTParametersRcd>().get(rctParameters);
00070   const L1RCTParameters* r = rctParameters.product();
00071   edm::ESHandle<L1RCTChannelMask> channelMask;
00072   eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
00073   const L1RCTChannelMask* c = channelMask.product();
00074   edm::ESHandle<L1CaloEcalScale> ecalScale;
00075   eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
00076   const L1CaloEcalScale* e = ecalScale.product();
00077   edm::ESHandle<L1CaloHcalScale> hcalScale;
00078   eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
00079   const L1CaloHcalScale* h = hcalScale.product();
00080   edm::ESHandle<L1CaloEtScale> emScale;
00081   eventSetup.get<L1EmEtScaleRcd>().get(emScale);
00082   const L1CaloEtScale* s = emScale.product();
00083 
00084   rctLookupTables->setRCTParameters(r);
00085   rctLookupTables->setChannelMask(c);
00086   rctLookupTables->setHcalScale(h);
00087   rctLookupTables->setEcalScale(e);
00088   rctLookupTables->setL1CaloEtScale(s);
00089 
00090   edm::Handle<EcalTrigPrimDigiCollection> ecal;
00091   edm::Handle<HcalTrigPrimDigiCollection> hcal;
00092   
00093   if (useEcal) { event.getByLabel(ecalDigisLabel, ecal); }
00094   if (useHcal) { event.getByLabel(hcalDigisLabel, hcal); }
00095 
00096   EcalTrigPrimDigiCollection ecalColl;
00097   HcalTrigPrimDigiCollection hcalColl;
00098   if (ecal.isValid()) { ecalColl = *ecal; }
00099   if (hcal.isValid()) { hcalColl = *hcal; }
00100 
00101   rct->digiInput(ecalColl, hcalColl);
00102 
00103   // Stuff to create
00104 
00105   std::auto_ptr<std::vector<unsigned short> > 
00106     rctCrate(new std::vector<unsigned short>);
00107   std::auto_ptr<std::vector<unsigned short> > 
00108     rctCard(new std::vector<unsigned short>);
00109   std::auto_ptr<std::vector<unsigned short> > 
00110     rctTower(new std::vector<unsigned short>);
00111   std::auto_ptr<std::vector<unsigned int> > 
00112     rctEGammaET(new std::vector<unsigned int>);
00113   std::auto_ptr<std::vector<bool> > rctHoEFGVetoBit(new std::vector<bool>);
00114   std::auto_ptr<std::vector<unsigned int> > 
00115     rctJetMETET(new std::vector<unsigned int>);
00116   std::auto_ptr<std::vector<bool> > rctTowerActivityBit(new std::vector<bool>);
00117   std::auto_ptr<std::vector<bool> > rctTowerMIPBit(new std::vector<bool>);
00118   
00119   for(int crate = 0; crate < 18; crate++) {
00120     for(int card = 0; card < 7; card++) {
00121       for(int tower = 0; tower < 32; tower++) {
00122         unsigned short ecalCompressedET = 
00123           rct->ecalCompressedET(crate, card, tower);
00124         unsigned short ecalFineGrainBit = 
00125           rct->ecalFineGrainBit(crate, card, tower);
00126         unsigned short hcalCompressedET = 
00127           rct->hcalCompressedET(crate, card, tower);
00128         unsigned int lutBits = 
00129           rctLookupTables->lookup(ecalCompressedET, hcalCompressedET, 
00130                                   ecalFineGrainBit, crate, card, tower);
00131         unsigned int eGammaETCode = lutBits & 0x0000007F;
00132         bool hOeFGVetoBit = (lutBits >> 7) & 0x00000001;
00133         unsigned int jetMETETCode = (lutBits >> 8) & 0x000001FF;
00134         bool activityBit = (lutBits >> 17) & 0x00000001;
00135         if(eGammaETCode > 0 || jetMETETCode > 0 || 
00136            hOeFGVetoBit || activityBit) {
00137           rctCrate->push_back(crate);
00138           rctCard->push_back(card);
00139           rctTower->push_back(tower);
00140           rctEGammaET->push_back(eGammaETCode);
00141           rctHoEFGVetoBit->push_back(hOeFGVetoBit);
00142           rctJetMETET->push_back(jetMETETCode);
00143           rctTowerActivityBit->push_back(activityBit);
00144           rctTowerMIPBit->push_back(0); // FIXME: MIP bit is not yet defined
00145         }
00146       }
00147     }
00148   }
00149 
00150   std::auto_ptr<std::vector<unsigned short> > 
00151     rctHFCrate(new std::vector<unsigned short>);
00152   std::auto_ptr<std::vector<unsigned short> > 
00153     rctHFRegion(new std::vector<unsigned short>);
00154   std::auto_ptr<std::vector<unsigned int> > rctHFET(new std::vector<unsigned int>);
00155   std::auto_ptr<std::vector<bool> > rctHFFG(new std::vector<bool>);
00156   for(int crate = 0; crate < 18; crate++) {
00157     for(int hfRegion = 0; hfRegion < 8; hfRegion++) {
00158       unsigned short hfCompressedET = rct->hfCompressedET(crate, hfRegion);
00159       unsigned int hfETCode = 
00160         rctLookupTables->lookup(hfCompressedET, crate, 999, hfRegion);
00161       if(hfETCode > 0) {
00162         rctHFCrate->push_back(crate);
00163         rctHFRegion->push_back(hfRegion);
00164         rctHFET->push_back(hfETCode);
00165         rctHFFG->push_back(0); // FIXME: HF FG is not yet defined
00166       }
00167     }
00168   }
00169 
00170   //putting stuff back into event
00171   event.put(rctCrate, "rctCrate");
00172   event.put(rctCard, "rctCard");
00173   event.put(rctTower, "rctTower");
00174   event.put(rctEGammaET, "rctEGammaET");
00175   event.put(rctHoEFGVetoBit, "rctHoEFGVetoBit");
00176   event.put(rctJetMETET, "rctJetMETET");
00177   event.put(rctTowerActivityBit, "rctTowerActivityBit");
00178   event.put(rctTowerMIPBit, "rctTowerMIPBit");
00179   event.put(rctHFCrate, "rctHFCrate");
00180   event.put(rctHFRegion, "rctHFRegion");
00181   event.put(rctHFET, "rctHFET");
00182   event.put(rctHFFG, "rctHFFG");
00183 
00184 }