ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.46
Committed: Thu Oct 27 08:13:32 2011 UTC (13 years, 6 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.45: +21 -56 lines
Log Message:
Remove previous limit calculation wrappers for SUSY scans (now using timed limit capsule); implemented weighted xs

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