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