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

Comparing UserCode/cbrown/Development/Plotting/Modules/ShapeLimit.C (file contents):
Revision 1.4 by buchmann, Wed Apr 25 12:59:53 2012 UTC vs.
Revision 1.9 by buchmann, Fri May 4 11:47:57 2012 UTC

# Line 38 | Line 38 | const char* strip_flip_away(string flipp
38    return flipped_name.c_str();
39   }
40  
41 < void prepare_limit_datacard(string RunDirectory, TFile *f, float uJSU, float uPDF, int flipped) {
42 < TH1F *dataob;
43 < if(flipped) dataob = (TH1F*)f->Get("flipped_data_obs");
44 < else dataob = (TH1F*)f->Get("data_obs");
45 < TH1F *signal;
46 <
47 < if(flipped) signal = (TH1F*)f->Get("flipped_signal");
48 < else signal = (TH1F*)f->Get("signal");
49 <
50 < TH1F *background1;
51 < if(flipped) background1 = (TH1F*)f->Get("flipped_TTbarBackground");
52 < else background1 = (TH1F*)f->Get("TTbarBackground");
53 <
54 < TH1F *background2;
55 < if(flipped) background2 = (TH1F*)f->Get("flipped_ZJetsBackground");
56 < else background2 = (TH1F*)f->Get("ZJetsBackground");
41 > void EliminateNegativeEntries(TH1F *histo) {
42 >  for(int i=1;i<=histo->GetNbinsX();i++) {
43 >    if(histo->GetBinContent(i)<0) histo->SetBinContent(i,0);
44 >  }
45 > }
46 >
47 > void prepare_limit_datacard(string RunDirectory, TFile *f, float uJSU, float uPDF) {
48 > TH1F *dataob = (TH1F*)f->Get("data_obs");
49 > TH1F *signal = (TH1F*)f->Get("signal");
50 > TH1F *Tbackground = (TH1F*)f->Get("TTbarBackground");
51 > TH1F *Zbackground  = (TH1F*)f->Get("ZJetsBackground");
52  
53   assert(dataob);
54   assert(signal);
55 < assert(background1);
56 < assert(background2);
55 > assert(Tbackground);
56 > assert(Zbackground);
57  
63 ofstream datacard;
64 write_warning(__FUNCTION__,"Need to rethink systematics we want to use !");
65 datacard.open ((RunDirectory+"/susydatacard.txt").c_str());
66 datacard << "Writing this to a file.\n";
67 datacard << "imax 1\n"; // number of channels
68 datacard << "jmax 2\n"; // number of backgrounds (Z+Jets prediction and TTbar prediction)
69 datacard << "kmax *\n"; // number of nuisance parameters (sources of systematic uncertainties)
70 datacard << "---------------\n";
71 datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
72 datacard << "---------------\n";
73 datacard << "bin 1\n";
74 datacard << "observation "<<dataob->Integral()<<"\n";
75 datacard << "------------------------------\n";
76 datacard << "bin             1          1          1\n";
77 datacard << "process         signal     TTbarBackground     ZJetsBackground\n";
78 datacard << "process         0          1          2\n";
79 datacard << "rate            "<<signal->Integral()<<"         "<<background1->Integral()<<"         "<<background2->Integral()<<"\n";
80 datacard << "--------------------------------\n";
81 datacard << "lumi     lnN    " << 1+ PlottingSetup::lumiuncert << "       -       -    luminosity uncertainty\n"; // only affects MC -> signal!
82 datacard << "Stat   shape    -          1          -    statistical uncertainty (ttbar)\n";
83 datacard << "Stat   shape    -          -          1    statistical uncertainty (zjets)\n";
84 datacard << "Sys    shape    -          1          -    systematic uncertainty on ttbar\n";
85 datacard << "Sys    shape    -          -          1    systematic uncertainty on zjets\n";
86 datacard << "Stat   shape    1          -          -    statistical uncertainty (signal)\n";
87 datacard << "JES    shape    1          -          -    uncertainty on Jet Energy Scale\n";
88 datacard << "JSU      lnN    " << 1+uJSU << "          -          -    JZB Scale Uncertainty\n";
89 if(uPDF>0) datacard << "PDF      lnN    " << 1+uPDF << "          -          -    uncertainty from PDFs\n";
58  
59 < // datacard << "peak   shape    1          1    uncertainty on signal resolution.
60 < datacard.close();
59 > if(FullMCAnalysis) {
60 >   //dealing with MC analysis - need to use shapes.
61 >   write_warning(__FUNCTION__,"Not correctly implemented yet for MC");
62 >   ofstream datacard;
63 >   write_warning(__FUNCTION__,"Need to rethink systematics we want to use !");
64 >   datacard.open ((RunDirectory+"/susydatacard.txt").c_str());
65 >   datacard << "Writing this to a file.\n";
66 >   datacard << "imax 1\n"; // number of channels
67 >   datacard << "jmax 2\n"; // number of backgrounds (Z+Jets prediction and TTbar prediction)
68 >   datacard << "kmax *\n"; // number of nuisance parameters (sources of systematic uncertainties)
69 >   datacard << "---------------\n";
70 >   datacard << "shapes * * limitfile.root $PROCESS $PROCESS_$SYSTEMATIC\n";
71 >   datacard << "---------------\n";
72 >   datacard << "bin 1\n";
73 >   datacard << "observation "<<dataob->Integral()<<"\n";
74 >   datacard << "------------------------------\n";
75 >   datacard << "bin             1          1          1\n";
76 >   datacard << "process         signal     TTbarBackground     ZJetsBackground\n";
77 >   datacard << "process         0          1          2\n";
78 >   datacard << "rate            "<<signal->Integral()<<"         "<<Tbackground->Integral()<<"         "<<Zbackground->Integral()<<"\n";
79 >   datacard << "--------------------------------\n";
80 >   datacard << "lumi     lnN    " << 1+ PlottingSetup::lumiuncert << "       -       -    luminosity uncertainty\n"; // only affects MC -> signal!
81 >   datacard << "Stat   shape    -          1          -    statistical uncertainty (ttbar)\n";
82 >   datacard << "Stat   shape    -          -          1    statistical uncertainty (zjets)\n";
83 >   datacard << "Sys    shape    -          1          -    systematic uncertainty on ttbar\n";
84 >   datacard << "Sys    shape    -          -          1    systematic uncertainty on zjets\n";
85 >   datacard << "Stat   shape    1          -          -    statistical uncertainty (signal)\n";
86 >   datacard << "JES    shape    1          -          -    uncertainty on Jet Energy Scale\n";
87 >   datacard << "JSU      lnN    " << 1+uJSU << "          -          -    JZB Scale Uncertainty\n";
88 >   if(uPDF>0) datacard << "PDF      lnN    " << 1+uPDF << "          -          -    uncertainty from PDFs\n";
89 >   datacard.close();
90 > } else {
91 >   //doing mutibin analysis
92 >   ofstream datacard;
93 >   write_warning(__FUNCTION__,"Need to rethink systematics we want to use !");
94 >   datacard.open ((RunDirectory+"/susydatacard.txt").c_str());
95 >   datacard << "Writing this to a file.\n";
96 >   datacard << "imax " << dataob->GetNbinsX() << "\n"; // number of channels
97 >   datacard << "jmax 2\n"; // number of backgrounds (Z+Jets prediction and TTbar prediction)
98 >   datacard << "kmax *\n"; // number of nuisance parameters (sources of systematic uncertainties)
99 >   datacard << "---------------\n";
100 >   datacard << "bin\t";
101 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << dataob->GetBinLowEdge(i) << "to" << dataob->GetBinLowEdge(i)+dataob->GetBinWidth(i) << " \t";
102 >   datacard << "\n";
103 >   datacard << "observation\t";
104 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << dataob->GetBinContent(i) << " \t";
105 >   datacard<<"\n";
106 >   datacard << "------------------------------\n";
107 >   datacard << "bin\t";
108 >   for(int i=1;i<=dataob->GetNbinsX();i++) {
109 >     datacard << " " << dataob->GetBinLowEdge(i) << "to" << dataob->GetBinLowEdge(i)+dataob->GetBinWidth(i) << "\t" <<
110 >                 " " << dataob->GetBinLowEdge(i) << "to" << dataob->GetBinLowEdge(i)+dataob->GetBinWidth(i) << "\t" <<
111 >                 " " << dataob->GetBinLowEdge(i) << "to" << dataob->GetBinLowEdge(i)+dataob->GetBinWidth(i) << "\t";
112 >   }
113 >   datacard << "\n";
114 >   datacard << "process\t";
115 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << "\t signal \t TTbarBackground \t ZJetsBackground";
116 >   datacard << "\n";
117 >   datacard << "process\t";
118 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << "\t 0 \t 1 \t 2";
119 >   datacard << "\n";
120 >  
121 >  
122 >   datacard << "rate\t";
123 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << "\t " << signal->GetBinContent(i) << " \t " << Tbackground->GetBinContent(i) << " \t " << Zbackground->GetBinContent(i) << "\t";
124 >   datacard<<"\n";
125 >  
126 >   datacard << "--------------------------------\n";
127 >  
128 >  
129 >   datacard << "lumi     lnN    \t";
130 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << 1+ PlottingSetup::lumiuncert << "\t - \t -";
131 >   datacard << "       luminosity uncertainty\n"; // only affects MC -> signal!
132 >  
133 >   // Statistical uncertainty
134 >   datacard << "Stat     lnN    \t";
135 >   for(int i=1;i<=dataob->GetNbinsX();i++) {
136 >     //Signal
137 >     float central = signal->GetBinContent(i);
138 >     float up      = ((TH1F*)f->Get("signal_StatDown"))->GetBinContent(i);
139 >     float down    = ((TH1F*)f->Get("signal_StatUp"))->GetBinContent(i);
140 >     float suncert=0;
141 >     if(central>0) {
142 >       if(abs(up-central)>abs(down-central)) suncert=abs(up-central)/central;
143 >       else suncert=abs(central-down)/central;
144 >     }
145 >
146 >     //TTbar
147 >     central = Tbackground->GetBinContent(i);
148 >     up      = ((TH1F*)f->Get("TTbarBackground_StatUp"))->GetBinContent(i);
149 >     down    = ((TH1F*)f->Get("TTbarBackground_StatDown"))->GetBinContent(i);
150 >     float tuncert=0;
151 >     if(central>0) {
152 >       if(abs(up-central)>abs(down-central)) tuncert=abs(up-central)/central;
153 >       else tuncert=abs(central-down)/central;
154 >     }
155 >     //ZJets
156 >     central = Zbackground->GetBinContent(i);
157 >     up      = ((TH1F*)f->Get("ZJetsBackground_StatUp"))->GetBinContent(i);
158 >     down    = ((TH1F*)f->Get("ZJetsBackground_StatDown"))->GetBinContent(i);
159 >     float zuncert=0;
160 >     if(central>0) {
161 >       if(abs(up-central)>abs(down-central)) zuncert=abs(up-central)/central;
162 >       else zuncert=abs(central-down)/central;
163 >     }
164 >     datacard << " " << 1+suncert << " \t " << 1+tuncert << "\t " << 1+zuncert << " \t ";
165 >   }
166 >  
167 >   datacard << "       statistical uncertainty\n";
168 >  
169 >   // Statistical uncertainty
170 >   datacard << "Sys     lnN    \t";
171 >   for(int i=1;i<=dataob->GetNbinsX();i++) {
172 >     float central = Tbackground->GetBinContent(i);
173 >     float up      = ((TH1F*)f->Get("TTbarBackground_SysUp"))->GetBinContent(i);
174 >     float down    = ((TH1F*)f->Get("TTbarBackground_SysDown"))->GetBinContent(i);
175 >     float tuncert=0;
176 >     if(central>0) {
177 >       if(abs(up-central)>abs(down-central)) tuncert=abs(up-central)/central;
178 >       else tuncert=abs(central-down)/central;
179 >     }
180 >     central = Zbackground->GetBinContent(i);
181 >     up      = ((TH1F*)f->Get("ZJetsBackground_SysUp"))->GetBinContent(i);
182 >     down    = ((TH1F*)f->Get("ZJetsBackground_SysDown"))->GetBinContent(i);
183 >     float zuncert=0;
184 >     if(central>0) {
185 >       if(abs(up-central)>abs(down-central)) zuncert=abs(up-central)/central;
186 >       else zuncert=abs(central-down)/central;
187 >     }
188 >     datacard << " - \t " << 1+tuncert << "\t " << 1+zuncert << " \t ";
189 >   }
190 >  
191 >   datacard << "       systematic uncertainty\n";
192 >  
193 >  
194 >   float JESup = ((TH1F*)f->Get("signal_JESUp"))->Integral();
195 >   float JESdn = ((TH1F*)f->Get("signal_JESDown"))->Integral();
196 >   float central = signal->Integral();
197 >   float uJES=0;
198 >   if(abs(JESup-central)>abs(JESdn-central)) uJES=abs(JESup-central)/central;
199 >   else uJES=abs(central-JESdn)/central;
200 >   datacard << "JES    lnN";
201 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << 1+uJES << "\t - \t  - \t";
202 >   datacard << "uncertainty on Jet Energy Scale\n";
203 >  
204 >   datacard << "JSU      lnN    ";
205 >   for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << 1+uJSU << "\t - \t  - \t";
206 >   datacard << "JZB Scale Uncertainty\n";
207 >  
208 >   if(uPDF>0) {
209 >     datacard << "PDF      lnN    ";
210 >     for(int i=1;i<=dataob->GetNbinsX();i++) datacard << " " << 1+uPDF << "\t - \t - \t";
211 >     datacard << "uncertainty from PDFs\n";
212 >   }
213 >  
214 >   datacard.close();
215 > }
216 >  
217   }
218  
219   float QuickDrawNevents=0;
# Line 122 | Line 246 | TH1F* QuickDraw(TTree *events, string hn
246    return histo;
247   }
248  
125 /*void do_stat_up(TH1F *h, float sign=1.0) {
126  for(int i=1;i<=h->GetNbinsX();i++) {
127    h->SetBinContent(i,h->GetBinContent(i)+sign*h->GetBinError(i));
128  }
129  h->Write();
130 }
131
132 void do_stat_dn(TH1F *h) {
133  do_stat_up(h,-1.0);
134 }*/
249  
250   void SQRT(TH1F *h) {
251    for (int i=1;i<=h->GetNbinsX();i++) {
# Line 176 | Line 290 | void generate_shapes_for_systematic(bool
290    }
291      
292    if(signalonly) {
293 <    cout << "Processing a signal with mcjzb: " << mcjzb << " (identifier: " << identifier << ")" << endl;
293 >    dout << "Processing a signal with mcjzb: " << mcjzb << " (identifier: '" << identifier << "')" << endl;
294      TH1F *ZOSSFP = QuickDraw(signalevents,"ZOSSFP",mcjzb,binning,     "JZB", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,addcut,mc,luminosity,xsec);
295      TH1F *ZOSOFP = QuickDraw(signalevents,"ZOSOFP",mcjzb,binning,     "JZB", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,addcut,mc,luminosity,xsec);
296      TH1F *ZOSSFN = QuickDraw(signalevents,"ZOSSFN","-"+mcjzb,binning, "JZB", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,addcut,mc,luminosity,xsec);
# Line 208 | Line 322 | void generate_shapes_for_systematic(bool
322      Lobs->Add(ZOSSFP);
323      Lpred->Add(ZOSSFN);
324      
325 <    cout << "SITUATION FOR SIGNAL: " << endl;
326 <    cout << " OSSF     JZB> 0 : " << ZOSSFP->Integral() << "     JZB < 0 :" << ZOSSFN->Integral() << endl;
327 <    cout << " OSOF     JZB> 0 : " << ZOSOFP->Integral() << "     JZB < 0 :" << ZOSOFN->Integral() << endl;
325 >    dout << "SITUATION FOR SIGNAL: " << endl;
326 >    dout << " OSSF     JZB> 0 : " << ZOSSFP->Integral() << "     JZB < 0 :" << ZOSSFN->Integral() << endl;
327 >    dout << " OSOF     JZB> 0 : " << ZOSOFP->Integral() << "     JZB < 0 :" << ZOSOFN->Integral() << endl;
328      if(PlottingSetup::RestrictToMassPeak) {
329 <      cout << " OSSF SB  JZB> 0 : " << SBOSSFP->Integral() << "     JZB < 0 :" << SBOSSFN->Integral() << endl;
330 <      cout << " OSOF SB  JZB> 0 : " << SBOSOFP->Integral() << "     JZB < 0 :" << SBOSOFN->Integral() << endl;
329 >      dout << " OSSF SB  JZB> 0 : " << SBOSSFP->Integral() << "     JZB < 0 :" << SBOSSFN->Integral() << endl;
330 >      dout << " OSOF SB  JZB> 0 : " << SBOSOFP->Integral() << "     JZB < 0 :" << SBOSOFN->Integral() << endl;
331      }
332  
333      
# Line 267 | Line 381 | void generate_shapes_for_systematic(bool
381        
382        for(int i=1;i<=signalStatDn->GetNbinsX();i++) {
383          float staterr = TMath::Sqrt(Lpred->GetBinContent(i) + Lobs->GetBinContent(i));
384 <        cout << "Stat err in bin " << i << " : " << staterr << endl;
385 <        cout << "    prediction: " << Lpred->GetBinContent(i) << " , observation: " << Lobs->GetBinContent(i) << " --> signal: " << signal->GetBinContent(i) << endl;
386 <        cout << "    we obtain : " << signal->GetBinContent(i)-staterr << " , " << signal->GetBinContent(i)+staterr << endl;
387 <        signalStatDn->SetBinContent(i,signal->GetBinContent(i)-staterr);
384 >        dout << "Stat err in bin " << i << " : " << staterr << endl;
385 >        dout << "    prediction: " << Lpred->GetBinContent(i) << " , observation: " << Lobs->GetBinContent(i) << " --> signal: " << signal->GetBinContent(i) << endl;
386 >        dout << "    we obtain : " << signal->GetBinContent(i)-staterr << " , " << signal->GetBinContent(i)+staterr << endl;
387 >        if(signal->GetBinContent(i)-staterr>0) signalStatDn->SetBinContent(i,signal->GetBinContent(i)-staterr);
388 >        else signalStatDn->SetBinContent(i,0);
389          signalStatUp->SetBinContent(i,signal->GetBinContent(i)+staterr);
390          signal->SetBinError(i,staterr);
391        }
# Line 291 | Line 406 | void generate_shapes_for_systematic(bool
406        
407        for(int i=1;i<=flippedsignalStatDn->GetNbinsX();i++) {
408          float staterr = TMath::Sqrt(flippedLpred->GetBinContent(i) + flippedLobs->GetBinContent(i));
409 <        flippedsignalStatDn->SetBinContent(i,flippedsignal->GetBinContent(i)-staterr);
409 >        if(flippedsignal->GetBinContent(i)-staterr>0) flippedsignalStatDn->SetBinContent(i,flippedsignal->GetBinContent(i)-staterr);
410 >        else flippedsignalStatDn->SetBinContent(i,0);
411          flippedsignalStatUp->SetBinContent(i,flippedsignal->GetBinContent(i)+staterr);
412          flippedsignal->SetBinError(i,staterr);
413        }
# Line 323 | Line 439 | void generate_shapes_for_systematic(bool
439    
440      
441    if(dataonly) {
442 <    cout << "Processing data with datajzb: " << datajzb << endl;
442 >    dout << "Processing data with datajzb: " << datajzb << endl;
443      TH1F *ZOSSFP = allsamples.Draw("ZOSSFP",datajzb,binning, "JZB", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,data,luminosity);
444      TH1F *ZOSOFP = allsamples.Draw("ZOSOFP",datajzb,binning, "JZB", "events",cutmass&&cutOSOF&&limitnJetcut&&basiccut,data,luminosity);
445      TH1F *ZOSSFN = allsamples.Draw("ZOSSFN","-"+datajzb,binning, "JZB", "events",cutmass&&cutOSSF&&limitnJetcut&&basiccut,data,luminosity);
# Line 457 | Line 573 | void generate_shapes_for_systematic(bool
573        SQRT(predstaterr);
574        TH1F *bgStatUp = (TH1F*)pred->Clone("background_StatUp");
575        bgStatUp->Add(predstaterr);
576 +      EliminateNegativeEntries(bgStatUp);
577        bgStatUp->Write();
578        TH1F *bgStatDn = (TH1F*)pred->Clone("background_StatDown");
579        bgStatDn->Add(predstaterr,-1);
580 +      EliminateNegativeEntries(bgStatDn);
581        bgStatDn->Write();
582   //      delete bgStatDn;
583   //      delete bgStatUp;
# Line 476 | Line 594 | void generate_shapes_for_systematic(bool
594        SQRT(flippedpredstaterr);
595        TH1F *fbgStatUp = (TH1F*)flippedpred->Clone("flipped_background_StatUp");
596        fbgStatUp->Add(predstaterr);
597 +      EliminateNegativeEntries(fbgStatUp);
598        fbgStatUp->Write();
599        TH1F *fbgStatDn = (TH1F*)flippedpred->Clone("flipped_background_StatDown");
600        fbgStatDn->Add(predstaterr,-1);
601 +      EliminateNegativeEntries(fbgStatDn);
602        fbgStatDn->Write();
603   //      delete fbgStatDn;
604   //      delete fbgStatUp;
# Line 491 | Line 611 | void generate_shapes_for_systematic(bool
611        SQRT(Tpredstaterr);
612        TH1F *TpredStatUp = (TH1F*)Tpred->Clone("TTbarBackground_StatUp");
613        TpredStatUp->Add(Tpredstaterr);
614 +      EliminateNegativeEntries(TpredStatUp);
615        TpredStatUp->Write();
616        TH1F *TpredStatDn = (TH1F*)Tpred->Clone("TTbarBackground_StatDown");
617        TpredStatDn->Add(Tpredstaterr,-1);
618 +      EliminateNegativeEntries(TpredStatDn);
619        TpredStatDn->Write();
620   //      delete TpredStatDn;
621   //      delete TpredStatUp;
# Line 506 | Line 628 | void generate_shapes_for_systematic(bool
628        SQRT(fTpredstaterr);
629        TH1F *fTpredStatUp = (TH1F*)flippedTpred->Clone("flipped_TTbarBackground_StatUp");
630        fTpredStatUp->Add(fTpredstaterr);
631 +      EliminateNegativeEntries(fTpredStatUp);
632        fTpredStatUp->Write();
633        TH1F *fTpredStatDn = (TH1F*)flippedTpred->Clone("flipped_TTbarBackground_StatDown");
634        fTpredStatDn->Add(fTpredstaterr,-1);
635 +      EliminateNegativeEntries(fTpredStatDn);
636        fTpredStatDn->Write();
637   //      delete fTpredStatDn;
638   //      delete fTpredStatUp;
# Line 522 | Line 646 | void generate_shapes_for_systematic(bool
646        SQRT(Zpredstaterr);
647        TH1F *ZpredStatUp = (TH1F*)Zpred->Clone("ZJetsBackground_StatUp");
648        ZpredStatUp->Add(Zpredstaterr);
649 +      EliminateNegativeEntries(ZpredStatUp);
650        ZpredStatUp->Write();
651        TH1F *ZpredStatDn = (TH1F*)Zpred->Clone("ZJetsBackground_StatDown");
652        ZpredStatDn->Add(Zpredstaterr,-1);
653 +      EliminateNegativeEntries(ZpredStatDn);
654        ZpredStatDn->Write();
655   //      delete ZpredStatDn;
656   //      delete ZpredStatUp;
# Line 537 | Line 663 | void generate_shapes_for_systematic(bool
663        SQRT(fTpredstaterr);
664        TH1F *fZpredStatUp = (TH1F*)flippedZpred->Clone("flipped_ZJetsBackground_StatUp");
665        fZpredStatUp->Add(fZpredstaterr);
666 +      EliminateNegativeEntries(fZpredStatUp);
667        fZpredStatUp->Write();
668        TH1F *fZpredStatDn = (TH1F*)flippedZpred->Clone("flipped_ZJetsBackground_StatDown");
669        fZpredStatDn->Add(fZpredstaterr,-1);
670 +      EliminateNegativeEntries(fZpredStatDn);
671        fZpredStatDn->Write();
672   //      delete fZpredStatDn;
673   //      delete fZpredStatUp;
# Line 559 | Line 687 | void generate_shapes_for_systematic(bool
687        SQRT(predsyserr);
688        TH1F *bgSysUp = (TH1F*)pred->Clone("background_SysUp");
689        bgSysUp->Add(predsyserr);
690 +      EliminateNegativeEntries(bgSysUp);
691        bgSysUp->Write();
692        TH1F *bgSysDn = (TH1F*)pred->Clone("background_SysDown");
693        bgSysDn->Add(predsyserr,-1);
694 +      EliminateNegativeEntries(bgSysDn);
695        bgSysDn->Write();
696        delete predsyserr;
697        
# Line 577 | Line 707 | void generate_shapes_for_systematic(bool
707        SQRT(fpredsyserr);
708        TH1F *fbgSysUp = (TH1F*)flippedpred->Clone("flipped_background_SysUp");
709        fbgSysUp->Add(fpredsyserr);
710 +      EliminateNegativeEntries(fbgSysUp);
711        fbgSysUp->Write();
712        TH1F *fbgSysDn = (TH1F*)flippedpred->Clone("flipped_background_SysDown");
713        fbgSysDn->Add(fpredsyserr,-1);
714 +      EliminateNegativeEntries(fbgSysDn);
715        fbgSysDn->Write();
716        delete fpredsyserr;
717        
# Line 592 | Line 724 | void generate_shapes_for_systematic(bool
724        SQRT(Tpredsyserr);
725        TH1F *TpredSysUp = (TH1F*)Tpred->Clone("TTbarBackground_SysUp");
726        TpredSysUp->Add(Tpredsyserr);
727 +      EliminateNegativeEntries(TpredSysUp);
728        TpredSysUp->Write();
729        TH1F *TpredSysDn = (TH1F*)Tpred->Clone("TTbarBackground_SysDown");
730        TpredSysDn->Add(Tpredsyserr,-1);
731 +      EliminateNegativeEntries(TpredSysDn);
732        TpredSysDn->Write();
733        delete Tpredsyserr;
734        
# Line 606 | Line 740 | void generate_shapes_for_systematic(bool
740        SQRT(fTpredsyserr);
741        TH1F *fTpredSysUp = (TH1F*)flippedTpred->Clone("flipped_TTbarBackground_SysUp");
742        fTpredSysUp->Add(fTpredsyserr);
743 +      EliminateNegativeEntries(fTpredSysUp);
744        fTpredSysUp->Write();
745        TH1F *fTpredSysDn = (TH1F*)flippedTpred->Clone("flipped_TTbarBackground_SysDown");
746        fTpredSysDn->Add(fTpredsyserr,-1);
747 +      EliminateNegativeEntries(fTpredSysDn);
748        fTpredSysDn->Write();
749        delete fTpredsyserr;
750        
# Line 623 | Line 759 | void generate_shapes_for_systematic(bool
759        SQRT(Zpredsyserr);
760        TH1F *ZpredSysUp = (TH1F*)Zpred->Clone("ZJetsBackground_SysUp");
761        ZpredSysUp->Add(Zpredsyserr);
762 +      EliminateNegativeEntries(ZpredSysUp);
763        ZpredSysUp->Write();
764        TH1F *ZpredSysDn = (TH1F*)Zpred->Clone("ZJetsBackground_SysDown");
765        ZpredSysDn->Add(Zpredsyserr,-1);
766 +      EliminateNegativeEntries(ZpredSysDn);
767        ZpredSysDn->Write();
768        delete Zpredsyserr;
769        
# Line 638 | Line 776 | void generate_shapes_for_systematic(bool
776        SQRT(fZpredsyserr);
777        TH1F *fZpredSysUp = (TH1F*)flippedZpred->Clone("flipped_ZJetsBackground_SysUp");
778        fZpredSysUp->Add(fZpredsyserr);
779 +      EliminateNegativeEntries(fZpredSysUp);
780        fZpredSysUp->Write();
781        TH1F *fZpredSysDn = (TH1F*)flippedZpred->Clone("flipped_ZJetsBackground_SysDown");
782        fZpredSysDn->Add(fZpredsyserr,-1);
783 +      EliminateNegativeEntries(fZpredSysDn);
784        fZpredSysDn->Write();
785        delete fZpredsyserr;
786      }
787      
788   /*if(identifier=="") {
789    for(int i=0;i<binning.size()-1;i++) {
790 <    cout << "[ " << binning[i] << " , " << binning[i+1] << "] : O " << obs->GetBinContent(i+1) << " P " << pred->GetBinContent(i+1) << " (Z: " << Zpred->GetBinContent(i+1) << " , T: " << Tpred->GetBinContent(i+1) << ")" << endl;
790 >    dout << "[ " << binning[i] << " , " << binning[i+1] << "] : O " << obs->GetBinContent(i+1) << " P " << pred->GetBinContent(i+1) << " (Z: " << Zpred->GetBinContent(i+1) << " , T: " << Tpred->GetBinContent(i+1) << ")" << endl;
791    }
792   }*/
793      delete ZOSSFP;
# Line 679 | Line 819 | ShapeDroplet LimitsFromShapes(bool asymp
819    
820    ensure_directory_exists(RunDirectory);
821    
822 <  TFile *datafile = new TFile("../StoredShapes.root","READ");
822 >  TFile *datafile = new TFile((PlottingSetup::cbafbasedir+"/DistributedModelCalculations/StoredShapes.root").c_str(),"READ");
823    if(datafile->IsZombie()) {
824      write_error(__FUNCTION__,"Fatal error: The stored shapes are not available!");
825      assert(!datafile->IsZombie());
826    }
827 <  cout << "Run Directory: " << RunDirectory << endl;
827 >  dout << "Run Directory: " << RunDirectory << endl;
828    TFile *limfile = new TFile((RunDirectory+"/PRElimitfile.root").c_str(),"RECREATE");
829    
830    TIter nextkey(datafile->GetListOfKeys());
# Line 717 | Line 857 | ShapeDroplet LimitsFromShapes(bool asymp
857    bool docomplicatedmSUGRAxsreweighting=false; //if you modify this value please also adapt it in Systematics.C not only here in ShapeLimit.C
858    
859    MCefficiency(events,mceff,mcefferr,flipped,mcjzb,requireZ,Neventsinfile,SUSYScanSpace::SUSYscantype,xsec,addcut,-1);
860 <  if(mceff<0) flipped=1;
860 >  if(mceff<0) {
861 >    flipped=1;
862 >    write_info(__FUNCTION__,"Doing flipping!");
863 >  }
864    doJZBscale(events,SUSYScanSpace::SUSYscantype==mSUGRA&&docomplicatedmSUGRAxsreweighting,xsec,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,flipped,requireZ,addcut);
865    float PDFuncert=0;
866    int NPdfs = get_npdfs(events);
# Line 763 | Line 906 | ShapeDroplet LimitsFromShapes(bool asymp
906        obj->Write();
907    }
908  
909 <  prepare_limit_datacard(RunDirectory,final_limfile,JZBscale,PDFuncert,flipped);
909 >  prepare_limit_datacard(RunDirectory,final_limfile,JZBscale,PDFuncert);
910    
911    final_limfile->Close();
912    limfile->Close();
# Line 773 | Line 916 | ShapeDroplet LimitsFromShapes(bool asymp
916      if(firstGuess>0) command << "bash CreateModel.sh " << RunDirectory << " susydatacard.txt" << " 1 0 0 " << firstGuess; // ASYMPTOTIC LIMITS WITH FIRST GUESS
917      else command << "bash CreateModel.sh " << RunDirectory << " susydatacard.txt" << " 0 0 0 0"; // ASYMPTOTIC LIMITS
918    }
919 <  else command << "bash CreateModel.sh " << RunDirectory << " susydatacard.txt" << " 2 0 " << int(0.5 * firstGuess) << " " << int(2*firstGuess); // ASYMPTOTIC LIMITS
919 >  else command << "bash CreateModel.sh " << RunDirectory << " susydatacard.txt" << " 2 0 " << int(0.333 * firstGuess) << " " << int(firstGuess); // ASYMPTOTIC LIMITS
920    dout <<"Going to run : " << command.str() << endl;
921    int CreatedModelFileExitCode = gSystem->Exec(command.str().c_str());
922 <  cout << "exit code of limit algorithm (CreateModel.sh) : " << CreatedModelFileExitCode << endl;
923 <  assert(CreatedModelFileExitCode==0);
922 >  dout << "exit code of limit algorithm (CreateModel.sh) : " << CreatedModelFileExitCode << endl;
923 >  if(!(CreatedModelFileExitCode==0)) {
924 >    write_warning(__FUNCTION__,"Something bad happened. It looks like a shape analysis is not the way to go. ");
925 >    ShapeDroplet alpha;
926 >    alpha.observed=-12345; // this is the flag to say watch out something went wrong with the signal ...
927 >    alpha.SignalIntegral=1;
928 >    return alpha;
929 >  }
930    ShapeDroplet alpha;
931    alpha.readDroplet(RunDirectory+"/ShapeDropletResult.txt");
932    alpha.PDF=PDFuncert;
# Line 787 | Line 936 | ShapeDroplet LimitsFromShapes(bool asymp
936    dout << alpha << endl;
937  
938    dout << "Everything is saved in " << RunDirectory << endl;
939 <  dout << "Will transfer model and datacard over for possible post-processing" << endl;
940 <  dout << "   1) Make sure models directory exists ... " << std::flush;
939 >  dout << "Cleaning up ... " << std::flush;
940 > /*  dout << "   1) Make sure models directory exists ... " << std::flush;
941    gSystem->Exec("mkdir -p models/");
942    dout << " ok!" << endl;
943    dout << "   2) Deleting any previous model files with the same name ... " << std::flush;
# Line 810 | Line 959 | ShapeDroplet LimitsFromShapes(bool asymp
959    copycommand3 << "cp " << RunDirectory << "/limitfile.root models/model_" << name << "_histo.root";
960    gSystem->Exec(copycommand3.str().c_str());
961    dout << " ok!" << endl;
962 <  dout << "   4) Removing original working directory (" << RunDirectory << ") ... " << std::flush;
963 < write_warning(__FUNCTION__,"Watch out : need to uncomment the line below to remove the original working directory again");
815 < //  gSystem->Exec(("rm -r "+RunDirectory).c_str());
962 >  dout << "   4) Removing original working directory (" << RunDirectory << ") ... " << std::flush;*/
963 >  gSystem->Exec(("rm -r "+RunDirectory).c_str());
964    dout << " ok!" << endl;
965    delete limcan;
966    return alpha;
# Line 827 | Line 975 | void PrepareDataShapes(string datajzb, v
975    bool dataonly=true;
976    bool signalonly=false;
977    string mcjzb="JZBforMCinPrepareDataShapes";//this string is not used.
978 <  float jzbpeakerrormc=0;
978 > //  float jzbpeakerrormc=0;
979    generate_shapes_for_systematic(signalonly,dataonly,datafile,faketree,"",mcjzb,datajzb,noJES,jzbbins,limcan,"",xsec);
980    // don't need these effects for obs & pred, only for signal!
981   //  generate_shapes_for_systematic(signalonly,dataonly,datafile,faketree,"peakUp",newjzbexpression(mcjzb,jzbpeakerrormc),newjzbexpression(datajzb,jzbpeakerrordata),noJES,jzbbins,limcan,"",xsec);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines