ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/EdgeLimit.C
Revision: 1.20
Committed: Fri Jun 14 12:12:54 2013 UTC (11 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.19: +38 -8 lines
Log Message:
Tree name of temporary skimmed and slimmed trees now reflects source root file; unweighted event yields are also shown; cross check for roodataset has been added (roodataset based histogram vs allsamples draw based histogram)

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2    
3 buchmann 1.10 #include <TVirtualIndex.h>
4    
5 buchmann 1.2 #include <RooRealVar.h>
6     #include <RooArgSet.h>
7     #include <RooDataSet.h>
8 buchmann 1.4 #include <RooMCStudy.h>
9     #include <RooCategory.h>
10    
11 buchmann 1.5 #include <RooPlot.h>
12     #include <RooSimultaneous.h>
13     #include <RooAddPdf.h>
14     #include <RooFitResult.h>
15     #include <RooVoigtian.h>
16     #include <RooMsgService.h>
17    
18 buchmann 1.3 #include <RooStats/ModelConfig.h>
19     #include "RooStats/ProfileLikelihoodCalculator.h"
20     #include "RooStats/LikelihoodInterval.h"
21     #include "RooStats/HypoTestResult.h"
22     #include "RooStats/SimpleLikelihoodRatioTestStat.h"
23     #include "RooStats/ProfileLikelihoodTestStat.h"
24     #include "RooStats/HybridCalculatorOriginal.h"
25     #include "RooStats/HypoTestInverterOriginal.h"
26    
27 buchmann 1.5 //#include "ParametrizedEdge.C"
28 buchmann 1.8 #include "EdgeModules/RooSUSYTPdf.cxx"
29     #include "EdgeModules/RooSUSYBkgPdf.cxx"
30 buchmann 1.5
31 buchmann 1.2
32 buchmann 1.1 using namespace std;
33     using namespace PlottingSetup;
34    
35    
36 buchmann 1.2
37    
38 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) {
39     write_error(__FUNCTION__,"Not implemented edge limits yet (returning crap)");
40     ShapeDroplet beta;beta.observed=-12345;beta.SignalIntegral=1;return beta;
41     }
42    
43    
44     void PrepareEdgeShapes(string mcjzb, string datajzb, vector<float> jzbbins, float jzbpeakerrordata) {
45     write_error(__FUNCTION__,"Not implemented edge shape storage yet");
46     }
47    
48    
49 buchmann 1.2 ///------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50    
51    
52     namespace EdgeFitter {
53    
54     void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree*);
55     void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree*);
56 buchmann 1.7 void getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp);
57 buchmann 1.2 void InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut);
58     void PrepareDatasets(int);
59 buchmann 1.15 void DrawDatasetContent(int);
60 buchmann 1.5 void DoFit(int is_data, float jzb_cut);
61 buchmann 1.2 string RandomStorageFile();
62     Yield Get_Z_estimate(float,int);
63     Yield Get_T_estimate(float,int);
64 buchmann 1.7 float calcExclusion(RooWorkspace *ws, RooDataSet data, bool calcExclusion);
65     vector<RooDataSet> generateToys(RooWorkspace *ws, int nToys);
66 buchmann 1.4 void prepareLimits(RooWorkspace *ws, bool ComputeBands);
67     TGraph* prepareLM(float mass, float nEv);
68 buchmann 1.2
69     float jzbmax;
70     float mllmin;
71     float mllmax;
72     TCut cut;
73    
74     RooDataSet* AllData;
75 buchmann 1.10 RooDataSet* SFSample;
76     RooDataSet* OFSample;
77 buchmann 1.2
78 buchmann 1.6 bool MarcoDebug=true;
79 buchmann 1.11
80     float FixedMEdge=-1;
81     float FixedMEdgeChi2=-1;
82    
83 buchmann 1.14 bool RejectPointIfNoConvergence=false;
84    
85     string Mode="UndefinedMode";
86    
87 buchmann 1.2 }
88    
89 buchmann 1.18 TLatex* WriteAppleStudel() {
90     string sel="Apple Strudel Preliminary";
91     TLatex *sele = new TLatex(0.97,0.135,sel.c_str());
92     sele->SetNDC(true);
93     sele->SetTextColor(TColor::GetColor("#848484"));
94     sele->SetTextFont(42);
95     sele->SetTextAlign(32);
96     sele->SetTextSize(0.03);
97     sele->SetTextAngle(270);
98     return sele;
99     }
100    
101 buchmann 1.4 TGraph* EdgeFitter::prepareLM(float mass, float nEv) {
102     float massLM[1];
103     massLM[0]=mass;
104     float accEffLM[1];
105     accEffLM[0]=nEv/PlottingSetup::luminosity;
106     TGraph *lm = new TGraph(1, massLM, accEffLM);
107     lm->GetXaxis()->SetNoExponent(true);
108     lm->GetXaxis()->SetTitle("m_{cut} [GeV]");
109     lm->GetYaxis()->SetTitle("#sigma #times A [pb] 95% CL UL");
110     lm->GetXaxis()->SetLimits(0.,300.);
111     lm->GetYaxis()->SetRangeUser(0.,0.08);
112     lm->SetMarkerStyle(34);
113     lm->SetMarkerColor(kRed);
114     return lm;
115     }
116    
117 buchmann 1.7 vector<RooDataSet> EdgeFitter::generateToys(RooWorkspace *ws, int nToys) {
118 buchmann 1.10 ws->ls();
119 buchmann 1.4 ws->var("nSig")->setVal(0.);
120     ws->var("nSig")->setConstant(true);
121     RooFitResult* fit = ws->pdf("combModel")->fitTo(*ws->data("data_obs"),RooFit::Save());
122 buchmann 1.7 vector<RooDataSet> theToys;
123 buchmann 1.4
124     RooMCStudy mcEE(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"EE"));
125     mcEE.generate(nToys,44,true);
126     RooMCStudy mcMM(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"MM"));
127     mcMM.generate(nToys,44,true);
128     RooMCStudy mcOSOF(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"OSOF"));
129     mcOSOF.generate(nToys,44,true);
130    
131 buchmann 1.10 RooRealVar mll("m_{ll}","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
132 buchmann 1.4 RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
133     RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
134     RooRealVar jzb("jzb","jzb",-jzbmax,jzbmax,"GeV/c");
135     RooRealVar weight("weight","weight",0,1000,"");
136     RooArgSet observables(mll,jzb,id1,id2,weight);
137    
138     for(int i=0;i<nToys;i++) {
139     RooDataSet* toyEE = (RooDataSet*)mcEE.genData(i);
140     RooDataSet* toyMM = (RooDataSet*)mcMM.genData(i);
141     RooDataSet* toyOSOF = (RooDataSet*)mcOSOF.genData(i);
142     stringstream toyname;
143     toyname << "theToy_" << i;
144     write_warning(__FUNCTION__,"Problem while adding toys");
145 buchmann 1.7 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));
146     theToys.push_back(toyData);
147 buchmann 1.4 }
148     ws->var("nSig")->setVal(17.0);
149     ws->var("nSig")->setConstant(false);
150     return theToys;
151     }
152    
153 buchmann 1.7 void EdgeFitter::getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp) {
154 buchmann 1.4 TH1F *gauLimit = new TH1F("gausLimit","gausLimit",60,0.,80./PlottingSetup::luminosity);
155     vector<float> theLimits;
156 buchmann 1.9 for(int itoy=0;itoy<(int)theToys.size();itoy++) {
157 buchmann 1.7 float theLimit = calcExclusion(ws,theToys[itoy],false);
158 buchmann 1.4 if(theLimit > 0 ) gauLimit->Fill(theLimit);
159     }
160     const Int_t nQ = 4;
161     Double_t yQ[nQ] = {0.,0.,0.,0.};
162     Double_t xQ[nQ] = {0.022750132,0.1586552539,0.84134474609999998,0.977249868};
163     gauLimit->GetQuantiles(nQ,yQ,xQ);
164     median = gauLimit->GetMean();
165     // median = median1(gauLimit);
166     twoSigmaDown = abs(yQ[0]-median);
167     sigmaDown = abs(yQ[1]-median);
168     sigmaUp = abs(yQ[2]-median);
169     twoSigmaUp = abs(yQ[3]-median);
170 buchmann 1.18 dout << median * PlottingSetup::luminosity << " " << sigmaUp * PlottingSetup::luminosity << endl;
171 buchmann 1.4 }
172    
173     void EdgeFitter::prepareLimits(RooWorkspace *ws, bool ComputeBands) {
174     if(ComputeBands) {
175 buchmann 1.7 vector<RooDataSet> theToys = EdgeFitter::generateToys(ws,50);
176 buchmann 1.4 vector<float> medVals;
177     vector<float> medLimits;
178     vector<float> sigmaLimitsDown;
179     vector<float> sigmaLimitsUp;
180     vector<float> twoSigmaLimitsDown;
181     vector<float> twoSigmaLimitsUp;
182     for(int i=20;i<=320;i+=40) {
183     ws->var("nSig")->setVal(10.0);
184     medVals.push_back((float)i);
185     ws->var("m0")->setVal((float)i);
186     ws->var("m0")->setConstant(true);
187     float Smedian,SsigmaDown,SsigmaUp,StwoSigmaDown,StwoSigmaUp;
188     EdgeFitter::getMedianLimit(ws,theToys,Smedian,SsigmaDown,SsigmaUp,StwoSigmaDown,StwoSigmaUp);
189     medLimits.push_back(Smedian);
190     sigmaLimitsDown.push_back(SsigmaDown);
191     sigmaLimitsUp.push_back(SsigmaUp);
192     twoSigmaLimitsDown.push_back(StwoSigmaDown);
193     twoSigmaLimitsUp.push_back(StwoSigmaUp);
194     }
195     write_warning(__FUNCTION__,"Still need to store limits");
196     } else {
197     vector<float> theVals;
198     vector<float> theLimits;
199     for(int i=20;i<300;i+=5) {
200     ws->var("nSig")->setVal(0.0);
201     theVals.push_back((float)i);
202     ws->var("m0")->setVal((float)i);
203     ws->var("m0")->setConstant(true);
204 buchmann 1.7 // theLimits.push_back(calcExclusion(ws,(RooDataSet)*ws->data("data_obs"),true));
205     write_error(__FUNCTION__,"Error while casting roo data set");
206 buchmann 1.4 }
207    
208 buchmann 1.7 for(int i=0;i<(int)theLimits.size();i++) {
209 buchmann 1.4 if((theLimits[i]<2.0/PlottingSetup::luminosity)||(theLimits[i]>40.0/PlottingSetup::luminosity)) {
210 buchmann 1.18 dout << i << " : " << theVals[i] << endl;
211 buchmann 1.4 theLimits[i] = (theLimits[i+2]+theLimits[i-2])/2.0;
212     write_warning(__FUNCTION__,"Need to store limits");
213     }
214     write_warning(__FUNCTION__,"Need to store limits");
215     }
216     }
217     }
218    
219    
220 buchmann 1.7 float EdgeFitter::calcExclusion(RooWorkspace *ws, RooDataSet data, bool LoadDataObs) {
221     int numberOfToys=50;
222 buchmann 1.3 RooRealVar mu("mu","nSig",0,10000,"");
223     RooArgSet poi = RooArgSet(mu);
224     RooArgSet *nullParams = (RooArgSet*)poi.snapshot();
225     nullParams->setRealValue("nSig",0);
226     RooStats::ModelConfig *model = new RooStats::ModelConfig();
227     model->SetWorkspace(*ws);
228     model->SetPdf("combModel");
229     model->SetParametersOfInterest(poi);
230 buchmann 1.7 // if(LoadDataObs) data = (RooDataSet)*ws->data("data_obs");
231 buchmann 1.3
232 buchmann 1.7 RooStats::ProfileLikelihoodCalculator plc(data, *model);
233 buchmann 1.3 plc.SetNullParameters(*nullParams);
234     plc.SetTestSize(0.05);
235 buchmann 1.7
236 buchmann 1.3 RooStats::LikelihoodInterval* interval = plc.GetInterval();
237     RooStats::HypoTestResult *htr = plc.GetHypoTest();
238     double theLimit = interval->UpperLimit( mu );
239 buchmann 1.7 // double significance = htr->Significance();
240 buchmann 1.3
241     ws->defineSet("obs","nB");
242     ws->defineSet("poi","nSig");
243    
244     RooStats::ModelConfig b_model = RooStats::ModelConfig("B_model", ws);
245     b_model.SetPdf(*ws->pdf("combModel"));
246     b_model.SetObservables(*ws->set("obs"));
247     b_model.SetParametersOfInterest(*ws->set("poi"));
248     ws->var("nSig")->setVal(0.0); //# important!
249     b_model.SetSnapshot(*ws->set("poi"));
250    
251     RooStats::ModelConfig sb_model = RooStats::ModelConfig("S+B_model", ws);
252     sb_model.SetPdf(*ws->pdf("combModel"));
253     sb_model.SetObservables(*ws->set("obs"));
254     sb_model.SetParametersOfInterest(*ws->set("poi"));
255     ws->var("nSig")->setVal(64.0); //# important!
256     sb_model.SetSnapshot(*ws->set("poi"));
257    
258     RooStats::SimpleLikelihoodRatioTestStat slrts = RooStats::SimpleLikelihoodRatioTestStat(*b_model.GetPdf(),*sb_model.GetPdf());
259     slrts.SetNullParameters(*b_model.GetSnapshot());
260     slrts.SetAltParameters(*sb_model.GetSnapshot());
261     RooStats::ProfileLikelihoodTestStat profll = RooStats::ProfileLikelihoodTestStat(*b_model.GetPdf());
262    
263 buchmann 1.7 RooStats::HybridCalculatorOriginal hc = RooStats::HybridCalculatorOriginal(data, sb_model, b_model,0,0);
264 buchmann 1.3 hc.SetTestStatistic(2);
265 buchmann 1.7 hc.SetNumberOfToys(numberOfToys);
266 buchmann 1.3
267     RooStats::HypoTestInverterOriginal hcInv = RooStats::HypoTestInverterOriginal(hc,*ws->var("nSig"));
268     hcInv.SetTestSize(0.05);
269     hcInv.UseCLs(true);
270     hcInv.RunFixedScan(5,theLimit-0.5,theLimit+0.5);;
271     RooStats::HypoTestInverterResult* hcInt = hcInv.GetInterval();
272     float ulError = hcInt->UpperLimitEstimatedError();
273     theLimit = hcInt->UpperLimit();
274 buchmann 1.18 dout << "Found upper limit : " << theLimit << "+/-" << ulError << endl;
275 buchmann 1.3
276     return theLimit/PlottingSetup::luminosity;
277    
278     }
279    
280 buchmann 1.2 TTree* SkimTree(int isample) {
281 buchmann 1.20 string TreeName = removefunnystring(allsamples.collection[isample].filename);
282     cout << "About to skim " << TreeName << " for sample id " << isample << endl;
283 buchmann 1.15 TTree* newTree = new TTree("NanoTree",TreeName.c_str());
284    
285     float mll,edgeWeight;
286     int id1,id2;
287    
288     newTree->Branch("edgeWeight",&edgeWeight,"edgeWeight/F");
289     newTree->Branch("mll",&mll,"mll/F");
290     newTree->Branch("id1",&id1,"id1/I");
291     newTree->Branch("id2",&id2,"id2/I");
292 buchmann 1.20 newTree->Branch("isample",&isample,"isample/I");
293 buchmann 1.15
294 buchmann 1.2 float xsweight=1.0;
295     if(allsamples.collection[isample].is_data==false) xsweight=luminosity*allsamples.collection[isample].weight;
296     if(EdgeFitter::MarcoDebug) {
297 buchmann 1.20 dout << " Going to reduce it with cut " << EdgeFitter::cut << endl;
298 buchmann 1.18 dout << " Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl;
299 buchmann 1.2 }
300 buchmann 1.15
301 buchmann 1.6 float tmll;
302 buchmann 1.15 int tid1,tid2;
303 buchmann 1.6 allsamples.collection[isample].events->SetBranchAddress("mll",&tmll);
304 buchmann 1.15 allsamples.collection[isample].events->SetBranchAddress("id1",&tid1);
305     allsamples.collection[isample].events->SetBranchAddress("id2",&tid2);
306 buchmann 1.6
307 buchmann 1.2 TTreeFormula *select = new TTreeFormula("select", EdgeFitter::cut, allsamples.collection[isample].events);
308 buchmann 1.10 TTreeFormula *Weight = new TTreeFormula("Weight", cutWeight, allsamples.collection[isample].events);
309 buchmann 1.15
310 buchmann 1.2 float wgt=1.0;
311     for (Int_t entry = 0 ; entry < allsamples.collection[isample].events->GetEntries() ; entry++) {
312     allsamples.collection[isample].events->LoadTree(entry);
313     if (select->EvalInstance()) {
314     allsamples.collection[isample].events->GetEntry(entry);
315 buchmann 1.15 mll=tmll;
316     id1=tid1;
317     id2=tid2;
318 buchmann 1.10 wgt=Weight->EvalInstance();
319 buchmann 1.6 edgeWeight=wgt*xsweight;
320 buchmann 1.2 newTree->Fill();
321     }
322     }
323    
324 buchmann 1.20 if(EdgeFitter::MarcoDebug) dout << " Reduced tree contains " << newTree->GetEntries() << " entries " << endl;
325 buchmann 1.2 return newTree;
326     }
327    
328     void EdgeFitter::InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut) {
329     mllmin=_mllmin;
330     mllmax=_mllmax;
331     jzbmax=_jzbmax;
332     cut=_cut;
333     }
334 buchmann 1.10
335     TTree* MergeTrees(vector<TTree*> trees) {
336 buchmann 1.15 TTree * newtree = (TTree*)trees[0]->CloneTree(0);
337 buchmann 1.20 newtree->SetTitle("FullTree");
338     newtree->SetName("FullTree");
339 buchmann 1.10 trees[0]->GetListOfClones()->Remove(newtree);
340     trees[0]->ResetBranchAddresses();
341     newtree->ResetBranchAddresses();
342    
343 buchmann 1.15 for(int itree=0;itree<trees.size();itree++) {
344 buchmann 1.10 newtree->CopyAddresses(trees[itree]);
345     Long64_t nentries = trees[itree]->GetEntries();
346     for (Long64_t iEntry=0;iEntry<nentries;iEntry++) {
347     trees[itree]->GetEntry(iEntry);
348     newtree->Fill();
349     }
350     trees[itree]->ResetBranchAddresses(); // Disconnect from new tree
351     if (newtree->GetTreeIndex()) {
352     newtree->GetTreeIndex()->Append(trees[itree]->GetTreeIndex(),kTRUE);
353     }
354     if (newtree && newtree->GetTreeIndex()) {
355     newtree->GetTreeIndex()->Append(0,kFALSE); // Force the sorting
356     }
357     }
358     return newtree;
359     }
360    
361    
362    
363 buchmann 1.2 void EdgeFitter::PrepareDatasets(int is_data) {
364 buchmann 1.5 write_warning(__FUNCTION__,"Need to make this function ready for scans as well (use signal from scan samples)");
365 buchmann 1.15 TFile *tempout = new TFile("tempout.root","RECREATE");
366 buchmann 1.10 vector<TTree*> SkimmedTrees;
367     TTree *SkimmedTree[(int)allsamples.collection.size()];
368 buchmann 1.7 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
369 buchmann 1.2 if(!allsamples.collection[isample].is_active) continue;
370     if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
371     if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
372     if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC
373     if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it.
374 buchmann 1.18 if(EdgeFitter::MarcoDebug) dout << "Considering : " << allsamples.collection[isample].samplename << endl;
375 buchmann 1.15 SkimmedTree[isample] = SkimTree(isample);
376     tempout->cd();
377     SkimmedTree[isample]->Write();
378     SkimmedTrees.push_back(SkimmedTree[isample]);
379 buchmann 1.2 }
380 buchmann 1.10
381     TTree *completetree = MergeTrees(SkimmedTrees);
382    
383 buchmann 1.18 if(EdgeFitter::MarcoDebug) dout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl;
384 buchmann 1.2
385 buchmann 1.10 RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
386 buchmann 1.2 RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
387     RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
388 buchmann 1.6 RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
389     RooArgSet observables(mll,id1,id2,edgeWeight);
390 buchmann 1.2
391     string title="CMS Data";
392     if(is_data!=1) title="CMS SIMULATION";
393 buchmann 1.6 RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","edgeWeight");
394 buchmann 1.15 tempout->cd();
395 buchmann 1.2 completetree->Write();
396 buchmann 1.15 tempout->Close();
397 buchmann 1.2
398 buchmann 1.10 EdgeFitter::SFSample = (RooDataSet*)LAllData.reduce("id1==id2");
399     EdgeFitter::OFSample = (RooDataSet*)LAllData.reduce("id1!=id2");
400 buchmann 1.2 EdgeFitter::AllData = (RooDataSet*)LAllData.reduce("id1!=id2||id1==id2");
401    
402 buchmann 1.10 SFSample->SetName("SFSample");
403     OFSample->SetName("OFSample");
404 buchmann 1.2 AllData->SetName("AllData");
405    
406     if(EdgeFitter::MarcoDebug) {
407 buchmann 1.20 dout << "Number of (weighted) events in full sample = " << AllData->sumEntries() << " (raw events : " << AllData->numEntries() << ")" << endl;
408     dout << "Number of (weighted) events in eemm sample = " << SFSample->sumEntries() << " (raw events : " << SFSample->numEntries() << ")" << endl;
409     dout << "Number of (weighted) events in em sample = " << OFSample->sumEntries() << " (raw events : " << OFSample->numEntries() << ")" << endl;
410 buchmann 1.2 }
411 buchmann 1.6
412 buchmann 1.2 }
413    
414 buchmann 1.15 void EdgeFitter::DrawDatasetContent(int is_data) {
415 buchmann 1.20 TCanvas* cSFdata = new TCanvas("cSFdata","cSFdata") ;
416    
417 buchmann 1.15 RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
418     RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("SF sample")) ;
419     frame1->GetXaxis()->CenterTitle(1);
420     frame1->GetYaxis()->CenterTitle(1);
421     SFSample->plotOn(frame1,RooFit::Name("SFdata")) ;
422    
423     RooPlot* frame2 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ;
424     frame2->GetXaxis()->CenterTitle(1);
425     frame2->GetYaxis()->CenterTitle(1);
426     OFSample->plotOn(frame2,RooFit::Name("OFdata")) ;
427    
428 buchmann 1.20 // 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);
429     // 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);
430    
431     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);
432     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);
433    
434     TH1F *sf_fit = (TH1F*)SFSample->createHistogram("sf_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true));
435     TH1F *of_fit = (TH1F*)OFSample->createHistogram("of_fit",mll,RooFit::Binning(int((mllmax-mllmin)/5)),RooFit::SumW2Error(true));
436    
437     TLegend *leg = allsamples.allbglegend();
438     leg->AddEntry(sf_fit,"RooDataSet content","p");
439     leg->SetX1(0.58);
440    
441 buchmann 1.15 cSFdata->cd() ;
442     gPad->SetLeftMargin(0.15);
443     frame1->GetYaxis()->SetTitleOffset(1.4);
444     frame1->Draw();
445 buchmann 1.20 sf_ref->Draw("histo,same");
446     sf_fit->Draw("e1,same");
447     leg->Draw("same");
448 buchmann 1.15 if(is_data==data) DrawPrelim();
449     else DrawPrelim(PlottingSetup::luminosity,true);
450     CompleteSave(cSFdata,"Edge/SF_NoFit");
451    
452     TCanvas* cOFdata = new TCanvas("cOFdata","cOFdata") ;
453     cOFdata->cd() ;
454     gPad->SetLeftMargin(0.15);
455 buchmann 1.16 frame2->SetMaximum(frame1->GetMaximum());
456 buchmann 1.15 frame2->GetYaxis()->SetTitleOffset(1.4);
457     frame2->Draw();
458 buchmann 1.20 of_ref->Draw("histo,same");
459     of_fit->Draw("e1,same");
460     leg->Draw("same");
461 buchmann 1.15 if(is_data==data) DrawPrelim();
462     else DrawPrelim(PlottingSetup::luminosity,true);
463     CompleteSave(cOFdata,"Edge/OF_NoFit");
464 buchmann 1.20
465     delete sf_fit;
466     delete of_fit;
467    
468     delete sf_ref;
469     delete of_ref;
470    
471 buchmann 1.15 }
472    
473 buchmann 1.10 string WriteWithError(float central, float error, int digits) {
474     float ref=central;
475     if(ref<0) ref=-central;
476     int HighestSigDigit = 0;
477     if(ref>1) HighestSigDigit = int(log(ref)/log(10))+1;
478     else HighestSigDigit = int(log(ref)/(log(10)));
479    
480     float divider=pow(10.0,(double(HighestSigDigit-digits)));
481    
482     stringstream result;
483     result << divider*int(central/divider+0.5) << " #pm " << divider*int(error/divider+0.5);
484     return result.str();
485     }
486    
487    
488 buchmann 1.2 string EdgeFitter::RandomStorageFile() {
489     TRandom3 *r = new TRandom3(0);
490     int rho = (int)r->Uniform(1,10000000);
491     stringstream RandomFile;
492     RandomFile << PlottingSetup::cbafbasedir << "/exchange/TempEdgeFile_" << rho << ".root";
493     delete r;
494     return RandomFile.str();
495     }
496    
497     Yield EdgeFitter::Get_Z_estimate(float jzb_cut, int icut) {
498     if(MarcoDebug) write_error(__FUNCTION__,"Returning random Z yield");
499     Yield a(123,45,67); return a;
500     return PlottingSetup::allresults.predictions[icut].Zbkg;
501     }
502    
503     Yield EdgeFitter::Get_T_estimate(float jzb_cut, int icut) {
504     if(MarcoDebug) write_error(__FUNCTION__,"Returning random TTbar yield");
505     Yield a(1234,56,78); return a;
506     return PlottingSetup::allresults.predictions[icut].Flavorsym;
507     }
508    
509 buchmann 1.5 void EdgeFitter::DoFit(int is_data, float jzb_cut) {
510 buchmann 1.16
511     stringstream prefix;
512     if(is_data==data) prefix << "data_";
513     if(is_data==mc) prefix << "mc_";
514     if(is_data==mcwithsignal) prefix << "mcwithS_";
515    
516     prefix << EdgeFitter::Mode << "_" << jzb_cut;
517    
518    
519    
520 buchmann 1.10 RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
521 buchmann 1.6 RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
522 buchmann 1.5 RooCategory sample("sample","sample") ;
523 buchmann 1.10 sample.defineType("SF");
524 buchmann 1.5 //sample.defineType("mm");
525 buchmann 1.10 sample.defineType("OF");
526 buchmann 1.6
527 buchmann 1.10 //RooDataSet combData("combData","combined data",mll,Index(sample),Import("SF",*SFSample),Import("mm",*mmSample),Import("OF",*OFSample));
528     RooDataSet combData("combData","combined data",RooArgSet(mll,edgeWeight),RooFit::Index(sample),RooFit::Import("SF",*SFSample),RooFit::Import("OF",*OFSample),RooFit::WeightVar(edgeWeight));
529 buchmann 1.6
530 buchmann 1.5
531     //First we make a fit to opposite flavor
532 buchmann 1.10 RooRealVar fttbarOF("fttbarOF", "fttbarOF", 100, 0, 10000);
533     RooRealVar par1ttbarOF("par1ttbarOF", "par1ttbarOF", 1.6, 0.01, 4.0);
534     RooRealVar par2ttbarOF("par2ttbarOF", "par2ttbarOF", 1.0);
535     RooRealVar par3ttbarOF("par3ttbarOF", "par3ttbarOF", 0.028, 0.001, 1.0);
536     RooRealVar par4ttbarOF("par4ttbarOF", "par4ttbarOF", 2.0);
537     RooSUSYBkgPdf ttbarOF("ttbarOF","ttbarOF", mll , par1ttbarOF, par2ttbarOF, par3ttbarOF, par4ttbarOF);
538     RooAddPdf model_OF("model_OF","model_OF", ttbarOF, fttbarOF);
539 buchmann 1.5 RooSimultaneous simPdfOF("simPdfOF","simultaneous pdf", sample) ;
540 buchmann 1.10 simPdfOF.addPdf(model_OF,"OF");
541 buchmann 1.14 RooFitResult *resultOF = simPdfOF.fitTo(combData, RooFit::Save(),RooFit::Extended(),RooFit::Minos(true));
542 buchmann 1.18 dout << "============================= < OF results > =============================" << endl;
543 buchmann 1.17 resultOF->Print();
544 buchmann 1.18 dout << "============================= < /OF results > =============================" << endl;
545 buchmann 1.14
546 buchmann 1.16
547     RooPlot* frameO = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample"));
548     frameO->GetXaxis()->CenterTitle(1);
549     frameO->GetYaxis()->CenterTitle(1);
550     combData.plotOn(frameO,RooFit::Name("OFdata"),RooFit::Cut("sample==sample::OF")) ;
551     simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
552     simPdfOF.plotOn(frameO,RooFit::Slice(sample,"OF"),RooFit::Name("TTbarOFonly"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
553    
554     TCanvas* pof = new TCanvas("pof","pof") ;
555     pof->cd() ;
556     gPad->SetLeftMargin(0.15);
557     frameO->GetYaxis()->SetTitleOffset(1.4);
558     frameO->Draw();
559     if(is_data==data) DrawPrelim();
560     else DrawPrelim(PlottingSetup::luminosity,true);
561 buchmann 1.17 if(EdgeFitter::FixedMEdge>=0) CompleteSave(pof,"Edge/OF__OFFitonly_"+prefix.str()+"__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false);
562     else CompleteSave(pof,"Edge/OF__OFFitonly_"+prefix.str(),false,false);
563 buchmann 1.16 delete pof;
564    
565 buchmann 1.14 if(resultOF->covQual()!=3) {
566     write_error(__FUNCTION__,"OF fit did not converge!!! Cannot continue!");
567 buchmann 1.18 dout << "covQual is " << resultOF->covQual() << endl;
568 buchmann 1.14 EdgeFitter::FixedMEdgeChi2=-1;
569     if(EdgeFitter::RejectPointIfNoConvergence) return;
570     } else {
571     write_info(__FUNCTION__,"OF fit converged");
572     }
573 buchmann 1.11
574     float StartingMedge=70;
575     if(EdgeFitter::FixedMEdge>0) StartingMedge=EdgeFitter::FixedMEdge;
576 buchmann 1.5
577    
578 buchmann 1.18 RooDataSet *ZDataSet = (RooDataSet*)EdgeFitter::AllData->reduce("id1==id2 && abs(mll-91.2)<20");
579    
580 buchmann 1.17 float maxZ = ZDataSet->sumEntries();
581 buchmann 1.18 dout << "maxZ was set to " << maxZ << endl;
582 buchmann 1.17 delete ZDataSet;
583    
584    
585 buchmann 1.5 // Now same flavor
586 buchmann 1.17 RooRealVar fzSF("fzSF", "fzSF", 39, 39, maxZ);
587 buchmann 1.10 RooRealVar meanzSF("meanzSF", "meanzSF", 91.1876, 89, 95);
588     //RooRealVar sigmazSF("sigmazSF", "sigmazSF", 0.5);
589     RooRealVar sigmazSF("sigmazSF", "sigmazSF", 5, 0.5, 5);
590     RooRealVar widthzSF("widthzSF", "widthzSF", 2.94);
591 buchmann 1.17 widthzSF.setConstant();
592 buchmann 1.10
593     RooRealVar fttbarSF("fttbarSF", "fttbarSF", 100, 0, 100000);
594 buchmann 1.17 RooRealVar par1ttbarSF("par1ttbarSF", "par1ttbarSF", 1.02*par1ttbarOF.getVal(), (1.02-0.07)*par1ttbarOF.getVal(), (1.02+0.07)*par1ttbarOF.getVal());
595 buchmann 1.5
596 buchmann 1.18 RooRealVar fsignalSF("fsignalSF", "fsignalSF", 0, 0, 300);
597 buchmann 1.10 RooRealVar par1signalSF("par1signalSF", "par1signalSF", 45, 20, 100);
598     RooRealVar par2signalSF("par2signalSF", "par2signalSF", 2, 1, 10);
599 buchmann 1.11 RooRealVar par3signalSF("par3signalSF", "par3signalSF", StartingMedge, 0, 300);
600 buchmann 1.5
601 buchmann 1.10 RooVoigtian zSF("zSF", "zSF", mll, meanzSF, widthzSF, sigmazSF);
602 buchmann 1.5
603 buchmann 1.11 if(EdgeFitter::FixedMEdge>0) par3signalSF.setConstant();
604 buchmann 1.5
605 buchmann 1.17 RooSUSYBkgPdf ttbarSF("ttbarSF","ttbarSF", mll , par1ttbarSF, par2ttbarOF, par3ttbarOF, par4ttbarOF);
606 buchmann 1.10 RooSUSYTPdf signalSF("signalSF","signalSF", mll , par1signalSF, sigmazSF, par3signalSF);
607    
608     RooAddPdf model_SF("model_SF","model_SF", RooArgList(zSF, ttbarSF, signalSF), RooArgList(fzSF, fttbarSF, fsignalSF));
609 buchmann 1.5
610     RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ;
611 buchmann 1.10 simPdf.addPdf(model_SF,"SF") ;
612 buchmann 1.14 simPdf.addPdf(model_OF,"OF") ;
613 buchmann 1.5
614 buchmann 1.14 RooFitResult *result = simPdf.fitTo(combData, RooFit::Save(), RooFit::Extended(),RooFit::Minos(true));
615    
616     if(result->covQual()!=3) {
617     write_error(__FUNCTION__,"Full fit did not converge!!! Cannot continue!");
618 buchmann 1.18 dout << "covQual is " << result->covQual() << endl;
619 buchmann 1.14 EdgeFitter::FixedMEdgeChi2=-1;
620     if(EdgeFitter::RejectPointIfNoConvergence) return;
621     } else {
622     write_info(__FUNCTION__,"Full fit converged");
623     }
624    
625 buchmann 1.18 dout << "============================= < OF results > =============================" << endl;
626 buchmann 1.17 result->Print();
627 buchmann 1.18 dout << "============================= < /OF results > =============================" << endl;
628 buchmann 1.17
629 buchmann 1.5
630 buchmann 1.10 RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("EE sample")) ;
631     frame1->GetXaxis()->CenterTitle(1);
632 buchmann 1.14 frame1->GetYaxis()->CenterTitle(1);
633 buchmann 1.11 combData.plotOn(frame1,RooFit::Name("SFdata"),RooFit::Cut("sample==sample::SF")) ;
634     simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
635     simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("TTbarSFonly"),RooFit::Components("ttbarSF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
636     simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("DYSFonly"),RooFit::Components("zSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
637     simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("SignalSFonly"),RooFit::Components("signalSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
638    
639 buchmann 1.12 EdgeFitter::FixedMEdgeChi2 = frame1->chiSquare("FullFit", "SFdata", 3);
640 buchmann 1.11
641 buchmann 1.5
642 buchmann 1.18 dout << "Result : " << endl;
643     dout << "f signal : " << fsignalSF.getVal() << " +/- " << fsignalSF.getError() << endl;
644     dout << "f ttbar : " << fttbarSF.getVal() << " +/- " << fttbarSF.getError() << endl;
645     dout << "f tt OF : " << fttbarOF.getVal() << " +/- " << fttbarOF.getError() << endl;
646     dout << "f z SF : " << fzSF.getVal() << " +/- " << fzSF.getError() << endl;
647     dout << "#Chi^{2}/NDF : " << EdgeFitter::FixedMEdgeChi2 << endl;
648 buchmann 1.5
649     // The same plot for the cointrol sample slice
650 buchmann 1.10 RooPlot* frame3 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ;
651     frame3->GetXaxis()->CenterTitle(1);
652 buchmann 1.14 frame3->GetYaxis()->CenterTitle(1);
653 buchmann 1.10 frame3->SetMaximum(frame1->GetMaximum());
654     combData.plotOn(frame3,RooFit::Cut("sample==sample::OF")) ;
655 buchmann 1.16 simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
656     simPdf.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::Components("ttbarOF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
657 buchmann 1.5
658    
659     TCanvas* c = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf") ;
660     c->cd() ;
661     gPad->SetLeftMargin(0.15);
662     frame1->GetYaxis()->SetTitleOffset(1.4);
663     frame1->Draw();
664     if(is_data==data) DrawPrelim();
665     else DrawPrelim(PlottingSetup::luminosity,true);
666 buchmann 1.10 stringstream infotext;
667 buchmann 1.14 infotext << "#splitline{Fit results (" << EdgeFitter::Mode << ">" << jzb_cut << "): }{#splitline{";
668 buchmann 1.15 infotext << "N(Data) = " << EdgeFitter::SFSample->sumEntries() << "}{#splitline{";
669 buchmann 1.10 infotext << "N(Z+Jets) = " << WriteWithError(fzSF.getVal(),fzSF.getError(),3) << "}{#splitline{";
670     infotext << "N(t#bar{t}) = " << WriteWithError(fttbarSF.getVal(),fttbarSF.getError(),3) << "}{#splitline{";
671     infotext << "N(signal) = " << WriteWithError(fsignalSF.getVal(),fsignalSF.getError(),3) << "}{";
672     infotext << "m_{edge} = " << WriteWithError(par3signalSF.getVal(),par3signalSF.getError(),3) << "}}}}}";
673    
674     TLatex *infobox = new TLatex(0.57,0.75,infotext.str().c_str());
675     infobox->SetNDC();
676     infobox->SetTextSize(0.03);
677     infobox->Draw();
678 buchmann 1.14 if(EdgeFitter::FixedMEdge>=0) CompleteSave(c,"Edge/"+prefix.str()+"_SF__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false);
679     else CompleteSave(c,"Edge/"+prefix.str()+"_SF",false,false);
680 buchmann 1.5 delete c;
681    
682     TCanvas* e = new TCanvas("rf501_simultaneouspdfem","rf403_simultaneouspdfem") ;
683     e->cd();
684     gPad->SetLeftMargin(0.15);
685     frame3->GetYaxis()->SetTitleOffset(1.4);
686     frame3->Draw();
687     if(is_data==data) DrawPrelim();
688     else DrawPrelim(PlottingSetup::luminosity,true);
689 buchmann 1.14 if(EdgeFitter::FixedMEdge>=0) CompleteSave(e,"Edge/"+prefix.str()+"_OF__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false);
690     else CompleteSave(e,"Edge/"+prefix.str()+"_OF",false,false);
691 buchmann 1.5 delete e;
692    
693 buchmann 1.6
694    
695    
696 buchmann 1.5 /* TCanvas* f = new TCanvas("rf501_simultaneouspdfem","rf403_simultaneouspdfem") ;
697     f->cd();
698     gPad->SetLeftMargin(0.15);
699     frame4->GetYaxis()->SetTitleOffset(1.4);
700     frame4->Draw();
701     if(is_data==data) DrawPrelim();
702     else DrawPrelim(PlottingSetup::luminosity,true);
703 buchmann 1.10 CompleteSave(f,"Edge/"+prefix.str()+"_SF");
704 buchmann 1.5 delete f;*/
705 buchmann 1.7
706 buchmann 1.10
707     /*
708     float maxZ=200;
709     RooWorkspace* wspace = new RooWorkspace();
710     stringstream mllvar;
711     mllvar << "mll[" << (mllmax-mllmin)/2 << "," << mllmin << "," << mllmax << "]";
712     wspace->factory(mllvar.str().c_str());
713     wspace->var("mll")->setBins(30);
714     wspace->factory("nSig[1.,0.,100.]");
715     wspace->factory(("nZ[0.04.,0.,"+any2string(maxZ)+"]").c_str());
716     wspace->factory("rME[1.12,1.05,1.19]");
717     wspace->factory("effUncert[1.]");
718     EdgeFitter::prepareLimits(wspace, true);
719     */
720    
721     write_warning(__FUNCTION__," A lot missing here to calculate limits");
722    
723 buchmann 1.5 }
724    
725 buchmann 1.2 void EdgeFitter::DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree *signalevents=0) {
726    
727 buchmann 1.5 TCut _cut(cut&&PlottingSetup::basiccut&&PlottingSetup::passtrig);
728    
729     TFile *f = new TFile("workingfile.root","RECREATE");
730    
731     EdgeFitter::InitializeVariables(PlottingSetup::iMllLow,PlottingSetup::iMllHigh,PlottingSetup::jzbHigh,_cut);
732 buchmann 1.2
733     EdgeFitter::PrepareDatasets(is_data);
734 buchmann 1.5
735 buchmann 1.15 EdgeFitter::DrawDatasetContent(is_data);
736    
737 buchmann 1.5 RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
738     RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
739 buchmann 1.11
740    
741 buchmann 1.18 bool ScanMassRange=false;
742 buchmann 1.17 float ScanSteps=5.0;//GeV
743 buchmann 1.12
744 buchmann 1.11
745    
746     if(ScanMassRange) {
747 buchmann 1.12 TFile *fscan = new TFile("fscan.root","UPDATE");
748     TGraph *gr = new TGraph();
749     stringstream GrName;
750 buchmann 1.14 GrName << "ScanGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut;
751 buchmann 1.12 gr->SetName(GrName.str().c_str());
752    
753 buchmann 1.11 int i=0;
754 buchmann 1.17 for(float tempMedge=10;tempMedge<=300;tempMedge+=ScanSteps) {
755 buchmann 1.14 write_info(__FUNCTION__,"Now testing Medge="+any2string(tempMedge)+" for "+EdgeFitter::Mode+">"+any2string(jzb_cut));
756 buchmann 1.11 EdgeFitter::FixedMEdge=tempMedge;
757     EdgeFitter::DoFit(is_data, jzb_cut);
758 buchmann 1.14 if(EdgeFitter::FixedMEdgeChi2<0) continue;
759 buchmann 1.11 gr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2);
760 buchmann 1.12 i++;
761 buchmann 1.11 }
762    
763     TCanvas *ScanCan = new TCanvas("ScanCan","ScanCan",500,500);
764     gr->GetXaxis()->SetTitle("m_{edge}");
765     gr->GetXaxis()->CenterTitle();
766 buchmann 1.12 gr->GetYaxis()->SetTitle("#Chi^{2} / NDF");
767 buchmann 1.11 gr->GetYaxis()->CenterTitle();
768 buchmann 1.13 gr->GetYaxis()->SetTitleOffset(0.95);
769     gr->GetXaxis()->SetTitleOffset(0.9);
770     gr->SetLineColor(kBlue);
771     gr->SetTitle("");
772     gr->Draw("AL");
773 buchmann 1.11 stringstream ScanCanSave;
774 buchmann 1.14 ScanCanSave << "Edge/MEdgeScan_"+EdgeFitter::Mode+"_" << jzb_cut;
775 buchmann 1.12 if(is_data) DrawPrelim();
776     else DrawMCPrelim();
777 buchmann 1.13 CompleteSave(ScanCan,ScanCanSave.str());
778     fscan->cd();
779     gr->Write();
780 buchmann 1.11 delete ScanCan;
781 buchmann 1.12 fscan->Close();
782 buchmann 1.11 } else {
783     EdgeFitter::DoFit(is_data, jzb_cut);
784     }
785    
786    
787    
788    
789 buchmann 1.5 EdgeFitter::DoFit(is_data, jzb_cut);
790     RooMsgService::instance().setGlobalKillBelow(msglevel);
791    
792 buchmann 1.2
793     f->Close();
794    
795     }
796    
797     void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree *signalevents=0) {
798 buchmann 1.14
799     EdgeFitter::Mode="JZB";
800     if(mcjzb=="met[4]") EdgeFitter::Mode="MET";
801    
802 buchmann 1.7 for(int icut=0;icut<(int)jzb_cut.size();icut++) {
803 buchmann 1.2 stringstream addcut;
804     if(is_data==1) addcut << "(" << datajzb << ">" << jzb_cut[icut] << ")";
805     if(is_data!=1) addcut << "(" << mcjzb << ">" << jzb_cut[icut] << ")";
806     TCut jcut(addcut.str().c_str());
807    
808 buchmann 1.5
809 buchmann 1.2 EdgeFitter::DoEdgeFit(mcjzb, datajzb, DataPeakError, MCPeakError, jzb_cut[icut], icut, is_data, jcut&&cut, signalevents);
810    
811     }
812     }