ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.62
Committed: Mon Nov 21 22:14:04 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.61: +46 -48 lines
Log Message:
Switched from 'fill' to 'setbincontent' to avoid filling any quantity twice

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.51 #include <assert.h>
7 buchmann 1.1
8     #include <TCut.h>
9     #include <TROOT.h>
10     #include <TCanvas.h>
11     #include <TMath.h>
12     #include <TColor.h>
13     #include <TPaveText.h>
14     #include <TRandom.h>
15     #include <TH1.h>
16     #include <TH2.h>
17     #include <TF1.h>
18     #include <TSQLResult.h>
19     #include <TProfile.h>
20 buchmann 1.31 #include <TKey.h>
21 buchmann 1.1
22     //#include "TTbar_stuff.C"
23     using namespace std;
24    
25     using namespace PlottingSetup;
26    
27     void susy_scan_axis_labeling(TH2F *histo) {
28 buchmann 1.37 histo->GetXaxis()->SetTitle("m_{#Chi_{2}^{0}}-m_{LSP}");
29 buchmann 1.1 histo->GetXaxis()->CenterTitle();
30     histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
31     histo->GetYaxis()->CenterTitle();
32     }
33    
34 buchmann 1.22 void prepare_scan_axis(TH2 *variablemap,bool ismSUGRA) {
35 buchmann 1.9 variablemap->GetXaxis()->SetTitle("m_{glu}");
36     variablemap->GetYaxis()->SetTitle("m_{LSP}");
37 buchmann 1.35
38 buchmann 1.22 if(ismSUGRA) {
39     variablemap->GetXaxis()->SetTitle("m_{0}");
40     variablemap->GetYaxis()->SetTitle("m_{1/2}");
41     }
42 buchmann 1.35
43 buchmann 1.9 variablemap->GetXaxis()->CenterTitle();
44     variablemap->GetYaxis()->CenterTitle();
45     }
46    
47 buchmann 1.31 void set_SUSY_style() {
48     Int_t MyPalette[100];
49     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
50     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
51     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
52     Double_t stop[] = {0., .25, .50, .75, 1.0};
53     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
54     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
55 buchmann 1.35
56 buchmann 1.31 gStyle->SetPalette(100, MyPalette);
57 buchmann 1.35
58 buchmann 1.31 float rightmargin=gStyle->GetPadRightMargin();
59     gStyle->SetPadRightMargin(0.15);
60    
61     }
62    
63 buchmann 1.53 bool delete_any_cached_scans() {
64 buchmann 1.50 //This should only be called via CRAB
65 buchmann 1.57 char hostname[1023];
66     gethostname(hostname,1023);
67     if((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))) return false;
68 buchmann 1.53 else {
69     vector<string> all_files;
70     char currentpath[1024];
71     TString directory=TString(getcwd(currentpath,1024));
72     directory=directory+"/";
73     process_directory(directory,all_files);
74     for(int ifile=0;ifile<all_files.size();ifile++)
75 buchmann 1.50 {
76     if(Contains(all_files[ifile],"_clean_splitup_")) {
77     dout << "About to delete " << all_files[ifile] << endl;
78     gSystem->Exec(((string)"rm "+all_files[ifile]).c_str());
79     }
80     }
81 buchmann 1.53 return true;
82     }
83 buchmann 1.50 }
84    
85     bool initialized_t2=false;
86    
87 buchmann 1.51 int srmcpretries=0;
88    
89 buchmann 1.50 void load_scan_sample(int a, int b, int &scanfileindex,bool ismSUGRA) {
90 buchmann 1.55
91     // There is no need to define your sample here. That is done in Setup.C where you define the loading directory!
92    
93 buchmann 1.50 dout << "Going to load file with Xzone=" << a << " and Yzone=" << b << endl;
94 buchmann 1.48 stringstream filetoload;
95 buchmann 1.57 char hostname[1023];
96     gethostname(hostname,1023);
97 buchmann 1.50
98 buchmann 1.57 if((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))) { // local case
99 buchmann 1.55 filetoload << "/shome/buchmann/ntuples/"<<PlottingSetup::ScanSampleDirectory;
100     if(ismSUGRA) filetoload << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
101     else filetoload << "/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
102 buchmann 1.50 if(!Contains(((scansample.collection)[(scansample.collection).size()-1]).filename,"_"+any2string(a)+"_"+any2string(b))) {
103     dout << "The last sample is NOT the same one as the current one, possibly popping off last one and adding the new one." << endl;
104 buchmann 1.48 if((scansample.collection).size()>1) {
105     scansample.RemoveLastSample();
106     }
107     scanfileindex=(scansample.collection).size();
108     //New: Loading file when necessary, not before (avoiding high memory usage and startup times)
109     if(scanfileindex!=0) scansample.AddSample(filetoload.str(),"scansample",1,1,false,true,scanfileindex,kRed);
110 buchmann 1.50 } else {
111     dout << "Last sample is the same as the current one. Recycling it." << endl;
112     scanfileindex=(scansample.collection).size()-1;
113     }
114 buchmann 1.58 dout << " Going to use the following file: " << filetoload.str() << endl;
115 buchmann 1.50 } // end of t3 case
116     else {
117     write_info(__FUNCTION__,"Hello, CRAB! Might need to load files ...");
118 buchmann 1.59 PlottingSetup::limitpatience=PlottingSetup::limitpatienceCRAB;
119 buchmann 1.50 stringstream copyfile;
120 buchmann 1.57 copyfile << "lcg-cp -b -T srmv2 srm://storage01.lcg.cscs.ch:8443/srm/managerv2?SFN=/pnfs/lcg.cscs.ch/cms/trivcat/store/user/buchmann/bussola/" << PlottingSetup::ScanSampleDirectory;
121 buchmann 1.55 if(ismSUGRA) copyfile << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root " << "mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root ";
122     else copyfile << "/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root " << "SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root ";
123 buchmann 1.50 stringstream newfilename;
124     if(ismSUGRA) newfilename << "mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
125     else newfilename << "SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
126    
127     if(!Contains(((scansample.collection)[(scansample.collection).size()-1]).filename,"_"+any2string(a)+"_"+any2string(b))||(a==0&&b==0)&&!initialized_t2) {
128     initialized_t2=true;
129     dout << "The last sample is NOT the same one as the current one, possibly popping off last one and downloading as well as adding the new one." << endl;
130     if((scansample.collection).size()>1) {
131     scansample.RemoveLastSample();
132     }
133     scanfileindex=(scansample.collection).size();
134     //New: Loading file when necessary, not before (avoiding high memory usage and startup times)
135     if(scanfileindex!=0) {
136     delete_any_cached_scans();
137     dout << "Going to download the scan file with the following copy command: " << copyfile.str() << endl;
138     gSystem->Exec(copyfile.str().c_str());
139 buchmann 1.51 if(doesROOTFileExist(newfilename.str())) {
140     scansample.AddSample(newfilename.str(),"scansample",1,1,false,true,scanfileindex,kRed);
141     } else {
142     srmcpretries++;
143     if(srmcpretries<5) {
144     dout << "The file could not be loaded correctly - retrying!" << endl;
145 buchmann 1.52 sleep(5);
146 buchmann 1.51 load_scan_sample(a,b,scanfileindex,ismSUGRA);
147     } else {
148     dout << "Have tried 5 times to load this sample. Giving up now and failing the program execution" << endl;
149     assert(0);
150     dout << "The command " << copyfile.str() << " failed to copy the file to the local storage (saving it as " << newfilename.str() << ")" << endl;
151     }
152     }
153 buchmann 1.50 }
154     } else {
155     dout << "Last sample is the same as the current one. Recycling it." << endl;
156 buchmann 1.48 scanfileindex=(scansample.collection).size()-1;
157 buchmann 1.50 }
158    
159 buchmann 1.48 }
160 buchmann 1.50 }
161 buchmann 1.48
162 buchmann 1.50 float get_xs(float &altxs, float mglu, float mlsp, string massgluname, string massLSPname, map < pair<float, float>, map<string, float> > &xsec, string mcjzb, bool requireZ) {
163     altxs=0;
164 buchmann 1.46 for(int iproc=1;iproc<=10;iproc++) {
165 buchmann 1.35 float process_xs = GetXSecForPointAndChannel(mglu,mlsp,xsec,iproc);
166 buchmann 1.49 altxs+=process_xs;
167 buchmann 1.46 }
168 buchmann 1.50 return altxs;
169 buchmann 1.35 }
170    
171 buchmann 1.31 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) {
172     bool runninglocally=true;
173     if(njobs>-1&&jobnumber>-1) {
174     runninglocally=false;
175     dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
176     } else {
177     dout << "Running locally " << endl;
178 buchmann 1.37 dout << "This will take a really, really long time - if you want to see the results within hours instead of weeks try running the worker script on the grid (DistributedModelCalculation/Limits/)" << endl;
179 buchmann 1.31 }
180 buchmann 1.35
181 buchmann 1.31 string massgluname="MassGlu";
182     string massLSPname="MassLSP";
183 buchmann 1.39 jzbSel=jzb_cut[ibin];
184     geqleq="geq";
185     automatized=true;
186     mcjzbexpression=mcjzb;
187    
188 buchmann 1.31 string prefix="SMS_";
189     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
190     bool ismSUGRA=false;
191     TIter nextkey(fsyst->GetListOfKeys());
192     TKey *key;
193     while ((key = (TKey*)nextkey()))
194     {
195     TObject *obj = key->ReadObj();
196     if(Contains((string)(obj->GetName()),"mSUGRA")) ismSUGRA=true;
197     }
198 buchmann 1.35
199     map < pair<float, float>, map<string, float> > xsec;
200 buchmann 1.31
201     if(ismSUGRA) {
202     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
203     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
204     mglustart=m0start;
205 buchmann 1.48 xsec=getXsec(PlottingSetup::cbafbasedir+"/Plotting/Modules/external/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
206 buchmann 1.31 mgluend=m0end;
207     mglustep=m0step;
208     mLSPstart=m12start;
209     mLSPend=m12end;
210     mLSPstep=m12step;
211     prefix="mSUGRA_";
212 buchmann 1.50 dout << "mSUGRA scan has been set up." << endl;
213 buchmann 1.31 } else {
214 buchmann 1.50 dout << "SMS scan has been set up." << endl;
215 buchmann 1.35 write_warning(__FUNCTION__,"Don't have the correct XS file yet");
216     xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
217 buchmann 1.31 }
218 buchmann 1.35
219 buchmann 1.31 set_SUSY_style();
220 buchmann 1.35
221 buchmann 1.31 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
222 buchmann 1.35
223 buchmann 1.31 int Npoints=0;
224 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
225     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(ismSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
226 buchmann 1.31 }
227 buchmann 1.37 TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
228     //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());
229 buchmann 1.31 TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
230 buchmann 1.33 TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
231 buchmann 1.52 TH2F *lflip = (TH2F*)fsyst->Get((prefix+"flipmap"+any2string(jzb_cut[ibin])).c_str());
232 buchmann 1.35
233 buchmann 1.56 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//observed limit
234     TH2F *explimitmap = new TH2F((prefix+"explimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit
235     TH2F *exp1plimitmap = new TH2F((prefix+"exp1plimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 1 sigma
236     TH2F *exp2plimitmap = new TH2F((prefix+"exp2plimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 2 sigma
237     TH2F *exp1mlimitmap = new TH2F((prefix+"exp1mlimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 1 sigma
238     TH2F *exp2mlimitmap = new TH2F((prefix+"exp2mlimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 2 sigma
239 buchmann 1.37
240 buchmann 1.56 TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzb_cut[ibin])).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
241     TH2F *xsmap = new TH2F((prefix+"crosssectionmap"+any2string(jzb_cut[ibin])).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
242     TH2F *totxsmap = new TH2F((prefix+"absolutecrosssectionmap"+any2string(jzb_cut[ibin])).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
243     TH2F *flipmap = new TH2F((prefix+"limitflipmap"+any2string(jzb_cut[ibin])).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,(int)((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
244 buchmann 1.52
245    
246 buchmann 1.35
247 buchmann 1.32 if(!fullerr || !mceff || !NEvents) {
248 buchmann 1.31 write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
249 buchmann 1.34 dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
250 buchmann 1.31 delete limcanvas;
251     return;
252     }
253 buchmann 1.37
254     bool doexpected=true;
255 buchmann 1.35
256 buchmann 1.31 int ipoint=-1;
257 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
258     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(ismSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
259 buchmann 1.31 {
260     ipoint++;
261 buchmann 1.56 if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
262 buchmann 1.62 int GlobalBin=flipmap->FindBin(mglu,mlsp);
263 buchmann 1.31 float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
264 buchmann 1.33 float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
265 buchmann 1.32 float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
266 buchmann 1.56 int flipped = (int)(lflip->GetBinContent(lflip->FindBin(mglu,mlsp)));
267 buchmann 1.62 flipmap->SetBinContent(GlobalBin,flipped);
268 buchmann 1.34 dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
269 buchmann 1.35 dout << "Found : MCeff=" << currmceff << " and total error=" << currtoterr << " and Nevents=" << nevents << endl;
270 buchmann 1.31 string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
271 buchmann 1.34 if(currmceff<=0||currtoterr<=0||nevents==0) {
272     dout << " Nothing to work with, skipping this point." << endl;
273     continue;
274     }
275 buchmann 1.31 vector<float> sigmas;
276 buchmann 1.52 sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true, flipped);
277 buchmann 1.48
278    
279 buchmann 1.62 if(sigmas[0]>0) limitmap->SetBinContent(GlobalBin,sigmas[0]); //anything else is an error code
280 buchmann 1.37 if(sigmas.size()>1) {
281 buchmann 1.62 explimitmap->SetBinContent(GlobalBin,sigmas[1]);
282     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
283     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
284     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
285     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
286 buchmann 1.37 }
287    
288 buchmann 1.35 dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " ) at " << sigmas[0] << endl;
289 buchmann 1.39 if(ismSUGRA) { // for SMS this is a bit easier at the moment - we have a reference XS file which we use when plotting
290 buchmann 1.35 dout << "Computing exclusion status" << endl;
291     float rel_limit=0;
292 buchmann 1.49 float totxs;
293     float xs=get_xs(totxs,mglu,mlsp,massgluname,massLSPname,xsec,mcjzb,requireZ);
294 buchmann 1.35 if(xs>0) rel_limit=sigmas[0]/xs;
295 buchmann 1.62 exclmap->SetBinContent(GlobalBin,rel_limit);
296     xsmap->SetBinContent(GlobalBin,xs);
297     totxsmap->SetBinContent(GlobalBin,totxs);
298 buchmann 1.32 }
299 buchmann 1.31 }
300     }
301 buchmann 1.35
302 buchmann 1.31 prepare_scan_axis(limitmap,ismSUGRA);
303 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 :-)
304     outputfile->cd();
305 buchmann 1.31 limitmap->Write();
306 buchmann 1.52 flipmap->Write();
307 buchmann 1.37 if(doexpected) {
308     explimitmap->Write();
309     exp1plimitmap->Write();
310     exp1mlimitmap->Write();
311     exp2plimitmap->Write();
312     exp2mlimitmap->Write();
313     }
314 buchmann 1.32 if(ismSUGRA) {
315     exclmap->Write();
316     xsmap->Write();
317 buchmann 1.49 totxsmap->Write();
318 buchmann 1.32 }
319     outputfile->Close();
320 buchmann 1.31 delete limcanvas;
321     }
322    
323     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
324     dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
325     TFile *fsyst = new TFile(fsystfilename.c_str());
326     if(!fsyst) {
327     write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
328     return;
329     }
330     for(int ibin=0;ibin<jzb_cut.size();ibin++) {
331     establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
332     }
333     }
334    
335    
336    
337    
338 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) {
339 buchmann 1.6 bool runninglocally=true;
340     if(njobs>-1&&jobnumber>-1) {
341     runninglocally=false;
342 buchmann 1.13 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
343 buchmann 1.6 } else {
344 buchmann 1.7 dout << "Running locally " << endl;
345 buchmann 1.40 dout << "This will take a really, really long time - if you want to see the results THIS month try running the LimitWorkerScript on the grid (DistributedModelCalculation/Limits/)" << endl;
346 buchmann 1.6 }
347 buchmann 1.35
348 buchmann 1.4 jzbSel=jzb_cut[ibin];
349     geqleq="geq";
350     automatized=true;
351     mcjzbexpression=mcjzb;
352 buchmann 1.35
353 buchmann 1.4 string massgluname="MassGlu";
354     string massLSPname="MassLSP";
355 buchmann 1.35
356 buchmann 1.23 string prefix="SMS_";
357 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!
358     bool ismSUGRA=false;
359 buchmann 1.24 if(Contains((scansample.collection)[0].samplename,"mSUGRA")) ismSUGRA=true;
360 buchmann 1.22 if(ismSUGRA) {
361     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
362     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
363     mglustart=m0start;
364     mgluend=m0end;
365     mglustep=m0step;
366     mLSPstart=m12start;
367     mLSPend=m12end;
368     mLSPstep=m12step;
369 buchmann 1.23 prefix="mSUGRA_";
370 buchmann 1.50 dout << "mSUGRA scan has been set up." << endl;
371 buchmann 1.24 } else {
372 buchmann 1.50 dout << "SMS scan has been set up." << endl;
373 buchmann 1.24 }
374 buchmann 1.35
375 buchmann 1.4 Int_t MyPalette[100];
376     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
377     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
378     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
379     Double_t stop[] = {0., .25, .50, .75, 1.0};
380     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
381     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
382 buchmann 1.35
383 buchmann 1.4 gStyle->SetPalette(100, MyPalette);
384 buchmann 1.35
385 buchmann 1.56 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//observed limit
386     TH2F *explimitmap = new TH2F((prefix+"explimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit
387     TH2F *exp1plimitmap = new TH2F((prefix+"exp1plimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 1 sigma
388     TH2F *exp2plimitmap = new TH2F((prefix+"exp2plimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 2 sigma
389     TH2F *exp1mlimitmap = new TH2F((prefix+"exp1mlimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 1 sigma
390     TH2F *exp2mlimitmap = new TH2F((prefix+"exp2mlimitmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 2 sigma
391 buchmann 1.37
392 buchmann 1.56 TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
393     TH2F *sysjesmap = new TH2F((prefix+"sysjes"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
394     TH2F *sysjsumap = new TH2F((prefix+"sysjsu"+any2string(jzbSel)).c_str(), "",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
395     TH2F *sysresmap = new TH2F((prefix+"sysresmap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
396     TH2F *efficiencymap = new TH2F((prefix+"efficiencymap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
397     TH2F *efficiencymapAcc = new TH2F((prefix+"efficiencymapAcc"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
398     TH2F *efficiencymapID = new TH2F((prefix+"efficiencymapID"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
399     TH2F *efficiencymapJets = new TH2F((prefix+"efficiencymapJets"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
400     TH2F *efficiencymapSignal = new TH2F((prefix+"efficiencymapSignal"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
401     TH2F *noscefficiencymap = new TH2F((prefix+"noscefficiencymap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
402     TH2F *Neventsmap = new TH2F((prefix+"Neventsmap"+any2string(jzbSel)).c_str(),"", (int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
403     TH2F *ipointmap = new TH2F((prefix+"ipointmap"+any2string(jzbSel)).c_str(),"", (int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
404     TH2F *syspdfmap = new TH2F((prefix+"syspdfmap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
405     TH2F *systotmap = new TH2F((prefix+"systotmap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
406     TH2F *sysstatmap = new TH2F((prefix+"sysstatmap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
407 buchmann 1.27
408 buchmann 1.56 TH2F *timemap = new TH2F((prefix+"timemap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
409 buchmann 1.36
410 buchmann 1.56 TH2F *flipmap = new TH2F((prefix+"flipmap"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
411 buchmann 1.52
412 buchmann 1.29 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
413 buchmann 1.35
414 buchmann 1.4 float rightmargin=gStyle->GetPadRightMargin();
415     gStyle->SetPadRightMargin(0.15);
416 buchmann 1.35
417 buchmann 1.4 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
418 buchmann 1.35
419 buchmann 1.37
420     bool doexpected=true;
421    
422 buchmann 1.6 int Npoints=0;
423 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
424     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(ismSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
425 buchmann 1.6 }
426 buchmann 1.35
427 buchmann 1.6 int ipoint=-1;
428 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
429     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(ismSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
430 buchmann 1.4 {
431 buchmann 1.6 ipoint++;
432 buchmann 1.62 int GlobalBin=efficiencymap->FindBin(mglu,mlsp);
433 buchmann 1.56 if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
434 buchmann 1.52 int flipped=0;
435 buchmann 1.19 float result=-987,resulterr=-987;
436 buchmann 1.50 float m0trees = PlottingSetup::mgluend;
437     float m12trees = PlottingSetup::mLSPend;
438 buchmann 1.42 int a = int((PlottingSetup::ScanXzones*mlsp)/(m12trees+1));
439     int b = int((PlottingSetup::ScanYzones*mglu)/(m0trees+1));
440 buchmann 1.50 int scanfileindex=PlottingSetup::ScanYzones*a+b;
441     load_scan_sample(a,b,scanfileindex,ismSUGRA);
442 buchmann 1.42
443 buchmann 1.36 clock_t start,finish;
444     start = clock(); // starting the clock to measure how long the computation takes!
445 buchmann 1.4 stringstream addcut;
446     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
447 buchmann 1.40 (scansample.collection)[scanfileindex].events->Draw("eventNum",addcut.str().c_str(),"goff");
448     float nevents = (scansample.collection)[scanfileindex].events->GetSelectedRows();
449 buchmann 1.4 vector<vector<float> > systematics;
450 buchmann 1.30 if(nevents<10) {
451 buchmann 1.40 dout << "This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be skipped."<< endl;
452     continue;
453 buchmann 1.6 } else {
454 buchmann 1.48 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore not be skipped. " << endl;
455     write_analysis_type(PlottingSetup::RestrictToMassPeak);
456 buchmann 1.22 }
457 buchmann 1.50 if(nevents!=0&&(efficiencyonly||systematicsonly)) {
458 buchmann 1.56 Value effwosigcont = MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1);
459 buchmann 1.52 if(result<0) {
460     write_info(__FUNCTION__,"Found negative efficiency (signal distribution populating JZB<0 more than JZB>0) - flipping analysis!");
461     flipped=1;
462 buchmann 1.56 MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1);
463 buchmann 1.52 }
464 buchmann 1.62 efficiencymap->SetBinContent(GlobalBin,result);
465     efficiencymap->SetBinError(GlobalBin,resulterr);
466     flipmap->SetBinContent(GlobalBin,flipped);
467     noscefficiencymap->SetBinContent(GlobalBin,effwosigcont.getValue());
468     noscefficiencymap->SetBinError(GlobalBin,effwosigcont.getError());
469 buchmann 1.47 //Partial efficiencies
470     float resultAcc, resultID, resultJets, resultSignal;
471     float resulterrAcc, resulterrID, resulterrJets, resulterrSignal;
472 buchmann 1.56 MCPartialefficiency((scansample.collection)[scanfileindex].events,resultAcc,resulterrAcc,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 1);
473     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultID,resulterrID,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 2);
474     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultJets,resulterrJets,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 3);
475     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultSignal,resulterrSignal,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 4);
476 buchmann 1.62 efficiencymapAcc->SetBinContent(GlobalBin,resultAcc);
477     efficiencymapAcc->SetBinError(GlobalBin,resulterrAcc);
478     efficiencymapID->SetBinContent(GlobalBin,resultID);
479     efficiencymapAcc->SetBinError(GlobalBin,resulterrID);
480     efficiencymapJets->SetBinContent(GlobalBin,resultJets);
481     efficiencymapAcc->SetBinError(GlobalBin,resulterrJets);
482     efficiencymapSignal->SetBinContent(GlobalBin,resultSignal);
483     efficiencymapAcc->SetBinError(GlobalBin,resulterrSignal);
484 buchmann 1.36 finish = clock();
485 buchmann 1.13 }
486 buchmann 1.62 Neventsmap->SetBinContent(GlobalBin,nevents);
487     ipointmap->SetBinContent(GlobalBin,ipoint);
488 buchmann 1.17 if(efficiencyonly) continue;
489    
490 buchmann 1.56 do_systematics_for_one_file((scansample.collection)[scanfileindex].events,(int)nevents,"SUSY SCAN", systematics,flipped, mcjzb,datajzb,peakerror,requireZ, addcut.str(),true);//mSUGRA is now always true here because we always want to compute PDF systematics
491 buchmann 1.9 float JZBcutat = systematics[0][0];
492     float mceff = systematics[0][1];
493 buchmann 1.22 float mcefferr = systematics[0][2];//MC stat error
494 buchmann 1.9 float toterr = systematics[0][4];
495     float sys_jes = systematics[0][5]; // Jet Energy Scale
496     float sys_jsu = systematics[0][6]; // JZB scale uncertainty
497     float sys_res = systematics[0][7]; // resolution
498 buchmann 1.37 float mcwoscef = systematics[0][8]; // efficiency without signal contamination
499     float mcwoscefr= systematics[0][9]; // error on efficiency without signal contamination
500 buchmann 1.27 float sys_pdf = 0;
501 buchmann 1.37 if(systematics[0].size()>10) sys_pdf = systematics[0][10]; // PDF
502 buchmann 1.35
503 buchmann 1.47 if(mceff!=mceff||toterr!=toterr||mceff<0 && (!systematicsonly&&!efficiencyonly)) {
504 buchmann 1.35 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;
505     continue;
506 buchmann 1.5 } else {
507 buchmann 1.35 if(!systematicsonly&&!efficiencyonly) {
508     dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
509     vector<float> sigmas;
510 buchmann 1.40 string plotfilename=(string)(TString((scansample.collection)[scanfileindex].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
511 buchmann 1.52 sigmas=compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,true,flipped);
512 buchmann 1.46 // do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
513 buchmann 1.50 dout << "back in " << __FUNCTION__ << endl;
514 buchmann 1.35 if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
515 buchmann 1.62 limitmap->SetBinContent(GlobalBin,sigmas[0]);
516 buchmann 1.37 if(sigmas.size()>1) {
517 buchmann 1.62 explimitmap->SetBinContent(GlobalBin,sigmas[1]);
518     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
519     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
520     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
521     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
522 buchmann 1.38 }
523 buchmann 1.37
524 buchmann 1.62 sysjesmap->SetBinContent(GlobalBin,sys_jes);
525     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
526     sysresmap->SetBinContent(GlobalBin,sys_res);
527     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
528     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
529     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
530 buchmann 1.35 dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
531     } //end of if sigma is positive
532 buchmann 1.36
533 buchmann 1.35 //end of not systematics only condition
534     }
535     if(systematicsonly) {
536 buchmann 1.62 sysjesmap->SetBinContent(GlobalBin,sys_jes);
537     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
538     sysresmap->SetBinContent(GlobalBin,sys_res);
539     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
540     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
541     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
542 buchmann 1.35 }
543 buchmann 1.15 }//efficiency is valid
544 buchmann 1.52 finish = clock();
545 buchmann 1.62 timemap->SetBinContent(GlobalBin,((float(finish)-float(start))/CLOCKS_PER_SEC));
546 buchmann 1.4 }
547     }
548 buchmann 1.52
549 buchmann 1.22 prepare_scan_axis(limitmap,ismSUGRA);
550     prepare_scan_axis(sysjesmap,ismSUGRA);
551     prepare_scan_axis(sysjsumap,ismSUGRA);
552     prepare_scan_axis(sysresmap,ismSUGRA);
553 buchmann 1.27 prepare_scan_axis(syspdfmap,ismSUGRA);
554     prepare_scan_axis(systotmap,ismSUGRA);
555     prepare_scan_axis(sysstatmap,ismSUGRA);
556 buchmann 1.36 prepare_scan_axis(timemap,ismSUGRA);
557 buchmann 1.35
558 buchmann 1.13 if(!systematicsonly&&!efficiencyonly) {
559 buchmann 1.9 limcanvas->cd();
560     limitmap->Draw("COLZ");
561 buchmann 1.22 string titletobewritten="Limits in LSP-Glu plane";
562     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
563     TText *title = write_title(titletobewritten);
564 buchmann 1.9 title->Draw();
565     if(runninglocally) {
566     CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
567     } else {
568 buchmann 1.12 TFile *outputfile;
569     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 :-)
570 buchmann 1.35 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
571 buchmann 1.9 limitmap->Write();
572 buchmann 1.37 if(doexpected) {
573     explimitmap->Write();
574     exp1plimitmap->Write();
575     exp1mlimitmap->Write();
576     exp2plimitmap->Write();
577     exp2mlimitmap->Write();
578     }
579 buchmann 1.18 sysjesmap->Write();
580     sysjsumap->Write();
581 buchmann 1.28 sysresmap->Write();
582 buchmann 1.18 efficiencymap->Write();
583 buchmann 1.52 flipmap->Write();
584 buchmann 1.47 efficiencymapAcc->Write();
585     efficiencymapID->Write();
586     efficiencymapJets->Write();
587     efficiencymapSignal->Write();
588 buchmann 1.37 noscefficiencymap->Write();
589 buchmann 1.27 syspdfmap->Write();
590     systotmap->Write();
591     sysstatmap->Write();
592 buchmann 1.18 Neventsmap->Write();
593 buchmann 1.24 ipointmap->Write();
594 buchmann 1.36 timemap->Write();
595 buchmann 1.9 outputfile->Close();
596     }
597 buchmann 1.35 }
598 buchmann 1.13 if(systematicsonly) { // systematics only :
599 buchmann 1.9 limcanvas->cd();
600     sysjesmap->Draw("COLZ");
601 buchmann 1.22 string titletobewritten="Jet Energy scale in LSP-Glu plane";
602     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
603     TText *title = write_title(titletobewritten);
604 buchmann 1.9 title->Draw();
605     if(runninglocally) {
606     CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
607     }
608     sysjsumap->Draw("COLZ");
609 buchmann 1.22 titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
610     if(ismSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
611     TText *title2 = write_title(titletobewritten);
612 buchmann 1.9 title2->Draw();
613     if(runninglocally) {
614     CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
615     }
616     sysresmap->Draw("COLZ");
617 buchmann 1.22 titletobewritten="Resolution in LSP-Glu plane";
618     if(ismSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
619     TText *title3 = write_title(titletobewritten);
620 buchmann 1.9 title3->Draw();
621     if(runninglocally) {
622     CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
623     }
624 buchmann 1.35
625 buchmann 1.9 if(!runninglocally) {
626     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
627     sysjesmap->Write();
628     sysjsumap->Write();
629     sysresmap->Write();
630 buchmann 1.52 flipmap->Write();
631 buchmann 1.18 efficiencymap->Write();
632 buchmann 1.47 efficiencymapAcc->Write();
633     efficiencymapID->Write();
634     efficiencymapJets->Write();
635     efficiencymapSignal->Write();
636 buchmann 1.37 noscefficiencymap->Write();
637 buchmann 1.18 Neventsmap->Write();
638 buchmann 1.24 ipointmap->Write();
639 buchmann 1.27 syspdfmap->Write();
640     systotmap->Write();
641     sysstatmap->Write();
642 buchmann 1.36 timemap->Write();
643 buchmann 1.9 outputfile->Close();
644     }
645     }//end of systematics only
646 buchmann 1.13 if(efficiencyonly) {
647     limcanvas->cd();
648 buchmann 1.22 string titletobewritten="Efficiencies in LSP-Glu plane";
649     if(ismSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
650     TText *title = write_title(titletobewritten);
651 buchmann 1.47 efficiencymap->Draw("COLZ");
652 buchmann 1.13 title->Draw();
653     if(runninglocally) {
654     CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
655     }
656     limcanvas->cd();
657 buchmann 1.47 efficiencymapAcc->Draw("COLZ");
658     title->Draw();
659     if(runninglocally) {
660     CompleteSave(limcanvas,"SUSYScan/EfficiencyAcc_geq"+any2string(jzb_cut[ibin]));
661     }
662     limcanvas->cd();
663     efficiencymapID->Draw("COLZ");
664     title->Draw();
665     if(runninglocally) {
666     CompleteSave(limcanvas,"SUSYScan/EfficiencyID_geq"+any2string(jzb_cut[ibin]));
667     }
668     limcanvas->cd();
669     efficiencymapJets->Draw("COLZ");
670     title->Draw();
671     if(runninglocally) {
672     CompleteSave(limcanvas,"SUSYScan/EfficiencyJets_geq"+any2string(jzb_cut[ibin]));
673     }
674     limcanvas->cd();
675     efficiencymapSignal->Draw("COLZ");
676     title->Draw();
677     if(runninglocally) {
678     CompleteSave(limcanvas,"SUSYScan/EfficiencySignal_geq"+any2string(jzb_cut[ibin]));
679     }
680     limcanvas->cd();
681     noscefficiencymap->Draw("COLZ");
682     title->Draw();
683     if(runninglocally) {
684     CompleteSave(limcanvas,"SUSYScan/NoEfficiency_geq"+any2string(jzb_cut[ibin]));
685     }
686     limcanvas->cd();
687 buchmann 1.13 sysjesmap->Draw("COLZ");
688 buchmann 1.22 titletobewritten="N(events) in LSP-Glu plane";
689     if(ismSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
690     TText *title2 = write_title(titletobewritten);
691 buchmann 1.13 title2->Draw();
692     if(runninglocally) {
693     CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
694     }
695     if(!runninglocally) {
696     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
697 buchmann 1.24 ipointmap->Write();
698 buchmann 1.13 Neventsmap->Write();
699 buchmann 1.37 noscefficiencymap->Write();
700 buchmann 1.13 efficiencymap->Write();
701 buchmann 1.52 flipmap->Write();
702 buchmann 1.47 efficiencymapAcc->Write();
703     efficiencymapID->Write();
704     efficiencymapJets->Write();
705     efficiencymapSignal->Write();
706 buchmann 1.36 timemap->Write();
707 buchmann 1.13 outputfile->Close();
708     }
709     }//end of efficiencies only
710 buchmann 1.35
711 buchmann 1.31 delete limitmap;
712     delete exclmap;
713     delete sysjesmap;
714     delete sysjsumap;
715     delete sysresmap;
716 buchmann 1.37 delete noscefficiencymap;
717 buchmann 1.31 delete efficiencymap;
718 buchmann 1.47 delete efficiencymapAcc;
719     delete efficiencymapID;
720     delete efficiencymapJets;
721     delete efficiencymapSignal;
722 buchmann 1.31 delete Neventsmap;
723     delete ipointmap;
724     delete syspdfmap;
725     delete systotmap;
726     delete sysstatmap;
727 buchmann 1.13 delete limcanvas;
728 buchmann 1.1 }
729 buchmann 1.4
730 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) {
731 buchmann 1.10 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
732 buchmann 1.4 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
733 buchmann 1.13 scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, ibin, njobs, jobnumber,systonly,effonly);
734 buchmann 1.4 }
735 buchmann 1.6 }
736 buchmann 1.35