forked from cbeiraod/StopNN
-
Notifications
You must be signed in to change notification settings - Fork 3
/
skimmer.cc
52 lines (41 loc) · 1.24 KB
/
skimmer.cc
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
#include "TROOT.h"
#include "TTree.h"
#include "TFile.h"
#include <string>
#include <iostream>
//int main(int argc, char** argv)
int skimmer(std::string fileToProcess)
{
//std::string fileToProcess = "";
TFile inFile((fileToProcess + ".root").c_str(), "READ");
TFile outFile((fileToProcess + "_skimmed.root").c_str(), "RECREATE");
TTree* inTree = static_cast<TTree*>(inFile.Get("bdttree"));
inTree->SetBranchStatus("*",1);
inTree->SetBranchStatus("*_Up",0);
inTree->SetBranchStatus("*_Down",0);
TTree* tmp = inTree->CloneTree(75000);
tmp->SetBranchStatus("*", 1);
tmp->SetBranchStatus("weight", 0);
TTree* outTree = tmp->CloneTree();
tmp->SetBranchStatus("weight", 1);
Float_t weight = 0;
tmp->SetBranchAddress("weight", &weight);
TBranch* newWeightBranch = outTree->Branch("weight", &weight);
Long64_t inEvents = inTree->GetEntries();
Long64_t copyEvents = tmp->GetEntries();
Float_t factor = 1;
if(copyEvents < inEvents)
{
factor = inEvents;
factor = factor / copyEvents;
}
std::cout << "The scaling factor is: " << factor << std::endl;
for(Long64_t i = 0; i < copyEvents; ++i)
{
tmp->GetEntry(i);
weight = weight * factor;
newWeightBranch->Fill();
}
outTree->Write();
return 0;
}