1 |
antoniov |
1.1 |
|
2 |
|
|
#include "FWCore/Framework/interface/EDAnalyzer.h"
|
3 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
4 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
5 |
|
|
|
6 |
|
|
class TFileService;
|
7 |
|
|
class TH1F;
|
8 |
|
|
|
9 |
|
|
class NCountsAnalyzer: public edm::EDAnalyzer
|
10 |
|
|
{
|
11 |
|
|
public:
|
12 |
|
|
typedef std::map<std::string,TH1F*> HistoMapTH1F;
|
13 |
|
|
|
14 |
|
|
explicit NCountsAnalyzer(edm::ParameterSet const&);
|
15 |
|
|
~NCountsAnalyzer();
|
16 |
|
|
|
17 |
|
|
void beginJob();
|
18 |
|
|
void analyze(edm::Event const&, edm::EventSetup const&);
|
19 |
|
|
private:
|
20 |
|
|
void bookHistos(HistoMapTH1F&, edm::Service<TFileService> const&);
|
21 |
|
|
|
22 |
|
|
bool useWeight_;
|
23 |
|
|
edm::InputTag weightTag_;
|
24 |
|
|
|
25 |
|
|
HistoMapTH1F histosTH1F_;
|
26 |
|
|
};
|
27 |
|
|
|
28 |
|
|
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
29 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
30 |
|
|
#include "FWCore/Framework/interface/EDAnalyzer.h"
|
31 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
32 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
33 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
34 |
|
|
|
35 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
36 |
|
|
#include "CommonTools/UtilAlgos/interface/TFileService.h"
|
37 |
|
|
|
38 |
|
|
#include "TH1F.h"
|
39 |
|
|
|
40 |
|
|
NCountsAnalyzer::NCountsAnalyzer(edm::ParameterSet const& pset): useWeight_(false){
|
41 |
|
|
|
42 |
|
|
std::string parName = "weightTag";
|
43 |
|
|
if( pset.exists(parName) ){
|
44 |
|
|
useWeight_ = true;
|
45 |
|
|
weightTag_ = pset.getParameter<edm::InputTag>("weightTag");
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
NCountsAnalyzer::~NCountsAnalyzer(){}
|
50 |
|
|
|
51 |
|
|
void NCountsAnalyzer::beginJob(){
|
52 |
|
|
edm::Service<TFileService> fs;
|
53 |
|
|
|
54 |
|
|
TH1::SetDefaultSumw2(true);
|
55 |
|
|
|
56 |
|
|
bookHistos(histosTH1F_,fs);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
void NCountsAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup){
|
60 |
|
|
|
61 |
|
|
histosTH1F_["NCounts"]->Fill(0.);
|
62 |
|
|
|
63 |
|
|
if(useWeight_){
|
64 |
|
|
edm::Handle<double> weightH;
|
65 |
|
|
event.getByLabel(weightTag_,weightH);
|
66 |
|
|
|
67 |
|
|
double weight = *weightH;
|
68 |
|
|
histosTH1F_["SumWeights"]->Fill(0.,weight);
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
void NCountsAnalyzer::bookHistos(HistoMapTH1F& histos, edm::Service<TFileService> const& fs){
|
73 |
|
|
histos["NCounts"] = fs->make<TH1F>("NCounts","NCounts",1,0,1);
|
74 |
|
|
histos["SumWeights"] = fs->make<TH1F>("SumWeights","SumWeights",1,0,1);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
DEFINE_FWK_MODULE(NCountsAnalyzer);
|