ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/SUSYScan.C
Revision: 1.8
Committed: Tue Mar 27 09:50:45 2012 UTC (13 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.7: +38 -23 lines
Log Message:
Updated cross section saving algorithm to take into account filter efficiency

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