ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SUSYScan.C
Revision: 1.36
Committed: Thu Sep 22 14:41:00 2011 UTC (13 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.35: +17 -4 lines
Log Message:
Added time map illustrating how long each point took for processing (to find ressource hogs)

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     histo->GetXaxis()->SetTitle("#Chi_{2}^{0}-LSP");
28     histo->GetXaxis()->CenterTitle();
29     histo->GetYaxis()->SetTitle("m_{#tilde{q}}");
30     histo->GetYaxis()->CenterTitle();
31     }
32    
33 buchmann 1.7 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 buchmann 1.25 string plotfilename;
42 buchmann 1.35 };
43 buchmann 1.7
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 buchmann 1.25 args->sigmas=compute_one_upper_limit(args->mceff,args->toterr,args->ibin,args->mcjzb,args->plotfilename,true);
49 buchmann 1.7 std::cout << "Thread to compute limits has finished" << std::endl;
50     isThreadActive=false;
51     return NULL; // oder in C++: return 0;// Damit kann man Werte zurückgeben
52     }
53    
54 buchmann 1.25 void do_limit_wrapper(float mceff,float toterr,int ibin,string mcjzb,vector<float> &sigmas,string plotfilename) {
55 buchmann 1.7 pthread_t limitthread;
56 buchmann 1.25 limit_args limargs={mceff,toterr,ibin,mcjzb,sigmas,plotfilename};
57 buchmann 1.7 pthread_create( &limitthread, NULL, compute_one_upper_limit_wrapper, (void*) &limargs);
58     int counter=0;
59 buchmann 1.29 int counterinterval=5;
60 buchmann 1.7 sleep(1); //waiting a second for the process to become active
61     while(counter<limitpatience*60 && isThreadActive) {
62 buchmann 1.28 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 buchmann 1.29 counter+=counterinterval;
64     sleep(counterinterval);
65 buchmann 1.7 }
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 buchmann 1.22 void prepare_scan_axis(TH2 *variablemap,bool ismSUGRA) {
80 buchmann 1.9 variablemap->GetXaxis()->SetTitle("m_{glu}");
81     variablemap->GetYaxis()->SetTitle("m_{LSP}");
82 buchmann 1.35
83 buchmann 1.22 if(ismSUGRA) {
84     variablemap->GetXaxis()->SetTitle("m_{0}");
85     variablemap->GetYaxis()->SetTitle("m_{1/2}");
86     }
87 buchmann 1.35
88 buchmann 1.9 variablemap->GetXaxis()->CenterTitle();
89     variablemap->GetYaxis()->CenterTitle();
90     }
91    
92 buchmann 1.31 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 buchmann 1.35
101 buchmann 1.31 gStyle->SetPalette(100, MyPalette);
102 buchmann 1.35
103 buchmann 1.31 float rightmargin=gStyle->GetPadRightMargin();
104     gStyle->SetPadRightMargin(0.15);
105    
106     }
107    
108 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) {
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     }
128     return weightedpointxs;
129     }
130    
131 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) {
132     bool runninglocally=true;
133     if(njobs>-1&&jobnumber>-1) {
134     runninglocally=false;
135     dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
136     } else {
137     dout << "Running locally " << endl;
138     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;
139     }
140 buchmann 1.35
141 buchmann 1.31 string massgluname="MassGlu";
142     string massLSPname="MassLSP";
143 buchmann 1.35
144 buchmann 1.31 string prefix="SMS_";
145     // up to here, everything is set up for SMS; now we need to switch stuff around if we're dealing with an mSUGRA scan!
146     bool ismSUGRA=false;
147     TIter nextkey(fsyst->GetListOfKeys());
148     TKey *key;
149     while ((key = (TKey*)nextkey()))
150     {
151     TObject *obj = key->ReadObj();
152     if(Contains((string)(obj->GetName()),"mSUGRA")) ismSUGRA=true;
153     }
154 buchmann 1.35
155     map < pair<float, float>, map<string, float> > xsec;
156 buchmann 1.31
157     if(ismSUGRA) {
158     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
159     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
160     mglustart=m0start;
161 buchmann 1.35 xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
162     write_warning(__FUNCTION__,"Don't have the correct XS file yet");
163 buchmann 1.31 mgluend=m0end;
164     mglustep=m0step;
165     mLSPstart=m12start;
166     mLSPend=m12end;
167     mLSPstep=m12step;
168     prefix="mSUGRA_";
169     cout << "mSUGRA scan has been set up." << endl;
170     } else {
171     cout << "SMS scan has been set up." << endl;
172 buchmann 1.35 write_warning(__FUNCTION__,"Don't have the correct XS file yet");
173     xsec=getXsec("/scratch/buchmann/C/scale_xsection_nlo1.0_m0_m12_10_0_1v1.txt");
174 buchmann 1.31 }
175 buchmann 1.35
176 buchmann 1.31 set_SUSY_style();
177 buchmann 1.35
178 buchmann 1.31 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
179 buchmann 1.35
180 buchmann 1.31 int Npoints=0;
181     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
182     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
183     }
184 buchmann 1.34 // TH2F *mceff = (TH2F*)fsyst->Get((prefix+"efficiencymap"+any2string(jzb_cut[ibin])).c_str());
185     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());
186 buchmann 1.31 TH2F *fullerr = (TH2F*)fsyst->Get((prefix+"systotmap"+any2string(jzb_cut[ibin])).c_str());
187 buchmann 1.33 TH2F *NEvents = (TH2F*)fsyst->Get((prefix+"Neventsmap"+any2string(jzb_cut[ibin])).c_str());
188 buchmann 1.35
189 buchmann 1.31 TH2F *limitmap = new TH2F((prefix+"limitmap"+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);
190 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);
191     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);
192 buchmann 1.35
193 buchmann 1.32 if(!fullerr || !mceff || !NEvents) {
194 buchmann 1.31 write_error(__FUNCTION__,"The supplied systematics file did not contain the correct histograms - please check the file");
195 buchmann 1.34 dout << "mc eff address: " << mceff << " , error address: " << fullerr << " , NEvents address: " << NEvents << endl;
196 buchmann 1.31 delete limcanvas;
197     return;
198     }
199 buchmann 1.35
200 buchmann 1.31 int ipoint=-1;
201     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
202     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
203     {
204     ipoint++;
205     if(!runninglocally&&!do_this_point(ipoint,Npoints,jobnumber,njobs)) continue;
206     float currmceff=mceff->GetBinContent(mceff->FindBin(mglu,mlsp));
207 buchmann 1.33 float currtoterr=(fullerr->GetBinContent(fullerr->FindBin(mglu,mlsp)))*currmceff;
208 buchmann 1.32 float nevents=NEvents->GetBinContent(NEvents->FindBin(mglu,mlsp));
209 buchmann 1.34 dout << "Looking at point " << ipoint << " / " << Npoints << " with masses " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << endl;
210 buchmann 1.35 dout << "Found : MCeff=" << currmceff << " and total error=" << currtoterr << " and Nevents=" << nevents << endl;
211 buchmann 1.31 string plotfilename=(string)(TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
212 buchmann 1.34 if(currmceff<=0||currtoterr<=0||nevents==0) {
213     dout << " Nothing to work with, skipping this point." << endl;
214     continue;
215     }
216 buchmann 1.31 vector<float> sigmas;
217 buchmann 1.32 //do_limit_wrapper(currmceff,currtoterr,ibin,mcjzb,sigmas,plotfilename); // no threading right now.
218     sigmas=compute_one_upper_limit(currmceff,currtoterr,ibin,mcjzb,plotfilename,true);
219 buchmann 1.34 if(sigmas[0]>0) limitmap->Fill(mglu,mlsp,sigmas[0]); //anything else is an error code
220 buchmann 1.35 dout << "An upper limit has been added for this point ( " << massgluname << " = " << mglu << " and " << massLSPname << " = " << mlsp << " ) at " << sigmas[0] << endl;
221     if(1) {
222     dout << "Computing exclusion status" << endl;
223     float rel_limit=0;
224     float xs=get_xs(mglu,mlsp,massgluname,massLSPname,xsec,mcjzb,requireZ);
225     if(xs>0) rel_limit=sigmas[0]/xs;
226     // stringstream addcut;
227     // addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
228     // vector<float> xs_weights = processMCefficiency((scansample.collection)[0].events,mcjzb,requireZ,nevents, addcut.str());
229     exclmap->Fill(mglu,mlsp,rel_limit);
230     xsmap->Fill(mglu,mlsp,xs);
231 buchmann 1.32 }
232 buchmann 1.31 }
233     }
234 buchmann 1.35
235 buchmann 1.31 prepare_scan_axis(limitmap,ismSUGRA);
236 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 :-)
237     outputfile->cd();
238 buchmann 1.31 limitmap->Write();
239 buchmann 1.32 if(ismSUGRA) {
240     exclmap->Write();
241     xsmap->Write();
242     }
243     outputfile->Close();
244 buchmann 1.31 delete limcanvas;
245     }
246    
247     void establish_SUSY_limits(string mcjzb,string datajzb,vector<float> jzb_cut,bool requireZ, float peakerror, string fsystfilename, float njobs=-1, float jobnumber=-1) {
248     dout << "Starting the SUSY scan from systematics file now with all " << jzb_cut.size() << " bin(s)" << " and using " << fsystfilename << endl;
249     TFile *fsyst = new TFile(fsystfilename.c_str());
250     if(!fsyst) {
251     write_error(__FUNCTION__,"You provided an invalid systematics file. Please change it ... ");
252     return;
253     }
254     for(int ibin=0;ibin<jzb_cut.size();ibin++) {
255     establish_SUSY_limits(mcjzb,datajzb,jzb_cut,requireZ, peakerror, fsyst, ibin,njobs, jobnumber);
256     }
257     }
258    
259    
260    
261    
262 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) {
263 buchmann 1.6 bool runninglocally=true;
264     if(njobs>-1&&jobnumber>-1) {
265     runninglocally=false;
266 buchmann 1.13 dout << "Running on the GRID (this is job " << jobnumber << "/" << njobs << ") for a jzb cut at " << jzb_cut[ibin] << endl;
267 buchmann 1.6 } else {
268 buchmann 1.7 dout << "Running locally " << endl;
269     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;
270 buchmann 1.6 }
271 buchmann 1.35
272 buchmann 1.18 cout << "FILE USED: " << (scansample.collection)[0].filename << endl;
273 buchmann 1.24 cout << "FILE USED (name): " << (scansample.collection)[0].samplename << endl;
274 buchmann 1.4 jzbSel=jzb_cut[ibin];
275     geqleq="geq";
276     automatized=true;
277     mcjzbexpression=mcjzb;
278 buchmann 1.35
279 buchmann 1.4 string massgluname="MassGlu";
280     string massLSPname="MassLSP";
281 buchmann 1.35
282 buchmann 1.23 string prefix="SMS_";
283 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!
284     bool ismSUGRA=false;
285 buchmann 1.24 if(Contains((scansample.collection)[0].samplename,"mSUGRA")) ismSUGRA=true;
286 buchmann 1.22 if(ismSUGRA) {
287     massgluname="M0"; // this is the "x axis" in the limit plot (like the gluino in the SMS case)
288     massLSPname="M12"; // this is the "y axis" in the limit plot (like the LSP in the SMS case)
289     mglustart=m0start;
290     mgluend=m0end;
291     mglustep=m0step;
292     mLSPstart=m12start;
293     mLSPend=m12end;
294     mLSPstep=m12step;
295 buchmann 1.23 prefix="mSUGRA_";
296 buchmann 1.24 cout << "mSUGRA scan has been set up." << endl;
297     } else {
298     cout << "SMS scan has been set up." << endl;
299     }
300 buchmann 1.35
301 buchmann 1.4 Int_t MyPalette[100];
302     Double_t r[] = {0., 0.0, 1.0, 1.0, 1.0};
303     Double_t g[] = {0., 0.0, 0.0, 1.0, 1.0};
304     Double_t b[] = {0., 1.0, 0.0, 0.0, 1.0};
305     Double_t stop[] = {0., .25, .50, .75, 1.0};
306     Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 110);
307     for (int i=0;i<100;i++) MyPalette[i] = FI+i;
308 buchmann 1.35
309 buchmann 1.4 gStyle->SetPalette(100, MyPalette);
310 buchmann 1.35
311 buchmann 1.23 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);
312     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);
313     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);
314     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);
315     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);
316 buchmann 1.31 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);
317     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);
318     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);
319 buchmann 1.27 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);
320     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);
321     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);
322    
323 buchmann 1.36 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);
324    
325 buchmann 1.29 write_warning(__FUNCTION__,"CURRENTLY SWITCHING AUTOMATIZED MODE OFF!");automatized=false;
326 buchmann 1.35
327 buchmann 1.4 float rightmargin=gStyle->GetPadRightMargin();
328     gStyle->SetPadRightMargin(0.15);
329 buchmann 1.35
330 buchmann 1.4 TCanvas *limcanvas = new TCanvas("limcanvas","Limit canvas");
331 buchmann 1.35
332 buchmann 1.6 int Npoints=0;
333     for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
334     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep) Npoints++;
335     }
336 buchmann 1.35
337 buchmann 1.6 int ipoint=-1;
338 buchmann 1.4 for(int mglu=mglustart;mglu<=mgluend;mglu+=mglustep) {
339     for (int mlsp=mLSPstart;mlsp<=mLSPend&&mlsp<=mglu;mlsp+=mLSPstep)
340     {
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.36 clock_t start,finish;
345     start = clock(); // starting the clock to measure how long the computation takes!
346 buchmann 1.4 stringstream addcut;
347     addcut << "(TMath::Abs("<<massgluname<<"-"<<mglu<<")<5)&&(TMath::Abs("<<massLSPname<<"-"<<mlsp<<")<5)";
348 buchmann 1.14 (scansample.collection)[0].events->Draw("eventNum",addcut.str().c_str(),"goff");
349     float nevents = (scansample.collection)[0].events->GetSelectedRows();
350 buchmann 1.4 vector<vector<float> > systematics;
351 buchmann 1.30 if(nevents<10) {
352 buchmann 1.35 dout << "This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") does not contain enough events and will be skipped."<< endl;
353     continue;
354 buchmann 1.6 } else {
355 buchmann 1.35 dout << "OK! This point ("<<ipoint<<") with configuration ("<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp << ") contains " << nevents << " and will therefore not be skipped."<< endl;
356 buchmann 1.22 }
357     if(nevents!=0&&efficiencyonly) {
358 buchmann 1.36 MCefficiency((scansample.collection)[0].events,result,resulterr,mcjzb,requireZ,nevents,addcut.str(),-1);
359     efficiencymap->Fill(mglu,mlsp,result);
360     finish = clock();
361     timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
362 buchmann 1.13 }
363 buchmann 1.17 Neventsmap->Fill(mglu,mlsp,nevents);
364 buchmann 1.24 ipointmap->Fill(mglu,mlsp,ipoint);
365 buchmann 1.17 if(efficiencyonly) continue;
366    
367 buchmann 1.22 do_systematics_for_one_file((scansample.collection)[0].events,nevents,"SUSY SCAN", systematics,mcjzb,datajzb,peakerror,requireZ, addcut.str(),ismSUGRA);
368 buchmann 1.9 float JZBcutat = systematics[0][0];
369     float mceff = systematics[0][1];
370 buchmann 1.22 float mcefferr = systematics[0][2];//MC stat error
371 buchmann 1.9 float toterr = systematics[0][4];
372     float sys_jes = systematics[0][5]; // Jet Energy Scale
373     float sys_jsu = systematics[0][6]; // JZB scale uncertainty
374     float sys_res = systematics[0][7]; // resolution
375 buchmann 1.27 float sys_pdf = 0;
376     if(systematics[0].size()>9) sys_pdf = systematics[0][9]; // PDF
377 buchmann 1.22 efficiencymap->Fill(mglu,mlsp,mceff);
378     efficiencymap->SetBinError(efficiencymap->FindBin(mglu,mlsp),mcefferr);//blublu
379 buchmann 1.35
380 buchmann 1.15 if(mceff!=mceff||toterr!=toterr||mceff<0) {
381 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;
382     continue;
383 buchmann 1.5 } else {
384 buchmann 1.35 if(!systematicsonly&&!efficiencyonly) {
385     dout << "Calculating limit now for "<<massgluname<<"="<<mglu<<" , "<<massLSPname<<"="<<mlsp <<endl;
386     vector<float> sigmas;
387     string plotfilename=(string)(TString((scansample.collection)[0].samplename)+TString(massgluname)+TString(any2string(mglu))+TString("__")+TString(massLSPname)+TString(any2string(mlsp))+TString(".png"));
388     do_limit_wrapper(mceff,toterr,ibin,mcjzb,sigmas,plotfilename);
389     cout << "back in " << __FUNCTION__ << endl;
390     if(sigmas[0]>-0.5) { // negative sigmas are the error signature of do_limit_wrapper, so we want to exclude them.
391     limitmap->Fill(mglu,mlsp,sigmas[0]);
392     sysjesmap->Fill(mglu,mlsp,sys_jes);
393     sysjsumap->Fill(mglu,mlsp,sys_jsu);
394     sysresmap->Fill(mglu,mlsp,sys_res);
395     syspdfmap->Fill(mglu,mlsp,sys_pdf);
396     systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
397     sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
398     dout << "A limit has been added at " << sigmas[0] << " for m_{glu}="<<mglu << " and m_{lsp}="<<mlsp<<endl;
399     } //end of if sigma is positive
400 buchmann 1.36 finish = clock();
401     timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
402    
403 buchmann 1.35 //end of not systematics only condition
404     }
405     if(systematicsonly) {
406     sysjesmap->Fill(mglu,mlsp,sys_jes);
407     sysjsumap->Fill(mglu,mlsp,sys_jsu);
408     sysresmap->Fill(mglu,mlsp,sys_res);
409     syspdfmap->Fill(mglu,mlsp,sys_pdf);
410     systotmap->Fill(mglu,mlsp,toterr/mceff);//total relative (!) error
411     sysstatmap->Fill(mglu,mlsp,mcefferr);//total relative (!) error
412 buchmann 1.36 finish = clock();
413     timemap->Fill(mglu,mlsp,((float(finish)-float(start))/CLOCKS_PER_SEC));
414 buchmann 1.35 }
415 buchmann 1.15 }//efficiency is valid
416 buchmann 1.4 }
417     }
418 buchmann 1.35
419 buchmann 1.22 prepare_scan_axis(limitmap,ismSUGRA);
420     prepare_scan_axis(sysjesmap,ismSUGRA);
421     prepare_scan_axis(sysjsumap,ismSUGRA);
422     prepare_scan_axis(sysresmap,ismSUGRA);
423 buchmann 1.27 prepare_scan_axis(syspdfmap,ismSUGRA);
424     prepare_scan_axis(systotmap,ismSUGRA);
425     prepare_scan_axis(sysstatmap,ismSUGRA);
426 buchmann 1.36 prepare_scan_axis(timemap,ismSUGRA);
427 buchmann 1.35
428 buchmann 1.13 if(!systematicsonly&&!efficiencyonly) {
429 buchmann 1.9 limcanvas->cd();
430     limitmap->Draw("COLZ");
431 buchmann 1.22 string titletobewritten="Limits in LSP-Glu plane";
432     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
433     TText *title = write_title(titletobewritten);
434 buchmann 1.9 title->Draw();
435     if(runninglocally) {
436     CompleteSave(limcanvas,"SUSYScan/Limits_JZB_geq"+any2string(jzb_cut[ibin]));
437     } else {
438 buchmann 1.12 TFile *outputfile;
439     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 :-)
440 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
441 buchmann 1.9 limitmap->Write();
442 buchmann 1.18 sysjesmap->Write();
443     sysjsumap->Write();
444 buchmann 1.28 sysresmap->Write();
445 buchmann 1.18 efficiencymap->Write();
446 buchmann 1.27 syspdfmap->Write();
447     systotmap->Write();
448     sysstatmap->Write();
449 buchmann 1.18 Neventsmap->Write();
450 buchmann 1.24 ipointmap->Write();
451 buchmann 1.36 timemap->Write();
452 buchmann 1.9 outputfile->Close();
453     }
454 buchmann 1.35 }
455 buchmann 1.13 if(systematicsonly) { // systematics only :
456 buchmann 1.9 limcanvas->cd();
457     sysjesmap->Draw("COLZ");
458 buchmann 1.22 string titletobewritten="Jet Energy scale in LSP-Glu plane";
459     if(ismSUGRA) titletobewritten="Limits in m_{1/2}-m_{0} plane";
460     TText *title = write_title(titletobewritten);
461 buchmann 1.9 title->Draw();
462     if(runninglocally) {
463     CompleteSave(limcanvas,"SUSYScan/JES_geq"+any2string(jzb_cut[ibin]));
464     }
465     sysjsumap->Draw("COLZ");
466 buchmann 1.22 titletobewritten="JZB Scale Uncertainty in LSP-Glu plane";
467     if(ismSUGRA) titletobewritten="JZB Scale Uncertainty in m_{1/2}-m_{0} plane";
468     TText *title2 = write_title(titletobewritten);
469 buchmann 1.9 title2->Draw();
470     if(runninglocally) {
471     CompleteSave(limcanvas,"SUSYScan/JSU_geq"+any2string(jzb_cut[ibin]));
472     }
473     sysresmap->Draw("COLZ");
474 buchmann 1.22 titletobewritten="Resolution in LSP-Glu plane";
475     if(ismSUGRA) titletobewritten="Resolution in m_{1/2}-m_{0} plane";
476     TText *title3 = write_title(titletobewritten);
477 buchmann 1.9 title3->Draw();
478     if(runninglocally) {
479     CompleteSave(limcanvas,"SUSYScan/Resolution_geq"+any2string(jzb_cut[ibin]));
480     }
481 buchmann 1.35
482 buchmann 1.9 if(!runninglocally) {
483     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
484     sysjesmap->Write();
485     sysjsumap->Write();
486     sysresmap->Write();
487 buchmann 1.18 efficiencymap->Write();
488     Neventsmap->Write();
489 buchmann 1.24 ipointmap->Write();
490 buchmann 1.27 syspdfmap->Write();
491     systotmap->Write();
492     sysstatmap->Write();
493 buchmann 1.36 timemap->Write();
494 buchmann 1.9 outputfile->Close();
495     }
496     }//end of systematics only
497 buchmann 1.13 if(efficiencyonly) {
498     limcanvas->cd();
499     efficiencymap->Draw("COLZ");
500 buchmann 1.22 string titletobewritten="Efficiencies in LSP-Glu plane";
501     if(ismSUGRA) titletobewritten="Efficiencies in m_{1/2}-m_{0} plane";
502     TText *title = write_title(titletobewritten);
503 buchmann 1.13 title->Draw();
504     if(runninglocally) {
505     CompleteSave(limcanvas,"SUSYScan/Efficiency_geq"+any2string(jzb_cut[ibin]));
506     }
507     limcanvas->cd();
508     sysjesmap->Draw("COLZ");
509 buchmann 1.22 titletobewritten="N(events) in LSP-Glu plane";
510     if(ismSUGRA) titletobewritten="N(events) in m_{1/2}-m_{0} plane";
511     TText *title2 = write_title(titletobewritten);
512 buchmann 1.13 title2->Draw();
513     if(runninglocally) {
514     CompleteSave(limcanvas,"SUSYScan/Nevents_geq"+any2string(jzb_cut[ibin]));
515     }
516     if(!runninglocally) {
517     TFile *outputfile=new TFile(("output/DistributedSystematics_job"+string(any2string(jobnumber))+"_of_"+string(any2string(njobs))+".root").c_str(),"UPDATE");
518 buchmann 1.24 ipointmap->Write();
519 buchmann 1.13 Neventsmap->Write();
520     efficiencymap->Write();
521 buchmann 1.36 timemap->Write();
522 buchmann 1.13 outputfile->Close();
523     }
524     }//end of efficiencies only
525 buchmann 1.35
526 buchmann 1.31 delete limitmap;
527     delete exclmap;
528     delete sysjesmap;
529     delete sysjsumap;
530     delete sysresmap;
531     delete efficiencymap;
532     delete Neventsmap;
533     delete ipointmap;
534     delete syspdfmap;
535     delete systotmap;
536     delete sysstatmap;
537 buchmann 1.13 delete limcanvas;
538 buchmann 1.1 }
539 buchmann 1.4
540 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) {
541 buchmann 1.10 dout << "Starting the SUSY scan now with all " << jzb_cut.size() << " bin(s)" << endl;
542 buchmann 1.4 for(int ibin=0;ibin<jzb_cut.size();ibin++) {
543 buchmann 1.13 scan_SUSY_parameter_space(mcjzb,datajzb,jzb_cut,requireZ, peakerror, ibin, njobs, jobnumber,systonly,effonly);
544 buchmann 1.4 }
545 buchmann 1.6 }
546 buchmann 1.35