ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/EdgeLimit.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/EdgeLimit.C (file contents):
Revision 1.5 by buchmann, Wed Jun 27 08:53:23 2012 UTC vs.
Revision 1.14 by buchmann, Wed Jun 12 13:50:28 2013 UTC

# Line 1 | Line 1
1   #include <iostream>
2  
3 + #include <TVirtualIndex.h>
4 +
5   #include <RooRealVar.h>
6   #include <RooArgSet.h>
7   #include <RooDataSet.h>
# Line 23 | Line 25
25   #include "RooStats/HypoTestInverterOriginal.h"
26  
27   //#include "ParametrizedEdge.C"
28 < #include "/shome/pablom/RooFit/Pdfs/RooSUSYTPdf.cxx"
29 < #include "/shome/pablom/RooFit/Pdfs/RooSUSYBkgPdf.cxx"
28 > #include "EdgeModules/RooSUSYTPdf.cxx"
29 > #include "EdgeModules/RooSUSYBkgPdf.cxx"
30  
31  
32   using namespace std;
# Line 51 | Line 53 | 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 <  void getMedianLimit(RooWorkspace *ws,vector<RooDataSet*> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp);
56 >  void getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp);
57    void InitializeVariables(float _mllmin, float _mllmax, float _jzbmax, TCut _cut);
58    void PrepareDatasets(int);
59    void DoFit(int is_data, float jzb_cut);
60    string RandomStorageFile();
61    Yield Get_Z_estimate(float,int);
62    Yield Get_T_estimate(float,int);
63 <  float calcExclusion(RooWorkspace *ws, RooDataSet *data = NULL);
64 <  void prepareLimits(RooWorkspace *ws);
63 <  vector<RooDataSet*> generateToys(RooWorkspace *ws, int nToys);
63 >  float calcExclusion(RooWorkspace *ws, RooDataSet data, bool calcExclusion);
64 >  vector<RooDataSet> generateToys(RooWorkspace *ws, int nToys);
65    void prepareLimits(RooWorkspace *ws, bool ComputeBands);
66    TGraph* prepareLM(float mass, float nEv);
67    
# Line 70 | Line 71 | namespace EdgeFitter {
71    TCut cut;
72    
73    RooDataSet* AllData;
74 <  RooDataSet* eeSample;
75 <  RooDataSet* mmSample;
76 <  RooDataSet* emSample;
74 >  RooDataSet* SFSample;
75 >  RooDataSet* OFSample;
76 >  
77 >  bool MarcoDebug=true;
78 >  
79 >  float FixedMEdge=-1;
80 >  float FixedMEdgeChi2=-1;
81 >  
82 >  bool RejectPointIfNoConvergence=false;
83 >  
84 >  string Mode="UndefinedMode";
85    
77  bool MarcoDebug;
86   }
87  
88   TGraph* EdgeFitter::prepareLM(float mass, float nEv) {
# Line 93 | Line 101 | TGraph* EdgeFitter::prepareLM(float mass
101    return lm;
102   }
103  
104 < vector<RooDataSet*> EdgeFitter::generateToys(RooWorkspace *ws, int nToys) {
104 > vector<RooDataSet> EdgeFitter::generateToys(RooWorkspace *ws, int nToys) {
105 >  ws->ls();
106    ws->var("nSig")->setVal(0.);
107    ws->var("nSig")->setConstant(true);
108    RooFitResult* fit = ws->pdf("combModel")->fitTo(*ws->data("data_obs"),RooFit::Save());
109 <  vector<RooDataSet*> theToys;
109 >  vector<RooDataSet> theToys;
110    
111    RooMCStudy mcEE(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"EE"));
112    mcEE.generate(nToys,44,true);
# Line 106 | Line 115 | vector<RooDataSet*> EdgeFitter::generate
115    RooMCStudy mcOSOF(*ws->pdf("combModel"),RooArgSet(*ws->var("inv")),RooFit::Slice(*ws->cat("cat"),"OSOF"));
116    mcOSOF.generate(nToys,44,true);
117    
118 <  RooRealVar mll("mll","mll",mllmin,mllmax,"GeV/c^{2}");
118 >  RooRealVar mll("m_{ll}","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
119    RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
120    RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
121    RooRealVar jzb("jzb","jzb",-jzbmax,jzbmax,"GeV/c");
# Line 120 | Line 129 | vector<RooDataSet*> EdgeFitter::generate
129      stringstream toyname;
130      toyname << "theToy_" << i;
131      write_warning(__FUNCTION__,"Problem while adding toys");
132 < //    RooDataSet *toyData = RooDataSet(toyname.str(),toyname.str(),observables,RooFit::Index(ws->cat("cat")),RooFit::Import("OSOF",*toyOSOF),RooFit::Import("EE",*toyEE),RooFit::Import("MM",*toyMM));
133 < //    theToys.push_back(toyData);
132 >    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));
133 >    theToys.push_back(toyData);
134    }
135    ws->var("nSig")->setVal(17.0);
136    ws->var("nSig")->setConstant(false);
137    return theToys;
138   }
139  
140 < void EdgeFitter::getMedianLimit(RooWorkspace *ws,vector<RooDataSet*> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp) {
140 > void EdgeFitter::getMedianLimit(RooWorkspace *ws,vector<RooDataSet> theToys,float &median,float &sigmaDown, float &sigmaUp, float &twoSigmaDown, float &twoSigmaUp) {
141    TH1F *gauLimit = new TH1F("gausLimit","gausLimit",60,0.,80./PlottingSetup::luminosity);
142    vector<float> theLimits;
143 <  for(int itoy=0;itoy<theToys.size();itoy++) {
144 <    float theLimit = calcExclusion(ws,theToys[itoy]);
143 >  for(int itoy=0;itoy<(int)theToys.size();itoy++) {
144 >    float theLimit = calcExclusion(ws,theToys[itoy],false);
145      if(theLimit > 0 ) gauLimit->Fill(theLimit);
146    }
147    const Int_t nQ = 4;
# Line 150 | Line 159 | void EdgeFitter::getMedianLimit(RooWorks
159  
160   void EdgeFitter::prepareLimits(RooWorkspace *ws, bool ComputeBands) {
161    if(ComputeBands) {
162 <    vector<RooDataSet*> theToys = EdgeFitter::generateToys(ws,50);
162 >    vector<RooDataSet> theToys = EdgeFitter::generateToys(ws,50);
163      vector<float> medVals;
164      vector<float> medLimits;
165      vector<float> sigmaLimitsDown;
# Line 179 | Line 188 | void EdgeFitter::prepareLimits(RooWorksp
188        theVals.push_back((float)i);
189        ws->var("m0")->setVal((float)i);
190        ws->var("m0")->setConstant(true);
191 <      theLimits.push_back(calcExclusion(ws));
191 > //      theLimits.push_back(calcExclusion(ws,(RooDataSet)*ws->data("data_obs"),true));
192 >      write_error(__FUNCTION__,"Error while casting roo data set");
193      }
194      
195 <    for(int i=0;i<theLimits.size();i++) {
195 >    for(int i=0;i<(int)theLimits.size();i++) {
196        if((theLimits[i]<2.0/PlottingSetup::luminosity)||(theLimits[i]>40.0/PlottingSetup::luminosity)) {
197          cout << i << " : " << theVals[i] << endl;
198          theLimits[i] = (theLimits[i+2]+theLimits[i-2])/2.0;
# Line 194 | Line 204 | void EdgeFitter::prepareLimits(RooWorksp
204   }
205    
206  
207 < float EdgeFitter::calcExclusion(RooWorkspace *ws, RooDataSet *data) {
207 > float EdgeFitter::calcExclusion(RooWorkspace *ws, RooDataSet data, bool LoadDataObs) {
208 >  int numberOfToys=50;
209    RooRealVar mu("mu","nSig",0,10000,"");
210    RooArgSet poi = RooArgSet(mu);
211    RooArgSet *nullParams = (RooArgSet*)poi.snapshot();
# Line 203 | Line 214 | float EdgeFitter::calcExclusion(RooWorks
214    model->SetWorkspace(*ws);
215    model->SetPdf("combModel");
216    model->SetParametersOfInterest(poi);
217 <  if(!data) data = (RooDataSet*)ws->data("data_obs");
217 > //  if(LoadDataObs) data = (RooDataSet)*ws->data("data_obs");
218  
219 <  RooStats::ProfileLikelihoodCalculator plc(*data, *model);
219 >  RooStats::ProfileLikelihoodCalculator plc(data, *model);
220    plc.SetNullParameters(*nullParams);
221    plc.SetTestSize(0.05);
222 +  
223    RooStats::LikelihoodInterval* interval = plc.GetInterval();
224    RooStats::HypoTestResult *htr = plc.GetHypoTest();
225    double theLimit = interval->UpperLimit( mu );
226 <  cout << "Significance " << htr->Significance() << endl;
226 > //  double significance = htr->Significance();
227    
228    ws->defineSet("obs","nB");
229    ws->defineSet("poi","nSig");
# Line 235 | Line 247 | float EdgeFitter::calcExclusion(RooWorks
247    slrts.SetAltParameters(*sb_model.GetSnapshot());
248    RooStats::ProfileLikelihoodTestStat profll = RooStats::ProfileLikelihoodTestStat(*b_model.GetPdf());
249    
250 <  RooStats::HybridCalculatorOriginal hc = RooStats::HybridCalculatorOriginal(*data, sb_model, b_model,0,0);
250 >  RooStats::HybridCalculatorOriginal hc = RooStats::HybridCalculatorOriginal(data, sb_model, b_model,0,0);
251    hc.SetTestStatistic(2);
252 <  hc.SetNumberOfToys(50);
252 >  hc.SetNumberOfToys(numberOfToys);
253    
254    RooStats::HypoTestInverterOriginal hcInv =  RooStats::HypoTestInverterOriginal(hc,*ws->var("nSig"));
255    hcInv.SetTestSize(0.05);
# Line 260 | Line 272 | TTree* SkimTree(int isample) {
272      cout << "   Original tree contains " << allsamples.collection[isample].events->GetEntries() << endl;
273      cout << "   Going to reduce it with cut " << EdgeFitter::cut << endl;
274    }
275 +  float edgeWeight;
276 +  newTree->Branch("edgeWeight",&edgeWeight,"edgeWeight/F");
277 +  float tmll;
278 +  allsamples.collection[isample].events->SetBranchAddress("mll",&tmll);
279 + //  int id1,id2;
280 +  
281    TTreeFormula *select = new TTreeFormula("select", EdgeFitter::cut, allsamples.collection[isample].events);
282 +  TTreeFormula *Weight = new TTreeFormula("Weight", cutWeight, allsamples.collection[isample].events);
283    float wgt=1.0;
284 <  allsamples.collection[isample].events->SetBranchAddress(cutWeight,&wgt);
284 > //  allsamples.collection[isample].events->SetBranchAddress(cutWeight,&wgt);
285    for (Int_t entry = 0 ; entry < allsamples.collection[isample].events->GetEntries() ; entry++) {
286     allsamples.collection[isample].events->LoadTree(entry);
287     if (select->EvalInstance()) {
288       allsamples.collection[isample].events->GetEntry(entry);
289 <     wgt=wgt*xsweight;
289 >     wgt=Weight->EvalInstance();
290 >     edgeWeight=wgt*xsweight;
291       newTree->Fill();
292     }
293    }
# Line 282 | Line 302 | void EdgeFitter::InitializeVariables(flo
302    jzbmax=_jzbmax;
303    cut=_cut;
304   }
305 <  
305 >
306 > TTree* MergeTrees(vector<TTree*> trees) {
307 >  TTree * newtree = (TTree*)trees[0]->CloneTree();
308 >  trees[0]->GetListOfClones()->Remove(newtree);
309 >  trees[0]->ResetBranchAddresses();
310 >  newtree->ResetBranchAddresses();
311 >  
312 >  for(int itree=1;itree<trees.size();itree++) {
313 >    newtree->CopyAddresses(trees[itree]);
314 >    Long64_t nentries = trees[itree]->GetEntries();
315 >    for (Long64_t iEntry=0;iEntry<nentries;iEntry++) {
316 >      trees[itree]->GetEntry(iEntry);
317 >      newtree->Fill();
318 >    }
319 >    trees[itree]->ResetBranchAddresses(); // Disconnect from new tree
320 >    if (newtree->GetTreeIndex()) {
321 >      newtree->GetTreeIndex()->Append(trees[itree]->GetTreeIndex(),kTRUE);
322 >    }
323 >    if (newtree && newtree->GetTreeIndex()) {
324 >      newtree->GetTreeIndex()->Append(0,kFALSE); // Force the sorting
325 >    }
326 >  }
327 >  return newtree;
328 > }
329 >    
330 >      
331 >
332   void EdgeFitter::PrepareDatasets(int is_data) {
287  TTree *completetree;
333    write_warning(__FUNCTION__,"Need to make this function ready for scans as well (use signal from scan samples)");
334 <  bool hashit=0;
335 <  for(int isample=0;isample<allsamples.collection.size();isample++) {
334 > //  TFile *tempout = new TFile("tempout.root","RECREATE");
335 >  vector<TTree*> SkimmedTrees;
336 >  TTree *SkimmedTree[(int)allsamples.collection.size()];
337 >  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
338      if(!allsamples.collection[isample].is_active) continue;
339      if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
340      if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
341      if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC
342      if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it.
343      if(EdgeFitter::MarcoDebug) cout << "Considering : " << allsamples.collection[isample].samplename << endl;
344 <    if(!hashit) {
345 <      hashit=true;
346 <      completetree = SkimTree(isample)->CloneTree();
347 <    } else {
348 <      completetree->CopyEntries(SkimTree(isample));
349 <    }
350 <    if(EdgeFitter::MarcoDebug) cout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl;
344 >    SkimmedTrees.push_back(SkimTree(isample));
345 > //      SkimmedTree[isample] = SkimTree(isample);
346 > //    tempout->cd();
347 > //    SkimmedTree[isample]->Write();
348 > //    treelist->Add(SkimmedTree[isample]);
349 >    //treelist->Add(SkimTree(isample));
350 > //    allsamples.collection[isample].tfile->Close();
351    }
352    
353 <  RooRealVar mll("mll","mll",mllmin,mllmax,"GeV/c^{2}");
353 >  TTree *completetree  = MergeTrees(SkimmedTrees);
354 >  
355 > //  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;
360 >  
361 >  RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
362    RooRealVar id1("id1","id1",0,1,"GeV/c^{2}");
363    RooRealVar id2("id2","id2",0,1,"GeV/c^{2}");
364 <  RooRealVar jzb("jzb","jzb",-jzbmax,jzbmax,"GeV/c");
365 <  RooRealVar weight("weight","weight",0,1000,"");
311 <  RooArgSet observables(mll,jzb,id1,id2,weight);
364 >  RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
365 >  RooArgSet observables(mll,id1,id2,edgeWeight);
366    
367    string title="CMS Data";
368    if(is_data!=1) title="CMS SIMULATION";
369 <  RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","weight");
369 >  RooDataSet LAllData("LAllData",title.c_str(),completetree,observables,"","edgeWeight");
370    completetree->Write();
371 < //  delete completetree;
371 >  delete completetree;
372 > //  tempout->Close();
373    
374 <  EdgeFitter::eeSample = (RooDataSet*)LAllData.reduce("id1==id2");
375 <  EdgeFitter::mmSample = (RooDataSet*)LAllData.reduce("id1==id2");
321 <  EdgeFitter::emSample = (RooDataSet*)LAllData.reduce("id1!=id2");
374 >  EdgeFitter::SFSample = (RooDataSet*)LAllData.reduce("id1==id2");
375 >  EdgeFitter::OFSample = (RooDataSet*)LAllData.reduce("id1!=id2");
376    EdgeFitter::AllData  = (RooDataSet*)LAllData.reduce("id1!=id2||id1==id2");
377    
378 <  eeSample->SetName("eeSample");
379 <  mmSample->SetName("mmSample");
326 <  emSample->SetName("emSample");
378 >  SFSample->SetName("SFSample");
379 >  OFSample->SetName("OFSample");
380    AllData->SetName("AllData");
381    
382    if(EdgeFitter::MarcoDebug) {
383      cout << "Number of events in data sample = " << AllData->numEntries() << endl;
384 <    cout << "Number of events in ee sample = " << eeSample->numEntries() << endl;
385 <    cout << "Number of events in mm sample = " << mmSample->numEntries() << endl;
333 <    cout << "Number of events in em sample = " << emSample->numEntries() << endl;
384 >    cout << "Number of events in eemm sample = " << SFSample->numEntries() << endl;
385 >    cout << "Number of events in em sample = " << OFSample->numEntries() << endl;
386    }
387 +  
388 + }
389 +
390 + string WriteWithError(float central, float error, int digits) {
391 +  float ref=central;
392 +  if(ref<0) ref=-central;
393 +  int HighestSigDigit = 0;
394 +  if(ref>1) HighestSigDigit = int(log(ref)/log(10))+1;
395 +  else HighestSigDigit = int(log(ref)/(log(10)));
396 +  
397 +  float divider=pow(10.0,(double(HighestSigDigit-digits)));
398 +  
399 +  stringstream result;
400 +  result << divider*int(central/divider+0.5) << " #pm " << divider*int(error/divider+0.5);
401 +  return result.str();
402   }
403  
404 +
405   string EdgeFitter::RandomStorageFile() {
406    TRandom3 *r = new TRandom3(0);
407    int rho = (int)r->Uniform(1,10000000);
# Line 356 | Line 424 | Yield EdgeFitter::Get_T_estimate(float j
424   }
425  
426   void EdgeFitter::DoFit(int is_data, float jzb_cut) {
427 <  RooRealVar mll("mll","mll",mllmin,mllmax,"GeV/c^{2}");
427 >  RooRealVar mll("mll","m_{ll}",mllmin,mllmax,"GeV/c^{2}");
428 >  RooRealVar edgeWeight("edgeWeight","edgeWeight",0,1000,"");
429    RooCategory sample("sample","sample") ;
430 <  sample.defineType("ee");
430 >  sample.defineType("SF");
431    //sample.defineType("mm");
432 <  sample.defineType("em");
433 <  //RooDataSet combData("combData","combined data",mll,Index(sample),Import("ee",*eeSample),Import("mm",*mmSample),Import("em",*emSample));
434 <  RooDataSet combData("combData","combined data",mll,RooFit::Index(sample),RooFit::Import("ee",*eeSample),RooFit::Import("em",*emSample));
432 >  sample.defineType("OF");
433 >  
434 >  //RooDataSet combData("combData","combined data",mll,Index(sample),Import("SF",*SFSample),Import("mm",*mmSample),Import("OF",*OFSample));
435 >  RooDataSet combData("combData","combined data",RooArgSet(mll,edgeWeight),RooFit::Index(sample),RooFit::Import("SF",*SFSample),RooFit::Import("OF",*OFSample),RooFit::WeightVar(edgeWeight));
436 >  
437    
367
368
438    //First we make a fit to opposite flavor
439 <  RooRealVar fttbarem("fttbarem", "fttbarem", 100, 0, 10000);
440 <  RooRealVar par1ttbarem("par1ttbarem", "par1ttbarem", 1.6, 0.01, 4.0);
441 <  RooRealVar par2ttbarem("par2ttbarem", "par2ttbarem", 1.0);
442 <  RooRealVar par3ttbarem("par3ttbarem", "par3ttbarem", 0.028, 0.001, 1.0);
443 <  RooRealVar par4ttbarem("par4ttbarem", "par4ttbarem", 2.0);
444 <  RooSUSYBkgPdf ttbarem("ttbarem","ttbarem", mll , par1ttbarem, par2ttbarem, par3ttbarem, par4ttbarem);
445 <  RooAddPdf model_em("model_em","model_em", ttbarem, fttbarem);
439 >  RooRealVar fttbarOF("fttbarOF", "fttbarOF", 100, 0, 10000);
440 >  RooRealVar par1ttbarOF("par1ttbarOF", "par1ttbarOF", 1.6, 0.01, 4.0);
441 >  RooRealVar par2ttbarOF("par2ttbarOF", "par2ttbarOF", 1.0);
442 >  RooRealVar par3ttbarOF("par3ttbarOF", "par3ttbarOF", 0.028, 0.001, 1.0);
443 >  RooRealVar par4ttbarOF("par4ttbarOF", "par4ttbarOF", 2.0);
444 >  RooSUSYBkgPdf ttbarOF("ttbarOF","ttbarOF", mll , par1ttbarOF, par2ttbarOF, par3ttbarOF, par4ttbarOF);
445 >  RooAddPdf model_OF("model_OF","model_OF", ttbarOF, fttbarOF);
446    RooSimultaneous simPdfOF("simPdfOF","simultaneous pdf", sample) ;
447 <  simPdfOF.addPdf(model_em,"em");
448 <  RooFitResult *resultOF = simPdfOF.fitTo(combData, RooFit::Save());
449 <  resultOF->Print();
447 >  simPdfOF.addPdf(model_OF,"OF");
448 >  RooFitResult *resultOF = simPdfOF.fitTo(combData, RooFit::Save(),RooFit::Extended(),RooFit::Minos(true));
449 >  //resultOF->Print();
450 >  
451 >  if(resultOF->covQual()!=3) {
452 >    write_error(__FUNCTION__,"OF fit did not converge!!! Cannot continue!");
453 >    cout << "covQual is " << resultOF->covQual() << endl;
454 >    EdgeFitter::FixedMEdgeChi2=-1;
455 >    if(EdgeFitter::RejectPointIfNoConvergence) return;
456 >  } else {
457 >    write_info(__FUNCTION__,"OF fit converged");
458 >  }
459  
460 <  RooRealVar* resultOFpar1_ = (RooRealVar*) resultOF->floatParsFinal().find("par1ttbarem");
460 >  RooRealVar* resultOFpar1_ = (RooRealVar*) resultOF->floatParsFinal().find("par1ttbarOF");
461    float resultOFpar1 = resultOFpar1_->getVal();
462 <  //RooRealVar* resultOFpar2_ = (RooRealVar*) resultOF->floatParsFinal().find("par2ttbarem");
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("par3ttbarem");
466 >  RooRealVar* resultOFpar3_ = (RooRealVar*) resultOF->floatParsFinal().find("par3ttbarOF");
467    float resultOFpar3 = resultOFpar3_->getVal();
468  
469 <  //RooRealVar* resultOFpar4_ = (RooRealVar*) resultOF->floatParsFinal().find("par4ttbarem");
469 >  //RooRealVar* resultOFpar4_ = (RooRealVar*) resultOF->floatParsFinal().find("par4ttbarOF");
470    //float resultOFpar4 = resultOFpar4_->getVal();
471    //cout << "caca4.txt" << endl;
472 +  
473 +  float StartingMedge=70;
474 +  if(EdgeFitter::FixedMEdge>0) StartingMedge=EdgeFitter::FixedMEdge;
475  
476  
477    // Now same flavor  
478 <  RooRealVar fzee("fzee", "fzee", 5, 0, 100000);
479 <  RooRealVar meanzee("meanzee", "meanzee", 91.1876, 89, 95);
480 <  //RooRealVar sigmazee("sigmazee", "sigmazee", 0.5);
481 <  RooRealVar sigmazee("sigmazee", "sigmazee", 5, 0, 100);
482 <  RooRealVar widthzee("widthzee", "widthzee", 2.94);
483 <  
484 <  RooRealVar fttbaree("fttbaree", "fttbaree", 100, 0, 100000);
485 <  RooRealVar par1ttbaree("par1ttbaree", "par1ttbaree", resultOFpar1, 0, 100);
486 <  RooRealVar par2ttbaree("par2ttbaree", "par2ttbaree", 1.0);
487 <  RooRealVar par3ttbaree("par3ttbaree", "par3ttbaree", resultOFpar3, 0, 100);
488 <  RooRealVar par4ttbaree("par4ttbaree", "par4ttbaree", 2.0);
478 >  RooRealVar fzSF("fzSF", "fzSF", 5, 0, 100000);
479 >  RooRealVar meanzSF("meanzSF", "meanzSF", 91.1876, 89, 95);
480 >  //RooRealVar sigmazSF("sigmazSF", "sigmazSF", 0.5);
481 >  RooRealVar sigmazSF("sigmazSF", "sigmazSF", 5, 0.5, 5);
482 >  RooRealVar widthzSF("widthzSF", "widthzSF", 2.94);
483 >  
484 >  RooRealVar fttbarSF("fttbarSF", "fttbarSF", 100, 0, 100000);
485 >  RooRealVar par1ttbarSF("par1ttbarSF", "par1ttbarSF", 1.02*resultOFpar1, 0, 100);
486 >  RooRealVar par2ttbarSF("par2ttbarSF", "par2ttbarSF", 1.0);
487 >  RooRealVar par3ttbarSF("par3ttbarSF", "par3ttbarSF", resultOFpar3, 0, 100);
488 >  RooRealVar par4ttbarSF("par4ttbarSF", "par4ttbarSF", 2.0);
489  
490 <  RooRealVar fsignalee("fsignalee", "fsignalee", 10, 0, 400);
491 <  RooRealVar par1signalee("par1signalee", "par1signalee", 45, 20, 100);
492 <  RooRealVar par2signalee("par2signalee", "par2signalee", 2, 1, 10);
493 <  RooRealVar par3signalee("par3signalee", "par3signalee", 45, 0, 200);
494 <
495 <  RooVoigtian zee("zee", "zee", mll, meanzee, widthzee, sigmazee);
496 <
497 <  
498 <  RooSUSYBkgPdf ttbaree("ttbaree","ttbaree", mll , par1ttbaree, par2ttbaree, par3ttbaree, par4ttbaree);
499 <  //RooSUSYTPdf signalee("signalee","signalee", mll , par1signalee, par2signalee, par3signalee);
500 <  RooSUSYTPdf signalee("signalee","signalee", mll , par1signalee, sigmazee, par3signalee);
501 <
502 <  //RooAddPdf model_ee("model_ee","model_ee", RooArgList(zee, ttbaree, signalee), RooArgList(fzee, fttbaree, fsignalee));
503 <  RooAddPdf model_ee("model_ee","model_ee", RooArgList(zee, ttbaree, signalee), RooArgList(fzee, fttbaree, fsignalee));
504 <  RooAddPdf model_emu("model_emu","model_emu", RooArgList(ttbaree), RooArgList(fttbaree));
490 >  RooRealVar fsignalSF("fsignalSF", "fsignalSF", 10, 0, 300);
491 >  RooRealVar par1signalSF("par1signalSF", "par1signalSF", 45, 20, 100);
492 >  RooRealVar par2signalSF("par2signalSF", "par2signalSF", 2, 1, 10);
493 >  RooRealVar par3signalSF("par3signalSF", "par3signalSF", StartingMedge, 0, 300);
494 >
495 >  RooVoigtian zSF("zSF", "zSF", mll, meanzSF, widthzSF, sigmazSF);
496 >
497 >  if(EdgeFitter::FixedMEdge>0) par3signalSF.setConstant();
498 >  
499 > /*  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);
507 >  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 >  
514 >
515 >  //RooAddPdf model_SF("model_SF","model_SF", RooArgList(zSF, ttbarSF, signalSF), RooArgList(fzSF, fttbarSF, fsignalSF));
516 >  RooAddPdf model_SF("model_SF","model_SF", RooArgList(zSF, ttbarSF, signalSF), RooArgList(fzSF, fttbarSF, fsignalSF));
517 >  RooAddPdf model_OF("model_OF","model_OF", RooArgList(ttbarSF), RooArgList(fttbarSF));
518  
519    
520    RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ;
521 <  simPdf.addPdf(model_ee,"ee") ;
522 <  simPdf.addPdf(model_emu,"em") ;
521 >  simPdf.addPdf(model_SF,"SF") ;
522 >  simPdf.addPdf(model_OF,"OF") ;
523  
524 <  RooFitResult *result = simPdf.fitTo(combData, RooFit::Save());
431 <  result->Print();
524 >  RooFitResult *result = simPdf.fitTo(combData, RooFit::Save(), RooFit::Extended(),RooFit::Minos(true));
525    
526 <  RooPlot* frame1 = mll.frame(RooFit::Bins(25),RooFit::Title("EE sample")) ;
527 <  combData.plotOn(frame1,RooFit::Cut("sample==sample::ee")) ;
528 <  simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
529 <  simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Components("ttbaree"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
530 <  simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Components("zee"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
531 <  simPdf.plotOn(frame1,RooFit::Slice(sample,"ee"),RooFit::Components("signalee"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
532 <
533 <  RooPlot* frame2 = mll.frame(RooFit::Bins(25),RooFit::Title("MM sample")) ;
441 <  combData.plotOn(frame2,RooFit::Cut("sample==sample::mm")) ;
442 <  simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
443 <  simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Components("ttbarmm"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
444 <  simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Components("zmm"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
445 <  simPdf.plotOn(frame2,RooFit::Slice(sample,"mm"),RooFit::Components("signalmm"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kGreen));
526 >  if(result->covQual()!=3) {
527 >    write_error(__FUNCTION__,"Full fit did not converge!!! Cannot continue!");
528 >    cout << "covQual is " << result->covQual() << endl;
529 >    EdgeFitter::FixedMEdgeChi2=-1;
530 >    if(EdgeFitter::RejectPointIfNoConvergence) return;
531 >  } else {
532 >    write_info(__FUNCTION__,"Full fit converged");
533 >  }
534  
535 + //  result->Print();
536 +  
537 +  RooPlot* frame1 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("EE sample")) ;
538 +  frame1->GetXaxis()->CenterTitle(1);
539 +  frame1->GetYaxis()->CenterTitle(1);
540 +  combData.plotOn(frame1,RooFit::Name("SFdata"),RooFit::Cut("sample==sample::SF")) ;
541 +  simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("FullFit"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
542 +  simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("TTbarSFonly"),RooFit::Components("ttbarSF"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
543 +  simPdf.plotOn(frame1,RooFit::Slice(sample,"SF"),RooFit::Name("DYSFonly"),RooFit::Components("zSF"), RooFit::ProjWData(sample, combData), RooFit::LineStyle(kDashed), RooFit::LineColor(kRed));
544 +  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 +  
548    
549    cout << "Result   : " << endl;
550 <  cout << "f signal : " << fsignalee.getVal() << " +/- " << fsignalee.getError() << endl;
551 <  cout << "f ttbar  : " << fttbaree.getVal() << " +/- " << fttbaree.getError() << endl;
552 <  cout << "f tt em  : " << fttbarem.getVal() << " +/- " << fttbarem.getError() << endl;
553 <  cout << "f z ee   : " << fzee.getVal() << " +/- " << fzee.getError() << endl;
550 >  cout << "f signal : " << fsignalSF.getVal() << " +/- " << fsignalSF.getError() << endl;
551 >  cout << "f ttbar  : " << fttbarSF.getVal() << " +/- " << fttbarSF.getError() << endl;
552 >  cout << "f tt OF  : " << fttbarOF.getVal() << " +/- " << fttbarOF.getError() << endl;
553 >  cout << "f z SF   : " << fzSF.getVal() << " +/- " << fzSF.getError() << endl;
554 >  cout << "#Chi^{2}/NDF     : " << EdgeFitter::FixedMEdgeChi2 << endl;
555    
556    // The same plot for the cointrol sample slice
557 <  RooPlot* frame3 = mll.frame(RooFit::Bins(25),RooFit::Title("EM sample")) ;
558 <  combData.plotOn(frame3,RooFit::Cut("sample==sample::em")) ;
559 <  simPdfOF.plotOn(frame3,RooFit::Slice(sample,"em"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
560 <  simPdfOF.plotOn(frame3,RooFit::Slice(sample,"em"),RooFit::Components("ttbarem"),RooFit::ProjWData(sample,combData),RooFit::LineStyle(kDashed)) ;
557 >  RooPlot* frame3 = mll.frame(RooFit::Bins(int((mllmax-mllmin)/5.0)),RooFit::Title("OF sample")) ;
558 >  frame3->GetXaxis()->CenterTitle(1);
559 >  frame3->GetYaxis()->CenterTitle(1);
560 >  frame3->SetMaximum(frame1->GetMaximum());
561 >  combData.plotOn(frame3,RooFit::Cut("sample==sample::OF")) ;
562 >  simPdfOF.plotOn(frame3,RooFit::Slice(sample,"OF"),RooFit::ProjWData(sample,combData), RooFit::LineColor(kBlack)) ;
563 >  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 << "JZB_" << jzb_cut;
571 >  prefix << EdgeFitter::Mode << "_" << jzb_cut;
572    
467 /*  cout << "fsignalee : " << fsignalee << endl;
468  cout << "fttbaree : " << fttbaree << endl;
469  cout << "fzee : " << fzee << endl;*/
573    
574    
575    TCanvas* c = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf") ;
# Line 476 | Line 579 | void EdgeFitter::DoFit(int is_data, floa
579    frame1->Draw();
580    if(is_data==data) DrawPrelim();
581    else DrawPrelim(PlottingSetup::luminosity,true);
582 <  CompleteSave(c,"Edge/"+prefix.str()+"eemm");
582 >  stringstream infotext;
583 >  infotext << "#splitline{Fit results (" << EdgeFitter::Mode << ">" << jzb_cut << "): }{#splitline{";
584 >  infotext << "N(Data) = " << EdgeFitter::SFSample->numEntries() << "}{#splitline{";
585 >  infotext << "N(Z+Jets) = " << WriteWithError(fzSF.getVal(),fzSF.getError(),3) << "}{#splitline{";
586 >  infotext << "N(t#bar{t}) = " << WriteWithError(fttbarSF.getVal(),fttbarSF.getError(),3) << "}{#splitline{";
587 >  infotext << "N(signal) = " << WriteWithError(fsignalSF.getVal(),fsignalSF.getError(),3) << "}{";
588 >  infotext << "m_{edge} = " << WriteWithError(par3signalSF.getVal(),par3signalSF.getError(),3) << "}}}}}";  
589 >
590 >  TLatex *infobox = new TLatex(0.57,0.75,infotext.str().c_str());
591 >  infobox->SetNDC();
592 >  infobox->SetTextSize(0.03);
593 >  infobox->Draw();
594 >  if(EdgeFitter::FixedMEdge>=0) CompleteSave(c,"Edge/"+prefix.str()+"_SF__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false);
595 >  else CompleteSave(c,"Edge/"+prefix.str()+"_SF",false,false);
596    delete c;
597    
482  TCanvas* d = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf") ;
483  d->cd() ;
484  gPad->SetLeftMargin(0.15);
485  frame2->GetYaxis()->SetTitleOffset(1.4);
486  frame2->Draw();
487  if(is_data==data) DrawPrelim();
488  else DrawPrelim(PlottingSetup::luminosity,true);
489  CompleteSave(d,"Edge/"+prefix.str()+"mm");
490  delete d;
491  //c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw();
492  
598    TCanvas* e = new TCanvas("rf501_simultaneouspdfem","rf403_simultaneouspdfem") ;
599    e->cd();
600    gPad->SetLeftMargin(0.15);
# Line 497 | Line 602 | void EdgeFitter::DoFit(int is_data, floa
602    frame3->Draw();
603    if(is_data==data) DrawPrelim();
604    else DrawPrelim(PlottingSetup::luminosity,true);
605 <  CompleteSave(e,"Edge/"+prefix.str()+"emu");
605 >  if(EdgeFitter::FixedMEdge>=0) CompleteSave(e,"Edge/"+prefix.str()+"_OF__MEdgeFix_"+any2string(EdgeFitter::FixedMEdge),false,false);
606 >  else CompleteSave(e,"Edge/"+prefix.str()+"_OF",false,false);
607    delete e;
608    
609 +  
610 +  
611 +  
612   /*  TCanvas* f = new TCanvas("rf501_simultaneouspdfem","rf403_simultaneouspdfem") ;
613    f->cd();
614    gPad->SetLeftMargin(0.15);
# Line 507 | Line 616 | void EdgeFitter::DoFit(int is_data, floa
616    frame4->Draw();
617    if(is_data==data) DrawPrelim();
618    else DrawPrelim(PlottingSetup::luminosity,true);
619 <  CompleteSave(f,"Edge/"+prefix.str()+"eemm");
619 >  CompleteSave(f,"Edge/"+prefix.str()+"_SF");
620    delete f;*/
621 <  
621 >
622 >
623 > /*
624 >  float maxZ=200;
625 >  RooWorkspace* wspace = new RooWorkspace();
626 >  stringstream mllvar;
627 >  mllvar << "mll[" << (mllmax-mllmin)/2 << "," << mllmin << "," << mllmax << "]";
628 >  wspace->factory(mllvar.str().c_str());
629 >  wspace->var("mll")->setBins(30);
630 >  wspace->factory("nSig[1.,0.,100.]");
631 >  wspace->factory(("nZ[0.04.,0.,"+any2string(maxZ)+"]").c_str());
632 >  wspace->factory("rME[1.12,1.05,1.19]");
633 >  wspace->factory("effUncert[1.]");
634 >  EdgeFitter::prepareLimits(wspace, true);
635 > */
636 >
637 > write_warning(__FUNCTION__," A lot missing here to calculate limits");
638 >
639   }
640  
641   void EdgeFitter::DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, float jzb_cut, int icut, int is_data, TCut cut, TTree *signalevents=0) {
# Line 524 | Line 650 | void EdgeFitter::DoEdgeFit(string mcjzb,
650    
651    RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
652    RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
653 +  
654 +  
655 +  bool ScanMassRange=false;
656 +  
657 +  
658 +  
659 +  if(ScanMassRange) {
660 +    TFile *fscan = new TFile("fscan.root","UPDATE");
661 +    TGraph *gr = new TGraph();
662 +    stringstream GrName;
663 +    GrName << "ScanGraphFor_" << EdgeFitter::Mode << "_" << jzb_cut;
664 +    gr->SetName(GrName.str().c_str());
665 +
666 +    int i=0;
667 +    for(float tempMedge=10;tempMedge<=300;tempMedge+=5.0) {
668 +      write_info(__FUNCTION__,"Now testing Medge="+any2string(tempMedge)+" for "+EdgeFitter::Mode+">"+any2string(jzb_cut));
669 +      EdgeFitter::FixedMEdge=tempMedge;
670 +      EdgeFitter::DoFit(is_data, jzb_cut);
671 +      if(EdgeFitter::FixedMEdgeChi2<0) continue;
672 +      gr->SetPoint(i,tempMedge,EdgeFitter::FixedMEdgeChi2);
673 +      i++;
674 +    }
675 +    
676 +    TCanvas *ScanCan = new TCanvas("ScanCan","ScanCan",500,500);
677 +    gr->GetXaxis()->SetTitle("m_{edge}");
678 +    gr->GetXaxis()->CenterTitle();
679 +    gr->GetYaxis()->SetTitle("#Chi^{2} / NDF");
680 +    gr->GetYaxis()->CenterTitle();
681 +    gr->GetYaxis()->SetTitleOffset(0.95);
682 +    gr->GetXaxis()->SetTitleOffset(0.9);
683 +    gr->SetLineColor(kBlue);
684 +    gr->SetTitle("");
685 +    gr->Draw("AL");
686 +    stringstream ScanCanSave;
687 +    ScanCanSave << "Edge/MEdgeScan_"+EdgeFitter::Mode+"_" << jzb_cut;
688 +    if(is_data) DrawPrelim();
689 +    else DrawMCPrelim();
690 +    CompleteSave(ScanCan,ScanCanSave.str());
691 +    fscan->cd();
692 +    gr->Write();
693 +    delete ScanCan;
694 +    fscan->Close();
695 +  } else {
696 +    EdgeFitter::DoFit(is_data, jzb_cut);
697 +  }
698 +  
699 +      
700 +  
701 +  
702    EdgeFitter::DoFit(is_data, jzb_cut);
703    RooMsgService::instance().setGlobalKillBelow(msglevel);
704  
# Line 533 | Line 708 | void EdgeFitter::DoEdgeFit(string mcjzb,
708   }
709  
710   void DoEdgeFit(string mcjzb, string datajzb, float DataPeakError, float MCPeakError, vector<float> jzb_cut, int is_data, TCut cut, TTree *signalevents=0) {
711 <  for(int icut=0;icut<jzb_cut.size();icut++) {
711 >  
712 >  EdgeFitter::Mode="JZB";
713 >  if(mcjzb=="met[4]") EdgeFitter::Mode="MET";
714 >  
715 >  for(int icut=0;icut<(int)jzb_cut.size();icut++) {
716      stringstream addcut;
717      if(is_data==1) addcut << "(" << datajzb << ">" << jzb_cut[icut] << ")";
718      if(is_data!=1) addcut << "(" << mcjzb << ">" << jzb_cut[icut] << ")";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines