FairRoot/PandaRoot
PndGemSmearingTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndGemSmearingTask source file -----
3 // ----- Created 04/11/08 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 "PndGemSmearingTask.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 #include "../pnddata/PndMCTrack.h"
22 #include "FairHit.h"
23 // PndGem includes
24 #include "PndGemHit.h"
25 #include "PndGemMCPoint.h"
26 
27 
28 // ----- Default constructor -------------------------------------------
30  FairTask("Ideal reconstruction task for PANDA PndGem"),
31  fHitCovMatrix(3,3)
32 {
33  fDigiPar = NULL;
34  fSigmaX=0.;
35  fSigmaY=0.;
36  fSigmaZ=0.;
37  fBranchName = "GEMPoint";
38 }
39 // -------------------------------------------------------------------------
40 
41 // ----- Constructor ---------------------------------------------------
43  FairTask("Ideal reconstruction task for PANDA PndGem"),
44  fHitCovMatrix(3,3)
45 {
46  fDigiPar = NULL;
47  fSigmaX=sx;
48  fSigmaY=sy;
49  fSigmaZ=sz;
50  fBranchName = "GEMPoint";
51 }
52 // -------------------------------------------------------------------------
53 
54 
55 // ----- Destructor ----------------------------------------------------
57 {
58  if ( fDigiPar) delete fDigiPar;
59 }
60 
61 // ----- Public method Init --------------------------------------------
63 {
64  // Get RootManager
65  FairRootManager* ioman = FairRootManager::Instance();
66  if ( ! ioman ) {
67  std::cout << "-E- PndGemSmearingTask::Init: "
68  << "RootManager not instantiated!" << std::endl;
69  return kFATAL; }
70 
71  // Get input array
72  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
73  if ( ! fPointArray ) {
74  std::cout << "-W- PndGemSmearingTask::Init: "<< "No "<<fBranchName
75  <<" array!" << std::endl;
76  return kERROR; }
77 
78  // Get MCTruth collection
79  fMctruthArray=(TClonesArray*) ioman->GetObject("MCTrack");
80  if(fMctruthArray==0) {
81  std::cout << "-W- PndGemSmearingTask::Init: No McTruth array!" << std::endl;
82  return kERROR; }
83 
84  // Create and register output array
85  fHitOutputArray = new TClonesArray("PndGemHit");
86  ioman->Register("GEMHit", "PndMvd ideal Hits",
87  fHitOutputArray, kTRUE);
88 
89  std::cout << "-I- gGeoManager = "<<gGeoManager << std::endl;
90 
91 
92  return kSUCCESS;
93 }
94 // -------------------------------------------------------------------------
96 {
97  // Get Base Container
98  FairRun* ana = FairRun::Instance();
99  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
100 
101  // Get GEM digitisation parameter container
102  fDigiPar = (PndGemDigiPar*)(rtdb->getContainer("PndGemDetectors"));
103 }
104 
105 
106 // ----- Public method Exec --------------------------------------------
108 {
109  // Fills PndGemHits with the MC Truth
110  // TODO filling of RecoHits, together with the sensor plane
111 
112 
113  if ( ! fHitOutputArray ) Fatal("Exec", "No fHitOutputArray");
114  fHitOutputArray->Clear();
115 
116  std::map<Int_t, PndGemHit*> clusterMap;
117 
118  Int_t nPndGemHits=fPointArray->GetEntriesFast();
119  for(Int_t iMvdPoint=0;iMvdPoint<nPndGemHits;++iMvdPoint)
120  {
122  Int_t trackid=fCurrentPndGemMCPoint->GetTrackID();
123  Int_t size = fHitOutputArray->GetEntriesFast();
124  InitTransMat();
125 
126  // cut on secondaries (deltas) etc
127  if(trackid<0)continue;
128 
129  //set the plane definition inside the local frame
130  //sensor origin in the middle, u^ and v^ are xy plane
131  TVector3 o(0.,0.,0.),u(1.,0.,0.),v(0.,1.,0.);
132  CalcGFDetPlane(o,u,v);
133  TVector3 pos;
134  fCurrentPndGemMCPoint->Position(pos);
135  smearLocal(pos);
136  TVector3 dposLocal(fSigmaX,fSigmaY,fSigmaZ);
137 
138  // TODO here we shall distinguish between strip and pixel sensors
139  // TODO How to handle the covariance matrix? OR do we really use local point
140  // errors. this would avoid two conversations, myabe overload the FairHit
141  // functions for the global error points.
142 
143  // Now the 3D Info is smared inside the FairHit part of PndGemHit
144  new ((*fHitOutputArray)[size]) PndGemHit(fCurrentPndGemMCPoint->GetDetectorID(),
145  pos,dposLocal,iMvdPoint,fCurrentPndGemMCPoint->GetEnergyLoss(),1);
146 
147  }//end for PndMvdiMvdPoint
148 
149  if (fVerbose > 0) {
150  std::cout<<fHitOutputArray->GetEntriesFast() <<" Hits created out of "
151  <<fPointArray->GetEntriesFast() <<" Points"<<std::endl;
152  }
153 
154 }
155 // -------------------------------------------------------------------------
157 {
158 // std::cout<<"InitTransMat() with "<<fCurrentPndGemMCPoint->GetDetName()<<std::endl;
159  Int_t sensorId = fCurrentPndGemMCPoint->GetSensorId();
160  TString nodeName = fDigiPar->GetNodeName(sensorId);
161  gGeoManager->cd(nodeName.Data());
162  fCurrentTransMat = gGeoManager->GetCurrentMatrix();
163  if (fVerbose > 1) {
164  fCurrentTransMat->Print("");
165  }
166 }
167 
168 
170 {
172 
173  Double_t sigx=gRandom->Gaus(0,fSigmaX);
174  Double_t sigy=gRandom->Gaus(0,fSigmaY);
175  Double_t sigz=gRandom->Gaus(0,fSigmaZ);
176 
177  Double_t x = pos.x() + sigx;
178  Double_t y = pos.y() + sigy;
179  Double_t z = pos.z() + sigz;
180 
181  if (fVerbose > 1) {
182  std::cout<<"PndGemSmearingTask::smear Point (x,y,z)=("
183  <<pos.x()<<","<<pos.z()<<","<<pos.z()<<") by ("
184  <<fSigmaX<<","<<fSigmaY<<","<<fSigmaZ<<") to ";
185  }
186  pos.SetXYZ(x,y,z);
187  if (fVerbose > 1) {
188  std::cout<<"("<<pos.x()<<","<<pos.y()<<","<<pos.z()<<")"<<std::endl;
189  }
190  return;
191 }
192 
193 
195 {
197  if (fVerbose > 1) {
198  std::cout<<"PndGemSmearingTask::smearLocal"<<std::endl;
199  }
200  Double_t posLab[3], posSens[3];
201 
202  posLab[0]=pos.x(); posLab[1]=pos.y(); posLab[2]=pos.z();
203  fCurrentTransMat->MasterToLocal(posLab,posSens);
204 
205  pos.SetXYZ(posSens[0],posSens[1],posSens[2]);
206 
207  smear(pos); // apply a gaussian
208 
209  posSens[0]=pos.x(); posSens[1]=pos.y(); posSens[2]=pos.z();
210  fCurrentTransMat->LocalToMaster(posSens,posLab);
211  pos.SetXYZ(posLab[0],posLab[1],posLab[2]);
212 
213 
214  return;
215 }
216 
217 
218 
219 void PndGemSmearingTask::CalcGFDetPlane(TVector3& oVect, TVector3& uVect,TVector3& vVect)
220 {
221  Double_t O[3], U[3], V[3], o[3], u[3], v[3];
222  O[0]=oVect.x(); O[1]=oVect.y(); O[2]=oVect.z();
223  U[0]=uVect.x(); U[1]=uVect.y(); U[2]=uVect.z();
224  V[0]=vVect.x(); V[1]=vVect.y(); V[2]=vVect.z();
225 
226  if (fVerbose > 1) {
227  std::cout<<"PndGemSmearingTask::CalcGFDetPlane from Detector sensorId "
228  <<fCurrentPndGemMCPoint->GetSensorId()<<std::endl;
229  }
230  //make transformation
231  fCurrentTransMat->LocalToMaster(O,o);
232  fCurrentTransMat->LocalToMaster(U,u);
233  fCurrentTransMat->LocalToMaster(V,v);
234  oVect.SetXYZ(o[0],o[1],o[2]);
235  uVect.SetXYZ(u[0],u[1],u[2]);
236  vVect.SetXYZ(v[0],v[1],v[2]);
237 }
238 
239 
TVector3 pos
int fVerbose
Definition: poormantracks.C:24
TGeoHMatrix * fCurrentTransMat
TClonesArray * fHitOutputArray
Digitization Parameter Class for GEM part.
Definition: PndGemDigiPar.h:31
TGeoManager * gGeoManager
__m128 v
Definition: P4_F32vec4.h:4
Int_t GetSensorId() const
Definition: PndGemMCPoint.h:90
void smear(TVector3 &pos)
Double_t
TClonesArray * fPointArray
TString GetNodeName(Int_t sensorId)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Double_t z
virtual void SetParContainers()
void CalcGFDetPlane(TVector3 &o, TVector3 &u, TVector3 &v)
virtual void Exec(Option_t *opt)
Double_t x
ClassImp(PndAnaContFact)
PndGemMCPoint * fCurrentPndGemMCPoint
TClonesArray * fMctruthArray
Double_t y
void smearLocal(TVector3 &pos)
PndGemDigiPar * fDigiPar
virtual InitStatus Init()