ROOTPWA
plotWeightedEvts.C
Go to the documentation of this file.
1 #include "TTree.h"
2 #include "TFile.h"
3 #include "TList.h"
4 #include "TLatex.h"
5 
6 #include "TLorentzVector.h"
7 #include "TVector3.h"
8 #include "TLorentzRotation.h"
9 #include "TH1D.h"
10 #include "TH2D.h"
11 #include "TGraphErrors.h"
12 #include "TClonesArray.h"
13 #include "TROOT.h"
14 #include "TMath.h"
15 #include "TPad.h"
16 #include "TColor.h"
17 #include "TStyle.h"
18 #include "TGaxis.h"
19 #include "TCanvas.h"
20 #include "TString.h"
21 #include <iostream>
22 #include <vector>
23 #include "NParticleEvent.h"
24 // #include "plotWeightedEvts.h" maybe you are missing this? not needed since declaration is not needed, too
25 
26 
27 using namespace std;
28 
29 
30 // subroutine to build a graph with errors out of a list of histograms
31 // the first histo is taken as the value
32 // the errors are computed from the spread of the values over all histograms
33 
34 TGraphErrors* buildGraph(vector<TH1D*> histo, unsigned int n){
35  unsigned int nbins=histo[0]->GetNbinsX();
36 
37  TGraphErrors* g=new TGraphErrors(nbins);
38  for(unsigned int ib=0;ib<nbins;++ib){
39  double x=histo[0]->GetBinCenter(ib+1);
40  double val=histo[0]->GetBinContent(ib+1);
41  double dx=histo[0]->GetBinWidth(ib+1)*0.5;
42  g->SetPoint(ib,x,val);
43  // calculate error by looping over all histos
44  double sigma=0;
45  for(unsigned int ih=0;ih<n;++ih){
46  double xi=val-histo[ih]->GetBinContent(ib+1);
47  sigma+=xi*xi;
48  }
49  sigma/=(n-1);
50  g->SetPointError(ib,dx,sqrt(sigma));
51  }
52 
53  return g;
54 
55 }
56 
57 // this moved to the header, this is a temporary solution
58 // if you need the default values, try to include the header
59 // I have no clue if it still compiles with ALIC compiler with root
60 //void plotWeightedEvts(TTree* mctr, TTree* datatr, TString outfilename="kineplots.root", TString mass="000");
61 
62 void plotWeightedEvts(TTree* mctr, TTree* datatr, TString outfilename, TString mass, unsigned int nsamples=1){
63 
64 gROOT->SetStyle("Plain");
65  Int_t NCont=100;
66 
67  const Int_t NRGBs = 5;
68  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
69  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
70  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
71  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
72  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
73 
74  gStyle->SetNumberContours(NCont);
75 
76  TString massbin;
77  if(mass!="000"){
78  massbin=("_m")+mass;massbin.ReplaceAll(" ","");
79  }
80 
81  int nbninsm=144; // 144
82  int nbinsang=40; // 80
83 
84 
85  gStyle->SetOptStat(0);
86  gStyle->SetOptTitle(0);
87  gStyle->SetStripDecimals(1);
88  TGaxis::SetMaxDigits(4);
89 
90  Int_t font=132;
91 
92  gStyle->SetTextFont(font);
93  gStyle->SetLabelFont(font,"xyz");
94  gStyle->SetTitleFont(font,"xyz");
95 
96  vector<TH1D*> hM;
97  TH1D* hMMC=new TH1D("hMMC"+massbin,"Mass (MC)",60,1.0,3.0);
98  hM.push_back(hMMC);
99  TH1D* hMData=new TH1D("hMData"+massbin,"Mass (DATA)",60,1.0,3.0);
100  hM.push_back(hMData);
101 
102 
103  vector<TH1D*> hMIsobar; // 4pi
104  vector<TH1D*> hMIsobar2; // 3pi
105  vector<TH1D*> hMIsobar3; // 2pi
106  vector<TH1D*> hGJ; // 4pi/1pi
107  vector<TH1D*> hTY; // 4pi/1pi
108 
109  vector<TH1D*> hGJ2; // 3pi/2pi
110  vector<TH1D*> hHe22; // 2pi2pi helicity frame
111  vector<TH1D*> hHe22Phi;
112  vector<TH1D*> hHe31; // 3pi1pi helicity frame
113  vector<TH1D*> hHe31Phi;
114  vector<TH1D*> hHe21; // 2pi1pi helicity frame
115  vector<TH1D*> hHe21Phi;
116 
117 
118  for(unsigned int isamples=0;isamples<nsamples;++isamples){
119  TString blub;blub+=massbin;blub+="_";blub+=isamples;
120  TH1D* hMIsobarMC=new TH1D("hMIsobarMC"+blub,"Isobar Mass (MC) for m_{5#pi}="+mass,nbninsm,0.2,3);
121  hMIsobar.push_back(hMIsobarMC);
122  hMIsobarMC->Sumw2();
123 
124  TH1D* hMIsobar2MC=new TH1D("hMIsobar2MC"+blub,"Isobar Mass (MC)",nbninsm,0.4,2.7);
125  hMIsobar2.push_back(hMIsobar2MC);
126  hMIsobar2MC->Sumw2();
127 
128  TH1D* hMIsobar3MC=new TH1D("hMIsobar3MC"+blub,"Isobar Mass (MC)",nbninsm,0.2,2.2);
129  hMIsobar3.push_back(hMIsobar3MC);
130  hMIsobar3MC->Sumw2();
131 
132  TString name="hGJMC";name+=+massbin;name+="_";name+=isamples;
133  TH1D* hGJMC=new TH1D(name,"Cos Gottfried-Jackson Theta (MC)",nbinsang,-1,1);
134  hGJ.push_back(hGJMC);
135  hGJMC->Sumw2();
136 
137  TH1D* hTYMC=new TH1D("hTYMC"+blub,"Treiman-Yang Phi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
138  hTY.push_back(hTYMC);
139  hTYMC->Sumw2();
140 
141 
142  TH1D* hGJ2MC=new TH1D("hGJ2MC"+blub,"Cos Gottfried-Jackson Theta (MC)",nbinsang,-1,1);
143  hGJ2.push_back(hGJ2MC);
144  hGJ2MC->Sumw2();
145 
146  TH1D* hHe22MC=new TH1D("hHe22ThMC"+blub,"Helicity Theta 2pi2pi (MC)",nbinsang,-1,1);
147  hHe22.push_back(hHe22MC);
148  hHe22MC->Sumw2();
149 
150  TH1D* hHe22PhiMC=new TH1D("hHe22PhiMC"+blub,"Helicity Phi 2pi2pi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
151  hHe22Phi.push_back(hHe22PhiMC);
152  hHe22PhiMC->Sumw2();
153 
154  TH1D* hHe31MC=new TH1D("hHe31ThMC"+blub,"Helicity Theta 3pi1pi (MC)",nbinsang,-1,1);
155  hHe31.push_back(hHe31MC);
156  hHe31MC->Sumw2();
157 
158  TH1D* hHe31PhiMC=new TH1D("hHe31PhiMC"+blub,"Helicity Phi 3pi1pi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
159  hHe31Phi.push_back(hHe31PhiMC);
160  hHe31PhiMC->Sumw2();
161 
162 
163 TH1D* hHe21MC=new TH1D("hHe21ThMC"+blub,"Helicity Theta 2pi1pi (MC)",nbinsang,-1,1);
164  hHe21.push_back(hHe21MC);
165  hHe21MC->Sumw2();
166 
167  TH1D* hHe21PhiMC=new TH1D("hHe21PhiMC"+blub,"Helicity Phi 2pi1pi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
168  hHe21Phi.push_back(hHe21PhiMC);
169  hHe21PhiMC->Sumw2();
170  } // end loop over model samples
171 
172 
173  TH1D* hMIsobarData=new TH1D("hMIsobarData"+massbin,"Isobar mass (DATA)",nbninsm,0.2,3);
174  hMIsobar.push_back(hMIsobarData);
175 
176  TH1D* hMIsobarAPS=new TH1D("hMIsobarAPS"+massbin,"Isobar mass (Accepted PS)",nbninsm,0.2,3);
177 
178 
179 
180  TH1D* hDiffMIsobar; //=new TH1D("hDiffMIsobarData","Isobar mass (DATA) Diff",40,0.2,2.2);
181 TH1D* hDiffMIsobar2;
182 TH1D* hDiffMIsobar3;
183 
184 
185  TH1D* hMIsobar2Data=new TH1D("hMIsobar2Data"+massbin,"Isobar mass (DATA)",nbninsm,0.4,2.7);
186  hMIsobar2.push_back(hMIsobar2Data);
187 TH1D* hMIsobar2APS=new TH1D("hMIsobar2APS"+massbin,"Isobar mass (Accepted PS)",nbninsm,0.4,2.7);
188 
189  TH1D* hMIsobar3Data=new TH1D("hMIsobar3Data"+massbin,"Isobar mass (DATA)",nbninsm,0.2,2.3);
190  hMIsobar3.push_back(hMIsobar3Data);
191 TH1D* hMIsobar3APS=new TH1D("hMIsobar3APS"+massbin,"Isobar mass (Accepted PS)",nbninsm,0.2,2.3);
192 
193  TH1D* hGJData=new TH1D("hGJData"+massbin,"Cos Gottfried-Jackson Theta (DATA)",nbinsang,-1,1); hGJ.push_back(hGJData);
194 
195  TH1D* hGJAPS=new TH1D("hGJAPS"+massbin,"Cos Gottfried-Jackson Theta (Accepted PS)",nbinsang,-1,1);
196 
197  TH1D* hHe22Data=new TH1D("hHe22ThData"+massbin,"Helicity Theta 2pi2pi (Data)",nbinsang,-1,1);
198  hHe22.push_back(hHe22Data);
199  TH1D* hHe22APS=new TH1D("hHe22ThAPS"+massbin,"Helicity Theta 2pi2pi (Accepted PS)",nbinsang,-1,1);
200 
201 
202  TH1D* hHe22PhiData=new TH1D("hHe22PhiData"+massbin,"Helicity Phi 2pi2pi (Data)",nbinsang,-TMath::Pi(),TMath::Pi());
203  hHe22Phi.push_back(hHe22PhiData);
204  TH1D* hHe22PhiAPS=new TH1D("hHe22PhiAPS"+massbin,"Helicity Phi 2pi2pi (Accepted PS)",nbinsang,-TMath::Pi(),TMath::Pi());
205 
206 
207  TH1D* hHe31Data=new TH1D("hHe31ThData"+massbin,"Helicity Theta 3pi1pi (Data)",nbinsang,-1,1);
208  hHe31.push_back(hHe31Data);
209  TH1D* hHe31APS=new TH1D("hHe31ThAPS"+massbin,"Helicity Theta 3pi1pi (Accepted PS)",nbinsang,-1,1);
210 
211  TH1D* hHe31PhiData=new TH1D("hHe31PhiData"+massbin,"Helicity Phi 3pi1pi (Data)",nbinsang,-TMath::Pi(),TMath::Pi());
212  hHe31Phi.push_back(hHe31PhiData);
213  TH1D* hHe31PhiAPS=new TH1D("hHe31PhiAPS"+massbin,"Helicity Phi 3pi1pi (Accepted PS)",nbinsang,-TMath::Pi(),TMath::Pi());
214 
215 
216  TH1D* hHe21Data=new TH1D("hHe21ThData"+massbin,"Helicity Theta 2pi1pi (Data)",nbinsang,-1,1);
217  hHe21.push_back(hHe21Data);
218  TH1D* hHe21APS=new TH1D("hHe21ThAPS"+massbin,"Helicity Theta 2pi1pi (Accepted PS)",nbinsang,-1,1);
219 
220  TH1D* hHe21PhiData=new TH1D("hHe21PhiData"+massbin,"Helicity Phi 2pi1pi (Data)",nbinsang,-TMath::Pi(),TMath::Pi());
221  hHe21Phi.push_back(hHe21PhiData);
222  TH1D* hHe21PhiAPS=new TH1D("hHe21PhiAPS"+massbin,"Helicity Phi 2pi1pi (Accepted PS)",nbinsang,-TMath::Pi(),TMath::Pi());
223 
224  vector<TH2D*> hM1vsGJ;
225  TH2D* hM1vsGJMC=new TH2D("hM1vsGJMC"+massbin,"M1 Cos Gottfried-Jackson Theta (MC)",nbinsang/4,-1,1,nbninsm/2,0.2,3.8);
226  hM1vsGJ.push_back(hM1vsGJMC);
227  TH2D* hM1vsGJData=new TH2D("hM1vsGJData"+massbin,"M1 Cos Gottfried-Jackson Theta (Data)",nbinsang/4,-1,1,nbninsm/2,0.2,3.8);
228  hM1vsGJ.push_back(hM1vsGJData);
229 
230 
231  vector<TH1D*> hThetaLab;
232  TH1D* hThetaLabMC=new TH1D("hThetaLabMC"+massbin,"Cos Theta Lab (MC)",nbninsm,0.997,1);
233  hThetaLab.push_back(hThetaLabMC);
234  TH1D* hThetaLabData=new TH1D("hThetaLabData"+massbin,"Cos Theta Lab (Data)",nbninsm,0.997,1);
235  hThetaLab.push_back(hThetaLabData);
236  hThetaLab[0]->Sumw2();
237 
238  vector<TH2D*> hGJt;
239  TH2D* hGJtMC=new TH2D("hGJtMC"+massbin,"Cos GJ Theta vs t' (MC)",nbinsang,-1,1,20,0,0.01);
240  hGJt.push_back(hGJtMC);
241  TH2D* hGJtData=new TH2D("hGJtData"+massbin,"Cos GJ Theta vs t' (DATA)",nbinsang,-1,1,20,0,0.01); hGJt.push_back(hGJtData);
242 
243 
244 
245 
246 
247  TH1D* hGJ2Data=new TH1D("hGJ2Data"+massbin,"Cos Gottfried-Jackson Theta (DATA)",nbinsang,-1,1); hGJ2.push_back(hGJ2Data);
248  TH1D* hGJ2APS=new TH1D("hGJ2APS"+massbin,"Cos Gottfried-Jackson Theta (Accepted PS)",nbinsang,-1,1); hGJ2.push_back(hGJ2Data);
249 
250  // vector<TH1D*> hGJ3;
251  //TH1D* hGJ3MC=new TH1D("hGJ3MC"+massbin,"Cos Gottfried-Jackson Theta (MC)",nbinsang,-1,1);
252  //hGJ3.push_back(hGJ3MC);
253  //TH1D* hGJ3Data=new TH1D("hGJ3Data"+massbin,"Cos Gottfried-Jackson Theta (DATA)",nbinsang,-1,1); hGJ3.push_back(hGJ3Data);
254  //hGJ3[0]->Sumw2();
255 
256 
257  TH1D* hTYData=new TH1D("hTYData"+massbin,"Treiman-Yang Phi (DATA)",nbinsang,-TMath::Pi(),TMath::Pi());
258  hTY.push_back(hTYData);
259  TH1D* hTYAPS=new TH1D("hTYAPS"+massbin,"Treiman-Yang Phi (Accepted PS)",nbinsang,-TMath::Pi(),TMath::Pi());
260 
261 vector<TH1D*> hTY2;
262  TH1D* hTY2MC=new TH1D("hTY2MC"+massbin,"Treiman-Yang Phi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
263  TH1D* hTY2Data=new TH1D("hTY2Data"+massbin,"Treiman-Yang Phi (DATA)",nbinsang,-TMath::Pi(),TMath::Pi());
264  hTY2.push_back(hTY2MC);
265  hTY2.push_back(hTY2Data);
266 hTY2[0]->Sumw2();
267 // TH1D* hTY2APS=new TH1D("hTY2APS"+massbin,"Treiman-Yang Phi (Accepted PS)",nbinsang,-TMath::Pi(),TMath::Pi());
268 
269 vector<TH1D*> hTY3;
270  TH1D* hTY3MC=new TH1D("hTY3MC"+massbin,"Treiman-Yang Phi (MC)",nbinsang,-TMath::Pi(),TMath::Pi());
271  TH1D* hTY3Data=new TH1D("hTY3Data"+massbin,"Treiman-Yang Phi (DATA)",nbinsang,-TMath::Pi(),TMath::Pi());
272  hTY3.push_back(hTY3MC);
273  hTY3.push_back(hTY3Data);
274 hTY3[0]->Sumw2();
275 // TH1D* hTY3APS=new TH1D("hTY3APS"+massbin,"Treiman-Yang Phi (DATA)",nbinsang,-TMath::Pi(),TMath::Pi());
276 
277  double avweight=1;
278 
279 //Loop both over data and mc tree.
280  for(unsigned int itree=0;itree<2;++itree){
281  TTree* tr= itree==0 ? mctr : datatr;
282  if(tr==NULL)continue;
283 
284  double weight=1;double impweight=1;
285  double maxweight=0;
286  TClonesArray* p=new TClonesArray("TLorentzVector");
287  TLorentzVector* beam=NULL;
288  int qbeam;
289  std::vector<int>* q=NULL;
290  std::vector<double> weights(nsamples);
291  if(itree==0){
292  for(unsigned int isamples=0;isamples<nsamples;++isamples){
293  TString wname("W");wname+=isamples;
294  tr->SetBranchAddress(wname.Data(),&weights[isamples]);
295  }
296  }
297 
298  if (itree==0)tr->SetBranchAddress("weight",&weight);
299  if (itree==0)tr->SetBranchAddress("impweight",&impweight);
300  tr->SetBranchAddress("p",&p);
301  tr->SetBranchAddress("beam",&beam);
302  tr->SetBranchAddress("qbeam",&qbeam);
303  tr->SetBranchAddress("q",&q);
304 
305 
306  TVector3 vertex;
307 
308  NParticleEvent event(p,q,beam,&qbeam,&vertex);
309 
310 
311  unsigned int nevt=tr->GetEntries();
312  for(unsigned int i=0;i<nevt;++i){
313  tr->GetEntry(i);
314  if(itree==1){weight=1;impweight=1;}
315  if(weight==0)continue;
316 
317  event.refresh();
318 
319  if(impweight!=0)weight/=impweight;
320 
321  if(weight>maxweight)maxweight=weight;
322  if(itree==0)avweight+=weight;
323 
324  //double tprime=event.tprime();
325 
326  //cout << tprime << endl;
327  unsigned int npart=event.nParticles();
328  // loop over pions
329  for(unsigned int ipart=0;ipart<npart;++ipart){
330  TLorentzVector p=event.getParticle(ipart).p();
331  hThetaLab[itree]->Fill(p.CosTheta(),weight);
332  }
333 
334 
335  // transform into GJ
336  event.toGJ();
337 
338  // loop over all states that contain n-1 final state particles
339  // and plot GJ angles
340 
341  unsigned int nstates=event.nStates();
342  for(unsigned int is=0;is<nstates;++is){
343 
344  const NParticleState& state=event.getState(is);
345  if(state.n()==npart){
346 
347 
348  hM[itree]->Fill(state.p().M());
349 
350  }
351 
352  if(state.n()==npart-1 && state.q()==0){
353 
354  if(itree==0){ // mc-tree
355  hGJAPS->Fill(state.p().CosTheta());
356  hMIsobarAPS->Fill(state.p().M());
357  hTYAPS->Fill(state.p().Phi());
358  for(unsigned int isamples=0;isamples<nsamples;++isamples){
359  hGJ[isamples]->Fill(state.p().CosTheta(),weights[isamples]);
360  hTY[isamples]->Fill(state.p().Phi(),weights[isamples]);
361  hMIsobar[isamples]->Fill(state.p().M(),weights[isamples]);
362  } // end loop over sample models
363  }
364  else { // data tree
365  hGJ[nsamples+itree-1]->Fill(state.p().CosTheta(),1);
366  hMIsobar[nsamples+itree-1]->Fill(state.p().M(),1);
367  //hGJt[itree]->Fill(state.p().CosTheta(),tprime,1);
368  hTY[nsamples+itree-1]->Fill(state.p().Phi(),1);
369  //hM1vsGJ[itree]->Fill(state.p().CosTheta(),state.p().M(),weight);
370  }
371  }
372  else if(state.n()==npart-2 && state.q()==-1){
373  if(itree==0){
374  hGJ2APS->Fill(state.p().CosTheta());
375  hMIsobar2APS->Fill(state.p().M());
376  for(unsigned int isamples=0;isamples<nsamples;++isamples){
377  hGJ2[isamples]->Fill(state.p().CosTheta(),weights[isamples]);
378  hMIsobar2[isamples]->Fill(state.p().M(),weights[isamples]);
379  }
380  }
381  else {
382  hGJ2[itree+nsamples-1]->Fill(state.p().CosTheta(),1);
383  hMIsobar2[itree+nsamples-1]->Fill(state.p().M(),1);
384  }
385  }
386  else if(state.n()==npart-3 && state.q()==0){
387  if(itree==0){
388  hMIsobar3APS->Fill(state.p().M());
389  for(unsigned int isamples=0;isamples<nsamples;++isamples){
390  //hGJ3[isamples]->Fill(state.p().CosTheta(),weights[isamples]);
391  hMIsobar3[isamples]->Fill(state.p().M(),weights[isamples]);
392  }
393  }
394  else {
395  //hGJ3[isamples]->Fill(state.p().CosTheta(),1);
396  hMIsobar3[itree+nsamples-1]->Fill(state.p().M(),1);
397  }
398  }
399  } // end loop over states 1
400 
401 
402 
403  // loop again and fill helicity frame stuff
404  // for this we get rid of GJ transform
405  event.refresh(); // we do not need to build states again!
406  TLorentzVector pX=event.p();
407  // and loooooop
408  for(unsigned int is=0;is<nstates;++is){
409 
410  const NParticleState& state=event.getState(is);
411  if(state.n()==4 && state.q()==0){
412  // select sub-systems
413  // (2pi)(2pi) or (3pi)(pi)
414  for(unsigned int js=0;js<nstates;++js){
415  const NParticleState& substate=event.getState(js);
416  // (2pi)(2pi)
417  if(substate.n()==2 && substate.q()==0){
418  //cerr << "FOUND 3PISTATE" << endl;
419  if(substate.isSubstate(&state)){
420  TLorentzVector phe=event.getHelicityFrame(pX,state.p(),substate.p());
421  if(itree==0){ // mc-tree
422  hHe22APS->Fill(phe.CosTheta());
423  hHe22PhiAPS->Fill(phe.Phi());
424  for(unsigned int isamples=0;isamples<nsamples;++isamples){
425  hHe22[isamples]->Fill(phe.CosTheta(),weights[isamples]);
426  hHe22Phi[isamples]->Fill(phe.Phi(),weights[isamples]);
427  } // end loop over sample models
428  }
429  else { // data tree
430  hHe22[nsamples+itree-1]->Fill(phe.CosTheta(),1);
431  hHe22Phi[nsamples+itree-1]->Fill(phe.Phi(),1);
432  }
433  //break; // make sure we do not double-count!
434  }// end (2pi)(2pi) case
435  }
436  else if(substate.n()==3 && substate.q()==-1){
437  //cerr << "FOUND 3PISTATE" << endl;
438  if(substate.isSubstate(&state)){
439  TLorentzVector phe=event.getHelicityFrame(pX,state.p(),substate.p());
440  if(itree==0){ // mc-tree
441  hHe31APS->Fill(phe.CosTheta());
442  hHe31PhiAPS->Fill(phe.Phi());
443  for(unsigned int isamples=0;isamples<nsamples;++isamples){
444  hHe31[isamples]->Fill(phe.CosTheta(),weights[isamples]);
445  hHe31Phi[isamples]->Fill(phe.Phi(),weights[isamples]);
446  } // end loop over sample models
447  }
448  else { // data tree
449  hHe31[nsamples+itree-1]->Fill(phe.CosTheta(),1);
450  hHe31Phi[nsamples+itree-1]->Fill(phe.Phi(),1);
451  }
452  //break; // make sure we do not double-count!
453  } // end (3pi)(1pi) case
454  }
455  } // end loop over substates js
456  } // end 4pi system
457  // 3pi system
458  if(state.n()==3 && state.q()==-1){
459  // select sub-systems
460  // (2pi)(1pi)
461  for(unsigned int js=0;js<nstates;++js){
462  const NParticleState& substate=event.getState(js);
463  // (2pi)(1pi)
464  if(substate.n()==2 && substate.q()==0){
465  //cerr << "FOUND 3PISTATE" << endl;
466  if(substate.isSubstate(&state)){
467  TLorentzVector phe=event.getHelicityFrame(pX,state.p(),substate.p());
468  if(itree==0){ // mc-tree
469  hHe21APS->Fill(phe.CosTheta());
470  hHe21PhiAPS->Fill(phe.Phi());
471  for(unsigned int isamples=0;isamples<nsamples;++isamples){
472  hHe21[isamples]->Fill(phe.CosTheta(),weights[isamples]);
473  hHe21Phi[isamples]->Fill(phe.Phi(),weights[isamples]);
474  } // end loop over sample models
475  }
476  else { // data tree
477  hHe21[nsamples+itree-1]->Fill(phe.CosTheta(),1);
478  hHe21Phi[nsamples+itree-1]->Fill(phe.Phi(),1);
479  }
480  //break; // make sure we do not double-count!
481  } // end (2pi)(1pi) case
482  }
483  } // end loop over substates ij
484  } // end 3pi case
485  } // end loop over states is 2
486 
487 
488  }// end loop over events
489  if(itree==0)avweight/=(double)nevt;
490  cout << "Maxweight=" << maxweight << endl;
491  cout << "Average weight=" << avweight << endl;
492  } // loop over trees
493 
494 
495 
496 
497  TCanvas* cm=new TCanvas("PredictM"+massbin,"Weighted Events",20,20,600,800);
498  if (!cm) cout << " äh " << endl;
499  hM[0]->SetLineColor(kRed);
500  hM[0]->Draw();
501  hM[1]->Draw("same");
502 
503  TCanvas* gjt=new TCanvas("GJT"+massbin,"Events",40,40,600,800);
504  // hGJt[0]->SetLineColor(kRed);
505  hGJt[1]->Draw("COLZ");
506  //hM[1]->Draw("same");
507 
508 
509  TCanvas* c=new TCanvas("KineValidate"+massbin,"Weighted Events",10,10,600,800);
510  c->Divide(3,4);
511 
512  // plot MC predictions
513  double totMC=hMIsobar[0]->Integral();
514  double totDATA=hMIsobar[nsamples]->Integral();
515 
516  cerr << "totMC/totData = " << totMC/totDATA << endl;
517 
518  for(unsigned int isamples=0;isamples<nsamples;++isamples){
519  const char* opt= (isamples==0) ? "" : "same";
520  c->cd(1);
521 
522  double totMC=hMIsobar[isamples]->Integral();
523  double totDATA=hMIsobar[nsamples]->Integral();
524  if(totMC!=0)hMIsobar[isamples]->Scale(totDATA/totMC);
525  hMIsobar[isamples]->SetLineColor(kRed);
527  hMIsobar[isamples]->Draw(opt);
528 
529  c->cd(2);
530 
531  totMC=hMIsobar2[isamples]->Integral();
532  totDATA=hMIsobar2[nsamples]->Integral();
533  if(totMC!=0)hMIsobar2[isamples]->Scale(totDATA/totMC);
534  hMIsobar2[isamples]->SetLineColor(kRed);
535  //hMIsobar2[isamples]->SetFillColor(kRed);
536  hMIsobar2[isamples]->Draw(opt);
537 
538 
539  c->cd(3);
540  totMC=hMIsobar3[isamples]->Integral();
541  totDATA=hMIsobar3[nsamples]->Integral();
542  if(totMC!=0)hMIsobar3[isamples]->Scale(totDATA/totMC);
543  hMIsobar3[isamples]->SetLineColor(kRed);
544  //hMIsobar3[isamples]->SetFillColor(kRed);
545  hMIsobar3[isamples]->Draw(opt);
546 
547  c->cd(4);
548  totDATA=hGJ[nsamples]->Integral();
549  totMC=hGJ[isamples]->Integral();
550  if(totMC!=0)hGJ[isamples]->Scale(totDATA/totMC);
551  hGJ[isamples]->SetLineColor(kRed);
552  //hGJ[isamples]->SetFillColor(kRed);
553 hGJ[isamples]->Draw(opt);
554 
555 
556 c->cd(5);
557  totDATA=hTY[nsamples]->Integral();
558  totMC=hTY[isamples]->Integral();
559  if(totMC!=0)hTY[isamples]->Scale(totDATA/totMC);
560  hTY[isamples]->SetLineColor(kRed);
561  //hGJ[isamples]->SetFillColor(kRed);
562 hTY[isamples]->Draw(opt);
563 
564  c->cd(6);
565  totMC=hGJ2[isamples]->Integral();
566  totDATA=hGJ2[nsamples]->Integral();
567  //hGJ2[isamples]->Sumw2();
568  if(totMC!=0)hGJ2[isamples]->Scale(totDATA/totMC);
569  hGJ2[isamples]->SetLineColor(kRed);
570  hGJ2[isamples]->SetFillColor(kRed);
571  hGJ2[isamples]->Draw(opt);
572 
573 
574  c->cd(7);
575  totMC=hHe22[isamples]->Integral();
576  totDATA=hHe22[nsamples]->Integral();
577  //hGJ2[isamples]->Sumw2();
578  if(totMC!=0)hHe22[isamples]->Scale(totDATA/totMC);
579  hHe22[isamples]->SetLineColor(kRed);
580  // hHe[isamples]->SetFillColor(kRed);
581  hHe22[isamples]->Draw(opt);
582 
583  c->cd(10);
584  totMC=hHe22Phi[isamples]->Integral();
585  totDATA=hHe22Phi[nsamples]->Integral();
586  //hGJ2[isamples]->Sumw2();
587  if(totMC!=0)hHe22Phi[isamples]->Scale(totDATA/totMC);
588  hHe22Phi[isamples]->SetLineColor(kRed);
589  // hHePhi[isamples]->SetFillColor(kRed);
590  hHe22Phi[isamples]->Draw(opt);
591 
592 
593  c->cd(8);
594  totMC=hHe31[isamples]->Integral();
595  totDATA=hHe31[nsamples]->Integral();
596  //hGJ2[isamples]->Sumw2();
597  if(totMC!=0)hHe31[isamples]->Scale(totDATA/totMC);
598  hHe31[isamples]->SetLineColor(kRed);
599  // hHe[isamples]->SetFillColor(kRed);
600  hHe31[isamples]->Draw(opt);
601 
602  c->cd(11);
603  totMC=hHe31Phi[isamples]->Integral();
604  totDATA=hHe31Phi[nsamples]->Integral();
605  //hGJ2[isamples]->Sumw2();
606  if(totMC!=0)hHe31Phi[isamples]->Scale(totDATA/totMC);
607  hHe31Phi[isamples]->SetLineColor(kRed);
608  // hHePhi[isamples]->SetFillColor(kRed);
609  hHe31Phi[isamples]->Draw(opt);
610 
611  c->cd(9);
612  totMC=hHe21[isamples]->Integral();
613  totDATA=hHe21[nsamples]->Integral();
614  //hGJ2[isamples]->Sumw2();
615  if(totMC!=0)hHe21[isamples]->Scale(totDATA/totMC);
616  hHe21[isamples]->SetLineColor(kRed);
617  // hHe[isamples]->SetFillColor(kRed);
618  hHe21[isamples]->Draw(opt);
619 
620  c->cd(12);
621  totMC=hHe21Phi[isamples]->Integral();
622  totDATA=hHe21Phi[nsamples]->Integral();
623  //hGJ2[isamples]->Sumw2();
624  if(totMC!=0)hHe21Phi[isamples]->Scale(totDATA/totMC);
625  hHe21Phi[isamples]->SetLineColor(kRed);
626  // hHePhi[isamples]->SetFillColor(kRed);
627  hHe21Phi[isamples]->Draw(opt);
628 
629  }// end loopover samples
630 
631  c->cd(6);
632 
633  hGJ2[nsamples]->Draw("same E");
634  hGJ2[0]->GetYaxis()->SetRangeUser(0,hGJ2[0]->GetMaximum()*1.5);
635  gPad->Update();
636 
637  c->cd(7);
638  hHe22[nsamples]->Draw("same E");
639  hHe22[0]->GetYaxis()->SetRangeUser(0,hHe22[0]->GetMaximum()*1.5);
640  gPad->Update();
641 
642 c->cd(10);
643  hHe22Phi[nsamples]->Draw("same E");
644  hHe22Phi[0]->GetYaxis()->SetRangeUser(0,hHe22Phi[0]->GetMaximum()*1.5);
645  gPad->Update();
646 
647  c->cd(8);
648  hHe31[nsamples]->Draw("same E");
649  hHe31[0]->GetYaxis()->SetRangeUser(0,hHe31[0]->GetMaximum()*1.5);
650  gPad->Update();
651 
652 c->cd(11);
653  hHe31Phi[nsamples]->Draw("same E");
654  hHe31Phi[0]->GetYaxis()->SetRangeUser(0,hHe31Phi[0]->GetMaximum()*1.5);
655  gPad->Update();
656 
657  c->cd(9);
658  hHe21[nsamples]->Draw("same E");
659  hHe21[0]->GetYaxis()->SetRangeUser(0,hHe21[0]->GetMaximum()*1.5);
660  gPad->Update();
661 
662 c->cd(12);
663  hHe21Phi[nsamples]->Draw("same E");
664  hHe21Phi[0]->GetYaxis()->SetRangeUser(0,hHe21Phi[0]->GetMaximum()*1.5);
665  gPad->Update();
666 
667  // hM[isamples]->SetLineColor(kRed);
668 // hM[isamples]->Draw("");
669 // hM[1]->Draw("same");
670  //if(totMC!=0)hThetaLab[itree+]->Scale(totDATA/totMC);
671  //hThetaLab[0]->SetLineColor(kRed);
672  //hThetaLab[isamples]->SetMarkerColor(kRed);
673  //hThetaLab[isamples]->Draw();
674  //gPad->Update();
675 //gPad->SetLogy();
676 
677  //hThetaLab[1]->Draw("same");
678  //gPad->SetLogy();
679  //gPad->Update();
680 
681 
682 
683 // totMC=hGJ3[isamples]->Integral();
684 // totDATA=hGJ3[1]->Integral();
685 // //hGJ3[isamples]->Sumw2();
686 // hGJ3[isamples]->Scale(totDATA/totMC);
687 // hGJ3[isamples]->SetLineColor(kRed);
688 // //hGJ3[isamples]->SetFillColor(kRed);
689 // hGJ3[isamples]->Draw();
690 
691 // hGJ3[1]->Draw("same E");
692 // hGJ3[isamples]->GetYaxis()->SetRangeUser(0,hGJ3[isamples]->GetMaximum()*1.5);
693 //gPad->Update();
694 
695 
696  c->cd(7);
697  // totMC=hTY[0]->Integral();
698 // totDATA=hTY[1]->Integral();
699 // hTY[0]->Sumw2();
700 // if(totMC!=0)hTY[0]->Scale(totDATA/totMC);
701 // hTY[0]->SetLineColor(kRed);
702 // hTY[0]->SetFillColor(kRed);
703 // hTY[0]->Draw("E");
704 
705 
706 // hTY[1]->Draw("same E");
707 // hTY[0]->GetYaxis()->SetRangeUser(0,hTY[0]->GetMaximum()*1.5);
708 // gPad->Update();
709 
710 // c->cd(8);
711 // totMC=hTY2[0]->Integral();
712 // totDATA=hTY2[1]->Integral();
713 // //hTY2[0]->Sumw2();
714 // if(totMC!=0)hTY2[0]->Scale(totDATA/totMC);
715 // hTY2[0]->SetLineColor(kRed);
716 // hTY2[0]->SetFillColor(kRed);
717 // hTY2[0]->Draw("E");
718 
719 // hTY2[1]->Draw("same E");
720 // hTY2[0]->GetYaxis()->SetRangeUser(0,hTY2[0]->GetMaximum()*1.5);
721 // gPad->Update();
722 
723 
724 // c->cd(9);
725 // totMC=hTY3[0]->Integral();
726 // totDATA=hTY3[1]->Integral();
727 // //hTY3[0]->Sumw2();
728 // if(totMC!=0)hTY3[0]->Scale(totDATA/totMC);
729 // hTY3[0]->SetLineColor(kRed);
730 // hTY3[0]->SetFillColor(kRed);
731 // hTY3[0]->Draw("E");
732 
733 // hTY3[1]->Draw("same E");
734 // hTY3[0]->GetYaxis()->SetRangeUser(0,hTY3[0]->GetMaximum()*1.5);
735 // gPad->Update();
736 
737  c->cd(1);
738 
739  hDiffMIsobar=(TH1D*)hMIsobar[0]->Clone("hMIsobarDiff"+massbin);
740  hDiffMIsobar->Add(hMIsobar[nsamples],-1.);
741  hMIsobar[nsamples]->Draw("same E");
742  hDiffMIsobar->SetLineColor(kOrange-3);
743  hDiffMIsobar->Draw("same");
744 
745  hMIsobar[0]->GetYaxis()->SetRangeUser(hDiffMIsobar->GetMinimum()*1.5,hMIsobar[0]->GetMaximum()*1.2);
746 
747  TString lab=massbin;lab.ReplaceAll("_m","m=");
748  TLatex* Label=new TLatex(1.5,hMIsobar[0]->GetMaximum()*0.8,lab.Data());
749  //Label->PaintLatex(2,hMIsobar[0]->GetMaximum()*0.8,0,0.1,massbin.Data());
750  Label->Draw();
751  gPad->Update();
752 
753 
754 c->cd(2);
755  hMIsobar2[nsamples]->Draw("same E");
756  hDiffMIsobar2=(TH1D*)hMIsobar2[0]->Clone("hMIsobar2Diff"+massbin);
757  hDiffMIsobar2->Add(hMIsobar2[nsamples],-1.);
758  hDiffMIsobar2->SetLineColor(kOrange-3);
759  hDiffMIsobar2->Draw("same E");
760 
761 
762 hMIsobar2[0]->GetYaxis()->SetRangeUser(hDiffMIsobar2->GetMinimum()*1.5,hMIsobar2[0]->GetMaximum()*1.2);
763  gPad->Update();
764 
765 c->cd(3);
766 hMIsobar3[nsamples]->Draw("same E");
767  hDiffMIsobar3=(TH1D*)hMIsobar3[0]->Clone("hMIsobar3Diff"+massbin);
768  hDiffMIsobar3->Add(hMIsobar3[nsamples],-1.);
769  hDiffMIsobar3->SetLineColor(kOrange-3);
770  hDiffMIsobar3->Draw("same");
771 
772  hMIsobar3[0]->GetYaxis()->SetRangeUser(hDiffMIsobar3->GetMinimum()*1.5,hMIsobar3[0]->GetMaximum()*1.2);
773  gPad->Update();
774 
775  c->cd(4);
776  TGraphErrors* gGJ=buildGraph(hGJ,nsamples);
777  gGJ->SetLineColor(kMagenta);
778  gGJ->SetFillColor(kMagenta);
779  gGJ->Draw("same 2");
780 
781  hGJ[nsamples]->Draw("same E");
782 
783  hGJ[0]->GetYaxis()->SetRangeUser(0,hGJ[0]->GetMaximum()*1.5);
784  gPad->Update();
785 
786  c->cd(5);
787  hTY[nsamples]->Draw("same E");
788  hTY[0]->GetYaxis()->SetRangeUser(0,hTY[0]->GetMaximum()*1.5);
789  gPad->Update();
790 
791 c->Update();
792 
793  TList* Hlist=gDirectory->GetList();
794  Hlist->Remove(mctr);
795  Hlist->Remove(datatr);
796  //Hlist->Remove("hWeights");
797 
798  TFile* outfile=TFile::Open(outfilename,"UPDATE");
799  TString psFileName=outfilename;
800  psFileName.ReplaceAll(".root",massbin);
801  psFileName.Append(".ps");
802 
803 
804  if(totMC!=0){
805  // get mass-integrated plots (or create them if not there)
806  TH1D* hMIsobarMCGlob=(TH1D*)outfile->Get("hMIsobarMCGlob");
807  if(hMIsobarMCGlob==NULL)hMIsobarMCGlob=new TH1D("hMIsobarMCGlob","4#pi Isobar Mass (MC)",nbninsm,0.2,3.8);
808  hMIsobarMCGlob->Add(hMIsobar[0]);
809  hMIsobarMCGlob->Write();
810  TH1D* hMIsobarDataGlob=(TH1D*)outfile->Get("hMIsobarDataGlob");
811  if(hMIsobarDataGlob==NULL)hMIsobarDataGlob=new TH1D("hMIsobarDataGlob","4#pi Isobar mass (DATA)",nbninsm,0.2,3.8);
812  hMIsobarDataGlob->Add(hMIsobar[nsamples]);
813  hMIsobarDataGlob->Write();
814 
815 TH1D* hMIsobar2MCGlob=(TH1D*)outfile->Get("hMIsobar2MCGlob");
816  if(hMIsobar2MCGlob==NULL)hMIsobar2MCGlob=new TH1D("hMIsobar2MCGlob","3#pi Isobar mass (MC)",nbninsm,0.4,3.6);
817  hMIsobar2MCGlob->Add(hMIsobar2[0]);
818  hMIsobar2MCGlob->Write();
819 
820  TH1D* hMIsobar2DataGlob=(TH1D*)outfile->Get("hMIsobar2DataGlob");
821  if(hMIsobar2DataGlob==NULL)hMIsobar2DataGlob=new TH1D("hMIsobar2DataGlob","3#pi Isobar mass (DATA)",nbninsm,0.4,3.6);
822  hMIsobar2DataGlob->Add(hMIsobar2[nsamples]);
823  hMIsobar2DataGlob->Write();
824 
825 TH1D* hMIsobar3MCGlob=(TH1D*)outfile->Get("hMIsobar3MCGlob");
826  if(hMIsobar3MCGlob==NULL)hMIsobar3MCGlob=new TH1D("hMIsobar3MCGlob","2#pi Isobar mass (MC)",nbninsm,0.2,3.4);
827  hMIsobar3MCGlob->Add(hMIsobar3[0]);
828  hMIsobar3MCGlob->Write();
829 
830  TH1D* hMIsobar3DataGlob=(TH1D*)outfile->Get("hMIsobar3DataGlob");
831  if(hMIsobar3DataGlob==NULL)hMIsobar3DataGlob=new TH1D("hMIsobar3DataGlob","2#pi Isobar mass (DATA)",nbninsm,0.2,3.4);
832  hMIsobar3DataGlob->Add(hMIsobar3[nsamples]);
833  hMIsobar3DataGlob->Write();
834 
835 
836  TH1D* hGJMCGlob=(TH1D*)outfile->Get("hGJMCGlob");
837  if(hGJMCGlob==NULL)hGJMCGlob=new TH1D("hGJMCGlob","Gottfried-Jackson Theta (MC)",nbinsang,-1,1);
838  hGJMCGlob->Add(hGJ[0]);
839  hGJMCGlob->Write();
840 
841 TH1D* hGJDataGlob=(TH1D*)outfile->Get("hGJDataGlob");
842  if(hGJDataGlob==NULL)hGJDataGlob=new TH1D("hGJDataGlob","Gottfried-Jackson Theta (Data)",nbinsang,-1,1);
843  hGJDataGlob->Add(hGJ[nsamples]);
844  hGJDataGlob->Write();
845 
846 TH1D* hGJ2MCGlob=(TH1D*)outfile->Get("hGJ2MCGlob");
847  if(hGJ2MCGlob==NULL)hGJ2MCGlob=new TH1D("hGJ2MCGlob","Gottfried-Jackson Theta (MC)",nbinsang,-1,1);
848  hGJ2MCGlob->Add(hGJ2[0]);
849  hGJ2MCGlob->Write();
850 
851 TH1D* hGJ2DataGlob=(TH1D*)outfile->Get("hGJ2DataGlob");
852  if(hGJ2DataGlob==NULL)hGJ2DataGlob=new TH1D("hGJ2DataGlob","Gottfried-Jackson Theta (Data)",nbinsang,-1,1);
853  hGJ2DataGlob->Add(hGJ2[nsamples]);
854  hGJ2DataGlob->Write();
855 
856 
857  // c->cd(13);
858  // hMIsobarMCGlob->SetLineColor(kRed);
859  // hMIsobarMCGlob->SetFillColor(kRed);
860  // hMIsobarMCGlob->Draw("E");
861  // hMIsobarDataGlob->Draw("E SAME");
862 
863  // c->cd(14);
864  // hMIsobar2MCGlob->SetLineColor(kRed);
865  // hMIsobar2MCGlob->SetFillColor(kRed);
866  // hMIsobar2MCGlob->Draw("E");
867  // hMIsobar2DataGlob->Draw("E SAME");
868 
869 
870  // c->cd(15);
871  // hGJMCGlob->SetLineColor(kRed);
872  // hGJMCGlob->SetFillColor(kRed);
873  // hGJMCGlob->GetYaxis()->SetRangeUser(0,hGJMCGlob->GetMaximum()*1.5);
874  // hGJMCGlob->Draw("E");
875  // hGJDataGlob->Draw("E SAME");
876 
877  // c->cd(10);
878  // hM1vsGJMC->Scale(totDATA/totMC);
879  // hM1vsGJMC->Draw("COLZ");
880 
881  // c->cd(11);
882  // hM1vsGJData->Draw("COLZ");
883 
884  // c->cd(12);
885  // TH2D* hDiff=new TH2D(*hM1vsGJ[0]);
886  // hDiff->Divide(hM1vsGJMC,hM1vsGJData,1,1);
887  // hDiff->Draw("COLZ");
888  // hDiff->GetZaxis()->SetRangeUser(0.7,1.3);
889 
890  }
891 
892  c->Write();
893  TCanvas dummyCanv("dummy", "dummy");
894  c->Print((psFileName));
895 
896  int nobj=Hlist->GetEntries();
897  std::cout<<"Found "<<nobj<<" Objects in HList"<<std::endl;
898  Hlist->Print();
899  Hlist->Write();
900  outfile->Close();
901 
902  gjt->Update();
903 
904  gROOT->cd();
905 
906 
907  }
908 
909 //If I'm not wrong this script should compile for root even with a main in it
910 // that will be simply ignored
911 int main(int argc, char** argv){
912 
913  if (argc != 5){
914  cout << " not enough arguments! " << endl;
915  return 1;
916  }
917 
918  TString evtfile(argv[1]);
919  TString mcfile(argv[2]);
920  TString outfile(argv[3]);
921  TString mass(argv[4]);
922 
923  TFile* file1=TFile::Open(evtfile,"READ");
924  TFile* file2=TFile::Open(mcfile,"READ");
925  TTree* data=(TTree*)file1->Get("events");
926  TTree* mc=(TTree*)file2->Get("pwevents");
927 
928  plotWeightedEvts(mc,data,outfile,mass);
929 
930  file1->Close();
931  file2->Close();
932 }