ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.68
Committed: Thu Jan 19 08:45:48 2012 UTC (13 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, beforeFR20120418, cbaf_4p7ifb, HEAD
Changes since 1.67: +25 -5 lines
Log Message:
Added maps containing the imposed x value (read from directory name) and the measured x value (if available); adapted CRAB caching method (for retries)

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4     #include <fstream>
5 buchmann 1.7 #include <pthread.h>
6 buchmann 1.51 #include <assert.h>
7 buchmann 1.1
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 buchmann 1.31 #include <TKey.h>
21 buchmann 1.1
22     //#include "TTbar_stuff.C"
23     using namespace std;
24    
25     using namespace PlottingSetup;
26    
27     void susy_scan_axis_labeling(TH2F *histo) {
28 buchmann 1.37 histo->GetXaxis()->SetTitle("m_{#Chi_{2}^{0}}-m_{LSP}");
29 buchmann 1.1 histo->GetXaxis()->CenterTitle();
30     histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
31     histo->GetYaxis()->CenterTitle();
32     }
33    
34 buchmann 1.64 void prepare_scan_axis(TH2 *variablemap,int scantype) {
35     //assuming regular SMS
36 buchmann 1.9 variablemap->GetXaxis()->SetTitle("m_{glu}");
37     variablemap->GetYaxis()->SetTitle("m_{LSP}");
38 buchmann 1.35
39 buchmann 1.64 if(scantype==mSUGRA) {
40 buchmann 1.22 variablemap->GetXaxis()->SetTitle("m_{0}");
41     variablemap->GetYaxis()->SetTitle("m_{1/2}");
42     }
43 buchmann 1.64
44     if(scantype==GMSB) {
45     variablemap->GetXaxis()->SetTitle("m_{glu}");
46     variablemap->GetYaxis()->SetTitle("m_{NLSP}");
47     }
48 buchmann 1.35
49 buchmann 1.9 variablemap->GetXaxis()->CenterTitle();
50     variablemap->GetYaxis()->CenterTitle();
51     }
52    
53 buchmann 1.31 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 buchmann 1.35
62 buchmann 1.31 gStyle->SetPalette(100, MyPalette);
63 buchmann 1.35
64 buchmann 1.31 float rightmargin=gStyle->GetPadRightMargin();
65     gStyle->SetPadRightMargin(0.15);
66    
67     }
68    
69 buchmann 1.53 bool delete_any_cached_scans() {
70 buchmann 1.50 //This should only be called via CRAB
71 buchmann 1.67 cout << " Deleting all cached files." << endl;
72 buchmann 1.68 gSystem->Exec("ls -ltrh | grep root");
73 buchmann 1.57 char hostname[1023];
74     gethostname(hostname,1023);
75     if((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))) return false;
76 buchmann 1.53 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 buchmann 1.50 {
84     if(Contains(all_files[ifile],"_clean_splitup_")) {
85 buchmann 1.67 dout << " About to delete " << all_files[ifile] << endl;
86 buchmann 1.50 gSystem->Exec(((string)"rm "+all_files[ifile]).c_str());
87     }
88     }
89 buchmann 1.53 return true;
90     }
91 buchmann 1.50 }
92    
93     bool initialized_t2=false;
94    
95 buchmann 1.51 int srmcpretries=0;
96    
97 buchmann 1.68 void load_scan_sample(int a, int b, int &scanfileindex,int scantype,bool isretry=false) {
98 buchmann 1.55
99     // There is no need to define your sample here. That is done in Setup.C where you define the loading directory!
100    
101 buchmann 1.50 dout << "Going to load file with Xzone=" << a << " and Yzone=" << b << endl;
102 buchmann 1.48 stringstream filetoload;
103 buchmann 1.57 char hostname[1023];
104     gethostname(hostname,1023);
105 buchmann 1.50
106 buchmann 1.57 if((Contains(hostname,"t3ui")||Contains(hostname,"t3wn"))) { // local case
107 buchmann 1.55 filetoload << "/shome/buchmann/ntuples/"<<PlottingSetup::ScanSampleDirectory;
108 buchmann 1.64 if(scantype==mSUGRA) filetoload << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
109 buchmann 1.66 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.50 if(!Contains(((scansample.collection)[(scansample.collection).size()-1]).filename,"_"+any2string(a)+"_"+any2string(b))) {
112     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 buchmann 1.48 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 buchmann 1.50 } else {
120     dout << "Last sample is the same as the current one. Recycling it." << endl;
121     scanfileindex=(scansample.collection).size()-1;
122     }
123 buchmann 1.58 dout << " Going to use the following file: " << filetoload.str() << endl;
124 buchmann 1.50 } // end of t3 case
125     else {
126     write_info(__FUNCTION__,"Hello, CRAB! Might need to load files ...");
127 buchmann 1.59 PlottingSetup::limitpatience=PlottingSetup::limitpatienceCRAB;
128 buchmann 1.50 stringstream copyfile;
129 buchmann 1.57 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 buchmann 1.64 if(scantype==mSUGRA) copyfile << "/mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root " << "mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root ";
131 buchmann 1.68 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 buchmann 1.50 stringstream newfilename;
134 buchmann 1.64 if(scantype==mSUGRA) newfilename << "mSUGRA_clean_splitup_" << any2string(a) << "_" << any2string(b) << ".root";
135 buchmann 1.66 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 buchmann 1.50
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 buchmann 1.68 if(scanfileindex!=0||isretry) {
146 buchmann 1.50 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 buchmann 1.51 if(doesROOTFileExist(newfilename.str())) {
150 buchmann 1.67 initialized_t2=true;
151 buchmann 1.51 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 buchmann 1.52 sleep(5);
157 buchmann 1.68 load_scan_sample(a,b,scanfileindex,scantype,true);
158 buchmann 1.51 } 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 buchmann 1.50 }
165     } else {
166     dout << "Last sample is the same as the current one. Recycling it." << endl;
167 buchmann 1.48 scanfileindex=(scansample.collection).size()-1;
168 buchmann 1.50 }
169    
170 buchmann 1.48 }
171 buchmann 1.50 }
172 buchmann 1.48
173 buchmann 1.50 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) {
174     altxs=0;
175 buchmann 1.46 for(int iproc=1;iproc<=10;iproc++) {
176 buchmann 1.35 float process_xs = GetXSecForPointAndChannel(mglu,mlsp,xsec,iproc);
177 buchmann 1.49 altxs+=process_xs;
178 buchmann 1.46 }
179 buchmann 1.50 return altxs;
180 buchmann 1.35 }
181    
182 buchmann 1.31 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) {
183     bool runninglocally=true;
184     if(njobs>-1&&jobnumber>-1) {
185     runninglocally=false;
186     dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
187     } else {
188     dout << "Running locally " << endl;
189 buchmann 1.37 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;
190 buchmann 1.31 }
191 buchmann 1.35
192 buchmann 1.31 string massgluname="MassGlu";
193     string massLSPname="MassLSP";
194 buchmann 1.39 jzbSel=jzb_cut[ibin];
195     geqleq="geq";
196     automatized=true;
197     mcjzbexpression=mcjzb;
198    
199 buchmann 1.31 string prefix="SMS_";
200     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
201 buchmann 1.64 int scantype=SMS;
202 buchmann 1.31 TIter nextkey(fsyst->GetListOfKeys());
203     TKey *key;
204     while ((key = (TKey*)nextkey()))
205     {
206     TObject *obj = key->ReadObj();
207 buchmann 1.64 if(Contains((string)(obj->GetName()),"mSUGRA")) scantype=mSUGRA;
208     if(Contains((string)(obj->GetName()),"GMSB")) scantype=GMSB;
209 buchmann 1.31 }
210 buchmann 1.35
211     map < pair<float, float>, map<string, float> > xsec;
212 buchmann 1.31
213 buchmann 1.64 if(scantype==mSUGRA) {
214 buchmann 1.31 massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
215     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
216     mglustart=m0start;
217 buchmann 1.48 xsec=getXsec(PlottingSetup::cbafbasedir+"/Plotting/Modules/external/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
218 buchmann 1.31 mgluend=m0end;
219     mglustep=m0step;
220     mLSPstart=m12start;
221     mLSPend=m12end;
222     mLSPstep=m12step;
223     prefix="mSUGRA_";
224 buchmann 1.50 dout << "mSUGRA scan has been set up." << endl;
225 buchmann 1.64 // xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
226     }
227     if(scantype==SMS) {
228 buchmann 1.50 dout << "SMS scan has been set up." << endl;
229 buchmann 1.35 write_warning(__FUNCTION__,"Don't have the correct XS file yet");
230 buchmann 1.64 }
231     if(scantype==GMSB) {
232     string massgluname="MassGMSBGlu";
233     string massLSPname="MassGMSBChi";
234 buchmann 1.65 prefix="GMSB_";
235 buchmann 1.64 dout << "GMSB scan has been set up." << endl;
236     write_warning(__FUNCTION__,"Don't have the correct XS file yet");
237 buchmann 1.31 }
238 buchmann 1.35
239 buchmann 1.31 set_SUSY_style();
240 buchmann 1.35
241 buchmann 1.31 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
242 buchmann 1.35
243 buchmann 1.31 int Npoints=0;
244 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
245 buchmann 1.64 for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
246 buchmann 1.31 }
247 buchmann 1.37 TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
248     //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());
249 buchmann 1.31 TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
250 buchmann 1.33 TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
251 buchmann 1.52 TH2F *lflip = (TH2F*)fsyst->Get((prefix+"flipmap"+any2string(jzb_cut[ibin])).c_str());
252 buchmann 1.35
253 buchmann 1.56 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
254     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
255     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
256     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
257     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
258     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
259 buchmann 1.37
260 buchmann 1.56 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);
261     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);
262     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);
263     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);
264 buchmann 1.52
265    
266 buchmann 1.35
267 buchmann 1.32 if(!fullerr || !mceff || !NEvents) {
268 buchmann 1.31 write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
269 buchmann 1.34 dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
270 buchmann 1.31 delete limcanvas;
271     return;
272     }
273 buchmann 1.37
274     bool doexpected=true;
275 buchmann 1.35
276 buchmann 1.31 int ipoint=-1;
277 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
278 buchmann 1.64 for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
279 buchmann 1.31 {
280     ipoint++;
281 buchmann 1.56 if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
282 buchmann 1.62 int GlobalBin=flipmap->FindBin(mglu,mlsp);
283 buchmann 1.31 float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
284 buchmann 1.33 float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
285 buchmann 1.32 float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
286 buchmann 1.56 int flipped = (int)(lflip->GetBinContent(lflip->FindBin(mglu,mlsp)));
287 buchmann 1.62 flipmap->SetBinContent(GlobalBin,flipped);
288 buchmann 1.34 dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
289 buchmann 1.35 dout << "Found : MCeff=" << currmceff << " and total error=" << currtoterr << " and Nevents=" << nevents << endl;
290 buchmann 1.31 string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
291 buchmann 1.34 if(currmceff<=0||currtoterr<=0||nevents==0) {
292     dout << " Nothing to work with, skipping this point." << endl;
293     continue;
294     }
295 buchmann 1.31 vector<float> sigmas;
296 buchmann 1.52 sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true, flipped);
297 buchmann 1.48
298    
299 buchmann 1.62 if(sigmas[0]>0) limitmap->SetBinContent(GlobalBin,sigmas[0]); //anything else is an error code
300 buchmann 1.37 if(sigmas.size()>1) {
301 buchmann 1.62 explimitmap->SetBinContent(GlobalBin,sigmas[1]);
302     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
303     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
304     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
305     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
306 buchmann 1.37 }
307    
308 buchmann 1.35 dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " ) at " << sigmas[0] << endl;
309 buchmann 1.64 if(scantype==mSUGRA) { // for SMS this is a bit easier at the moment - we have a reference XS file which we use when plotting
310 buchmann 1.35 dout << "Computing exclusion status" << endl;
311     float rel_limit=0;
312 buchmann 1.49 float totxs;
313     float xs=get_xs(totxs,mglu,mlsp,massgluname,massLSPname,xsec,mcjzb,requireZ);
314 buchmann 1.35 if(xs>0) rel_limit=sigmas[0]/xs;
315 buchmann 1.62 exclmap->SetBinContent(GlobalBin,rel_limit);
316     xsmap->SetBinContent(GlobalBin,xs);
317     totxsmap->SetBinContent(GlobalBin,totxs);
318 buchmann 1.32 }
319 buchmann 1.31 }
320     }
321 buchmann 1.35
322 buchmann 1.64 prepare_scan_axis(limitmap,scantype);
323 buchmann 1.32 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 :-)
324     outputfile->cd();
325 buchmann 1.31 limitmap->Write();
326 buchmann 1.52 flipmap->Write();
327 buchmann 1.37 if(doexpected) {
328     explimitmap->Write();
329     exp1plimitmap->Write();
330     exp1mlimitmap->Write();
331     exp2plimitmap->Write();
332     exp2mlimitmap->Write();
333     }
334 buchmann 1.64 if(scantype==mSUGRA) {
335 buchmann 1.32 exclmap->Write();
336     xsmap->Write();
337 buchmann 1.49 totxsmap->Write();
338 buchmann 1.32 }
339     outputfile->Close();
340 buchmann 1.31 delete limcanvas;
341     }
342    
343     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
344     dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
345     TFile *fsyst = new TFile(fsystfilename.c_str());
346     if(!fsyst) {
347     write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
348     return;
349     }
350     for(int ibin=0;ibin<jzb_cut.size();ibin++) {
351     establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
352     }
353     }
354    
355    
356    
357    
358 buchmann 1.13 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) {
359 buchmann 1.6 bool runninglocally=true;
360     if(njobs>-1&&jobnumber>-1) {
361     runninglocally=false;
362 buchmann 1.13 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
363 buchmann 1.6 } else {
364 buchmann 1.7 dout << "Running locally " << endl;
365 buchmann 1.40 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;
366 buchmann 1.6 }
367 buchmann 1.35
368 buchmann 1.4 jzbSel=jzb_cut[ibin];
369     geqleq="geq";
370     automatized=true;
371     mcjzbexpression=mcjzb;
372 buchmann 1.35
373 buchmann 1.4 string massgluname="MassGlu";
374     string massLSPname="MassLSP";
375 buchmann 1.35
376 buchmann 1.23 string prefix="SMS_";
377 buchmann 1.22 // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
378 buchmann 1.64 int scantype=SMS;
379     if(Contains((scansample.collection)[0].samplename,"mSUGRA")) scantype=mSUGRA;
380     if(Contains((scansample.collection)[0].samplename,"GMSB")) scantype=GMSB;
381 buchmann 1.66
382     if(scantype==mSUGRA) {
383 buchmann 1.22 massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
384     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
385     mglustart=m0start;
386     mgluend=m0end;
387     mglustep=m0step;
388     mLSPstart=m12start;
389     mLSPend=m12end;
390     mLSPstep=m12step;
391 buchmann 1.23 prefix="mSUGRA_";
392 buchmann 1.50 dout << "mSUGRA scan has been set up." << endl;
393 buchmann 1.64 }
394 buchmann 1.66 if(scantype==SMS) {
395 buchmann 1.64 dout << "SMS scan has been set up." << endl;
396     }
397 buchmann 1.66 if(scantype==GMSB) {
398 buchmann 1.65 dout << "GMSB scan has been set up." << endl;
399     prefix="GMSB_";
400 buchmann 1.64 massgluname="MassGMSBGlu"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
401     massLSPname="MassGMSBChi"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
402     }
403 buchmann 1.35
404 buchmann 1.4 Int_t MyPalette[100];
405     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
406     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
407     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
408     Double_t stop[] = {0., .25, .50, .75, 1.0};
409     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
410     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
411 buchmann 1.35
412 buchmann 1.4 gStyle->SetPalette(100, MyPalette);
413 buchmann 1.35
414 buchmann 1.56 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
415     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
416     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
417     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
418     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
419     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
420 buchmann 1.37
421 buchmann 1.56 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);
422     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);
423     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);
424     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);
425     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);
426 pablom 1.63 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);
427 buchmann 1.56 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);
428     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);
429     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);
430     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);
431     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);
432     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);
433     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);
434     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);
435     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);
436     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);
437 buchmann 1.27
438 buchmann 1.68 TH2F *imposedxmap = new TH2F((prefix+"imposedxmap"+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 *realxmap = new TH2F((prefix+"realxmap"+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    
441 buchmann 1.56 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);
442 buchmann 1.36
443 buchmann 1.56 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);
444 buchmann 1.52
445 buchmann 1.29 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
446 buchmann 1.35
447 buchmann 1.4 float rightmargin=gStyle->GetPadRightMargin();
448     gStyle->SetPadRightMargin(0.15);
449 buchmann 1.35
450 buchmann 1.4 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
451 buchmann 1.35
452 buchmann 1.37
453     bool doexpected=true;
454    
455 buchmann 1.6 int Npoints=0;
456 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
457 buchmann 1.64 for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep) Npoints++;
458 buchmann 1.6 }
459 buchmann 1.35
460 buchmann 1.6 int ipoint=-1;
461 buchmann 1.56 for(int mglu=(int)mglustart;mglu<=mgluend;mglu+=(int)mglustep) {
462 buchmann 1.64 for (int mlsp=(int)mLSPstart;mlsp<=mLSPend&&(scantype==mSUGRA||mlsp<=mglu);mlsp+=(int)mLSPstep)
463 buchmann 1.4 {
464 buchmann 1.6 ipoint++;
465 buchmann 1.62 int GlobalBin=efficiencymap->FindBin(mglu,mlsp);
466 buchmann 1.56 if(!runninglocally&&!do_this_point(ipoint,(int)Npoints,(int)jobnumber,(int)njobs)) continue;
467 buchmann 1.52 int flipped=0;
468 buchmann 1.19 float result=-987,resulterr=-987;
469 buchmann 1.50 float m0trees = PlottingSetup::mgluend;
470     float m12trees = PlottingSetup::mLSPend;
471 buchmann 1.42 int a = int((PlottingSetup::ScanXzones*mlsp)/(m12trees+1));
472     int b = int((PlottingSetup::ScanYzones*mglu)/(m0trees+1));
473 buchmann 1.50 int scanfileindex=PlottingSetup::ScanYzones*a+b;
474 buchmann 1.64 load_scan_sample(a,b,scanfileindex,scantype);
475 buchmann 1.42
476 buchmann 1.36 clock_t start,finish;
477     start = clock(); // starting the clock to measure how long the computation takes!
478 buchmann 1.4 stringstream addcut;
479     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
480 buchmann 1.40 (scansample.collection)[scanfileindex].events->Draw("eventNum",addcut.str().c_str(),"goff");
481     float nevents = (scansample.collection)[scanfileindex].events->GetSelectedRows();
482 buchmann 1.4 vector<vector<float> > systematics;
483 buchmann 1.30 if(nevents<10) {
484 buchmann 1.40 dout << "This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be skipped."<< endl;
485     continue;
486 buchmann 1.6 } else {
487 buchmann 1.48 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore not be skipped. " << endl;
488     write_analysis_type(PlottingSetup::RestrictToMassPeak);
489 buchmann 1.22 }
490 buchmann 1.68 TH1F *realxhisto = new TH1F("realxhisto","realxhisto",1000,0,1);
491     (scansample.collection)[scanfileindex].events->Draw("xSMS>>realxhisto",addcut.str().c_str(),"goff");
492     realxmap->SetBinContent(GlobalBin,realxhisto->GetMean());
493     realxmap->SetBinError(GlobalBin,realxhisto->GetRMS());
494     float impx=0.0;
495     if(Contains(((scansample.collection)[0].filename),"T5zz")) impx=0.5;
496     if(Contains(((scansample.collection)[0].filename),"T5zzl")) impx=0.75;
497     if(Contains(((scansample.collection)[0].filename),"T5zzh")) impx=0.25;
498     imposedxmap->SetBinContent(GlobalBin,impx);
499     delete realxhisto;
500    
501    
502 buchmann 1.50 if(nevents!=0&&(efficiencyonly||systematicsonly)) {
503 buchmann 1.56 Value effwosigcont = MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1);
504 buchmann 1.52 if(result<0) {
505     write_info(__FUNCTION__,"Found negative efficiency (signal distribution populating JZB<0 more than JZB>0) - flipping analysis!");
506     flipped=1;
507 buchmann 1.56 MCefficiency((scansample.collection)[scanfileindex].events,result,resulterr,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1);
508 buchmann 1.52 }
509 buchmann 1.62 efficiencymap->SetBinContent(GlobalBin,result);
510     efficiencymap->SetBinError(GlobalBin,resulterr);
511     flipmap->SetBinContent(GlobalBin,flipped);
512     noscefficiencymap->SetBinContent(GlobalBin,effwosigcont.getValue());
513     noscefficiencymap->SetBinError(GlobalBin,effwosigcont.getError());
514 buchmann 1.47 //Partial efficiencies
515 pablom 1.63 float resultAcc, resultID, resultJets, resultSignal, resultmet;
516     float resulterrAcc, resulterrID, resulterrJets, resulterrSignal, resulterrmet;
517 buchmann 1.56 MCPartialefficiency((scansample.collection)[scanfileindex].events,resultAcc,resulterrAcc,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 1);
518     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultID,resulterrID,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 2);
519     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultJets,resulterrJets,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 3);
520     MCPartialefficiency((scansample.collection)[scanfileindex].events,resultSignal,resulterrSignal,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 4);
521 pablom 1.63 MCPartialefficiency((scansample.collection)[scanfileindex].events,resultmet,resulterrmet,flipped,mcjzb,requireZ,(int)nevents,addcut.str(),-1, 5);
522 buchmann 1.62 efficiencymapAcc->SetBinContent(GlobalBin,resultAcc);
523     efficiencymapAcc->SetBinError(GlobalBin,resulterrAcc);
524 pablom 1.63 efficiencymapmet->SetBinContent(GlobalBin,resultmet);
525     efficiencymapmet->SetBinError(GlobalBin,resulterrmet);
526 buchmann 1.62 efficiencymapID->SetBinContent(GlobalBin,resultID);
527 pablom 1.63 efficiencymapID->SetBinError(GlobalBin,resulterrID);
528 buchmann 1.62 efficiencymapJets->SetBinContent(GlobalBin,resultJets);
529 pablom 1.63 efficiencymapJets->SetBinError(GlobalBin,resulterrJets);
530 buchmann 1.62 efficiencymapSignal->SetBinContent(GlobalBin,resultSignal);
531 pablom 1.63 efficiencymapSignal->SetBinError(GlobalBin,resulterrSignal);
532 buchmann 1.36 finish = clock();
533 buchmann 1.13 }
534 buchmann 1.62 Neventsmap->SetBinContent(GlobalBin,nevents);
535     ipointmap->SetBinContent(GlobalBin,ipoint);
536 buchmann 1.17 if(efficiencyonly) continue;
537    
538 buchmann 1.56 do_systematics_for_one_file((scansample.collection)[scanfileindex].events,(int)nevents,"SUSY SCAN", systematics,flipped, mcjzb,datajzb,peakerror,requireZ, addcut.str(),true);//mSUGRA is now always true here because we always want to compute PDF systematics
539 buchmann 1.9 float JZBcutat = systematics[0][0];
540     float mceff = systematics[0][1];
541 buchmann 1.22 float mcefferr = systematics[0][2];//MC stat error
542 buchmann 1.9 float toterr = systematics[0][4];
543     float sys_jes = systematics[0][5]; // Jet Energy Scale
544     float sys_jsu = systematics[0][6]; // JZB scale uncertainty
545     float sys_res = systematics[0][7]; // resolution
546 buchmann 1.37 float mcwoscef = systematics[0][8]; // efficiency without signal contamination
547     float mcwoscefr= systematics[0][9]; // error on efficiency without signal contamination
548 buchmann 1.27 float sys_pdf = 0;
549 buchmann 1.37 if(systematics[0].size()>10) sys_pdf = systematics[0][10]; // PDF
550 buchmann 1.35
551 buchmann 1.47 if(mceff!=mceff||toterr!=toterr||mceff<0 && (!systematicsonly&&!efficiencyonly)) {
552 buchmann 1.35 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;
553     continue;
554 buchmann 1.5 } else {
555 buchmann 1.35 if(!systematicsonly&&!efficiencyonly) {
556     dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
557     vector<float> sigmas;
558 buchmann 1.40 string plotfilename=(string)(TString((scansample.collection)[scanfileindex].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
559 buchmann 1.52 sigmas=compute_one_upper_limit(mceff,toterr,ibin,mcjzb,plotfilename,true,flipped);
560 buchmann 1.46 // do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
561 buchmann 1.50 dout << "back in " << __FUNCTION__ << endl;
562 buchmann 1.35 if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
563 buchmann 1.62 limitmap->SetBinContent(GlobalBin,sigmas[0]);
564 buchmann 1.37 if(sigmas.size()>1) {
565 buchmann 1.62 explimitmap->SetBinContent(GlobalBin,sigmas[1]);
566     exp1plimitmap->SetBinContent(GlobalBin,sigmas[2]);
567     exp1mlimitmap->SetBinContent(GlobalBin,sigmas[3]);
568     exp2plimitmap->SetBinContent(GlobalBin,sigmas[4]);
569     exp2mlimitmap->SetBinContent(GlobalBin,sigmas[5]);
570 buchmann 1.38 }
571 buchmann 1.37
572 buchmann 1.62 sysjesmap->SetBinContent(GlobalBin,sys_jes);
573     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
574     sysresmap->SetBinContent(GlobalBin,sys_res);
575     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
576     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
577     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
578 buchmann 1.35 dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
579     } //end of if sigma is positive
580 buchmann 1.36
581 buchmann 1.35 //end of not systematics only condition
582     }
583     if(systematicsonly) {
584 buchmann 1.62 sysjesmap->SetBinContent(GlobalBin,sys_jes);
585     sysjsumap->SetBinContent(GlobalBin,sys_jsu);
586     sysresmap->SetBinContent(GlobalBin,sys_res);
587     syspdfmap->SetBinContent(GlobalBin,sys_pdf);
588     systotmap->SetBinContent(GlobalBin,toterr/mceff);//total relative (!) error
589     sysstatmap->SetBinContent(GlobalBin,mcefferr);//total relative (!) error
590 buchmann 1.35 }
591 buchmann 1.15 }//efficiency is valid
592 buchmann 1.52 finish = clock();
593 buchmann 1.62 timemap->SetBinContent(GlobalBin,((float(finish)-float(start))/CLOCKS_PER_SEC));
594 buchmann 1.4 }
595     }
596 buchmann 1.52
597 buchmann 1.64 prepare_scan_axis(limitmap,scantype);
598     prepare_scan_axis(sysjesmap,scantype);
599     prepare_scan_axis(sysjsumap,scantype);
600     prepare_scan_axis(sysresmap,scantype);
601     prepare_scan_axis(syspdfmap,scantype);
602     prepare_scan_axis(systotmap,scantype);
603     prepare_scan_axis(sysstatmap,scantype);
604     prepare_scan_axis(timemap,scantype);
605 buchmann 1.35
606 buchmann 1.13 if(!systematicsonly&&!efficiencyonly) {
607 buchmann 1.9 limcanvas->cd();
608     limitmap->Draw("COLZ");
609 buchmann 1.22 string titletobewritten="Limits in LSP-Glu plane";
610 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
611     if(scantype==GMSB) titletobewritten="Limits in Chi-Glu plane";
612 buchmann 1.22 TText *title = write_title(titletobewritten);
613 buchmann 1.9 title->Draw();
614     if(runninglocally) {
615     CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
616     } else {
617 buchmann 1.12 TFile *outputfile;
618     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 :-)
619 buchmann 1.35 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
620 buchmann 1.9 limitmap->Write();
621 buchmann 1.37 if(doexpected) {
622     explimitmap->Write();
623     exp1plimitmap->Write();
624     exp1mlimitmap->Write();
625     exp2plimitmap->Write();
626     exp2mlimitmap->Write();
627     }
628 buchmann 1.18 sysjesmap->Write();
629     sysjsumap->Write();
630 buchmann 1.28 sysresmap->Write();
631 buchmann 1.18 efficiencymap->Write();
632 buchmann 1.52 flipmap->Write();
633 pablom 1.63 efficiencymapmet->Write();
634 buchmann 1.47 efficiencymapAcc->Write();
635     efficiencymapID->Write();
636     efficiencymapJets->Write();
637     efficiencymapSignal->Write();
638 buchmann 1.37 noscefficiencymap->Write();
639 buchmann 1.27 syspdfmap->Write();
640     systotmap->Write();
641     sysstatmap->Write();
642 buchmann 1.68 imposedxmap->Write();
643     realxmap->Write();
644 buchmann 1.18 Neventsmap->Write();
645 buchmann 1.24 ipointmap->Write();
646 buchmann 1.36 timemap->Write();
647 buchmann 1.9 outputfile->Close();
648     }
649 buchmann 1.35 }
650 buchmann 1.13 if(systematicsonly) { // systematics only :
651 buchmann 1.9 limcanvas->cd();
652     sysjesmap->Draw("COLZ");
653 buchmann 1.22 string titletobewritten="Jet Energy scale in LSP-Glu plane";
654 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
655     if(scantype==GMSB) titletobewritten="Limits in Chi-Glu plane";
656 buchmann 1.22 TText *title = write_title(titletobewritten);
657 buchmann 1.9 title->Draw();
658     if(runninglocally) {
659     CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
660     }
661     sysjsumap->Draw("COLZ");
662 buchmann 1.22 titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
663 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
664     if(scantype==GMSB) titletobewritten="JZB Scale Uncertainty in Chi-Glu plane";
665 buchmann 1.22 TText *title2 = write_title(titletobewritten);
666 buchmann 1.9 title2->Draw();
667     if(runninglocally) {
668     CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
669     }
670     sysresmap->Draw("COLZ");
671 buchmann 1.22 titletobewritten="Resolution in LSP-Glu plane";
672 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
673     if(scantype==GMSB) titletobewritten="Resolution in Chi-Glu plane";
674 buchmann 1.22 TText *title3 = write_title(titletobewritten);
675 buchmann 1.9 title3->Draw();
676     if(runninglocally) {
677     CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
678     }
679 buchmann 1.35
680 buchmann 1.9 if(!runninglocally) {
681     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
682     sysjesmap->Write();
683     sysjsumap->Write();
684     sysresmap->Write();
685 buchmann 1.52 flipmap->Write();
686 buchmann 1.18 efficiencymap->Write();
687 pablom 1.63 efficiencymapmet->Write();
688 buchmann 1.47 efficiencymapAcc->Write();
689     efficiencymapID->Write();
690     efficiencymapJets->Write();
691     efficiencymapSignal->Write();
692 buchmann 1.37 noscefficiencymap->Write();
693 buchmann 1.18 Neventsmap->Write();
694 buchmann 1.24 ipointmap->Write();
695 buchmann 1.27 syspdfmap->Write();
696     systotmap->Write();
697     sysstatmap->Write();
698 buchmann 1.68 imposedxmap->Write();
699     realxmap->Write();
700 buchmann 1.36 timemap->Write();
701 buchmann 1.9 outputfile->Close();
702     }
703     }//end of systematics only
704 buchmann 1.13 if(efficiencyonly) {
705     limcanvas->cd();
706 buchmann 1.22 string titletobewritten="Efficiencies in LSP-Glu plane";
707 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
708     if(scantype==GMSB) titletobewritten="Efficiencies in Chi-Glu plane";
709 buchmann 1.22 TText *title = write_title(titletobewritten);
710 buchmann 1.47 efficiencymap->Draw("COLZ");
711 buchmann 1.13 title->Draw();
712     if(runninglocally) {
713     CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
714     }
715     limcanvas->cd();
716 pablom 1.63 efficiencymapmet->Draw("COLZ");
717     title->Draw();
718     if(runninglocally) {
719     CompleteSave(limcanvas,"SUSYScan/EfficiencyMet_geq"+any2string(jzb_cut[ibin]));
720     }
721     limcanvas->cd();
722 buchmann 1.47 efficiencymapAcc->Draw("COLZ");
723     title->Draw();
724     if(runninglocally) {
725     CompleteSave(limcanvas,"SUSYScan/EfficiencyAcc_geq"+any2string(jzb_cut[ibin]));
726     }
727     limcanvas->cd();
728     efficiencymapID->Draw("COLZ");
729     title->Draw();
730     if(runninglocally) {
731     CompleteSave(limcanvas,"SUSYScan/EfficiencyID_geq"+any2string(jzb_cut[ibin]));
732     }
733     limcanvas->cd();
734     efficiencymapJets->Draw("COLZ");
735     title->Draw();
736     if(runninglocally) {
737     CompleteSave(limcanvas,"SUSYScan/EfficiencyJets_geq"+any2string(jzb_cut[ibin]));
738     }
739     limcanvas->cd();
740     efficiencymapSignal->Draw("COLZ");
741     title->Draw();
742     if(runninglocally) {
743     CompleteSave(limcanvas,"SUSYScan/EfficiencySignal_geq"+any2string(jzb_cut[ibin]));
744     }
745     limcanvas->cd();
746     noscefficiencymap->Draw("COLZ");
747     title->Draw();
748     if(runninglocally) {
749     CompleteSave(limcanvas,"SUSYScan/NoEfficiency_geq"+any2string(jzb_cut[ibin]));
750     }
751     limcanvas->cd();
752 buchmann 1.13 sysjesmap->Draw("COLZ");
753 buchmann 1.22 titletobewritten="N(events) in LSP-Glu plane";
754 buchmann 1.64 if(scantype==mSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
755     if(scantype==GMSB) titletobewritten="Resolution in Chi-Glu plane";
756 buchmann 1.22 TText *title2 = write_title(titletobewritten);
757 buchmann 1.13 title2->Draw();
758     if(runninglocally) {
759     CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
760     }
761     if(!runninglocally) {
762     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
763 buchmann 1.24 ipointmap->Write();
764 buchmann 1.13 Neventsmap->Write();
765 buchmann 1.37 noscefficiencymap->Write();
766 buchmann 1.13 efficiencymap->Write();
767 buchmann 1.52 flipmap->Write();
768 pablom 1.63 efficiencymapmet->Write();
769 buchmann 1.47 efficiencymapAcc->Write();
770     efficiencymapID->Write();
771     efficiencymapJets->Write();
772     efficiencymapSignal->Write();
773 buchmann 1.36 timemap->Write();
774 buchmann 1.13 outputfile->Close();
775     }
776     }//end of efficiencies only
777 buchmann 1.35
778 buchmann 1.31 delete limitmap;
779     delete exclmap;
780     delete sysjesmap;
781     delete sysjsumap;
782     delete sysresmap;
783 buchmann 1.37 delete noscefficiencymap;
784 buchmann 1.31 delete efficiencymap;
785 pablom 1.63 delete efficiencymapmet;
786 buchmann 1.47 delete efficiencymapAcc;
787     delete efficiencymapID;
788     delete efficiencymapJets;
789     delete efficiencymapSignal;
790 buchmann 1.31 delete Neventsmap;
791     delete ipointmap;
792     delete syspdfmap;
793     delete systotmap;
794     delete sysstatmap;
795 buchmann 1.13 delete limcanvas;
796 buchmann 1.1 }
797 buchmann 1.4
798 buchmann 1.13 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) {
799 buchmann 1.10 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
800 buchmann 1.4 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
801 buchmann 1.13 scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, ibin, njobs, jobnumber,systonly,effonly);
802 buchmann 1.4 }
803 buchmann 1.6 }
804 buchmann 1.35