1 |
#include <iostream>
|
2 |
|
3 |
|
4 |
|
5 |
#include <TVirtualIndex.h>
|
6 |
|
7 |
#include <RooRealVar.h>
|
8 |
#include <RooArgSet.h>
|
9 |
#include <RooDataSet.h>
|
10 |
#include <RooMCStudy.h>
|
11 |
#include <RooCategory.h>
|
12 |
|
13 |
#include <RooPlot.h>
|
14 |
#include <RooGaussian.h>
|
15 |
#include <RooConstVar.h>
|
16 |
#include <RooSimultaneous.h>
|
17 |
#include <RooAddPdf.h>
|
18 |
#include <RooFitResult.h>
|
19 |
#include <RooVoigtian.h>
|
20 |
#include <RooMsgService.h>
|
21 |
#include <RooChebychev.h>
|
22 |
|
23 |
#include <RooStats/ModelConfig.h>
|
24 |
#include "RooStats/ProfileLikelihoodCalculator.h"
|
25 |
#include "RooStats/LikelihoodInterval.h"
|
26 |
#include "RooStats/HypoTestResult.h"
|
27 |
#include "RooStats/SimpleLikelihoodRatioTestStat.h"
|
28 |
#include "RooStats/ProfileLikelihoodTestStat.h"
|
29 |
#include "RooStats/HybridCalculatorOriginal.h"
|
30 |
#include "RooStats/HypoTestInverterOriginal.h"
|
31 |
|
32 |
//#include "ParametrizedEdge.C"
|
33 |
#include "ExtendedMath.C"
|
34 |
#include "EdgeModules/RooSUSYTPdf.cxx"
|
35 |
#include "EdgeModules/RooSUSYBkgPdf.cxx"
|
36 |
#include "EdgeModules/RooSUSYCompleteBkgPdf.cxx"
|
37 |
#include "EdgeModules/RooSUSYPolynomial.cxx"
|
38 |
|
39 |
#include "md5/md5.h"
|
40 |
#include "md5/md5.C"
|
41 |
|
42 |
using namespace std;
|
43 |
using namespace PlottingSetup;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
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) {
|
49 |
write_error(__FUNCTION__,"Not implemented edge limits yet (returning crap)");
|
50 |
ShapeDroplet beta;beta.observed=-12345;beta.SignalIntegral=1;return beta;
|
51 |
}
|
52 |
|
53 |
|
54 |
void PrepareEdgeShapes(string mcjzb, string datajzb, vector<float> jzbbins, float jzbpeakerrordata) {
|
55 |
write_error(__FUNCTION__,"Not implemented edge shape storage yet");
|
56 |
}
|
57 |
|
58 |
|
59 |
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
60 |
|
61 |
|
62 |
namespace EdgeFitter {
|
63 |
|
64 |
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree*);
|
65 |
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree*);
|
66 |
void getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp);
|
67 |
void InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut);
|
68 |
void PrepareDatasets(int);
|
69 |
void DrawDatasetContent(int);
|
70 |
void DoFit(int is_data, float jzb_cut);
|
71 |
string RandomStorageFile();
|
72 |
Yield Get_Z_estimate(float,int);
|
73 |
Yield Get_T_estimate(float,int);
|
74 |
float calcExclusion(RooWorkspace *ws, RooDataSet data, bool calcExclusion);
|
75 |
vector<RooDataSet> generateToys(RooWorkspace *ws, int nToys);
|
76 |
void prepareLimits(RooWorkspace *ws, bool ComputeBands);
|
77 |
TGraph* prepareLM(float mass, float nEv);
|
78 |
|
79 |
float jzbmax;
|
80 |
float mllmin;
|
81 |
float mllmax;
|
82 |
TCut cut;
|
83 |
|
84 |
RooDataSet* AllData;
|
85 |
RooDataSet* eeSample;
|
86 |
RooDataSet* mmSample;
|
87 |
RooDataSet* OFSample;
|
88 |
RooDataSet* SFSample;
|
89 |
|
90 |
bool MarcoDebug=true;
|
91 |
|
92 |
float FixedMEdge=-1;
|
93 |
float FixedMEdgeChi2_H1=-1;
|
94 |
float FixedMEdgeChi2_H0=-1;
|
95 |
|
96 |
bool RejectPointIfNoConvergence=false;
|
97 |
|
98 |
string Mode="UndefinedMode";
|
99 |
|
100 |
bool AllowTriangle=true;
|
101 |
}
|
102 |
|
103 |
TGraph* EdgeFitter::prepareLM(float mass, float nEv) {
|
104 |
float massLM[1];
|
105 |
massLM[0]=mass;
|
106 |
float accEffLM[1];
|
107 |
accEffLM[0]=nEv/PlottingSetup::luminosity;
|
108 |
TGraph *lm = new TGraph(1, massLM, accEffLM);
|
109 |
lm->GetXaxis()->SetNoExponent(true);
|
110 |
lm->GetXaxis()->SetTitle("m_{cut} [GeV]");
|
111 |
lm->GetYaxis()->SetTitle("#sigma #times A [pb] 95% CL UL");
|
112 |
lm->GetXaxis()->SetLimits(0.,300.);
|
113 |
lm->GetYaxis()->SetRangeUser(0.,0.08);
|
114 |
lm->SetMarkerStyle(34);
|
115 |
lm->SetMarkerColor(kRed);
|
116 |
return lm;
|
117 |
}
|
118 |
|
119 |
vector<RooDataSet> EdgeFitter::generateToys(RooWorkspace *ws, int nToys) {
|
120 |
ws->ls();
|
121 |
ws->var("nSig")->setVal(0.);
|
122 |
ws->var("nSig")->setConstant(true);
|
123 |
RooFitResult* fit = ws->pdf("combModel")->fitTo(*ws->data("data_obs"),RooFit::Save());
|
124 |
vector<RooDataSet> theToys;
|
125 |
|
126 |
RooMCStudy mcEE(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"EE"));
|
127 |
mcEE.generate(nToys,44,true);
|
128 |
RooMCStudy mcMM(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"MM"));
|
129 |
mcMM.generate(nToys,44,true);
|
130 |
RooMCStudy mcOSOF(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"OSOF"));
|
131 |
mcOSOF.generate(nToys,44,true);
|
132 |
|
133 |
RooRealVar mll("m_{ll}","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
|
134 |
RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
|
135 |
RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
|
136 |
RooRealVar jzb("jzb","jzb",-jzbmax,jzbmax,"GeV/c");
|
137 |
RooRealVar weight("weight","weight",0,1000,"");
|
138 |
RooArgSet observables(mll,jzb,id1,id2,weight);
|
139 |
|
140 |
for(int i=0;i<nToys;i++) {
|
141 |
RooDataSet* toyEE = (RooDataSet*)mcEE.genData(i);
|
142 |
RooDataSet* toyMM = (RooDataSet*)mcMM.genData(i);
|
143 |
RooDataSet* toyOSOF = (RooDataSet*)mcOSOF.genData(i);
|
144 |
stringstream toyname;
|
145 |
toyname << "theToy_" << i;
|
146 |
write_warning(__FUNCTION__,"Problem while adding toys");
|
147 |
RooDataSet toyData = RooDataSet(toyname.str().c_str(),toyname.str().c_str(),observables,RooFit::Index(const_cast<RooCategory&>(*ws->cat("cat"))),RooFit::Import("OSOF",*toyOSOF),RooFit::Import("EE",*toyEE),RooFit::Import("MM",*toyMM));
|
148 |
theToys.push_back(toyData);
|
149 |
}
|
150 |
ws->var("nSig")->setVal(17.0);
|
151 |
ws->var("nSig")->setConstant(false);
|
152 |
return theToys;
|
153 |
}
|
154 |
|
155 |
void EdgeFitter::getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp) {
|
156 |
TH1F *gauLimit = new TH1F("gausLimit","gausLimit",60,0.,80./PlottingSetup::luminosity);
|
157 |
vector<float> theLimits;
|
158 |
for(int itoy=0;itoy<(int)theToys.size();itoy++) {
|
159 |
float theLimit = calcExclusion(ws,theToys[itoy],false);
|
160 |
if(theLimit > 0 ) gauLimit->Fill(theLimit);
|
161 |
}
|
162 |
const Int_t nQ = 4;
|
163 |
Double_t yQ[nQ] = {0.,0.,0.,0.};
|
164 |
Double_t xQ[nQ] = {0.022750132,0.1586552539,0.84134474609999998,0.977249868};
|
165 |
gauLimit->GetQuantiles(nQ,yQ,xQ);
|
166 |
median = gauLimit->GetMean();
|
167 |
// median = median1(gauLimit);
|
168 |
twoSigmaDown = abs(yQ[0]-median);
|
169 |
sigmaDown = abs(yQ[1]-median);
|
170 |
sigmaUp = abs(yQ[2]-median);
|
171 |
twoSigmaUp = abs(yQ[3]-median);
|
172 |
dout << median * PlottingSetup::luminosity << " " << sigmaUp * PlottingSetup::luminosity << endl;
|
173 |
}
|
174 |
|
175 |
void EdgeFitter::prepareLimits(RooWorkspace *ws, bool ComputeBands) {
|
176 |
if(ComputeBands) {
|
177 |
vector<RooDataSet> theToys = EdgeFitter::generateToys(ws,50);
|
178 |
vector<float> medVals;
|
179 |
vector<float> medLimits;
|
180 |
vector<float> sigmaLimitsDown;
|
181 |
vector<float> sigmaLimitsUp;
|
182 |
vector<float> twoSigmaLimitsDown;
|
183 |
vector<float> twoSigmaLimitsUp;
|
184 |
for(int i=20;i<=320;i+=40) {
|
185 |
ws->var("nSig")->setVal(10.0);
|
186 |
medVals.push_back((float)i);
|
187 |
ws->var("m0")->setVal((float)i);
|
188 |
ws->var("m0")->setConstant(true);
|
189 |
float Smedian,SsigmaDown,SsigmaUp,StwoSigmaDown,StwoSigmaUp;
|
190 |
EdgeFitter::getMedianLimit(ws,theToys,Smedian,SsigmaDown,SsigmaUp,StwoSigmaDown,StwoSigmaUp);
|
191 |
medLimits.push_back(Smedian);
|
192 |
sigmaLimitsDown.push_back(SsigmaDown);
|
193 |
sigmaLimitsUp.push_back(SsigmaUp);
|
194 |
twoSigmaLimitsDown.push_back(StwoSigmaDown);
|
195 |
twoSigmaLimitsUp.push_back(StwoSigmaUp);
|
196 |
}
|
197 |
write_warning(__FUNCTION__,"Still need to store limits");
|
198 |
} else {
|
199 |
vector<float> theVals;
|
200 |
vector<float> theLimits;
|
201 |
for(int i=20;i<300;i+=5) {
|
202 |
ws->var("nSig")->setVal(0.0);
|
203 |
theVals.push_back((float)i);
|
204 |
ws->var("m0")->setVal((float)i);
|
205 |
ws->var("m0")->setConstant(true);
|
206 |
// theLimits.push_back(calcExclusion(ws,(RooDataSet)*ws->data("data_obs"),true));
|
207 |
write_error(__FUNCTION__,"Error while casting roo data set");
|
208 |
}
|
209 |
|
210 |
for(int i=0;i<(int)theLimits.size();i++) {
|
211 |
if((theLimits[i]<2.0/PlottingSetup::luminosity)||(theLimits[i]>40.0/PlottingSetup::luminosity)) {
|
212 |
dout << i << " : " << theVals[i] << endl;
|
213 |
theLimits[i] = (theLimits[i+2]+theLimits[i-2])/2.0;
|
214 |
write_warning(__FUNCTION__,"Need to store limits");
|
215 |
}
|
216 |
write_warning(__FUNCTION__,"Need to store limits");
|
217 |
}
|
218 |
}
|
219 |
}
|
220 |
|
221 |
|
222 |
float EdgeFitter::calcExclusion(RooWorkspace *ws, RooDataSet data, bool LoadDataObs) {
|
223 |
int numberOfToys=50;
|
224 |
RooRealVar mu("mu","nSig",0,10000,"");
|
225 |
RooArgSet poi = RooArgSet(mu);
|
226 |
RooArgSet *nullParams = (RooArgSet*)poi.snapshot();
|
227 |
nullParams->setRealValue("nSig",0);
|
228 |
RooStats::ModelConfig *model = new RooStats::ModelConfig();
|
229 |
model->SetWorkspace(*ws);
|
230 |
model->SetPdf("combModel");
|
231 |
model->SetParametersOfInterest(poi);
|
232 |
// if(LoadDataObs) data = (RooDataSet)*ws->data("data_obs");
|
233 |
|
234 |
RooStats::ProfileLikelihoodCalculator plc(data, *model);
|
235 |
plc.SetNullParameters(*nullParams);
|
236 |
plc.SetTestSize(0.05);
|
237 |
|
238 |
RooStats::LikelihoodInterval* interval = plc.GetInterval();
|
239 |
RooStats::HypoTestResult *htr = plc.GetHypoTest();
|
240 |
double theLimit = interval->UpperLimit( mu );
|
241 |
// double significance = htr->Significance();
|
242 |
|
243 |
ws->defineSet("obs","nB");
|
244 |
ws->defineSet("poi","nSig");
|
245 |
|
246 |
RooStats::ModelConfig b_model = RooStats::ModelConfig("B_model", ws);
|
247 |
b_model.SetPdf(*ws->pdf("combModel"));
|
248 |
b_model.SetObservables(*ws->set("obs"));
|
249 |
b_model.SetParametersOfInterest(*ws->set("poi"));
|
250 |
ws->var("nSig")->setVal(0.0); //# important!
|
251 |
b_model.SetSnapshot(*ws->set("poi"));
|
252 |
|
253 |
RooStats::ModelConfig sb_model = RooStats::ModelConfig("S+B_model", ws);
|
254 |
sb_model.SetPdf(*ws->pdf("combModel"));
|
255 |
sb_model.SetObservables(*ws->set("obs"));
|
256 |
sb_model.SetParametersOfInterest(*ws->set("poi"));
|
257 |
ws->var("nSig")->setVal(64.0); //# important!
|
258 |
sb_model.SetSnapshot(*ws->set("poi"));
|
259 |
|
260 |
RooStats::SimpleLikelihoodRatioTestStat slrts = RooStats::SimpleLikelihoodRatioTestStat(*b_model.GetPdf(),*sb_model.GetPdf());
|
261 |
slrts.SetNullParameters(*b_model.GetSnapshot());
|
262 |
slrts.SetAltParameters(*sb_model.GetSnapshot());
|
263 |
RooStats::ProfileLikelihoodTestStat profll = RooStats::ProfileLikelihoodTestStat(*b_model.GetPdf());
|
264 |
|
265 |
RooStats::HybridCalculatorOriginal hc = RooStats::HybridCalculatorOriginal(data, sb_model, b_model,0,0);
|
266 |
hc.SetTestStatistic(2);
|
267 |
hc.SetNumberOfToys(numberOfToys);
|
268 |
|
269 |
RooStats::HypoTestInverterOriginal hcInv = RooStats::HypoTestInverterOriginal(hc,*ws->var("nSig"));
|
270 |
hcInv.SetTestSize(0.05);
|
271 |
hcInv.UseCLs(true);
|
272 |
hcInv.RunFixedScan(5,theLimit-0.5,theLimit+0.5);;
|
273 |
RooStats::HypoTestInverterResult* hcInt = hcInv.GetInterval();
|
274 |
float ulError = hcInt->UpperLimitEstimatedError();
|
275 |
theLimit = hcInt->UpperLimit();
|
276 |
dout << "Found upper limit : " << theLimit << "+/-" << ulError << endl;
|
277 |
|
278 |
return theLimit/PlottingSetup::luminosity;
|
279 |
|
280 |
}
|
281 |
|
282 |
string GetSkimName(int isample) {
|
283 |
return removefunnystring(allsamples.collection[isample].filename);
|
284 |
}
|
285 |
|
286 |
TTree* SkimTree(int isample) {
|
287 |
string TreeName = GetSkimName(isample);
|
288 |
cout << "About to skim " << TreeName << " for sample id " << isample << endl;
|
289 |
TTree* newTree = new TTree(TreeName.c_str(),TreeName.c_str());
|
290 |
|
291 |
float mll,edgeWeight;
|
292 |
int id1,id2;
|
293 |
|
294 |
newTree->Branch("edgeWeight",&edgeWeight,"edgeWeight/F");
|
295 |
newTree->Branch("mll",&mll,"mll/F");
|
296 |
newTree->Branch("id1",&id1,"id1/I");
|
297 |
newTree->Branch("id2",&id2,"id2/I");
|
298 |
newTree->Branch("isample",&isample,"isample/I");
|
299 |
|
300 |
float xsweight=1.0;
|
301 |
if(allsamples.collection[isample].is_data==false) xsweight=luminosity*allsamples.collection[isample].weight;
|
302 |
if(EdgeFitter::MarcoDebug) {
|
303 |
dout << " Going to reduce it with cut " << EdgeFitter::cut << endl;
|
304 |
dout << " Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl;
|
305 |
}
|
306 |
|
307 |
float tmll;
|
308 |
int tid1,tid2;
|
309 |
allsamples.collection[isample].events->SetBranchAddress("mll",&tmll);
|
310 |
allsamples.collection[isample].events->SetBranchAddress("id1",&tid1);
|
311 |
allsamples.collection[isample].events->SetBranchAddress("id2",&tid2);
|
312 |
|
313 |
TTreeFormula *select = new TTreeFormula("select", EdgeFitter::cut, allsamples.collection[isample].events);
|
314 |
TTreeFormula *Weight = new TTreeFormula("Weight", cutWeight, allsamples.collection[isample].events);
|
315 |
|
316 |
float wgt=1.0;
|
317 |
for (Int_t entry = 0 ; entry < allsamples.collection[isample].events->GetEntries() ; entry++) {
|
318 |
allsamples.collection[isample].events->LoadTree(entry);
|
319 |
if (select->EvalInstance()) {
|
320 |
allsamples.collection[isample].events->GetEntry(entry);
|
321 |
mll=tmll;
|
322 |
id1=tid1;
|
323 |
id2=tid2;
|
324 |
wgt=Weight->EvalInstance();
|
325 |
edgeWeight=wgt*xsweight;
|
326 |
newTree->Fill();
|
327 |
}
|
328 |
}
|
329 |
|
330 |
if(EdgeFitter::MarcoDebug) dout << " Reduced tree contains " << newTree->GetEntries() << " entries " << endl;
|
331 |
return newTree;
|
332 |
}
|
333 |
|
334 |
void EdgeFitter::InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut) {
|
335 |
mllmin=_mllmin;
|
336 |
mllmax=_mllmax;
|
337 |
jzbmax=_jzbmax;
|
338 |
cut=_cut;
|
339 |
}
|
340 |
|
341 |
TTree* MergeTrees(vector<TTree*> trees) {
|
342 |
assert(trees.size()>0);
|
343 |
TTree * newtree = (TTree*)trees[0]->CloneTree(0);
|
344 |
newtree->SetTitle("FullTree");
|
345 |
newtree->SetName("FullTree");
|
346 |
trees[0]->GetListOfClones()->Remove(newtree);
|
347 |
trees[0]->ResetBranchAddresses();
|
348 |
newtree->ResetBranchAddresses();
|
349 |
|
350 |
for(int itree=0;itree<trees.size();itree++) {
|
351 |
newtree->CopyAddresses(trees[itree]);
|
352 |
Long64_t nentries = trees[itree]->GetEntries();
|
353 |
for (Long64_t iEntry=0;iEntry<nentries;iEntry++) {
|
354 |
trees[itree]->GetEntry(iEntry);
|
355 |
newtree->Fill();
|
356 |
}
|
357 |
trees[itree]->ResetBranchAddresses(); // Disconnect from new tree
|
358 |
if (newtree->GetTreeIndex()) {
|
359 |
newtree->GetTreeIndex()->Append(trees[itree]->GetTreeIndex(),kTRUE);
|
360 |
}
|
361 |
if (newtree && newtree->GetTreeIndex()) {
|
362 |
newtree->GetTreeIndex()->Append(0,kFALSE); // Force the sorting
|
363 |
}
|
364 |
}
|
365 |
return newtree;
|
366 |
}
|
367 |
|
368 |
|
369 |
|
370 |
void EdgeFitter::PrepareDatasets(int is_data) {
|
371 |
ensure_directory_exists(PlottingSetup::cbafbasedir+"/EdgeCache/");
|
372 |
|
373 |
stringstream FileName;
|
374 |
FileName << PlottingSetup::cbafbasedir << "/EdgeCache/" << md5((const char*)cut) << ".root";
|
375 |
|
376 |
|
377 |
TFile *fEdgeCache;
|
378 |
if(PlottingSetup::do_CleanCache) fEdgeCache = new TFile(FileName.str().c_str(),"RECREATE");
|
379 |
else fEdgeCache = new TFile(FileName.str().c_str(),"UPDATE");
|
380 |
|
381 |
if(fEdgeCache->GetNkeys()==0) {
|
382 |
ofstream CacheOverview;
|
383 |
CacheOverview.open((PlottingSetup::cbafbasedir+"/EdgeCache/CacheOverview").c_str(),ios::app);
|
384 |
CacheOverview << md5((const char*)cut) << ";" << (const char*) cut << endl;
|
385 |
CacheOverview.close();
|
386 |
}
|
387 |
|
388 |
vector<TTree*> SkimmedTrees;
|
389 |
TTree *SkimmedTree[(int)allsamples.collection.size()];
|
390 |
for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
|
391 |
if(!allsamples.collection[isample].is_active) continue;
|
392 |
if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
|
393 |
if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
|
394 |
if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC
|
395 |
if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it.
|
396 |
if(EdgeFitter::MarcoDebug) dout << "Considering : " << allsamples.collection[isample].samplename << endl;
|
397 |
|
398 |
string SkimName = GetSkimName(isample);
|
399 |
SkimmedTree[isample] = (TTree*)fEdgeCache->Get(SkimName.c_str());
|
400 |
if(!SkimmedTree[isample]) {
|
401 |
dout << "Need to generate tree for " << allsamples.collection[isample].filename << endl;
|
402 |
SkimmedTree[isample] = SkimTree(isample);
|
403 |
fEdgeCache->cd();
|
404 |
SkimmedTree[isample]->Write();
|
405 |
} else {
|
406 |
dout << "Loaded tree for " << allsamples.collection[isample].filename << " from cache file " << endl;
|
407 |
}
|
408 |
|
409 |
SkimmedTrees.push_back(SkimmedTree[isample]);
|
410 |
}
|
411 |
|
412 |
TTree *completetree = MergeTrees(SkimmedTrees);
|
413 |
|
414 |
if(EdgeFitter::MarcoDebug) dout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl;
|
415 |
|
416 |
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
|
417 |
RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
|
418 |
RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
|
419 |
RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
|
420 |
RooArgSet observables(mll,id1,id2,edgeWeight);
|
421 |
|
422 |
string title="CMS Data";
|
423 |
if(is_data!=1) title="CMS SIMULATION";
|
424 |
RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","edgeWeight");
|
425 |
fEdgeCache->Close();
|
426 |
dout << "Edge cache closed." << endl;
|
427 |
|
428 |
EdgeFitter::eeSample = (RooDataSet*)LAllData.reduce("id1==id2&&id1==0");
|
429 |
EdgeFitter::mmSample = (RooDataSet*)LAllData.reduce("id1==id2&&id1==1");
|
430 |
EdgeFitter::OFSample = (RooDataSet*)LAllData.reduce("id1!=id2");
|
431 |
EdgeFitter::SFSample = (RooDataSet*)LAllData.reduce("id1==id2");
|
432 |
EdgeFitter::AllData = (RooDataSet*)LAllData.reduce("id1!=id2||id1==id2");
|
433 |
|
434 |
|
435 |
eeSample->SetName("eeSample");
|
436 |
mmSample->SetName("mmSample");
|
437 |
OFSample->SetName("OFSample");
|
438 |
SFSample->SetName("SFSample");
|
439 |
AllData->SetName("AllData");
|
440 |
|
441 |
eeSample->SetTitle("eeSample");
|
442 |
mmSample->SetTitle("mmSample");
|
443 |
OFSample->SetTitle("OFSample");
|
444 |
SFSample->SetTitle("SFSample");
|
445 |
AllData->SetTitle("AllData");
|
446 |
|
447 |
if(EdgeFitter::MarcoDebug) {
|
448 |
dout << "Number of (weighted) events in full sample = " << AllData->sumEntries() << " (raw events : " << AllData->numEntries() << ")" << endl;
|
449 |
dout << "Number of (weighted) events in ee sample = " << eeSample->sumEntries() << " (raw events : " << eeSample->numEntries() << ")" << endl;
|
450 |
dout << "Number of (weighted) events in mm sample = " << mmSample->sumEntries() << " (raw events : " << mmSample->numEntries() << ")" << endl;
|
451 |
dout << "Number of (weighted) events in SF sample = " << SFSample->sumEntries() << " (raw events : " << SFSample->numEntries() << ")" << endl;
|
452 |
dout << "Number of (weighted) events in em sample = " << OFSample->sumEntries() << " (raw events : " << OFSample->numEntries() << ")" << endl;
|
453 |
}
|
454 |
|
455 |
}
|
456 |
|
457 |
void EdgeFitter::DrawDatasetContent(int is_data) {
|
458 |
TCanvas* ceedata = new TCanvas("ceedata","ceedata") ;
|
459 |
|
460 |
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
|
461 |
RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("ee sample")) ;
|
462 |
frame1->GetXaxis()->CenterTitle(1);
|
463 |
frame1->GetYaxis()->CenterTitle(1);
|
464 |
eeSample->plotOn(frame1,RooFit::Name("eedata"));
|
465 |
|
466 |
RooPlot* frame2 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("mm sample")) ;
|
467 |
frame2->GetXaxis()->CenterTitle(1);
|
468 |
frame2->GetYaxis()->CenterTitle(1);
|
469 |
mmSample->plotOn(frame2,RooFit::Name("mmdata"));
|
470 |
|
471 |
RooPlot* frame3 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ;
|
472 |
frame3->GetXaxis()->CenterTitle(1);
|
473 |
frame3->GetYaxis()->CenterTitle(1);
|
474 |
OFSample->plotOn(frame3,RooFit::Name("OFdata"));
|
475 |
|
476 |
TH1F *ee_ref = allsamples.Draw("ee_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1==id2&&id1==0"),is_data, luminosity);
|
477 |
TH1F *mm_ref = allsamples.Draw("mm_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1==id2&&id1==1"),is_data, luminosity);
|
478 |
TH1F *of_ref = allsamples.Draw("of_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1!=id2"),is_data, luminosity);
|
479 |
|
480 |
ee_ref->SetFillColor(TColor::GetColor("#3ADF00"));
|
481 |
mm_ref->SetFillColor(TColor::GetColor("#3ADF00"));
|
482 |
of_ref->SetFillColor(TColor::GetColor("#3ADF00"));
|
483 |
|
484 |
TH1F *ee_fit = (TH1F*)eeSample->createHistogram("ee_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true));
|
485 |
TH1F *mm_fit = (TH1F*)mmSample->createHistogram("mm_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true));
|
486 |
TH1F *of_fit = (TH1F*)OFSample->createHistogram("of_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true));
|
487 |
|
488 |
TLegend *leg = make_legend();
|
489 |
leg->AddEntry(ee_fit,"RooDataSet content","p");
|
490 |
leg->AddEntry(ee_ref,"CBAF cross-check","f");
|
491 |
leg->SetX1(0.5);
|
492 |
leg->SetY1(0.75);
|
493 |
|
494 |
ceedata->cd() ;
|
495 |
gPad->SetLeftMargin(0.15);
|
496 |
frame1->SetMaximum(1.2*frame1->GetMaximum());
|
497 |
frame1->GetYaxis()->SetTitleOffset(1.4);
|
498 |
frame1->Draw();
|
499 |
ee_ref->Draw("histo,same");
|
500 |
ee_fit->Draw("e1,same");
|
501 |
leg->Draw("same");
|
502 |
if(is_data==data) DrawPrelim();
|
503 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
504 |
CompleteSave(ceedata,"Edge/PreFit_ee");
|
505 |
|
506 |
ceedata->cd() ;
|
507 |
gPad->SetLeftMargin(0.15);
|
508 |
frame2->SetMaximum(1.2*frame2->GetMaximum());
|
509 |
frame2->GetYaxis()->SetTitleOffset(1.4);
|
510 |
frame2->Draw();
|
511 |
mm_ref->Draw("histo,same");
|
512 |
mm_fit->Draw("e1,same");
|
513 |
leg->Draw("same");
|
514 |
if(is_data==data) DrawPrelim();
|
515 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
516 |
CompleteSave(ceedata,"Edge/PreFit_mm");
|
517 |
|
518 |
TCanvas* cOFdata = new TCanvas("cOFdata","cOFdata") ;
|
519 |
cOFdata->cd() ;
|
520 |
gPad->SetLeftMargin(0.15);
|
521 |
frame3->SetMaximum(1.2*frame3->GetMaximum());
|
522 |
frame3->GetYaxis()->SetTitleOffset(1.4);
|
523 |
frame3->Draw();
|
524 |
of_ref->Draw("histo,same");
|
525 |
of_fit->Draw("e1,same");
|
526 |
leg->Draw("same");
|
527 |
if(is_data==data) DrawPrelim();
|
528 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
529 |
CompleteSave(cOFdata,"Edge/PreFit_OF");
|
530 |
|
531 |
delete ee_fit;
|
532 |
delete mm_fit;
|
533 |
delete of_fit;
|
534 |
|
535 |
delete ee_ref;
|
536 |
delete mm_ref;
|
537 |
delete of_ref;
|
538 |
}
|
539 |
|
540 |
string WriteWithError(float central, float error, int digits) {
|
541 |
float ref=central;
|
542 |
if(ref<0) ref=-central;
|
543 |
int HighestSigDigit = 0;
|
544 |
if(ref>1) HighestSigDigit = int(log(ref)/log(10))+1;
|
545 |
else HighestSigDigit = int(log(ref)/(log(10)));
|
546 |
|
547 |
float divider=pow(10.0,(double(HighestSigDigit-digits)));
|
548 |
|
549 |
stringstream result;
|
550 |
result << divider*int(central/divider+0.5) << " #pm " << divider*int(error/divider+0.5);
|
551 |
return result.str();
|
552 |
}
|
553 |
|
554 |
|
555 |
string EdgeFitter::RandomStorageFile() {
|
556 |
TRandom3 *r = new TRandom3(0);
|
557 |
int rho = (int)r->Uniform(1,10000000);
|
558 |
stringstream RandomFile;
|
559 |
RandomFile << PlottingSetup::cbafbasedir << "/exchange/TempEdgeFile_" << rho << ".root";
|
560 |
delete r;
|
561 |
return RandomFile.str();
|
562 |
}
|
563 |
|
564 |
Yield EdgeFitter::Get_Z_estimate(float jzb_cut, int icut) {
|
565 |
if(MarcoDebug) write_error(__FUNCTION__,"Returning random Z yield");
|
566 |
Yield a(123,45,67); return a;
|
567 |
return PlottingSetup::allresults.predictions[icut].Zbkg;
|
568 |
}
|
569 |
|
570 |
Yield EdgeFitter::Get_T_estimate(float jzb_cut, int icut) {
|
571 |
if(MarcoDebug) write_error(__FUNCTION__,"Returning random TTbar yield");
|
572 |
Yield a(1234,56,78); return a;
|
573 |
return PlottingSetup::allresults.predictions[icut].Flavorsym;
|
574 |
}
|
575 |
|
576 |
void EdgeFitter::DoFit(int is_data, float jzb_cut) {
|
577 |
|
578 |
stringstream prefix;
|
579 |
if(is_data==data) prefix << "data_";
|
580 |
if(is_data==mc) prefix << "mc_";
|
581 |
if(is_data==mcwithsignal) prefix << "mcwithS_";
|
582 |
|
583 |
prefix << EdgeFitter::Mode << "_" << jzb_cut;
|
584 |
|
585 |
if(!EdgeFitter::AllowTriangle && EdgeFitter::FixedMEdge>=0) prefix << "__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge);
|
586 |
|
587 |
if(EdgeFitter::AllowTriangle) prefix << "__H1";
|
588 |
else prefix << "__H0";
|
589 |
|
590 |
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
|
591 |
RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
|
592 |
RooCategory sample("sample","sample") ;
|
593 |
sample.defineType("ee");
|
594 |
sample.defineType("mm");
|
595 |
sample.defineType("OF");
|
596 |
sample.defineType("SF");
|
597 |
|
598 |
RooDataSet combData("combData","combined data",RooArgSet(mll,edgeWeight),RooFit::Index(sample),RooFit::Import("ee",*eeSample),RooFit::Import("mm",*mmSample),RooFit::Import("OF",*OFSample),RooFit::Import("SF",*SFSample),RooFit::WeightVar(edgeWeight));
|
599 |
|
600 |
//------------------------------------------------------------------------------------------------------------------------------------
|
601 |
// _____ _ __
|
602 |
// / ____| | /_ |
|
603 |
// | (___ | |_ ___ _ __ | |
|
604 |
// \___ \| __/ _ \ '_ \ | |
|
605 |
// ____) | || __/ |_) | | |
|
606 |
// |_____/ \__\___| .__/ |_|
|
607 |
// | |
|
608 |
// |_|
|
609 |
//
|
610 |
// Fit OF to get good initial values for flavor-symmetric background
|
611 |
|
612 |
|
613 |
|
614 |
//First we make a fit to opposite flavor
|
615 |
RooRealVar fttbarOF("fttbarOF", "fttbarOF", 0.8*OFSample->sumEntries(), 0, 1.2*OFSample->sumEntries());
|
616 |
|
617 |
RooRealVar par1ttbarOF("par1ttbarOF", "par1ttbarOF", 1.77, 0.01, 4.0);
|
618 |
RooRealVar par2ttbarOF("par2ttbarOF", "par2ttbarOF", 1.0);
|
619 |
RooRealVar par3ttbarOF("par3ttbarOF", "par3ttbarOF", 0.0272, 0.001, 1.0);
|
620 |
RooRealVar par4ttbarOF("par4ttbarOF", "par4ttbarOF", 2.0);
|
621 |
//RooSUSYBkgPdf ttbarOF("ttbarOF","ttbarOF", mll , par1ttbarOF, par2ttbarOF, par3ttbarOF, par4ttbarOF);
|
622 |
|
623 |
|
624 |
RooRealVar p0("p0","p0",2.97442e+02,0,500) ;
|
625 |
RooRealVar p1("p1","p1",-9.88858e+00,-11,11) ;
|
626 |
RooRealVar p2("p2","p2",7.88900e-01,-1,1) ;
|
627 |
RooRealVar p3("p3","p3",-1.39526e-02,-0.1,0.1) ;
|
628 |
RooRealVar p4("p4","p4",1.08647e-04,-0.001,0.001) ;
|
629 |
RooRealVar p5("p5","p5",-4.34647e-07,-1e-6,1e-6) ;
|
630 |
RooRealVar p6("p6","p6",8.78765e-10,-1e-8,1e-8) ;
|
631 |
RooRealVar p7("p7","p7",-7.13562e-13,-1e-11,1e-11) ;
|
632 |
|
633 |
RooSUSYPolynomial ttbarOF("ttbarOF","ttbarOF",mll,p0,p1,p2,p3,p4,p5,p6,p7);
|
634 |
|
635 |
RooAddPdf model_OF("model_OF","model_OF", ttbarOF, fttbarOF);
|
636 |
RooSimultaneous simPdfOF("simPdfOF","simultaneous pdf", sample) ;
|
637 |
simPdfOF.addPdf(model_OF,"OF");
|
638 |
RooFitResult *resultOF = simPdfOF.fitTo(combData, RooFit::Save(),RooFit::Extended(),RooFit::Minos(true));
|
639 |
dout << "============================= < OF results > =============================" << endl;
|
640 |
resultOF->Print();
|
641 |
dout << "============================= < /OF results > =============================" << endl;
|
642 |
|
643 |
|
644 |
RooPlot* frameO = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample"));
|
645 |
frameO->GetXaxis()->CenterTitle(1);
|
646 |
frameO->GetYaxis()->CenterTitle(1);
|
647 |
combData.plotOn(frameO,RooFit::Name("OFdata"),RooFit::Cut("sample==sample::OF")) ;
|
648 |
simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
|
649 |
simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("TTbarOFonly"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
|
650 |
|
651 |
TCanvas* pof = new TCanvas("pof","pof") ;
|
652 |
pof->cd() ;
|
653 |
gPad->SetLeftMargin(0.15);
|
654 |
frameO->GetYaxis()->SetTitleOffset(1.4);
|
655 |
frameO->Draw();
|
656 |
if(is_data==data) DrawPrelim();
|
657 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
658 |
CompleteSave(pof,"Edge/OF__OFFitonly_"+prefix.str(),false,false);
|
659 |
delete pof;
|
660 |
|
661 |
TCanvas* pof2 = new TCanvas("pof2","pof2") ;
|
662 |
pof2->cd();
|
663 |
gPad->SetLeftMargin(0.15);
|
664 |
frameO->GetYaxis()->SetTitleOffset(1.4);
|
665 |
frameO->Draw();
|
666 |
if(is_data==data) DrawPrelim();
|
667 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
668 |
stringstream OFFitParameterSummary;
|
669 |
OFFitParameterSummary << "#splitline{ftbbarOF = " << WriteWithError(fttbarOF.getVal(),fttbarOF.getError(),3) << "}{";
|
670 |
OFFitParameterSummary << "#splitline{par1ttbarOF = " << WriteWithError(par1ttbarOF.getVal(),par1ttbarOF.getError(),3) << "}{";
|
671 |
OFFitParameterSummary << "#splitline{par2ttbarOF = " << WriteWithError(par2ttbarOF.getVal(),par2ttbarOF.getError(),3) << "}{";
|
672 |
OFFitParameterSummary << "#splitline{par3ttbarOF = " << WriteWithError(par3ttbarOF.getVal(),par3ttbarOF.getError(),3) << "}{";
|
673 |
OFFitParameterSummary << "par4ttbarOF = " << WriteWithError(par4ttbarOF.getVal(),par4ttbarOF.getError(),3);
|
674 |
OFFitParameterSummary << "}}}}";
|
675 |
TLatex *OFFitinfobox = new TLatex(0.57,0.75,OFFitParameterSummary.str().c_str());
|
676 |
OFFitinfobox->SetNDC();
|
677 |
OFFitinfobox->SetTextSize(0.03);
|
678 |
OFFitinfobox->Draw();
|
679 |
|
680 |
|
681 |
CompleteSave(pof2,"Edge/OF__OFFitonly_"+prefix.str()+"__INFO",false,false);
|
682 |
|
683 |
delete pof2;
|
684 |
|
685 |
if(resultOF->covQual()!=3) {
|
686 |
write_error(__FUNCTION__,"OF fit did not converge!!! Cannot continue!");
|
687 |
dout << "covQual is " << resultOF->covQual() << endl;
|
688 |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=-1;
|
689 |
else EdgeFitter::FixedMEdgeChi2_H0=-1;
|
690 |
if(EdgeFitter::RejectPointIfNoConvergence) return;
|
691 |
} else {
|
692 |
write_info(__FUNCTION__,"OF fit converged");
|
693 |
}
|
694 |
|
695 |
|
696 |
// _____ _ ___
|
697 |
// / ____| | |__ \
|
698 |
// | (___ | |_ ___ _ __ ) |
|
699 |
// \___ \| __/ _ \ '_ \ / /
|
700 |
// ____) | || __/ |_) | / /_
|
701 |
// |_____/ \__\___| .__/ |____|
|
702 |
// | |
|
703 |
// |_|
|
704 |
//
|
705 |
// Set up all the models
|
706 |
|
707 |
|
708 |
// Step 2a: set up edge position (if fixed), and maximum Z yield
|
709 |
float StartingMedge=70;
|
710 |
if(EdgeFitter::FixedMEdge>0) StartingMedge=EdgeFitter::FixedMEdge;
|
711 |
|
712 |
RooDataSet *ZDataSet = (RooDataSet*)EdgeFitter::AllData->reduce("id1==id2 && abs(mll-91.2)<20");
|
713 |
|
714 |
float maxZ = ZDataSet->sumEntries();
|
715 |
dout << "maxZ was set to " << maxZ << endl;
|
716 |
delete ZDataSet;
|
717 |
|
718 |
RooRealVar JustOne("JustOne","Just One",1) ;
|
719 |
|
720 |
|
721 |
// Step 2b: set up the models!
|
722 |
RooRealVar eefrac("eefrac","eefrac",eeSample->sumEntries()/(eeSample->sumEntries()+mmSample->sumEntries()));
|
723 |
RooFormulaVar mmfrac("mmfrac","1-eefrac",RooArgSet(eefrac));
|
724 |
|
725 |
RooRealVar rOneOverEMFrac("rOneOverEMFrac","rOneOverEMFrac",1.02,1.02-0.07,1.02+0.07);
|
726 |
RooRealVar rmean("rmean","rmean",1.02);
|
727 |
RooRealVar rwidth("rwidth","rwidth",0.07);
|
728 |
RooGaussian OneOverEMFrac("OneOverEMFrac","OneOverEMFrac",rOneOverEMFrac,rmean,rwidth);
|
729 |
|
730 |
|
731 |
// FIRST: Drell-Yan: different parameters for resolution of DY (and of course yield), but same mean and so on
|
732 |
RooRealVar widthz("widthz", "widthz", 2.94);
|
733 |
widthz.setConstant(1);
|
734 |
RooRealVar meanz("meanz", "meanz", 91.1876, 89, 93);
|
735 |
RooRealVar fzSF("fzSF","fzSF",39,0,maxZ);
|
736 |
RooFormulaVar fzee("fzee","eefrac*fzSF",RooArgSet(eefrac,fzSF));
|
737 |
RooFormulaVar fzmm("fzmm","mmfrac*fzSF",RooArgSet(mmfrac,fzSF));
|
738 |
RooRealVar sigmazee("sigmazee", "sigmazee", 5, 0.5, 5);
|
739 |
RooRealVar sigmazmm("sigmazmm", "sigmazmm", 5, 0.5, 5);
|
740 |
|
741 |
RooVoigtian zee("zee", "zee", mll, meanz, widthz, sigmazee);
|
742 |
RooVoigtian zmm("zmm", "zmm", mll, meanz, widthz, sigmazmm);
|
743 |
|
744 |
|
745 |
|
746 |
//SECOND: Flavor-Symmetry contribution. Only relative fraction is different, all other parameters are the same;
|
747 |
RooFormulaVar fttbaree("fttbaree","eefrac*fttbarOF*OneOverEMFrac",RooArgSet(eefrac,fttbarOF,OneOverEMFrac));
|
748 |
RooFormulaVar fttbarmm("fttbarmm","mmfrac*fttbarOF*OneOverEMFrac",RooArgSet(mmfrac,fttbarOF,OneOverEMFrac));
|
749 |
|
750 |
/*RooSUSYBkgPdf ttbaree("ttbaree","ttbaree", mll , par1ttbarOF, par2ttbarOF, par3ttbarOF, par4ttbarOF);
|
751 |
RooSUSYBkgPdf ttbarmm("ttbarmm","ttbarmm", mll , par1ttbarOF, par2ttbarOF, par3ttbarOF, par4ttbarOF);*/
|
752 |
|
753 |
// RooChebychev ttbaree("ttbaree","ttbaree",mll,RooArgList(p0,p1,p2,p3,p4,p5,p6,p7)) ;
|
754 |
// RooChebychev ttbarmm("ttbarmm","ttbarmm",mll,RooArgList(p0,p1,p2,p3,p4,p5,p6,p7)) ;
|
755 |
// RooChebychev ttbaree("ttbaree","ttbaree",mll,RooArgList(p0,p1,p2,p3)) ;
|
756 |
// RooChebychev ttbarmm("ttbarmm","ttbarmm",mll,RooArgList(p0,p1,p2,p3)) ;
|
757 |
|
758 |
RooSUSYPolynomial ttbaree("ttbaree","ttbaree",mll,p0,p1,p2,p3,p4,p5,p6,p7);
|
759 |
RooSUSYPolynomial ttbarmm("ttbarmm","ttbarmm",mll,p0,p1,p2,p3,p4,p5,p6,p7);
|
760 |
|
761 |
|
762 |
//for signal only the resolution and absolute fraction are different for ee / mm
|
763 |
RooRealVar fsignal("fsignal", "fsignal", 0, 0, (eeSample->sumEntries()+mmSample->sumEntries()-OFSample->sumEntries()));
|
764 |
RooFormulaVar fsignalee("fsignalee","eefrac*fsignal",RooArgSet(eefrac,fsignal));
|
765 |
RooFormulaVar fsignalmm("fsignalmm","mmfrac*fsignal",RooArgSet(mmfrac,fsignal));
|
766 |
|
767 |
RooRealVar par1signal("par1signal", "par1signal", 45, 20, 100);
|
768 |
par1signal.setConstant(1); // doesn't have any effect.
|
769 |
RooRealVar par3signal("par3signal", "par3signal", StartingMedge, 0, 300); // this is the edge position
|
770 |
if(EdgeFitter::FixedMEdge>0) par3signal.setConstant();
|
771 |
|
772 |
RooSUSYTPdf signalee("signalee","signalee", mll , par1signal, sigmazee, par3signal);
|
773 |
RooSUSYTPdf signalmm("signalmm","signalmm", mll , par1signal, sigmazmm, par3signal);
|
774 |
RooAddPdf signalSF("signalSF","signalSF",RooArgList(signalee,signalmm),RooArgList(fsignalee,fsignalmm));
|
775 |
|
776 |
if(!EdgeFitter::AllowTriangle) {
|
777 |
fsignal.setVal(0.0); // kill off the signal if we don't want the triangle
|
778 |
fsignal.setConstant(1);
|
779 |
par1signal.setConstant(1);
|
780 |
par3signal.setConstant(1);
|
781 |
}
|
782 |
|
783 |
|
784 |
|
785 |
//COMPLETE MODEL:
|
786 |
RooAddPdf model_ee("model_ee","model_ee", RooArgList(zee, ttbaree, signalee), RooArgList(fzee, fttbaree, fsignalee));
|
787 |
RooAddPdf model_mm("model_mm","model_mm", RooArgList(zmm, ttbarmm, signalmm), RooArgList(fzmm, fttbarmm, fsignalmm));
|
788 |
RooAddPdf model_SF("model_SF","model_SF",RooArgList(model_ee,model_mm),RooArgList(JustOne,JustOne));
|
789 |
|
790 |
|
791 |
// _____ _ ____
|
792 |
// / ____| | |___ \
|
793 |
// | (___ | |_ ___ _ __ __) |
|
794 |
// \___ \| __/ _ \ '_ \ |__ <
|
795 |
// ____) | || __/ |_) | ___) |
|
796 |
// |_____/ \__\___| .__/ |____/
|
797 |
// | |
|
798 |
// |_|
|
799 |
//
|
800 |
// Fitting
|
801 |
|
802 |
RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ;
|
803 |
simPdf.addPdf(model_ee,"ee") ;
|
804 |
simPdf.addPdf(model_mm,"mm") ;
|
805 |
simPdf.addPdf(model_OF,"OF") ;
|
806 |
|
807 |
//RooFitResult *result = simPdf.fitTo(combData, RooFit::Save(), RooFit::Extended(),RooFit::Minos(true),RooFit::ExternalConstraints(OneOverEMFrac));
|
808 |
RooFitResult *result = simPdf.fitTo(combData, RooFit::Save(), RooFit::Extended(),RooFit::Minos(true));
|
809 |
|
810 |
if(result->covQual()!=3) {
|
811 |
write_error(__FUNCTION__,"Full fit did not converge!!! Cannot continue!");
|
812 |
dout << "covQual is " << result->covQual() << endl;
|
813 |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=-1;
|
814 |
else EdgeFitter::FixedMEdgeChi2_H0=-1;
|
815 |
if(EdgeFitter::RejectPointIfNoConvergence) return;
|
816 |
} else {
|
817 |
write_info(__FUNCTION__,"Full fit converged");
|
818 |
}
|
819 |
|
820 |
dout << "============================= < Full results > =============================" << endl;
|
821 |
result->Print();
|
822 |
dout << "============================= < /Full results > =============================" << endl;
|
823 |
|
824 |
// _____ _ _ _
|
825 |
// / ____| | | || |
|
826 |
// | (___ | |_ ___ _ __ | || |_
|
827 |
// \___ \| __/ _ \ '_ \ |__ _|
|
828 |
// ____) | || __/ |_) | | |
|
829 |
// |_____/ \__\___| .__/ |_|
|
830 |
// | |
|
831 |
// |_|
|
832 |
//
|
833 |
// Present results
|
834 |
|
835 |
RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("EE sample")) ;
|
836 |
frame1->GetXaxis()->CenterTitle(1);
|
837 |
frame1->GetYaxis()->CenterTitle(1);
|
838 |
combData.plotOn(frame1,RooFit::Name("eedata"),RooFit::Cut("sample==sample::ee")) ;
|
839 |
simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Name("FullFitEE"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
|
840 |
simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Name("TTbarEEonly"),RooFit::Components("ttbaree"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
|
841 |
simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Name("DYEEonly"),RooFit::Components("zee"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
|
842 |
if(EdgeFitter::AllowTriangle) simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Name("SignalEEonly"),RooFit::Components("signalee"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
|
843 |
|
844 |
|
845 |
RooPlot* frame2 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("mm sample")) ;
|
846 |
frame2->GetXaxis()->CenterTitle(1);
|
847 |
frame2->GetYaxis()->CenterTitle(1);
|
848 |
combData.plotOn(frame2,RooFit::Name("mmdata"),RooFit::Cut("sample==sample::mm")) ;
|
849 |
simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Name("FullFitMM"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
|
850 |
simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Name("TTbarMMonly"),RooFit::Components("ttbarmm"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
|
851 |
simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Name("DYMMonly"),RooFit::Components("zmm"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
|
852 |
if(EdgeFitter::AllowTriangle) simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Name("SignalMMonly"),RooFit::Components("signalmm"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
|
853 |
|
854 |
|
855 |
RooPlot* frame3 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ;
|
856 |
frame3->GetXaxis()->CenterTitle(1);
|
857 |
frame3->GetYaxis()->CenterTitle(1);
|
858 |
combData.plotOn(frame3,RooFit::Name("OFdata"),RooFit::Cut("sample==sample::OF")) ;
|
859 |
simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Name("FullFitOF"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
|
860 |
simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Name("TTbarOFonly"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
|
861 |
simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Name("DYOFonly"),RooFit::Components("zOF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
|
862 |
|
863 |
RooAbsPdf *ee_result = simPdf.getPdf("ee");
|
864 |
RooAbsPdf *mm_result = simPdf.getPdf("mm");
|
865 |
RooAddPdf SF_result("SF_result","SF_result",RooArgList(*ee_result,*mm_result));
|
866 |
|
867 |
|
868 |
TCanvas* g = new TCanvas("g","g") ;
|
869 |
|
870 |
RooPlot* frame4 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("SF sample")) ;
|
871 |
frame4->GetXaxis()->CenterTitle(1);
|
872 |
frame4->GetYaxis()->CenterTitle(1);
|
873 |
EdgeFitter::SFSample->plotOn(frame4,RooFit::Name("SFdata")) ;
|
874 |
SF_result.plotOn(frame4,RooFit::Name("FullFitSF"),RooFit::ProjWData(*EdgeFitter::SFSample),RooFit::LineColor(kBlack));
|
875 |
SF_result.plotOn(frame4,RooFit::Name("TTbarSFonly"),RooFit::ProjWData(*EdgeFitter::SFSample),RooFit::Components("ttbaree,ttbarmm"),RooFit::LineColor(kBlue),RooFit::LineStyle(kDashed));
|
876 |
SF_result.plotOn(frame4,RooFit::Name("DYSFonly"),RooFit::ProjWData(*EdgeFitter::SFSample),RooFit::Components("zmm,zee"), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
|
877 |
if(EdgeFitter::AllowTriangle) SF_result.plotOn(frame4,RooFit::Name("SignalSFonly"),RooFit::Components("signalee,signalmm"), RooFit::ProjWData(*EdgeFitter::SFSample), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
|
878 |
|
879 |
/// ********************************************************************************************************************************
|
880 |
TCanvas* c = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf") ;
|
881 |
c->cd() ;
|
882 |
gPad->SetLeftMargin(0.15);
|
883 |
frame1->GetYaxis()->SetTitleOffset(1.4);
|
884 |
frame1->Draw();
|
885 |
if(is_data==data) DrawPrelim();
|
886 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
887 |
CompleteSave(c,"Edge/"+prefix.str()+"_ee",false,false);
|
888 |
stringstream eeFitParameterSummary;
|
889 |
eeFitParameterSummary << "#splitline{t#bar{t} : " << WriteWithError((OneOverEMFrac.getVal()*fttbarOF.getVal()*eefrac.getVal()),(OneOverEMFrac.getVal()*fttbarOF.getVal()*eefrac.getVal())*sqrt(pow(fttbarOF.getError()/fttbarOF.getVal(),2)+pow(eefrac.getError()/eefrac.getVal(),2)),3) << "}{";//no taking uncertainty on R(SF/OF) into consideration!
|
890 |
eeFitParameterSummary << "#splitline{DY : " << WriteWithError((fzSF.getVal()*eefrac.getVal()),(fzSF.getVal()*eefrac.getVal())*sqrt(pow(fzSF.getError()/fzSF.getVal(),2)+pow(eefrac.getError()/eefrac.getVal(),2)),3) << "}{";
|
891 |
eeFitParameterSummary << "#splitline{signal : " << WriteWithError((fsignal.getVal()*eefrac.getVal()),(fsignal.getVal()*eefrac.getVal())*sqrt(pow(fsignal.getError()/fsignal.getVal(),2)+pow(eefrac.getError()/eefrac.getVal(),2)),3) << "}{";
|
892 |
eeFitParameterSummary << "}}}";
|
893 |
TLatex *eeFitinfobox = new TLatex(0.57,0.75,eeFitParameterSummary.str().c_str());
|
894 |
eeFitinfobox->SetNDC();
|
895 |
eeFitinfobox->SetTextSize(0.03);
|
896 |
eeFitinfobox->Draw();
|
897 |
CompleteSave(c,"Edge/"+prefix.str()+"_ee__INFO",false,false);
|
898 |
|
899 |
c->cd() ;
|
900 |
gPad->SetLeftMargin(0.15);
|
901 |
frame2->GetYaxis()->SetTitleOffset(1.4);
|
902 |
frame2->Draw();
|
903 |
if(is_data==data) DrawPrelim();
|
904 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
905 |
CompleteSave(c,"Edge/"+prefix.str()+"_mm",false,false);
|
906 |
stringstream mmFitParameterSummary;
|
907 |
mmFitParameterSummary << "#splitline{t#bar{t} : " << WriteWithError((OneOverEMFrac.getVal()*fttbarOF.getVal()*(1-eefrac.getVal())),(OneOverEMFrac.getVal()*fttbarOF.getVal()*(1-eefrac.getVal()))*sqrt(pow(fttbarOF.getError()/fttbarOF.getVal(),2)+pow(eefrac.getError()/(1-eefrac.getVal()),2)),3) << "}{";//no taking uncertainty on R(SF/OF) into consideration!
|
908 |
mmFitParameterSummary << "#splitline{DY : " << WriteWithError((fzSF.getVal()*(1-eefrac.getVal())),(fzSF.getVal()*(1-eefrac.getVal()))*sqrt(pow(fzSF.getError()/fzSF.getVal(),2)+pow(eefrac.getError()/(1-eefrac.getVal()),2)),3) << "}{";
|
909 |
mmFitParameterSummary << "#splitline{signal : " << WriteWithError((fsignal.getVal()*(1-eefrac.getVal())),(fsignal.getVal()*(1-eefrac.getVal()))*sqrt(pow(fsignal.getError()/fsignal.getVal(),2)+pow(eefrac.getError()/(1-eefrac.getVal()),2)),3) << "}{";
|
910 |
mmFitParameterSummary << "}}}";
|
911 |
TLatex *mmFitinfobox = new TLatex(0.57,0.75,mmFitParameterSummary.str().c_str());
|
912 |
mmFitinfobox->SetNDC();
|
913 |
mmFitinfobox->SetTextSize(0.03);
|
914 |
mmFitinfobox->Draw();
|
915 |
CompleteSave(c,"Edge/"+prefix.str()+"_mm__INFO",false,false);
|
916 |
|
917 |
c->cd() ;
|
918 |
gPad->SetLeftMargin(0.15);
|
919 |
frame3->GetYaxis()->SetTitleOffset(1.4);
|
920 |
frame3->Draw();
|
921 |
if(is_data==data) DrawPrelim();
|
922 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
923 |
CompleteSave(c,"Edge/"+prefix.str()+"_OF",false,false);
|
924 |
|
925 |
c->cd() ;
|
926 |
gPad->SetLeftMargin(0.15);
|
927 |
frame4->GetYaxis()->SetTitleOffset(1.4);
|
928 |
frame4->Draw();
|
929 |
if(is_data==data) DrawPrelim();
|
930 |
else DrawPrelim(PlottingSetup::luminosity,true);
|
931 |
CompleteSave(c,"Edge/"+prefix.str()+"_SF",false,false);
|
932 |
stringstream SFFitParameterSummary;
|
933 |
SFFitParameterSummary << "#splitline{t#bar{t} : " << WriteWithError((OneOverEMFrac.getVal()*fttbarOF.getVal()),(OneOverEMFrac.getVal()*fttbarOF.getVal())*sqrt(pow(fttbarOF.getError()/fttbarOF.getVal(),2)),3) << "}{";//no taking uncertainty on R(SF/OF) into consideration!
|
934 |
SFFitParameterSummary << "#splitline{DY : " << WriteWithError((fzSF.getVal()),(fzSF.getVal())*sqrt(pow(fzSF.getError()/fzSF.getVal(),2)),3) << "}{";
|
935 |
SFFitParameterSummary << "#splitline{signal : " << WriteWithError(fsignal.getVal(),(fsignal.getVal())*sqrt(pow(fsignal.getError()/fsignal.getVal(),2)),3) << "}{";
|
936 |
SFFitParameterSummary << "}}}";
|
937 |
TLatex *SFFitinfobox = new TLatex(0.57,0.75,SFFitParameterSummary.str().c_str());
|
938 |
SFFitinfobox->SetNDC();
|
939 |
SFFitinfobox->SetTextSize(0.03);
|
940 |
SFFitinfobox->Draw();
|
941 |
CompleteSave(c,"Edge/"+prefix.str()+"_SF__INFO",false,false);
|
942 |
|
943 |
delete c;
|
944 |
/// ********************************************************************************************************************************
|
945 |
|
946 |
if(result->covQual()==3) {
|
947 |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=frame4->chiSquare("FullFitSF", "SFdata", 3);
|
948 |
else EdgeFitter::FixedMEdgeChi2_H0=frame4->chiSquare("FullFitSF", "SFdata", 3);
|
949 |
}
|
950 |
|
951 |
}
|
952 |
|
953 |
void EdgeFitter::DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree *signalevents=0) {
|
954 |
|
955 |
TCut _cut(cut&&PlottingSetup::basiccut&&PlottingSetup::passtrig);
|
956 |
|
957 |
TFile *f = new TFile("workingfile.root","RECREATE");
|
958 |
|
959 |
EdgeFitter::InitializeVariables(PlottingSetup::iMllLow,PlottingSetup::iMllHigh,PlottingSetup::jzbHigh,_cut);
|
960 |
|
961 |
EdgeFitter::PrepareDatasets(is_data);
|
962 |
|
963 |
EdgeFitter::DrawDatasetContent(is_data);
|
964 |
|
965 |
RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
|
966 |
RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
|
967 |
|
968 |
|
969 |
EdgeFitter::AllowTriangle=false;
|
970 |
EdgeFitter::DoFit(is_data, jzb_cut);
|
971 |
|
972 |
EdgeFitter::AllowTriangle=true;
|
973 |
|
974 |
bool ScanMassRange=false;
|
975 |
float ScanSteps=5.0;//GeV
|
976 |
|
977 |
|
978 |
if(ScanMassRange) {
|
979 |
TFile *fscan = new TFile("fscan.root","UPDATE");
|
980 |
TGraph *gr = new TGraph();
|
981 |
TGraph *Rgr = new TGraph();
|
982 |
stringstream GrName;
|
983 |
GrName << "ScanGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut;
|
984 |
stringstream RGrName;
|
985 |
RGrName << "ScanRatioGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut;
|
986 |
gr->SetName(GrName.str().c_str());
|
987 |
Rgr->SetName(RGrName.str().c_str());
|
988 |
|
989 |
int i=0;
|
990 |
for(float tempMedge=10;tempMedge<=300;tempMedge+=ScanSteps) {
|
991 |
write_info(__FUNCTION__,"Now testing Medge="+any2string(tempMedge)+" for "+EdgeFitter::Mode+">"+any2string(jzb_cut));
|
992 |
EdgeFitter::FixedMEdge=tempMedge;
|
993 |
EdgeFitter::DoFit(is_data, jzb_cut);
|
994 |
if(EdgeFitter::FixedMEdgeChi2_H1<0) continue;
|
995 |
gr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2_H1);
|
996 |
Rgr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2_H1/EdgeFitter::FixedMEdgeChi2_H0);
|
997 |
i++;
|
998 |
}
|
999 |
|
1000 |
TCanvas *ScanCan = new TCanvas("ScanCan","ScanCan",500,500);
|
1001 |
gr->GetXaxis()->SetTitle("m_{edge}");
|
1002 |
gr->GetXaxis()->CenterTitle();
|
1003 |
gr->GetYaxis()->SetTitle("#chi^{2}");
|
1004 |
gr->GetYaxis()->CenterTitle();
|
1005 |
gr->GetYaxis()->SetTitleOffset(0.95);
|
1006 |
gr->GetXaxis()->SetTitleOffset(0.9);
|
1007 |
gr->SetLineColor(kBlue);
|
1008 |
gr->SetTitle("");
|
1009 |
gr->Draw("AL");
|
1010 |
stringstream ScanCanSave;
|
1011 |
ScanCanSave << "Edge/MEdgeScan_"+EdgeFitter::Mode+"_" << jzb_cut;
|
1012 |
if(is_data) DrawPrelim();
|
1013 |
else DrawMCPrelim();
|
1014 |
CompleteSave(ScanCan,ScanCanSave.str());
|
1015 |
|
1016 |
Rgr->GetXaxis()->SetTitle("m_{edge}");
|
1017 |
Rgr->GetXaxis()->CenterTitle();
|
1018 |
Rgr->GetYaxis()->SetTitle("#frac{#chi^{2}(H_{1})}{#chi^{2}(H_{0})}");
|
1019 |
Rgr->GetYaxis()->CenterTitle();
|
1020 |
Rgr->GetYaxis()->SetTitleOffset(0.95);
|
1021 |
Rgr->GetXaxis()->SetTitleOffset(0.9);
|
1022 |
Rgr->SetLineColor(kBlue);
|
1023 |
Rgr->SetTitle("");
|
1024 |
Rgr->Draw("AL");
|
1025 |
ScanCanSave.str("");
|
1026 |
ScanCanSave << "Edge/MEdgeScan_Ratio_"+EdgeFitter::Mode+"_" << jzb_cut;
|
1027 |
if(is_data) DrawPrelim();
|
1028 |
else DrawMCPrelim();
|
1029 |
CompleteSave(ScanCan,ScanCanSave.str());
|
1030 |
fscan->cd();
|
1031 |
gr->Write();
|
1032 |
delete ScanCan;
|
1033 |
fscan->Close();
|
1034 |
} else {
|
1035 |
EdgeFitter::DoFit(is_data, jzb_cut);
|
1036 |
dout << "Chi^2 (H0) = " << EdgeFitter::FixedMEdgeChi2_H0 << endl;
|
1037 |
dout << "Chi^2 (H1) = " << EdgeFitter::FixedMEdgeChi2_H1 << endl;
|
1038 |
}
|
1039 |
|
1040 |
|
1041 |
RooMsgService::instance().setGlobalKillBelow(msglevel);
|
1042 |
|
1043 |
f->Close();
|
1044 |
|
1045 |
}
|
1046 |
|
1047 |
void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree *signalevents=0) {
|
1048 |
|
1049 |
EdgeFitter::Mode="JZB";
|
1050 |
if(mcjzb=="met[4]") EdgeFitter::Mode="MET";
|
1051 |
|
1052 |
for(int icut=0;icut<(int)jzb_cut.size();icut++) {
|
1053 |
stringstream addcut;
|
1054 |
if(is_data==1) addcut << "(" << datajzb << ">" << jzb_cut[icut] << ")";
|
1055 |
if(is_data!=1) addcut << "(" << mcjzb << ">" << jzb_cut[icut] << ")";
|
1056 |
TCut jcut(addcut.str().c_str());
|
1057 |
|
1058 |
|
1059 |
EdgeFitter::DoEdgeFit(mcjzb, datajzb, DataPeakError, MCPeakError, jzb_cut[icut], icut, is_data, jcut&&cut, signalevents);
|
1060 |
|
1061 |
}
|
1062 |
}
|