Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:31

0001 ///
0002 /// \class l1t::L1TExtCondLegacyToStage2
0003 ///
0004 /// Description: Fill uGT external condition (stage2) with legacy information from data
0005 ///
0006 ///
0007 /// \author: D. Puigh OSU
0008 /// \revised: V. Rekovic
0009 
0010 // system include files
0011 
0012 // user include files
0013 
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/EDGetToken.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0027 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0028 #include "L1Trigger/L1TGlobal/plugins/TriggerMenuParser.h"
0029 
0030 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0031 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0032 
0033 //#include <vector>
0034 
0035 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0036 
0037 #include "DataFormats/L1Trigger/interface/BXVector.h"
0038 
0039 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0040 
0041 using namespace std;
0042 using namespace edm;
0043 using namespace l1t;
0044 
0045 //
0046 // class declaration
0047 //
0048 
0049 class L1TExtCondLegacyToStage2 : public stream::EDProducer<> {
0050 public:
0051   explicit L1TExtCondLegacyToStage2(const ParameterSet&);
0052   ~L1TExtCondLegacyToStage2() override;
0053 
0054   static void fillDescriptions(ConfigurationDescriptions& descriptions);
0055 
0056 private:
0057   void produce(edm::Event&, const edm::EventSetup&) override;
0058 
0059   // ----------member data ---------------------------
0060   //unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
0061   //std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
0062   //std::shared_ptr<const FirmwareVersion> m_fwv;
0063   //std::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
0064 
0065   // BX parameters
0066   int bxFirst_;
0067   int bxLast_;
0068 
0069   // Readout Record token
0070   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> gtReadoutRecordToken;
0071 
0072   // EventSetup Token for l1GtMenu
0073   edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> l1GtMenuToken;
0074 
0075   unsigned long long m_l1GtMenuCacheID;
0076   std::map<std::string, unsigned int> m_extBitMap;
0077 };
0078 
0079 //
0080 // constructors and destructor
0081 //
0082 L1TExtCondLegacyToStage2::L1TExtCondLegacyToStage2(const ParameterSet& iConfig)
0083     : bxFirst_(iConfig.getParameter<int>("bxFirst")),
0084       bxLast_(iConfig.getParameter<int>("bxLast")),
0085       gtReadoutRecordToken(
0086           consumes<L1GlobalTriggerReadoutRecord>(iConfig.getParameter<edm::InputTag>("LegacyGtReadoutRecord"))),
0087       l1GtMenuToken(esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>()) {
0088   // register what you produce
0089   produces<GlobalExtBlkBxCollection>();
0090 
0091   m_l1GtMenuCacheID = 0ULL;
0092 }
0093 
0094 L1TExtCondLegacyToStage2::~L1TExtCondLegacyToStage2() {}
0095 
0096 //
0097 // member functions
0098 //
0099 
0100 // ------------ method called to produce the data ------------
0101 void L1TExtCondLegacyToStage2::produce(Event& iEvent, const EventSetup& iSetup) {
0102   LogDebug("L1TExtCondLegacyToStage2") << "L1TExtCondLegacyToStage2::produce function called...\n";
0103 
0104   // get / update the trigger menu from the EventSetup
0105   // local cache & check on cacheIdentifier
0106   unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
0107 
0108   if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
0109     edm::ESHandle<L1TUtmTriggerMenu> l1GtMenu = iSetup.getHandle(l1GtMenuToken);
0110     const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
0111 
0112     // Instantiate Parser
0113     TriggerMenuParser gtParser = TriggerMenuParser();
0114 
0115     std::map<std::string, unsigned int> extBitMap = gtParser.getExternalSignals(utml1GtMenu);
0116 
0117     m_l1GtMenuCacheID = l1GtMenuCacheID;
0118     m_extBitMap = extBitMap;
0119   }
0120 
0121   bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
0122   bool foundBptxPlus = (m_extBitMap.find("BPTX_plus.v0") != m_extBitMap.end());
0123   bool foundBptxMinus = (m_extBitMap.find("BPTX_minus.v0") != m_extBitMap.end());
0124   bool foundBptxOR = (m_extBitMap.find("BPTX_plus_OR_minus.v0") != m_extBitMap.end());
0125 
0126   unsigned int bitBptxAND = m_extBitMap["BPTX_plus_AND_minus.v0"];
0127   unsigned int bitBptxPlus = m_extBitMap["BPTX_plus.v0"];
0128   unsigned int bitBptxMinus = m_extBitMap["BPTX_minus.v0"];
0129   unsigned int bitBptxOR = m_extBitMap["BPTX_plus_OR_minus.v0"];
0130 
0131   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
0132   iEvent.getByToken(gtReadoutRecordToken, gtReadoutRecord);
0133 
0134   // Setup vectors
0135   GlobalExtBlk extCond_bx_m2;
0136   GlobalExtBlk extCond_bx_m1;
0137   GlobalExtBlk extCond_bx_0;
0138   GlobalExtBlk extCond_bx_p1;
0139   GlobalExtBlk extCond_bx_p2;
0140 
0141   if (gtReadoutRecord.isValid()) {
0142     // L1GlobalTriggerReadoutRecord const & l1tResults = * gtReadoutRecord;
0143 
0144     // // select PSB#9 and bunch crossing 0
0145     // const L1GtPsbWord & psb = l1tResults.gtPsbWord(0xbb09, 0);
0146 
0147     // // the four 16-bit words psb.bData(1), psb.aData(1), psb.bData(0) and psb.aData(0) yield
0148     // // (in this sequence) the 64 technical trigger bits from most significant to least significant bit
0149     // uint64_t psbTriggerWord = ( (uint64_t) psb.bData(1) << 48) |
0150     //  ((uint64_t) psb.aData(1) << 32) |
0151     //  ((uint64_t) psb.bData(0) << 16) |
0152     //  ((uint64_t) psb.aData(0));
0153 
0154     // std::cout << "psbTriggerWord = " << psbTriggerWord << std::endl;
0155     // //
0156 
0157     for (int ibx = 0; ibx < 5; ibx++) {
0158       int useBx = ibx - 2;
0159       if (useBx < bxFirst_ || useBx > bxLast_)
0160         continue;
0161 
0162       //std::cout << "  BX = " << ibx - 2 << std::endl;
0163 
0164       // L1 technical
0165       const TechnicalTriggerWord& gtTTWord = gtReadoutRecord->technicalTriggerWord(useBx);
0166       int tbitNumber = 0;
0167       TechnicalTriggerWord::const_iterator GTtbitItr;
0168       bool passBptxAND = false;
0169       bool passBptxPlus = false;
0170       bool passBptxMinus = false;
0171       bool passBptxOR = false;
0172       for (GTtbitItr = gtTTWord.begin(); GTtbitItr != gtTTWord.end(); GTtbitItr++) {
0173         int pass_l1t_tech = 0;
0174         if (*GTtbitItr)
0175           pass_l1t_tech = 1;
0176 
0177         if (pass_l1t_tech == 1) {
0178           if (tbitNumber == 0)
0179             passBptxAND = true;
0180           else if (tbitNumber == 1)
0181             passBptxPlus = true;
0182           else if (tbitNumber == 2)
0183             passBptxMinus = true;
0184           else if (tbitNumber == 3)
0185             passBptxOR = true;
0186         }
0187 
0188         tbitNumber++;
0189       }
0190 
0191       if (useBx == -2) {
0192         if (passBptxAND && foundBptxAND)
0193           extCond_bx_m2.setExternalDecision(bitBptxAND, true);
0194         if (passBptxPlus && foundBptxPlus)
0195           extCond_bx_m2.setExternalDecision(bitBptxPlus, true);
0196         if (passBptxMinus && foundBptxMinus)
0197           extCond_bx_m2.setExternalDecision(bitBptxMinus, true);
0198         if (passBptxOR && foundBptxOR)
0199           extCond_bx_m2.setExternalDecision(bitBptxOR, true);
0200       } else if (useBx == -1) {
0201         if (passBptxAND && foundBptxAND)
0202           extCond_bx_m1.setExternalDecision(bitBptxAND, true);
0203         if (passBptxPlus && foundBptxPlus)
0204           extCond_bx_m1.setExternalDecision(bitBptxPlus, true);
0205         if (passBptxMinus && foundBptxMinus)
0206           extCond_bx_m1.setExternalDecision(bitBptxMinus, true);
0207         if (passBptxOR && foundBptxOR)
0208           extCond_bx_m1.setExternalDecision(bitBptxOR, true);
0209       } else if (useBx == 0) {
0210         if (passBptxAND && foundBptxAND)
0211           extCond_bx_0.setExternalDecision(bitBptxAND, true);
0212         if (passBptxPlus && foundBptxPlus)
0213           extCond_bx_0.setExternalDecision(bitBptxPlus, true);
0214         if (passBptxMinus && foundBptxMinus)
0215           extCond_bx_0.setExternalDecision(bitBptxMinus, true);
0216         if (passBptxOR && foundBptxOR)
0217           extCond_bx_0.setExternalDecision(bitBptxOR, true);
0218       } else if (useBx == 1) {
0219         if (passBptxAND && foundBptxAND)
0220           extCond_bx_p1.setExternalDecision(bitBptxAND, true);
0221         if (passBptxPlus && foundBptxPlus)
0222           extCond_bx_p1.setExternalDecision(bitBptxPlus, true);
0223         if (passBptxMinus && foundBptxMinus)
0224           extCond_bx_p1.setExternalDecision(bitBptxMinus, true);
0225         if (passBptxOR && foundBptxOR)
0226           extCond_bx_p1.setExternalDecision(bitBptxOR, true);
0227       } else if (useBx == 2) {
0228         if (passBptxAND && foundBptxAND)
0229           extCond_bx_p2.setExternalDecision(bitBptxAND, true);
0230         if (passBptxPlus && foundBptxPlus)
0231           extCond_bx_p2.setExternalDecision(bitBptxPlus, true);
0232         if (passBptxMinus && foundBptxMinus)
0233           extCond_bx_p2.setExternalDecision(bitBptxMinus, true);
0234         if (passBptxOR && foundBptxOR)
0235           extCond_bx_p2.setExternalDecision(bitBptxOR, true);
0236       }
0237     }
0238   } else {
0239     LogWarning("MissingProduct") << "Input L1GlobalTriggerReadoutRecord collection not found\n";
0240   }
0241 
0242   //outputs
0243   std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));
0244 
0245   // Fill Externals
0246   if (-2 >= bxFirst_ && -2 <= bxLast_)
0247     extCond->push_back(-2, extCond_bx_m2);
0248   if (-1 >= bxFirst_ && -1 <= bxLast_)
0249     extCond->push_back(-1, extCond_bx_m1);
0250   if (0 >= bxFirst_ && 0 <= bxLast_)
0251     extCond->push_back(0, extCond_bx_0);
0252   if (1 >= bxFirst_ && 1 <= bxLast_)
0253     extCond->push_back(1, extCond_bx_p1);
0254   if (2 >= bxFirst_ && 2 <= bxLast_)
0255     extCond->push_back(2, extCond_bx_p2);
0256 
0257   iEvent.put(std::move(extCond));
0258 }
0259 
0260 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
0261 void L1TExtCondLegacyToStage2::fillDescriptions(ConfigurationDescriptions& descriptions) {
0262   // l1GtExtCondLegacyToStage2
0263   edm::ParameterSetDescription desc;
0264   desc.add<int>("bxFirst", -2);
0265   desc.add<int>("bxLast", 2);
0266   desc.add<edm::InputTag>("LegacyGtReadoutRecord", edm::InputTag("unpackLegacyGtDigis"));
0267   descriptions.add("l1GtExtCondLegacyToStage2", desc);
0268 }
0269 
0270 //define this as a plug-in
0271 DEFINE_FWK_MODULE(L1TExtCondLegacyToStage2);