ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/interface/samples.h
Revision: 1.2
Committed: Thu May 31 08:05:06 2012 UTC (12 years, 11 months ago) by bortigno
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
removed duplication

File Contents

# Content
1 #ifndef samples_h
2 #define samples_h
3
4 #include <string>
5 #include <vector>
6 #include <TFile.h>
7 #include <TH1F.h>
8 #include <TTree.h>
9 #include <iostream>
10 #include <sstream>
11 #include "TMath.h"
12 #include <TCut.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <time.h>
16
17 struct Sample {
18 Sample();
19 Sample( float xs, std::string n, std::string f, int c, bool isdata, float datalumi=-1., float nEvents=-1 )
20 : xsec(xs),luminosity(datalumi),name(n),filename(f),color(c),data(isdata),f(0),nevents(nEvents) {}
21
22 float lumi() { if(data) return luminosity; else return numberOfEvents()/xsec; }
23 float lumi(double fA, double fB) { if(data) return luminosity; else return numberOfEvents(fA,fB)/xsec; }
24 float scale(float l) { if(lumi()>0) return l/lumi(); else return 0;}
25 float scale(float l, double fA, double fB) { if(lumi(fA,fB)>0) return l/lumi(fA,fB); else return 0;}
26 float scale(float l, double fA, double fB, double *SF) {
27 std::string DYL("DYL");
28 std::string DYC("DYC");
29 std::string DYNoB("DYNoB");
30 std::string DYB("DYB");
31 std::string TTbar("TTbar");
32 if(lumi(fA,fB)>0){
33 if(name == DYL || name == DYC || name == DYNoB)
34 return SF[0]*l/lumi(fA,fB);
35 else if(name == TTbar)
36 return SF[1]*l/lumi(fA,fB);
37 else if(name == DYB)
38 return SF[2]*l/lumi(fA,fB);
39 else
40 return scale(l,fA,fB);
41 }
42 else
43 return 0; }
44 TFile * file() { if(f) return f; else return f=TFile::Open(filename.c_str());}
45 float numberOfEvents( double fA, double fB )
46 {
47 if(data) return luminosity;
48 double CountWithPU,CountWithPU2011B;
49 double nOfEvents;
50 if(nevents !=-1) return nevents;
51 else
52 {
53 CountWithPU = ((TH1F*)file()->Get("CountWithPU"))->GetBinContent(1);
54 CountWithPU2011B = ((TH1F*)file()->Get("CountWithPU2011B"))->GetBinContent(1);
55 nOfEvents = fA*CountWithPU + fB*CountWithPU2011B;
56 return nOfEvents;
57 }
58 }
59
60 float numberOfEvents()
61 {
62 if(data) return luminosity;
63 if(nevents !=-1) return nevents;
64 else
65 {
66 return ((TH1F*)file()->Get("Count"))->GetBinContent(1);
67 }
68 }
69
70 void dump(float l)
71 {
72 std::cout << name << "\t& " << xsec << "\t& " << lumi()/1000 << "/fb \t& " << scale(l) << "\t& " << numberOfEvents() << std::endl;
73 // std::cout << name << "\t& " << xsec << "\t& " << lumi()/1000 << "/fb \t& " << scale(l) << std::endl;
74 // std::cout << name << "\t& " << xsec << "\t& " << lumi()/1000 << std::endl;
75 }
76
77 void dump(float l, double fa, double fb)
78 {
79 std::cout << name << "\t& " << xsec << "\t& " << lumi(fa,fb)/1000 << "/fb \t& " << scale(l,fa,fb) << "\t& " << numberOfEvents(fa,fb) << std::endl;
80 // std::cout << name << "\t& " << xsec << "\t& " << lumi()/1000 << "/fb \t& " << scale(l) << std::endl;
81 // std::cout << name << "\t& " << xsec << "\t& " << lumi()/1000 << std::endl;
82 }
83
84 float bareCount(TCut iCut){
85 float NpassedEvents = 0;
86 file()->cd();
87 NpassedEvents = ((TTree*)file()->Get("tree"))->Draw("H.dPhi", iCut, "goff");
88 return NpassedEvents;
89 }
90
91 float bareCount(TCut iWeight, TCut iCut){
92 float NpassedEvents = 0;
93 file()->cd();
94 NpassedEvents = ((TTree*)file()->Get("tree"))->Draw("H.dPhi", iWeight * iCut, "goff");
95 return NpassedEvents;
96 }
97
98 float bareCountError(TCut iCut){ bareCountError_ = 0; if(bareCount(iCut)>0) bareCountError_ = TMath::Sqrt(bareCount(iCut)); return bareCountError_; }
99
100 float count(TCut iCut){
101 float NweightedEvents = 0;
102 if(data)
103 return bareCount(iCut);
104 else{
105 TH1F* histo;
106 ((TTree*)file()->Get("tree"))->Draw("H.dPhi>>histo", iCut, "goff");
107 histo = (TH1F*)gDirectory->Get("histo");
108 NweightedEvents = histo->Integral()/lumi();
109 return NweightedEvents;
110 }
111 }
112
113 float count(TCut iWeight, TCut iCut){
114 float NweightedEvents = 0;
115 if(data)
116 return bareCount(iCut);
117 else{
118 TH1F* histo;
119 ((TTree*)file()->Get("tree"))->Draw("H.dPhi>>histo", iWeight*iCut, "goff");
120 histo = (TH1F*)gDirectory->Get("histo");
121 NweightedEvents = histo->Integral()/lumi();
122 return NweightedEvents;
123 }
124 }
125
126 float count(TCut iCut, double fA, double fB){
127 float NweightedEvents = 0;
128 if(data)
129 return bareCount(iCut);
130 else{
131 TH1F* histo;
132 ((TTree*)file()->Get("tree"))->Draw("H.dPhi>>histo", iCut, "goff");
133 histo = (TH1F*)gDirectory->Get("histo");
134 NweightedEvents = histo->Integral()/lumi(fA, fB);
135 return NweightedEvents;
136 }
137 }
138
139 float count(TCut iWeight, TCut iCut, double fA, double fB){
140 float NweightedEvents = 0;
141 if(data)
142 return bareCount(iCut);
143 else{
144 TH1F* histo;
145 std::stringstream oss;
146 srand( time(NULL) );
147 int num = rand() % 10000 + 1;
148 oss << num;
149 std::string var("H.dPhi>>");
150 std::string histoName("histo");
151 histoName=histoName+name+oss.str();
152 ((TTree*)file()->Get("tree"))->Draw((var+histoName).c_str(), iWeight*iCut, "goff");
153 histo = (TH1F*)gDirectory->Get(histoName.c_str());
154 NweightedEvents = histo->Integral()/lumi(fA, fB);
155 return NweightedEvents;
156 }
157 }
158
159 float countError(TCut iCut){ countError_ = count(iCut)/bareCountError(iCut); return countError_; }
160
161 float countError(TCut iWeight, TCut iCut, double fA, double fB){ countError_ = 0; if(bareCountError(iCut)>0) countError_ = count(iWeight,iCut,fA, fB)/bareCountError(iCut); return countError_; }
162
163 float countError(TCut iCut, float systematicError ){
164 float totalError=0;
165 if(systematicError < 1)
166 totalError = TMath::Sqrt( TMath::Power(count(iCut)/bareCountError(iCut),2) + TMath::Power( systematicError*count(iCut),2) );
167 else
168 std::cout << "Systematic error has to be espressed in %" << std::endl;
169 return totalError;
170 }
171
172 float addSysError( float error, float systematicError ){ return TMath::Sqrt( TMath::Power(error,2) + TMath::Power( systematicError,2) ); }
173
174 void setCountError( float newCountError ){
175 countError_ = newCountError;
176 }
177
178
179 float countError_;
180 float bareCountError_;
181 float nevents;
182 float xsec;
183 float luminosity;
184 std::string name;
185 std::string filename;
186 int color;
187 bool data;
188 TFile * f;
189
190 };
191
192 #endif