ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.18
Committed: Mon May 28 10:20:40 2012 UTC (12 years, 11 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.17: +47 -6 lines
Log Message:
Provide possibility to do shape analysis for benchmark points as well (still testing)

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4     #include <fstream>
5     #include <pthread.h>
6     #include <assert.h>
7 buchmann 1.16 #include <cctype>
8 buchmann 1.1
9     #include <TCut.h>
10     #include <TROOT.h>
11     #include <TCanvas.h>
12     #include <TMath.h>
13     #include <TColor.h>
14     #include <TPaveText.h>
15     #include <TRandom.h>
16     #include <TH1.h>
17     #include <TH2.h>
18     #include <TF1.h>
19     #include <TSQLResult.h>
20     #include <TProfile.h>
21     #include <TKey.h>
22    
23 buchmann 1.9 #include "ShapeDroplet.C"
24     #include "ShapeLimit.C"
25    
26 buchmann 1.1 //#include "TTbar_stuff.C"
27     using namespace std;
28    
29     using namespace PlottingSetup;
30    
31 buchmann 1.13 void scan_SUSY_parameter_space(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, float peakerrordata, float njobs, float jobnumber, bool systonly, bool effonly,bool shapeanalysis);
32    
33     bool isValidShapeResult(ShapeDroplet droplet) {
34 buchmann 1.17 if(droplet.isValid==false) return false;
35 buchmann 1.13 if(droplet.observed>50000) {
36     // error code of ShapeLimit/CreateModel.sh, invoked if there were too many errors during computation
37     write_warning(__FUNCTION__,"Shape limit was ridiculously high ("+any2string(droplet.observed)+"); this is a typical error signature of the combine tool. Shape result will be discarded, and c&c will be carried out instead.");
38     return false;
39     }
40     if(droplet.observed==-12345) {
41     write_warning(__FUNCTION__,"Shape limit was ("+any2string(droplet.observed)+"); this is the error signature of CreateModel.sh / ShapeDroplet. Shape result will be discarded, and c&c will be carried out instead.");
42     return false;
43     }
44     if(droplet.expected>-1&&droplet.expected==0&&droplet.observed>5000) {
45     write_warning(__FUNCTION__,"Observed shape limit was ("+any2string(droplet.observed)+") while expected limit was "+any2string(droplet.expected)+"; this is a typical error signature of the combine tool. Shape result will be discarded, and c&c will be carried out instead.");
46     return false;
47     }
48     if(droplet.expected>-1&&droplet.expected/droplet.observed>50) {
49     write_warning(__FUNCTION__,"Observed shape limit was ("+any2string(droplet.observed)+") while expected limit was "+any2string(droplet.expected)+"; such a high ratio between expected & observed limit is a typical error signature of the combine tool. Shape result will be discarded, and c&c will be carried out instead.");
50     return false;
51     }
52     if(droplet.expected>-1&&droplet.observed/droplet.expected>50) {
53     write_warning(__FUNCTION__,"Observed shape limit was ("+any2string(droplet.observed)+") while expected limit was "+any2string(droplet.expected)+"; such a high ratio between observed & expected limit is a typical error signature of the combine tool. Shape result will be discarded, and c&c will be carried out instead.");
54     return false;
55     }
56     return true;
57     }
58    
59 buchmann 1.1 void susy_scan_axis_labeling(TH2F *histo) {
60     histo->GetXaxis()->SetTitle("m_{#Chi_{2}^{0}}-m_{LSP}");
61     histo->GetXaxis()->CenterTitle();
62     histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
63     histo->GetYaxis()->CenterTitle();
64     }
65    
66     void prepare_scan_axis(TH2 *variablemap,int scantype) {
67     //assuming regular SMS
68     variablemap->GetXaxis()->SetTitle("m_{glu}");
69     variablemap->GetYaxis()->SetTitle("m_{LSP}");
70    
71     if(scantype==mSUGRA) {
72     variablemap->GetXaxis()->SetTitle("m_{0}");
73     variablemap->GetYaxis()->SetTitle("m_{1/2}");
74     }
75    
76     if(scantype==GMSB) {
77     variablemap->GetXaxis()->SetTitle("m_{glu}");
78     variablemap->GetYaxis()->SetTitle("m_{NLSP}");
79     }
80    
81     variablemap->GetXaxis()->CenterTitle();
82     variablemap->GetYaxis()->CenterTitle();
83     }
84    
85     void set_SUSY_style() {
86     Int_t MyPalette[100];
87     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
88     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
89     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
90     Double_t stop[] = {0., .25, .50, .75, 1.0};
91     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
92     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
93    
94     gStyle->SetPalette(100, MyPalette);
95    
96     gStyle->SetPadRightMargin(0.15);
97    
98     }
99    
100     bool delete_any_cached_scans() {
101 buchmann 1.8 char hostname[1023];
102     gethostname(hostname,1023);
103 buchmann 1.6
104    
105     /*
106 buchmann 1.1 //This should only be called via CRAB
107 buchmann 1.14 dout << " Deleting all cached files." << endl;
108 buchmann 1.1 gSystem->Exec("ls -ltrh | grep root");
109 buchmann 1.6 if(!((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))))
110     {
111 buchmann 1.1 vector<string> all_files;
112     char currentpath[1024];
113     TString directory=TString(getcwd(currentpath,1024));
114     directory=directory+"/";
115     process_directory(directory,all_files);
116     for(int ifile=0;ifile<all_files.size();ifile++)
117     {
118     if(Contains(all_files[ifile],"_clean_splitup_")) {
119     dout << " About to delete " << all_files[ifile] << endl;
120     gSystem->Exec(((string)"rm "+all_files[ifile]).c_str());
121     }
122     }
123 buchmann 1.6 return true;
124     }
125     */
126 buchmann 1.8 if(!((Contains(hostname,"t3ui")||Contains(hostname,"t3wn")))) {
127 buchmann 1.14 dout << "Going to purge files in local_storage that have been loaded!" << endl;
128 buchmann 1.15 for(int i=0;i<(int)SUSYScanSpace::loaded_files.size();i++) {
129 buchmann 1.6 gSystem->Exec(((string)"rm "+SUSYScanSpace::loaded_files[i]).c_str());
130     dout << " Purging : Deleted file " << SUSYScanSpace::loaded_files[i] << endl;
131     }
132     }
133 buchmann 1.1 return true;
134     }
135    
136     bool initialized_t2=false;
137    
138     int srmcpretries=0;
139    
140 buchmann 1.8 void load_local_scan_sample(int a, int b, int &scanfileindex,int scantype,int mglu, int mlsp, bool isretry=false) {
141     stringstream filetoload;
142     string samplename;
143 buchmann 1.1 filetoload << "/shome/buchmann/ntuples/"<<PlottingSetup::ScanSampleDirectory;
144 buchmann 1.4 if(scantype==mSUGRA) {
145     //filetoload << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
146     filetoload.str("");
147     filetoload << "/shome/lbaeni/jzb/" << PlottingSetup::ScanSampleDirectory << "/mSUGRA_M0_" << mglu << "__M12_" << mlsp << ".root";
148     samplename="mSUGRA";
149     // filetoload << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
150     }
151     if(scantype==SMS) {
152     filetoload << "/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
153     samplename="SMS";
154     }
155     if(scantype==GMSB) {
156     filetoload << "/GMSB_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
157     samplename="GMSB";
158     }
159 buchmann 1.9
160     if(scantype==SMS && Contains(PlottingSetup::ScanSampleDirectory,"T1lh")) {
161     filetoload.str("");
162     filetoload << "/shome/lbaeni/jzb/" << PlottingSetup::ScanSampleDirectory << "/SMS_MassGlu_" << mglu << "__MassLSP_" << mlsp << ".root";
163     samplename="SMS";
164     }
165    
166 buchmann 1.3 if(scansample.collection.size()<1||!Contains(((scansample.collection)[(scansample.collection).size()-1]).filename,"_"+any2string(a)+"_"+any2string(b))) {
167 buchmann 1.1 dout << "The last sample is NOT the same one as the current one, possibly popping off last one and adding the new one." << endl;
168 buchmann 1.4 if((scansample.collection).size()>=1) {
169 buchmann 1.1 scansample.RemoveLastSample();
170     }
171     scanfileindex=(scansample.collection).size();
172     //New: Loading file when necessary, not before (avoiding high memory usage and startup times)
173 buchmann 1.4
174     scansample.AddSample(filetoload.str(),samplename,1,1,false,true,scanfileindex,kRed);
175     dout << "Just added the following file: " << filetoload.str() << endl;
176 buchmann 1.1 } else {
177     dout << "Last sample is the same as the current one. Recycling it." << endl;
178     scanfileindex=(scansample.collection).size()-1;
179     }
180     dout << " Going to use the following file: " << filetoload.str() << endl;
181 buchmann 1.8 }
182    
183     void load_remote_scan_sample(int a, int b, int &scanfileindex,int scantype,int mglu, int mlsp, bool isretry=false) {
184 buchmann 1.1 write_info(__FUNCTION__,"Hello, CRAB! Might need to load files ...");
185 buchmann 1.8 string samplename;
186 buchmann 1.1 PlottingSetup::limitpatience=PlottingSetup::limitpatienceCRAB;
187     stringstream copyfile;
188 buchmann 1.4 gSystem->Exec("mkdir -p local_storage");
189 buchmann 1.1 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;
190 buchmann 1.4 if(scantype==mSUGRA) {
191 buchmann 1.5 copyfile<< "/mSUGRA_M0_" << mglu << "__M12_" << mlsp << ".root local_storage/mSUGRA_M0_" << mglu << "__M12_" << mlsp << ".root ";
192 buchmann 1.4 samplename="mSUGRA";
193     }
194     if(scantype==SMS) {
195     copyfile << "/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root " << "local_storage/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root ";
196     samplename="SMS";
197     }
198     if(scantype==GMSB) {
199     copyfile << "/GMSB_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root " << "local_storage/GMSB_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root ";
200     samplename="GMSB";
201     }
202 buchmann 1.1 stringstream newfilename;
203 buchmann 1.5 // if(scantype==mSUGRA) newfilename << "local_storage/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
204     if(scantype==mSUGRA) newfilename << "local_storage/mSUGRA_M0_" << mglu << "__M12_" << mlsp << ".root";
205 buchmann 1.4 if(scantype==SMS) newfilename << "local_storage/SMS_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
206     if(scantype==GMSB) newfilename << "local_storage/GMSB_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
207 buchmann 1.1
208 buchmann 1.6 SUSYScanSpace::SUSYscantype=scantype;
209    
210 buchmann 1.7 if((scansample.collection).size()==0||!Contains(((scansample.collection)[(scansample.collection).size()-1]).filename,"_"+any2string(a)+"_"+any2string(b))||(a==0&&b==0)&&!initialized_t2) {
211 buchmann 1.1 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;
212 buchmann 1.5 while((scansample.collection).size()>0) {
213 buchmann 1.1 scansample.RemoveLastSample();
214     }
215 buchmann 1.14 dout << "New scanfileindex stems from scansample size: " << (scansample.collection).size() << endl;
216 buchmann 1.1 scanfileindex=(scansample.collection).size();
217     //New: Loading file when necessary, not before (avoiding high memory usage and startup times)
218 buchmann 1.5 if(1) {
219     if(!doesROOTFileExist(newfilename.str())) {
220     dout << "Going to download the scan file with the following copy command: " << copyfile.str() << endl;
221 buchmann 1.7 int retcode = gSystem->Exec(copyfile.str().c_str()); // download it if it hasn't been downloaded before
222     if(retcode==0) SUSYScanSpace::loaded_files.push_back(newfilename.str()); // adding it to the list of loaded files (will be deleted once we finish running
223 buchmann 1.5 }
224 buchmann 1.1 if(doesROOTFileExist(newfilename.str())) {
225     initialized_t2=true;
226 buchmann 1.14 dout << "Going to add the following sample: " << newfilename.str() << endl;
227 buchmann 1.5 gSystem->Exec(("ls -ltrh "+newfilename.str()).c_str());
228     scansample.AddSample(newfilename.str(),samplename,1,1,false,true,scanfileindex,kRed);
229 buchmann 1.1 } else {
230     srmcpretries++;
231     if(srmcpretries<5) {
232     dout << "The file could not be loaded correctly - retrying!" << endl;
233     sleep(5);
234 buchmann 1.8 load_remote_scan_sample(a,b,scanfileindex,scantype,mglu,mlsp,true);
235 buchmann 1.1 } else {
236     dout << "Have tried 5 times to load this sample. Giving up now and failing the program execution" << endl;
237 buchmann 1.4 assert(srmcpretries<5);
238 buchmann 1.1 dout << "The command " << copyfile.str() << " failed to copy the file to the local storage (saving it as " << newfilename.str() << ")" << endl;
239     }
240     }
241     }
242     } else {
243     dout << "Last sample is the same as the current one. Recycling it." << endl;
244     scanfileindex=(scansample.collection).size()-1;
245     }
246 buchmann 1.8 }
247    
248     void load_scan_sample(int a, int b, int &scanfileindex,int scantype,int mglu, int mlsp, bool isretry=false) {
249    
250     // There is no need to define your sample here. That is done in Setup.C where you define the loading directory!
251 buchmann 1.3
252 buchmann 1.12 SUSYScanSpace::SUSYscantype=scantype;
253 buchmann 1.8 dout << "Going to load file with Xzone=" << a << " and Yzone=" << b << " for scantype (mSugra: " << (bool)(scantype==mSUGRA) << " , SMS: " << (bool)(scantype==SMS) << " , GMSB: " << (bool)(scantype==GMSB) << ")" << endl;
254     char hostname[1023];
255     gethostname(hostname,1023);
256     if((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))) load_local_scan_sample(a,b,scanfileindex,scantype,mglu,mlsp,isretry);
257     else load_remote_scan_sample(a,b,scanfileindex,scantype,mglu,mlsp,isretry);
258 buchmann 1.1 }
259    
260 buchmann 1.3 /*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) {
261 buchmann 1.1 altxs=0;
262 buchmann 1.3 for(int iproc=1;iproc<=10;iproc++) altxs+=GetXSecForPointAndChannel(mglu,mlsp,xsec,iproc);
263 buchmann 1.1 return altxs;
264 buchmann 1.3 }*/
265 buchmann 1.1
266     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) {
267     bool runninglocally=true;
268     if(njobs>-1&&jobnumber>-1) {
269     runninglocally=false;
270     dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
271     } else {
272     dout << "Running locally " << endl;
273     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;
274     }
275    
276     string massgluname="MassGlu";
277     string massLSPname="MassLSP";
278     jzbSel=jzb_cut[ibin];
279     geqleq="geq";
280     automatized=true;
281     mcjzbexpression=mcjzb;
282    
283     string prefix="SMS_";
284     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
285     int scantype=SMS;
286     TIter nextkey(fsyst->GetListOfKeys());
287     TKey *key;
288     while ((key = (TKey*)nextkey()))
289     {
290     TObject *obj = key->ReadObj();
291 buchmann 1.4 if(Contains((string)(obj->GetName()),"SUGRA")) scantype=mSUGRA;
292 buchmann 1.1 if(Contains((string)(obj->GetName()),"GMSB")) scantype=GMSB;
293     }
294    
295     map < pair<float, float>, map<string, float> > xsec;
296    
297     if(scantype==mSUGRA) {
298     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
299     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
300     mglustart=m0start;
301 buchmann 1.10 xsec=getXsec(PlottingSetup::cbafbasedir+"/"+mSUGRAxsFile);
302    
303 buchmann 1.1 mgluend=m0end;
304     mglustep=m0step;
305     mLSPstart=m12start;
306     mLSPend=m12end;
307     mLSPstep=m12step;
308     prefix="mSUGRA_";
309     dout << "mSUGRA scan has been set up." << endl;
310     }
311     if(scantype==SMS) {
312     dout << "SMS scan has been set up." << endl;
313     write_warning(__FUNCTION__,"Don't have the correct XS file yet");
314     }
315     if(scantype==GMSB) {
316     string massgluname="MassGMSBGlu";
317     string massLSPname="MassGMSBChi";
318     prefix="GMSB_";
319     dout << "GMSB scan has been set up." << endl;
320     write_warning(__FUNCTION__,"Don't have the correct XS file yet");
321     }
322    
323     set_SUSY_style();
324    
325     TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
326    
327     int Npoints=0;
328     for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
329     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
330     }
331     TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
332     //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());
333     TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
334     TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
335     TH2F *lflip = (TH2F*)fsyst->Get((prefix+"flipmap"+any2string(jzb_cut[ibin])).c_str());
336 buchmann 1.3 TH2F *XSmap = (TH2F*)fsyst->Get((prefix+"XS"+any2string(jzb_cut[ibin])).c_str());
337 buchmann 1.1
338     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
339     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
340     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
341     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
342     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
343     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
344    
345     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);
346     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);
347 buchmann 1.5 TH2F *asymptoticmap = new TH2F((prefix+"asymptoticmap"+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);
348 buchmann 1.1
349    
350     if(!fullerr || !mceff || !NEvents) {
351     write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
352     dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
353     delete limcanvas;
354     return;
355     }
356    
357     bool doexpected=true;
358    
359     int ipoint=-1;
360     for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
361     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
362     {
363     ipoint++;
364     if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
365     int GlobalBin=flipmap->FindBin(mglu,mlsp);
366     float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
367     float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
368     float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
369     int flipped = (int)(lflip->GetBinContent(lflip->FindBin(mglu,mlsp)));
370     flipmap->SetBinContent(GlobalBin,flipped);
371     dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
372     dout << "Found : MCeff=" << currmceff << " and total error=" << currtoterr << " and Nevents=" << nevents << endl;
373     string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
374     if(currmceff<=0||currtoterr<=0||nevents==0) {
375     dout << " Nothing to work with, skipping this point." << endl;
376     continue;
377     }
378     vector<float> sigmas;
379 buchmann 1.9 if(scantype!=mSUGRA) {
380     sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true, flipped,true);
381     write_warning(__FUNCTION__,"Temporarily doing asymptotic limits!!!!");
382     }
383 buchmann 1.3 else {
384     //this is a bit trickier - what we want to do is compute the limit fast, and if it is in [0.5 xs, 2xs], compute it again but "correctly"!
385     vector<float> asigmas;
386     asigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true, flipped,true); // asymptotic limit first
387     float strength=asigmas[0]/XSmap->GetBinContent(GlobalBin);
388 buchmann 1.9 /* if(strength>0.5&&strength<2) {
389 buchmann 1.5 sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true, flipped); // asymptotic limit first
390     asymptoticmap->SetBinContent(GlobalBin,0);
391 buchmann 1.9 } else {*/
392 buchmann 1.5 sigmas=asigmas;
393     asymptoticmap->SetBinContent(GlobalBin,1);
394 buchmann 1.9 /* }*/
395 buchmann 1.3 exclmap->SetBinContent(GlobalBin,strength);
396     }
397    
398 buchmann 1.1 if(sigmas[0]>0) limitmap->SetBinContent(GlobalBin,sigmas[0]); //anything else is an error code
399     if(sigmas.size()>1) {
400     explimitmap->SetBinContent(GlobalBin,sigmas[1]);
401     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
402     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
403     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
404     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
405     }
406    
407     dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " ) at " << sigmas[0] << endl;
408     }
409     }
410    
411     prepare_scan_axis(limitmap,scantype);
412 buchmann 1.6 gSystem->Exec("mkdir -p output");
413 buchmann 1.1 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 :-)
414     outputfile->cd();
415     limitmap->Write();
416 buchmann 1.8 XSmap->Write();
417 buchmann 1.1 flipmap->Write();
418 buchmann 1.5 asymptoticmap->Write();
419 buchmann 1.1 if(doexpected) {
420     explimitmap->Write();
421     exp1plimitmap->Write();
422     exp1mlimitmap->Write();
423     exp2plimitmap->Write();
424     exp2mlimitmap->Write();
425     }
426 buchmann 1.5 if(scantype==mSUGRA) exclmap->Write();
427 buchmann 1.1 outputfile->Close();
428     delete limcanvas;
429     }
430    
431     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
432     dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
433     TFile *fsyst = new TFile(fsystfilename.c_str());
434     if(!fsyst) {
435     write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
436     return;
437     }
438 buchmann 1.15 for(int ibin=0;ibin<(int)jzb_cut.size();ibin++) {
439 buchmann 1.1 establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
440     }
441     }
442    
443    
444 buchmann 1.16 string SimpleFormat(string input) {
445     string output;
446     for (unsigned int i=0; i<input.length();i++) {
447     if (isalnum(input[i])) //If current character is alpha-numeric
448     output+= input[i]; //Add the character to strConverted
449    
450     }
451     return output;
452     }
453 buchmann 1.1
454    
455 buchmann 1.18 vector<float> scan_SUSY_parameter_space_for_one_cut(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, float peakerrordata, int ibin,float njobs=-1, float jobnumber=-1, bool systematicsonly=false,bool efficiencyonly=false, bool shapeanalysis=false,string specialfilename="") {
456     //note: njobs==-2 means that we're running a benchmark point
457     vector<float> empty;
458 buchmann 1.9
459 buchmann 1.18 if(shapeanalysis&&ibin>0) return empty; // pointless since we're doing a shape analysis :-)
460 buchmann 1.9
461 buchmann 1.1 bool runninglocally=true;
462     if(njobs>-1&&jobnumber>-1) {
463     runninglocally=false;
464 buchmann 1.2 dout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
465 buchmann 1.1 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
466     } else {
467     dout << "Running locally " << endl;
468 buchmann 1.18 if(njobs>-2) dout << "If you are running more than one point and you want to see the results THIS month try running scripts from DistributedModelCalculation" << endl;
469 buchmann 1.1 }
470    
471     jzbSel=jzb_cut[ibin];
472 buchmann 1.13 if(shapeanalysis) jzbSel=0;
473 buchmann 1.1 geqleq="geq";
474     automatized=true;
475     mcjzbexpression=mcjzb;
476    
477     string massgluname="MassGlu";
478     string massLSPname="MassLSP";
479    
480     string prefix="SMS_";
481     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
482     int scantype=SMS;
483 buchmann 1.9 if(Contains((PlottingSetup::ScanSampleDirectory),"SUGRA")) scantype=mSUGRA;
484     if(Contains((PlottingSetup::ScanSampleDirectory),"GMSB")) scantype=GMSB;
485 buchmann 1.1
486     if(scantype==mSUGRA) {
487     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
488     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
489     mglustart=m0start;
490     mgluend=m0end;
491     mglustep=m0step;
492     mLSPstart=m12start;
493     mLSPend=m12end;
494     mLSPstep=m12step;
495     prefix="mSUGRA_";
496     dout << "mSUGRA scan has been set up." << endl;
497     }
498     if(scantype==SMS) {
499     dout << "SMS scan has been set up." << endl;
500     }
501     if(scantype==GMSB) {
502     dout << "GMSB scan has been set up." << endl;
503     prefix="GMSB_";
504     massgluname="MassGMSBGlu"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
505     massLSPname="MassGMSBChi"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
506     }
507    
508     Int_t MyPalette[100];
509     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
510     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
511     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
512     Double_t stop[] = {0., .25, .50, .75, 1.0};
513     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
514     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
515    
516     gStyle->SetPalette(100, MyPalette);
517    
518 buchmann 1.12 TH2F *rawlimitmap = new TH2F((prefix+"rawlimitmap"+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
519     TH2F *rawelimitmap = new TH2F((prefix+"rawelimitmap"+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
520    
521 buchmann 1.1 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
522     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
523     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
524     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
525     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
526     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
527    
528 buchmann 1.2 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);
529     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);
530     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);
531     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);
532     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);
533     TH2F *efficiencymapmet = new TH2F((prefix+"efficiencymapmet"+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);
534     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);
535     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);
536 buchmann 1.1 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);
537     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);
538 buchmann 1.3 TH2F *efficiencymapContam = new TH2F((prefix+"efficiencymapContam"+any2string(jzbSel)).c_str(),"",(int)((mgluend-mglustart)/mglustep+1),mglustart-0.5*mglustep,mgluend+0.5*mglustep,int((mLSPend-
539     mLSPstart)/mLSPstep+1),mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
540 buchmann 1.1 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);
541 buchmann 1.2 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);
542     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);
543     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);
544     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);
545     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);
546 buchmann 1.3 TH2F *XSmap = new TH2F((prefix+"XS"+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);
547 buchmann 1.8 TH2F *absXSmap = new TH2F((prefix+"absXS"+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);
548 buchmann 1.9 TH2F *FilterEff = new TH2F((prefix+"FilterEfficiency"+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);
549 buchmann 1.13
550 buchmann 1.16 TH2F *ScanIdentifier = new TH2F(("ScanIdentifier"+any2string(jzbSel)+SimpleFormat(PlottingSetup::ScanSampleDirectory)).c_str(),("ScanIdentifier"+any2string(jzbSel)+SimpleFormat(PlottingSetup::ScanSampleDirectory)).c_str(),1,0,1,1,0,1);
551    
552    
553 buchmann 1.13 TH2F *asymptoticmap = new TH2F((prefix+"asymptoticmap"+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);
554     // only used for asymptoticmap
555 buchmann 1.1
556 buchmann 1.2 TH2F *imposedxmap;
557     TH2F *realxmap;
558 buchmann 1.1
559 buchmann 1.3 TH2F *centermap;
560     TH2F *widthmap;
561    
562 buchmann 1.2 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);
563    
564     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);
565 buchmann 1.1
566 buchmann 1.2 if(ibin==0) {
567 buchmann 1.3 centermap = new TH2F((prefix+"centermap").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);
568     widthmap = new TH2F((prefix+"widthmap").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);
569    
570 buchmann 1.2 imposedxmap = new TH2F((prefix+"imposedxmap").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);
571     realxmap = new TH2F((prefix+"realxmap").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);
572     }
573    
574 buchmann 1.13
575     if(shapeanalysis) jzbSel=jzb_cut[ibin];
576 buchmann 1.2 vector<int> susy_Zdecay_origin;
577     vector<TH2F*> h_susy_Zdecay_origin;
578     // we only generate these histograms IF we're dealing with the lowest cut! (we don't need them n times, they're the same for all of them)
579     for(int i=1000022;i<1000039;i++) {
580     if(ibin>0) continue;
581     susy_Zdecay_origin.push_back(i);
582     TH2F *susy_dec = new TH2F((prefix+"SUSY_Decay_From_"+any2string(i)+"_to_Z").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);
583     h_susy_Zdecay_origin.push_back(susy_dec);
584     }
585     for(int i=2000006;i<2000016;i++) {
586     if(ibin>0) continue;
587     susy_Zdecay_origin.push_back(i);
588     TH2F *susy_dec = new TH2F((prefix+"SUSY_Decay_From_"+any2string(i)+"_to_Z").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);
589     h_susy_Zdecay_origin.push_back(susy_dec);
590     }
591    
592     TH2F *PrimaryZSource = new TH2F((prefix+"PrimaryZSource").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);
593     TH2F *SecondaryZSource = new TH2F((prefix+"SecondaryZSource").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);
594    
595 buchmann 1.1 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
596    
597     gStyle->SetPadRightMargin(0.15);
598    
599     TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
600    
601    
602     bool doexpected=true;
603    
604     int Npoints=0;
605     for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
606     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
607     }
608 buchmann 1.3
609     map < pair<float, float>, map<string, float> > xsec;
610     if(scantype==mSUGRA) {
611 buchmann 1.12 xsec=getXsec(PlottingSetup::cbafbasedir+"/"+mSUGRAxsFile);
612 buchmann 1.3 }
613    
614 buchmann 1.1 int ipoint=-1;
615     for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
616     for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
617     {
618     ipoint++;
619     int GlobalBin=efficiencymap->FindBin(mglu,mlsp);
620     if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
621 buchmann 1.13
622 buchmann 1.1 int flipped=0;
623     float result=-987,resulterr=-987;
624     float m0trees = PlottingSetup::mgluend;
625     float m12trees = PlottingSetup::mLSPend;
626     int a = int((PlottingSetup::ScanXzones*mlsp)/(m12trees+1));
627     int b = int((PlottingSetup::ScanYzones*mglu)/(m0trees+1));
628     int scanfileindex=PlottingSetup::ScanYzones*a+b;
629 buchmann 1.18 if(njobs>-2) load_scan_sample(a,b,scanfileindex,scantype,mglu,mlsp);
630     else {
631     if((scansample.collection).size()>=1) scansample.RemoveLastSample();
632     scanfileindex=(scansample.collection).size();
633     scansample.AddSample(specialfilename,"LMpoint",1,1,false,true,scanfileindex,kRed);
634     }
635 buchmann 1.1
636     clock_t start,finish;
637     start = clock(); // starting the clock to measure how long the computation takes!
638     stringstream addcut;
639     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
640 buchmann 1.18 if(njobs==-2) {
641     dout << "Processing a signal sample, not a scan : setting addcut to \"eventNum>0||eventNum<1\" (empty cut)" << endl;
642     addcut.str("(eventNum>0||eventNum<1)");
643     }
644    
645 buchmann 1.1 (scansample.collection)[scanfileindex].events->Draw("eventNum",addcut.str().c_str(),"goff");
646     float nevents = (scansample.collection)[scanfileindex].events->GetSelectedRows();
647     vector<vector<float> > systematics;
648     if(nevents<10) {
649 buchmann 1.3 dout << "This point ("<<ipoint<<" / " << Npoints << ") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be \033[1;31m skipped \033[0m."<< endl;
650 buchmann 1.1 continue;
651     } else {
652 buchmann 1.2 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore \033[1;32m not be skipped \033[0m. " << endl;
653 buchmann 1.13 if(PlottingSetup::RestrictToMassPeak==true) dout << "Analysis type: on-peak" << endl;
654     if(PlottingSetup::RestrictToMassPeak==false) dout << "Analysis type: offpeak" << endl;
655     if(shapeanalysis) dout << "Shape analysis? Yes." << endl;
656     else dout << "Shape analysis? No." << endl;
657 buchmann 1.2 }
658     float hitrecord=0;
659     int hitrecordholder=0;
660     float hitsecondplace=0;
661     int hitsecondplaceholder=0;
662 buchmann 1.18 for(int imo=0;imo<(int)susy_Zdecay_origin.size()&&ibin==0&&njobs>-2;imo++) {
663 buchmann 1.2 if(ibin>0) continue;
664     int MotherParticlePDGid = susy_Zdecay_origin[imo];
665     (scansample.collection)[scanfileindex].events->Draw("eventNum",("("+addcut.str()+")&&(abs(SourceOfZ-"+any2string(MotherParticlePDGid)+")<0.5)").c_str(),"goff");
666     float hits = (scansample.collection)[scanfileindex].events->GetSelectedRows();
667     hits/=nevents;
668     h_susy_Zdecay_origin[imo]->SetBinContent(GlobalBin,hits);
669     if(hits>hitrecord) {
670     hitsecondplace=hitrecord;
671     hitsecondplaceholder=hitrecordholder;
672     hitrecord=hits;
673     hitrecordholder=imo;
674     }
675     if(hits<hitrecord&&hits>hitsecondplace) {
676     hitsecondplace=hits;
677     hitsecondplaceholder=imo;
678     }
679     }
680     if(ibin==0) {
681     PrimaryZSource->SetBinContent(GlobalBin,hitrecordholder);
682     SecondaryZSource->SetBinContent(GlobalBin,hitsecondplaceholder);
683     }
684    
685 buchmann 1.18 if(ibin==0&&njobs>-2) {
686 buchmann 1.2 TH1F *realxhisto = new TH1F("realxhisto","realxhisto",1000,0,1);
687     (scansample.collection)[scanfileindex].events->Draw("realx>>realxhisto",addcut.str().c_str(),"goff");
688     realxmap->SetBinContent(GlobalBin,realxhisto->GetMean());
689     realxmap->SetBinError(GlobalBin,realxhisto->GetRMS());
690     (scansample.collection)[scanfileindex].events->Draw("imposedx>>realxhisto",addcut.str().c_str(),"goff");
691     imposedxmap->SetBinContent(GlobalBin,realxhisto->GetMean());
692     imposedxmap->SetBinError(GlobalBin,realxhisto->GetRMS());
693 buchmann 1.3 stringstream specialexpression;
694     specialexpression << mcjzb << ">>jzbhisto";
695     TH1F *jzbhisto = new TH1F("jzbhisto","jzbhisto",100,-500,500);
696     (scansample.collection)[scanfileindex].events->Draw(specialexpression.str().c_str(),addcut.str().c_str(),"goff");
697     centermap->SetBinContent(GlobalBin,jzbhisto->GetMean());
698     widthmap->SetBinContent(GlobalBin,jzbhisto->GetRMS());
699 buchmann 1.2 delete realxhisto;
700 buchmann 1.3 delete jzbhisto;
701 buchmann 1.1 }
702    
703    
704 buchmann 1.5 if(scantype==mSUGRA) {
705     float absxs=0;
706     for(int i=0;i<12;i++) absxs+=GetXSecForPointAndChannel(mglu,mlsp,xsec,i);
707 buchmann 1.8 TFile *FilterEffFile = new TFile(PlottingSetup::FilterEfficiencyFile.c_str());
708     TH2F *FilterEfficiency = (TH2F*)FilterEffFile->Get("FilterEfficiency");
709     float filtereff = FilterEfficiency->GetBinContent(FilterEfficiency->FindBin(mglu,mlsp));
710     FilterEff->SetBinContent(GlobalBin,filtereff);
711     FilterEffFile->Close();
712     absXSmap->SetBinContent(GlobalBin,absxs);
713     absxs*=filtereff;
714 buchmann 1.5 XSmap->SetBinContent(GlobalBin,absxs);
715     }
716    
717 buchmann 1.14 if(nevents!=0) {
718 buchmann 1.3 Value effwosigcont = MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,scantype,xsec,addcut.str(),-1);
719 buchmann 1.2 if(result<0&&allowflipping) {
720 buchmann 1.1 write_info(__FUNCTION__,"Found negative efficiency (signal distribution populating JZB<0 more than JZB>0) - flipping analysis!");
721     flipped=1;
722 buchmann 1.3 MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,scantype,xsec,addcut.str(),-1);
723 buchmann 1.1 }
724     efficiencymap->SetBinContent(GlobalBin,result);
725     efficiencymap->SetBinError(GlobalBin,resulterr);
726     flipmap->SetBinContent(GlobalBin,flipped);
727     noscefficiencymap->SetBinContent(GlobalBin,effwosigcont.getValue());
728     noscefficiencymap->SetBinError(GlobalBin,effwosigcont.getError());
729 buchmann 1.2 efficiencymapContam->SetBinContent(GlobalBin,effwosigcont.getValue()-result);
730     efficiencymapContam->SetBinError(GlobalBin,TMath::Sqrt(effwosigcont.getError()+resulterr));
731 buchmann 1.1 //Partial efficiencies
732     float resultAcc, resultID, resultJets, resultSignal, resultmet;
733     float resulterrAcc, resulterrID, resulterrJets, resulterrSignal, resulterrmet;
734     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultAcc,resulterrAcc,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 1);
735     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultID,resulterrID,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 2);
736     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultJets,resulterrJets,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 3);
737     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultSignal,resulterrSignal,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 4);
738     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultmet,resulterrmet,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 5);
739     efficiencymapAcc->SetBinContent(GlobalBin,resultAcc);
740     efficiencymapAcc->SetBinError(GlobalBin,resulterrAcc);
741     efficiencymapmet->SetBinContent(GlobalBin,resultmet);
742     efficiencymapmet->SetBinError(GlobalBin,resulterrmet);
743     efficiencymapID->SetBinContent(GlobalBin,resultID);
744     efficiencymapID->SetBinError(GlobalBin,resulterrID);
745     efficiencymapJets->SetBinContent(GlobalBin,resultJets);
746     efficiencymapJets->SetBinError(GlobalBin,resulterrJets);
747     efficiencymapSignal->SetBinContent(GlobalBin,resultSignal);
748     efficiencymapSignal->SetBinError(GlobalBin,resulterrSignal);
749     finish = clock();
750     }
751     Neventsmap->SetBinContent(GlobalBin,nevents);
752     ipointmap->SetBinContent(GlobalBin,ipoint);
753     if(efficiencyonly) continue;
754 buchmann 1.9
755     if(!shapeanalysis) {
756     do_systematics_for_one_file((scansample.collection)[scanfileindex].events,(int)nevents,"SUSY SCAN", systematics,flipped, xsec, mcjzb,datajzb,peakerror,requireZ, addcut.str(),true,scantype);
757 buchmann 1.15 // float JZBcutat = systematics[0][0];
758 buchmann 1.9 float mceff = systematics[0][1];
759     float mcefferr = systematics[0][2];//MC stat error
760     float toterr = systematics[0][4];
761     float sys_jes = systematics[0][5]; // Jet Energy Scale
762     float sys_jsu = systematics[0][6]; // JZB scale uncertainty
763     float sys_res = systematics[0][7]; // resolution
764 buchmann 1.15 // float mcwoscef = systematics[0][8]; // efficiency without signal contamination
765     // float mcwoscefr= systematics[0][9]; // error on efficiency without signal contamination
766 buchmann 1.9 float sys_pdf = 0;
767     if(systematics[0].size()>10) sys_pdf = systematics[0][10]; // PDF
768 buchmann 1.14 dout << "Going to store: total error is: " << toterr << " and the relative tot error, i.e. total error / mc efficiency is " << toterr/mceff << endl;
769 buchmann 1.9 if(mceff!=mceff||toterr!=toterr||mceff<0 && (!systematicsonly&&!efficiencyonly)) {
770 buchmann 1.13 dout << "Limits can't be calculated for this configuration (" << massgluname <<"="<<mglu<<" , " << massLSPname << "="<<mlsp << ") as either the efficiency or its error are not positive numbers! (mceff="<<mceff<<"and toterr="<<toterr<<")"<< endl;
771 buchmann 1.9 continue;
772     } else {
773     // Systematics and efficiencies make sense (i.e. non-zero, and all numbers)
774     if(!systematicsonly&&!efficiencyonly) {
775     dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
776     vector<float> sigmas;
777     string plotfilename=(string)(TString((scansample.collection)[scanfileindex].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
778     sigmas=compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,true,flipped);
779     // do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
780     if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
781     limitmap->SetBinContent(GlobalBin,sigmas[0]);
782     if(sigmas.size()>1) {
783     explimitmap->SetBinContent(GlobalBin,sigmas[1]);
784     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
785     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
786     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
787     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
788     }
789     sysjesmap->SetBinContent(GlobalBin,sys_jes);
790     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
791     sysresmap->SetBinContent(GlobalBin,sys_res);
792     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
793     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
794     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
795     dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
796     }//end of if sigma is positive
797     }//end of not systematics only condition
798     if(systematicsonly) {
799     sysjesmap->SetBinContent(GlobalBin,sys_jes);
800     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
801     sysresmap->SetBinContent(GlobalBin,sys_res);
802     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
803     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
804     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
805     }
806     }//efficiency is valid
807 buchmann 1.13 }
808     if(shapeanalysis) {
809 buchmann 1.9 //shape analysis
810 buchmann 1.14 dout << "This is the shape analysis. Have fun with it!" << endl;
811 buchmann 1.11 float quickmceff,quickmcefferr;
812     MCefficiency((scansample.collection)[scanfileindex].events,quickmceff,quickmcefferr,flipped,mcjzb,requireZ,(int)nevents,scantype,xsec,addcut.str(),-1);
813     if(quickmceff==0) {
814     write_warning(__FUNCTION__,"The MC efficiency is zero - need to skip this point.");
815     continue;
816     }
817 buchmann 1.9 stringstream PointName;
818     PointName << massgluname << "_" << mglu << "__" << massLSPname << "_" << mlsp;
819 buchmann 1.10 SUSYScanSpace::SavedMLSP=mlsp;
820     SUSYScanSpace::SavedMGlu=mglu;
821     SUSYScanSpace::SavedMLSPname=massLSPname;
822     SUSYScanSpace::SavedMGluname=massgluname;
823 buchmann 1.17 float referenceXS=0;
824     if(scantype==mSUGRA) referenceXS=XSmap->GetBinContent(GlobalBin);
825     else referenceXS=getSMSxs(mlsp,mglu);
826     float low_fullCLs=referenceXS*0.5;
827     float high_fullCLs=referenceXS*2.5;
828     if(scantype!=mSUGRA) {
829     low_fullCLs=-1;
830     high_fullCLs=10e10;
831     }
832     ShapeDroplet droplet = LimitsFromShapes(low_fullCLs,high_fullCLs, (scansample.collection)[scanfileindex].events,addcut.str().c_str(),PointName.str(),mcjzb,datajzb,jzb_cut,peakerror,peakerror);
833 buchmann 1.13 if(!isValidShapeResult(droplet)) {
834 buchmann 1.14 write_error(__FUNCTION__,"Something went horribly wrong with the shape analysis - ignoring this point!!!");
835 buchmann 1.13 // scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, peakerrordata, (float)Npoints, (float)ipoint, systematicsonly, efficiencyonly,false); // don't uncomment this line; it would lead to multiple limitmap histos ...
836 buchmann 1.18 if(njobs==-2) return empty;
837 buchmann 1.13 continue;
838 buchmann 1.18
839 buchmann 1.13 }
840    
841 buchmann 1.12 float excludedXSobs = droplet.observed/droplet.SignalIntegral;
842     absXSmap->SetBinContent(GlobalBin,referenceXS);
843     write_info(__FUNCTION__,"Established limit at "+any2string(excludedXSobs)+" , ref XS is "+any2string(referenceXS));
844 buchmann 1.18 if(njobs==-2) {
845     //this is the non-scan case
846     vector<float> sigmas;
847     sigmas.push_back(droplet.observed/droplet.SignalIntegral);
848     sigmas.push_back(droplet.expected/droplet.SignalIntegral);
849     sigmas.push_back(droplet.expectedPlus1Sigma/droplet.SignalIntegral);
850     sigmas.push_back(droplet.expectedMinus1Sigma/droplet.SignalIntegral);
851     sigmas.push_back(droplet.expectedPlus2Sigma/droplet.SignalIntegral);
852     sigmas.push_back(droplet.expectedMinus2Sigma/droplet.SignalIntegral);
853     return sigmas;
854     }
855 buchmann 1.17
856 buchmann 1.12 rawlimitmap->SetBinContent(GlobalBin,droplet.observed);
857     rawelimitmap->SetBinContent(GlobalBin,droplet.expected);
858     limitmap->SetBinContent(GlobalBin,droplet.observed/droplet.SignalIntegral);
859     explimitmap->SetBinContent(GlobalBin,droplet.expected/droplet.SignalIntegral);
860     exp1plimitmap->SetBinContent(GlobalBin,droplet.expectedPlus1Sigma/droplet.SignalIntegral);
861     exp1mlimitmap->SetBinContent(GlobalBin,droplet.expectedMinus1Sigma/droplet.SignalIntegral);
862     exp2plimitmap->SetBinContent(GlobalBin,droplet.expectedPlus2Sigma/droplet.SignalIntegral);
863     exp2mlimitmap->SetBinContent(GlobalBin,droplet.expectedMinus2Sigma/droplet.SignalIntegral);
864 buchmann 1.16 dout <<"Saved the following shape limit: " << droplet.observed/droplet.SignalIntegral << " (observed) , " << droplet.expected/droplet.SignalIntegral << " (expected) " << endl;
865 buchmann 1.9 sysjesmap->SetBinContent(GlobalBin,droplet.JES);
866     sysjsumap->SetBinContent(GlobalBin,droplet.JSU);
867     syspdfmap->SetBinContent(GlobalBin,droplet.PDF);
868     systotmap->SetBinContent(GlobalBin,droplet.toterr);
869     sysstatmap->SetBinContent(GlobalBin,droplet.staterr);
870     }
871 buchmann 1.1 finish = clock();
872     timemap->SetBinContent(GlobalBin,((float(finish)-float(start))/CLOCKS_PER_SEC));
873     }
874     }
875     prepare_scan_axis(limitmap,scantype);
876     prepare_scan_axis(sysjesmap,scantype);
877     prepare_scan_axis(sysjsumap,scantype);
878     prepare_scan_axis(sysresmap,scantype);
879     prepare_scan_axis(syspdfmap,scantype);
880     prepare_scan_axis(systotmap,scantype);
881     prepare_scan_axis(sysstatmap,scantype);
882     prepare_scan_axis(timemap,scantype);
883    
884     if(!systematicsonly&&!efficiencyonly) {
885 buchmann 1.13 TObject* old=gDirectory->GetList()->FindObject("limcanvas");
886     if(old) gDirectory->GetList()->Remove(old);
887     TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
888 buchmann 1.1 limitmap->Draw("COLZ");
889     string titletobewritten="Limits in LSP-Glu plane";
890     if(scantype==mSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
891     if(scantype==GMSB) titletobewritten="Limits in Chi-Glu plane";
892     TText *title = write_title(titletobewritten);
893     title->Draw();
894     if(runninglocally) {
895     CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
896     } else {
897     TFile *outputfile;
898     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 :-)
899     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
900     limitmap->Write();
901 buchmann 1.12 rawlimitmap->Write();
902     rawelimitmap->Write();
903 buchmann 1.1 if(doexpected) {
904     explimitmap->Write();
905     exp1plimitmap->Write();
906     exp1mlimitmap->Write();
907     exp2plimitmap->Write();
908     exp2mlimitmap->Write();
909     }
910     sysjesmap->Write();
911     sysjsumap->Write();
912     sysresmap->Write();
913     efficiencymap->Write();
914 buchmann 1.3 if(ibin==0) centermap->Write();
915     if(ibin==0) widthmap->Write();
916 buchmann 1.1 flipmap->Write();
917     efficiencymapmet->Write();
918     efficiencymapAcc->Write();
919     efficiencymapID->Write();
920     efficiencymapJets->Write();
921     efficiencymapSignal->Write();
922     noscefficiencymap->Write();
923 buchmann 1.2 efficiencymapContam->Write();
924 buchmann 1.1 syspdfmap->Write();
925     systotmap->Write();
926     sysstatmap->Write();
927 buchmann 1.3 XSmap->Write();
928 buchmann 1.8 absXSmap->Write();
929     FilterEff->Write();
930 buchmann 1.13 if(shapeanalysis) asymptoticmap->Write();
931 buchmann 1.2 if(ibin==0) imposedxmap->Write();
932     if(ibin==0) realxmap->Write();
933 buchmann 1.1 Neventsmap->Write();
934 buchmann 1.16 ScanIdentifier->Write();
935 buchmann 1.1 ipointmap->Write();
936     timemap->Write();
937 buchmann 1.15 for(int i=0;i<(int)susy_Zdecay_origin.size();i++) {
938 buchmann 1.2 h_susy_Zdecay_origin[i]->Write();
939     }
940 buchmann 1.3 outputfile->Close();
941 buchmann 1.1 }
942     }
943     if(systematicsonly) { // systematics only :
944     limcanvas->cd();
945     sysjesmap->Draw("COLZ");
946     string titletobewritten="Jet Energy scale in LSP-Glu plane";
947     if(scantype==mSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
948     if(scantype==GMSB) titletobewritten="Limits in Chi-Glu plane";
949     TText *title = write_title(titletobewritten);
950     title->Draw();
951     if(runninglocally) {
952     CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
953     }
954     sysjsumap->Draw("COLZ");
955     titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
956     if(scantype==mSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
957     if(scantype==GMSB) titletobewritten="JZB Scale Uncertainty in Chi-Glu plane";
958     TText *title2 = write_title(titletobewritten);
959     title2->Draw();
960     if(runninglocally) {
961     CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
962     }
963     sysresmap->Draw("COLZ");
964     titletobewritten="Resolution in LSP-Glu plane";
965     if(scantype==mSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
966     if(scantype==GMSB) titletobewritten="Resolution in Chi-Glu plane";
967     TText *title3 = write_title(titletobewritten);
968     title3->Draw();
969     if(runninglocally) {
970     CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
971     }
972    
973     if(!runninglocally) {
974     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
975     sysjesmap->Write();
976     sysjsumap->Write();
977     sysresmap->Write();
978     flipmap->Write();
979 buchmann 1.3 if(ibin==0) centermap->Write();
980     if(ibin==0) widthmap->Write();
981 buchmann 1.1 efficiencymap->Write();
982     efficiencymapmet->Write();
983     efficiencymapAcc->Write();
984     efficiencymapID->Write();
985     efficiencymapJets->Write();
986     efficiencymapSignal->Write();
987     noscefficiencymap->Write();
988 buchmann 1.2 efficiencymapContam->Write();
989 buchmann 1.1 Neventsmap->Write();
990 buchmann 1.16 ScanIdentifier->Write();
991 buchmann 1.1 ipointmap->Write();
992     syspdfmap->Write();
993     systotmap->Write();
994     sysstatmap->Write();
995 buchmann 1.8 absXSmap->Write();
996 buchmann 1.9 XSmap->Write();
997 buchmann 1.8 FilterEff->Write();
998 buchmann 1.13 if(shapeanalysis) asymptoticmap->Write();
999 buchmann 1.2 if(ibin==0) imposedxmap->Write();
1000     if(ibin==0) realxmap->Write();
1001 buchmann 1.1 timemap->Write();
1002 buchmann 1.15 for(int i=0;i<(int)susy_Zdecay_origin.size();i++) {
1003 buchmann 1.2 h_susy_Zdecay_origin[i]->Write();
1004     }
1005 buchmann 1.3 outputfile->Close();
1006 buchmann 1.1 }
1007     }//end of systematics only
1008     if(efficiencyonly) {
1009     limcanvas->cd();
1010     string titletobewritten="Efficiencies in LSP-Glu plane";
1011     if(scantype==mSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
1012     if(scantype==GMSB) titletobewritten="Efficiencies in Chi-Glu plane";
1013     TText *title = write_title(titletobewritten);
1014     efficiencymap->Draw("COLZ");
1015     title->Draw();
1016     if(runninglocally) {
1017     CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
1018     }
1019     limcanvas->cd();
1020     efficiencymapmet->Draw("COLZ");
1021     title->Draw();
1022     if(runninglocally) {
1023     CompleteSave(limcanvas,"SUSYScan/EfficiencyMet_geq"+any2string(jzb_cut[ibin]));
1024     }
1025     limcanvas->cd();
1026     efficiencymapAcc->Draw("COLZ");
1027     title->Draw();
1028     if(runninglocally) {
1029     CompleteSave(limcanvas,"SUSYScan/EfficiencyAcc_geq"+any2string(jzb_cut[ibin]));
1030     }
1031     limcanvas->cd();
1032     efficiencymapID->Draw("COLZ");
1033     title->Draw();
1034     if(runninglocally) {
1035     CompleteSave(limcanvas,"SUSYScan/EfficiencyID_geq"+any2string(jzb_cut[ibin]));
1036     }
1037     limcanvas->cd();
1038     efficiencymapJets->Draw("COLZ");
1039     title->Draw();
1040     if(runninglocally) {
1041     CompleteSave(limcanvas,"SUSYScan/EfficiencyJets_geq"+any2string(jzb_cut[ibin]));
1042     }
1043     limcanvas->cd();
1044     efficiencymapSignal->Draw("COLZ");
1045     title->Draw();
1046     if(runninglocally) {
1047     CompleteSave(limcanvas,"SUSYScan/EfficiencySignal_geq"+any2string(jzb_cut[ibin]));
1048     }
1049     limcanvas->cd();
1050     noscefficiencymap->Draw("COLZ");
1051     title->Draw();
1052     if(runninglocally) {
1053     CompleteSave(limcanvas,"SUSYScan/NoEfficiency_geq"+any2string(jzb_cut[ibin]));
1054     }
1055     limcanvas->cd();
1056     sysjesmap->Draw("COLZ");
1057     titletobewritten="N(events) in LSP-Glu plane";
1058     if(scantype==mSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
1059     if(scantype==GMSB) titletobewritten="Resolution in Chi-Glu plane";
1060     TText *title2 = write_title(titletobewritten);
1061     title2->Draw();
1062     if(runninglocally) {
1063     CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
1064     }
1065     if(!runninglocally) {
1066     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
1067     ipointmap->Write();
1068     Neventsmap->Write();
1069 buchmann 1.16 ScanIdentifier->Write();
1070 buchmann 1.1 noscefficiencymap->Write();
1071 buchmann 1.2 efficiencymapContam->Write();
1072 buchmann 1.1 efficiencymap->Write();
1073 buchmann 1.3 if(ibin==0) centermap->Write();
1074     if(ibin==0) widthmap->Write();
1075 buchmann 1.1 flipmap->Write();
1076     efficiencymapmet->Write();
1077     efficiencymapAcc->Write();
1078     efficiencymapID->Write();
1079     efficiencymapJets->Write();
1080     efficiencymapSignal->Write();
1081     timemap->Write();
1082     outputfile->Close();
1083     }
1084     }//end of efficiencies only
1085 buchmann 1.13
1086 buchmann 1.15 for(int i=0;i<(int)susy_Zdecay_origin.size();i++) {
1087 buchmann 1.2 delete h_susy_Zdecay_origin[i];
1088     }
1089    
1090     delete PrimaryZSource;
1091     delete SecondaryZSource;
1092    
1093    
1094 buchmann 1.1 delete limitmap;
1095     delete exclmap;
1096     delete sysjesmap;
1097     delete sysjsumap;
1098     delete sysresmap;
1099     delete noscefficiencymap;
1100 buchmann 1.2 delete efficiencymapContam;
1101 buchmann 1.1 delete efficiencymap;
1102     delete efficiencymapmet;
1103     delete efficiencymapAcc;
1104     delete efficiencymapID;
1105     delete efficiencymapJets;
1106     delete efficiencymapSignal;
1107     delete Neventsmap;
1108 buchmann 1.16 delete ScanIdentifier;
1109 buchmann 1.1 delete ipointmap;
1110     delete syspdfmap;
1111     delete systotmap;
1112     delete sysstatmap;
1113 buchmann 1.3 delete XSmap;
1114 buchmann 1.8 delete absXSmap;
1115 buchmann 1.13 TObject* old=gDirectory->GetList()->FindObject("limcanvas");
1116     if(old) gDirectory->GetList()->Remove(old);
1117 buchmann 1.1 }
1118    
1119 buchmann 1.9 void scan_SUSY_parameter_space(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, float peakerrordata, float njobs=-1, float jobnumber=-1, bool systonly=false, bool effonly=false,bool shapeanalysis=false) {
1120 buchmann 1.1 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
1121 buchmann 1.15 for(int ibin=0;ibin<(int)jzb_cut.size();ibin++) {
1122 buchmann 1.13 scan_SUSY_parameter_space_for_one_cut(mcjzb,datajzb,jzb_cut,requireZ, peakerror, peakerrordata, ibin, njobs, jobnumber,systonly,effonly,shapeanalysis);
1123 buchmann 1.1 }
1124 buchmann 1.6 delete_any_cached_scans();// tidy up ...
1125 buchmann 1.1 }
1126    
1127 buchmann 1.18
1128    
1129     void compute_upper_limits_from_shapes(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, float peakerrordata) {
1130     dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
1131     vector<vector<float> > limits;
1132     vector<string> samplename;
1133     for(int isample=0;isample<signalsamples.collection.size();isample++) {
1134     limits.push_back(scan_SUSY_parameter_space_for_one_cut(mcjzb,datajzb,jzb_cut,requireZ, peakerror, peakerrordata, 0, -2, -2,false,false,true,signalsamples.collection[isample].filename));// the "-2" stands for "load from customized path"
1135     }
1136     for(int isample=0;isample<signalsamples.collection.size();isample++) {
1137     dout << signalsamples.collection[isample].samplename << " :" << endl;
1138     dout << " observed : " << limits[isample][0] << endl;
1139     dout << " expected : " << limits[isample][1] << endl;
1140     dout << " exp. band: [ " << limits[isample][5] << " , " << limits[isample][3] << " , \033[1;34m " << limits[isample][1] << "\033[0m , " << limits[isample][2] << " , " << limits[isample][4] << "] " << endl;
1141     }
1142     }