FairRoot/PandaRoot
PndPmtPoormantracks.cxx
Go to the documentation of this file.
1 
2 #include "TMath.h"
3 #include "TRandom3.h"
4 #include "TDatabasePDG.h"
5 //#include "FairRootManager.h"
6 //#include "FairRunAna.h"
7 //#include "FairRuntimeDb.h"
8 
9 #include "RhoCandidate.h"
10 #include "RhoCalculationTools.h"
11 
12 #include <string>
13 #include <iostream>
14 
15 #include "PndPmtPoormantracks.h"
16 
17 
18 using std::cout;
19 using std::flush;
20 using std::endl;
21 
22 
24 {
25  fSigVx=0.005; //[cm]
26  fSigVy=0.005; //[cm]
27  fSigVz=0.005; //[cm]
28  fSigPx=0.01; //[GeV/c]
29  fSigPy=0.01; //[GeV/c]
30  fSigPz=0.01; //[GeV/c]
31  fPtMin=0.9;//[GeV/c]
32  fPtMax=1.1;//[GeV/c]
33  fCharge=1.;
34  fDtheta = 1.; //0.3 [pi]
35  fPID=211;// 211 pion, 22 muon, 2212 proton, 321 kaon
36  fPDG = 0;
37  fNumTrk=2;
38  fSeed=936650;//
39  fVerbose=0;
40  fMcCands = new TClonesArray("RhoCandidate");
41  fCands = new TClonesArray("RhoCandidate");
42 }
43 
45 {
46 }
47 
48 
49 
50 
51 TVector3 PndPmtPoormantracks::RollVertexBox(double widx,double widy, double widz)
52 {
53  double rnd1=widx*2*(0.5-gRandom->Rndm());
54  double rnd2=widy*2*(0.5-gRandom->Rndm());
55  double rnd3=widz*2*(0.5-gRandom->Rndm());
56  TVector3 vertex(rnd1,rnd2,rnd3);
57  if(fVerbose>2) cout<<"RollVertexBox: ("<<vertex.x()<<","<<vertex.y()<<","<<vertex.z()<<")"<<endl;
58  return vertex;
59 }
60 
61 void PndPmtPoormantracks::SmearVertex(TVector3& vertex)
62 {
63  double rnd1=gRandom->Gaus(vertex.x(),fSigVx);
64  double rnd2=gRandom->Gaus(vertex.y(),fSigVy);
65  double rnd3=gRandom->Gaus(vertex.z(),fSigVz);
66  if(fVerbose>2) cout<<"SmearVertex (B): ("<<vertex.x()<<","<<vertex.y()<<","<<vertex.z()<<")"<<endl;
67  vertex.SetXYZ(rnd1,rnd2,rnd3);
68  if(fVerbose>2) cout<<"SmearVertex (A): ("<<vertex.x()<<","<<vertex.y()<<","<<vertex.z()<<")"<<endl;
69  return;
70 }
71 
72 TVector3 PndPmtPoormantracks::RollMomentumBox(const TVector3& vtx, double dtheta, double ptmin, double ptmax)
73 {
74  // allow whole phi range
75  double phi=TMath::TwoPi()*gRandom->Rndm();
76  // allow theta at vertex pointing theta +- dtheta
77  double theta = vtx.Theta() + dtheta*2*(0.5-gRandom->Rndm());
78  // allow transverse momentum in [ptmin,ptmax]
79  double pt = ptmin + (ptmax-ptmin)*gRandom->Rndm();
80  TVector3 momentum;
81  momentum.SetPtThetaPhi(pt,theta,phi);
82  if(fVerbose>2) cout<<"RollMomentumBox: ("<<momentum.x()<<","<<momentum.y()<<","<<momentum.z()<<")"<<endl;
83  return momentum;
84 }
85 
86 void PndPmtPoormantracks::SmearMomentum(TVector3& momentum)
87 {
88  double rnd1=gRandom->Gaus(momentum.Px(),fSigPx);
89  double rnd2=gRandom->Gaus(momentum.Py(),fSigPy);
90  double rnd3=gRandom->Gaus(momentum.Pz(),fSigPz);
91  momentum.SetXYZ(rnd1,rnd2,rnd3);
92  return;
93 }
94 
95 void PndPmtPoormantracks::PoorManTracks()//TVector3& vtx=fVertex
96 {
97  if(fVerbose>1) cout<<" --------------------------------------------------- "<<endl;
98  if(fVerbose>0) cout<<"Poor man tracks."<<endl;
99  fMcCands->Clear("C");
100  fCands->Clear("C");
101 
102  RhoError covPos(3), covP4(4);
103  covPos[0][0]=fSigVx*fSigVx;
104  covPos[1][1]=fSigVy*fSigVy;
105  covPos[2][2]=fSigVz*fSigVz;
106  covP4[0][0]=fSigPx*fSigPx;
107  covP4[1][1]=fSigPy*fSigPy;
108  covP4[2][2]=fSigPz*fSigPz;
109 
110  for (int iTr=0; iTr<fNumTrk; iTr++)
111  {
112  fPDG = TDatabasePDG::Instance()->GetParticle(fPID);
113  TVector3 momentum = RollMomentumBox(fVertex,fDtheta*TMath::Pi(),fPtMin,fPtMax);
114 
115  int sizeMc = fMcCands->GetEntriesFast();
116  RhoCandidate *pmc=new ((*fMcCands)[sizeMc]) RhoCandidate(momentum,fPDG);
117  pmc->SetPos(fVertex);
118 
119  // Smeared "reco"
120  int size = fCands->GetEntriesFast();
121  TVector3 vertexMeasure = fVertex;
122  SmearVertex(vertexMeasure);
123  TVector3 momMeasure = momentum;
124  SmearMomentum(momMeasure);
125 
126 
127  RhoCandidate *p=new ((*fCands)[size]) RhoCandidate(momMeasure,fPDG);//TODO charge
128  p->SetMcTruth(pmc);
129  p->SetPos(vertexMeasure);
130  EnergyCorrelations(covP4,p->P4());
131  p->SetCov7(covPos,covP4);
132 
133  if(fVerbose>1) cout<<" ---------\n pmc, p, pmcpos, ppos, fVertex"<<endl;
134  if(fVerbose>1) std::cout<<*pmc<<std::endl;
135  if(fVerbose>1) std::cout<<*p<<std::endl;
136  if(fVerbose>1) p->P3Cov().Print();
137  if(fVerbose>1) pmc->GetPosition().Print();
138  if(fVerbose>1) p->GetPosition().Print();
139  if(fVerbose>1) fVertex.Print();
140  // print helix parameters and cov together with RhoCandidate V-P4 and cov7
141 
142  // alternate particle type
143  fCharge*=-1;
144  fPID*=-1;
145  }
146 }
147 void PndPmtPoormantracks::EnergyCorrelations(RhoError& covP4, TLorentzVector p4)
148 {
149  double invE=1/p4.E();
150  covP4[3][3] = (p4.X()*p4.X()*covP4[0][0]+p4.Y()*p4.Y()*covP4[1][1]+p4.Z()*p4.Z()*covP4[2][2])*invE*invE;
151  covP4[0][3] = covP4[3][0] = p4.X()*covP4[0][0]*invE;
152  covP4[1][3] = covP4[3][1] = p4.Y()*covP4[1][1]*invE;
153  covP4[2][3] = covP4[3][2] = p4.Z()*covP4[2][2]*invE;
154 // covP4[0][3] = covP4[3][0] = (p4.X()*covP4[0][0]+p4.Y()*covP4[0][1]+p4.Z()*covP4[0][2])*invE;
155 // covP4[1][3] = covP4[3][1] = (p4.X()*covP4[1][0]+p4.Y()*covP4[1][1]+p4.Z()*covP4[1][2])*invE;
156 // covP4[2][3] = covP4[3][2] = (p4.X()*covP4[2][0]+p4.Y()*covP4[2][1]+p4.Z()*covP4[2][2])*invE;
157 
158 }
159 
160 
161 
162 
163 
164 
165 
166 
Double_t p
Definition: anasim.C:58
TVector3 RollMomentumBox(const TVector3 &vtx, double dtheta, double ptmin, double ptmax)
RhoError P3Cov() const
void SetPos(const TVector3 &pos)
Definition: RhoCandidate.h:235
void SmearVertex(TVector3 &vertex)
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
TVector3 GetPosition() const
Definition: RhoCandidate.h:185
void SmearMomentum(TVector3 &momentum)
double dtheta
Definition: anaLmdCluster.C:54
TLorentzVector P4() const
Definition: RhoCandidate.h:195
void SetMcTruth(RhoCandidate *mct)
Definition: RhoCandidate.h:436
static float TwoPi()
Definition: PndCAMath.h:61
Double_t Pi
void SetCov7(const TMatrixD &cov7)
TVector3 RollVertexBox(double widx, double widy, double widz)