ROOTPWA
plotEvts.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 "TF1.h"
12 #include "TRandom3.h"
13 #include "TClonesArray.h"
14 #include "TROOT.h"
15 #include "TMath.h"
16 #include "TPad.h"
17 #include "TCanvas.h"
18 #include "TString.h"
19 #include <iostream>
20 #include <vector>
21 #include "NParticleEvent.h"
22 
23 
24 using namespace std;
25 
26 
27 void plotEvts(TTree* datatr, TString outfilename="kineplots.root", TString mass="000"){
28 
29 gROOT->SetStyle("Plain");
30 
31  TString massbin;
32  if(mass!="000"){
33  massbin=("_m")+mass;massbin.ReplaceAll(" ","");
34  }
35 
36 
37 
38  TTree* tr= datatr;
39  double impweight=1;
40  TClonesArray* p=new TClonesArray("TLorentzVector");
41  TLorentzVector* beam=NULL;
42  int qbeam;
43  std::vector<int>* q=NULL;
44  //if (itree==0)tr->SetBranchAddress("weight",&weight);
45  //if (itree==0)tr->SetBranchAddress("impweight",&impweight);
46  tr->SetBranchAddress("p",&p);
47  tr->SetBranchAddress("beam",&beam);
48  tr->SetBranchAddress("qbeam",&qbeam);
49  tr->SetBranchAddress("q",&q);
50 
51  TVector3 vertex;
52  NParticleEvent event(p,q,beam,&qbeam,&vertex);
53 
54  TF1* acc=new TF1("acc","1-exp([0]*(1-x))",0,2000); // artificial acceptance function
55 
56  TH1D* hMass=new TH1D("hmass","Mass",1000,0,20);
57 
58  TH1D* hGJ=new TH1D("hGJ","Cos GJ-Theta",20,-1,1);
59  TH1D* hGJacc=new TH1D("hGJacc","acc Cos GJ-Theta",20,-1,1);
60 
61  TH1D* hExcl=new TH1D("hExcl","Charged Exclusivity",100,0,200);
62  TH1D* hT=new TH1D("hT","Charged t",1000,0,2);
63 
64  TH1D* hMom=new TH1D("hMOM","events",50,0,50);
65  TH1D* hMombad=new TH1D("hMOMbad","events",50,0,50);
66 
67  TH2D* hPbad=new TH2D("hPbad","bad events",40,0,0.05,50,0,160);
68  TH2D* hP=new TH2D("hP","events",40,0,0.05,50,0,160);
69  TH2D* hPXYbad=new TH2D("hPXYbad","bad events",50,-0.05,0.05,50,-0.05,0.05);
70  TH2D* hPXY=new TH2D("hPXY","events",50,-0.05,0.05,50,-0.05,0.05);
71 
72  acc->SetParameter(0,0.2);
73 
74  unsigned int nevt=tr->GetEntries();
75  for(unsigned int i=0;i<nevt;++i){
76  tr->GetEntry(i);
77 
78  event.refresh();
79 
80  hMass->Fill(event.p().M());
81 
82  if(1){
83  TLorentzVector xcharged;
84  // save momenta
85  vector<TLorentzVector> momenta;
86  bool accept=true;
87  for(unsigned int ip=0;ip<event.nParticles();++ip){
88  if(event.getParticle(ip).q()==0)continue; // only look at charged particles
89  momenta.push_back(event.getParticle(ip).p());
90  xcharged += momenta[ip];
91  double mag=momenta[ip].Vect().Mag();
92  hMom->Fill(mag);
93  hP->Fill(momenta[ip].Vect().Theta(),
94  momenta[ip].Vect().Mag());
95  hPXY->Fill(momenta[ip].Vect().X()/mag,
96  momenta[ip].Vect().Y()/mag);
97  // cut away events with small momentum particles:
98  //double w=acc->Eval(mag);
99  //accept &= gRandom->Uniform()<w;
100 
101  } // end loop over particles
102 
103  hExcl->Fill(xcharged.E());
104 
105 
106  event.toGJ();
107 
108  // loop over all states that contain n-1 final state particles
109  // and plot GJ angles
110  unsigned int npart=event.nParticles();
111  unsigned int nstates=event.nStates();
112  for(unsigned int is=0;is<nstates;++is){
113  const NParticleState& state=event.getState(is);
114  if(state.qabs()==5 && state.n()==5){
115  double t=state.t();
116  double m=state.p().M();
117  double p2=state.beam().Vect()*state.beam().Vect();
118  double term=m*m-0.019479835;
119  double tmin=term*term*0.25/p2;
120  //cout << "t="<<t<<" tmin= " << tmin << endl;
121  double tprime=t-tmin;
122  hT->Fill(tprime);
123  }
124 
125  if(state.n()==npart){
126 
127 
128 
129 
130  }
131 
132  if(state.n()==npart-1 && state.q()==0){
133  // cut out a bit of the CosGJ distribution
134  hGJ->Fill(state.p().CosTheta());
135  //double w=acc->Eval(state.p().CosTheta());
136  //acc &= gRandom->Uniform()<w;
137 
138 
139  if(accept){
140  hGJacc->Fill(state.p().CosTheta());
141  }
142  else {
143  for(unsigned int ip=0;ip<event.nParticles();++ip){
144  double mag=momenta[ip].Vect().Mag();
145  hMombad->Fill(mag);
146  hPbad->Fill(momenta[ip].Vect().Theta(),
147  momenta[ip].Vect().Mag());
148  hPXYbad->Fill(momenta[ip].Vect().X()/mag,
149  momenta[ip].Vect().Y()/mag);
150  } // end loop over particles
151 
152  }
153 
154  }
155  else if(state.n()==npart-2 && state.q()==-1){
156 
157  }
158  else if(state.n()==npart-3 && state.q()==0){
159 
160  }
161  }
162  } // end if(0)
163 
164 
165  }// end loop over events
166 
167 
168 
169 
170 
171 
172  TCanvas* c=new TCanvas("KineValidate"+massbin,"Events",10,10,1000,800);
173  c->Divide(3,3);
174  c->cd(1);
175  hExcl->Draw();
176  c->cd(3);
177  hT->Draw();
178 
179  c->cd(2);
180  hP->Draw("colz");
181 
182 
183 
184  c->cd(4);
185  hMass->Draw();
186 
187  c->cd(5);
188 hGJ->Draw();
189  hGJ->GetYaxis()->SetRangeUser(0,hGJ->GetMaximum()*1.5);
190  hGJacc->SetLineColor(kBlue);
191  hGJacc->SetFillColor(kBlue);
192 
193  hGJacc->Draw("same");
194 
195  //hPXYbad->Draw("surf2");
196 c->cd(6);
197  hPXY->Draw("surf2");
198 
199  c->cd(7);
200  hMombad->Draw();
201 c->cd(8);
202  hMom->Draw();
203 
204  TCanvas* cm=new TCanvas("cm","Mass",10,10,1000,800);
205  hMass->Draw();
206  TF1* mparm=new TF1("fm","(x-[0])*exp((x-[0])*([1]+(x-[0])*[2]))",0.9,3.);
207  hMass->Fit(mparm,"","",0.9,3);
208 
209 }