Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:22

0001 #include <iostream>
0002 #include <sstream>
0003 #include <istream>
0004 #include <fstream>
0005 #include <iomanip>
0006 #include <cstdlib>
0007 #include <cstring>
0008 
0009 #include "EventHeader.h"
0010 
0011 EventHeader::EventHeader()
0012     : fEvent(0), fLumiBlock(-1), fRun(-1), fBx(-1), fOrbit(-1), fAvgInstDelLumi(-999.), _Debug(false) {}
0013 
0014 EventHeader::~EventHeader() = default;
0015 
0016 /*  Setup the analysis to put the branch-variables into the tree. */
0017 void EventHeader::setup(edm::ConsumesCollector&& iC, TTree* HltTree) {
0018   fEvent = 0;
0019   fLumiBlock = -1;
0020   fRun = -1;
0021   fBx = -1;
0022   fOrbit = -1;
0023   fAvgInstDelLumi = -999.;
0024 
0025   HltTree->Branch("Event", &fEvent, "Event/l");
0026   HltTree->Branch("LumiBlock", &fLumiBlock, "LumiBlock/I");
0027   HltTree->Branch("Run", &fRun, "Run/I");
0028   HltTree->Branch("Bx", &fBx, "Bx/I");
0029   HltTree->Branch("Orbit", &fOrbit, "Orbit/I");
0030   HltTree->Branch("AvgInstDelLumi", &fAvgInstDelLumi, "AvgInstDelLumi/D");
0031 
0032   lumi_Token = iC.consumes<LumiSummary, edm::InLumi>(edm::InputTag("lumiProducer"));
0033 }
0034 
0035 /* **Analyze the event** */
0036 void EventHeader::analyze(edm::Event const& iEvent, TTree* HltTree) {
0037   fEvent = iEvent.id().event();
0038   fLumiBlock = iEvent.luminosityBlock();
0039   fRun = iEvent.id().run();
0040   fBx = iEvent.bunchCrossing();
0041   fOrbit = iEvent.orbitNumber();
0042 
0043   bool lumiException = false;
0044   const edm::LuminosityBlock& iLumi = iEvent.getLuminosityBlock();
0045   edm::Handle<LumiSummary> lumiSummary;
0046   try {
0047     iLumi.getByToken(lumi_Token, lumiSummary);
0048     lumiSummary->isValid();
0049   } catch (cms::Exception&) {
0050     lumiException = true;
0051   }
0052   if (!lumiException)
0053     fAvgInstDelLumi = lumiSummary->avgInsDelLumi();
0054   else
0055     fAvgInstDelLumi = -999.;
0056 
0057   if (_Debug) {
0058     std::cout << "EventHeader -- event = " << fEvent << std::endl;
0059     std::cout << "EventHeader -- lumisection = " << fLumiBlock << std::endl;
0060     std::cout << "EventHeader -- run   = " << fRun << std::endl;
0061     std::cout << "EventHeader -- bunch crossing = " << fBx << std::endl;
0062     std::cout << "EventHeader -- orbit number = " << fOrbit << std::endl;
0063   }
0064 }