ROOTPWA
plotWeightedEvts_3pin.C
Go to the documentation of this file.
1 /*
2  * IMPORTANT:
3  *
4  * The naming scheme of histogram files is critical in this program.
5  * More complex diagrams, that are automatically generated, rely on the specific scheme defined below.
6  * The program requests names for the Monte Carlo histograms to contain "MC_"
7  * or end with "MC". (the reason for _ is that the string doesnt no accidentally contain another "MC")
8  * The Data histograms must have the same filename as the corresponding MC histogram but "Data" replaced for "MC".
9  *
10  * Also for each massbin create a directory and create the same filenames for each variable
11  */
12 
13 #include "TTree.h"
14 #include "TFile.h"
15 #include "TList.h"
16 #include "TLatex.h"
17 
18 #include "TLorentzVector.h"
19 #include "TVector3.h"
20 #include "TLorentzRotation.h"
21 #include "TH1D.h"
22 #include "TH2D.h"
23 #include "TClonesArray.h"
24 #include "TROOT.h"
25 #include "TMath.h"
26 #include "TPad.h"
27 #include "TCanvas.h"
28 #include "TString.h"
29 #include <iostream>
30 #include <vector>
31 #include "NParticleEvent.h"
32 #include "TPRegexp.h"
33 
34 using namespace std;
35 
36 TString massbin;
37 TString mass;
38 
39 int nbninsm = 144;
40 int nbinsang = 80;
41 
42 
43 
44 struct GJHistBunch {
45  // base histograms
46  std::vector<TH1D*> isobar_mass;
47  std::vector<TH1D*> costheta_GJF;
48  std::vector<TH1D*> phi_GJF;
50  std::vector<TH2D*> costheta_GJF_tprime;
51 
52  // difference histograms
55  TH1D* phi_GJF_diff;
57 };
58 
60  // base histograms
61  std::vector<TH1D*> costheta_HF;
62  std::vector<TH1D*> phi_HF;
63 
64  // difference histograms
66  TH1D* phi_HF_diff;
67 };
68 
70  double cosTheta;
71  double phi;
72 };
73 
74 int getTotalCharge(std::pair<int, int> p) {
75  return p.first + p.second;
76 }
77 
78 TString stripUnits(TString s) {
79  //std::cout<<"stripunits-in: "<<s<<std::endl;
80  TPRegexp re("^(.*)\\s*(\\[.*])\\s*$");
81  re.Substitute(s,"$1");
82  //std::cout<<"stripunits-out: "<<s<<std::endl;
83  return s;
84 }
85 
86 TString getUnits(TString s) {
87  //std::cout << "getunits-in: " << s << std::endl;
88  TPRegexp re("^.*(\\[.*])\\s*$");
89  if(re.MatchB(s) > 0)
90  re.Substitute(s,"$1");
91  else
92  s = "";
93  //std::cout << "getunits-out: " << s << std::endl;
94  return s;
95 }
96 
97 GJHistBunch GJHistBunchFactory(TString name_prefix) {
98  GJHistBunch temp;
99  TH1D* hMIsobarMC = new TH1D("hMIsobarMC_" + name_prefix, name_prefix + " Isobar Mass (MC)", nbninsm, 0.0, 1.5);
100  hMIsobarMC->SetXTitle("isobar mass [GeV]");
101  hMIsobarMC->SetYTitle("# of events");
102  temp.isobar_mass.push_back(hMIsobarMC);
103  TH1D* hMIsobarData = new TH1D("hMIsobarData_" + name_prefix, name_prefix + " Isobar Mass (DATA)", nbninsm,
104  0.0, 1.5);
105  hMIsobarData->SetXTitle("isobar mass [GeV]");
106  hMIsobarData->SetYTitle("# of events");
107  temp.isobar_mass.push_back(hMIsobarData);
108  temp.isobar_mass[0]->Sumw2();
109 
110  TH1D* hGJMC = new TH1D("hGJMC_" + name_prefix, name_prefix + " Isobar Cos Gottfried-Jackson Theta (MC)", nbinsang, -1, 1);
111  hGJMC->SetXTitle("isobar cos(#theta_{GJ})");
112  hGJMC->SetYTitle("# of events");
113  temp.costheta_GJF.push_back(hGJMC);
114  TH1D* hGJData = new TH1D("hGJData_" + name_prefix, name_prefix + " Isobar Cos Gottfried-Jackson Theta (DATA)", nbinsang, -1,
115  1);
116  hGJData->SetXTitle("isobar cos(#theta_{GJ})");
117  hGJData->SetYTitle("# of events");
118  temp.costheta_GJF.push_back(hGJData);
119  temp.costheta_GJF[0]->Sumw2();
120 
121  temp.costheta_GJF_MC_raw = new TH1D("hGJMC_raw" + name_prefix,
122  "Cos Gottfried-Jackson Theta (unweighted MC)", nbinsang, -1, 1);
123  temp.costheta_GJF_MC_raw->SetXTitle("isobar cos(#theta_{GJ})");
124  temp.costheta_GJF_MC_raw->SetYTitle("# of events");
125 
126  TH2D* hGJtMC = new TH2D("hGJtMC_" + name_prefix, name_prefix + " Isobar Cos GJ Theta vs t' (MC)", nbinsang, -1, 1, 20, 0,
127  0.01);
128  hGJtMC->SetXTitle("isobar cos(#theta_{GJ})");
129  hGJtMC->SetYTitle("t' [GeV]");
130  temp.costheta_GJF_tprime.push_back(hGJtMC);
131  TH2D* hGJtData = new TH2D("hGJtData_" + name_prefix, name_prefix + " Isobar Cos GJ Theta vs t' (DATA)", nbinsang, -1, 1, 20,
132  0, 0.01);
133  hGJData->SetXTitle("isobar cos(#theta_{GJ})");
134  hGJData->SetYTitle("t' [GeV]");
135  temp.costheta_GJF_tprime.push_back(hGJtData);
136 
137  TH1D* hTYMC = new TH1D("hTYMC_" + name_prefix, name_prefix + " Isobar Treiman-Yang Phi (MC)", nbinsang, -TMath::Pi(),
138  TMath::Pi());
139  hTYMC->SetXTitle("isobar #phi_{TY} [rad]");
140  hTYMC->SetYTitle("# of events");
141  TH1D* hTYData = new TH1D("hTYData_" + name_prefix, name_prefix + " Isobar Treiman-Yang Phi (DATA)", nbinsang, -TMath::Pi(),
142  TMath::Pi());
143  hTYData->SetXTitle("isobar #phi_{TY} [rad]");
144  hTYData->SetYTitle("# of events");
145  temp.phi_GJF.push_back(hTYMC);
146  temp.phi_GJF.push_back(hTYData);
147  temp.phi_GJF[0]->Sumw2();
148 
149  return temp;
150 }
151 
153  HelicityHistBunch temp;
154  TH1D* hHThetaMC = new TH1D("hHThetaMC_" + name_prefix, name_prefix + " Isobar Helicity Cos Theta (MC)", nbinsang, -1, 1);
155  hHThetaMC->SetXTitle("cos(#theta_{hel} of #pi^{0} from isobar)");
156  hHThetaMC->SetYTitle("# of events");
157  temp.costheta_HF.push_back(hHThetaMC);
158  TH1D* hHThetaData = new TH1D("hHThetaData_" + name_prefix, name_prefix + " Isobar Helicity Cos Theta (DATA)", nbinsang, -1,
159  1);
160  hHThetaData->SetXTitle("cos(#theta_{hel}) of #pi^{0} from isobar");
161  hHThetaData->SetYTitle("# of events");
162  temp.costheta_HF.push_back(hHThetaData);
163  temp.costheta_HF[0]->Sumw2();
164 
165  TH1D* hHPhiMC = new TH1D("hHPhiMC_" + name_prefix, name_prefix + " Isobar Helicity Phi (MC)", nbinsang, -TMath::Pi(),
166  TMath::Pi());
167  hHPhiMC->SetXTitle("#phi_{hel} [rad] of #pi^{0} from isobar");
168  hHPhiMC->SetYTitle("# of events");
169  TH1D* hHPhiData = new TH1D("hHPhiData_" + name_prefix, name_prefix + " Isobar Helicity Phi (DATA)", nbinsang, -TMath::Pi(),
170  TMath::Pi());
171  hHPhiData->SetXTitle("#phi_{hel} [rad] of #pi^{0} from isobar");
172  hHPhiData->SetYTitle("# of events");
173  temp.phi_HF.push_back(hHPhiMC);
174  temp.phi_HF.push_back(hHPhiData);
175  temp.phi_HF[0]->Sumw2();
176 
177  return temp;
178 }
179 
180 void fillWeightedHelicityAnglePlots(const HelicityAngles &ha, double weight, unsigned int tree_index, HelicityHistBunch &hhb) {
181  hhb.costheta_HF[tree_index]->Fill(ha.cosTheta, weight);
182  hhb.phi_HF[tree_index]->Fill(ha.phi, weight);
183 }
184 
185 void fillWeightedGJAnglePlots(const TLorentzVector &isobar, double weight, double tprime, unsigned int tree_index, GJHistBunch &hBunch) {
186  hBunch.costheta_GJF[tree_index]->Fill(isobar.CosTheta(), weight);
187  if (tree_index == 0)
188  hBunch.costheta_GJF_MC_raw->Fill(isobar.CosTheta());
189  hBunch.costheta_GJF_tprime[tree_index]->Fill(isobar.CosTheta(), tprime, weight);
190  hBunch.phi_GJF[tree_index]->Fill(isobar.Phi(), weight);
191  hBunch.isobar_mass[tree_index]->Fill(isobar.M(), weight);
192 }
193 
194 HelicityAngles calculateHelicityAngles(const NParticleState &isobar, TLorentzVector *beam = NULL) {
195  HelicityAngles temp;
196 
197  TVector3 zaxis_gjf;
198  if(beam != NULL) {
199  zaxis_gjf = beam->Vect().Unit();
200  }
201  else {
202  zaxis_gjf = TVector3(0,0,1);
203  }
204  // create helicity frame coordinate system
205  TVector3 zaxis = isobar.p().Vect().Unit();
206  TVector3 yaxis = zaxis_gjf.Cross(zaxis).Unit();
207  TVector3 xaxis = yaxis.Cross(zaxis);
208 
209  // boost NParticleState into isobar rest frame
210  TLorentzVector particle;
211  if(isobar.getParticle(0)->q() == 0)
212  particle = isobar.getParticle(0)->p();
213  else
214  particle = isobar.getParticle(1)->p();
215  const TVector3 boost_vec = isobar.p().BoostVector();
216  particle.Boost(-boost_vec);
217  // theta
218  double theta = zaxis.Angle(particle.Vect());
219  temp.cosTheta = TMath::Cos(theta);
220  double fX = xaxis.Dot(particle.Vect());
221  double fY = yaxis.Dot(particle.Vect());
222  if(fX == 0.0 && fY == 0.0)
223  temp.phi = 0.0;
224  else
225  temp.phi = TMath::ATan2(fY,fX);
226 
227  return temp;
228 }
229 
230 
231 void makeDifferencePlots(TFile *outfile) {
232  outfile->cd();
233  TList *dirlist = outfile->GetListOfKeys();
234  TIter diriter(dirlist);
235  TDirectory *dir;
236 
237  std::cout << "scanning directories and creating diff histograms..." << std::endl;
238  while ((dir = (TDirectory *) diriter())) {
239  std::string dirname = dir->GetName();
240  // check if directory is mass bin dir
241  unsigned int pointpos = dirname.find(".");
242  if (pointpos == 0 || pointpos == dirname.size())
243  continue;
244 
245  outfile->cd(dir->GetName());
246 
247  // make list of MC Histograms
248  TList mclist;
249  TList *histlist = gDirectory->GetListOfKeys();
250  TIter histiter(histlist);
251  TObject *obj;
252  while ((obj = histiter())) {
253  TString s(obj->GetName());
254  if (s.EndsWith("MC"))
255  mclist.Add(obj);
256  else if (s.Contains("MC_"))
257  mclist.Add(obj);
258  }
259  histiter = TIter(&mclist);
260  TH1D *diffhist, *reldiffhist, *mchist, *datahist;
261  double scale;
262  while ((mchist = (TH1D*) histiter())) {
263  // generate difference histograms
264  std::string hnamemc(mchist->GetName());
265  int pos = hnamemc.find("MC");
266  // create new string with MC exchanged for Diff
267  std::string hnamediff(hnamemc);
268  hnamediff.erase(pos, 2);
269  hnamediff.insert(pos, "Diff");
270  // create new string with MC exchanged for RelDiff
271  std::string hnamereldiff(hnamemc);
272  hnamereldiff.erase(pos, 2);
273  hnamereldiff.insert(pos, "RelDiff");
274  // create new string with MC exchanged for Data
275  std::string hnamedata(hnamemc);
276  hnamedata.erase(pos, 2);
277  hnamedata.insert(pos, "Data");
278 
279  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamediff).c_str(), diffhist);
280  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamereldiff).c_str(), reldiffhist);
281  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamedata).c_str(), datahist);
282  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamemc).c_str(), mchist);
283  if (!diffhist) {
284  if (datahist) {
285  outfile->cd(dir->GetName());
286  scale = datahist->Integral();
287  scale = scale / (mchist->Integral());
288  mchist->Scale(scale);
289 
290  diffhist = new TH1D(*mchist);
291  diffhist->SetName(hnamediff.c_str());
292  diffhist->SetTitle("");
293  diffhist->Add(datahist, -1.);
294  diffhist->SetYTitle("# of events difference(MC-Data)");
295  diffhist->Write();
296 
297  reldiffhist = new TH1D(*diffhist);
298  reldiffhist->SetName(hnamereldiff.c_str());
299  reldiffhist->Divide(datahist);
300  reldiffhist->SetYTitle("relative difference((MC-Data)/Data)");
301  reldiffhist->Write();
302  }
303  }
304  }
305 
306  histiter = TIter(&mclist);
307  TH2D *diffhist2d, *reldiffhist2d, *mchist2d, *datahist2d;
308  scale = 1.0;
309  while ((mchist2d = (TH2D*) histiter())) {
310  // generate difference histograms
311  std::string hnamemc(mchist2d->GetName());
312  int pos = hnamemc.find("MC");
313  // create new string with MC exchanged for Diff
314  std::string hnamediff(hnamemc);
315  hnamediff.erase(pos, 2);
316  hnamediff.insert(pos, "Diff");
317  // create new string with MC exchanged for RelDiff
318  std::string hnamereldiff(hnamemc);
319  hnamereldiff.erase(pos, 2);
320  hnamereldiff.insert(pos, "RelDiff");
321  // create new string with MC exchanged for Data
322  std::string hnamedata(hnamemc);
323  hnamedata.erase(pos, 2);
324  hnamedata.insert(pos, "Data");
325 
326  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamediff).c_str(), diffhist2d);
327  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamereldiff).c_str(), reldiffhist2d);
328  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamedata).c_str(), datahist2d);
329  outfile->GetObject((std::string(dir->GetName()) + "/" + hnamemc).c_str(), mchist2d);
330  if (!diffhist2d) {
331  if (datahist2d) {
332  outfile->cd(dir->GetName());
333  scale = datahist2d->Integral();
334  scale = scale / (mchist2d->Integral());
335  mchist2d->Scale(scale);
336 
337  diffhist2d = new TH2D(*mchist2d);
338  diffhist2d->SetName(hnamediff.c_str());
339  diffhist2d->SetTitle("diff(MC-Data)");
340  diffhist2d->Add(datahist2d, -1.);
341  double max = diffhist2d->GetMaximum();
342  if(max < TMath::Abs(diffhist2d->GetMinimum()))
343  max = TMath::Abs(diffhist2d->GetMinimum());
344  diffhist2d->SetMaximum(max);
345  diffhist2d->SetMinimum(-max);
346  diffhist2d->Write();
347 
348  reldiffhist2d = new TH2D(*diffhist2d);
349  reldiffhist2d->SetName(hnamereldiff.c_str());
350  reldiffhist2d->SetTitle("rel. diff((MC-Data)/Data)");
351  reldiffhist2d->Divide(datahist2d);
352  reldiffhist2d->SetMaximum();
353  reldiffhist2d->SetMinimum();
354  max = reldiffhist2d->GetMaximum();
355  if (max < TMath::Abs(reldiffhist2d->GetMinimum()))
356  max = TMath::Abs(reldiffhist2d->GetMinimum());
357  reldiffhist2d->SetMaximum(max);
358  reldiffhist2d->SetMinimum(-max);
359  reldiffhist2d->Write();
360  }
361  }
362  }
363  }
364 }
365 
366 TH2D* createDalitzHistogram(TString name, TString title, double mass, unsigned int treeentries) {
367  double rangelow = 0.0;
368  double rangehigh = pow(mass-0.1, 2);
369  unsigned int nbins = 0;
370  nbins = 0.6*TMath::Sqrt(treeentries)*(rangehigh-rangelow);
371  std::cout<<"nbins for mass "<<mass<<": "<<nbins<<std::endl;
372  // lower bound is 20 bins
373  if(nbins < 20) nbins = 20;
374  // upper bound is 130 bins
375  if(nbins > 130) nbins = 130;
376  TH2D* phist = new TH2D(name, title, nbins, rangelow, rangehigh, nbins, rangelow, rangehigh);
377  return phist;
378 }
379 
380 
381 void plotWeightedEvts_3pin(TTree* mctr, TTree* datatr, TString outfilename = "kineplots.root",
382  TString mass_ = "000") {
383  double massval = 0.0;
384  unsigned int datatreeentries = 0;
385  mass = mass_;
386  if (mass != "000") {
387  massbin = ("_m") + mass;
388  massbin.ReplaceAll(" ", "");
389  }
390 
391  std::string binname(mass.Data());
392  unsigned int pointpos = binname.find(".");
393  if(pointpos == 0 || pointpos == binname.size())
394  std::cout<<"Warning: Bad massbin name!"<<std::endl;
395  std::string masshigh = binname.substr(pointpos+1);
396  massval = atof(masshigh.c_str());
397  massval /=1000;
398  datatreeentries = datatr->GetEntries();
399 
400 
401  gROOT->SetStyle("Plain");
402  TFile* outfile = TFile::Open(outfilename, "UPDATE");
403  outfile->cd();
404  gDirectory->cd();
405  if (!gDirectory->GetDirectory(mass)) {
406  gDirectory->mkdir(mass);
407  }
408  gDirectory->cd(mass);
409 
410  // --------------- global diagrams
411  std::vector<TH1D*> hM;
412  TH1D* hMMC = new TH1D("hResMassMC", "Mass (MC)", 60, 0.5, 2.5);
413  hM.push_back(hMMC);
414  TH1D* hMData = new TH1D("hResMassData", "Mass (DATA)", 60, 0.5, 2.5);
415  hM.push_back(hMData);
416 
417  vector<TH1D*> hThetaLab;
418  TH1D* hThetaLabMC = new TH1D("hThetaLabMC", "Cos Theta Lab (MC)", nbninsm, 0.997, 1);
419  hThetaLab.push_back(hThetaLabMC);
420  TH1D* hThetaLabData = new TH1D("hThetaLabData", "Cos Theta Lab (Data)", nbninsm, 0.997, 1);
421  hThetaLab.push_back(hThetaLabData);
422  hThetaLab[0]->Sumw2();
423 
424  // Dalitz plots
425  std::vector<TH2D*> dalitz_neutral;
426  TH2D* dalitz = createDalitzHistogram("hDalitzMC",
427  "Dalitz Plot #pi^{0}#pi^{0} vs. #pi^{-}#pi^{0} (MC)", massval, datatreeentries);
428  dalitz->SetXTitle("mass^{2}(#pi^{0}#pi^{0}) [GeV^{2}/c^{4}]");
429  dalitz->SetYTitle("mass^{2}(#pi^{-}#pi^{0}) [GeV^{2}/c^{4}]");
430  dalitz->SetStats(0);
431  dalitz_neutral.push_back(dalitz);
432  dalitz = createDalitzHistogram("hDalitzData",
433  "Dalitz Plot #pi^{0}#pi^{0} vs. #pi^{-}#pi^{0} (Data)", massval, datatreeentries);
434  dalitz->SetXTitle("mass^{2}(#pi^{0}#pi^{0}) [GeV^{2}/c^{4}]");
435  dalitz->SetYTitle("mass^{2}(#pi^{-}#pi^{0}) [GeV^{2}/c^{4}]");
436  dalitz->SetStats(0);
437  dalitz_neutral.push_back(dalitz);
438  /*std::vector<TH2D*> dalitz_charged;
439  dalitz = new TH2D("hDalitzChargedMC", "Dalitz Plot #pi^{-}#pi^{0} vs. #pi^{-}#pi^{0} (MC)", nbninsm, 0.0,
440  2.2, nbninsm, 0.0, 2.2);
441  dalitz_charged.push_back(dalitz);
442  dalitz = new TH2D("hDalitzChargedData", "Dalitz Plot #pi^{-}#pi^{0} vs. #pi^{-}#pi^{0} (Data)", nbninsm,
443  0.0, 2.2, nbninsm, 0.0, 2.2);
444  dalitz_charged.push_back(dalitz);*/
445 
446  // --------------- generate histogram bunches
447  // neutral isobar
448  // GJ Histogram Bunch
449  GJHistBunch GJHB_neutral_isobar = GJHistBunchFactory("Neutral");
450  // Helicity Histogram Bunch
451  HelicityHistBunch HHB_neutral_isobar = HelicityHistBunchFactory("Neutral");
452 
453  // charged isobar
454  // GJ Histogram Bunch MC
455  GJHistBunch GJHB_charged_isobar = GJHistBunchFactory("Charged");
456  // Helicity Histogram Bunch
457  HelicityHistBunch HHB_charged_isobar = HelicityHistBunchFactory("Charged");
458 
459  double avweight = 1;
460 
461  /*TH1D* hCosTheta[2] = {new TH1D("hCosThetaMC", "Cos Theta (Data)", nbninsm, -1, 1), new TH1D("hCosThetaData", "Cos Theta (MC)", nbninsm, -1, 1) };
462  TH1D* foohTY[2] = {new TH1D("foohTYMC_", " Isobar Treiman-Yang Phi (MC)", nbinsang, -TMath::Pi(),
463  TMath::Pi()), new TH1D("foohTYData_", " Isobar Treiman-Yang Phi (DATA)", nbinsang, -TMath::Pi(),
464  TMath::Pi()) };
465  hCosTheta[0]->Sumw2();
466  foohTY[0]->Sumw2();
467 
468  TH1D* hhCosTheta[2] = {new TH1D("hhCosThetaMC", "Cos Theta (Data)", nbninsm, -1, 1), new TH1D("hhCosThetaData", "Cos Theta (MC)", nbninsm, -1, 1) };
469  TH1D* hfoohTY[2] = {new TH1D("hfoohTYMC_", " Isobar Treiman-Yang Phi (MC)", nbinsang, -TMath::Pi(),
470  TMath::Pi()), new TH1D("hfoohTYData_", " Isobar Treiman-Yang Phi (DATA)", nbinsang, -TMath::Pi(),
471  TMath::Pi()) };
472  hhCosTheta[0]->Sumw2();
473  hfoohTY[0]->Sumw2();*/
474 
475  //Loop both over data and mc tree
476  // itree = 0: mc tree
477  // itree = 1: data tree
478  for (unsigned int itree = 0; itree < 2; ++itree) {
479  TTree* tr = (itree == 0) ? mctr : datatr;
480  if (tr == NULL)
481  continue;
482 
483  double weight = 1;
484  double impweight = 1;
485  double maxweight = 0;
486  TClonesArray* p = new TClonesArray("TLorentzVector");
487  TLorentzVector* beam = NULL;
488  int qbeam;
489  std::vector<int>* q = NULL;
490  if (itree == 0)
491  tr->SetBranchAddress("weight", &weight);
492  if (itree == 0)
493  tr->SetBranchAddress("impweight", &impweight);
494  tr->SetBranchAddress("p", &p);
495  tr->SetBranchAddress("beam", &beam);
496  tr->SetBranchAddress("qbeam", &qbeam);
497  tr->SetBranchAddress("q", &q);
498 
499  TVector3 vertex;
500 
501  NParticleEvent event(p, q, beam, &qbeam, &vertex);
502 
503  // loop over tree entries
504  unsigned int nevt = tr->GetEntries();
505  for (unsigned int i = 0; i < nevt; ++i) {
506  tr->GetEntry(i);
507  // in case its data tree (itree=1) put weights to 1
508  if (itree == 1) {
509  weight = 1;
510  impweight = 1;
511  }
512  if (weight == 0)
513  continue;
514 
515  // this builds all subsystems
516  event.refresh();
517 
518  if (impweight != 0)
519  weight /= impweight;
520 
521  if (weight > maxweight)
522  maxweight = weight;
523  if (itree == 0)
524  avweight += weight;
525 
526  double tprime = event.tprime();
527  //cout << tprime << endl;
528  unsigned int npart = event.nParticles();
529  // loop over pions
530  for (unsigned int ipart = 0; ipart < npart; ++ipart) {
531  TLorentzVector p = event.getParticle(ipart).p();
532  hThetaLab[itree]->Fill(p.CosTheta(), weight);
533  }
534 
535  // ----dalitz plots
536  // make all combinations
537  std::vector<std::pair<std::pair<int, int>, double> > comb;
538  for(unsigned int i=0; i < npart; i++) {
539  for(unsigned int j=0; j < i; j++) {
540  TLorentzVector lv = event.getParticle(i).p() + event.getParticle(j).p();
541  double mass2 = lv.M2();
542  std::pair<int, int> charge(event.getParticle(i).q(), event.getParticle(j).q());
543  std::pair<std::pair<int, int>, double> temp;
544  temp = make_pair(charge, mass2);
545  comb.push_back(temp);
546  }
547  }
548 
549  // now fill corresponding dalitz plots
550  // this part is pi-pi0pi0 specific
551 
552  // put pi0 pi0 combination to front of vector to make combination picks easier later on
553  for(unsigned int i = 0; i < comb.size(); i++) {
554  if(getTotalCharge(comb[i].first) == 0) {
555  if(i == 0) break;
556  else {
557  std::pair<std::pair<int, int>, double> temp = comb[0];
558  comb[0] = comb[i];
559  comb[i] = temp;
560  break;
561  }
562  }
563  }
564  // now actually fill the histograms
565  dalitz_neutral[itree]->Fill(comb[0].second, comb[1].second, weight);
566  //dalitz_charged[itree]->Fill(comb[1].second, comb[2].second, weight);
567 
568  /* unsigned int index = 0;
569  TLorentzVector fsParticles[3];
570  TLorentzVector beam = *event.beam();
571  TLorentzVector X(0, 0, 0, 0);
572  for (unsigned int is = 0; is < 3; ++is) {
573  if (event.getParticle(is).q() == -1)
574  index = is;
575  fsParticles[is] = event.getParticle(is).p();
576  X += fsParticles[is];
577  }
578  TVector3 xboost = X.BoostVector();
579  for (unsigned int is = 0; is < 3; ++is) {
580  fsParticles[is].Boost(-xboost);
581  }
582  beam.Boost(-xboost);
583  TVector3 zaxis = beam.Vect().Unit();
584  TVector3 yaxis = beam.Vect().Cross(X.Vect()).Unit();
585  TVector3 xaxis = yaxis.Cross(zaxis);
586 
587  double phi = 0.0;
588  double theta = zaxis.Angle(fsParticles[index].Vect());
589  double cosTheta = TMath::Cos(theta);
590  double fX = xaxis.Dot(fsParticles[index].Vect());
591  double fY = yaxis.Dot(fsParticles[index].Vect());
592  if (!(fX == 0.0 && fY == 0.0))
593  phi = TMath::ATan2(fY, fX);
594 
595  hCosTheta[itree]->Fill(cosTheta, weight);
596  foohTY[itree]->Fill(phi, weight);
597 
598  TLorentzVector isobar(0, 0, 0, 0);
599  unsigned int hindex = 0;
600  for (unsigned int is = 0; is < 3; ++is) {
601  if (is == index)
602  continue;
603  isobar += fsParticles[is];
604  hindex = is;
605  }
606 
607  // create helicity frame coordinate system
608  TVector3 hzaxis = isobar.Vect().Unit();
609  TVector3 hyaxis = zaxis.Cross(hzaxis).Unit();
610  TVector3 hxaxis = hyaxis.Cross(hzaxis);
611 
612  // boost NParticleState into isobar rest frame
613  const TVector3 hboost = isobar.BoostVector();
614  fsParticles[hindex].Boost(-hboost);
615  // theta
616  double htheta = hzaxis.Angle(fsParticles[hindex].Vect());
617  double hcosTheta = TMath::Cos(htheta);
618  double hfX = hxaxis.Dot(fsParticles[hindex].Vect());
619  double hfY = hyaxis.Dot(fsParticles[hindex].Vect());
620  double hphi = 0.0;
621  if (!(hfX == 0.0 && hfY == 0.0))
622  hphi = TMath::ATan2(hfY, hfX);
623 
624  hhCosTheta[itree]->Fill(hcosTheta, weight);
625  hfoohTY[itree]->Fill(hphi, weight);*/
626 
627  // transform into GJ
628  event.toGJ();
629  // build again to get particles in GJF
630  event.build();
631 
632  /*TLorentzVector temp(0,0,0,0);
633  //cout<<"number of particles in event: "<<event.nParticles()<<endl;
634  for (unsigned int is = 0; is < 3; ++is) {
635  temp += event.getParticle(is).p();
636  }
637  temp.Dump();*/
638 
639  // loop over all states that contain n-1 final state particles
640  // and plot angles
641  unsigned int nstates = event.nStates();
642  //cout<<"number of substates: "<<event.nStates()<<endl;
643  for (unsigned int is = 0; is < nstates; ++is) {
644 
645  const NParticleState& state = event.getState(is);
646  if (state.n() == npart) {
647  hM[itree]->Fill(state.p().M());
648  }
649  if (state.n() == npart - 1 && state.q() == 0) {
650  // this is a neutral isobar state with n-1 (here 2) final state particles
651  fillWeightedGJAnglePlots(state.p(), weight, tprime, itree, GJHB_neutral_isobar);
652  fillWeightedHelicityAnglePlots(calculateHelicityAngles(state), weight, itree, HHB_neutral_isobar);
653  }
654  else if (state.n() == npart - 1 && state.q() == -1) {
655  // this is a negativly charged isobar state with n-1 (here 2) final state particles
656  fillWeightedGJAnglePlots(state.p(), weight, tprime, itree, GJHB_charged_isobar);
657  fillWeightedHelicityAnglePlots(calculateHelicityAngles(state), weight, itree, HHB_charged_isobar);
658  }
659  }
660 
661  }// end loop over events
662  if (itree == 0)
663  avweight /= (double) nevt;
664  cout << "Maxweight=" << maxweight << endl;
665  cout << "Average weight=" << avweight << endl;
666  }// end loop over trees
667 
668  outfile->Write();
669  makeDifferencePlots(outfile);
670 
671  TList* Hlist = gDirectory->GetList();
672  Hlist->Remove(mctr);
673  Hlist->Remove(datatr);
674  //Hlist->Remove("hWeights");
675  int nobj = Hlist->GetEntries();
676  std::cout << "Found " << nobj << " Objects in HList" << std::endl;
677 
678  outfile->Close();
679 
680  gROOT->cd();
681 
682 }