1 |
|
#include <iostream> |
2 |
|
|
3 |
+ |
|
4 |
+ |
|
5 |
|
#include <TVirtualIndex.h> |
6 |
|
|
7 |
|
#include <RooRealVar.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> |
60 |
|
void getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp); |
61 |
|
void InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut); |
62 |
|
void PrepareDatasets(int); |
63 |
+ |
void DrawDatasetContent(int); |
64 |
|
void DoFit(int is_data, float jzb_cut); |
65 |
|
string RandomStorageFile(); |
66 |
|
Yield Get_Z_estimate(float,int); |
82 |
|
bool MarcoDebug=true; |
83 |
|
|
84 |
|
float FixedMEdge=-1; |
85 |
< |
float FixedMEdgeChi2=-1; |
85 |
> |
float FixedMEdgeChi2_H1=-1; |
86 |
> |
float FixedMEdgeChi2_H0=-1; |
87 |
|
|
88 |
|
bool RejectPointIfNoConvergence=false; |
89 |
|
|
90 |
|
string Mode="UndefinedMode"; |
91 |
|
|
92 |
+ |
bool AllowTriangle=true; |
93 |
+ |
} |
94 |
+ |
|
95 |
+ |
TLatex* WriteAppleStudel() { |
96 |
+ |
string sel="Apple Strudel Preliminary"; |
97 |
+ |
TLatex *sele = new TLatex(0.97,0.135,sel.c_str()); |
98 |
+ |
sele->SetNDC(true); |
99 |
+ |
sele->SetTextColor(TColor::GetColor("#848484")); |
100 |
+ |
sele->SetTextFont(42); |
101 |
+ |
sele->SetTextAlign(32); |
102 |
+ |
sele->SetTextSize(0.03); |
103 |
+ |
sele->SetTextAngle(270); |
104 |
+ |
return sele; |
105 |
|
} |
106 |
|
|
107 |
|
TGraph* EdgeFitter::prepareLM(float mass, float nEv) { |
173 |
|
sigmaDown = abs(yQ[1]-median); |
174 |
|
sigmaUp = abs(yQ[2]-median); |
175 |
|
twoSigmaUp = abs(yQ[3]-median); |
176 |
< |
cout << median * PlottingSetup::luminosity << " " << sigmaUp * PlottingSetup::luminosity << endl; |
176 |
> |
dout << median * PlottingSetup::luminosity << " " << sigmaUp * PlottingSetup::luminosity << endl; |
177 |
|
} |
178 |
|
|
179 |
|
void EdgeFitter::prepareLimits(RooWorkspace *ws, bool ComputeBands) { |
213 |
|
|
214 |
|
for(int i=0;i<(int)theLimits.size();i++) { |
215 |
|
if((theLimits[i]<2.0/PlottingSetup::luminosity)||(theLimits[i]>40.0/PlottingSetup::luminosity)) { |
216 |
< |
cout << i << " : " << theVals[i] << endl; |
216 |
> |
dout << i << " : " << theVals[i] << endl; |
217 |
|
theLimits[i] = (theLimits[i+2]+theLimits[i-2])/2.0; |
218 |
|
write_warning(__FUNCTION__,"Need to store limits"); |
219 |
|
} |
277 |
|
RooStats::HypoTestInverterResult* hcInt = hcInv.GetInterval(); |
278 |
|
float ulError = hcInt->UpperLimitEstimatedError(); |
279 |
|
theLimit = hcInt->UpperLimit(); |
280 |
< |
cout << "Found upper limit : " << theLimit << "+/-" << ulError << endl; |
280 |
> |
dout << "Found upper limit : " << theLimit << "+/-" << ulError << endl; |
281 |
|
|
282 |
|
return theLimit/PlottingSetup::luminosity; |
283 |
|
|
284 |
|
} |
285 |
|
|
286 |
|
TTree* SkimTree(int isample) { |
287 |
< |
TTree* newTree = allsamples.collection[isample].events->CloneTree(0); |
287 |
> |
string TreeName = removefunnystring(allsamples.collection[isample].filename); |
288 |
> |
cout << "About to skim " << TreeName << " for sample id " << isample << endl; |
289 |
> |
TTree* newTree = new TTree("NanoTree",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 |
< |
cout << " Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl; |
304 |
< |
cout << " Going to reduce it with cut " << EdgeFitter::cut << endl; |
303 |
> |
dout << " Going to reduce it with cut " << EdgeFitter::cut << endl; |
304 |
> |
dout << " Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl; |
305 |
|
} |
306 |
< |
float edgeWeight; |
276 |
< |
newTree->Branch("edgeWeight",&edgeWeight,"edgeWeight/F"); |
306 |
> |
|
307 |
|
float tmll; |
308 |
+ |
int tid1,tid2; |
309 |
|
allsamples.collection[isample].events->SetBranchAddress("mll",&tmll); |
310 |
< |
// int id1,id2; |
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; |
284 |
– |
// allsamples.collection[isample].events->SetBranchAddress(cutWeight,&wgt); |
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) cout << " Reduced tree contains " << newTree->GetEntries() << " entries " << endl; |
330 |
> |
if(EdgeFitter::MarcoDebug) dout << " Reduced tree contains " << newTree->GetEntries() << " entries " << endl; |
331 |
|
return newTree; |
332 |
|
} |
333 |
|
|
339 |
|
} |
340 |
|
|
341 |
|
TTree* MergeTrees(vector<TTree*> trees) { |
342 |
< |
TTree * newtree = (TTree*)trees[0]->CloneTree(); |
342 |
> |
TTree * newtree = (TTree*)trees[0]->CloneTree(0); |
343 |
> |
newtree->SetTitle("FullTree"); |
344 |
> |
newtree->SetName("FullTree"); |
345 |
|
trees[0]->GetListOfClones()->Remove(newtree); |
346 |
|
trees[0]->ResetBranchAddresses(); |
347 |
|
newtree->ResetBranchAddresses(); |
348 |
|
|
349 |
< |
for(int itree=1;itree<trees.size();itree++) { |
349 |
> |
for(int itree=0;itree<trees.size();itree++) { |
350 |
|
newtree->CopyAddresses(trees[itree]); |
351 |
|
Long64_t nentries = trees[itree]->GetEntries(); |
352 |
|
for (Long64_t iEntry=0;iEntry<nentries;iEntry++) { |
368 |
|
|
369 |
|
void EdgeFitter::PrepareDatasets(int is_data) { |
370 |
|
write_warning(__FUNCTION__,"Need to make this function ready for scans as well (use signal from scan samples)"); |
371 |
< |
// TFile *tempout = new TFile("tempout.root","RECREATE"); |
371 |
> |
TFile *tempout = new TFile("tempout.root","RECREATE"); |
372 |
|
vector<TTree*> SkimmedTrees; |
373 |
|
TTree *SkimmedTree[(int)allsamples.collection.size()]; |
374 |
|
for(int isample=0;isample<(int)allsamples.collection.size();isample++) { |
377 |
|
if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data. |
378 |
|
if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC |
379 |
|
if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it. |
380 |
< |
if(EdgeFitter::MarcoDebug) cout << "Considering : " << allsamples.collection[isample].samplename << endl; |
381 |
< |
SkimmedTrees.push_back(SkimTree(isample)); |
382 |
< |
// SkimmedTree[isample] = SkimTree(isample); |
383 |
< |
// tempout->cd(); |
384 |
< |
// SkimmedTree[isample]->Write(); |
348 |
< |
// treelist->Add(SkimmedTree[isample]); |
349 |
< |
//treelist->Add(SkimTree(isample)); |
350 |
< |
// allsamples.collection[isample].tfile->Close(); |
380 |
> |
if(EdgeFitter::MarcoDebug) dout << "Considering : " << allsamples.collection[isample].samplename << endl; |
381 |
> |
SkimmedTree[isample] = SkimTree(isample); |
382 |
> |
tempout->cd(); |
383 |
> |
SkimmedTree[isample]->Write(); |
384 |
> |
SkimmedTrees.push_back(SkimmedTree[isample]); |
385 |
|
} |
386 |
|
|
387 |
|
TTree *completetree = MergeTrees(SkimmedTrees); |
388 |
|
|
389 |
< |
// for(int isample=0;isample<(int)allsamples.collection.size();isample++) { |
356 |
< |
// if(SkimmedTree[isample]) SkimmedTree[isample]->Delete(); |
357 |
< |
// } |
358 |
< |
|
359 |
< |
if(EdgeFitter::MarcoDebug) cout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl; |
389 |
> |
if(EdgeFitter::MarcoDebug) dout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl; |
390 |
|
|
391 |
|
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}"); |
392 |
|
RooRealVar id1("id1","id1",0,1,"GeV/c^{2}"); |
397 |
|
string title="CMS Data"; |
398 |
|
if(is_data!=1) title="CMS SIMULATION"; |
399 |
|
RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","edgeWeight"); |
400 |
+ |
tempout->cd(); |
401 |
|
completetree->Write(); |
402 |
< |
delete completetree; |
372 |
< |
// tempout->Close(); |
402 |
> |
tempout->Close(); |
403 |
|
|
404 |
|
EdgeFitter::SFSample = (RooDataSet*)LAllData.reduce("id1==id2"); |
405 |
|
EdgeFitter::OFSample = (RooDataSet*)LAllData.reduce("id1!=id2"); |
410 |
|
AllData->SetName("AllData"); |
411 |
|
|
412 |
|
if(EdgeFitter::MarcoDebug) { |
413 |
< |
cout << "Number of events in data sample = " << AllData->numEntries() << endl; |
414 |
< |
cout << "Number of events in eemm sample = " << SFSample->numEntries() << endl; |
415 |
< |
cout << "Number of events in em sample = " << OFSample->numEntries() << endl; |
413 |
> |
dout << "Number of (weighted) events in full sample = " << AllData->sumEntries() << " (raw events : " << AllData->numEntries() << ")" << endl; |
414 |
> |
dout << "Number of (weighted) events in eemm sample = " << SFSample->sumEntries() << " (raw events : " << SFSample->numEntries() << ")" << endl; |
415 |
> |
dout << "Number of (weighted) events in em sample = " << OFSample->sumEntries() << " (raw events : " << OFSample->numEntries() << ")" << endl; |
416 |
|
} |
417 |
|
|
418 |
|
} |
419 |
|
|
420 |
+ |
void EdgeFitter::DrawDatasetContent(int is_data) { |
421 |
+ |
TCanvas* cSFdata = new TCanvas("cSFdata","cSFdata") ; |
422 |
+ |
|
423 |
+ |
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}"); |
424 |
+ |
RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("SF sample")) ; |
425 |
+ |
frame1->GetXaxis()->CenterTitle(1); |
426 |
+ |
frame1->GetYaxis()->CenterTitle(1); |
427 |
+ |
SFSample->plotOn(frame1,RooFit::Name("SFdata")) ; |
428 |
+ |
|
429 |
+ |
RooPlot* frame2 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ; |
430 |
+ |
frame2->GetXaxis()->CenterTitle(1); |
431 |
+ |
frame2->GetYaxis()->CenterTitle(1); |
432 |
+ |
OFSample->plotOn(frame2,RooFit::Name("OFdata")) ; |
433 |
+ |
|
434 |
+ |
// THStack sf_ref = allsamples.DrawStack("sf_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1==id2"),is_data, luminosity); |
435 |
+ |
// THStack of_ref = allsamples.DrawStack("of_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1!=id2"),is_data, luminosity); |
436 |
+ |
|
437 |
+ |
TH1F *sf_ref = allsamples.Draw("sf_ref","mll",int((mllmax-mllmin)/5.0),mllmin,mllmax, "m_{ll} [GeV]", "events", cut&&TCut("id1==id2"),is_data, luminosity); |
438 |
+ |
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); |
439 |
+ |
|
440 |
+ |
TH1F *sf_fit = (TH1F*)SFSample->createHistogram("sf_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true)); |
441 |
+ |
TH1F *of_fit = (TH1F*)OFSample->createHistogram("of_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true)); |
442 |
+ |
|
443 |
+ |
TLegend *leg = allsamples.allbglegend(); |
444 |
+ |
leg->AddEntry(sf_fit,"RooDataSet content","p"); |
445 |
+ |
leg->SetX1(0.58); |
446 |
+ |
|
447 |
+ |
cSFdata->cd() ; |
448 |
+ |
gPad->SetLeftMargin(0.15); |
449 |
+ |
frame1->GetYaxis()->SetTitleOffset(1.4); |
450 |
+ |
frame1->Draw(); |
451 |
+ |
sf_ref->Draw("histo,same"); |
452 |
+ |
sf_fit->Draw("e1,same"); |
453 |
+ |
leg->Draw("same"); |
454 |
+ |
if(is_data==data) DrawPrelim(); |
455 |
+ |
else DrawPrelim(PlottingSetup::luminosity,true); |
456 |
+ |
CompleteSave(cSFdata,"Edge/SF_NoFit"); |
457 |
+ |
|
458 |
+ |
TCanvas* cOFdata = new TCanvas("cOFdata","cOFdata") ; |
459 |
+ |
cOFdata->cd() ; |
460 |
+ |
gPad->SetLeftMargin(0.15); |
461 |
+ |
frame2->SetMaximum(frame1->GetMaximum()); |
462 |
+ |
frame2->GetYaxis()->SetTitleOffset(1.4); |
463 |
+ |
frame2->Draw(); |
464 |
+ |
of_ref->Draw("histo,same"); |
465 |
+ |
of_fit->Draw("e1,same"); |
466 |
+ |
leg->Draw("same"); |
467 |
+ |
if(is_data==data) DrawPrelim(); |
468 |
+ |
else DrawPrelim(PlottingSetup::luminosity,true); |
469 |
+ |
CompleteSave(cOFdata,"Edge/OF_NoFit"); |
470 |
+ |
|
471 |
+ |
delete sf_fit; |
472 |
+ |
delete of_fit; |
473 |
+ |
|
474 |
+ |
delete sf_ref; |
475 |
+ |
delete of_ref; |
476 |
+ |
|
477 |
+ |
} |
478 |
+ |
|
479 |
|
string WriteWithError(float central, float error, int digits) { |
480 |
|
float ref=central; |
481 |
|
if(ref<0) ref=-central; |
513 |
|
} |
514 |
|
|
515 |
|
void EdgeFitter::DoFit(int is_data, float jzb_cut) { |
516 |
+ |
|
517 |
+ |
stringstream prefix; |
518 |
+ |
if(is_data==data) prefix << "data_"; |
519 |
+ |
if(is_data==mc) prefix << "mc_"; |
520 |
+ |
if(is_data==mcwithsignal) prefix << "mcwithS_"; |
521 |
+ |
|
522 |
+ |
prefix << EdgeFitter::Mode << "_" << jzb_cut; |
523 |
+ |
|
524 |
+ |
if(EdgeFitter::AllowTriangle) prefix << "__H1"; |
525 |
+ |
else prefix << "__H0"; |
526 |
+ |
|
527 |
|
RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}"); |
528 |
|
RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,""); |
529 |
|
RooCategory sample("sample","sample") ; |
536 |
|
|
537 |
|
|
538 |
|
//First we make a fit to opposite flavor |
539 |
< |
RooRealVar fttbarOF("fttbarOF", "fttbarOF", 100, 0, 10000); |
539 |
> |
RooRealVar fttbarOF("fttbarOF", "fttbarOF", 100, 0, 1.5*combData.sumEntries()); |
540 |
|
RooRealVar par1ttbarOF("par1ttbarOF", "par1ttbarOF", 1.6, 0.01, 4.0); |
541 |
|
RooRealVar par2ttbarOF("par2ttbarOF", "par2ttbarOF", 1.0); |
542 |
|
RooRealVar par3ttbarOF("par3ttbarOF", "par3ttbarOF", 0.028, 0.001, 1.0); |
546 |
|
RooSimultaneous simPdfOF("simPdfOF","simultaneous pdf", sample) ; |
547 |
|
simPdfOF.addPdf(model_OF,"OF"); |
548 |
|
RooFitResult *resultOF = simPdfOF.fitTo(combData, RooFit::Save(),RooFit::Extended(),RooFit::Minos(true)); |
549 |
< |
//resultOF->Print(); |
549 |
> |
dout << "============================= < OF results > =============================" << endl; |
550 |
> |
resultOF->Print(); |
551 |
> |
dout << "============================= < /OF results > =============================" << endl; |
552 |
> |
|
553 |
> |
|
554 |
> |
RooPlot* frameO = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")); |
555 |
> |
frameO->GetXaxis()->CenterTitle(1); |
556 |
> |
frameO->GetYaxis()->CenterTitle(1); |
557 |
> |
combData.plotOn(frameO,RooFit::Name("OFdata"),RooFit::Cut("sample==sample::OF")) ; |
558 |
> |
simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ; |
559 |
> |
simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("TTbarOFonly"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ; |
560 |
|
|
561 |
+ |
TCanvas* pof = new TCanvas("pof","pof") ; |
562 |
+ |
pof->cd() ; |
563 |
+ |
gPad->SetLeftMargin(0.15); |
564 |
+ |
frameO->GetYaxis()->SetTitleOffset(1.4); |
565 |
+ |
frameO->Draw(); |
566 |
+ |
if(is_data==data) DrawPrelim(); |
567 |
+ |
else DrawPrelim(PlottingSetup::luminosity,true); |
568 |
+ |
if(EdgeFitter::FixedMEdge>=0) CompleteSave(pof,"Edge/OF__OFFitonly_"+prefix.str()+"__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false); |
569 |
+ |
else CompleteSave(pof,"Edge/OF__OFFitonly_"+prefix.str(),false,false); |
570 |
+ |
delete pof; |
571 |
+ |
|
572 |
|
if(resultOF->covQual()!=3) { |
573 |
|
write_error(__FUNCTION__,"OF fit did not converge!!! Cannot continue!"); |
574 |
< |
cout << "covQual is " << resultOF->covQual() << endl; |
575 |
< |
EdgeFitter::FixedMEdgeChi2=-1; |
574 |
> |
dout << "covQual is " << resultOF->covQual() << endl; |
575 |
> |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=-1; |
576 |
> |
else EdgeFitter::FixedMEdgeChi2_H0=-1; |
577 |
|
if(EdgeFitter::RejectPointIfNoConvergence) return; |
578 |
|
} else { |
579 |
|
write_info(__FUNCTION__,"OF fit converged"); |
580 |
|
} |
459 |
– |
|
460 |
– |
RooRealVar* resultOFpar1_ = (RooRealVar*) resultOF->floatParsFinal().find("par1ttbarOF"); |
461 |
– |
float resultOFpar1 = resultOFpar1_->getVal(); |
462 |
– |
//RooRealVar* resultOFpar2_ = (RooRealVar*) resultOF->floatParsFinal().find("par2ttbarOF"); |
463 |
– |
//float resultOFpar2 = resultOFpar2_->getVal(); |
464 |
– |
//cout << "caca2.txt" << endl; |
465 |
– |
|
466 |
– |
RooRealVar* resultOFpar3_ = (RooRealVar*) resultOF->floatParsFinal().find("par3ttbarOF"); |
467 |
– |
float resultOFpar3 = resultOFpar3_->getVal(); |
468 |
– |
|
469 |
– |
//RooRealVar* resultOFpar4_ = (RooRealVar*) resultOF->floatParsFinal().find("par4ttbarOF"); |
470 |
– |
//float resultOFpar4 = resultOFpar4_->getVal(); |
471 |
– |
//cout << "caca4.txt" << endl; |
581 |
|
|
582 |
|
float StartingMedge=70; |
583 |
|
if(EdgeFitter::FixedMEdge>0) StartingMedge=EdgeFitter::FixedMEdge; |
584 |
|
|
585 |
|
|
586 |
+ |
RooDataSet *ZDataSet = (RooDataSet*)EdgeFitter::AllData->reduce("id1==id2 && abs(mll-91.2)<20"); |
587 |
+ |
|
588 |
+ |
float maxZ = ZDataSet->sumEntries(); |
589 |
+ |
dout << "maxZ was set to " << maxZ << endl; |
590 |
+ |
delete ZDataSet; |
591 |
+ |
|
592 |
+ |
|
593 |
|
// Now same flavor |
594 |
< |
RooRealVar fzSF("fzSF", "fzSF", 5, 0, 100000); |
594 |
> |
RooRealVar fzSF("fzSF", "fzSF", 39, 39, maxZ); |
595 |
|
RooRealVar meanzSF("meanzSF", "meanzSF", 91.1876, 89, 95); |
596 |
|
//RooRealVar sigmazSF("sigmazSF", "sigmazSF", 0.5); |
597 |
|
RooRealVar sigmazSF("sigmazSF", "sigmazSF", 5, 0.5, 5); |
598 |
|
RooRealVar widthzSF("widthzSF", "widthzSF", 2.94); |
599 |
+ |
widthzSF.setConstant(1); |
600 |
+ |
|
601 |
+ |
RooRealVar fttbarSFx("fttbarSFx","fttbarSFx",0.2,1.8); |
602 |
+ |
RooRealVar mRsfof("mRsfof","mRsfof",1.02); |
603 |
+ |
RooRealVar wRsfof("wRsfof","wRsfof",0.07); |
604 |
|
|
605 |
< |
RooRealVar fttbarSF("fttbarSF", "fttbarSF", 100, 0, 100000); |
606 |
< |
RooRealVar par1ttbarSF("par1ttbarSF", "par1ttbarSF", 1.02*resultOFpar1, 0, 100); |
607 |
< |
RooRealVar par2ttbarSF("par2ttbarSF", "par2ttbarSF", 1.0); |
608 |
< |
RooRealVar par3ttbarSF("par3ttbarSF", "par3ttbarSF", resultOFpar3, 0, 100); |
488 |
< |
RooRealVar par4ttbarSF("par4ttbarSF", "par4ttbarSF", 2.0); |
605 |
> |
RooGaussian RSFOF("RSFOF","RSFOF",fttbarSFx,mRsfof,wRsfof); |
606 |
> |
RooProdPdf fttbarSF("fttbarSF","fttbarOF*RSFOF",RooArgList(RSFOF,fttbarOF)); |
607 |
> |
|
608 |
> |
RooRealVar par1ttbarSF("par1ttbarSF", "par1ttbarSF", 1.02*par1ttbarOF.getVal(), (1.02-0.07)*par1ttbarOF.getVal(), (1.02+0.07)*par1ttbarOF.getVal()); |
609 |
|
|
610 |
< |
RooRealVar fsignalSF("fsignalSF", "fsignalSF", 10, 0, 300); |
610 |
> |
RooRealVar fsignalSF("fsignalSF", "fsignalSF", 0, 0, 300); |
611 |
|
RooRealVar par1signalSF("par1signalSF", "par1signalSF", 45, 20, 100); |
612 |
|
RooRealVar par2signalSF("par2signalSF", "par2signalSF", 2, 1, 10); |
613 |
|
RooRealVar par3signalSF("par3signalSF", "par3signalSF", StartingMedge, 0, 300); |
616 |
|
|
617 |
|
if(EdgeFitter::FixedMEdge>0) par3signalSF.setConstant(); |
618 |
|
|
619 |
< |
/* par1ttbarOF.setConstant(1); |
500 |
< |
par2ttbarOF.setConstant(1); |
501 |
< |
par3ttbarOF.setConstant(1); |
502 |
< |
par4ttbarOF.setConstant(1); |
503 |
< |
fttbarOF.setConstant(1);*/ |
504 |
< |
|
505 |
< |
RooSUSYBkgPdf ttbarSF("ttbarSF","ttbarSF", mll , par1ttbarSF, par2ttbarSF, par3ttbarSF, par4ttbarSF); |
506 |
< |
//RooSUSYTPdf signalSF("signalSF","signalSF", mll , par1signalSF, par2signalSF, par3signalSF); |
619 |
> |
RooSUSYBkgPdf ttbarSF("ttbarSF","ttbarSF", mll , par1ttbarSF, par2ttbarOF, par3ttbarOF, par4ttbarOF); |
620 |
|
RooSUSYTPdf signalSF("signalSF","signalSF", mll , par1signalSF, sigmazSF, par3signalSF); |
508 |
– |
|
509 |
– |
/* par1ttbarSF.setConstant(true); |
510 |
– |
par2ttbarSF.setConstant(true); |
511 |
– |
par3ttbarSF.setConstant(true); |
512 |
– |
par4ttbarSF.setConstant(true);*/ |
513 |
– |
|
621 |
|
|
515 |
– |
//RooAddPdf model_SF("model_SF","model_SF", RooArgList(zSF, ttbarSF, signalSF), RooArgList(fzSF, fttbarSF, fsignalSF)); |
622 |
|
RooAddPdf model_SF("model_SF","model_SF", RooArgList(zSF, ttbarSF, signalSF), RooArgList(fzSF, fttbarSF, fsignalSF)); |
623 |
< |
RooAddPdf model_OF("model_OF","model_OF", RooArgList(ttbarSF), RooArgList(fttbarSF)); |
624 |
< |
|
623 |
> |
|
624 |
> |
|
625 |
> |
if(!EdgeFitter::AllowTriangle) { |
626 |
> |
fsignalSF.setVal(0.0); // kill off the signal if we don't want the triangle |
627 |
> |
fsignalSF.setConstant(1); |
628 |
> |
par2signalSF.setConstant(1); |
629 |
> |
par3signalSF.setConstant(1); |
630 |
> |
} |
631 |
|
|
632 |
|
RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ; |
633 |
|
simPdf.addPdf(model_SF,"SF") ; |
634 |
|
simPdf.addPdf(model_OF,"OF") ; |
635 |
|
|
636 |
+ |
|
637 |
|
RooFitResult *result = simPdf.fitTo(combData, RooFit::Save(), RooFit::Extended(),RooFit::Minos(true)); |
638 |
|
|
639 |
|
if(result->covQual()!=3) { |
640 |
|
write_error(__FUNCTION__,"Full fit did not converge!!! Cannot continue!"); |
641 |
< |
cout << "covQual is " << result->covQual() << endl; |
642 |
< |
EdgeFitter::FixedMEdgeChi2=-1; |
641 |
> |
dout << "covQual is " << result->covQual() << endl; |
642 |
> |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=-1; |
643 |
> |
else EdgeFitter::FixedMEdgeChi2_H0=-1; |
644 |
|
if(EdgeFitter::RejectPointIfNoConvergence) return; |
645 |
|
} else { |
646 |
|
write_info(__FUNCTION__,"Full fit converged"); |
647 |
|
} |
648 |
|
|
649 |
< |
// result->Print(); |
649 |
> |
dout << "============================= < Full results > =============================" << endl; |
650 |
> |
result->Print(); |
651 |
> |
dout << "============================= < /Full results > =============================" << endl; |
652 |
> |
|
653 |
|
|
654 |
|
RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("EE sample")) ; |
655 |
|
frame1->GetXaxis()->CenterTitle(1); |
658 |
|
simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ; |
659 |
|
simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("TTbarSFonly"),RooFit::Components("ttbarSF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ; |
660 |
|
simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("DYSFonly"),RooFit::Components("zSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed)); |
661 |
< |
simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("SignalSFonly"),RooFit::Components("signalSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen)); |
545 |
< |
|
546 |
< |
EdgeFitter::FixedMEdgeChi2 = frame1->chiSquare("FullFit", "SFdata", 3); |
547 |
< |
|
661 |
> |
if(EdgeFitter::AllowTriangle) simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("SignalSFonly"),RooFit::Components("signalSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen)); |
662 |
|
|
663 |
< |
cout << "Result : " << endl; |
664 |
< |
cout << "f signal : " << fsignalSF.getVal() << " +/- " << fsignalSF.getError() << endl; |
665 |
< |
cout << "f ttbar : " << fttbarSF.getVal() << " +/- " << fttbarSF.getError() << endl; |
666 |
< |
cout << "f tt OF : " << fttbarOF.getVal() << " +/- " << fttbarOF.getError() << endl; |
667 |
< |
cout << "f z SF : " << fzSF.getVal() << " +/- " << fzSF.getError() << endl; |
668 |
< |
cout << "#Chi^{2}/NDF : " << EdgeFitter::FixedMEdgeChi2 << endl; |
663 |
> |
if(EdgeFitter::AllowTriangle) EdgeFitter::FixedMEdgeChi2_H1=frame1->chiSquare("FullFit", "SFdata", 3); |
664 |
> |
else EdgeFitter::FixedMEdgeChi2_H0=frame1->chiSquare("FullFit", "SFdata", 3); |
665 |
> |
|
666 |
> |
dout << "Result : " << endl; |
667 |
> |
if(EdgeFitter::AllowTriangle) dout << "f signal : " << fsignalSF.getVal() << " +/- " << fsignalSF.getError() << endl; |
668 |
> |
// dout << "f ttbar : " << fttbarSF.getVal() << " +/- " << fttbarSF.getError() << endl; |
669 |
> |
dout << "f ttbar : " << fttbarSF.getVal() << " +/- NO ERROR CUZ ITS A PDF "<< endl; |
670 |
> |
dout << "f tt OF : " << fttbarOF.getVal() << " +/- " << fttbarOF.getError() << endl; |
671 |
> |
dout << "f z SF : " << fzSF.getVal() << " +/- " << fzSF.getError() << endl; |
672 |
> |
if(EdgeFitter::AllowTriangle) dout << "#Chi^{2}/NDF : " << EdgeFitter::FixedMEdgeChi2_H1 << endl; |
673 |
> |
else dout << "#Chi^{2}/NDF : " << EdgeFitter::FixedMEdgeChi2_H0 << endl; |
674 |
|
|
675 |
|
// The same plot for the cointrol sample slice |
676 |
|
RooPlot* frame3 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ; |
678 |
|
frame3->GetYaxis()->CenterTitle(1); |
679 |
|
frame3->SetMaximum(frame1->GetMaximum()); |
680 |
|
combData.plotOn(frame3,RooFit::Cut("sample==sample::OF")) ; |
681 |
< |
simPdfOF.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ; |
682 |
< |
simPdfOF.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ; |
564 |
< |
|
565 |
< |
|
566 |
< |
stringstream prefix; |
567 |
< |
if(is_data==data) prefix << "data_"; |
568 |
< |
if(is_data==mc) prefix << "mc_"; |
569 |
< |
if(is_data==mcwithsignal) prefix << "mcwithS_"; |
570 |
< |
|
571 |
< |
prefix << EdgeFitter::Mode << "_" << jzb_cut; |
572 |
< |
|
681 |
> |
simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ; |
682 |
> |
simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ; |
683 |
|
|
684 |
|
|
685 |
|
TCanvas* c = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf") ; |
691 |
|
else DrawPrelim(PlottingSetup::luminosity,true); |
692 |
|
stringstream infotext; |
693 |
|
infotext << "#splitline{Fit results (" << EdgeFitter::Mode << ">" << jzb_cut << "): }{#splitline{"; |
694 |
< |
infotext << "N(Data) = " << EdgeFitter::SFSample->numEntries() << "}{#splitline{"; |
694 |
> |
infotext << "N(Data) = " << EdgeFitter::SFSample->sumEntries() << "}{#splitline{"; |
695 |
|
infotext << "N(Z+Jets) = " << WriteWithError(fzSF.getVal(),fzSF.getError(),3) << "}{#splitline{"; |
696 |
< |
infotext << "N(t#bar{t}) = " << WriteWithError(fttbarSF.getVal(),fttbarSF.getError(),3) << "}{#splitline{"; |
697 |
< |
infotext << "N(signal) = " << WriteWithError(fsignalSF.getVal(),fsignalSF.getError(),3) << "}{"; |
698 |
< |
infotext << "m_{edge} = " << WriteWithError(par3signalSF.getVal(),par3signalSF.getError(),3) << "}}}}}"; |
696 |
> |
//infotext << "N(t#bar{t}) = " << WriteWithError(fttbarSF.getVal(),fttbarSF.getError(),3) << "}{#splitline{"; |
697 |
> |
infotext << "N(t#bar{t}) = " << WriteWithError(fttbarSF.getVal(),0,3) << "}{#splitline{"; |
698 |
> |
write_warning(any2string(__LINE__),"Don't have the error yet, need to complete this"); |
699 |
> |
if(EdgeFitter::AllowTriangle) { |
700 |
> |
infotext << "N(signal) = " << WriteWithError(fsignalSF.getVal(),fsignalSF.getError(),3) << "}{"; |
701 |
> |
infotext << "m_{edge} = " << WriteWithError(par3signalSF.getVal(),par3signalSF.getError(),3) << "}}}}}"; |
702 |
> |
} else infotext << "}{}}}}}"; |
703 |
|
|
704 |
|
TLatex *infobox = new TLatex(0.57,0.75,infotext.str().c_str()); |
705 |
|
infobox->SetNDC(); |
762 |
|
|
763 |
|
EdgeFitter::PrepareDatasets(is_data); |
764 |
|
|
765 |
+ |
EdgeFitter::DrawDatasetContent(is_data); |
766 |
+ |
|
767 |
|
RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow(); |
768 |
|
RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL); |
769 |
|
|
770 |
|
|
655 |
– |
bool ScanMassRange=false; |
771 |
|
|
772 |
+ |
EdgeFitter::AllowTriangle=false; |
773 |
+ |
EdgeFitter::DoFit(is_data, jzb_cut); |
774 |
+ |
|
775 |
+ |
write_info(__FUNCTION__,"TAKING SHORTCUT");return; |
776 |
+ |
|
777 |
+ |
EdgeFitter::AllowTriangle=true; |
778 |
+ |
|
779 |
+ |
bool ScanMassRange=false; |
780 |
+ |
float ScanSteps=5.0;//GeV |
781 |
|
|
782 |
|
|
783 |
|
if(ScanMassRange) { |
784 |
|
TFile *fscan = new TFile("fscan.root","UPDATE"); |
785 |
|
TGraph *gr = new TGraph(); |
786 |
+ |
TGraph *Rgr = new TGraph(); |
787 |
|
stringstream GrName; |
788 |
|
GrName << "ScanGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut; |
789 |
+ |
stringstream RGrName; |
790 |
+ |
RGrName << "ScanRatioGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut; |
791 |
|
gr->SetName(GrName.str().c_str()); |
792 |
+ |
Rgr->SetName(RGrName.str().c_str()); |
793 |
|
|
794 |
|
int i=0; |
795 |
< |
for(float tempMedge=10;tempMedge<=300;tempMedge+=5.0) { |
795 |
> |
for(float tempMedge=10;tempMedge<=300;tempMedge+=ScanSteps) { |
796 |
|
write_info(__FUNCTION__,"Now testing Medge="+any2string(tempMedge)+" for "+EdgeFitter::Mode+">"+any2string(jzb_cut)); |
797 |
|
EdgeFitter::FixedMEdge=tempMedge; |
798 |
|
EdgeFitter::DoFit(is_data, jzb_cut); |
799 |
< |
if(EdgeFitter::FixedMEdgeChi2<0) continue; |
800 |
< |
gr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2); |
799 |
> |
if(EdgeFitter::FixedMEdgeChi2_H1<0) continue; |
800 |
> |
gr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2_H1); |
801 |
> |
Rgr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2_H1/EdgeFitter::FixedMEdgeChi2_H0); |
802 |
|
i++; |
803 |
|
} |
804 |
|
|
817 |
|
if(is_data) DrawPrelim(); |
818 |
|
else DrawMCPrelim(); |
819 |
|
CompleteSave(ScanCan,ScanCanSave.str()); |
820 |
+ |
|
821 |
+ |
Rgr->GetXaxis()->SetTitle("m_{edge}"); |
822 |
+ |
Rgr->GetXaxis()->CenterTitle(); |
823 |
+ |
Rgr->GetYaxis()->SetTitle("#Chi^{2} / NDF"); |
824 |
+ |
Rgr->GetYaxis()->CenterTitle(); |
825 |
+ |
Rgr->GetYaxis()->SetTitleOffset(0.95); |
826 |
+ |
Rgr->GetXaxis()->SetTitleOffset(0.9); |
827 |
+ |
Rgr->SetLineColor(kBlue); |
828 |
+ |
Rgr->SetTitle(""); |
829 |
+ |
Rgr->Draw("AL"); |
830 |
+ |
ScanCanSave.str(""); |
831 |
+ |
ScanCanSave << "Edge/MEdgeScan_Ratio_"+EdgeFitter::Mode+"_" << jzb_cut; |
832 |
+ |
if(is_data) DrawPrelim(); |
833 |
+ |
else DrawMCPrelim(); |
834 |
+ |
CompleteSave(ScanCan,ScanCanSave.str()); |
835 |
|
fscan->cd(); |
836 |
|
gr->Write(); |
837 |
|
delete ScanCan; |
838 |
|
fscan->Close(); |
839 |
|
} else { |
840 |
|
EdgeFitter::DoFit(is_data, jzb_cut); |
841 |
+ |
dout << "Chi^2 (H0) = " << EdgeFitter::FixedMEdgeChi2_H0 << endl; |
842 |
+ |
dout << "Chi^2 (H1) = " << EdgeFitter::FixedMEdgeChi2_H1 << endl; |
843 |
|
} |
844 |
|
|
699 |
– |
|
700 |
– |
|
845 |
|
|
702 |
– |
EdgeFitter::DoFit(is_data, jzb_cut); |
846 |
|
RooMsgService::instance().setGlobalKillBelow(msglevel); |
847 |
|
|
705 |
– |
|
848 |
|
f->Close(); |
849 |
|
|
850 |
|
} |