FairRoot/PandaRoot
PndHypMicroIdealWriter.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 "PndHypMicroIdealWriter.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 
30 #include "PndHypHit.h"
31 #include "PndHypPoint.h"
32 
33 #include "TVector3.h"
34 #include "TVectorD.h"
35 #include "FairRun.h"
36 #include "FairRuntimeDb.h"
37 #include <string>
38 #include <iostream>
39 
40 #include "RhoBase/RhoCandidate.h"
41 #include "PndPidCandidate.h"
42 #include "RhoTools/TEventShape.h"
43 #include "RhoBase/RhoCandList.h"
44 #include "PndEventInfo.h"
45 #include "RhoBase/RhoFactory.h"
46 //#include "RhoBase/TRho.h"
47 
48 using std::cout;
49 using std::endl;
50 
51 
52 
53 // ----- Default constructor -------------------------------------------
55  FairTask("FastSim Dump") {
56 }
57 // -------------------------------------------------------------------------
58 
59 // ----- Destructor ----------------------------------------------------
63  if (fMcCandidates) {fMcCandidates->Delete(); delete fMcCandidates;}
65  if (fEventInfo) {fEventInfo->Delete(); delete fEventInfo;}
66 
67  }
68 // -------------------------------------------------------------------------
69 
70 
71 
72 // ----- Public method Init --------------------------------------------
74 {
75 
76  fStoreNeutral=true;
77  fStoreCharged=true;
78  fStoreMC=true;
79 
80  //TDatabasePDG *dbpdg=TDatabasePDG::Instance();
81 
82  //TRho::Instance()->SetPDG(dbpdg);
83 
84  cout << " Inside the Init function****" << endl;
85 
86  //FairDetector::Initialize();
87  //FairRun* sim = FairRun::Instance();
88  //FairRuntimeDb* rtdb=sim->GetRuntimeDb();
89 
90  // Get RootManager
91  FairRootManager* ioman = FairRootManager::Instance();
92  if ( ! ioman ) {
93  cout << "-E- PndHypMicroIdealWriter::Init: "
94  << "RootManager not instantiated!" << endl;
95  return kFATAL;
96  }
97  // Get input array
98  fTrArray = (TClonesArray*) ioman->GetObject("Track");
99  if ( ! fTrArray) {
100  cout << "-W- PndHypMicroIdealWriter::Init: "
101  << "No TpcTrack array!" << endl;
102  fTrArray=new TClonesArray("Track");
103  fStoreCharged=false;
104  //return kERROR;
105  }
106 
107  fHitArray = (TClonesArray*) ioman->GetObject("HypPoint");
108  if ( ! fHitArray) {
109  cout << "-W- PndHypMicroIdealWriter::Init: "
110  << "No Hit array!" << endl;
111  fHitArray = new TClonesArray("HypPoint");
112  fStoreNeutral=false;
113  //return kERROR;
114  }
115 
116  /*
117  fMCTrack = (TClonesArray*) ioman->GetObject("MCTrack");
118  if ( ! fMCTrack) {
119  cout << "-W- PndHypMicroIdealWriter::Init: "
120  << "No MCTrack array!" << endl;
121  fMCTrack = new TClonesArray("MCTrack");
122  fStoreMC=false;
123  //return kERROR;
124  }
125 */
126 
127  // fChargedCandidates = new TClonesArray("RhoCandidate");
128 // FairRootManager::Instance()->Register("PndChargedCandidates","FullSim", fChargedCandidates, kTRUE);
129 
130 // fNeutralCandidates = new TClonesArray("RhoCandidate");
131 // FairRootManager::Instance()->Register("PndNeutralCandidates","FullSim", fNeutralCandidates, kTRUE);
132 
133 // fMcCandidates = new TClonesArray("RhoCandidate");
134 // FairRootManager::Instance()->Register("PndMcTracks","FullSim", fMcCandidates, kTRUE);
135 
136  fMicroIdealCandidates = new TClonesArray("PndPidCandidate");
137  FairRootManager::Instance()->Register("PndMicroIdealCandidates","FullSim", fMicroIdealCandidates, kTRUE);
138 
139 // fEventInfo = new TClonesArray("PndEventInfo");
140 // FairRootManager::Instance()->Register("PndEventSummary","FullSim", fEventInfo, kTRUE);
141 
142  // Create and register output array
143  cout << "-I- PndHypMicroIdealWriter: Intialization successfull" << endl;
144 
145  //fInvMass = new TH1D("invmass","",100,0.0,4.0);
146 
147  evtcnt=0;
148 
149  return kSUCCESS;
150 
151 }
152 
154 
155  // Get Base Container
156  FairRunAna* ana = FairRunAna::Instance();
157  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
158 
159  // Get run and runtime database
160  // FairRunAna* run = FairRunAna::Instance();
161 // if ( ! run ) Fatal("SetParContainers", "No analysis run");
162 
163  // FairRuntimeDb* db = run->GetRuntimeDb();
164 // if ( ! db ) Fatal("SetParContainers", "No runtime database");
165 
166 
167 }
168 
169 // -------------------------------------------------------------------------
170 
171 // ----- Public method Exec --------------------------------------------
173 {
174  if ((++evtcnt)%100==0)cout <<"evt: "<<evtcnt<<endl;
175 
176  // find # in input array
177  Int_t nTracks = 0;
178  if (fStoreCharged) nTracks=fTrArray->GetEntriesFast();
179 
180  Int_t nCluster = 0;
181  //if (fStoreNeutral) nCluster=fEmcArray->GetEntriesFast();
182 
183  int nMCTrack=0;
184  //if (fStoreMC) nMCTrack=fMCTrack->GetEntriesFast();
185 
186  //PndStack *fStack=(PndStack*)gMC->GetStack();
187  //int nMCTracks=fStack->GetNtrack();
188 
189  // Reset output array
190  //if (fChargedCandidates->GetEntriesFast() != 0) fChargedCandidates->Clear("C");
191  // if (fNeutralCandidates->GetEntriesFast() != 0) fNeutralCandidates->Clear("C");
192  // if (fMcCandidates->GetEntriesFast() != 0) fMcCandidates->Clear("C");
193  if (fMicroIdealCandidates->GetEntriesFast() != 0) fMicroIdealCandidates->Clear("C");
194  // if (fEventInfo->GetEntriesFast() != 0) fEventInfo->Clear("C");
195 
196 
197  //TClonesArray &chrgCandidates = *fChargedCandidates;
198  // TClonesArray &neutCandidates = *fNeutralCandidates;
199 // TClonesArray &mctracks = *fMcCandidates;
200  TClonesArray &microCandidates = *fMicroIdealCandidates;
201 
202  //RhoCandList l;
203 
204  TLorentzVector McSumP4(0,0,0,0);
205  TVector3 McAvgVtx(0,0,0);
206 
207  int nPrimary=0;
208 
209 
210  GFTrack *tr1;
211 
212 
213  // *************************
214  // Loop over the charged tracks
215  // ************************
216  LSLTrackRep* grep=0;
217  GFAbsTrackRep* rep=0;
218 
219  for (Int_t i=0; i<nTracks; i++)
220  {
221 
222  //Int_t chcandsize = chrgCandidates.GetEntriesFast();
223  Int_t micsize = microCandidates.GetEntriesFast();
224 
225  // Get the Tpc Track information
226 
227  tr1 = (GFTrack *)fTrArray->At(i);
228 
229  // check that track has been fitted
230  if(tr1->getCardinalRep()->getStatusFlag()!=0){
231  std::cout<< "Discarding track. Status flag !=0" <<std::endl;
232  continue;
233  }
234  LSLTrackRep* myrep=dynamic_cast<LSLTrackRep*>(tr1->getTrackRep(0));//tr1->getCardinalRep());
235  TVectorD d(6);
236  //TVector3 vtx;
237 
238  d = myrep->getGlobal();
239  //TVector3 pos =tr1->getPos();
240  //TVector3 pos2 =tr1->getTrackRep(0)->getPos();
241  //TVector3 mom =tr1->getTrackRep(0)->getMom();
242 
243  // std::cout<< "pos1 "<<pos.x()<<" "<<pos.x()<<" "<<pos.z()<<std::endl;
244 // std::cout<< "pos2 "<<pos2.x()<<" "<<pos2.x()<<" "<<pos2.z()<<std::endl;
245 // std::cout<< "mom "<<mom.x()<<" "<<mom.x()<<" "<<mom.z()<<std::endl;
246 
247  TVector3 vtx(d[0],d[1],d[2]);
248 
249  TLorentzVector lv;
250  lv.SetXYZM(d[3],d[4],d[5],0.13957);
251 
252  //std::cout<< "pos glob "<<d[0]<<" "<<d[1]<<" "<<d[2]<<std::endl;
253 // std::cout<< "mom glob "<<d[3]<<" "<<d[4]<<" "<<d[5]<<std::endl;
254 
255 
256 
257  // propagate(lv,vtx,myrep->getCharge());
258 
259  // create the RhoCandidate (keep this for the time being)
260  //RhoCandidate *tcand=new (chrgCandidates[chcandsize]) RhoCandidate(lv,myrep->getCharge());
261 
262  //tcand->SetPos(vtx);
263 
264  //set the convariance matrix of tcand
265 
266  TMatrixD globalCov = myrep->getGlobalCov();
267  TMatrixD mat(7,7);
268  int ii,jj;
269 
270 
271  for (ii=0;ii<6;ii++) for(jj=0;jj<6;jj++) mat[ii][jj]=globalCov[ii][jj];
272 
273 
274  //Extend matrix for energy (with default pion hypothesis)
275  double invE = 1./lv.E();
276  // mat[0+3][3+3] = mat[3+3][0+3] = (lv.X()*mat[0+3][0+3]+lv.Y()*mat[0+3][1+3]+lv.Z()*mat[0+3][2+3])*invE;
277 // mat[1+3][3+3] = mat[3+3][1+3] = (lv.X()*mat[0+3][1+3]+lv.Y()*mat[1+3][1+3]+lv.Z()*mat[1+3][2+3])*invE;
278 // mat[2+3][3+3] = mat[3+3][2+3] = (lv.X()*mat[0+3][2+3]+lv.Y()*mat[1+3][2+3]+lv.Z()*mat[2+3][2+3])*invE;
279 // mat[3+3][3+3] = (lv.X()*lv.X()*mat[0+3][0+3]+lv.Y()*lv.Y()*mat[1+3][1+3]+lv.Z()*lv.Z()*mat[2+3][2+3]
280 // +2.0*lv.X()*lv.Y()*mat[0+3][1+3]
281 // +2.0*lv.X()*lv.Z()*mat[0+3][2+3]
282 // +2.0*lv.Y()*lv.Z()*mat[1+3][2+3])*invE*invE;
283 
284 // mat[3+3][4-4] = mat[4-4][3+3] = (lv.X()*mat[0+3][4-4]+lv.Y()*mat[1+3][4-4]+lv.Z()*mat[2+3][4-4])*invE;
285 // mat[3+3][5-4] = mat[5-4][3+3] = (lv.X()*mat[0+3][5-4]+lv.Y()*mat[1+3][5-4]+lv.Z()*mat[2+3][5-4])*invE;
286 // mat[3+3][6-4] = mat[6-4][3+3] = (lv.X()*mat[0+3][6-4]+lv.Y()*mat[1+3][6-4]+lv.Z()*mat[2+3][6-4])*invE;
287 
288  //tcand->SetCov7(mat);
289 
290  //l.Add(*tcand);
291  unsigned int detId, hitId;
292  unsigned int numhits=0,mvdhits=0,stthits=0,tpchits=0;
293 
294  numhits=tr1->getCand().getNHits();
295  //cout<<" numhits "<<numhits<<endl;
296  // create the PndMicroIdealCandidate
297 
298  PndPidCandidate *micro=new (microCandidates[micsize]) PndPidCandidate((Int_t)myrep->getCharge(),vtx,lv,mat);//myrep->getCharge()
299 
300 
301 
302  for (ii=0;ii<numhits;++ii)
303  {
304  tr1->getCand().getHit(ii,detId,hitId);
305  //cout<<" numhits loop "<<ii<<" "<<detId<<" "<<hitId<<endl;
306  switch (detId)
307  {
308  case 2: mvd_hitidx[mvdhits]=hitId; if(mvdhits<1000) mvdhits++; break;
309  //case 1: stt_hitidx[stthits]=hitId; if(stthits<1000) stthits++;break;
310  default: tpc_hitidx[tpchits]=hitId; if(tpchits<1000) tpchits++;break;
311  }
312  }
313  micro->SetMvdHitIndexArray(mvdhits, mvd_hitidx);
314  //micro->SetSttHitIndexArray(stthits, stt_hitidx);
315  //micro->SetTpcHitIndexArray(tpchits, tpc_hitidx);
316 
318 
319 
320  //rep=tr1->getTrackRep(0)->clone();
321 
322  tr1->getCand().getHit(0,detId,hitId);
323  PndHypPoint* hit = (PndHypPoint*) fHitArray->At(hitId);
324 
325 
326  //std::cout<<" hit "<<hit->GetX()<<std::endl;
327  TVector3 init;
328  if(hit==0)continue;
329  hit->PositionIn(init);
330 
331 
332  //DetPlane pinit(init,TVector3(1,0,0),TVector3(0,1,0));
333 
334  //myrep->extrapolate(pinit);
335  // myrep->setReferencePlane(pinit);
336 
337  TVector3 pos(0,0,-76.5);
338  GFDetPlane pfin(pos,TVector3(1,0,0),TVector3(0,1,0));
339 
340  TVector3 dist,fin;
341 
342  TMatrixT<double> state(5,1);
343  TMatrixT<double> cov(5,5);
344  GFDetPlane p;
345  dist=myrep->getPos(pfin) ;
346  micro->SetPosition(dist);
347 
348  //std::cout<< (micro->GetPosition()).x()<<std::endl;
349  //dist = myrep->extrapolateToPoca(pos,state,cov,p);
350  //vtx.SetXYZ(dist.x(),dist.y(),dist.z());
351 
352  // std::cout<<dist.x()<<" "<<dist.y()<<" "<<dist.z()<<std::endl;
353  //std::cout<<fin.x()<<" "<<fin.y()<<" "<<fin.z()<<std::endl;
354  // grep=dynamic_cast<LSLTrackRep*>(rep);
355 
356 // if(grep!=0){
357 
358 // //grep->setPropDir(-1);
359 // TMatrixT<double> state(5,1);
360 // TMatrixT<double> cov(5,5);
361 // DetPlane p;
362 // //dist = grep->extrapolateToPoca(pos,state,cov,p);
363 // //dist=trk->getPos();
364 // //grep->Print();
365 
366 // vtx.SetXYZ(dist.x(),dist.y(),dist.z());
367 
368 // //double length=grep->extrapolate(pmed,state);
369 // //std::cout<<"length "<<length<<std::endl;
370 // //std::cout<<" x poca "<<grep->getChiSqu()<<" "<<dist.x()<<" "<<dist.y()<<" "<<dist.z()<<std::endl;
371 // //std::cout<<"error poca "<<sqrt(grep->getCovElem(0, 0))<<" erry "<<sqrt(grep->getCovElem(1, 1))<<std::endl;
372 
373 // }
374 
375 
376 
377  }
378 
379  // *************************
380  // Loop over the neutral clusters
381  // ************************
382 
383  double calFactor=1.035;
384 
385 
386 
387 
388  Finish();
389 
390 }
391 // -------------------------------------------------------------------------
392 
394  {
395  //fChargedCandidates->Delete();
396 // // fNeutralCandidates->Delete();
397 // // fMcCandidates->Delete();
398  fTrArray->Delete();
399  fHitArray->Delete();
400  //fMicroIdealCandidates->Delete();
401 // //fEventInfo->Delete();
402 // //fInvMass->Write();
403  }
404 
405 // -------------------------------------------------------------------------
406 
407 
408 // void PndHypMicroIdealWriter::propagate(TLorentzVector &l, TVector3 &p, float charge)
409 // {
410 // double x0=p.X()/100;
411 // double y0=p.Y()/100;
412 // double z0=p.Z()/100;
413 
414 // double px0=l.Px();
415 // double py0=l.Py();
416 // double pz0=l.Pz();
417 
418 // double B=2;
419 
420 // double pt=sqrt(px0*px0+py0*py0);
421 // double lambda=pz0/pt;
422 // double s_t=z0/lambda;
423 // double a=-0.2998*B*charge;
424 // double rho=a/pt;
425 
426 // double cosrs=cos(rho*s_t);
427 // double sinrs=sin(rho*s_t);
428 
429 // double px = px0*cosrs + py0*sinrs;
430 // double py = py0*cosrs - px0*sinrs;
431 // double pz = pz0;
432 
433 // double x=x0 - px/a*sinrs + py/a*(1-cosrs);
434 // double y=y0 - py/a*sinrs - px/a*(1-cosrs);
435 // double z=z0 - lambda*s_t;
436 
437 // l.SetX(px);
438 // l.SetY(py);
439 // l.SetZ(pz);
440 
441 // p.SetX(x*100);
442 // p.SetY(y*100);
443 // p.SetZ(z*100);
444 // }
445 
TVector3 pos
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:80
Double_t p
Definition: anasim.C:58
TObjArray * d
Int_t i
Definition: run_full.C:25
Detector plane genfit geometry class.
Definition: GFDetPlane.h:59
Track object for genfit. genfit algorithms work on these objects.
Definition: GFTrack.h:60
unsigned int getNHits() const
Definition: GFTrackCand.h:113
void SetPosition(TVector3 &pos)
static int init
Definition: ranlxd.cxx:374
TClonesArray * fMicroIdealCandidates
bool getStatusFlag()
void PositionIn(TVector3 &pos)
Definition: PndHypPoint.h:125
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
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:186
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:202
const GFTrackCand & getCand() const
Definition: GFTrack.h:142
ClassImp(PndAnaContFact)
virtual void Exec(Option_t *opt)
PndSdsMCPoint * hit
Definition: anasim.C:70
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52