ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.14
Committed: Fri Apr 27 10:19:13 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.13: +10 -10 lines
Log Message:
Made error message for shapes clearer; replaced several cout's by dout's; made sure flipping is also done when falling back to CnC for limit setting

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