CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventHeader.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <istream>
4 #include <fstream>
5 #include <iomanip>
6 #include <stdlib.h>
7 #include <string.h>
8 
10 
12  fRun( -1 ),
13  fEvent( -1 ),
14  fLumiBlock( -1 ),
15  fBx( -1 ),
16  fOrbit( -1 ),
17  fAvgInstDelLumi( -999. ),
18  _Debug( false )
19 { }
20 
22 
23 }
24 
25 /* Setup the analysis to put the branch-variables into the tree. */
26 void EventHeader::setup(TTree* HltTree) {
27 
28  fRun = -1;
29  fEvent = -1;
30  fLumiBlock=-1;
31  fBx = -1;
32  fOrbit = -1;
33  fAvgInstDelLumi = -999.;
34 
35  HltTree->Branch("Run", &fRun, "Run/I");
36  HltTree->Branch("Event", &fEvent, "Event/I");
37  HltTree->Branch("LumiBlock", &fLumiBlock, "LumiBlock/I");
38  HltTree->Branch("Bx", &fBx, "Bx/I");
39  HltTree->Branch("Orbit", &fOrbit, "Orbit/I");
40  HltTree->Branch("AvgInstDelLumi", &fAvgInstDelLumi, "AvgInstDelLumi/D");
41 }
42 
43 /* **Analyze the event** */
44 void EventHeader::analyze(edm::Event const& iEvent, const edm::ESHandle<LumiCorrectionParam> & lumicorrdatahandle, TTree* HltTree) {
45  //void EventHeader::analyze(edm::Event const& iEvent, TTree* HltTree) {
46  fRun = iEvent.id().run();
47  fEvent = iEvent.id().event();
48  fLumiBlock = iEvent.luminosityBlock();
49  fBx = iEvent.bunchCrossing();
50  fOrbit = iEvent.orbitNumber();
51 
52 
53  bool lumiException = false;
54  const edm::LuminosityBlock& iLumi = iEvent.getLuminosityBlock();
56  try{
57  iLumi.getByLabel("lumiProducer", lumiSummary);
58  lumiSummary->isValid();
59  }
60  catch(cms::Exception&){
61  lumiException = true;
62  }
63  if(!lumiException)
64  {
65  // Raw delivered lumi
66  fAvgInstDelLumi = lumiSummary->avgInsDelLumi();
67 
68  // Now apply lumi corrections per LumiCalc#Luminosity_Objects_in_EDM_and_lu twiki
69  float instlumi = fAvgInstDelLumi;
70  float corrfac=1.;
71  if(lumicorrdatahandle.isValid()){
72  const LumiCorrectionParam* mydata=lumicorrdatahandle.product();
73  corrfac=mydata->getCorrection(instlumi);
74  fAvgInstDelLumi= corrfac * instlumi;
75  }
76  }
77  else
78  fAvgInstDelLumi = -999.;
79 
80  if (_Debug) {
81  std::cout << "EventHeader -- run = " << fRun << std::endl;
82  std::cout << "EventHeader -- event = " << fEvent << std::endl;
83  std::cout << "EventHeader -- lumisection = " << fLumiBlock << std::endl;
84  std::cout << "EventHeader -- bunch crossing = " << fBx << std::endl;
85  std::cout << "EventHeader -- orbit number = " << fOrbit << std::endl;
86  }
87 
88 }
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
int bunchCrossing() const
Definition: EventBase.h:62
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
tuple lumiSummary
Definition: runregparse.py:290
bool getByLabel(std::string const &label, Handle< PROD > &result) const
int iEvent
Definition: GenABIO.cc:243
void setup(TTree *tree)
Definition: EventHeader.cc:26
int fLumiBlock
Definition: EventHeader.h:36
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:68
int orbitNumber() const
Definition: EventBase.h:63
bool isValid() const
Definition: HandleBase.h:76
double fAvgInstDelLumi
Definition: EventHeader.h:39
T const * product() const
Definition: ESHandle.h:62
edm::EventID id() const
Definition: EventBase.h:56
float getCorrection(float luminonorm) const
get the final correction factor
tuple cout
Definition: gather_cfg.py:121
bool isValid() const
Definition: ESHandle.h:37
void analyze(edm::Event const &iEvent, const edm::ESHandle< LumiCorrectionParam > &lumiCorr, TTree *tree)
Definition: EventHeader.cc:44