forked from osWW-VBS/WWAnalysisRun2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskimDuplicateEventsW.cpp
102 lines (80 loc) · 2.42 KB
/
skimDuplicateEventsW.cpp
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
//c++ -o skimDuplicateEventsW skimDuplicateEventsW.cpp `root-config --cflags --glibs`
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include "TROOT.h"
#include "TSystem.h"
#include "TKey.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TProfile.h"
#include "TF1.h"
#include "TGraphAsymmErrors.h"
#include "TString.h"
#include "TCut.h"
#include "TMath.h"
#include "TApplication.h"
#include "TError.h"
#include "TCanvas.h"
#include "TGraphErrors.h"
#include "TPad.h"
#include "TStyle.h"
#include "TLorentzVector.h"
#include "TChain.h"
#include "TMath.h"
#include <cmath>
using namespace std;
int main(int argc, char** argv)
{
TFile myFile("WTOT.root"); // Open the file
TTree* myTree = (TTree*) myFile.Get("Wtree"); // Get the Muon tree from the file
int run,event;
float invMass, ele1_eta, ele1_SCE, ele1_ET, caloMet;
myTree->SetBranchAddress("run", &run);
myTree->SetBranchAddress("event", &event);
myTree->SetBranchAddress("caloMet",&caloMet);
myTree->SetBranchAddress("ele1_eta",&ele1_eta);
myTree->SetBranchAddress("ele1_SCE",&ele1_SCE);
myTree->SetBranchAddress("ele1_ET",&ele1_ET);
TFile *fileOut = new TFile("Wtree_final.root","RECREATE");
TTree *treeOut = new TTree("Wtree","Wtree");
int Event, Run;
float caloMET, ele1eta, ele1SCE, ele1ET;
treeOut->Branch("Run",&Run,"Run/I");
treeOut->Branch("Event",&Event,"Event/I");
treeOut->Branch("caloMET",&caloMET,"caloMET/F");
treeOut->Branch("ele1eta",&ele1eta,"ele1eta/F");
treeOut->Branch("ele1SCE",&ele1SCE,"ele1SCE/F");
treeOut->Branch("ele1ET",&ele1ET,"ele1ET/F");
std::vector<int> runList;
std::vector<int> eventList;
std::cout<<"Events: "<<myTree->GetEntries()<<std::endl<<"Press any key to continue"<<std::endl;
// getchar();
bool skipEvent=false;
for (long int i=0; i<myTree->GetEntries(); i++)
{
myTree->GetEntry(i);
if(i % 1000 == 0)
cout << "read entry: " << i << "/" << myTree->GetEntries()<<endl;
for (int j=0; j<runList.size(); j++) {
if (run==runList.at(j) && event==eventList.at(j))
skipEvent=true;
}
if (skipEvent) continue;
runList.push_back(run);
eventList.push_back(event);
Event = event;
Run = run;
ele1SCE = ele1_SCE;
ele1eta = ele1_eta;
ele1ET = ele1_ET;
caloMET = caloMet;
treeOut->Fill();
}
fileOut->Write();
fileOut->Print();
return 0;
}