FairRoot/PandaRoot
PndFtofHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- FairFtofProducerIdeal source file -----
3 // ----- Created by A. Sanchez -----
4 // -------------------------------------------------------------------------
5 
6 #include <cmath>
7 
8 #include "TClonesArray.h"
9 #include "TGeoManager.h"
10 #include "FairRootManager.h"
12 #include "PndFtofHit.h"
13 #include "TGeoBBox.h"
14 #include "TGeoBBox.h"
15 //#include "PndFtofHitInfo.h"
16 #include "PndFtofPoint.h"
17 #include "FairRunAna.h"
18 #include "FairRuntimeDb.h"
19 #include "FairGeoVector.h"
20 #include "TVector3.h"
21 
22 
23 // ----- Default constructor -------------------------------------------
25  PndPersistencyTask("Ideal PndFtof Hit Producer"), fTimeOrderedDigi(kFALSE)
26 {
27  fBranchName = "FtofPoint";
28  SetPersistency(kTRUE);
29 
30 }
31 // -------------------------------------------------------------------------
32 
33 // ----- Default constructor -------------------------------------------
35  PndPersistencyTask("Ideal PndFtof Hit Producer"), fTimeOrderedDigi(kFALSE)
36 {
37  fBranchName = "FtofPoint";
38  fdt= dt; fdt2= dt2;
39  SetPersistency(kTRUE);
40 }
41 // -------------------------------------------------------------------------
42 
43 // ----- Destructor ----------------------------------------------------
45 {
46 }
47 
48 // ----- Public method Init --------------------------------------------
50 {
51  // Get RootManager
52  FairRootManager* ioman = FairRootManager::Instance();
53 
54  if ( ! ioman )
55  {
56  std::cout << "-E- PndFtofHitProducerIdeal::Init: "
57  << "RootManager not instantiated!" << std::endl;
58  return kFATAL;
59  }
60 
61  // Get input array
62  fPointArray = (TClonesArray*) ioman->GetObject(fBranchName);
63 
64  if ( ! fPointArray )
65  {
66  std::cout << "-W- PndFtofHitProducerIdeal::Init: "
67  << "No FtofPoint array!" << std::endl;
68  return kERROR;
69  }
70 
71 
72 
73  // Create and register output array
74  fHitArray = new TClonesArray("PndFtofHit");
75  ioman->Register("FtofHit", "Ftof", fHitArray, GetPersistency());
76 
77  std::cout << "-I- PndFtofHitProducerIdeal: Intialisation successfull" << std::endl;
78  return kSUCCESS;
79 }
80 // -------------------------------------------------------------------------
82 {
83  // Get Base Container
84  //FairRun* ana = FairRun::Instance(); //[R.K. 01/2017] unused variable?
85  //FairRuntimeDb* rtdb=ana->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
86  //fGeoPar = (PndGeoFtofPar*)(rtdb->getContainer("PndGeoFtofPar"));
87 
88 }
89 
90 
91 // ----- Public method Exec --------------------------------------------
93 {
94  // Reset output array
95  if ( ! fHitArray )
96  Fatal("Exec", "No HitArray");
97 
98  fHitArray->Clear();
99 
100 
101  // Declare some variables
102  PndFtofPoint *point = 0;
103 
104  Int_t
105  detID = 0, // Detector ID
106  trackID = 0; // Track index
107 
108 
109  Double_t time = 0.;
110  //Double_t scitime = 0.; //[R.K. 01/2017] unused variable?
111  //Double_t t2 = 0.; //[R.K. 01/2017] unused variable?
112  Double_t t1 = 0.;
113  //Double_t phdt2 = 0.,tdc12 =0.,tz=0.; //[R.K. 01/2017] unused variable?
114  //Double_t phdt1 = 0.,tsig = 0.; //[R.K. 01/2017] unused variable?
115 
116  // Loop over FtofPoints
117  Int_t
118  nPoints = fPointArray->GetEntriesFast();
119 
120  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
121  {
122  point = (PndFtofPoint*) fPointArray->At(iPoint);
123  if (fVerbose>0) std::cout << " Ideal Hit Producer -Point-: " << point << std::endl;
124  if ( ! point)
125  continue;
126 
127  // Detector ID
128  detID = point->GetVolumeID();
129 
130  // MCTrack ID
131  trackID = point->GetTrackID();
132  /* // original part commented out because not working properly
133  FairGeoVector posCInL, posCOut, meanPos, meanPosL;
134  Double_t ZLoc;Double_t Ztdc[3];
135  Double_t DistZ[3];
136 
137  GetLocalHitPoints(point, posCInL,meanPos);
138 
139  TVector3 size = GetSensorDimensions(point->GetDetName().Data());
140 
141  if (meanPos.getZ()>0.)
142  {
143  tz = size.z()-meanPos.getZ();
144  phdt1 = 1.492*(tz)/30;
145  phdt2 = 1.492*(2*size.z()-tz)/30;
146  }
147  if(meanPos.getZ()<0.){
148  tz = -size.z()-meanPos.getZ();
149  phdt1 = 1.492*(2*size.z()+tz)/30;
150  phdt2 = -1.492*(tz)/30;
151  }
152  if(meanPos.getZ()==0.)phdt1=phdt2=1.492*(size.z())/30;
153 
154  // std::cout<<" z tdc "<<tz<<" z point "<<meanPos.getZ()<<std::endl;
155  // std::cout<<" t1 phot "<<phdt1<<" t2 phot "<<phdt2<<std::endl;
156 
157  tdc12 = (phdt1-phdt2);
158  tsig = 0.08;
159  smear(tdc12,tsig);
160 
161 
162  if(phdt2>phdt1){
163  ZLoc = ((tdc12*30)/(2*1.492))+size.z();
164  DistZ[2]=size.z()-ZLoc;
165  //std::cout<<" t2>t1"<<std::endl;
166 
167  }
168 
169  if(phdt1>phdt2)
170  {ZLoc = ((tdc12*30)/(2*1.492))-size.z();
171  DistZ[2]=-size.z()-ZLoc;
172  //std::cout<<" t1>t2"<<std::endl;
173  }
174 
175 
176  if(phdt1==phdt2)DistZ[2]=0.;
177 
178  DistZ[0]=DistZ[1]=0.;
179 
180  //std::cout<<" z loc "<<ZLoc<<" distz "<<DistZ[2]<<std::endl;
181 
182  TGeoHMatrix trans = GetTransformation(point->GetDetName().Data());
183  trans.LocalToMaster(DistZ, Ztdc);
184 
185 
186  //std::cout<<" z tdc "<<Ztdc[2]<<" z point "<<point->GetZin()<<std::endl;
187  // ____________/__
188  // phdt2 | @ / | phdt1, (phdt1-phdt2)c/2n=x
189  // |_________/__|
190  // L-x / x
191 
192  //phdt1 phdt 2 time signals produced at each side of the
193  //scintillator bar(scintillation process not treated
194  // i introduce some aprox. for the TDC signal
195  //to calculate the position in the bar by knowing tdc time.
196 
197 
198  //refraction index polipropilrne 1.492 poliviniltoluene 1.58
199 
200 
201 
202  TVector3 dpos;
203 
204  dpos.SetXYZ(3.,0.25,fabs(Ztdc[2]-point->GetZin()));
205 
206  // coord. of the center of the slab in lab.c.s
207  // z coord. determined by measuring t1-t2
208  // at each side of the bar
209  TVector3 position(posCInL.getX(),
210  posCInL.getY(),
211  Ztdc[2]);
212  //point->Position(pos);
213  */ // end of old part
214 
215  // Stefano's part
216  TVector3 position(0,0,0), dpos(0,0,0), fPosHit(0,0,0), fDPosHit(0,0,0);
217  TGeoNode *ftofNode = (TGeoNode*)gGeoManager->FindNode(point->GetX(), point->GetY(), point->GetZ());
218 
219  //retrieving size of the scintillator rod
220  fDPosHit[0] = ((TGeoBBox*)ftofNode->GetVolume()->GetShape())->GetDX();
221  fDPosHit[1] = ((TGeoBBox*)ftofNode->GetVolume()->GetShape())->GetDY();
222  fDPosHit[2] = ((TGeoBBox*)ftofNode->GetVolume()->GetShape())->GetDZ();
223 
224  // retrieving center of the scintillator rod
225  TGeoMatrix *ftofMat = (TGeoMatrix*)gGeoManager->GetCurrentMatrix();
226  const Double_t *ftofPos = ftofMat->GetTranslation();
227  fPosHit.SetXYZ(ftofPos[0], ftofPos[1], ftofPos[2]);
228 
229  //Filling values
230  position.SetXYZ(ftofPos[0], gRandom->Gaus(point->GetY(), 10.), ftofPos[2]); // smearing of 10 cm of McPoint
231  dpos. SetXYZ(fDPosHit[0], 10., fDPosHit[2]);
232  time = gRandom->Gaus(point->GetTime(), 0.07); //70 ps time resolution
233 
234  // Create new hit
235 // if (fTimeOrderedDigi){
236  double timeBasedTime = time + FairRootManager::Instance()->GetEventTime();
237  new ((*fHitArray)[iPoint]) PndFtofHit(trackID, detID,
238  point->GetDetName(),timeBasedTime, t1,
239  position,dpos,iPoint,
240  point->GetEnergyLoss());
241 
242 // } else {
243 // new ((*fHitArray)[iPoint]) PndFtofHit(trackID, detID,
244 // point->GetDetName(),time, t1,
245 // position,dpos,iPoint,
246 // point->GetEnergyLoss());
247 // }
248  //std::cout << "Hit created for module: " << point->GetDetName() << std::endl;
249 
250 
251 
252  } // Loop over MCPoints
253 
254 
255 
256 
257  // Event summary
258  if (fVerbose>0) std::cout << "-I- PndFtofHitProducerIdeal: " << nPoints << " FtofPoints, "
259  << nPoints << " Hits created." << std::endl;
260 
261 
262 }
263 /* // useless
264 // -------------------------------------------------------------------------
265 void PndFtofHitProducerIdeal::smear(Double_t& time, Double_t& fdt)
266 {
268 
269  Double_t t = time;
270  //std::cout<<" time "<<time<<std::endl;
271  Double_t sigt;
272 
273  sigt=gRandom->Gaus(0,fdt);
274  t += sigt;
275  time = t;
276  return;
277 }
278 
279 void PndFtofHitProducerIdeal::GetLocalHitPoints(PndFtofPoint* myPoint,
280  FairGeoVector& myHitIn,FairGeoVector& myInL)
281 {
282 
283  if (fVerbose > 1)
284  std::cout << "GetLocalHitPoints" << std::endl;
285  TGeoHMatrix trans = GetTransformation(myPoint->GetDetName().Data());
286 
287  Double_t posIn[3];
288  Double_t posOut[3];
289  Double_t posInLocal[3];
290  Double_t posOutLocal[3];
291  Double_t posCInLocal[3];
292  Double_t posCOutLocal[3];
293  Double_t posCIn[3];
294  Double_t posCOut[3];
295 
296  posIn[0] = myPoint->GetXin();
297  posIn[1] = myPoint->GetYin();
298  posIn[2] = myPoint->GetZin();
299 
300  posOut[0] = myPoint->GetXout();
301  posOut[1] = myPoint->GetYout();
302  posOut[2] = myPoint->GetZout();
303 
304  //trans.MasterToLocal(posIn, posInLocal);
305 
306  if (fVerbose > 1){
307  for (Int_t i = 0; i < 3; i++)
308  std::cout << "posIn "<< i << ": " << posIn[i] << std::endl;
309  //std::cout << "posInLOcal "<< i << ": " << posInLocal[i] << std::endl;
310  trans.Print("");
311  }
312  trans.MasterToLocal(posIn, posInLocal);
313 
314  posCInLocal[0]=0.;
315  posCInLocal[1]=0.;
316  posCInLocal[2]=0.;
317 
318  trans.LocalToMaster(posCInLocal, posCIn);
319 
320  if (fVerbose > 1) {
321  for (Int_t i = 0; i < 3; i++){
322  std::cout << "posCInLocal "<< i << ": " << posCInLocal[i] << std::endl;
323  std::cout << "posCIn "<< i << ": " << posCIn[i] << std::endl;
324  std::cout << "posInLocal "<< i << ": " << posInLocal[i] << std::endl;
325  }
326  }
327 
328  myHitIn.setVector(posCIn);
329  myInL.setVector(posInLocal);
330 
331 }
332 
333 
334 
335 
336 TGeoHMatrix PndFtofHitProducerIdeal::GetTransformation(std::string detName) const
337 {
338  gGeoManager->cd(detName.c_str());
339  TGeoHMatrix* transMat = gGeoManager->GetCurrentMatrix();
340  if (fVerbose > 1)
341  transMat->Print("");
342  return *transMat;
343 }
344 
345 TVector3 PndFtofHitProducerIdeal::GetSensorDimensions(std::string detName) const
346  {
347  gGeoManager->cd(detName.c_str());
348  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
349  TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
350  TVector3 result;
351  result.SetX(actBox->GetDX());
352  result.SetY(actBox->GetDY());
353  result.SetZ(actBox->GetDZ());
354 
355  //result.Dump();
356 
357  return result;
358  }
359 */
virtual void Exec(Option_t *opt)
int fVerbose
Definition: poormantracks.C:24
Int_t GetVolumeID() const
Definition: PndFtofPoint.h:62
void SetPersistency(Bool_t val=kTRUE)
TGeoManager * gGeoManager
Int_t t1
Definition: hist-t7.C:106
Double_t
TString GetDetName() const
Definition: PndFtofPoint.h:84
boxGen SetXYZ(0., 0., 0.)
ClassImp(PndAnaContFact)
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72