18 #include "TLorentzVector.h"
20 #include "TLorentzRotation.h"
23 #include "TClonesArray.h"
75 return p.first + p.second;
80 TPRegexp re(
"^(.*)\\s*(\\[.*])\\s*$");
81 re.Substitute(s,
"$1");
88 TPRegexp re(
"^.*(\\[.*])\\s*$");
90 re.Substitute(s,
"$1");
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");
103 TH1D* hMIsobarData =
new TH1D(
"hMIsobarData_" + name_prefix, name_prefix +
" Isobar Mass (DATA)",
nbninsm,
105 hMIsobarData->SetXTitle(
"isobar mass [GeV]");
106 hMIsobarData->SetYTitle(
"# of events");
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");
114 TH1D* hGJData =
new TH1D(
"hGJData_" + name_prefix, name_prefix +
" Isobar Cos Gottfried-Jackson Theta (DATA)",
nbinsang, -1,
116 hGJData->SetXTitle(
"isobar cos(#theta_{GJ})");
117 hGJData->SetYTitle(
"# of events");
122 "Cos Gottfried-Jackson Theta (unweighted MC)",
nbinsang, -1, 1);
126 TH2D* hGJtMC =
new TH2D(
"hGJtMC_" + name_prefix, name_prefix +
" Isobar Cos GJ Theta vs t' (MC)",
nbinsang, -1, 1, 20, 0,
128 hGJtMC->SetXTitle(
"isobar cos(#theta_{GJ})");
129 hGJtMC->SetYTitle(
"t' [GeV]");
131 TH2D* hGJtData =
new TH2D(
"hGJtData_" + name_prefix, name_prefix +
" Isobar Cos GJ Theta vs t' (DATA)",
nbinsang, -1, 1, 20,
133 hGJData->SetXTitle(
"isobar cos(#theta_{GJ})");
134 hGJData->SetYTitle(
"t' [GeV]");
137 TH1D* hTYMC =
new TH1D(
"hTYMC_" + name_prefix, name_prefix +
" Isobar Treiman-Yang Phi (MC)",
nbinsang, -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(),
143 hTYData->SetXTitle(
"isobar #phi_{TY} [rad]");
144 hTYData->SetYTitle(
"# of events");
146 temp.
phi_GJF.push_back(hTYData);
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");
158 TH1D* hHThetaData =
new TH1D(
"hHThetaData_" + name_prefix, name_prefix +
" Isobar Helicity Cos Theta (DATA)",
nbinsang, -1,
160 hHThetaData->SetXTitle(
"cos(#theta_{hel}) of #pi^{0} from isobar");
161 hHThetaData->SetYTitle(
"# of events");
165 TH1D* hHPhiMC =
new TH1D(
"hHPhiMC_" + name_prefix, name_prefix +
" Isobar Helicity Phi (MC)",
nbinsang, -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(),
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);
182 hhb.
phi_HF[tree_index]->Fill(ha.
phi, weight);
186 hBunch.
costheta_GJF[tree_index]->Fill(isobar.CosTheta(), weight);
190 hBunch.
phi_GJF[tree_index]->Fill(isobar.Phi(), weight);
191 hBunch.
isobar_mass[tree_index]->Fill(isobar.M(), weight);
199 zaxis_gjf = beam->Vect().Unit();
202 zaxis_gjf = TVector3(0,0,1);
205 TVector3 zaxis = isobar.
p().Vect().Unit();
206 TVector3 yaxis = zaxis_gjf.Cross(zaxis).Unit();
207 TVector3 xaxis = yaxis.Cross(zaxis);
215 const TVector3 boost_vec = isobar.
p().BoostVector();
216 particle.Boost(-boost_vec);
218 double theta = zaxis.Angle(particle.Vect());
220 double fX = xaxis.Dot(particle.Vect());
221 double fY = yaxis.Dot(particle.Vect());
222 if(fX == 0.0 && fY == 0.0)
225 temp.
phi = TMath::ATan2(fY,fX);
233 TList *dirlist = outfile->GetListOfKeys();
234 TIter diriter(dirlist);
237 std::cout <<
"scanning directories and creating diff histograms..." << std::endl;
238 while ((dir = (TDirectory *) diriter())) {
239 std::string dirname = dir->GetName();
241 unsigned int pointpos = dirname.find(
".");
242 if (pointpos == 0 || pointpos == dirname.size())
245 outfile->cd(dir->GetName());
249 TList *histlist = gDirectory->GetListOfKeys();
250 TIter histiter(histlist);
252 while ((obj = histiter())) {
253 TString s(obj->GetName());
254 if (s.EndsWith(
"MC"))
256 else if (s.Contains(
"MC_"))
259 histiter = TIter(&mclist);
260 TH1D *diffhist, *reldiffhist, *mchist, *datahist;
262 while ((mchist = (TH1D*) histiter())) {
264 std::string hnamemc(mchist->GetName());
265 int pos = hnamemc.find(
"MC");
267 std::string hnamediff(hnamemc);
268 hnamediff.erase(pos, 2);
269 hnamediff.insert(pos,
"Diff");
271 std::string hnamereldiff(hnamemc);
272 hnamereldiff.erase(pos, 2);
273 hnamereldiff.insert(pos,
"RelDiff");
275 std::string hnamedata(hnamemc);
276 hnamedata.erase(pos, 2);
277 hnamedata.insert(pos,
"Data");
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);
285 outfile->cd(dir->GetName());
286 scale = datahist->Integral();
287 scale = scale / (mchist->Integral());
288 mchist->Scale(scale);
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)");
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();
306 histiter = TIter(&mclist);
307 TH2D *diffhist2d, *reldiffhist2d, *mchist2d, *datahist2d;
309 while ((mchist2d = (TH2D*) histiter())) {
311 std::string hnamemc(mchist2d->GetName());
312 int pos = hnamemc.find(
"MC");
314 std::string hnamediff(hnamemc);
315 hnamediff.erase(pos, 2);
316 hnamediff.insert(pos,
"Diff");
318 std::string hnamereldiff(hnamemc);
319 hnamereldiff.erase(pos, 2);
320 hnamereldiff.insert(pos,
"RelDiff");
322 std::string hnamedata(hnamemc);
323 hnamedata.erase(pos, 2);
324 hnamedata.insert(pos,
"Data");
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);
332 outfile->cd(dir->GetName());
333 scale = datahist2d->Integral();
334 scale = scale / (mchist2d->Integral());
335 mchist2d->Scale(scale);
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);
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();
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;
373 if(nbins < 20) nbins = 20;
375 if(nbins > 130) nbins = 130;
376 TH2D* phist =
new TH2D(name, title, nbins, rangelow, rangehigh, nbins, rangelow, rangehigh);
382 TString mass_ =
"000") {
383 double massval = 0.0;
384 unsigned int datatreeentries = 0;
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());
398 datatreeentries = datatr->GetEntries();
401 gROOT->SetStyle(
"Plain");
402 TFile* outfile = TFile::Open(outfilename,
"UPDATE");
405 if (!gDirectory->GetDirectory(
mass)) {
406 gDirectory->mkdir(
mass);
408 gDirectory->cd(
mass);
411 std::vector<TH1D*> hM;
412 TH1D* hMMC =
new TH1D(
"hResMassMC",
"Mass (MC)", 60, 0.5, 2.5);
414 TH1D* hMData =
new TH1D(
"hResMassData",
"Mass (DATA)", 60, 0.5, 2.5);
415 hM.push_back(hMData);
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();
425 std::vector<TH2D*> dalitz_neutral;
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}]");
431 dalitz_neutral.push_back(dalitz);
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}]");
437 dalitz_neutral.push_back(dalitz);
478 for (
unsigned int itree = 0; itree < 2; ++itree) {
479 TTree* tr = (itree == 0) ? mctr : datatr;
484 double impweight = 1;
485 double maxweight = 0;
486 TClonesArray*
p =
new TClonesArray(
"TLorentzVector");
487 TLorentzVector* beam = NULL;
489 std::vector<int>*
q = NULL;
491 tr->SetBranchAddress(
"weight", &weight);
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);
504 unsigned int nevt = tr->GetEntries();
505 for (
unsigned int i = 0;
i < nevt; ++
i) {
521 if (weight > maxweight)
526 double tprime =
event.tprime();
528 unsigned int npart =
event.nParticles();
530 for (
unsigned int ipart = 0; ipart < npart; ++ipart) {
531 TLorentzVector p =
event.getParticle(ipart).p();
532 hThetaLab[itree]->Fill(p.CosTheta(), weight);
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);
553 for(
unsigned int i = 0;
i < comb.size();
i++) {
557 std::pair<std::pair<int, int>,
double> temp = comb[0];
565 dalitz_neutral[itree]->Fill(comb[0].second, comb[1].second, weight);
641 unsigned int nstates =
event.nStates();
643 for (
unsigned int is = 0; is < nstates; ++is) {
646 if (state.
n() == npart) {
647 hM[itree]->Fill(state.
p().M());
649 if (state.
n() == npart - 1 && state.
q() == 0) {
654 else if (state.
n() == npart - 1 && state.
q() == -1) {
663 avweight /= (double) nevt;
664 cout <<
"Maxweight=" << maxweight << endl;
665 cout <<
"Average weight=" << avweight << endl;
671 TList* Hlist = gDirectory->GetList();
673 Hlist->Remove(datatr);
675 int nobj = Hlist->GetEntries();
676 std::cout <<
"Found " << nobj <<
" Objects in HList" << std::endl;