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

Comparing UserCode/cbrown/Development/Plotting/Modules/ZbTools.C (file contents):
Revision 1.14 by buchmann, Mon Nov 26 12:06:26 2012 UTC vs.
Revision 1.15 by buchmann, Tue Nov 27 07:25:55 2012 UTC

# Line 30 | Line 30 | namespace ZbData {
30    
31   }
32  
33 + class ZbPointResult {
34 + public:
35 +  ZbPointResult(string var, float ptlow, float pthigh, float alphalow, float alphahigh, Value Data, Value MC);
36 +  float PtLow;
37 +  float PtHigh;
38 +  float AlphaLow;
39 +  float AlphaHigh;
40 +  string variable;
41 +  Value Data;
42 +  Value MC;
43 +  Value Ratio;
44 + };
45 +
46 + ZbPointResult::ZbPointResult(string var, float ptlow, float pthigh, float alphalow, float alphahigh, Value data, Value mc) :
47 +  variable(var), PtLow(ptlow), PtHigh(pthigh), AlphaLow(alphalow), AlphaHigh(alphahigh), Data(data), MC(mc) {
48 +    Ratio = data/mc;
49 + }
50 +  
51 + std::ostream &operator<<(std::ostream &ostr, ZbPointResult &b)
52 + {
53 +  ostr << b.PtLow << ";" << b.PtHigh << ";" << b.AlphaLow << ";" << b.AlphaHigh << ";" << b.Data.getValue() << ";" << b.Data.getError() << ";" << b.MC.getValue() << ";" << b.MC.getError() << ";" << b.Ratio.getValue() << ";" << b.Ratio.getError();
54 +  return ostr;
55 + }
56 +
57 +
58 + class ZbResultContainer {
59 + public:
60 +  string name;  
61 +  vector<ZbPointResult> MPF_Rabs_location;
62 +  Value MPF_Result_FaceValue;
63 +  Value Rabs_Result_FaceValue;
64 +  Value MPF_Result_Extrapolated;
65 +  Value Rabs_Result_Extrapolated;
66 +  
67 +  ZbResultContainer(string name);
68 +  ZbResultContainer(const ZbResultContainer &old);
69 + };
70 +
71 +
72 + ZbResultContainer::ZbResultContainer(string _name) {
73 +  name=_name;
74 +  cout<< "Result Container for \"" << name << "\" has been initialized" << endl;
75 +  
76 + }
77 +
78 + std::ostream &operator<<(std::ostream &ostr, ZbResultContainer &b)
79 + {
80 +  ostr << "Results for " << b.name << endl;
81 +  ostr << " MPF and Rabs locations: " << endl;
82 +  for(int i=0;i<b.MPF_Rabs_location.size();i++) ostr << "   " << b.MPF_Rabs_location[i] << endl;
83 +  ostr << " Results: " << endl;
84 +  ostr << "   Face Value: " << endl;
85 +  ostr << "     MPF " << b.MPF_Result_FaceValue << endl;
86 +  ostr << "     Rabs " << b.Rabs_Result_FaceValue << endl;
87 +  ostr << "   Extrapolated: " << endl;
88 +  ostr << "     MPF " << b.MPF_Result_Extrapolated << endl;
89 +  ostr << "             Rabs " << b.Rabs_Result_Extrapolated << endl;
90 +  
91 +  return ostr;
92 + }
93 +
94 +
95 +
96   using namespace ZbData;
97  
98  
# Line 101 | Line 164 | void draw_kin_variable(string variable,
164    delete ckin;
165   }
166    
104 Value getfrom2Dmap(TH2F *map, int ixbin, int iybin) {
105  Value sum(0,0);
106  for(int iy=1;iy<=iybin;iy++) {
107    sum=sum+Value(map->GetBinContent(ixbin,iy),map->GetBinError(ixbin,iy));
108  }
109  return sum;
110 }
111  
167   void print_all_b_yields() {
168    cout << "Basic selection with a b jet" << endl;
169    print_yield(ZplusBsel&&"Zb3010_pfJetGoodNumBtag>0");
# Line 134 | Line 189 | void print_all_b_yields() {
189   //  print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"(Zb3010_alpha)<0.05");
190   }  
191  
192 < void DrawEvilCutFlow() {
192 > void TEST_DrawEvilCutFlow() {
193    stringstream MegaCut;
194    
195    MegaCut << "   1*(" << (const char*) (ZplusBsel&&TCut("Zb3010_pfJetGoodNumBtag>0")) << ")";
# Line 267 | Line 322 | void draw_mpf_vars() {
322      return TMath::Median(numBins, &x, &y);
323   }*/
324  
325 < Value get_Zb_data_over_mc(string variable, string variable2, TCut cut, string saveas) {
325 > Value get_Zb_data_over_mc(ZbResultContainer &res, string variable, string variable2, TCut cut, string saveas, float pt1, float pt2, float a1, float a2) {
326   //  write_warning(__FUNCTION__,"Debugging this function, therefore always returning 3.1415+/-1.010101"); return Value(3.1415,1.010101);
327    TCanvas *cn = new TCanvas("cn","cn");
328    string varname="MPF";
# Line 276 | Line 331 | Value get_Zb_data_over_mc(string variabl
331    TH1F *hmc    = allsamples.Draw("hmc" , variable,1200,0,30, varname, "events", cut, mc,  luminosity);
332    hmc->SetLineColor(kBlue);
333    
279  
280  
281  
334    float a=hdata->GetMean();
335    float b=hmc->GetMean();
336    float da=hdata->GetMeanError();
# Line 333 | Line 385 | Value get_Zb_data_over_mc(string variabl
385    DrawPrelim();
386    CompleteSave(cn,"ResponsePlots/"+saveas);
387    
388 +  res.MPF_Rabs_location.push_back(ZbPointResult(variable,pt1,pt2,a1,a2,Value(a,da),Value(b,db)));
389    cout << "Data;" << a << ";"<<da<<";MC"<<b<<";"<<db<<endl;
390    delete cn;
391    delete hdata;
392    delete hmc;
393  
341 //    cout << a << "+/-" << da << "        " << b << "=/-" << db << endl;
342
394    return Value(factor,error);
395   }
396    
397 + ZbResultContainer new_data_mc_agreement_2d(string AlphaVariable, string ContainerName, TCut BTagCut, TCut BTagWgt) {
398 +  ZbResultContainer results(ContainerName);
399    
400 <
401 < void new_data_mc_agreement_2d() {
400 >  cutWeight=TCut("(weight*(weight<1000)*(is_data+(!is_data)))")*BTagWgt;
401 >  LeadingB=BTagCut;
402    
403    gStyle->SetOptFit(0);
404    TCut basecut(ZplusBsel&&LeadingB&&EtaB&&PhiZcut);
405 <  const int nalphacuts=6;
406 <  float alphacuts[nalphacuts] = {0.1,0.15,0.2,0.25,0.3,0.35};
405 > //  const int nalphacuts=6;
406 > //  float alphacuts[nalphacuts] = {0.1,0.15,0.2,0.25,0.3,0.35};
407 >  
408 > //  const int nptcuts=5;
409 > //  float ptcuts[nptcuts]={30,50,75,125,1000};
410 >  
411 >  write_info(__FUNCTION__,"JUST TESTING - PLEASE REMOVE THIS LINE");const int nalphacuts=2;float alphacuts[nalphacuts] = {0.1,0.3};const int nptcuts=3;float ptcuts[nptcuts]={30,75,1000};
412    
355  const int nptcuts=5;
356  float ptcuts[nptcuts]={30,50,75,125,1000};
413    
414    float MPF_Results[nalphacuts][nptcuts];
415    float MPF_Errors[nalphacuts][nptcuts];
# Line 364 | Line 420 | void new_data_mc_agreement_2d() {
420    for(int ia=0;ia<nalphacuts;ia++) {
421      for(int ipt=0;ipt<nptcuts-1;ipt++) {
422        stringstream specialcut;
423 <      if(ia>0) specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (Zb3010_alpha<" << alphacuts[ia] << " && Zb3010_alpha>" << alphacuts[ia-1] << "))";
424 <      else     specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (Zb3010_alpha<" << alphacuts[ia] << "))";
423 >      float alow,ahigh;
424 >      if(ia>0) {
425 >        specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<" << alphacuts[ia] << " && " << AlphaVariable << ">" << alphacuts[ia-1] << "))";
426 >        alow=alphacuts[ia-1];
427 >        ahigh=alphacuts[ia];
428 >      } else {
429 >        specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<" << alphacuts[ia] << "))";
430 >        alow=0;
431 >        ahigh=alphacuts[ia];
432 >      }
433        cout << specialcut.str() << endl;
434 <      Value MPF_data_over_mc = get_Zb_data_over_mc("mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(alphacuts[ia]));
435 <      Value RABS_data_over_mc = get_Zb_data_over_mc("Zb3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(alphacuts[ia]));
434 >      Value MPF_data_over_mc = get_Zb_data_over_mc(results,"mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(alphacuts[ia]), ptcuts[ipt], ptcuts[ipt+1],alow,ahigh);
435 >      Value RABS_data_over_mc = get_Zb_data_over_mc(results,"Zb3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(alphacuts[ia]), ptcuts[ipt], ptcuts[ipt+1],alow,ahigh);
436        
437        MPF_Results[ia][ipt]=MPF_data_over_mc.getValue();
438        MPF_Errors[ia][ipt]=MPF_data_over_mc.getError();
# Line 425 | Line 489 | void new_data_mc_agreement_2d() {
489      }
490      
491      stringstream specialcut;
492 <    specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (Zb3010_alpha<0.3))";
493 <    Value MPF_data_over_mc = get_Zb_data_over_mc("mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_0.3");
494 <    Value RABS_data_over_mc = get_Zb_data_over_mc("Zb3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_0.3");
492 >    specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<0.3))";
493 >    Value MPF_data_over_mc = get_Zb_data_over_mc(results,"mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_0.3",ptcuts[ipt],ptcuts[ipt+1],0,0.3);
494 >    Value RABS_data_over_mc = get_Zb_data_over_mc(results,"Zb3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_0.3",ptcuts[ipt],ptcuts[ipt+1],0,0.3);
495      cout << "About to add a point in pt (" << (ptcuts[ipt]+ptcuts[ipt+1])/2 << " ) to face value : " << MPF_data_over_mc << " (MPF) , " <<  RABS_data_over_mc << "(RABS)" << endl;
496      MPF_FaceValueAtPoint3->SetPoint(ipt,(ptcuts[ipt]+ptcuts[ipt+1])/2,MPF_data_over_mc.getValue());
497      MPF_FaceValueAtPoint3->SetPointError(ipt,0,MPF_data_over_mc.getError());
# Line 490 | Line 554 | void new_data_mc_agreement_2d() {
554      string filenamebkp=filename.str();
555      filename << "__MPF";
556      DrawPrelim();
557 <    CompleteSave(can,filename.str());
557 >    CompleteSave(can,ContainerName+"/"+filename.str());
558      cout << "MPF : " << mpf_a << " + " << mpf_b << " * alpha " << endl;
559      
560      filename.str("");
# Line 544 | Line 608 | void new_data_mc_agreement_2d() {
608      RABS_ExtraPolatedResults[ipt]=rabs_a;
609      filename << filenamebkp << "__RABS";
610      DrawPrelim();
611 <    CompleteSave(can,filename.str());
611 >    CompleteSave(can,ContainerName+"/"+filename.str());
612      cout << "RABS : " << rabs_a << " + " << rabs_b << " * alpha " << endl;
613    }
614    
# Line 578 | Line 642 | void new_data_mc_agreement_2d() {
642    
643    stringstream filename2;
644    filename2 << "Extrapolation/FINAL_RESULT_MPF";
645 <  CompleteSave(can,filename2.str());
645 >  CompleteSave(can,ContainerName+"/"+filename2.str());
646    
647    
648    RABS_FinalGraph->SetMarkerStyle(21);
# Line 606 | Line 670 | void new_data_mc_agreement_2d() {
670    
671    filename2.str("");
672    filename2 << "Extrapolation/FINAL_RESULT_RABS";
673 <  CompleteSave(can,filename2.str());
673 >  CompleteSave(can,ContainerName+"/"+filename2.str());
674    
675    can->cd();
676    MPF_FaceValueAtPoint3->SetMarkerStyle(21);
# Line 638 | Line 702 | void new_data_mc_agreement_2d() {
702    
703    filename2.str("");
704    filename2 << "Extrapolation/FINAL_RESULT_MPF_FaceValp3";
705 <  CompleteSave(can,filename2.str());
705 >  CompleteSave(can,ContainerName+"/"+filename2.str());
706    
707    can->cd();
708    RABS_FaceValueAtPoint3->SetMarkerStyle(21);
# Line 670 | Line 734 | void new_data_mc_agreement_2d() {
734    
735    filename2.str("");
736    filename2 << "Extrapolation/FINAL_RESULT_RABS_FaceValp3";
737 <  CompleteSave(can,filename2.str());
737 >  CompleteSave(can,ContainerName+"/"+filename2.str());
738    
739    cout << "FINAL RESULTS: " << endl;
740    cout << "MPF : " << MPFResult  << " +/- " << MPFResultError  << endl;
# Line 680 | Line 744 | void new_data_mc_agreement_2d() {
744    
745    delete can;
746    
747 <  
747 >  write_info(__FUNCTION__,"Need to fill result capsule");
748 >  results.MPF_Result_FaceValue=Value(FaceValResult,FaceValResultError);
749 >  results.Rabs_Result_FaceValue=Value(RABSFaceValResult,RABSFaceValResultError);
750 >  results.MPF_Result_Extrapolated=Value(MPFResult,MPFResultError);
751 >  results.Rabs_Result_Extrapolated=Value(RabsResult,RabsResultError);
752 >  cout << results << endl;
753 >  return results;
754   }
755  
756  
757 < void DoPUStudy(string identifier) {
757 > void TEST_DoPUStudy(string identifier) {
758    
759    float numVtxcuts[7]={0,10,15,20};
760    
# Line 734 | Line 804 | void DoPUStudy(string identifier) {
804    
805   }
806  
807 < void ScenarioComparison() {
807 > void TEST_ScenarioComparison() {
808   //very dumb way to do this.
809    TGraphAsymmErrors *gr[5];
810    TF1 *fit[5];
# Line 824 | Line 894 | void ScenarioComparison() {
894    
895   }
896  
897 < void ScenarioComparisonInclusive() {
897 > void TEST_ScenarioComparisonInclusive() {
898    //dumbest way ever to do this. but ok we only need to do it once.
899    TGraphAsymmErrors *gr[5];
900    TF1 *fit[5];
# Line 914 | Line 984 | void ScenarioComparisonInclusive() {
984    
985   }
986  
987 < void compare_selection(string identifier) {
987 > void TEST_compare_selection(string identifier) {
988    bool recognized_scenario=false;
989    
990    cout << "Running with identifier " << identifier << endl;
# Line 1068 | Line 1138 | void GetNumberEventsInsideOutsideAlphaWi
1138    delete mc_OUT;
1139   }
1140  
1141 < void GetNumberEventsInsideOutsideAlphaWindow() {
1141 > void TEST_GetNumberEventsInsideOutsideAlphaWindow() {
1142    TCanvas *ca = new TCanvas("ca","ca");
1143   //   GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==0"), "ee");
1144   //   GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==1"), "mm");
# Line 1107 | Line 1177 | void GetNumberEventsInsideOutsideAlphaWi
1177  
1178  
1179      
1180 < void do_basic_ZB_analysis(int do_inclusive) {
1180 > void do_basic_ZB_analysis(bool DoCompleteAnalysis) {
1181    
1182    //https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagPOG#2011_Data_and_MC
1183    //https://twiki.cern.ch/twiki/pub/CMS/BtagPOG/SFb-ttbar_payload.txt
1184    
1185    cout << "The lepton requirement is " << (const char*) leptoncut << endl;
1116  if(do_inclusive) {
1117    LeadingB=TCut("Zb3010_bTagProbCSVBP[0]>=-10000");
1118    cutWeight=TCut("(weight*(weight<1000)*(is_data+(!is_data)))");
1119    write_info(__FUNCTION__,"Inclusive selection - no btag requirement, no btag efficiency/mistag correction (weight)");
1120  } else {
1121    LeadingB=TCut("Zb3010_bTagProbCSVBP[0]>0.898");
1122    cutWeight=TCut("(weight*(weight<1000)*(is_data+(!is_data)*((id1==id2&&id1==0)*0.95+(id1==id2&&id1==1)*0.88+(id1!=id2)*0.92)*Zb3010_BTagWgt))");
1123    write_info(__FUNCTION__,"Exclusive selection - switched on btag requirement and btag efficiency/mistag correction (weight)");
1124  }
1125  
1186    bool doquick=true;
1187    
1188    TCanvas *zbcanvas = new TCanvas("zbcanvas","zbcanvas");
# Line 1151 | Line 1211 | void do_basic_ZB_analysis(int do_inclusi
1211     }
1212    
1213   //  GetNumberEventsInsideOutsideAlphaWindow();
1214 <  new_data_mc_agreement_2d();
1214 >  
1215 >  dout <<"THIS IS WHERE IT GETS REALLY INTERESTING!!!!" << endl;
1216 >  if(DoCompleteAnalysis) {
1217 >    /* need to run the following scenarios:
1218 >     * - normal
1219 >     * - inclusive
1220 >     * - medium WP
1221 >     * - alpha up
1222 >     * - alpha down
1223 >     */
1224 >    
1225 >    ZbResultContainer inclusive = new_data_mc_agreement_2d("Zb3010_alpha","inclusive",TCut("Zb3010_bTagProbCSVBP[0]>-10000"),TCut("1.0"));
1226 >    ZbResultContainer Reference = new_data_mc_agreement_2d("Zb3010_alpha","reference",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgt"));
1227 >    ZbResultContainer effmistagUp = new_data_mc_agreement_2d("Zb3010_alpha","effmistagUp",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtUp"));
1228 >    ZbResultContainer effmistagDown = new_data_mc_agreement_2d("Zb3010_alpha","effmistagDown",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtDown"));
1229 >    ZbResultContainer medium = new_data_mc_agreement_2d("Zb3010_alpha","medium",TCut("Zb3010_bTagProbCSVBP[0]>0.679"),TCut("ZbCHS3010_BTagWgtMedium"));
1230 >    ZbResultContainer AlphaUp = new_data_mc_agreement_2d("Zb3010_alphaUP","AlphaUp",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgt"));
1231 >    ZbResultContainer AlphaDown = new_data_mc_agreement_2d("Zb3010_alphaDOWN","AlphaDown",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgt"));
1232 >
1233 >    LeadingB=TCut("Zb3010_bTagProbCSVBP[0]>0.898");
1234 >  } else {
1235 >    ZbResultContainer Reference = new_data_mc_agreement_2d("Zb3010_alpha","reference",TCut("Zb3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgt"));
1236 >  }
1237 >  
1238    
1239    delete zbcanvas;
1240   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines