ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.3
Committed: Thu Mar 15 20:34:15 2012 UTC (13 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.2: +60 -29 lines
Log Message:
Updated SUSYScan.C to allow quicker scans and also try out mSUGRA scans

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