FairRoot/PandaRoot
PndFtsHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndFtsHitProducerIdeal source file -----
3 // -------------------------------------------------------------------------
4 
6 
7 #include "PndFtsHit.h"
8 #include "PndFtsHitInfo.h"
9 #include "PndFtsPoint.h"
10 #include "PndFtsTube.h"
11 #include "PndFtsSingleStraw.h"
12 #include "PndFtsMapCreator.h"
13 
14 #include "FairRootManager.h"
15 #include "FairRunAna.h"
16 #include "FairRuntimeDb.h"
17 
18 #include "TClonesArray.h"
19 #include "TRandom.h"
20 
21 #include <iostream>
22 #include <cmath>
23 
24 using std::cout;
25 using std::endl;
26 using std::sqrt;
27 
28 // TODO: read this from a configuration file
29 #define foldResolution 0 // <===== NO SMEARING
30 #define radialResolutionPolynomialConstant1 0.0150
31 #define radialResolutionPolynomialConstant2 0.
32 #define radialResolutionPolynomialConstant3 0.
33 //#define longitudinalResolutionPolynomialConstant1 3.
34 #define longitudinalResolutionPolynomialConstant1 0.0001
35 #define longitudinalResolutionPolynomialConstant2 0.
36 #define longitudinalResolutionPolynomialConstant3 0.
37 
38 // TODO: read this from geant initialization
39 #define innerStrawDiameter 1.
40 
41 // ----- Default constructor -------------------------------------------
43  PndPersistencyTask("Ideal FTS Hit Producer",0)
44 {
45  SetPersistency(kTRUE);
46  fPointArray = NULL;
47  fHitArray = NULL;
48  fHitInfoArray = NULL;
49  fTubeArray = NULL;
50  fFtsParameters =0;
51 }
52 // -------------------------------------------------------------------------
53 
54 
55 
56 // ----- Destructor ----------------------------------------------------
58 {
59 }
60 // -------------------------------------------------------------------------
61 
62 
63 
64 // ----- Public method Init --------------------------------------------
66 {
67  // Get RootManager
68  FairRootManager* ioman = FairRootManager::Instance();
69  if ( ! ioman )
70  {
71  cout << "-E- PndFtsHitProducerIdeal::Init: "
72  << "RootManager not instantiated!" << endl;
73  return kFATAL;
74  }
75 
76  // Get input array
77  fPointArray = (TClonesArray*) ioman->GetObject("FTSPoint");
78  if ( ! fPointArray )
79  {
80  cout << "-W- PndFtsHitProducerIdeal::Init: "
81  << "No FTSPoint array!" << endl;
82  return kERROR;
83  }
84 
85  // Create and register output array
86  fHitArray = new TClonesArray("PndFtsHit");
87  ioman->Register("FTSHit", "FTS", fHitArray, GetPersistency());
88 
89  // Create and register output array
90  fHitInfoArray = new TClonesArray("PndFtsHitInfo");
91  ioman->Register("FTSHitInfo", "FTS", fHitInfoArray, kFALSE);
92 
93  // CHECK added
94  //PndFtsMapCreator *fMapper = new PndFtsMapCreator(fFtsParameters);
95  cout << "-I- PndFtsHitProducerIdeal: Intialisation successfull" << endl;
96 
97  return kSUCCESS;
98 }
99 // -------------------------------------------------------------------------
100 
101 // CHECK added
103  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
104  fFtsParameters = (PndGeoFtsPar*) rtdb->getContainer("PndGeoFtsPar");
105 }
106 
107 // ----- Public method Exec --------------------------------------------
109 {
110  if(fTubeArray == NULL){
112  fTubeArray = mapper->FillTubeArray();
113  }
114  // Reset output array
115  if ( ! fHitArray )
116  Fatal("Exec", "No HitArray");
117 
118  fHitArray->Delete();
119  fHitInfoArray->Delete();
120 
121  // Declare some variables
123  *point = NULL;
124 
125  Int_t
126  detID = 0, // Detector ID
127  trackID = 0; // Track index
128 
129  TVector3
130  pos, dpos; // Position and error vectors
131 
132  // Loop over FtsPoints
133  Int_t
134  nPoints = fPointArray->GetEntriesFast();
135  Int_t counter=0;
136  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
137  {
138  point = (PndFtsPoint*) fPointArray->At(iPoint);
139 
140  if ( ! point)
141  continue;
142 
143  // Detector ID
144  detID = point->GetDetectorID();
145 
146  // MCTrack ID
147  trackID = point->GetTrackID();
148 
149  // tubeID CHECK added
150  Int_t skew = 0;
151  Int_t tubeID = point->GetTubeID();
152  Int_t chamberID = point->GetChamberID();
153  Int_t layerID = point->GetLayerID();
154  PndFtsTube *tube = (PndFtsTube*) fTubeArray->At(tubeID);
155 
156  //if skewed tube: skew==1
157  if(layerID>=3 && layerID<=6){skew=1;} //skewed tudes fts1
158  if(layerID>=11 && layerID<=14){skew=1;} //skewed tudes fts2
159  if(layerID>=19 && layerID<=22){skew=1;} //skewed tudes fts3
160  if(layerID>=27 && layerID<=30){skew=1;} //skewed tudes fts4
161  if(layerID>=35 && layerID<=38){skew=1;} //skewed tudes fts5
162  if(layerID>=43 && layerID<=46){skew=1;} //skewed tudes fts6
163 
164 
165  // Determine hit position and isochrone (x,y of wire, measured z position)
166  TVector3
167  posInLocal(point->GetXInLocal(), point->GetYInLocal(), point->GetZInLocal()),
168  posOutLocal(point->GetXOutLocal(), point->GetYOutLocal(), point->GetZOutLocal());
169 
170  TVector3 position = tube->GetPosition();
171 
172  Double_t
173  closestDistance,
174  closestDistanceError;
175 
176  //GetClostestApproachToWire(closestDistance, closestDistanceError,
177  // posInLocal, posOutLocal);
178 
179  //minimum distance ----------------
180 
181  //Double_t fd_in = sqrt(pow(point->GetXInLocal(),2)+pow(point->GetYInLocal(),2)); //[R.K. 01/2017] unused variable?
182  //cout<<fd_in<<endl;
183  double InOut[6];
184  memset(InOut, 0, sizeof(InOut));
185 
186  InOut[0] = point->GetXInLocal();
187  InOut[1] = point->GetYInLocal();
188  InOut[2] = point->GetZInLocal();
189  InOut[3] = point->GetXOutLocal();
190  InOut[4] = point->GetYOutLocal();
191  InOut[5] = point->GetZOutLocal();
192 
193  PndFtsSingleStraw fts;
194  fts.PutWireXYZ(0., 0., -75., 0., 0., 75.);
195  closestDistance = fts.TrueDist(InOut);
196  closestDistanceError =0.;
197 
198  Double_t eloss = point->GetEnergyLoss();
199  //---------------------
200 
201  Double_t
202  zpos = position.Z() + ((posOutLocal.Z() + posInLocal.Z()) / 2.),
203  zposError;
204 
205  FoldZPosWithResolution(zpos, zposError,
206  posInLocal, posOutLocal);
207 
208  // Create new hit
209  // pos.SetXYZ(position.X(), position.Y(), zpos);
210  pos.SetXYZ(position.X(), position.Y(), position.Z()); // CHECK!
211  dpos.SetXYZ(innerStrawDiameter / 2., innerStrawDiameter / 2., GetLongitudinalResolution(position.Z()));
212 
213  // if(fabs(fd_in-0.5)>0.001) continue;
214 
215  Double_t eventTime = FairRootManager::Instance()->GetEventTime();
216  Double_t flightTime = point->GetTime();
217 
218  new ((*fHitArray)[counter]) PndFtsHit(detID, tubeID, chamberID, layerID, skew, iPoint, pos, dpos, eventTime+flightTime, closestDistance, closestDistanceError, eloss * 1e6);
219 
220  new ((*fHitInfoArray)[counter]) PndFtsHitInfo(0, 0, trackID, iPoint,
221  0, kFALSE);
222  counter++;
223  } // Loop over MCPoints
224 
225  // Event summary
226  cout << "-I- PndFtsHitProducerIdeal: " << nPoints << " FtsPoints, "
227  << nPoints << " Hits created." << endl;
228 
229 }
230 // -------------------------------------------------------------------------
231 
232 // ----- Private method GetRadialResolution-------------------------------
234 {
237  radius * radius * radialResolutionPolynomialConstant3;
238 }
239 // -------------------------------------------------------------------------
240 
241 
242 
243 // ----- Private method GetLongitudinalResolution ------------------------
245 {
249 }
250 // -------------------------------------------------------------------------
251 
252 // ----- Private method GetClostestApproachToWire ------------------------
254  Double_t &closestDistanceError,
255  TVector3 localInPos,
256  TVector3 localOutPos)
257 {
258  Double_t
259  a = (localOutPos.X() - localInPos.X()),
260  b = (localOutPos.Y() - localInPos.Y()),
261  c = sqrt(a * a + b * b) / 2.;
262 
263  // fold with Gaussian for resolution
264 
265  if (c > innerStrawDiameter / 2.)
266  {
267  c = innerStrawDiameter / 2.;
268  }
269 
270  closestDistance = sqrt((innerStrawDiameter / 2.) * (innerStrawDiameter / 2.) - c * c);
271  closestDistanceError = 0.;
272 
273  if (foldResolution)
274  {
275  closestDistanceError = GetRadialResolution(closestDistance);
276  closestDistance += gRandom->Gaus(0., closestDistanceError);
277  }
278 }
279 // -------------------------------------------------------------------------
280 
282  TVector3 localInPos, TVector3 localOutPos)
283 {
284  Double_t
285  zPosInStrawFrame = (localOutPos.Z() - localInPos.Z()) / 2.;
286 
287  zposError = gRandom->Gaus(0., GetLongitudinalResolution(zPosInStrawFrame));
288 
289  zpos += zposError;
290  // cout << "zpos in prod: " << zpos << endl;
291 }
292 
293 
294 
Double_t GetXOutLocal() const
Definition: PndFtsPoint.h:59
TVector3 pos
Int_t GetChamberID()
Definition: PndFtsPoint.h:89
virtual void Exec(Option_t *opt)
#define radialResolutionPolynomialConstant3
TTree * b
#define foldResolution
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Double_t GetZOutLocal() const
Definition: PndFtsPoint.h:61
#define longitudinalResolutionPolynomialConstant3
double eloss
Definition: anaLmdSim.C:34
void SetPersistency(Bool_t val=kTRUE)
#define radialResolutionPolynomialConstant1
Double_t GetYOutLocal() const
Definition: PndFtsPoint.h:60
Double_t GetLongitudinalResolution(Double_t zpos)
void GetClostestApproachToWire(Double_t &closestDistance, Double_t &closestDistanceError, TVector3 inPos, TVector3 outPos)
Double_t GetYInLocal() const
Definition: PndFtsPoint.h:63
Double_t GetZInLocal() const
Definition: PndFtsPoint.h:64
double skew
Int_t a
Definition: anaLmdDigi.C:126
Int_t GetTubeID()
Definition: PndFtsPoint.h:86
Double_t TrueDist(Double_t Point[])
#define radialResolutionPolynomialConstant2
int counter
Definition: ZeeAnalysis.C:59
Double_t
const Double_t zpos
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
#define longitudinalResolutionPolynomialConstant1
void FoldZPosWithResolution(Double_t &zpos, Double_t &zposError, TVector3 localInPos, TVector3 localOutPos)
TVector3 GetPosition() const
Definition: PndFtsTube.cxx:68
void PutWireXYZ(Double_t w1, Double_t w2, Double_t w3, Double_t w4, Double_t w5, Double_t w6)
#define innerStrawDiameter
ClassImp(PndAnaContFact)
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast
Double_t GetRadialResolution(Double_t radius)
Double_t GetXInLocal() const
Definition: PndFtsPoint.h:62
Int_t GetLayerID()
Definition: PndFtsPoint.h:90
#define longitudinalResolutionPolynomialConstant2
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72