Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:46

0001 #include "ShallowEventDataProducer.h"
0002 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 // #include <bitset>
0008 
0009 ShallowEventDataProducer::ShallowEventDataProducer(const edm::ParameterSet& iConfig) {
0010   runPut_ = produces<unsigned int>("run");
0011   eventPut_ = produces<unsigned int>("event");
0012   bxPut_ = produces<unsigned int>("bx");
0013   lumiPut_ = produces<unsigned int>("lumi");
0014   instLumiPut_ = produces<float>("instLumi");
0015   puPut_ = produces<float>("PU");
0016 #ifdef ExtendedCALIBTree
0017   trigTechPut_ = produces<std::vector<bool>>("TrigTech");
0018   trigPhPut_ = produces<std::vector<bool>>("TrigPh");
0019   trig_token_ = consumes<L1GlobalTriggerReadoutRecord>(iConfig.getParameter<edm::InputTag>("trigRecord"));
0020 #endif
0021 
0022   scalerToken_ = consumes<LumiScalersCollection>(iConfig.getParameter<edm::InputTag>("lumiScalers"));
0023   metaDataToken_ = consumes<OnlineLuminosityRecord>(iConfig.getParameter<edm::InputTag>("metadata"));
0024 }
0025 
0026 void ShallowEventDataProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0027   iEvent.emplace(runPut_, iEvent.id().run());
0028   iEvent.emplace(eventPut_, iEvent.id().event());
0029   iEvent.emplace(bxPut_, iEvent.bunchCrossing());
0030   iEvent.emplace(lumiPut_, iEvent.luminosityBlock());
0031 
0032 #ifdef ExtendedCALIBTree
0033   edm::Handle<L1GlobalTriggerReadoutRecord> gtRecord;
0034   iEvent.getByToken(trig_token_, gtRecord);
0035 
0036   std::vector<bool> TrigTech_(64, false);
0037   std::vector<bool> TrigPh_(128, false);
0038 
0039   // Get dWord after masking disabled bits
0040   DecisionWord dWord = gtRecord->decisionWord();
0041   if (!dWord.empty()) {  // if board not there this is zero
0042     // loop over dec. bit to get total rate (no overlap)
0043     for (int i = 0; i < 64; ++i) {
0044       TrigPh_[i] = dWord[i];
0045     }
0046   }
0047 
0048   TechnicalTriggerWord tw = gtRecord->technicalTriggerWord();
0049   if (!tw.empty()) {
0050     // loop over dec. bit to get total rate (no overlap)
0051     for (int i = 0; i < 64; ++i) {
0052       TrigTech_[i] = tw[i];
0053     }
0054   }
0055 
0056   iEvent.emplace(trigTechPut_, std::move(TrigTech_));
0057   iEvent.emplace(trigPhPut_, std::move(TrigPh_));
0058 #endif
0059 
0060   // Luminosity informations
0061   edm::Handle<LumiScalersCollection> lumiScalers = iEvent.getHandle(scalerToken_);
0062   edm::Handle<OnlineLuminosityRecord> metaData = iEvent.getHandle(metaDataToken_);
0063 
0064   float instLumi_ = 0;
0065   float PU_ = 0;
0066 
0067   if (lumiScalers.isValid() && !lumiScalers->empty()) {
0068     if (lumiScalers->begin() != lumiScalers->end()) {
0069       instLumi_ = lumiScalers->begin()->instantLumi();
0070       PU_ = lumiScalers->begin()->pileup();
0071     }
0072   } else if (metaData.isValid()) {
0073     instLumi_ = metaData->instLumi();
0074     PU_ = metaData->avgPileUp();
0075   } else {
0076     edm::LogInfo("ShallowEventDataProducer")
0077         << "LumiScalers collection not found in the event; will write dummy values";
0078   }
0079 
0080   iEvent.emplace(instLumiPut_, instLumi_);
0081   iEvent.emplace(puPut_, PU_);
0082 }