18 #include "TLorentzVector.h"
20 #include "TLorentzRotation.h"
23 #include "TClonesArray.h"
46 std::vector<TH1D*> isobar_mass;
47 std::vector<TH1D*> costheta_GJF;
48 std::vector<TH1D*> phi_GJF;
49 TH1D* costheta_GJF_MC_raw;
50 std::vector<TH2D*> costheta_GJF_tprime;
53 TH1D* isobar_mass_diff;
54 TH1D* costheta_GJF_diff;
56 TH2D* costheta_GJF_tprime_diff;
61 std::vector<TH1D*> costheta_HF;
62 std::vector<TH1D*> phi_HF;
65 TH1D* costheta_HF_diff;
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, 3.0);
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 negative particle 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 negative particle 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 negative particle 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 negative particle 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 cout <<
" running histo creator " << endl;
384 double massval = 0.0;
385 unsigned int datatreeentries = 0;
392 std::string binname(
mass.Data());
393 unsigned int pointpos = binname.find(
".");
394 if(pointpos == 0 || pointpos == binname.size())
395 std::cout<<
"Warning: Bad massbin name!"<<std::endl;
396 std::string masshigh = binname.substr(pointpos+1);
397 massval = atof(masshigh.c_str());
399 datatreeentries = datatr->GetEntries();
402 gROOT->SetStyle(
"Plain");
403 TFile* outfile = TFile::Open(outfilename,
"UPDATE");
406 if (!gDirectory->GetDirectory(
mass)) {
407 gDirectory->mkdir(
mass);
409 gDirectory->cd(
mass);
412 std::vector<TH1D*> hM;
413 TH1D* hMMC =
new TH1D(
"hResMassMC",
"Mass (MC)", 60, 0.5, 2.5);
415 TH1D* hMData =
new TH1D(
"hResMassData",
"Mass (DATA)", 60, 0.5, 2.5);
416 hM.push_back(hMData);
418 vector<TH1D*> hThetaLab;
419 TH1D* hThetaLabMC =
new TH1D(
"hThetaLabMC",
"Cos Theta Lab (MC)",
nbninsm, 0.997, 1);
420 hThetaLab.push_back(hThetaLabMC);
421 TH1D* hThetaLabData =
new TH1D(
"hThetaLabData",
"Cos Theta Lab (Data)",
nbninsm, 0.997, 1);
422 hThetaLab.push_back(hThetaLabData);
423 hThetaLab[0]->Sumw2();
426 std::vector<TH2D*> dalitz_neutral;
440 "Dalitz Plot K^{-}#pi^{+} vs. #pi^{-}#pi^{+} (MC)", massval, datatreeentries);
441 dalitz->SetXTitle(
"mass^{2}(#pi^{-}#pi^{+}) [GeV^{2}/c^{4}]");
442 dalitz->SetYTitle(
"mass^{2}(K^{-}#pi^{+}) [GeV^{2}/c^{4}]");
444 dalitz_neutral.push_back(dalitz);
446 "Dalitz Plot K^{-}#pi^{+} vs. #pi^{-}#pi^{+} (MC)", massval, datatreeentries);
447 dalitz->SetXTitle(
"mass^{2}(#pi^{-}#pi^{+}) [GeV^{2}/c^{4}]");
448 dalitz->SetYTitle(
"mass^{2}(K^{-}#pi^{+}) [GeV^{2}/c^{4}]");
450 dalitz_neutral.push_back(dalitz);
491 for (
unsigned int itree = 0; itree < 2; ++itree) {
492 TTree* tr = (itree == 0) ? mctr : datatr;
497 double impweight = 1;
498 double maxweight = 0;
499 TClonesArray*
p =
new TClonesArray(
"TLorentzVector");
500 TLorentzVector* beam = NULL;
502 std::vector<int>*
q = NULL;
504 tr->SetBranchAddress(
"weight", &weight);
506 tr->SetBranchAddress(
"impweight", &impweight);
507 tr->SetBranchAddress(
"p", &p);
508 tr->SetBranchAddress(
"beam", &beam);
509 tr->SetBranchAddress(
"qbeam", &qbeam);
510 tr->SetBranchAddress(
"q", &q);
518 unsigned int nevt = tr->GetEntries();
519 for (
unsigned int i = 0;
i < nevt-1; ++
i) {
539 if (weight > maxweight)
544 double tprime =
event.tprime();
546 unsigned int npart =
event.nParticles();
548 for (
unsigned int ipart = 0; ipart < npart; ++ipart) {
549 TLorentzVector p =
event.getParticle(ipart).p();
550 hThetaLab[itree]->Fill(p.CosTheta(), weight);
555 std::vector<std::pair<std::pair<int, int>,
double> > comb;
556 for(
unsigned int i=0;
i < npart;
i++) {
557 for(
unsigned int j=0; j <
i; j++) {
558 TLorentzVector lv =
event.getParticle(i).p() +
event.getParticle(j).p();
559 double mass2 = lv.M2();
560 std::pair<int, int> charge(event.
getParticle(i).
q(),
event.getParticle(j).q());
561 std::pair<std::pair<int, int>,
double> temp;
562 temp = make_pair(charge, mass2);
563 comb.push_back(temp);
591 for(
unsigned int i = 0;
i < comb.size();
i++) {
593 if(comb[
i].first.first < 0 && comb[
i].first.second < 0) {
596 std::pair<std::pair<float, float>,
double> temp = comb[2];
603 if (fabs(comb[1].first.first)+fabs(comb[1].first.second) > fabs(comb[0].first.first)+fabs(comb[0].first.second)){
604 std::pair<std::pair<float, float>,
double> temp = comb[0];
609 dalitz_neutral[itree]->Fill(comb[1].second, comb[0].second, weight);
684 unsigned int nstates =
event.nStates();
686 for (
unsigned int is = 0; is < nstates; ++is) {
689 if (state.
n() == npart) {
690 hM[itree]->Fill(state.
p().M());
693 if (state.
n() == 2 && state.
q() == 0){
695 if (fabs(sum_mass-0.633) < 0.010) {
701 if (fabs(sum_mass-0.279) < 0.010) {
712 avweight /= (double) nevt;
713 cout <<
"Maxweight=" << maxweight << endl;
714 cout <<
"Average weight=" << avweight << endl;
720 TList* Hlist = gDirectory->GetList();
722 Hlist->Remove(datatr);
724 int nobj = Hlist->GetEntries();
725 std::cout <<
"Found " << nobj <<
" Objects in HList" << std::endl;