1 |
|
2 |
#include "FWCore/Framework/interface/EDProducer.h"
|
3 |
#include "FWCore/Utilities/interface/InputTag.h"
|
4 |
#include "FWCore/Framework/interface/EventSetup.h"
|
5 |
|
6 |
#include <string>
|
7 |
|
8 |
class TFile;
|
9 |
|
10 |
class LuminosityWeightProducer : public edm::EDProducer {
|
11 |
public:
|
12 |
LuminosityWeightProducer( edm::ParameterSet const& );
|
13 |
~LuminosityWeightProducer();
|
14 |
private:
|
15 |
void produce( edm::Event &, edm::EventSetup const& );
|
16 |
|
17 |
std::string rootFileName_;
|
18 |
std::string prefix_;
|
19 |
TFile* rootFile_;
|
20 |
};
|
21 |
|
22 |
#include "DataFormats/Common/interface/Handle.h"
|
23 |
#include "FWCore/Framework/interface/Event.h"
|
24 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
25 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
26 |
#include "FWCore/Framework/interface/ESHandle.h"
|
27 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
28 |
|
29 |
#include <sstream>
|
30 |
#include "TFile.h"
|
31 |
#include "TH1F.h"
|
32 |
|
33 |
LuminosityWeightProducer::LuminosityWeightProducer(edm::ParameterSet const& pset):
|
34 |
rootFileName_( pset.getParameter<std::string>("rootFileName") ),
|
35 |
prefix_( pset.getUntrackedParameter<std::string>("prefix","instLumi") ) {
|
36 |
|
37 |
rootFile_ = TFile::Open(rootFileName_.c_str(),"read");
|
38 |
edm::LogVerbatim("LuminosityWeightProducer") << "[LuminosityWeightProducer]: Opened file " << rootFile_->GetName();
|
39 |
|
40 |
//produces<double>("luminosityWeight");
|
41 |
produces<double>();
|
42 |
}
|
43 |
|
44 |
LuminosityWeightProducer::~LuminosityWeightProducer(){
|
45 |
rootFile_->Close();
|
46 |
}
|
47 |
|
48 |
void LuminosityWeightProducer::produce(edm::Event& event, edm::EventSetup const& setup) {
|
49 |
|
50 |
unsigned int runNumber = event.id().run();
|
51 |
unsigned int lumiSection = event.luminosityBlock();
|
52 |
int bunchCrossing = event.bunchCrossing();
|
53 |
|
54 |
edm::LogVerbatim("LuminosityWeightProducer") << "[LuminosityWeightProducer]: Run, Lumi, Bx= " << runNumber << ", " << lumiSection << ", " << bunchCrossing;
|
55 |
|
56 |
std::stringstream dirName;
|
57 |
dirName << "Run" << runNumber;
|
58 |
|
59 |
std::auto_ptr<double> luminosityWeight( new double(-1.) );
|
60 |
|
61 |
TDirectory* runDir = rootFile_->GetDirectory(dirName.str().c_str());
|
62 |
if( runDir ){
|
63 |
std::stringstream histoName;
|
64 |
histoName << prefix_ << "_" << runNumber << "_" << bunchCrossing;
|
65 |
TH1F* hist = static_cast<TH1F*>( runDir->Get(histoName.str().c_str()) );
|
66 |
if( hist ){
|
67 |
edm::LogVerbatim("LuminosityWeightProducer") << "[LuminosityWeightProducer]: Accessing histogram " << hist->GetName();
|
68 |
double lumi = hist->GetBinContent( hist->FindBin(lumiSection) );
|
69 |
*luminosityWeight = lumi;
|
70 |
}
|
71 |
}
|
72 |
edm::LogVerbatim("LuminosityWeightProducer") << "[LuminosityWeightProducer]: Lumi weight " << *luminosityWeight;
|
73 |
|
74 |
//event.put( luminosityWeight, "luminosityWeight" );
|
75 |
event.put( luminosityWeight );
|
76 |
}
|
77 |
|
78 |
DEFINE_FWK_MODULE(LuminosityWeightProducer);
|