1 |
buchmann |
1.1 |
#include <iostream>
|
2 |
|
|
|
3 |
buchmann |
1.2 |
#include <RooRealVar.h>
|
4 |
|
|
#include <RooArgSet.h>
|
5 |
|
|
#include <RooDataSet.h>
|
6 |
|
|
|
7 |
buchmann |
1.1 |
using namespace std;
|
8 |
|
|
using namespace PlottingSetup;
|
9 |
|
|
|
10 |
|
|
|
11 |
buchmann |
1.2 |
|
12 |
|
|
|
13 |
buchmann |
1.1 |
ShapeDroplet LimitsFromEdge(float low_fullCLs, float high_CLs, TTree *events, string addcut, string name, string mcjzb, string datajzb, vector<float> jzbbins, float jzbpeakerrormc, float jzbpeakerrordata) {
|
14 |
|
|
write_error(__FUNCTION__,"Not implemented edge limits yet (returning crap)");
|
15 |
|
|
ShapeDroplet beta;beta.observed=-12345;beta.SignalIntegral=1;return beta;
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
void PrepareEdgeShapes(string mcjzb, string datajzb, vector<float> jzbbins, float jzbpeakerrordata) {
|
20 |
|
|
write_error(__FUNCTION__,"Not implemented edge shape storage yet");
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
|
24 |
buchmann |
1.2 |
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
namespace EdgeFitter {
|
28 |
|
|
|
29 |
|
|
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree*);
|
30 |
|
|
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree*);
|
31 |
|
|
void InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut);
|
32 |
|
|
void PrepareDatasets(int);
|
33 |
|
|
void DoFit();
|
34 |
|
|
string RandomStorageFile();
|
35 |
|
|
Yield Get_Z_estimate(float,int);
|
36 |
|
|
Yield Get_T_estimate(float,int);
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
float jzbmax;
|
40 |
|
|
float mllmin;
|
41 |
|
|
float mllmax;
|
42 |
|
|
TCut cut;
|
43 |
|
|
|
44 |
|
|
RooDataSet* AllData;
|
45 |
|
|
RooDataSet* eeSample;
|
46 |
|
|
RooDataSet* mmSample;
|
47 |
|
|
RooDataSet* emSample;
|
48 |
|
|
|
49 |
|
|
bool MarcoDebug;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
TTree* SkimTree(int isample) {
|
53 |
|
|
TTree* newTree = allsamples.collection[isample].events->CloneTree(0);
|
54 |
|
|
float xsweight=1.0;
|
55 |
|
|
if(allsamples.collection[isample].is_data==false) xsweight=luminosity*allsamples.collection[isample].weight;
|
56 |
|
|
if(EdgeFitter::MarcoDebug) {
|
57 |
|
|
cout << " Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl;
|
58 |
|
|
cout << " Going to reduce it with cut " << EdgeFitter::cut << endl;
|
59 |
|
|
}
|
60 |
|
|
TTreeFormula *select = new TTreeFormula("select", EdgeFitter::cut, allsamples.collection[isample].events);
|
61 |
|
|
float wgt=1.0;
|
62 |
|
|
allsamples.collection[isample].events->SetBranchAddress(cutWeight,&wgt);
|
63 |
|
|
for (Int_t entry = 0 ; entry < allsamples.collection[isample].events->GetEntries() ; entry++) {
|
64 |
|
|
allsamples.collection[isample].events->LoadTree(entry);
|
65 |
|
|
if (select->EvalInstance()) {
|
66 |
|
|
allsamples.collection[isample].events->GetEntry(entry);
|
67 |
|
|
wgt=wgt*xsweight;
|
68 |
|
|
newTree->Fill();
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
if(EdgeFitter::MarcoDebug) cout << " Reduced tree contains " << newTree->GetEntries() << " entries " << endl;
|
73 |
|
|
return newTree;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
void EdgeFitter::InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut) {
|
77 |
|
|
mllmin=_mllmin;
|
78 |
|
|
mllmax=_mllmax;
|
79 |
|
|
jzbmax=_jzbmax;
|
80 |
|
|
cut=_cut;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
void EdgeFitter::PrepareDatasets(int is_data) {
|
84 |
|
|
TTree *completetree;
|
85 |
|
|
bool hashit=0;
|
86 |
|
|
for(int isample=0;isample<allsamples.collection.size();isample++) {
|
87 |
|
|
if(!allsamples.collection[isample].is_active) continue;
|
88 |
|
|
if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
|
89 |
|
|
if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
|
90 |
|
|
if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC
|
91 |
|
|
if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it.
|
92 |
|
|
if(EdgeFitter::MarcoDebug) cout << "Considering : " << allsamples.collection[isample].samplename << endl;
|
93 |
|
|
if(!hashit) {
|
94 |
|
|
hashit=true;
|
95 |
|
|
completetree = SkimTree(isample)->CloneTree();
|
96 |
|
|
} else {
|
97 |
|
|
completetree->CopyEntries(SkimTree(isample));
|
98 |
|
|
}
|
99 |
|
|
if(EdgeFitter::MarcoDebug) cout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
RooRealVar mll("mll","mll",mllmin,mllmax,"GeV/c^{2}");
|
103 |
|
|
RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
|
104 |
|
|
RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
|
105 |
|
|
RooRealVar jzb("jzb","jzb",-jzbmax,jzbmax,"GeV/c");
|
106 |
|
|
RooRealVar weight("weight","weight",0,1000,"");
|
107 |
|
|
RooArgSet observables(mll,jzb,id1,id2,weight);
|
108 |
|
|
|
109 |
|
|
string title="CMS Data";
|
110 |
|
|
if(is_data!=1) title="CMS SIMULATION";
|
111 |
|
|
RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","weight");
|
112 |
|
|
completetree->Write();
|
113 |
|
|
// delete completetree;
|
114 |
|
|
|
115 |
|
|
EdgeFitter::eeSample = (RooDataSet*)LAllData.reduce("id1==id2&&id1==0");
|
116 |
|
|
EdgeFitter::mmSample = (RooDataSet*)LAllData.reduce("id1==id2&&id1==1");
|
117 |
|
|
EdgeFitter::emSample = (RooDataSet*)LAllData.reduce("id1!=id2");
|
118 |
|
|
EdgeFitter::AllData = (RooDataSet*)LAllData.reduce("id1!=id2||id1==id2");
|
119 |
|
|
|
120 |
|
|
eeSample->SetName("eeSample");
|
121 |
|
|
mmSample->SetName("mmSample");
|
122 |
|
|
emSample->SetName("emSample");
|
123 |
|
|
AllData->SetName("AllData");
|
124 |
|
|
|
125 |
|
|
if(EdgeFitter::MarcoDebug) {
|
126 |
|
|
cout << "Number of events in data sample = " << AllData->numEntries() << endl;
|
127 |
|
|
cout << "Number of events in ee sample = " << eeSample->numEntries() << endl;
|
128 |
|
|
cout << "Number of events in mm sample = " << mmSample->numEntries() << endl;
|
129 |
|
|
cout << "Number of events in em sample = " << emSample->numEntries() << endl;
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
string EdgeFitter::RandomStorageFile() {
|
134 |
|
|
TRandom3 *r = new TRandom3(0);
|
135 |
|
|
int rho = (int)r->Uniform(1,10000000);
|
136 |
|
|
stringstream RandomFile;
|
137 |
|
|
RandomFile << PlottingSetup::cbafbasedir << "/exchange/TempEdgeFile_" << rho << ".root";
|
138 |
|
|
delete r;
|
139 |
|
|
return RandomFile.str();
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
Yield EdgeFitter::Get_Z_estimate(float jzb_cut, int icut) {
|
143 |
|
|
if(MarcoDebug) write_error(__FUNCTION__,"Returning random Z yield");
|
144 |
|
|
Yield a(123,45,67); return a;
|
145 |
|
|
|
146 |
|
|
return PlottingSetup::allresults.predictions[icut].Zbkg;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
Yield EdgeFitter::Get_T_estimate(float jzb_cut, int icut) {
|
150 |
|
|
if(MarcoDebug) write_error(__FUNCTION__,"Returning random TTbar yield");
|
151 |
|
|
Yield a(1234,56,78); return a;
|
152 |
|
|
return PlottingSetup::allresults.predictions[icut].Flavorsym;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
void EdgeFitter::DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree *signalevents=0) {
|
156 |
|
|
|
157 |
|
|
string storagefile=EdgeFitter::RandomStorageFile();
|
158 |
|
|
TFile *f = new TFile(storagefile.c_str(),"RECREATE");
|
159 |
|
|
EdgeFitter::InitializeVariables(iMllLow,iMllHigh,jzbHigh,cut);
|
160 |
|
|
|
161 |
|
|
Yield Zestimate=EdgeFitter::Get_Z_estimate(jzb_cut,icut);
|
162 |
|
|
Yield Testimate=EdgeFitter::Get_T_estimate(jzb_cut,icut);
|
163 |
|
|
cout << "Cut at JZB>" << jzb_cut << "; using estimates: " << endl;
|
164 |
|
|
cout << " Z : " << Zestimate << endl;
|
165 |
|
|
cout << " T : " << Testimate << endl;
|
166 |
|
|
|
167 |
|
|
EdgeFitter::PrepareDatasets(is_data);
|
168 |
|
|
|
169 |
|
|
EdgeFitter::eeSample->Write();
|
170 |
|
|
EdgeFitter::emSample->Write();
|
171 |
|
|
EdgeFitter::mmSample->Write();
|
172 |
|
|
EdgeFitter::AllData->Write();
|
173 |
|
|
f->Close();
|
174 |
|
|
|
175 |
|
|
write_warning(__FUNCTION__,"Work continues here");
|
176 |
|
|
|
177 |
|
|
if(EdgeFitter::MarcoDebug) write_warning(__FUNCTION__,"Need to uncomment the next line (remove the output file)");
|
178 |
|
|
// gSystem->Exec(("rm "+storagefile).c_str());
|
179 |
|
|
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree *signalevents=0) {
|
183 |
|
|
for(int icut=0;icut<jzb_cut.size();icut++) {
|
184 |
|
|
stringstream addcut;
|
185 |
|
|
if(is_data==1) addcut << "(" << datajzb << ">" << jzb_cut[icut] << ")";
|
186 |
|
|
if(is_data!=1) addcut << "(" << mcjzb << ">" << jzb_cut[icut] << ")";
|
187 |
|
|
TCut jcut(addcut.str().c_str());
|
188 |
|
|
|
189 |
|
|
EdgeFitter::DoEdgeFit(mcjzb, datajzb, DataPeakError, MCPeakError, jzb_cut[icut], icut, is_data, jcut&&cut, signalevents);
|
190 |
|
|
|
191 |
|
|
}
|
192 |
|
|
}
|