FairRoot/PandaRoot
PndHypMicroWriter.cxx
Go to the documentation of this file.
1 /******************************************************
2 Class PndHypMicroWriter
3 
4 Collects Micro infromation from Reconstruction and
5 writes out PndPidCandidates
6 
7 Author: K.Goetzen, GSI, 06/2008
8 modified by A. Sanchez for hyp purpose
9 
10 *******************************************************/
11 
12 #include "PndHypMicroWriter.h"
13 
14 #include "TClonesArray.h"
15 #include "TVirtualMC.h"
16 #include "TDatabasePDG.h"
17 #include "TParticlePDG.h"
18 //#include "TParticle.h"
19 
20 #include "FairRootManager.h"
21 #include "FairRunAna.h"
22 #include "FairRuntimeDb.h"
23 
24 #include "PndStack.h"
25 #include "PndMCTrack.h"
26 
27 #include "GFTrack.h"
28 #include "LSLTrackRep.h"
29 #include "GeaneTrackRep.h"
30 #include "PndHypHit.h"
31 
32 #include "TVector3.h"
33 #include "TVectorD.h"
34 #include "FairRun.h"
35 #include "FairRuntimeDb.h"
36 #include <string>
37 #include <iostream>
38 
39 #include "RhoBase/RhoCandidate.h"
40 #include "PndPidCandidate.h"
41 //#include "RhoTools/TEventShape.h"
42 #include "RhoBase/RhoCandList.h"
43 //#include "PndEventInfo.h"
44 #include "RhoBase/RhoFactory.h"
45 //#include "RhoBase/TRho.h"
46 
47 using std::cout;
48 using std::endl;
49 
50 
51 
52 // ----- Default constructor -------------------------------------------
54  FairTask("FastSim Dump") {
55 }
56 // -------------------------------------------------------------------------
57 
58 // ----- Destructor ----------------------------------------------------
62  if (fMcCandidates) {fMcCandidates->Delete(); delete fMcCandidates;}
63  if (fMicroCandidates) {fMicroCandidates->Delete(); delete fMicroCandidates;}
64  if (fEventInfo) {fEventInfo->Delete(); delete fEventInfo;}
65 
66  }
67 // -------------------------------------------------------------------------
68 
69 
70 
71 // ----- Public method Init --------------------------------------------
73 {
74 
75  fStoreNeutral=true;
76  fStoreCharged=true;
77  fStoreMC=true;
78 
79  //TDatabasePDG *dbpdg=TDatabasePDG::Instance();
80 
81  //TRho::Instance()->SetPDG(dbpdg);
82 
83  cout << " Inside the Init function****" << endl;
84 
85  //FairDetector::Initialize();
86  //FairRun* sim = FairRun::Instance();
87  //FairRuntimeDb* rtdb=sim->GetRuntimeDb();
88 
89  // Get RootManager
90  FairRootManager* ioman = FairRootManager::Instance();
91  if ( ! ioman ) {
92  cout << "-E- PndHypMicroWriter::Init: "
93  << "RootManager not instantiated!" << endl;
94  return kFATAL;
95  }
96  // Get input array
97  fTrArray = (TClonesArray*) ioman->GetObject("Track");
98  if ( ! fTrArray) {
99  cout << "-W- PndHypMicroWriter::Init: "
100  << "No TpcTrack array!" << endl;
101  fTrArray=new TClonesArray("GFTrack");
102  fStoreCharged=false;
103  //return kERROR;
104  }
105 
106  fHitArray = (TClonesArray*) ioman->GetObject("HypHit");
107  if ( ! fHitArray) {
108  cout << "-W- PndHypMicroWriter::Init: "
109  << "No Hit array!" << endl;
110  fHitArray = new TClonesArray("HypHit");
111  fStoreNeutral=false;
112  //return kERROR;
113  }
114 
115  /*
116  fMCTrack = (TClonesArray*) ioman->GetObject("MCTrack");
117  if ( ! fMCTrack) {
118  cout << "-W- PndHypMicroWriter::Init: "
119  << "No MCTrack array!" << endl;
120  fMCTrack = new TClonesArray("MCTrack");
121  fStoreMC=false;
122  //return kERROR;
123  }
124 */
125 
126  // fChargedCandidates = new TClonesArray("RhoCandidate");
127 // FairRootManager::Instance()->Register("PndChargedCandidates","FullSim", fChargedCandidates, kTRUE);
128 
129 // fNeutralCandidates = new TClonesArray("RhoCandidate");
130 // FairRootManager::Instance()->Register("PndNeutralCandidates","FullSim", fNeutralCandidates, kTRUE);
131 
132 // fMcCandidates = new TClonesArray("RhoCandidate");
133 // FairRootManager::Instance()->Register("PndMcTracks","FullSim", fMcCandidates, kTRUE);
134 
135  fMicroCandidates = new TClonesArray("PndPidCandidate");
136  FairRootManager::Instance()->Register("PndPidCandidates","FullSim", fMicroCandidates, kTRUE);
137 
138 // fEventInfo = new TClonesArray("PndEventInfo");
139 // FairRootManager::Instance()->Register("PndEventSummary","FullSim", fEventInfo, kTRUE);
140 
141  // Create and register output array
142  cout << "-I- PndHypMicroWriter: Intialization successfull" << endl;
143 
144  //fInvMass = new TH1D("invmass","",100,0.0,4.0);
145 
146  evtcnt=0;
147 
148  return kSUCCESS;
149 
150 }
151 
153 
154  // Get Base Container
155  FairRunAna* ana = FairRunAna::Instance();
156  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
157 
158  // Get run and runtime database
159  // FairRunAna* run = FairRunAna::Instance();
160 // if ( ! run ) Fatal("SetParContainers", "No analysis run");
161 
162  // FairRuntimeDb* db = run->GetRuntimeDb();
163 // if ( ! db ) Fatal("SetParContainers", "No runtime database");
164 
165 
166 }
167 
168 // -------------------------------------------------------------------------
169 
170 // ----- Public method Exec --------------------------------------------
171 void PndHypMicroWriter::Exec(Option_t*)
172 {
173  if ((++evtcnt)%100==0)cout <<"evt: "<<evtcnt<<endl;
174 
175  // find # in input array
176  Int_t nTracks = 0;
177  if (fStoreCharged) nTracks=fTrArray->GetEntriesFast();
178 
179  Int_t nCluster = 0;
180  //if (fStoreNeutral) nCluster=fEmcArray->GetEntriesFast();
181 
182  int nMCTrack=0;
183  //if (fStoreMC) nMCTrack=fMCTrack->GetEntriesFast();
184 
185  //PndStack *fStack=(PndStack*)gMC->GetStack();
186  //int nMCTracks=fStack->GetNtrack();
187 
188  // Reset output array
189  //if (fChargedCandidates->GetEntriesFast() != 0) fChargedCandidates->Clear("C");
190  // if (fNeutralCandidates->GetEntriesFast() != 0) fNeutralCandidates->Clear("C");
191  // if (fMcCandidates->GetEntriesFast() != 0) fMcCandidates->Clear("C");
192  if (fMicroCandidates->GetEntriesFast() != 0) fMicroCandidates->Clear("C");
193  // if (fEventInfo->GetEntriesFast() != 0) fEventInfo->Clear("C");
194 
195 
196  //TClonesArray &chrgCandidates = *fChargedCandidates;
197  // TClonesArray &neutCandidates = *fNeutralCandidates;
198 // TClonesArray &mctracks = *fMcCandidates;
199  TClonesArray &microCandidates = *fMicroCandidates;
200 
201  //RhoCandList l;
202 
203  TLorentzVector McSumP4(0,0,0,0);
204  TVector3 McAvgVtx(0,0,0);
205 
206  int nPrimary=0;
207 
208 
209  GFTrack *tr1;
210 
211 
212  // *************************
213  // Loop over the charged tracks
214  // ************************
215  LSLTrackRep* grep=0;
216  GFAbsTrackRep* rep=0;
217 
218  for (Int_t i=0; i<nTracks; i++)
219  {
220 
221  //Int_t chcandsize = chrgCandidates.GetEntriesFast();
222  Int_t micsize = microCandidates.GetEntriesFast();
223 
224  // Get the Tpc Track information
225 
226  tr1 = (GFTrack *)fTrArray->At(i);
227 
228  // check that track has been fitted
229  if(tr1->getCardinalRep()->getStatusFlag()!=0){
230  std::cout<< "Discarding track. Status flag !=0" <<std::endl;
231  continue;
232  }
233 
234  //LSLTrackRep* myrep=dynamic_cast<LSLTrackRep*>(tr1->getTrackRep(0));//tr1->getCardinalRep());
235  GeaneTrackRep* myrep=dynamic_cast<GeaneTrackRep*>(tr1->getTrackRep(0));
236 
237  TVectorD d(6);
238  //TVector3 vtx;
239 
240  //d = myrep->getGlobal();
241  //TVector3 pos =tr1->getPos();
242  TVector3 pos =tr1->getTrackRep(0)->getPos();
243  TVector3 mom =tr1->getTrackRep(0)->getMom();
244 
245  // std::cout<< "pos1 "<<pos.x()<<" "<<pos.x()<<" "<<pos.z()<<std::endl;
246 // std::cout<< "pos2 "<<pos2.x()<<" "<<pos2.x()<<" "<<pos2.z()<<std::endl;
247 // std::cout<< "mom "<<mom.x()<<" "<<mom.x()<<" "<<mom.z()<<std::endl;
248 
249  TVector3 vtx(pos.x(),pos.y(),pos.z());//d[0],d[1],d[2]);
250 
251  TLorentzVector lv;
252  lv.SetXYZM(mom.x(),mom.y(),mom.z(),0.13957);//d[3],d[4],d[5],0.13957);
253 
254  //std::cout<< "pos glob "<<d[0]<<" "<<d[1]<<" "<<d[2]<<std::endl;
255 // std::cout<< "mom glob "<<d[3]<<" "<<d[4]<<" "<<d[5]<<std::endl;
256 
257 
258 
259  // propagate(lv,vtx,myrep->getCharge());
260 
261  // create the RhoCandidate (keep this for the time being)
262  //RhoCandidate *tcand=new (chrgCandidates[chcandsize]) RhoCandidate(lv,myrep->getCharge());
263 
264  //tcand->SetPos(vtx);
265 
266  //set the convariance matrix of tcand
267 
268  /* TMatrixD globalCov = myrep->getGlobalCov();*/
269  TMatrixD mat(7,7);
270  int ii,jj;
271 
272 
273 
274  unsigned int detId, hitId;
275  unsigned int numhits=0,mvdhits=0,stthits=0,tpchits=0;
276 
277  numhits=tr1->getCand().getNHits();
278  //cout<<" numhits "<<numhits<<endl;
279  // create the PndPidCandidate
280 
281  PndPidCandidate *micro=new (microCandidates[micsize]) PndPidCandidate((Int_t)myrep->getCharge(),vtx,lv,mat);//myrep->getCharge()
282 
283 
284 
285  for (ii=0;ii<numhits;++ii)
286  {
287  tr1->getCand().getHit(ii,detId,hitId);
288  //cout<<" numhits loop "<<ii<<" "<<detId<<" "<<hitId<<endl;
289  switch (detId)
290  {
291  case 2: mvd_hitidx[mvdhits]=hitId; if(mvdhits<1000) mvdhits++; break;
292  //case 1: stt_hitidx[stthits]=hitId; if(stthits<1000) stthits++;break;
293  default: tpc_hitidx[tpchits]=hitId; if(tpchits<1000) tpchits++;break;
294  }
295  }
296 
297  micro->SetMvdHits(numhits);
298 
299  //micro->SetSttHitIndexArray(stthits, stt_hitidx);
300  //micro->SetTpcHitIndexArray(tpchits, tpc_hitidx);
301 
303 
304 
305  //rep=tr1->getTrackRep(0)->clone();
306  unsigned int hid;
307  hid=-1;
308 
309  tr1->getCand().getHit(0,detId,hid);
310  //std::cout<<" entries "<<fHitArray->GetEntriesFast()<<" hid "<<hid<<std::endl;;
311  PndHypHit* hit = (PndHypHit*) fHitArray->At(hid);
312  if(hit==0)continue;
313 
314  //std::cout<<" hit "<<hit->GetX()<<std::endl;
315  TVector3 init= hit->GetPosition();
316 
317  GFDetPlane pinit(init,TVector3(1,0,0),TVector3(0,1,0));
318 
319  //myrep->extrapolate(pinit);
320  // myrep->setReferencePlane(pinit);
321 
322  /* TVector3 pos(0,0,-76.5);
323  GFDetPlane pfin(pos,TVector3(1,0,0),TVector3(0,1,0));
324 
325  TVector3 dist,fin;
326 
327  TMatrixT<double> state(5,1);
328  TMatrixT<double> cov(5,5);
329  GFDetPlane p;
330  */
331  // dist=myrep->getPos(pfin) ;
332  //micro->SetPosition(dist);
333 
334  //std::cout<< (micro->GetPosition()).x()<<std::endl;
335  //dist = myrep->extrapolateToPoca(pos,state,cov,p);
336  //vtx.SetXYZ(dist.x(),dist.y(),dist.z());
337 
338  // std::cout<<dist.x()<<" "<<dist.y()<<" "<<dist.z()<<std::endl;
339  //std::cout<<fin.x()<<" "<<fin.y()<<" "<<fin.z()<<std::endl;
340  // grep=dynamic_cast<LSLTrackRep*>(rep);
341 
342 // if(grep!=0){
343 
344 // //grep->setPropDir(-1);
345 // TMatrixT<double> state(5,1);
346 // TMatrixT<double> cov(5,5);
347 // DetPlane p;
348 // //dist = grep->extrapolateToPoca(pos,state,cov,p);
349 // //dist=trk->getPos();
350 // //grep->Print();
351 
352 // vtx.SetXYZ(dist.x(),dist.y(),dist.z());
353 
354 // //double length=grep->extrapolate(pmed,state);
355 // //std::cout<<"length "<<length<<std::endl;
356 // //std::cout<<" x poca "<<grep->getChiSqu()<<" "<<dist.x()<<" "<<dist.y()<<" "<<dist.z()<<std::endl;
357 // //std::cout<<"error poca "<<sqrt(grep->getCovElem(0, 0))<<" erry "<<sqrt(grep->getCovElem(1, 1))<<std::endl;
358 
359 // }
360 
361 
362 
363  }
364 
365  // *************************
366  // Loop over the neutral clusters
367  // ************************
368 
369  double calFactor=1.035;
370 
371 
372 
373 
374  Finish();
375 
376 }
377 // -------------------------------------------------------------------------
378 
380  {
381  //fChargedCandidates->Delete();
382 // // fNeutralCandidates->Delete();
383 // // fMcCandidates->Delete();
384  fTrArray->Delete();
385  fHitArray->Delete();
386  //fMicroCandidates->Delete();
387 // //fEventInfo->Delete();
388 // //fInvMass->Write();
389  }
390 
391 // -------------------------------------------------------------------------
392 
393 
394 
395 
TVector3 pos
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:80
virtual void SetParContainers()
TClonesArray * fMicroCandidates
TClonesArray * fEventInfo
TObjArray * d
Int_t i
Definition: run_full.C:25
Detector plane genfit geometry class.
Definition: GFDetPlane.h:59
Int_t tpc_hitidx[1000]
Track object for genfit. genfit algorithms work on these objects.
Definition: GFTrack.h:60
TVector3 GetPosition() const
Definition: PndHypHit.h:87
TClonesArray * fTrArray
unsigned int getNHits() const
Definition: GFTrackCand.h:113
virtual InitStatus Init()
TClonesArray * fMcCandidates
void SetMvdHits(Int_t val)
Double_t mom
Definition: plot_dirc.C:14
static int init
Definition: ranlxd.cxx:374
virtual TVector3 getMom(const GFDetPlane &pl)=0
TClonesArray * fNeutralCandidates
virtual TVector3 getPos(const GFDetPlane &pl)=0
virtual void Exec(Option_t *opt)
bool getStatusFlag()
void getHit(unsigned int i, unsigned int &detId, unsigned int &hitId) const
Get detector ID and cluster index (hitId) for hit number i.
Definition: GFTrackCand.h:84
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
virtual double getCharge() const
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:186
TClonesArray * fHitArray
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:202
const GFTrackCand & getCand() const
Definition: GFTrack.h:142
ClassImp(PndAnaContFact)
TClonesArray * fChargedCandidates
Int_t mvd_hitidx[1000]
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52