ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.5
Committed: Sun Mar 18 17:53:29 2012 UTC (13 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.4: +31 -20 lines
Log Message:
Updated scan format for point-by-point files

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