1 |
anderson |
1.1 |
/*************************************************
|
2 |
|
|
This script adds plots from TTrees from many
|
3 |
|
|
files into the same histograms, scaling each,
|
4 |
|
|
and saves histograms into a new file.
|
5 |
|
|
|
6 |
|
|
Very customizable.
|
7 |
|
|
|
8 |
|
|
Michael B. Anderson
|
9 |
|
|
Feb 19, 2009
|
10 |
|
|
*************************************************/
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
#include "TH1F.h"
|
14 |
|
|
#include <vector>
|
15 |
|
|
#include <cmath>
|
16 |
|
|
|
17 |
|
|
void ttreesToHistograms() {
|
18 |
anderson |
1.2 |
//********************************************************************
|
19 |
|
|
//**** Variables ****//
|
20 |
anderson |
1.4 |
cout << "Loading variables into vectors..." << endl;
|
21 |
|
|
|
22 |
anderson |
1.2 |
vector<TString> fileName;
|
23 |
anderson |
1.4 |
fileName.push_back( "rootfiles0/PhotonJetPt15_Summer09.root" );//file0
|
24 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt30_Summer09.root" );//file1
|
25 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt80_Summer09.root" );//file2
|
26 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt170_Summer09.root" );//file3
|
27 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt300_Summer09.root" );//file4
|
28 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt470_Summer09.root" );//file5
|
29 |
|
|
fileName.push_back( "rootfiles0/PhotonJetPt800_Summer09.root" );//file6
|
30 |
anderson |
1.2 |
|
31 |
anderson |
1.4 |
TString treeName = "TreePhotonJet";
|
32 |
anderson |
1.2 |
|
33 |
anderson |
1.5 |
TString outputFileName = "PhotonJetHists-2009-09-02-matchesReco.root";
|
34 |
anderson |
1.1 |
|
35 |
|
|
|
36 |
anderson |
1.2 |
//*********************************
|
37 |
|
|
//**** Set Scale
|
38 |
anderson |
1.1 |
// The following 4 number set the scale
|
39 |
anderson |
1.2 |
// example:
|
40 |
|
|
// scale = (integrated luminosity (1/pb))*(cross section (pb))*(filter eff)/(events analyzed)
|
41 |
anderson |
1.1 |
float invLuminosityToScaleTo = 200; // in pb-1
|
42 |
|
|
|
43 |
|
|
vector<float> crossSection;
|
44 |
anderson |
1.2 |
crossSection.push_back( 2.887E5 -3.222E4 ); // in pb
|
45 |
|
|
crossSection.push_back( 3.222E4 -1.010E3 );
|
46 |
|
|
crossSection.push_back( 1.010E3 -5.143E1 );
|
47 |
|
|
crossSection.push_back( 5.143E1 -4.193E0 );
|
48 |
|
|
crossSection.push_back( 4.193E0 -4.515E-1 );
|
49 |
|
|
crossSection.push_back( 4.515E-1 -2.003E-2 );
|
50 |
|
|
crossSection.push_back( 2.003E-2 );
|
51 |
anderson |
1.1 |
|
52 |
|
|
vector<float> filterEffeciency;
|
53 |
|
|
filterEffeciency.push_back( 1.0 );
|
54 |
|
|
filterEffeciency.push_back( 1.0 );
|
55 |
anderson |
1.2 |
filterEffeciency.push_back( 1.0 );
|
56 |
|
|
filterEffeciency.push_back( 1.0 );
|
57 |
|
|
filterEffeciency.push_back( 1.0 );
|
58 |
|
|
filterEffeciency.push_back( 1.0 );
|
59 |
|
|
filterEffeciency.push_back( 1.0 );
|
60 |
anderson |
1.1 |
|
61 |
|
|
vector<float> eventsAnalyzied;
|
62 |
anderson |
1.4 |
eventsAnalyzied.push_back( 1073270 );
|
63 |
|
|
eventsAnalyzied.push_back( 1088546 );
|
64 |
|
|
eventsAnalyzied.push_back( 993509 );
|
65 |
|
|
eventsAnalyzied.push_back( 1483940 );
|
66 |
|
|
eventsAnalyzied.push_back( 1024589 );
|
67 |
|
|
eventsAnalyzied.push_back( 1014413 );
|
68 |
|
|
eventsAnalyzied.push_back( 1216320 );
|
69 |
anderson |
1.1 |
// END of setting scale
|
70 |
anderson |
1.2 |
//*********************************
|
71 |
anderson |
1.1 |
|
72 |
|
|
|
73 |
anderson |
1.2 |
//*********************************
|
74 |
|
|
//**** Set Cuts ****//
|
75 |
|
|
// Variables will be plotted for each "location"
|
76 |
|
|
vector<TString> locationCut;
|
77 |
anderson |
1.4 |
locationCut.push_back( "abs(hardGenPhoton_eta)>1.55&&abs(hardGenPhoton_eta)<2.5" );
|
78 |
|
|
locationCut.push_back( "abs(hardGenPhoton_eta)<1.45" );
|
79 |
anderson |
1.1 |
|
80 |
|
|
vector<TString> locationName;
|
81 |
|
|
locationName.push_back( "Endcap" );
|
82 |
|
|
locationName.push_back( "Barrel" );
|
83 |
|
|
|
84 |
anderson |
1.2 |
// These cuts will be merged into one giant cut, applied to all plots for all files
|
85 |
anderson |
1.1 |
vector<TString> cuts;
|
86 |
anderson |
1.4 |
cuts.push_back( "hardGenPhoton_et>15.0&&photon_et>15.0&&photon_matches_hardGen>0.5" );
|
87 |
anderson |
1.1 |
|
88 |
anderson |
1.2 |
// These cuts will be applied only to corresponding file
|
89 |
|
|
vector<TString> fileCuts;
|
90 |
anderson |
1.4 |
fileCuts.push_back( "event_genEventScale>15&&event_genEventScale<30" ); //file0
|
91 |
|
|
fileCuts.push_back( "event_genEventScale>30&&event_genEventScale<80" ); //file1
|
92 |
|
|
fileCuts.push_back( "event_genEventScale>80&&event_genEventScale<170" ); //file2
|
93 |
|
|
fileCuts.push_back( "event_genEventScale>170&&event_genEventScale<300" ); //file3
|
94 |
|
|
fileCuts.push_back( "event_genEventScale>300&&event_genEventScale<470" ); //file4
|
95 |
|
|
fileCuts.push_back( "event_genEventScale>470&&event_genEventScale<800" ); //file5
|
96 |
|
|
fileCuts.push_back( "event_genEventScale>800&&event_genEventScale<1400" ); //file6
|
97 |
anderson |
1.2 |
//**** END of setting cuts
|
98 |
|
|
//*********************************
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
//*********************************
|
102 |
anderson |
1.4 |
int locationVariablesToPlot[2][2]; // [a][b], a=number of locations, b=2 (for min,max range of variables to plot)
|
103 |
anderson |
1.5 |
locationVariablesToPlot[0][0] = 16; // Endcap
|
104 |
|
|
locationVariablesToPlot[0][1] = 35;
|
105 |
|
|
locationVariablesToPlot[1][0] = 16; // Barrel
|
106 |
|
|
locationVariablesToPlot[1][1] = 35;
|
107 |
anderson |
1.4 |
/*locationVariablesToPlot[2][0] = 0;
|
108 |
|
|
locationVariablesToPlot[2][1] = 4;
|
109 |
|
|
locationVariablesToPlot[3][0] = 0;
|
110 |
|
|
locationVariablesToPlot[3][1] = 4;
|
111 |
|
|
locationVariablesToPlot[4][0] = 0;
|
112 |
|
|
locationVariablesToPlot[4][1] = 4;
|
113 |
|
|
locationVariablesToPlot[5][0] = 0;
|
114 |
|
|
locationVariablesToPlot[5][1] = 4;
|
115 |
|
|
locationVariablesToPlot[6][0] = 0;
|
116 |
|
|
locationVariablesToPlot[6][1] = 4;
|
117 |
|
|
locationVariablesToPlot[7][0] = 0;
|
118 |
|
|
locationVariablesToPlot[7][1] = 4;*/
|
119 |
anderson |
1.2 |
|
120 |
|
|
// Variables you want plotted
|
121 |
anderson |
1.1 |
vector<TString> variableToPlot;
|
122 |
anderson |
1.3 |
// --- the following require gen level info
|
123 |
anderson |
1.5 |
variableToPlot.push_back( "hardGenPhoton_et" ); // 0
|
124 |
anderson |
1.4 |
variableToPlot.push_back( "hardGenPhoton_eta" );
|
125 |
|
|
variableToPlot.push_back( "hardGenPhoton_phi" );
|
126 |
|
|
variableToPlot.push_back( "fmod(hardGenPhoton_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" );
|
127 |
|
|
variableToPlot.push_back( "abs(hardGenPhoton_eta)" ); // 4
|
128 |
|
|
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy" );
|
129 |
anderson |
1.5 |
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_energy" );
|
130 |
anderson |
1.4 |
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:abs(hardGenPhoton_eta)" );
|
131 |
anderson |
1.5 |
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_phiMod" );
|
132 |
|
|
variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_et" );
|
133 |
anderson |
1.4 |
variableToPlot.push_back( "photon_hadronicOverEm:abs(hardGenPhoton_eta)" ); // 10
|
134 |
anderson |
1.5 |
variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_phiMod" );
|
135 |
anderson |
1.4 |
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta" );
|
136 |
|
|
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:hardGenPhoton_et" );
|
137 |
|
|
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:abs(hardGenPhoton_eta)" );
|
138 |
anderson |
1.3 |
variableToPlot.push_back( "deltaPhiGenRecPhoton" ); // 15
|
139 |
|
|
// --- the following require only rec photons
|
140 |
anderson |
1.4 |
variableToPlot.push_back( "photon_et" ); // 16
|
141 |
|
|
variableToPlot.push_back( "photon_eta" );
|
142 |
|
|
variableToPlot.push_back( "photon_phi" );
|
143 |
|
|
variableToPlot.push_back( "fmod(photon_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" );
|
144 |
|
|
variableToPlot.push_back( "abs(photon_eta)" ); // 20
|
145 |
|
|
variableToPlot.push_back( "photon_r9" );
|
146 |
anderson |
1.5 |
variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03" );
|
147 |
|
|
variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03" );
|
148 |
|
|
variableToPlot.push_back( "photon_trkSumPtSolidConeDR03" );
|
149 |
|
|
variableToPlot.push_back( "photon_trkSumPtHollowConeDR03" ); //25
|
150 |
|
|
variableToPlot.push_back( "photon_nTrkSolidConeDR03" );
|
151 |
|
|
variableToPlot.push_back( "photon_nTrkHollowConeDR03" );
|
152 |
|
|
variableToPlot.push_back( "photon_hadronicOverEm" );
|
153 |
|
|
variableToPlot.push_back( "photon_r2x5" );
|
154 |
|
|
variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03/photon_et" ); // 30
|
155 |
|
|
variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03/photon_et" );
|
156 |
|
|
variableToPlot.push_back( "photon_trkSumPtSolidConeDR03/photon_et" );
|
157 |
|
|
variableToPlot.push_back( "photon_trkSumPtHollowConeDR03/photon_et" );
|
158 |
|
|
// --- the following require jets
|
159 |
|
|
/*variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet_phi)" );
|
160 |
|
|
variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet2_phi)" ); // 35
|
161 |
|
|
variableToPlot.push_back( "calcDeltaPhi(jet_phi,jet2_phi)" );*/
|
162 |
|
|
variableToPlot.push_back( "(photon_et-jet_et)/photon_et" );
|
163 |
|
|
variableToPlot.push_back( "jet2_et/photon_et" );
|
164 |
anderson |
1.2 |
|
165 |
|
|
// Histograms for the above variables
|
166 |
|
|
vector<TH1*> histogram;
|
167 |
anderson |
1.3 |
// --- the following require gen level info
|
168 |
anderson |
1.4 |
histogram.push_back( new TH1F("photonGenEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750) ); // 0
|
169 |
|
|
histogram.push_back( new TH1F("photonGenEta", "Photon #eta ;#eta;entries per 0.1 bin", 61, -3.05, 3.05) );
|
170 |
|
|
histogram.push_back( new TH1F("photonGenPhi", "Photon #phi ;#phi;entries per bin", 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) );
|
171 |
anderson |
1.3 |
histogram.push_back( new TH1F("photonGenPhiMod", "Photon #phi_{mod} ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) );
|
172 |
|
|
histogram.push_back( new TH1F("photonGenAbsEta", "Photon |#eta| ", 51, 0.00, 2.55) );
|
173 |
|
|
histogram.push_back( new TH1F("photonDeltaE", "(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) ", 50, -0.8, 0.3) );
|
174 |
|
|
histogram.push_back( new TH2F("photonDeltaE_vs_E","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs E(#gamma_{gen}) ", 50, 0, 3000, 50, -0.8, 0.3) );
|
175 |
|
|
histogram.push_back( new TH2F("photonDeltaE_vs_AbsEta","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs |#eta(#gamma_{gen}|) ", 51, 0.0, 2.5, 50, -0.8, 0.3) );
|
176 |
|
|
histogram.push_back( new TH2F("photonDeltaE_vs_PhiMod","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, -0.9, 0.2) );
|
177 |
|
|
histogram.push_back( new TH2F("photonHoverE_vs_Et", "H/E vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 50, 0.0, 0.2) );
|
178 |
|
|
histogram.push_back( new TH2F("photonHoverE_vs_AbsEta", "H/E vs |#eta(#gamma_{gen})| ", 51, 0.0, 2.5, 50, 0.0, 0.2) );
|
179 |
|
|
histogram.push_back( new TH2F("photonHoverE_vs_PhiMod", "H/E vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, 0.0, 0.2) );
|
180 |
anderson |
1.4 |
histogram.push_back( new TH1F("photonDeltaEta", "#Delta#eta(#gamma_{rec},#gamma_{gen}) ;#Delta#eta(#gamma_{rec},#gamma_{gen});entries/bin", 41, -0.01, 0.01) );
|
181 |
|
|
histogram.push_back( new TH2F("photonDeltaEta_vs_Et", "#Delta#eta(#gamma_{rec},#gamma_{gen}) vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 41, -0.1, 0.1) );
|
182 |
|
|
histogram.push_back( new TH2F("photonDeltaEta_vs_AbsEta","#Delta#eta(#gamma_{rec},#gamma_{gen}) vs #eta(#gamma_{gen})", 51, 0.0, 2.55, 41, -0.1, 0.1) );
|
183 |
|
|
histogram.push_back( new TH1F("photonDeltaPhi", "#Delta#phi(#gamma_{rec},#gamma_{gen}) ;#Delta#phi(#gamma_{rec},#gamma_{gen});entries/bin", 41, 0.0, 0.01) ); // 15
|
184 |
anderson |
1.3 |
// --- the following require only rec photons
|
185 |
anderson |
1.5 |
histogram.push_back( new TH1F("photonEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750 ) ); // 16
|
186 |
|
|
histogram.push_back( new TH1F("photonEta", "Photon #eta ;#eta;entries per 0.1" , 61, -3.05, 3.05) );
|
187 |
|
|
histogram.push_back( new TH1F("photonPhi", "Photon #phi ;#phi;entries per bin" , 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) );
|
188 |
|
|
histogram.push_back( new TH1F("photonPhiMod", "Photon #phi_{mod} " , 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) );
|
189 |
|
|
histogram.push_back( new TH1F("photonAbsEta", "Photon |#eta| " , 51, 0.00, 2.55) ); // 20
|
190 |
|
|
histogram.push_back( new TH1F("photonR9", "R9 = E(3x3) / E(SuperCluster) ;R9;entries/bin" , 50, 0.6, 1.0) );
|
191 |
|
|
histogram.push_back( new TH1F("photonEcalIso", "#SigmaEcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) );
|
192 |
|
|
histogram.push_back( new TH1F("photonHcalIso", "#SigmaHcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) );
|
193 |
|
|
histogram.push_back( new TH1F("photonTrackSolidIso", "#Sigmatrack p_{T} in Solid #DeltaR cone " , 50, 0 , 15) );
|
194 |
|
|
histogram.push_back( new TH1F("photonTrackHollowIso", "#Sigmatrack p{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); // 25
|
195 |
anderson |
1.4 |
histogram.push_back( new TH1F("photonTrackCountSolid", "Number of tracks in Solid #DeltaR cone ;Number of Tracks;entries/bin" , 25, -0.5, 24.5) );
|
196 |
anderson |
1.5 |
histogram.push_back( new TH1F("photonTrackCountHollow", "Number of tracks in Hollow #DeltaR cone ;Number of Tracks;entries/bin", 25, -0.5, 24.5) );
|
197 |
anderson |
1.3 |
histogram.push_back( new TH1F("photonHoverE", "Hadronic / EM ", 50, 0.0, 0.2) );
|
198 |
anderson |
1.5 |
histogram.push_back( new TH1F("photonScSeedE2x5over5x5", "E2x5/E5x5 " , 50, 0.6, 1.0) );
|
199 |
|
|
histogram.push_back( new TH1F("photonEcalIsoOverE", "#SigmaEcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // 30
|
200 |
|
|
histogram.push_back( new TH1F("photonHcalIsoOverE", "#SigmaHcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) );
|
201 |
|
|
histogram.push_back( new TH1F("photonTrackSolidIsoOverE" , "#SigmaTrack p_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) );
|
202 |
|
|
histogram.push_back( new TH1F("photonTrackHollowIsoOverE", "#SigmaTrack p_{T} in Hollow #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) );
|
203 |
|
|
// --- the following require jets
|
204 |
|
|
/*histogram.push_back( new TH1F("h_deltaPhi_photon_jet", "#Delta#phi between Highest E_{T} #gamma and jet;#Delta#phi(#gamma,1^{st} jet)" , 50, 0, 3.1415926) );
|
205 |
|
|
histogram.push_back( new TH1F("h_deltaPhi_photon_jet2","#Delta#phi between Highest E_{T} #gamma and 2^{nd} highest jet;#Delta#phi(#gamma,2^{nd} jet)", 50, 0, 3.1415926) );
|
206 |
|
|
histogram.push_back( new TH1F("h_deltaPhi_jet_jet2" , "#Delta#phi between Highest E_{T} jet and 2^{nd} jet;#Delta#phi(1^{st} jet,2^{nd} jet)" , 50, 0, 3.1415926) );*/
|
207 |
|
|
histogram.push_back( new TH1F("h_deltaEt_photon_jet" , "(E_{T}(#gamma)-E_{T}(jet))/E_{T}(#gamma) when #Delta#phi(#gamma,1^{st} jet) > 2.8;#DeltaE_{T}(#gamma,1^{st} jet)/E_{T}(#gamma)", 20, -1.0, 1.0) );
|
208 |
|
|
histogram.push_back( new TH1F("h_jet2_etOverPhotonEt", "E_{T}(2^{nd} highest jet) / E_{T}(#gamma);E_{T}(2^{nd} Jet)/E_{T}(#gamma)", 20, 0.0, 4.0) );
|
209 |
anderson |
1.2 |
//**** END of Variables ****//
|
210 |
|
|
//********************************************************************
|
211 |
|
|
|
212 |
anderson |
1.1 |
|
213 |
|
|
|
214 |
anderson |
1.5 |
|
215 |
anderson |
1.2 |
//********************************************************************
|
216 |
|
|
//**** Main part of Program ****//
|
217 |
anderson |
1.1 |
|
218 |
|
|
// Human error checking
|
219 |
anderson |
1.4 |
if (variableToPlot.size() != histogram.size() ) {
|
220 |
|
|
cout << "Should have equal entries in histogram and variableToPlot vector." << endl;
|
221 |
|
|
return;
|
222 |
|
|
}
|
223 |
|
|
if (fileName.size() > crossSection.size() ) {
|
224 |
|
|
cout << "Should have equal entries in fileName and crossSection vetor." << endl;
|
225 |
|
|
return;
|
226 |
|
|
}
|
227 |
|
|
if (fileName.size() > fileCuts.size() ) {
|
228 |
|
|
cout << "Should have equal entries in fileName and fileCuts vector." << endl;
|
229 |
anderson |
1.1 |
return;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
// Combine all the cuts into one
|
233 |
anderson |
1.2 |
cout << endl << "Cuts that will be applied to everything: " << endl << " ";
|
234 |
anderson |
1.1 |
TCut allCuts = "";
|
235 |
|
|
for (int i =0; i<cuts.size(); i++) {
|
236 |
|
|
allCuts += cuts[i];
|
237 |
anderson |
1.2 |
if (i>0) cout << "&&";
|
238 |
|
|
cout << "(" << cuts[i] << ")";
|
239 |
anderson |
1.1 |
}
|
240 |
anderson |
1.2 |
cout << endl << endl;
|
241 |
anderson |
1.1 |
|
242 |
|
|
|
243 |
|
|
// Open the files & set their scales
|
244 |
anderson |
1.2 |
cout << endl << "Histograms will be scaled to " << invLuminosityToScaleTo << "pb-1 " << endl;
|
245 |
anderson |
1.1 |
cout << "Looking for TTree named \"" << treeName << "\" in files..." << endl;
|
246 |
|
|
vector<float> fileScale;
|
247 |
|
|
TList *fileList = new TList();
|
248 |
|
|
for (int i=0; i < fileName.size(); i++) {
|
249 |
|
|
|
250 |
|
|
TFile* currentFile = TFile::Open(fileName[i]);
|
251 |
|
|
fileList->Add(currentFile);
|
252 |
|
|
float currentScale = crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i];
|
253 |
|
|
fileScale.push_back( currentScale );
|
254 |
|
|
|
255 |
anderson |
1.2 |
// Display entries in that file's TTree
|
256 |
anderson |
1.1 |
TTree* tree;
|
257 |
|
|
currentFile->GetObject(treeName, tree);
|
258 |
anderson |
1.5 |
cout << "file" << i <<": " << fileName[i] << " contains " << tree->GetEntries(allCuts) << " entries, and will be scaled by " <<
|
259 |
|
|
currentScale << endl;
|
260 |
anderson |
1.1 |
}
|
261 |
|
|
cout << endl << endl;
|
262 |
|
|
|
263 |
anderson |
1.2 |
|
264 |
anderson |
1.1 |
//Create output file
|
265 |
|
|
TFile *outputFile = TFile::Open( outputFileName, "RECREATE" );
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
//************************************************************
|
269 |
|
|
// Core of the Script //
|
270 |
|
|
// Loop over locations
|
271 |
|
|
for (int l=0; l<locationName.size(); l++) {
|
272 |
|
|
TString currentLocation = locationName[l];
|
273 |
|
|
TCut currentCuts = allCuts;
|
274 |
|
|
currentCuts += locationCut[l];
|
275 |
|
|
cout << "Creating plots for " << currentLocation << ", " << locationCut[l] << endl;
|
276 |
|
|
|
277 |
|
|
// Loop over variables to plot
|
278 |
|
|
for (int i=0; i<variableToPlot.size(); i++) {
|
279 |
anderson |
1.2 |
// should we plot this variable for this location?
|
280 |
|
|
if (i<locationVariablesToPlot[l][0] || i>locationVariablesToPlot[l][1]) continue;
|
281 |
|
|
|
282 |
|
|
TString currentHistType = histogram[i]->IsA()->GetName();
|
283 |
anderson |
1.1 |
TString currentHistName = TString(histogram[i]->GetName()) + "_" + currentLocation;
|
284 |
|
|
TString currentHistTitle = TString(histogram[i]->GetTitle()) + "(" + currentLocation + ")";
|
285 |
anderson |
1.2 |
cout << " " << variableToPlot[i] << " >> " << currentHistName;
|
286 |
|
|
TString currentHistDrawOpt;
|
287 |
|
|
if (currentHistType=="TH2F") {
|
288 |
|
|
currentHistDrawOpt="goffbox";
|
289 |
|
|
} else {
|
290 |
|
|
currentHistDrawOpt="egoff";
|
291 |
|
|
}
|
292 |
|
|
TH1* currentHist = (TH1*)histogram[i]->Clone(currentHistName); // Creates clone with name currentHistName
|
293 |
|
|
currentHist->Sumw2(); // store errors
|
294 |
anderson |
1.1 |
currentHist->SetTitle(currentHistTitle);
|
295 |
anderson |
1.2 |
//cout << " from file";
|
296 |
anderson |
1.1 |
|
297 |
anderson |
1.4 |
// Plot from the first file
|
298 |
anderson |
1.1 |
int f = 0;
|
299 |
anderson |
1.4 |
//cout << f;
|
300 |
|
|
TTree *tree;
|
301 |
anderson |
1.1 |
TFile *current_file = (TFile*)fileList->First();
|
302 |
anderson |
1.4 |
current_file->cd();
|
303 |
|
|
current_file->GetObject(treeName, tree);
|
304 |
|
|
tree->Draw(variableToPlot[i]+">>"+currentHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt);
|
305 |
|
|
currentHist->Scale(fileScale[f]);
|
306 |
|
|
f++;
|
307 |
|
|
|
308 |
|
|
// Loop over files
|
309 |
|
|
current_file = (TFile*)fileList->After( current_file );
|
310 |
anderson |
1.1 |
while ( current_file ) {
|
311 |
|
|
current_file->cd();
|
312 |
anderson |
1.2 |
//cout << ", file" << f;
|
313 |
anderson |
1.1 |
current_file->GetObject(treeName, tree);
|
314 |
|
|
|
315 |
|
|
TString tempHistName = currentHistName+"Temp";
|
316 |
anderson |
1.2 |
TH1* tempHist = (TH1*)currentHist->Clone(tempHistName);
|
317 |
|
|
tree->Draw(variableToPlot[i]+">>"+tempHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt);
|
318 |
anderson |
1.1 |
tempHist->Scale(fileScale[f]);
|
319 |
|
|
currentHist->Add(tempHist);
|
320 |
|
|
tempHist->Delete();
|
321 |
|
|
|
322 |
|
|
current_file = (TFile*)fileList->After( current_file );
|
323 |
|
|
f++;
|
324 |
|
|
} // End of loop over files
|
325 |
|
|
|
326 |
|
|
outputFile->cd();
|
327 |
|
|
currentHist->Write();
|
328 |
|
|
cout << endl;
|
329 |
|
|
} // End of loop over variabls to plot
|
330 |
|
|
} // End of loop over locations
|
331 |
|
|
// END of Core of Script //
|
332 |
|
|
//************************************************************
|
333 |
|
|
|
334 |
anderson |
1.4 |
cout << endl;
|
335 |
anderson |
1.2 |
cout << "Wrote file " << outputFileName << endl;
|
336 |
anderson |
1.4 |
cout << endl;
|
337 |
anderson |
1.1 |
outputFile->Close();
|
338 |
|
|
}
|