ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/interface/ntupleReader.hpp
Revision: 1.5
Committed: Fri Jun 22 15:50:09 2012 UTC (12 years, 10 months ago) by bortigno
Branch: MAIN
CVS Tags: lhcp_UnblindFix, hcp_Unblind, lhcp_11April, LHCP_PreAppFixAfterFreeze, LHCP_PreAppFreeze, workingVersionAfterHCP, hcpApproval, hcpPreApp, ICHEP8TeV, HEAD
Changes since 1.4: +28 -16 lines
Log Message:
ichep 8TeV

File Contents

# Content
1 #ifndef ntupleReader_h
2 #define ntupleReader_h
3
4 #include <TROOT.h>
5 #include <TChain.h>
6 #include <TFile.h>
7 #include "TLorentzVector.h"
8 #include "ntupleLoader.hpp"
9
10
11 class ntupleReader : public ntupleLoader {
12 public :
13
14 ntupleReader(const char * infile) : ntupleLoader( infile ){};
15 // virtual ~ntupleReader();
16 virtual int GetSign(int v);
17 virtual std::vector<TLorentzVector> SimBs();
18 virtual std::vector<TLorentzVector> SVs();
19 virtual double typeIcorrMET( double sign );
20 virtual int CountJets();
21 virtual int CountAddJets();
22 virtual int CountAddForwardJets();
23 virtual int CountAddJets_jec( double sign );
24 virtual int CountAddLeptons();
25 virtual bool TriggerBit();
26 virtual TLorentzVector VectorBoson(); //vector boson TLorentz vector
27 virtual double resolution(double eta); //smearing for the jet energy resolution
28 virtual TLorentzVector hJet_jer( int idx, double sign );
29 virtual TLorentzVector H_jer( double sing );
30 virtual double hJet_PT( int idx, int sign ); //higgs jet energy correction
31 virtual double aJet_PT( int idx, int sign ); //addtional jet energy correction
32 virtual double hJet_E( int idx, int sign ); //higgs jet energy correction
33 virtual double aJet_E( int idx, int sign ); //addtional jet energy correction
34 virtual TLorentzVector Higgs( int sign ); //higgs candidate jet energy correction
35 virtual double hJet_CSV( int idx, int sign ); //higgs jet energy correction
36 virtual double hJet_pt_jec( int idx, double sign ); //higgs jet energy correction
37 virtual double aJet_pt_jec( int idx, double sign ); //addtional jet energy correction
38 virtual double hJet_e_jec( int idx, double sign );
39 virtual double aJet_e_jec( int idx, double sign );
40 virtual TLorentzVector H_jec( double sign ); //higgs candidate jet energy correction
41 virtual double hJet_csv_cUP( int idx );
42 virtual double hJet_csv_cDOWN( int idx );
43 virtual double hJet_csv_cFUP( int idx );
44 virtual double hJet_csv_cFDOWN( int idx );
45 virtual double hJet_pt_jecUP( int idx );
46 virtual double hJet_pt_jecDOWN( int idx );
47 virtual double aJet_pt_jecUP( int idx );
48 virtual double aJet_pt_jecDOWN( int idx );
49 virtual TLorentzVector H_jecUP();
50 virtual TLorentzVector H_jecDOWN();
51
52 };
53
54 int ntupleReader::GetSign(int v){
55 return v > 0 ? 1 : (v < 0 ? -1 : 0);
56 }
57
58 std::vector<TLorentzVector> ntupleReader::SimBs(){
59 TLorentzVector simB;
60 std::vector<TLorentzVector> iSimBs;
61 for(int j=0; j<nSimBs; ++j){
62 simB.SetPtEtaPhiM( SimBs_pt[j], SimBs_eta[j], SimBs_phi[j], SimBs_mass[j]);
63 iSimBs.push_back( simB );
64 }
65 return iSimBs;
66 }
67
68 std::vector<TLorentzVector> ntupleReader::SVs(){
69 TLorentzVector sv;
70 std::vector<TLorentzVector> iSVs;
71 for(int j=0; j<nSvs; ++j){
72 sv.SetPtEtaPhiM( Sv_pt[j], Sv_eta[j], Sv_phi[j], Sv_massBCand[j]);
73 iSVs.push_back( sv );
74 }
75 return iSVs;
76 }
77
78 double ntupleReader::typeIcorrMET( double sign = 0 ){
79 double met_et;
80 TLorentzVector sumPt;
81 TLorentzVector sumPtRaw;
82 TLorentzVector rawMet, jet, rawJet;
83 for(int i=0; i<nhJets; ++i){
84 jet.SetPtEtaPhiE( hJet_PT(i, sign) , hJet_eta[i], hJet_phi[i], hJet_E(i, sign));
85 rawJet.SetPtEtaPhiE( hJet_ptRaw[i] , hJet_eta[i], hJet_phi[i], (hJet_ptRaw[i]/hJet_PT(i,sign)) * hJet_E(i,sign));
86 sumPt += jet;
87 sumPtRaw += rawJet;
88 }
89 rawMet.SetPtEtaPhiE(MET_et, 0., MET_phi, MET_et);
90 met_et = (rawMet - (sumPt - sumPtRaw)).Pt();
91 return met_et;
92 }
93 TLorentzVector ntupleReader::VectorBoson(){
94 TLorentzVector l1, l2;
95 l1.SetPtEtaPhiM(vLepton_pt[0],vLepton_eta[0],vLepton_phi[0],vLepton_mass[0] );
96 l2.SetPtEtaPhiM(vLepton_pt[1],vLepton_eta[1],vLepton_phi[1],vLepton_mass[1] );
97 return (l1+l2);
98 }
99
100 //JER
101 double ntupleReader::resolution(double eta){
102 double inner = 0.06;
103 double outer = 0.1;
104 double eta_tracker = 1.1;
105 if(abs(eta) < eta_tracker) return inner; else return outer;
106 }
107
108 TLorentzVector ntupleReader::hJet_jer( int idx, double sign ){
109 TLorentzVector tmp;
110 double hJet_pt_jer = hJet_pt[idx] + sign * resolution(hJet_eta[idx])*TMath::Abs(hJet_pt[idx]-hJet_genPt[idx]);
111 tmp.SetPtEtaPhiE( hJet_pt_jer,
112 hJet_eta[idx],
113 hJet_phi[idx],
114 hJet_e[idx]*(hJet_pt_jer/hJet_pt[idx]) );
115 return tmp;
116 }
117
118 TLorentzVector ntupleReader::H_jer( double sign ){
119 TLorentzVector h;
120 h = hJet_jer( 0, sign ) + hJet_jer( 1, sign );
121 return h;
122 }
123
124 double ntupleReader::hJet_PT( int idx, int sign ){
125 if( TMath::Abs(sign) < 2 )
126 return hJet_pt[idx]*(1 + (sign)*hJet_JECUnc[idx]);
127 else // +- 2 are for jet energy corrections
128 return (hJet_jer( idx, sign - GetSign(sign)*1 )).Pt() ;
129 }
130 double ntupleReader::aJet_PT( int idx, int sign ){ return aJet_pt[idx]*(1 + (sign)*aJet_JECUnc[idx]); }
131 double ntupleReader::hJet_E( int idx, int sign ){ return hJet_e[idx] * hJet_PT(idx, sign)/hJet_pt[idx]; }
132 double ntupleReader::aJet_E( int idx, int sign ){ return aJet_e[idx] * aJet_PT(idx, sign)/aJet_pt[idx]; }
133 TLorentzVector ntupleReader::Higgs( int sign ){
134 TLorentzVector j1,j2,H;
135 j1.SetPtEtaPhiE( hJet_PT(0,sign), hJet_eta[0], hJet_phi[0], hJet_E(0,sign) );
136 j2.SetPtEtaPhiE( hJet_PT(1,sign), hJet_eta[1], hJet_phi[1], hJet_E(1,sign) );
137 return H=j1+j2;
138 }
139 double ntupleReader::hJet_CSV( int idx, int sign ){
140 //this is not reshaped
141 //else return (hJet_csv[idx]);
142 //this is reshaped using my framework
143 // else return (sh.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csv[idx], hJet_flavour[idx] ));
144 //using Niklas framework the csv not reshaped is called csvOld
145 if( hJet_flavour[0] < 1 ) // stupid check if it is data. In niklas framework there is no csvOld for data. reshaping knows about data for flavour 0
146 return (reshape.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csv[idx], hJet_flavour[idx] ));
147 else{ //MC
148 if(sign == 1) return (reshape_bTagUp.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csvOld[idx], hJet_flavour[idx] ));
149 else if(sign == -1) return (reshape_bTagDown.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csvOld[idx], hJet_flavour[idx] ));
150 else if( sign == 2 ) return (reshape_misTagUp.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csvOld[idx], hJet_flavour[idx] ));
151 else if( sign == -2 ) return (reshape_misTagDown.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csvOld[idx], hJet_flavour[idx] ));
152 else return (reshape.reshape( hJet_eta[idx], hJet_pt[idx], hJet_csvOld[idx], hJet_flavour[idx] ));
153 }
154 }
155
156
157 //for jet energy correction variation
158 double ntupleReader::hJet_pt_jec( int idx, double sign ){ return hJet_pt[idx]*(1 + (sign)*hJet_JECUnc[idx]); }
159 double ntupleReader::aJet_pt_jec( int idx, double sign ){ return aJet_pt[idx]*(1 + (sign)*aJet_JECUnc[idx]); }
160
161 double ntupleReader::hJet_e_jec( int idx, double sign ){ return hJet_e[idx]*(1 + (sign)*hJet_JECUnc[idx]); }
162 double ntupleReader::aJet_e_jec( int idx, double sign ){ return aJet_e[idx]*(1 + (sign)*aJet_JECUnc[idx]); }
163
164 TLorentzVector ntupleReader::H_jec( double sign ){
165 TLorentzVector j1,j2,H;
166 j1.SetPtEtaPhiE( hJet_pt_jec(0,sign), hJet_eta[0], hJet_phi[0], hJet_e_jec(0,sign) );
167 j2.SetPtEtaPhiE( hJet_pt_jec(1,sign), hJet_eta[1], hJet_phi[1], hJet_e_jec(1,sign) );
168 return H=j1+j2;
169 }
170 double ntupleReader::hJet_csv_cUP( int idx ){ return ( hJet_csvUp[idx] ); }
171 double ntupleReader::hJet_csv_cDOWN( int idx ){ return ( hJet_csvDown[idx] ); }
172 double ntupleReader::hJet_csv_cFUP( int idx ){ return ( hJet_csvFUp[idx] ); }
173 double ntupleReader::hJet_csv_cFDOWN( int idx ){ return ( hJet_csvFDown[idx] ); }
174 double ntupleReader::hJet_pt_jecUP( int idx ){ return hJet_pt_jec(idx,+1); }
175 double ntupleReader::hJet_pt_jecDOWN( int idx ){ return hJet_pt_jec(idx,-1); }
176 double ntupleReader::aJet_pt_jecUP( int idx ){ return aJet_pt_jec(idx,+1); }
177 double ntupleReader::aJet_pt_jecDOWN( int idx ){ return aJet_pt_jec(idx,-1); }
178 TLorentzVector ntupleReader::H_jecUP(){ return H_jec(+1); }
179 TLorentzVector ntupleReader::H_jecDOWN(){ return H_jec(-1); }
180
181
182 int ntupleReader::CountJets(){
183 int sum=0;
184 for(int i=0; i<nhJets; ++i)
185 if( hJet_pt[i] > 20.
186 && TMath::Abs(hJet_eta[i]) < 2.4 )
187 sum++;
188 for(int i=0; i<naJets; ++i)
189 if( aJet_pt[i] > 20.
190 && TMath::Abs(aJet_eta[i]) < 2.4 )
191 sum++;
192 return sum;
193 }
194 int ntupleReader::CountAddJets(){
195 int sum=0;
196 for(int i=0; i<naJets; ++i)
197 if( aJet_pt[i] > 20.
198 && TMath::Abs(aJet_eta[i]) < 2.4 )
199 sum++;
200 return sum;
201 }
202 int ntupleReader::CountAddForwardJets(){
203 int sum=0;
204 for(int i=0; i<naJets; ++i)
205 if( aJet_pt[i] > 30.
206 && TMath::Abs(aJet_eta[i]) > 2.4
207 && TMath::Abs(aJet_eta[i]) < 4.5 )
208 sum++;
209 return sum;
210 }
211 int ntupleReader::CountAddJets_jec( double sign ){
212 int sum=0;
213 for(int i=0; i<naJets; ++i)
214 if( aJet_pt[i]*(1+(sign)*aJet_JECUnc[i]) > 20.
215 && TMath::Abs(aJet_eta[i]) < 2.4 )
216 sum++;
217 return sum;
218 }
219
220 int ntupleReader::CountAddLeptons(){
221 int sum=0;
222 for(int i=0; i<nalep; ++i)
223 if( aLepton_pt[i] > 15.
224 && abs(aLepton_eta[i]) < 2.5
225 && aLepton_pfCombRelIso[i] < 0.15 )
226 sum++;
227 return sum;
228 }
229 bool ntupleReader::TriggerBit()
230 {
231 if( triggerFlags[5]
232 || triggerFlags[6] )
233 return false;
234 else
235 return true;
236 }
237
238 #endif // #ifdef ntupleReader_cxx
239