ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.66
Committed: Sun Nov 27 11:08:55 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.65: +10 -6 lines
Log Message:
Updated v4 data; switched to GMSB

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