FairRoot/PandaRoot
PndSciTHitProducerIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // FairSciTProducerIdeal source file
3 //
4 // created by A. Sanchez
5 // modified by D. Steinschaden
6 // last update 04.2015
7 // -------------------------------------------------------------------------
8 
10 #include "PndSciTHit.h"
11 #include "PndSciTPoint.h"
12 
13 #include "FairRootManager.h"
14 #include "FairRunAna.h"
15 #include "FairRuntimeDb.h"
16 #include "FairGeoVector.h"
17 
18 #include "TVector3.h"
19 #include "TGeoBBox.h"
20 #include "TClonesArray.h"
21 #include "TGeoManager.h"
22 
23 #include <cmath>
24 
25 // ----- Default constructor -------------------------------------------
27  PndPersistencyTask("Ideal PndSciT Hit Producer"), fInBranchName(""), fdt(0.1) //auto time resolution 0.1 ns
28 {
29  fInBranchName = "SciTPoint";
30  fGeoH = NULL;
31  SetPersistency(kTRUE);
32 
33 }
34 // -------------------------------------------------------------------------
35 
36 // ----- Default constructor -------------------------------------------
38  PndPersistencyTask("Ideal PndSciT Hit Producer"), fInBranchName(""), fdt(dt)
39 {
40  fInBranchName = "SciTPoint";
41  fGeoH = NULL;
42  SetPersistency(kTRUE);
43 }
44 // -------------------------------------------------------------------------
45 
46 // ----- Destructor ----------------------------------------------------
48 {
49 }
50 
51 // ----- Public method Init --------------------------------------------
53 {
54  // Get RootManager
55  FairRootManager* ioman = FairRootManager::Instance();
56 
57  if ( ! ioman )
58  {
59  std::cout << "-E- PndSciTHitProducerIdeal::Init: "
60  << "RootManager not instantiated!" << std::endl;
61  return kFATAL;
62  }
63 
64  // Get input array
65  fPointArray = (TClonesArray*) ioman->GetObject(fInBranchName);
66 
67  if ( ! fPointArray )
68  {
69  std::cout << "-W- PndSciTHitProducerIdeal::Init: "
70  << "No SciTPoint array!" << std::endl;
71  return kERROR;
72  }
73 
74  // Create and register output array
75  fHitArray = ioman->Register("SciTHit", "PndSciTHit", "SciT", GetPersistency());
76 
77  std::cout << "-I- PndSciTHitProducerIdeal: Intialisation successfull" << std::endl;
78  return kSUCCESS;
79 }
80 // -------------------------------------------------------------------------
82 {
83  // Get Base Container
84  // FairRun* ana = FairRun::Instance();
85  //FairRuntimeDb* rtdb=ana->GetRuntimeDb();
86 
87  if ( fGeoH == NULL ){
88  std::cout << "ScitTil fGeoH is loading" << std::endl;
90  }
91  else std::cout << "ScitTil fGeoH is already defind but shouldn't" << std::endl;
92  if ( fGeoH == NULL ){
93  std::cout << "ScitTil fGeoH was loaded but is still NULL" << std::endl;
94  }
96 
97  return;
98 }
99 
100 
101 // ----- Public method Exec --------------------------------------------
103 {
104  // Reset output array
105  if ( ! fHitArray )
106  Fatal("Exec", "No HitArray");
107 
108  fHitArray->Delete();
109 
110 
111  // Declare some variables
112 
113  PndSciTPoint *point = NULL;
114 
115  Int_t detectorID; // Detector ID /shortID
116  TString detectorName;
117  Double_t time;
118  TVector3 zeroVector(0,0,0);
119 
120  TVector3 detectorPosition;
121  TVector3 hitPosition;
122  TVector3 sensorDim; // Sensor dimension always in half the lenghts in root!
123  TVector3 dHitPosition;
124 
125  // Loop over SciTPoints
126  Int_t
127  nPoints = fPointArray->GetEntriesFast();
128 
129  for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
130  {
131  point = (PndSciTPoint*) fPointArray->At(iPoint);
132  if (fVerbose>0) std::cout << " Ideal Hit Producer -Point-: " << point << std::endl;
133  if ( ! point)
134  continue;
135 
136  // Detector ID
137  detectorID = point->GetDetectorID();
138  detectorName = point->GetDetName();
139 
140  // HitPosition in the middle of the sensor = Detector Position
141 
142  detectorPosition = fGeoH->LocalToMasterShortId(zeroVector, detectorID);
143  hitPosition = detectorPosition;
144 
145  // Get the range for the Hit position
146 
147  // sensor Dimensions equivalent to the potential error of the hitPosition in the center of the Tile. Attention,in real its no Gaussian shaped distribution but an rectangual!!
148 
149  sensorDim = fGeoH->GetSensorDimensionsShortId(detectorID);
150  dHitPosition = sensorDim*2*(1/sqrt(12));
151 
152 
153  // produce realistic timestamp
154 
155  time = point->GetTime();//Get MCTime
156  smear(time,fdt);// smear with fdt to creat realistic Time
157 
158  // Create new hit
159  new ((*fHitArray)[iPoint]) PndSciTHit(detectorID, detectorName,
160  time+FairRootManager::Instance()->GetEventTime(), fdt,
161  0,0,0,0,
162  hitPosition,dHitPosition,
163  iPoint,
164  point->GetEnergyLoss());
165  } // Loop over MCPoints
166 
167  fHitArray->Sort();
168  // Event summary
169  if (fVerbose>1) std::cout << "-I- PndSciTHitProducerIdeal: " << nPoints << " SciTPoints, "
170  << nPoints << " Hits created." << std::endl;
171 }
172 // -------------------------------------------------------------------------
173 
174 
176 {
178 
179  Double_t t = time;
180  //std::cout<<" time "<<time<<std::endl;
181  Double_t sigt;
182 
183  sigt=gRandom->Gaus(0,dt);
184  t += sigt;
185  time = t;
186  return;
187 }
188 
189 
int fVerbose
Definition: poormantracks.C:24
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
virtual void SetParContainers()
void SetPersistency(Bool_t val=kTRUE)
TVector3 GetSensorDimensionsShortId(Int_t shortId)
Double_t
TClonesArray * point
Definition: anaLmdDigi.C:29
virtual void Exec(Option_t *opt)
static PndGeoHandling * Instance()
ClassImp(PndAnaContFact)
TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId)
TTree * t
Definition: bump_analys.C:13
TString GetDetName() const
Definition: PndSciTPoint.h:53
void smear(Double_t &time, Double_t &dt)