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