FairRoot/PandaRoot
PndMvdIdealRecoTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMvdIdealRecoTask source file -----
3 // ----- Created 20/03/07 by R.Kliemt -----
4 // -------------------------------------------------------------------------
5 // libc includes
6 #include <iostream>
7 
8 // Root includes
9 #include "TROOT.h"
10 #include "TClonesArray.h"
11 #include "TParticlePDG.h"
12 #include "TRandom.h"
13 #include "TGeoManager.h"
14 #include "TGeoMatrix.h"
15 
16 // framework includes
17 #include "FairRootManager.h"
18 #include "PndMvdIdealRecoTask.h"
19 #include "FairRun.h"
20 #include "FairRuntimeDb.h"
21 #include "../pnddata/PndMCTrack.h"
22 #include "FairHit.h"
23 // PndMvd includes
24 #include "PndSdsHit.h"
25 #include "PndSdsMCPoint.h"
26 
27 
28 // ----- Default constructor -------------------------------------------
30 FairTask("Ideal reconstruction task for PANDA PndMvd"),
31  fPersistance(kTRUE),
32  fBranchName("MVDPoint"),
33  fGeoH(PndGeoHandling::Instance()),
34  fPointArray(NULL),
35  fMctruthArray(NULL),
36  fHitOutputArray(NULL),
37  fSigmaX(0.),
38  fSigmaY(0.),
39  fSigmaZ(0.),
40  fCurrentPndMvdMCPoint(NULL),
41  fCurrentTransMat(NULL),
42  fHitCovMatrix(3,3)
43 {
44 }
45 // -------------------------------------------------------------------------
46 
47 // ----- Constructor ---------------------------------------------------
49 FairTask("Ideal reconstruction task for PANDA PndMvd"),
50  fPersistance(kTRUE),
51  fBranchName("MVDPoint"),
52  fGeoH(PndGeoHandling::Instance()),
53  fPointArray(NULL),
54  fMctruthArray(NULL),
55  fHitOutputArray(NULL),
56  fSigmaX(sx),
57  fSigmaY(sy),
58  fSigmaZ(sz),
59  fCurrentPndMvdMCPoint(NULL),
60  fCurrentTransMat(NULL),
61  fHitCovMatrix(3,3)
62 {
63 }
64 // -------------------------------------------------------------------------
65 
66 
67 // ----- Destructor ----------------------------------------------------
69 {
70 }
71 
72 // ----- Public method Init --------------------------------------------
74 {
75  // Get RootManager
76  FairRootManager* ioman = FairRootManager::Instance();
77  if ( ! ioman ) {
78  std::cout << "-E- PndMvdIdealRecoTask::Init: "
79  << "RootManager not instantiated!" << std::endl;
80  return kFATAL; }
81 
82  // Get input array
83  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
84  if ( ! fPointArray ) {
85  std::cout << "-W- PndMvdIdealRecoTask::Init: "<< "No "<<fBranchName
86  <<" array!" << std::endl;
87  return kERROR; }
88 
89  // Get MCTruth collection
90  fMctruthArray=(TClonesArray*) ioman->GetObject("MCTrack");
91  if(fMctruthArray==0) {
92  std::cout << "-W- PndMvdIdealRecoTask::Init: No McTruth array!" << std::endl;
93  return kERROR; }
94 
95  // Create and register output array
96  fHitOutputArray = new TClonesArray("PndSdsHit");
97  ioman->Register("MVDHit", "PndMvd ideal Hits",
99 
100  std::cout << "-I- gGeoManager = "<<gGeoManager << std::endl;
101  return kSUCCESS;
102 }
103 // -------------------------------------------------------------------------
105 {
106  // Get Base Container
107  // FairRun* ana = FairRun::Instance();
108  // FairRuntimeDb* rtdb=ana->GetRuntimeDb();
109  // PndSdsIdealRecoTask::SetParContainers();
111 }
112 
113 
114 // ----- Public method Exec --------------------------------------------
116 {
117  // Fills PndMvdHits with the MC Truth
118  // TODO filling of RecoHits, together with the sensor plane
119 
120 
121  if ( ! fHitOutputArray ) Fatal("Exec", "No fHitOutputArray");
122  fHitOutputArray->Delete();
123 
124  std::map<Int_t, PndSdsHit*> clusterMap;
125 
126  Int_t nPndMvdHits=fPointArray->GetEntriesFast();
127  for(Int_t iMvdPoint=0;iMvdPoint<nPndMvdHits;++iMvdPoint)
128  {
130  Int_t trackid=fCurrentPndMvdMCPoint->GetTrackID();
131  Int_t size = fHitOutputArray->GetEntriesFast();
132  InitTransMat();
133 
134  // cut on secondaries (deltas) etc
135  if(trackid<0)continue;
136 
137  //set the plane definition inside the local frame
138  //sensor origin in the middle, u^ and v^ are xy plane
139  TVector3 o(0.,0.,0.),u(1.,0.,0.),v(0.,1.,0.);
140  CalcDetPlane(o,u,v);
141  TVector3 pos;
142  fCurrentPndMvdMCPoint->Position(pos);
143  smearLocal(pos);
144  TVector3 dposLocal(fSigmaX,fSigmaY,fSigmaZ);
145 
146  // TODO here we shall distinguish between strip and pixel sensors
147  // TODO How to handle the covariance matrix? OR do we really use local point
148  // errors. this would avoid two conversations, myabe overload the FairHit
149  // functions for the global error points.
150 
151  // Now the 3D Info is smared inside the FairHit part of PndSdsHit
152  new ((*fHitOutputArray)[size]) PndSdsHit(fCurrentPndMvdMCPoint->GetDetectorID(),
154  pos,dposLocal,-1,fCurrentPndMvdMCPoint->GetEnergyLoss(),1,iMvdPoint);
155 
156  }//end for PndMvdiMvdPoint
157 
158  if (fVerbose > 0) {
159  std::cout<<fHitOutputArray->GetEntriesFast() <<" Hits created out of "
160  <<fPointArray->GetEntriesFast() <<" Points"<<std::endl;
161  }
162 
163 }
164 // -------------------------------------------------------------------------
166 {
167  // std::cout<<"InitTransMat() with "<<fCurrentPndMvdMCPoint->GetDetName()<<std::endl;
168  gGeoManager->cd(
170  );
171  fCurrentTransMat = gGeoManager->GetCurrentMatrix();
172  if (fVerbose > 1) {
173  fCurrentTransMat->Print("");
174  }
175 }
176 
177 
179 {
181 
182  Double_t sigx=gRandom->Gaus(0,fSigmaX);
183  Double_t sigy=gRandom->Gaus(0,fSigmaY);
184  Double_t sigz=gRandom->Gaus(0,fSigmaZ);
185 
186  Double_t x = pos.x() + sigx;
187  Double_t y = pos.y() + sigy;
188  Double_t z = pos.z() + sigz;
189 
190  if (fVerbose > 1) {
191  std::cout<<"PndMvdIdealRecoTask::smear Point (x,y,z)=("
192  <<pos.x()<<","<<pos.z()<<","<<pos.z()<<") by ("
193  <<fSigmaX<<","<<fSigmaY<<","<<fSigmaZ<<") to ";
194  }
195  pos.SetXYZ(x,y,z);
196  if (fVerbose > 1) {
197  std::cout<<"("<<pos.x()<<","<<pos.y()<<","<<pos.z()<<")"<<std::endl;
198  }
199  return;
200 }
201 
202 
204 {
206  if (fVerbose > 1) {
207  std::cout<<"PndMvdIdealRecoTask::smearLocal"<<std::endl;
208  }
209  Double_t posLab[3], posSens[3];
210 
211  posLab[0]=pos.x(); posLab[1]=pos.y(); posLab[2]=pos.z();
212  fCurrentTransMat->MasterToLocal(posLab,posSens);
213 
214  pos.SetXYZ(posSens[0],posSens[1],posSens[2]);
215 
216  smear(pos); // apply a gaussian
217 
218  posSens[0]=pos.x(); posSens[1]=pos.y(); posSens[2]=pos.z();
219  fCurrentTransMat->LocalToMaster(posSens,posLab);
220  pos.SetXYZ(posLab[0],posLab[1],posLab[2]);
221 
222 
223  // TMatrixT<Double_t> cov(3,3);
224  // cov[0][0]=fSigmaX; cov[0][1]=0.; cov[0][2]=0.;
225  // cov[1][0]=0.; cov[1][1]=fSigmaY; cov[1][2]=0.;
226  // cov[2][0]=0.; cov[2][1]=0.; cov[2][2]=fSigmaZ;
227 
228  // TMatrixT<Double_t> rot(3,3);
229  // rot[0][0] = fCurrentTransMat->GetRotationMatrix()[0];
230  // rot[0][1] = fCurrentTransMat->GetRotationMatrix()[1];
231  // rot[0][2] = fCurrentTransMat->GetRotationMatrix()[2];
232  // rot[1][0] = fCurrentTransMat->GetRotationMatrix()[3];
233  // rot[1][1] = fCurrentTransMat->GetRotationMatrix()[4];
234  // rot[1][2] = fCurrentTransMat->GetRotationMatrix()[5];
235  // rot[2][0] = fCurrentTransMat->GetRotationMatrix()[6];
236  // rot[2][1] = fCurrentTransMat->GetRotationMatrix()[7];
237  // rot[2][2] = fCurrentTransMat->GetRotationMatrix()[8];
238 
239  // fHitCovMatrix = cov;
240  // fHitCovMatrix *= rot;
241 
242  return;
243 }
244 
245 
246 
247 void PndMvdIdealRecoTask::CalcDetPlane(TVector3& oVect, TVector3& uVect,TVector3& vVect)
248 {
249  Double_t O[3], U[3], V[3], o[3], u[3], v[3];
250  O[0]=oVect.x(); O[1]=oVect.y(); O[2]=oVect.z();
251  U[0]=uVect.x(); U[1]=uVect.y(); U[2]=uVect.z();
252  V[0]=vVect.x(); V[1]=vVect.y(); V[2]=vVect.z();
253 
254  if (fVerbose > 1) {
255  std::cout<<"PndMvdIdealRecoTask::CalcDetPlane from Detector "
256  <<fCurrentPndMvdMCPoint->GetSensorID()<<std::endl;
257  }
258  //make transformation
259  fCurrentTransMat->LocalToMaster(O,o);
260  fCurrentTransMat->LocalToMaster(U,u);
261  fCurrentTransMat->LocalToMaster(V,v);
262  oVect.SetXYZ(o[0],o[1],o[2]);
263  uVect.SetXYZ(u[0],u[1],u[2]);
264  vVect.SetXYZ(v[0],v[1],v[2]);
265 }
266 
267 
TVector3 pos
int fVerbose
Definition: poormantracks.C:24
PndGeoHandling * fGeoH
Definition: anasim.C:34
PndGeoHandling * fGeoH
virtual void SetParContainers()
PndSdsMCPoint * fCurrentPndMvdMCPoint
void CalcDetPlane(TVector3 &o, TVector3 &u, TVector3 &v)
TGeoManager * gGeoManager
Int_t GetSensorID() const
Definition: PndSdsMCPoint.h:89
TString GetPath(Int_t shortID)
for a given shortID the path is returned
__m128 v
Definition: P4_F32vec4.h:4
TClonesArray * fHitOutputArray
Class to access the naming information of the MVD.
virtual void Exec(Option_t *opt)
TClonesArray * fPointArray
Double_t
TClonesArray * fMctruthArray
void smear(TVector3 &pos)
Double_t z
TGeoHMatrix * fCurrentTransMat
virtual void SetParContainers()
Double_t x
ClassImp(PndAnaContFact)
void smearLocal(TVector3 &pos)
Double_t y
virtual InitStatus Init()