-
Notifications
You must be signed in to change notification settings - Fork 4
/
SkimFromCSV.C
71 lines (63 loc) · 1.76 KB
/
SkimFromCSV.C
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
#include"TString.h"
#include"TChain.h"
#include"TTree.h"
#include"TFile.h"
#include"TH1F.h"
#include"TTreeFormula.h"
#include <iostream>
#include <fstream>
#include <sstream>
void
skim (TString inputFile, TString outputFile)
{
cout << "I'm doing " << outputFile << endl;
TFile *fileout = new TFile (outputFile, "recreate");
TFile *filein = new TFile (inputFile);
TTree *tree = (TTree *) filein->Get ("rootTupleTree/tree");
cout << "tree:" << tree << endl;
Double_t run, lumi;
tree->GetEntry (0);
tree->SetBranchAddress ("run", &run);
tree->SetBranchAddress ("lumi", &lumi);
cout << "2" << endl;
fileout->cd ();
int entries = tree->GetEntries ();
if (entries <= 0) {
cout << "No entries in file " << inputFile << endl;
throw 1;
}
TTree *newTree = tree->CloneTree (0);
cout << "3" << endl;
ifstream file ("lowLumi.csv"); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
int idx = 0;
int goodRun = -1;
int goodLumi = -1;
std::string s;
for (int i = 0; i < tree->GetEntries (); i++) {
tree->GetEntry (i);
while (file.good () && (run > goodRun || (run == goodRun && lumi > goodLumi))) {
getline (file, s);
if(s.size()>5){
int comma = s.find(",");
goodRun = std::stoi(s.substr(0,comma));
goodLumi = std::stoi(s.substr(comma+1,s.size()));
}
}
if (run == goodRun
&& lumi == goodLumi) {
newTree->Fill ();
}
}
newTree->Write ();
// Add histogram with Count ///
TH1F *Count = new TH1F ("Count", "Count", 1, 0, 1);
Count->SetBinContent (1, entries);
Count->Write ();
fileout->Close ();
}
void
skimFromCSV ()
{
skim ("../ntupleTrigger/CaloJet40Skim.root",
"../ntupleTrigger/CaloJet40Skim_lowLumi.root");
}