ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.37
Committed: Mon Sep 26 15:43:37 2011 UTC (13 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.36: +86 -23 lines
Log Message:
Several improvements: 1) Added expected limits (as requested); 2) Added efficiency without signal contamination as an additional th2; 3) Changed label of histos; 4) changed the order of the systematics (to establish compatibility with older files without PDF); 5) Added a 'timemap' so we can see which points take up the most time; 6) Switched expected limits on; 7) Switched XS weighting off completely for the moment (it's for mSUGRA scans later on)

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <sys/stat.h>
4 #include <fstream>
5 #include <pthread.h>
6
7 #include <TCut.h>
8 #include <TROOT.h>
9 #include <TCanvas.h>
10 #include <TMath.h>
11 #include <TColor.h>
12 #include <TPaveText.h>
13 #include <TRandom.h>
14 #include <TH1.h>
15 #include <TH2.h>
16 #include <TF1.h>
17 #include <TSQLResult.h>
18 #include <TProfile.h>
19 #include <TKey.h>
20
21 //#include "TTbar_stuff.C"
22 using namespace std;
23
24 using namespace PlottingSetup;
25
26 void susy_scan_axis_labeling(TH2F *histo) {
27 histo->GetXaxis()->SetTitle("m_{#Chi_{2}^{0}}-m_{LSP}");
28 histo->GetXaxis()->CenterTitle();
29 histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
30 histo->GetYaxis()->CenterTitle();
31 }
32
33 bool isThreadActive=false;
34
35 struct limit_args {
36 float mceff;
37 float toterr;
38 int ibin;
39 string mcjzb;
40 vector<float> sigmas;
41 string plotfilename;
42 };
43
44 void* compute_one_upper_limit_wrapper(void* data) {
45 isThreadActive=true;
46 limit_args* args = (limit_args*) data;
47 std::cout << "Thread to compute limits has been started" << std::endl;
48 args->sigmas=compute_one_upper_limit(args->mceff,args->toterr,args->ibin,args->mcjzb,args->plotfilename,true);
49 std::cout << "Thread to compute limits has finished" << std::endl;
50 isThreadActive=false;
51 return NULL;
52 }
53
54 void do_limit_wrapper(float mceff,float toterr,int ibin,string mcjzb,vector<float> &sigmas,string plotfilename) {
55 pthread_t limitthread;
56 limit_args limargs={mceff,toterr,ibin,mcjzb,sigmas,plotfilename};
57 pthread_create( &limitthread, NULL, compute_one_upper_limit_wrapper, (void*) &limargs);
58 int counter=0;
59 int counterinterval=5;
60 sleep(1); //waiting a second for the process to become active
61 while(counter<limitpatience*60 && isThreadActive) {
62 std::cout << "Limits are being calculated; Checking round " << counter << " ( corresponds to " << seconds_to_time(counter) << " ) , patience will end in " << seconds_to_time(60*limitpatience-counter) << std::endl;
63 counter+=counterinterval;
64 sleep(counterinterval);
65 }
66
67 if(!isThreadActive) {
68 cout << "Thread finished sucessfully" << endl;
69 pthread_join( limitthread, NULL );
70 std::cout<< __FUNCTION__ << " : going to save sigmas " << std::endl;
71 sigmas=limargs.sigmas;
72 } else {
73 pthread_cancel(limitthread);
74 std::cout << "DID NOT TERMINATE IN TIME - ABORTED!" << std::endl;
75 sigmas.push_back(-1);sigmas.push_back(-1);sigmas.push_back(-1);
76 }
77 }
78
79 void prepare_scan_axis(TH2 *variablemap,bool ismSUGRA) {
80 variablemap->GetXaxis()->SetTitle("m_{glu}");
81 variablemap->GetYaxis()->SetTitle("m_{LSP}");
82
83 if(ismSUGRA) {
84 variablemap->GetXaxis()->SetTitle("m_{0}");
85 variablemap->GetYaxis()->SetTitle("m_{1/2}");
86 }
87
88 variablemap->GetXaxis()->CenterTitle();
89 variablemap->GetYaxis()->CenterTitle();
90 }
91
92 void set_SUSY_style() {
93 Int_t MyPalette[100];
94 Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
95 Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
96 Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
97 Double_t stop[] = {0., .25, .50, .75, 1.0};
98 Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
99 for (int i=0;i<100;i++) MyPalette[i] = FI+i;
100
101 gStyle->SetPalette(100, MyPalette);
102
103 float rightmargin=gStyle->GetPadRightMargin();
104 gStyle->SetPadRightMargin(0.15);
105
106 }
107
108 float get_xs(float mglu, float mlsp, string massgluname, string massLSPname, map < pair<float, float>, map<string, float> > &xsec, string mcjzb, bool requireZ) {
109 float weightedpointxs=0;
110 stringstream addcut;
111 addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
112 cout << "About to calculate the process efficiencies " << endl;
113 /* for(int iproc=1;iproc<=10;iproc++) {
114 float process_xs = GetXSecForPointAndChannel(mglu,mlsp,xsec,iproc);
115 stringstream addcutplus;
116 addcutplus<<addcut.str()<<"&&(pfJetGoodNum=="<<iproc<<")";
117 write_warning(__FUNCTION__,"replaced process with pfJetGoodNum for testing purposes only!");
118 (scansample.collection)[0].events->Draw("eventNum",addcutplus.str().c_str(),"goff");
119 float nprocessevents = (scansample.collection)[0].events->GetSelectedRows();
120 float nselectedprocessevents,nselectedprocesseventserr;
121 cout << "nprocessevents = " << nprocessevents << endl;
122 MCefficiency((scansample.collection)[0].events,nselectedprocessevents,nselectedprocesseventserr,mcjzb,requireZ,1,addcutplus.str(),-1);//1 is the number to normalize to :-)
123 float weight=0;
124 if(nprocessevents>0) weight=(process_xs)/(nprocessevents);//*luminosity;
125 weightedpointxs+=weight*nselectedprocessevents;
126 }
127 return weightedpointxs;
128 */
129 return 1.0;
130 }
131
132 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) {
133 bool runninglocally=true;
134 if(njobs>-1&&jobnumber>-1) {
135 runninglocally=false;
136 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
137 } else {
138 dout << "Running locally " << endl;
139 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;
140 }
141
142 string massgluname="MassGlu";
143 string massLSPname="MassLSP";
144
145 string prefix="SMS_";
146 // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
147 bool ismSUGRA=false;
148 TIter nextkey(fsyst->GetListOfKeys());
149 TKey *key;
150 while ((key = (TKey*)nextkey()))
151 {
152 TObject *obj = key->ReadObj();
153 if(Contains((string)(obj->GetName()),"mSUGRA")) ismSUGRA=true;
154 }
155
156 map < pair<float, float>, map<string, float> > xsec;
157
158 if(ismSUGRA) {
159 massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
160 massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
161 mglustart=m0start;
162 xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
163 write_warning(__FUNCTION__,"Don't have the correct XS file yet");
164 mgluend=m0end;
165 mglustep=m0step;
166 mLSPstart=m12start;
167 mLSPend=m12end;
168 mLSPstep=m12step;
169 prefix="mSUGRA_";
170 cout << "mSUGRA scan has been set up." << endl;
171 } else {
172 cout << "SMS scan has been set up." << endl;
173 write_warning(__FUNCTION__,"Don't have the correct XS file yet");
174 xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
175 }
176
177 set_SUSY_style();
178
179 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
180
181 int Npoints=0;
182 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
183 for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
184 }
185 TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
186 //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());
187 TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
188 TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
189
190 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//observed limit
191 TH2F *explimitmap = new TH2F((prefix+"explimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit
192 TH2F *exp1plimitmap = new TH2F((prefix+"exp1plimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 1 sigma
193 TH2F *exp2plimitmap = new TH2F((prefix+"exp2plimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 2 sigma
194 TH2F *exp1mlimitmap = new TH2F((prefix+"exp1mlimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 1 sigma
195 TH2F *exp2mlimitmap = new TH2F((prefix+"exp2mlimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 2 sigma
196
197 TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzb_cut[ibin])).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
198 TH2F *xsmap = new TH2F((prefix+"crosssectionmap"+any2string(jzb_cut[ibin])).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
199
200 if(!fullerr || !mceff || !NEvents) {
201 write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
202 dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
203 delete limcanvas;
204 return;
205 }
206
207 bool doexpected=true;
208
209 int ipoint=-1;
210 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
211 for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
212 {
213 ipoint++;
214 if(!runninglocally&&!do_this_point(ipoint,Npoints,jobnumber,njobs)) continue;
215 float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
216 float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
217 float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
218 dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
219 dout << "Found : MCeff=" << currmceff << " and total error=" << currtoterr << " and Nevents=" << nevents << endl;
220 string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
221 if(currmceff<=0||currtoterr<=0||nevents==0) {
222 dout << " Nothing to work with, skipping this point." << endl;
223 continue;
224 }
225 vector<float> sigmas;
226 //do_limit_wrapper(currmceff,currtoterr,ibin,mcjzb,sigmas,plotfilename); // no threading right now.
227 sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true);
228 if(sigmas[0]>0) limitmap->Fill(mglu,mlsp,sigmas[0]); //anything else is an error code
229 if(sigmas.size()>1) {
230 explimitmap->Fill(mglu,mlsp,sigmas[1]);
231 exp1plimitmap->Fill(mglu,mlsp,sigmas[2]);
232 exp1mlimitmap->Fill(mglu,mlsp,sigmas[3]);
233 exp2plimitmap->Fill(mglu,mlsp,sigmas[4]);
234 exp2mlimitmap->Fill(mglu,mlsp,sigmas[5]);
235 } else {
236 write_warning(__FUNCTION__,"Watch out, limit results did not contain expected limits!");
237 }
238
239 dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " ) at " << sigmas[0] << endl;
240 if(1) {
241 dout << "Computing exclusion status" << endl;
242 float rel_limit=0;
243 float xs=get_xs(mglu,mlsp,massgluname,massLSPname,xsec,mcjzb,requireZ);
244 if(xs>0) rel_limit=sigmas[0]/xs;
245 // stringstream addcut;
246 // addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
247 // vector<float> xs_weights = processMCefficiency((scansample.collection)[0].events,mcjzb,requireZ,nevents, addcut.str());
248 exclmap->Fill(mglu,mlsp,rel_limit);
249 xsmap->Fill(mglu,mlsp,xs);
250 }
251 }
252 }
253
254 prepare_scan_axis(limitmap,ismSUGRA);
255 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 :-)
256 outputfile->cd();
257 limitmap->Write();
258 if(doexpected) {
259 explimitmap->Write();
260 exp1plimitmap->Write();
261 exp1mlimitmap->Write();
262 exp2plimitmap->Write();
263 exp2mlimitmap->Write();
264 }
265 if(ismSUGRA) {
266 exclmap->Write();
267 xsmap->Write();
268 }
269 outputfile->Close();
270 delete limcanvas;
271 }
272
273 void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
274 dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
275 TFile *fsyst = new TFile(fsystfilename.c_str());
276 if(!fsyst) {
277 write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
278 return;
279 }
280 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
281 establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
282 }
283 }
284
285
286
287
288 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) {
289 bool runninglocally=true;
290 if(njobs>-1&&jobnumber>-1) {
291 runninglocally=false;
292 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
293 } else {
294 dout << "Running locally " << endl;
295 dout << "This will take a really, really long time - if you want to see the results THIS week try running the LimitWorkerScript on the grid (DistributedModelCalculation/Limits/)" << endl;
296 }
297
298 cout << "FILE USED: " << (scansample.collection)[0].filename << endl;
299 cout << "FILE USED (name): " << (scansample.collection)[0].samplename << endl;
300 jzbSel=jzb_cut[ibin];
301 geqleq="geq";
302 automatized=true;
303 mcjzbexpression=mcjzb;
304
305 string massgluname="MassGlu";
306 string massLSPname="MassLSP";
307
308 string prefix="SMS_";
309 // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
310 bool ismSUGRA=false;
311 if(Contains((scansample.collection)[0].samplename,"mSUGRA")) ismSUGRA=true;
312 if(ismSUGRA) {
313 massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
314 massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
315 mglustart=m0start;
316 mgluend=m0end;
317 mglustep=m0step;
318 mLSPstart=m12start;
319 mLSPend=m12end;
320 mLSPstep=m12step;
321 prefix="mSUGRA_";
322 cout << "mSUGRA scan has been set up." << endl;
323 } else {
324 cout << "SMS scan has been set up." << endl;
325 }
326
327 Int_t MyPalette[100];
328 Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
329 Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
330 Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
331 Double_t stop[] = {0., .25, .50, .75, 1.0};
332 Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
333 for (int i=0;i<100;i++) MyPalette[i] = FI+i;
334
335 gStyle->SetPalette(100, MyPalette);
336
337 TH2F *limitmap = new TH2F((prefix+"limitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//observed limit
338 TH2F *explimitmap = new TH2F((prefix+"explimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit
339 TH2F *exp1plimitmap = new TH2F((prefix+"exp1plimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 1 sigma
340 TH2F *exp2plimitmap = new TH2F((prefix+"exp2plimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit + 2 sigma
341 TH2F *exp1mlimitmap = new TH2F((prefix+"exp1mlimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 1 sigma
342 TH2F *exp2mlimitmap = new TH2F((prefix+"exp2mlimitmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);//expected limit - 2 sigma
343
344 TH2F *exclmap = new TH2F((prefix+"exclusionmap"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
345 TH2F *sysjesmap = new TH2F((prefix+"sysjes"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
346 TH2F *sysjsumap = new TH2F((prefix+"sysjsu"+any2string(jzbSel)).c_str(), "",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
347 TH2F *sysresmap = new TH2F((prefix+"sysresmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
348 TH2F *efficiencymap = new TH2F((prefix+"efficiencymap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
349 TH2F *noscefficiencymap = new TH2F((prefix+"nosc_efficiencymap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
350 TH2F *Neventsmap = new TH2F((prefix+"Neventsmap"+any2string(jzbSel)).c_str(),"", (mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
351 TH2F *ipointmap = new TH2F((prefix+"Neventsmap"+any2string(jzbSel)).c_str(),"", (mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
352 TH2F *syspdfmap = new TH2F((prefix+"syspdfmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
353 TH2F *systotmap = new TH2F((prefix+"systotmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
354 TH2F *sysstatmap = new TH2F((prefix+"sysstatmap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
355
356 TH2F *timemap = new TH2F((prefix+"timemap"+any2string(jzbSel)).c_str(),"",(mgluend-mglustart)/mglustep+1,mglustart-0.5*mglustep,mgluend+0.5*mglustep,(mLSPend-mLSPstart)/mLSPstep+1,mLSPstart-0.5*mLSPstep,mLSPend+0.5*mLSPstep);
357
358 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
359
360 float rightmargin=gStyle->GetPadRightMargin();
361 gStyle->SetPadRightMargin(0.15);
362
363 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
364
365
366 bool doexpected=true;
367
368 int Npoints=0;
369 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
370 for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
371 }
372
373 int ipoint=-1;
374 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
375 for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
376 {
377 ipoint++;
378 if(!runninglocally&&!do_this_point(ipoint,Npoints,jobnumber,njobs)) continue;
379 float result=-987,resulterr=-987;
380 clock_t start,finish;
381 start = clock(); // starting the clock to measure how long the computation takes!
382 stringstream addcut;
383 addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
384 (scansample.collection)[0].events->Draw("eventNum",addcut.str().c_str(),"goff");
385 float nevents = (scansample.collection)[0].events->GetSelectedRows();
386 vector<vector<float> > systematics;
387 if(nevents<10) {
388 dout << "This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be skipped."<< endl;
389 continue;
390 } else {
391 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore not be skipped."<< endl;
392 }
393 if(nevents!=0&&efficiencyonly) {
394 Value effwosigcont = MCefficiency((scansample.collection)[0].events,result,resulterr,mcjzb,requireZ,nevents,addcut.str(),-1);
395 efficiencymap->Fill(mglu,mlsp,result);
396 noscefficiencymap->Fill(mglu,mlsp,effwosigcont.getValue());
397 noscefficiencymap->SetBinError(mglu,mlsp,effwosigcont.getError());
398 finish = clock();
399 timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
400 }
401 Neventsmap->Fill(mglu,mlsp,nevents);
402 ipointmap->Fill(mglu,mlsp,ipoint);
403 if(efficiencyonly) continue;
404
405 do_systematics_for_one_file((scansample.collection)[0].events,nevents,"SUSY SCAN", systematics,mcjzb,datajzb,peakerror,requireZ, addcut.str(),ismSUGRA);
406 float JZBcutat = systematics[0][0];
407 float mceff = systematics[0][1];
408 float mcefferr = systematics[0][2];//MC stat error
409 float toterr = systematics[0][4];
410 float sys_jes = systematics[0][5]; // Jet Energy Scale
411 float sys_jsu = systematics[0][6]; // JZB scale uncertainty
412 float sys_res = systematics[0][7]; // resolution
413 float mcwoscef = systematics[0][8]; // efficiency without signal contamination
414 float mcwoscefr= systematics[0][9]; // error on efficiency without signal contamination
415 float sys_pdf = 0;
416 if(systematics[0].size()>10) sys_pdf = systematics[0][10]; // PDF
417 efficiencymap->Fill(mglu,mlsp,mceff);
418 efficiencymap->SetBinError(efficiencymap->FindBin(mglu,mlsp),mcefferr);
419 noscefficiencymap->Fill(mglu,mlsp,mcwoscef);
420 noscefficiencymap->SetBinError(efficiencymap->FindBin(mglu,mlsp),mcwoscefr);
421
422 if(mceff!=mceff||toterr!=toterr||mceff<0) {
423 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;
424 continue;
425 } else {
426 if(!systematicsonly&&!efficiencyonly) {
427 dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
428 vector<float> sigmas;
429 string plotfilename=(string)(TString((scansample.collection)[0].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
430 do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
431 cout << "back in " << __FUNCTION__ << endl;
432 if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
433 limitmap->Fill(mglu,mlsp,sigmas[0]);
434 if(sigmas.size()>1) {
435 explimitmap->Fill(mglu,mlsp,sigmas[1]);
436 exp1plimitmap->Fill(mglu,mlsp,sigmas[2]);
437 exp1mlimitmap->Fill(mglu,mlsp,sigmas[3]);
438 exp2plimitmap->Fill(mglu,mlsp,sigmas[4]);
439 exp2mlimitmap->Fill(mglu,mlsp,sigmas[5]);
440 } else {
441 write_warning(__FUNCTION__,"Watch out, limit results did not contain expected limits!");
442 }
443
444 sysjesmap->Fill(mglu,mlsp,sys_jes);
445 sysjsumap->Fill(mglu,mlsp,sys_jsu);
446 sysresmap->Fill(mglu,mlsp,sys_res);
447 syspdfmap->Fill(mglu,mlsp,sys_pdf);
448 systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
449 sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
450 dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
451 } //end of if sigma is positive
452 finish = clock();
453 timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
454
455 //end of not systematics only condition
456 }
457 if(systematicsonly) {
458 sysjesmap->Fill(mglu,mlsp,sys_jes);
459 sysjsumap->Fill(mglu,mlsp,sys_jsu);
460 sysresmap->Fill(mglu,mlsp,sys_res);
461 syspdfmap->Fill(mglu,mlsp,sys_pdf);
462 systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
463 sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
464 finish = clock();
465 timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
466 }
467 }//efficiency is valid
468 }
469 }
470
471 prepare_scan_axis(limitmap,ismSUGRA);
472 prepare_scan_axis(sysjesmap,ismSUGRA);
473 prepare_scan_axis(sysjsumap,ismSUGRA);
474 prepare_scan_axis(sysresmap,ismSUGRA);
475 prepare_scan_axis(syspdfmap,ismSUGRA);
476 prepare_scan_axis(systotmap,ismSUGRA);
477 prepare_scan_axis(sysstatmap,ismSUGRA);
478 prepare_scan_axis(timemap,ismSUGRA);
479
480 if(!systematicsonly&&!efficiencyonly) {
481 limcanvas->cd();
482 limitmap->Draw("COLZ");
483 string titletobewritten="Limits in LSP-Glu plane";
484 if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
485 TText *title = write_title(titletobewritten);
486 title->Draw();
487 if(runninglocally) {
488 CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
489 } else {
490 TFile *outputfile;
491 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 :-)
492 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
493 limitmap->Write();
494 if(doexpected) {
495 explimitmap->Write();
496 exp1plimitmap->Write();
497 exp1mlimitmap->Write();
498 exp2plimitmap->Write();
499 exp2mlimitmap->Write();
500 }
501 sysjesmap->Write();
502 sysjsumap->Write();
503 sysresmap->Write();
504 efficiencymap->Write();
505 noscefficiencymap->Write();
506 syspdfmap->Write();
507 systotmap->Write();
508 sysstatmap->Write();
509 Neventsmap->Write();
510 ipointmap->Write();
511 timemap->Write();
512 outputfile->Close();
513 }
514 }
515 if(systematicsonly) { // systematics only :
516 limcanvas->cd();
517 sysjesmap->Draw("COLZ");
518 string titletobewritten="Jet Energy scale in LSP-Glu plane";
519 if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
520 TText *title = write_title(titletobewritten);
521 title->Draw();
522 if(runninglocally) {
523 CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
524 }
525 sysjsumap->Draw("COLZ");
526 titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
527 if(ismSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
528 TText *title2 = write_title(titletobewritten);
529 title2->Draw();
530 if(runninglocally) {
531 CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
532 }
533 sysresmap->Draw("COLZ");
534 titletobewritten="Resolution in LSP-Glu plane";
535 if(ismSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
536 TText *title3 = write_title(titletobewritten);
537 title3->Draw();
538 if(runninglocally) {
539 CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
540 }
541
542 if(!runninglocally) {
543 TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
544 sysjesmap->Write();
545 sysjsumap->Write();
546 sysresmap->Write();
547 efficiencymap->Write();
548 noscefficiencymap->Write();
549 Neventsmap->Write();
550 ipointmap->Write();
551 syspdfmap->Write();
552 systotmap->Write();
553 sysstatmap->Write();
554 timemap->Write();
555 outputfile->Close();
556 }
557 }//end of systematics only
558 if(efficiencyonly) {
559 limcanvas->cd();
560 efficiencymap->Draw("COLZ");
561 string titletobewritten="Efficiencies in LSP-Glu plane";
562 if(ismSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
563 TText *title = write_title(titletobewritten);
564 title->Draw();
565 if(runninglocally) {
566 CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
567 }
568 limcanvas->cd();
569 sysjesmap->Draw("COLZ");
570 titletobewritten="N(events) in LSP-Glu plane";
571 if(ismSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
572 TText *title2 = write_title(titletobewritten);
573 title2->Draw();
574 if(runninglocally) {
575 CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
576 }
577 if(!runninglocally) {
578 TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
579 ipointmap->Write();
580 Neventsmap->Write();
581 noscefficiencymap->Write();
582 efficiencymap->Write();
583 timemap->Write();
584 outputfile->Close();
585 }
586 }//end of efficiencies only
587
588 delete limitmap;
589 delete exclmap;
590 delete sysjesmap;
591 delete sysjsumap;
592 delete sysresmap;
593 delete noscefficiencymap;
594 delete efficiencymap;
595 delete Neventsmap;
596 delete ipointmap;
597 delete syspdfmap;
598 delete systotmap;
599 delete sysstatmap;
600 delete limcanvas;
601 }
602
603 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) {
604 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
605 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
606 scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, ibin, njobs, jobnumber,systonly,effonly);
607 }
608 }
609