ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.15
Committed: Mon Apr 30 08:38:11 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.14: +10 -14 lines
Log Message:
fixed some uint vs int comparisons; commented out/removed unused variables; made Wall happy

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