Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:30

0001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTInputProducer.h"
0002 
0003 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0004 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0005 
0006 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCT.h"
0007 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h"
0008 
0009 #include <vector>
0010 using std::vector;
0011 
0012 #include <iostream>
0013 using std::cout;
0014 using std::endl;
0015 
0016 L1RCTInputProducer::L1RCTInputProducer(const edm::ParameterSet &conf)
0017     : rctLookupTables(new L1RCTLookupTables),
0018       rct(new L1RCT(rctLookupTables)),
0019       useEcal(conf.getParameter<bool>("useEcal")),
0020       useHcal(conf.getParameter<bool>("useHcal")),
0021       ecalDigisLabel(conf.getParameter<edm::InputTag>("ecalDigisLabel")),
0022       hcalDigisLabel(conf.getParameter<edm::InputTag>("hcalDigisLabel")),
0023       rctParametersToken(esConsumes<L1RCTParameters, L1RCTParametersRcd>()),
0024       channelMaskToken(esConsumes<L1RCTChannelMask, L1RCTChannelMaskRcd>()),
0025       ecalScaleToken(esConsumes<L1CaloEcalScale, L1CaloEcalScaleRcd>()),
0026       hcalScaleToken(esConsumes<L1CaloHcalScale, L1CaloHcalScaleRcd>()),
0027       emScaleToken(esConsumes<L1CaloEtScale, L1EmEtScaleRcd>()) {
0028   produces<std::vector<unsigned short>>("rctCrate");
0029   produces<std::vector<unsigned short>>("rctCard");
0030   produces<std::vector<unsigned short>>("rctTower");
0031   produces<std::vector<unsigned int>>("rctEGammaET");
0032   produces<std::vector<bool>>("rctHoEFGVetoBit");
0033   produces<std::vector<unsigned int>>("rctJetMETET");
0034   produces<std::vector<bool>>("rctTowerActivityBit");
0035   produces<std::vector<bool>>("rctTowerMIPBit");
0036   produces<std::vector<unsigned short>>("rctHFCrate");
0037   produces<std::vector<unsigned short>>("rctHFRegion");
0038   produces<std::vector<unsigned int>>("rctHFET");
0039   produces<std::vector<bool>>("rctHFFG");
0040 }
0041 
0042 L1RCTInputProducer::~L1RCTInputProducer() {
0043   if (rct != nullptr)
0044     delete rct;
0045   if (rctLookupTables != nullptr)
0046     delete rctLookupTables;
0047 }
0048 
0049 void L1RCTInputProducer::produce(edm::Event &event, const edm::EventSetup &eventSetup) {
0050   // Refresh configuration information every event
0051   // Hopefully, this does not take too much time
0052   // There should be a call back function in future to
0053   // handle changes in configuration
0054 
0055   edm::ESHandle<L1RCTParameters> rctParameters = eventSetup.getHandle(rctParametersToken);
0056   const L1RCTParameters *r = rctParameters.product();
0057   edm::ESHandle<L1RCTChannelMask> channelMask = eventSetup.getHandle(channelMaskToken);
0058   const L1RCTChannelMask *c = channelMask.product();
0059   edm::ESHandle<L1CaloEcalScale> ecalScale = eventSetup.getHandle(ecalScaleToken);
0060   const L1CaloEcalScale *e = ecalScale.product();
0061   edm::ESHandle<L1CaloHcalScale> hcalScale = eventSetup.getHandle(hcalScaleToken);
0062   const L1CaloHcalScale *h = hcalScale.product();
0063   edm::ESHandle<L1CaloEtScale> emScale = eventSetup.getHandle(emScaleToken);
0064   const L1CaloEtScale *s = emScale.product();
0065 
0066   rctLookupTables->setRCTParameters(r);
0067   rctLookupTables->setChannelMask(c);
0068   rctLookupTables->setHcalScale(h);
0069   rctLookupTables->setEcalScale(e);
0070   rctLookupTables->setL1CaloEtScale(s);
0071 
0072   edm::Handle<EcalTrigPrimDigiCollection> ecal;
0073   edm::Handle<HcalTrigPrimDigiCollection> hcal;
0074 
0075   if (useEcal) {
0076     event.getByLabel(ecalDigisLabel, ecal);
0077   }
0078   if (useHcal) {
0079     event.getByLabel(hcalDigisLabel, hcal);
0080   }
0081 
0082   EcalTrigPrimDigiCollection ecalColl;
0083   HcalTrigPrimDigiCollection hcalColl;
0084   if (ecal.isValid()) {
0085     ecalColl = *ecal;
0086   }
0087   if (hcal.isValid()) {
0088     hcalColl = *hcal;
0089   }
0090 
0091   rct->digiInput(ecalColl, hcalColl);
0092 
0093   // Stuff to create
0094 
0095   std::unique_ptr<std::vector<unsigned short>> rctCrate(new std::vector<unsigned short>);
0096   std::unique_ptr<std::vector<unsigned short>> rctCard(new std::vector<unsigned short>);
0097   std::unique_ptr<std::vector<unsigned short>> rctTower(new std::vector<unsigned short>);
0098   std::unique_ptr<std::vector<unsigned int>> rctEGammaET(new std::vector<unsigned int>);
0099   std::unique_ptr<std::vector<bool>> rctHoEFGVetoBit(new std::vector<bool>);
0100   std::unique_ptr<std::vector<unsigned int>> rctJetMETET(new std::vector<unsigned int>);
0101   std::unique_ptr<std::vector<bool>> rctTowerActivityBit(new std::vector<bool>);
0102   std::unique_ptr<std::vector<bool>> rctTowerMIPBit(new std::vector<bool>);
0103 
0104   for (int crate = 0; crate < 18; crate++) {
0105     for (int card = 0; card < 7; card++) {
0106       for (int tower = 0; tower < 32; tower++) {
0107         unsigned short ecalCompressedET = rct->ecalCompressedET(crate, card, tower);
0108         unsigned short ecalFineGrainBit = rct->ecalFineGrainBit(crate, card, tower);
0109         unsigned short hcalCompressedET = rct->hcalCompressedET(crate, card, tower);
0110         unsigned int lutBits =
0111             rctLookupTables->lookup(ecalCompressedET, hcalCompressedET, ecalFineGrainBit, crate, card, tower);
0112         unsigned int eGammaETCode = lutBits & 0x0000007F;
0113         bool hOeFGVetoBit = (lutBits >> 7) & 0x00000001;
0114         unsigned int jetMETETCode = (lutBits >> 8) & 0x000001FF;
0115         bool activityBit = (lutBits >> 17) & 0x00000001;
0116         if (eGammaETCode > 0 || jetMETETCode > 0 || hOeFGVetoBit || activityBit) {
0117           rctCrate->push_back(crate);
0118           rctCard->push_back(card);
0119           rctTower->push_back(tower);
0120           rctEGammaET->push_back(eGammaETCode);
0121           rctHoEFGVetoBit->push_back(hOeFGVetoBit);
0122           rctJetMETET->push_back(jetMETETCode);
0123           rctTowerActivityBit->push_back(activityBit);
0124           rctTowerMIPBit->push_back(false);  // FIXME: MIP bit is not yet defined
0125         }
0126       }
0127     }
0128   }
0129 
0130   std::unique_ptr<std::vector<unsigned short>> rctHFCrate(new std::vector<unsigned short>);
0131   std::unique_ptr<std::vector<unsigned short>> rctHFRegion(new std::vector<unsigned short>);
0132   std::unique_ptr<std::vector<unsigned int>> rctHFET(new std::vector<unsigned int>);
0133   std::unique_ptr<std::vector<bool>> rctHFFG(new std::vector<bool>);
0134   for (int crate = 0; crate < 18; crate++) {
0135     for (int hfRegion = 0; hfRegion < 8; hfRegion++) {
0136       unsigned short hfCompressedET = rct->hfCompressedET(crate, hfRegion);
0137       unsigned int hfETCode = rctLookupTables->lookup(hfCompressedET, crate, 999, hfRegion);
0138       if (hfETCode > 0) {
0139         rctHFCrate->push_back(crate);
0140         rctHFRegion->push_back(hfRegion);
0141         rctHFET->push_back(hfETCode);
0142         rctHFFG->push_back(false);  // FIXME: HF FG is not yet defined
0143       }
0144     }
0145   }
0146 
0147   // putting stuff back into event
0148   event.put(std::move(rctCrate), "rctCrate");
0149   event.put(std::move(rctCard), "rctCard");
0150   event.put(std::move(rctTower), "rctTower");
0151   event.put(std::move(rctEGammaET), "rctEGammaET");
0152   event.put(std::move(rctHoEFGVetoBit), "rctHoEFGVetoBit");
0153   event.put(std::move(rctJetMETET), "rctJetMETET");
0154   event.put(std::move(rctTowerActivityBit), "rctTowerActivityBit");
0155   event.put(std::move(rctTowerMIPBit), "rctTowerMIPBit");
0156   event.put(std::move(rctHFCrate), "rctHFCrate");
0157   event.put(std::move(rctHFRegion), "rctHFRegion");
0158   event.put(std::move(rctHFET), "rctHFET");
0159   event.put(std::move(rctHFFG), "rctHFFG");
0160 }