StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPeCGeant.cxx
1 //
3 // Revision 1.0 2000/12/18 yepes
4 //
6 #include <Stiostream.h>
7 #include <math.h>
8 #include "StPeCGeant.h"
9 #include "tables/St_g2t_track_Table.h"
10 #include "tables/St_g2t_vertex_Table.h"
11 #include "StMuDSTMaker/COMMON/StMuDst.h"
12 #include "StMuDSTMaker/COMMON/StMuEvent.h"
13 #include "StMuDSTMaker/COMMON/StMuTrack.h"
14 #include "StMuDSTMaker/COMMON/StMuMcTrack.h"
15 #include "StMuDSTMaker/COMMON/StMuMcVertex.h"
16 
17 
18 ClassImp(StPeCGeant)
19 
21  pPart = new TClonesArray ("StPeCParticle", 10);
22  nPart = 0 ;
23 }
24 
25 StPeCGeant::~StPeCGeant() {
26  delete pPart ;
27 }
28 
29 void StPeCGeant::clear() {
30  nPart = 0 ;
31  gPt = 0 ;
32  gPz = 0 ;
33  gEta = 0 ;
34  gMass = 0 ;
35  gY = 0 ;
36  gPsi = 0 ;
37  gZVertex = 0 ;
38 
39  pPart->Clear();
40 }
41 
42 Int_t StPeCGeant::fill ( TDataSet* geant ) {
43 //
44 // fill our local Track class
45 //
46  St_g2t_track* trk = 0 ;
47  trk = (St_g2t_track *)geant->Find("g2t_track") ;
48 
49 // TDataSet* jaja ;
50 // Bool_t a = 1 ;
51 // TDataSetIter tI(jaja,a);
52 // St_g2t_track *g2t_trackTablePointer = (St_g2t_track *) geantDstI("g2t_track");
53 // geantDstI("g2t_tpc_hit");
54 
55 
56  if ( !trk ) {
57  printf ( "StPeCGeant::fill: tracks not found \n" ) ;
58  return 1 ;
59  }
60 
61  int nTracks = trk->GetNRows() ;
62 
63  g2t_track_st* trkT = trk->GetTable() ;
64 
65 
66  float px = 0 ;
67  float py = 0 ;
68  gPz = 0 ;
69  float e = 0 ;
70  nPart = 0 ;
71  TClonesArray &pParticle = *pPart ;
72 
73  int vert ;
74  printf ( "StPeCGeant::fill: %i tracks found \n", nTracks ) ;
75 
76  for ( int i = 0 ; i < nTracks ; i++ ) {
77  new(pParticle[nPart++]) StPeCParticle(&(trkT[i])) ;
78 
79  vert = trkT[i].start_vertex_p ;
80  if ( vert != 1 ) continue ;
81  px += trkT[i].p[0];
82  py += trkT[i].p[1];
83  gPz += trkT[i].p[2];
84  e += trkT[i].e ;
85  }
86 
87  gPt = ::sqrt(px*px+py*py);
88  gPsi = atan2(py,px);
89  if ( gPsi < 0 ) gPsi += M_PI ;
90  gMass = ::sqrt(e*e-gPt*gPt-gPz*gPz);
91 
92  float theta = atan2(gPt,gPz);
93  gEta = -::log(tan(theta/2.)) ;
94  gY = 0.5*::log((e+gPz)/(e-gPz));
95 
96  St_g2t_vertex* vtx = 0 ;
97  vtx = (St_g2t_vertex *)geant->Find("g2t_vertex") ;
98  if ( !vtx ) {
99  printf ( "StPeCGeant::fill: vertex not found \n" ) ;
100  return 1 ;
101  }
102  g2t_vertex_st* vtxT = vtx->GetTable() ;
103 
104  gZVertex = vtxT->ge_x[2] ;
105 
106  return 0 ;
107 }
108 
109 Int_t StPeCGeant::fill ( StMuDst * mu ) {
110 //
111 // fill McEvent class to access StMuMcTracks
112 //
113  StMuEvent* muEvent = mu->event(); // get a pointer to the class holding event-wise information
114  LOG_INFO << "StPeCGeant::fill: using MuDst ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- " << endm;
115  if ( !muEvent ) {
116  printf ( "StPeCGeant::fill: MC event not found \n" ) ;
117  return 1 ;
118  }
119 
120  TClonesArray *MuMcTracks = mu->mcArray(1);
121  TClonesArray *MuMcVertices = mu->mcArray(0);
122 
123  int nTracks = MuMcTracks->GetEntriesFast();
124  LOG_INFO << "StPeCGeant::fill: "<<nTracks<<" tracks found "<<endm;
125 
126  float px = 0 ;
127  float py = 0 ;
128  gPz = 0 ;
129  float e = 0 ;
130  nPart = 0 ;
131  TClonesArray &pParticle = *pPart ;
132 
133  int vert ;
134 
135 for (Int_t kg = 0; kg < nTracks; kg++) {
136  StMuMcTrack *mcTrack = (StMuMcTrack *) MuMcTracks->UncheckedAt(kg);
137 
138  new(pParticle[nPart++]) StPeCParticle(mcTrack) ;
139 
140  LOG_INFO << "StPeCGeant::fill Geant pid: "<<mcTrack->GePid()<<endm;
141  // vert = trkT[i].start_vertex_p ;
142  // if ( vert != 1 ) continue ;
143  if(mcTrack->GePid()==8 || mcTrack->GePid()==9){
144  px += mcTrack->Pxyz().x();
145  py += mcTrack->Pxyz().y();
146  gPz += mcTrack->Pxyz().z();
147  e += mcTrack->E();
148  }
149  }
150 
151  gPt = ::sqrt(px*px+py*py);
152  gPsi = atan2(py,px);
153  if ( gPsi < 0 ) gPsi += M_PI ;
154  gMass = ::sqrt(e*e-gPt*gPt-gPz*gPz);
155 
156  float theta = atan2(gPt,gPz);
157  gEta = -::log(tan(theta/2.)) ;
158  gY = 0.5*::log((e+gPz)/(e-gPz));
159 
160 // St_g2t_vertex* vtx = 0 ;
161 // vtx = (St_g2t_vertex *)geant->Find("g2t_vertex") ;
162 // if ( !vtx ) {
163 // printf ( "StPeCGeant::fill: vertex not found \n" ) ;
164 // return 1 ;
165 // }
166 // g2t_vertex_st* vtxT = vtx->GetTable() ;
167 
168  StMuMcVertex *mcVertex = (StMuMcVertex *) MuMcVertices->UncheckedAt(0);
169 
170  gZVertex = mcVertex->XyzV().z() ;
171 
172  return 0 ;
173 }
174 
175 
176 
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362