-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNtp1Finalizer.C
More file actions
186 lines (116 loc) · 4.66 KB
/
Ntp1Finalizer.C
File metadata and controls
186 lines (116 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "Ntp1Finalizer.h"
#include <iostream>
#include "TROOT.h"
Ntp1Finalizer::Ntp1Finalizer( const std::string& analyzerType, const std::string& dataset, const std::string& flags) {
DEBUG_ = false;
tree_ = new TChain("reducedTree");
analyzerType_ = analyzerType;
inputAnalyzerType_ = analyzerType;
dataset_ = dataset;
flags_ = flags;
outFile_ = 0;
nCounter_ = 0.;
nCounterW_ = 0.;
nCounterPU_ = 0.;
h1_nPU_gen_ = new TH1F("nPU_gen", "", 55, -0.5, 54.5);
} //constructor
Ntp1Finalizer::~Ntp1Finalizer() {
std::cout << std::endl << "-> Histograms saved in: " << outFile_->GetName() << std::endl;
if( tree_!=0 ) {
delete tree_;
tree_=0;
}
delete h1_nPU_gen_;
} //destructor
void Ntp1Finalizer::createOutputFile( const std::string& additionalFlags ) {
std::string outfileName;
if( DEBUG_ ) outfileName = "prova_"+dataset_;
else {
if(dataset_!="") outfileName = analyzerType_ + "_" + dataset_;
else outfileName = analyzerType_;
}
if( flags_!="" )
outfileName = outfileName + "_" + flags_;
if( additionalFlags!="" )
outfileName = outfileName + "_" + additionalFlags;
outfileName = outfileName + ".root";
outFile_ = TFile::Open(outfileName.c_str(), "RECREATE");
outFile_->cd();
}
void Ntp1Finalizer::clear() {
if( tree_!=0 ) delete tree_;
tree_ = new TChain("reducedTree");
if( h1_nPU_gen_!=0 ) delete h1_nPU_gen_;
h1_nPU_gen_ = new TH1F("nPU_gen", "", 55, -0.5, 54.5);
}
void Ntp1Finalizer::addFile(const std::string& dataset, const std::string& selection) {
std::string infileName = inputAnalyzerType_ + "_2ndLevelTreeW_" + dataset + ".root"; //the W is important: means that files have passed treatment (merging and weights)
TFile* infile = TFile::Open(infileName.c_str(), "READ");
if( infile==0 ) {
std::cout << "---> Didn't find file: " << infileName << std::endl;
std::cout << "---> Exiting!!" << std::endl;
exit(11);
}
infile->cd();
std::string treeName = infileName +"/reducedTree";
tree_->Add(treeName.c_str());
std::cout << "-> Added " << treeName << ". Tree now has " << tree_->GetEntries() << " entries." << std::endl;
TH1F* h1_nCounter = (TH1F*)infile->Get("nCounter");
TH1F* h1_nCounterW = (TH1F*)infile->Get("nCounterW");
TH1F* h1_nCounterPU = (TH1F*)infile->Get("nCounterPU");
h1_nPU_gen_->Add((TH1F*)infile->Get("nPU_gen"));
if( h1_nCounter!= 0 && h1_nCounterW != 0 && h1_nCounterPU ) {
nCounter_ += h1_nCounter->GetBinContent(1);
nCounterW_ += h1_nCounterW->GetBinContent(1);
nCounterPU_ += h1_nCounterPU->GetBinContent(1);
} else {
std::cout << std::endl << std::endl << "WARNING!! Dataset '" << dataset << "' has no nCounter information!!!" << std::endl;
}
infile->Close();
}
std::vector<TH1F*> Ntp1Finalizer::getResponseHistos(const std::string& name, unsigned binArraySize, Double_t* ptBins) {
std::vector<TH1F*> returnVector;
for( unsigned i=0; i<(binArraySize-1); ++i ) {
char histoName[100];
sprintf( histoName, "%s_ptBin_%.0f_%.0f", name.c_str(), ptBins[i], ptBins[i+1]);
int nbins = 50;
float xmin = 0.5;
float xmax = 2.;
TH1F* newHisto = new TH1F(histoName, "", nbins, xmin, xmax);
newHisto->Sumw2();
returnVector.push_back(newHisto);
}
return returnVector;
}
void Ntp1Finalizer::writeResponseHistos( TFile* file, std::vector<TH1F*> h1_response, std::string dirName ) {
file->mkdir( dirName.c_str() );
file->cd( dirName.c_str() );
for( unsigned iHisto=0; iHisto<h1_response.size(); ++iHisto ) h1_response[iHisto]->Write();
file->cd();
}
/*
int Ntp1Finalizer::get_nBTags( const AnalysisJet& jet1, const AnalysisJet& jet2, BTagSFUtil* btsfutil, bool loosebtags ) {
int nBTags;
bool jet1_tagged_medium = jet1.btag_medium();
bool jet1_tagged_loose = jet1.btag_loose();
bool jet2_tagged_medium = jet2.btag_medium();
bool jet2_tagged_loose = jet2.btag_loose();
//btsfutil->modifyBTagsWithSF( jet1_tagged_loose, jet1_tagged_medium, jet1.Pt(), jet1.Eta(), jet1.pdgIdPart );
//btsfutil->modifyBTagsWithSF( jet2_tagged_loose, jet2_tagged_medium, jet2.Pt(), jet2.Eta(), jet2.pdgIdPart );
if( loosebtags ) {
bool twoBTags = ( jet1_tagged_medium && jet2_tagged_loose )
|| ( jet1_tagged_loose && jet2_tagged_medium );
bool oneBTag = (!twoBTags) && ( jet1_tagged_loose || jet2_tagged_loose );
if( twoBTags ) nBTags=2;
else if( oneBTag ) nBTags=1;
else nBTags=0;
} else {
bool twoBTags = ( jet1_tagged_medium && jet2_tagged_medium );
bool oneBTag = (!twoBTags) && ( jet1_tagged_medium || jet2_tagged_medium );
if( twoBTags ) nBTags=2;
else if( oneBTag ) nBTags=1;
else nBTags=0;
}
return nBTags;
}
*/