-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify.C
150 lines (117 loc) · 4.24 KB
/
verify.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
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
#include <math.h>
#include <iostream>
#include <vector>
using namespace std;
#include "TH1.h"
#include "TTree.h"
#include "TGraphErrors.h"
#include "TFile.h"
#define PI 3.141592653589793
#define max_particles 20000
struct PhiDist
{
float eta_MIN;
float eta_MAX;
TH1F * phi_GEN;
TH1F * phi_RECO;
PhiDist(float minEta, float maxEta)
: eta_MIN(minEta), eta_MAX(maxEta)
{
phi_GEN = new TH1F(Form("phi_GEN_eta=[%.1f,%.1f]",minEta,maxEta),Form("phi_GEN_eta=[%.1f,%.1f]",minEta,maxEta),200,-PI,PI);
phi_RECO = new TH1F(Form("phi_RECO_eta=[%.1f,%.1f]",minEta,maxEta),Form("phi_RECO_eta=[%.1f,%.1f]",minEta,maxEta),200,-PI,PI);
}
};
struct UniversalData
{
TTree * steg;
Int_t nEvents;
Int_t np; // # of particles in event
float phi[max_particles];
float eta[max_particles];
//float pt[max_particles];
bool reco[max_particles]; // whether or not particle has been reconstructed
};
void fillEta(UniversalData * data, TH1F * eta_GEN, TH1F * eta_RECO);
void fillPhi(UniversalData * data, PhiDist * phiDist, Int_t cur, Int_t tot);
bool withinEtaRange(float eta, float min, float max);
//void plot(TH1F * eta_GEN, TH1F * eta_RECO, vector<PhiDist*> v);
void verify()
{
UniversalData * data = new UniversalData;
//TFile * fInput = new TFile("/home/palmerjh/CMSSW_5_3_20/STEGEff/STEGData.root");
TFile * fInput = new TFile("/home/palmerjh/CMSSW_5_3_20/STEGEff/testCluster0.root");
TFile * fOutput = new TFile("verify.root", "RECREATE", "description");
TH1F * eta_GEN = new TH1F("eta_GEN","eta_GEN",200,-2.5,2.5);
TH1F * eta_RECO = new TH1F("eta_RECO","eta_RECO",200,-2.5,2.5);
data->steg = (TTree*) fInput->Get("tree");
(data->steg)->SetBranchAddress("reconstructed",&(data->reco));
// Here the TTree object is given the memory addresses
// of our variables above as places to put the contents
// of each branch when the "GetEntry" method is called
(data->steg)->SetBranchAddress("npg",&(data->np));
(data->steg)->SetBranchAddress("phig",&(data->phi));
(data->steg)->SetBranchAddress("etag",&(data->eta));
//(data->steg)->SetBranchAddress("ptg",&(data->pt));
// total number of events
data->nEvents = (Int_t) (data->steg)->GetEntries();
PhiDist * A = new PhiDist(-2.4,-1.6);
PhiDist * B = new PhiDist(1.6,2.4);
PhiDist * C = new PhiDist(-1,1);
vector<PhiDist*> v; v.push_back(A); v.push_back(B); v.push_back(C);
fillEta(data, eta_GEN, eta_RECO);
for (Int_t i = 0; i < v.size(); i++)
{
fillPhi(data, v[i], i, v.size());
v[i]->phi_GEN->Write();
v[i]->phi_RECO->Write();
}
eta_GEN->Write();
eta_RECO->Write();
fInput->Close();
fOutput->Close();
cout << "DONE" << endl;
//plot(eta_GEN, eta_RECO, v);
}
void fillEta(UniversalData * data, TH1F * eta_GEN, TH1F * eta_RECO)
{
for( Int_t i=0; i < data->nEvents; i++)
{
// print a message every 1000 events
if( i%10000 == 0) cout << "Filling eta histograms. Processing event " << i << " out of " << data->nEvents << "...\n";
// Load the information from event i
(data->steg)->GetEntry(i);
//Loop over all particles in the event to determine event planes
for( Int_t j=0; j < data->np; j++)
{
eta_GEN->Fill((data->eta)[j]);
if((data->reco)[j]) {
eta_RECO->Fill((data->eta)[j]);
}
}
}
}
void fillPhi(UniversalData * data, PhiDist * phiDist, Int_t cur, Int_t tot)
{
for( Int_t i=0; i < data->nEvents; i++)
{
// print a message every 1000 events
if( i%10000 == 0) cout << Form("Filling phi histograms. (Step %d of %d) Processing event %d out of %d...\n",cur,tot,i,data->nEvents);
// Load the information from event i
(data->steg)->GetEntry(i);
//Loop over all particles in the event to determine event planes
for( Int_t j=0; j < data->np; j++)
{
if (withinEtaRange((data->eta)[j], phiDist->eta_MIN, phiDist->eta_MAX)) {
phiDist->phi_GEN->Fill((data->phi)[j]);
if((data->reco)[j]) {
phiDist->phi_RECO->Fill((data->phi)[j]);
}
}
}
}
}
bool withinEtaRange(float eta, float min, float max)
{
return eta >= min && eta <= max;
}
//void plot(TH1F * eta_GEN, TH1F * eta_RECO, vector<PhiDist*> v);