ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.34
Committed: Mon Sep 12 19:06:15 2011 UTC (13 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.33: +9 -4 lines
Log Message:
Checking limit before entering it into limit map (check to see if it's not an error code); providing more output; TEMPORARILY switched to Pablo's naming convention (to be reverted, the code will complain automatically); informing the user when skipping a point. Systematics2Limits now pretty much ready for review.

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4     #include <fstream>
5 buchmann 1.7 #include <pthread.h>
6 buchmann 1.1
7     #include <TCut.h>
8     #include <TROOT.h>
9     #include <TCanvas.h>
10     #include <TMath.h>
11     #include <TColor.h>
12     #include <TPaveText.h>
13     #include <TRandom.h>
14     #include <TH1.h>
15     #include <TH2.h>
16     #include <TF1.h>
17     #include <TSQLResult.h>
18     #include <TProfile.h>
19 buchmann 1.31 #include <TKey.h>
20 buchmann 1.1
21     //#include "TTbar_stuff.C"
22     using namespace std;
23    
24     using namespace PlottingSetup;
25    
26     void susy_scan_axis_labeling(TH2F *histo) {
27     histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
28     histo->GetXaxis()->CenterTitle();
29     histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
30     histo->GetYaxis()->CenterTitle();
31     }
32    
33 buchmann 1.7 bool isThreadActive=false;
34    
35     struct limit_args {
36     float mceff;
37     float toterr;
38     int ibin;
39     string mcjzb;
40     vector<float> sigmas;
41 buchmann 1.25 string plotfilename;
42 buchmann 1.7 };
43    
44     void* compute_one_upper_limit_wrapper(void* data) {
45     isThreadActive=true;
46     limit_args* args = (limit_args*) data;
47     std::cout << "Thread to compute limits has been started" << std::endl;
48 buchmann 1.25 args->sigmas=compute_one_upper_limit(args->mceff,args->toterr,args->ibin,args->mcjzb,args->plotfilename,true);
49 buchmann 1.7 std::cout << "Thread to compute limits has finished" << std::endl;
50     isThreadActive=false;
51     return NULL; // oder in C++: return 0;// Damit kann man Werte zurückgeben
52     }
53    
54 buchmann 1.25 void do_limit_wrapper(float mceff,float toterr,int ibin,string mcjzb,vector<float> &sigmas,string plotfilename) {
55 buchmann 1.7 pthread_t limitthread;
56 buchmann 1.25 limit_args limargs={mceff,toterr,ibin,mcjzb,sigmas,plotfilename};
57 buchmann 1.7 pthread_create( &limitthread, NULL, compute_one_upper_limit_wrapper, (void*) &limargs);
58     int counter=0;
59 buchmann 1.29 int counterinterval=5;
60 buchmann 1.7 sleep(1); //waiting a second for the process to become active
61     while(counter<limitpatience*60 && isThreadActive) {
62 buchmann 1.28 std::cout << "Limits are being calculated; Checking round " << counter << " ( corresponds to " << seconds_to_time(counter) << " ) , patience will end in " << seconds_to_time(60*limitpatience-counter) << std::endl;
63 buchmann 1.29 counter+=counterinterval;
64     sleep(counterinterval);
65 buchmann 1.7 }
66    
67     if(!isThreadActive) {
68     cout << "Thread finished sucessfully" << endl;
69     pthread_join( limitthread, NULL );
70     std::cout<< __FUNCTION__ << " : going to save sigmas " << std::endl;
71     sigmas=limargs.sigmas;
72     } else {
73     pthread_cancel(limitthread);
74     std::cout << "DID NOT TERMINATE IN TIME - ABORTED!" << std::endl;
75     sigmas.push_back(-1);sigmas.push_back(-1);sigmas.push_back(-1);
76     }
77     }
78    
79 buchmann 1.22 void prepare_scan_axis(TH2 *variablemap,bool ismSUGRA) {
80 buchmann 1.9 variablemap->GetXaxis()->SetTitle("m_{glu}");
81     variablemap->GetYaxis()->SetTitle("m_{LSP}");
82    
83 buchmann 1.22 if(ismSUGRA) {
84     variablemap->GetXaxis()->SetTitle("m_{0}");
85     variablemap->GetYaxis()->SetTitle("m_{1/2}");
86     }
87    
88 buchmann 1.9 variablemap->GetXaxis()->CenterTitle();
89     variablemap->GetYaxis()->CenterTitle();
90     }
91    
92 buchmann 1.31 void set_SUSY_style() {
93     Int_t MyPalette[100];
94     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
95     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
96     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
97     Double_t stop[] = {0., .25, .50, .75, 1.0};
98     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
99     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
100    
101     gStyle->SetPalette(100, MyPalette);
102    
103     float rightmargin=gStyle->GetPadRightMargin();
104     gStyle->SetPadRightMargin(0.15);
105    
106     }
107    
108     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, TFile *fsyst, int ibin,float njobs=-1, float jobnumber=-1) {
109     bool runninglocally=true;
110     if(njobs>-1&&jobnumber>-1) {
111     runninglocally=false;
112     dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
113     } else {
114     dout << "Running locally " << endl;
115     dout << "This will take a really, really long time - if you want to see the results THIS week try running the LimitWorkerScript on the grid (DistributedModelCalculation/Limits/)" << endl;
116     }
117    
118     string massgluname="MassGlu";
119     string massLSPname="MassLSP";
120    
121     string prefix="SMS_";
122     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
123     bool ismSUGRA=false;
124     TIter nextkey(fsyst->GetListOfKeys());
125     TKey *key;
126     while ((key = (TKey*)nextkey()))
127     {
128     TObject *obj = key->ReadObj();
129     if(Contains((string)(obj->GetName()),"mSUGRA")) ismSUGRA=true;
130     }
131    
132     if(ismSUGRA) {
133     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
134     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
135     mglustart=m0start;
136     mgluend=m0end;
137     mglustep=m0step;
138     mLSPstart=m12start;
139     mLSPend=m12end;
140     mLSPstep=m12step;
141     prefix="mSUGRA_";
142     cout << "mSUGRA scan has been set up." << endl;
143     } else {
144     cout << "SMS scan has been set up." << endl;
145     }
146    
147     set_SUSY_style();
148    
149     TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
150    
151     int Npoints=0;
152     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
153     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
154     }
155    
156 buchmann 1.34 // TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
157     write_warning(__FUNCTION__,"Currently the efficiencymap name was switched to Pablo's convention. This NEEDS to be switched BACK!");TH2F *mceff = (TH2F*)fsyst->Get(("efficiency_jzbdiff"+any2string(jzb_cut[ibin])).c_str());
158 buchmann 1.31 TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
159 buchmann 1.33 TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
160 buchmann 1.32
161 buchmann 1.31 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzb_cut[ibin])).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
162 buchmann 1.32 TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzb_cut[ibin])).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
163     TH2F *xsmap = new TH2F((prefix+"crosssectionmap"+any2string(jzb_cut[ibin])).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
164 buchmann 1.31
165 buchmann 1.32 if(!fullerr || !mceff || !NEvents) {
166 buchmann 1.31 write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
167 buchmann 1.34 dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
168 buchmann 1.31 delete limcanvas;
169     return;
170     }
171    
172     int ipoint=-1;
173     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
174     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
175     {
176     ipoint++;
177     if(!runninglocally&&!do_this_point(ipoint,Npoints,jobnumber,njobs)) continue;
178     float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
179 buchmann 1.33 float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
180 buchmann 1.32 float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
181 buchmann 1.34 dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
182 buchmann 1.32 dout << "Found : systerr=" << currtoterr << " and eff=" << currmceff << " and nevents=" << nevents << endl;
183 buchmann 1.31 string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
184 buchmann 1.34 if(currmceff<=0||currtoterr<=0||nevents==0) {
185     dout << " Nothing to work with, skipping this point." << endl;
186     continue;
187     }
188 buchmann 1.31 vector<float> sigmas;
189 buchmann 1.32 //do_limit_wrapper(currmceff,currtoterr,ibin,mcjzb,sigmas,plotfilename); // no threading right now.
190     sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true);
191 buchmann 1.34 if(sigmas[0]>0) limitmap->Fill(mglu,mlsp,sigmas[0]); //anything else is an error code
192 buchmann 1.32 dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " )at " << sigmas[0] << endl;
193     if(ismSUGRA) {
194     dout << "Computing XS" << endl;
195     float rel_limit=0;
196     float xs=-1;
197     stringstream addcut;
198     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
199    
200     vector<float> xs_weights = processMCefficiency((scansample.collection)[0].events,mcjzb,requireZ,nevents, addcut.str());
201    
202     exclmap->Fill(mglu,mlsp,rel_limit);
203     xsmap->Fill(mglu,mlsp,xs);
204     }
205    
206 buchmann 1.31 }
207     }
208    
209     prepare_scan_axis(limitmap,ismSUGRA);
210 buchmann 1.32 TFile *outputfile=new TFile(("output/DistributedLimitsFromSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");//needs to be "UPDATE" as we can get to this point for different JZB cuts and don't want to erase the previous data :-)
211     outputfile->cd();
212 buchmann 1.31 limitmap->Write();
213 buchmann 1.32 if(ismSUGRA) {
214     exclmap->Write();
215     xsmap->Write();
216     }
217     outputfile->Close();
218 buchmann 1.31 delete limcanvas;
219     }
220    
221     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
222     dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
223     TFile *fsyst = new TFile(fsystfilename.c_str());
224     if(!fsyst) {
225     write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
226     return;
227     }
228     for(int ibin=0;ibin<jzb_cut.size();ibin++) {
229     establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
230     }
231     }
232    
233    
234    
235    
236 buchmann 1.13 void scan_SUSY_parameter_space(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, int ibin,float njobs=-1, float jobnumber=-1, bool systematicsonly=false,bool efficiencyonly=false) {
237 buchmann 1.6 bool runninglocally=true;
238     if(njobs>-1&&jobnumber>-1) {
239     runninglocally=false;
240 buchmann 1.13 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
241 buchmann 1.6 } else {
242 buchmann 1.7 dout << "Running locally " << endl;
243     dout << "This will take a really, really long time - if you want to see the results THIS week try running the LimitWorkerScript on the grid (DistributedModelCalculation/Limits/)" << endl;
244 buchmann 1.6 }
245 buchmann 1.4
246 buchmann 1.18 cout << "FILE USED: " << (scansample.collection)[0].filename << endl;
247 buchmann 1.24 cout << "FILE USED (name): " << (scansample.collection)[0].samplename << endl;
248 buchmann 1.4 jzbSel=jzb_cut[ibin];
249     geqleq="geq";
250     automatized=true;
251     mcjzbexpression=mcjzb;
252    
253     string massgluname="MassGlu";
254     string massLSPname="MassLSP";
255    
256 buchmann 1.23 string prefix="SMS_";
257 buchmann 1.22 // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
258     bool ismSUGRA=false;
259 buchmann 1.24 if(Contains((scansample.collection)[0].samplename,"mSUGRA")) ismSUGRA=true;
260 buchmann 1.22 if(ismSUGRA) {
261     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
262     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
263     mglustart=m0start;
264     mgluend=m0end;
265     mglustep=m0step;
266     mLSPstart=m12start;
267     mLSPend=m12end;
268     mLSPstep=m12step;
269 buchmann 1.23 prefix="mSUGRA_";
270 buchmann 1.24 cout << "mSUGRA scan has been set up." << endl;
271     } else {
272     cout << "SMS scan has been set up." << endl;
273     }
274 buchmann 1.22
275 buchmann 1.4 Int_t MyPalette[100];
276     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
277     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
278     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
279     Double_t stop[] = {0., .25, .50, .75, 1.0};
280     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
281     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
282    
283     gStyle->SetPalette(100, MyPalette);
284    
285 buchmann 1.23 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
286     TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
287     TH2F *sysjesmap = new TH2F((prefix+"sysjes"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
288     TH2F *sysjsumap = new TH2F((prefix+"sysjsu"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
289     TH2F *sysresmap = new TH2F((prefix+"sysresmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
290 buchmann 1.31 TH2F *efficiencymap = new TH2F((prefix+"efficiencymap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
291     TH2F *Neventsmap = new TH2F((prefix+"Neventsmap"+any2string(jzbSel)).c_str(),"", (mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
292     TH2F *ipointmap = new TH2F((prefix+"Neventsmap"+any2string(jzbSel)).c_str(),"", (mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
293 buchmann 1.27 TH2F *syspdfmap = new TH2F((prefix+"syspdfmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
294     TH2F *systotmap = new TH2F((prefix+"systotmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
295     TH2F *sysstatmap = new TH2F((prefix+"sysstatmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
296    
297    
298    
299 buchmann 1.29 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
300 buchmann 1.27
301 buchmann 1.4 float rightmargin=gStyle->GetPadRightMargin();
302     gStyle->SetPadRightMargin(0.15);
303    
304     TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
305    
306 buchmann 1.6 int Npoints=0;
307     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
308     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
309     }
310    
311     int ipoint=-1;
312 buchmann 1.4 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
313     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
314     {
315 buchmann 1.6 ipoint++;
316     if(!runninglocally&&!do_this_point(ipoint,Npoints,jobnumber,njobs)) continue;
317 buchmann 1.19 float result=-987,resulterr=-987;
318 buchmann 1.4 stringstream addcut;
319     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
320 buchmann 1.14 (scansample.collection)[0].events->Draw("eventNum",addcut.str().c_str(),"goff");
321     float nevents = (scansample.collection)[0].events->GetSelectedRows();
322 buchmann 1.4 vector<vector<float> > systematics;
323 buchmann 1.30 if(nevents<10) {
324     dout << "This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be skipped."<< endl;
325 buchmann 1.6 continue;
326     } else {
327 buchmann 1.24 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore not be skipped."<< endl;
328 buchmann 1.22 }
329     if(nevents!=0&&efficiencyonly) {
330 buchmann 1.31 MCefficiency((scansample.collection)[0].events,result,resulterr,mcjzb,requireZ,nevents,addcut.str(),-1);
331 buchmann 1.22 efficiencymap->Fill(mglu,mlsp,result);
332 buchmann 1.13 }
333 buchmann 1.17 Neventsmap->Fill(mglu,mlsp,nevents);
334 buchmann 1.24 ipointmap->Fill(mglu,mlsp,ipoint);
335 buchmann 1.17 if(efficiencyonly) continue;
336    
337 buchmann 1.22 do_systematics_for_one_file((scansample.collection)[0].events,nevents,"SUSY SCAN", systematics,mcjzb,datajzb,peakerror,requireZ, addcut.str(),ismSUGRA);
338 buchmann 1.9 float JZBcutat = systematics[0][0];
339     float mceff = systematics[0][1];
340 buchmann 1.22 float mcefferr = systematics[0][2];//MC stat error
341 buchmann 1.9 float toterr = systematics[0][4];
342     float sys_jes = systematics[0][5]; // Jet Energy Scale
343     float sys_jsu = systematics[0][6]; // JZB scale uncertainty
344     float sys_res = systematics[0][7]; // resolution
345 buchmann 1.27 float sys_pdf = 0;
346     if(systematics[0].size()>9) sys_pdf = systematics[0][9]; // PDF
347 buchmann 1.22 efficiencymap->Fill(mglu,mlsp,mceff);
348     efficiencymap->SetBinError(efficiencymap->FindBin(mglu,mlsp),mcefferr);//blublu
349 buchmann 1.10
350 buchmann 1.15 if(mceff!=mceff||toterr!=toterr||mceff<0) {
351     dout << "Limits can't be calculated for this configuration (mglu="<<mglu<<" , mlsp="<<mlsp << ") as either the efficiency or its error are not positive numbers! (mceff="<<mceff<<" and toterr="<<toterr<<")"<< endl;
352 buchmann 1.4 continue;
353 buchmann 1.5 } else {
354 buchmann 1.13 if(!systematicsonly&&!efficiencyonly) {
355 buchmann 1.22 dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
356 buchmann 1.9 vector<float> sigmas;
357 buchmann 1.27 string plotfilename=(string)(TString((scansample.collection)[0].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
358 buchmann 1.25 do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
359 buchmann 1.9 cout << "back in " << __FUNCTION__ << endl;
360     if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
361     limitmap->Fill(mglu,mlsp,sigmas[0]);
362 buchmann 1.17 sysjesmap->Fill(mglu,mlsp,sys_jes);
363     sysjsumap->Fill(mglu,mlsp,sys_jsu);
364     sysresmap->Fill(mglu,mlsp,sys_res);
365 buchmann 1.27 syspdfmap->Fill(mglu,mlsp,sys_pdf);
366     systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
367     sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
368 buchmann 1.9 dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
369 buchmann 1.11 } //end of if sigma is positive
370     //end of not systematics only condition
371 buchmann 1.13 }
372     if(systematicsonly) {
373 buchmann 1.9 sysjesmap->Fill(mglu,mlsp,sys_jes);
374     sysjsumap->Fill(mglu,mlsp,sys_jsu);
375     sysresmap->Fill(mglu,mlsp,sys_res);
376 buchmann 1.27 syspdfmap->Fill(mglu,mlsp,sys_pdf);
377     systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
378     sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
379 buchmann 1.11 }
380 buchmann 1.15 }//efficiency is valid
381 buchmann 1.4 }
382     }
383    
384 buchmann 1.22 prepare_scan_axis(limitmap,ismSUGRA);
385     prepare_scan_axis(sysjesmap,ismSUGRA);
386     prepare_scan_axis(sysjsumap,ismSUGRA);
387     prepare_scan_axis(sysresmap,ismSUGRA);
388 buchmann 1.27 prepare_scan_axis(syspdfmap,ismSUGRA);
389     prepare_scan_axis(systotmap,ismSUGRA);
390     prepare_scan_axis(sysstatmap,ismSUGRA);
391 buchmann 1.9
392 buchmann 1.13 if(!systematicsonly&&!efficiencyonly) {
393 buchmann 1.9 limcanvas->cd();
394     limitmap->Draw("COLZ");
395 buchmann 1.22 string titletobewritten="Limits in LSP-Glu plane";
396     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
397     TText *title = write_title(titletobewritten);
398 buchmann 1.9 title->Draw();
399     if(runninglocally) {
400     CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
401     } else {
402 buchmann 1.12 TFile *outputfile;
403     if(systematicsonly) outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");//needs to be "UPDATE" as we can get to this point for different JZB cuts and don't want to erase the previous data :-)
404     else outputfile=new TFile(("output/DistributedLimits_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");//needs to be "UPDATE" as we can get to this point for
405 buchmann 1.9 limitmap->Write();
406 buchmann 1.18 sysjesmap->Write();
407     sysjsumap->Write();
408 buchmann 1.28 sysresmap->Write();
409 buchmann 1.18 efficiencymap->Write();
410 buchmann 1.27 syspdfmap->Write();
411     systotmap->Write();
412     sysstatmap->Write();
413 buchmann 1.18 Neventsmap->Write();
414 buchmann 1.24 ipointmap->Write();
415 buchmann 1.9 outputfile->Close();
416     }
417 buchmann 1.13 }
418     if(systematicsonly) { // systematics only :
419 buchmann 1.9 limcanvas->cd();
420     sysjesmap->Draw("COLZ");
421 buchmann 1.22 string titletobewritten="Jet Energy scale in LSP-Glu plane";
422     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
423     TText *title = write_title(titletobewritten);
424 buchmann 1.9 title->Draw();
425     if(runninglocally) {
426     CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
427     }
428     sysjsumap->Draw("COLZ");
429 buchmann 1.22 titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
430     if(ismSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
431     TText *title2 = write_title(titletobewritten);
432 buchmann 1.9 title2->Draw();
433     if(runninglocally) {
434     CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
435     }
436     sysresmap->Draw("COLZ");
437 buchmann 1.22 titletobewritten="Resolution in LSP-Glu plane";
438     if(ismSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
439     TText *title3 = write_title(titletobewritten);
440 buchmann 1.9 title3->Draw();
441     if(runninglocally) {
442     CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
443     }
444    
445     if(!runninglocally) {
446     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
447     sysjesmap->Write();
448     sysjsumap->Write();
449     sysresmap->Write();
450 buchmann 1.18 efficiencymap->Write();
451     Neventsmap->Write();
452 buchmann 1.24 ipointmap->Write();
453 buchmann 1.27 syspdfmap->Write();
454     systotmap->Write();
455     sysstatmap->Write();
456 buchmann 1.9 outputfile->Close();
457     }
458     }//end of systematics only
459 buchmann 1.13 if(efficiencyonly) {
460     limcanvas->cd();
461     efficiencymap->Draw("COLZ");
462 buchmann 1.22 string titletobewritten="Efficiencies in LSP-Glu plane";
463     if(ismSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
464     TText *title = write_title(titletobewritten);
465 buchmann 1.13 title->Draw();
466     if(runninglocally) {
467     CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
468     }
469     limcanvas->cd();
470     sysjesmap->Draw("COLZ");
471 buchmann 1.22 titletobewritten="N(events) in LSP-Glu plane";
472     if(ismSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
473     TText *title2 = write_title(titletobewritten);
474 buchmann 1.13 title2->Draw();
475     if(runninglocally) {
476     CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
477     }
478     if(!runninglocally) {
479     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
480 buchmann 1.24 ipointmap->Write();
481 buchmann 1.13 Neventsmap->Write();
482     efficiencymap->Write();
483     outputfile->Close();
484     }
485     }//end of efficiencies only
486 buchmann 1.31
487     delete limitmap;
488     delete exclmap;
489     delete sysjesmap;
490     delete sysjsumap;
491     delete sysresmap;
492     delete efficiencymap;
493     delete Neventsmap;
494     delete ipointmap;
495     delete syspdfmap;
496     delete systotmap;
497     delete sysstatmap;
498 buchmann 1.13 delete limcanvas;
499 buchmann 1.1 }
500 buchmann 1.4
501 buchmann 1.13 void scan_SUSY_parameter_space(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, float njobs=-1, float jobnumber=-1, bool systonly=false, bool effonly=false) {
502 buchmann 1.10 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
503 buchmann 1.4 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
504 buchmann 1.13 scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, ibin, njobs, jobnumber,systonly,effonly);
505 buchmann 1.4 }
506 buchmann 1.6 }