FairRoot/PandaRoot
PndSciT.cxx
Go to the documentation of this file.
1 //
3 // PndSciT
4 //
5 // created by A. Sanchez
6 // modified by D. Steinschaden
7 // last update 06.2015
9 
10 #include "PndSciT.h"
11 #include "PndSciTPoint.h"
12 //#include "PndGeoSciT.h"
13 #include "PndStack.h"
14 #include "PndDetectorList.h"
15 
16 #include "FairGeoTransform.h"
17 #include "FairGeoInterface.h"
18 #include "FairGeoLoader.h"
19 #include "FairGeoNode.h"
20 #include "FairGeoMedium.h"
21 #include "FairGeoInterface.h"
22 #include "FairGeoMedia.h"
23 //#include "FairGeoG3Builder.h"
24 #include "FairGeoRootBuilder.h"
25 #include "FairRootManager.h"
26 #include "FairVolume.h"
27 #include "FairRuntimeDb.h"
28 #include "FairRun.h"
29 
30 #include "TClonesArray.h"
31 #include "TGeoManager.h"
32 #include "TLorentzVector.h"
33 #include "TParticle.h"
34 #include "TVirtualMC.h"
35 #include "TString.h"
36 #include "TList.h"
37 #include "TGeoBBox.h"
38 #include "TGeoMCGeometry.h"
39 #include "TObjArray.h"
40 #include "TGeoVoxelFinder.h"
41 #include "TGeoMatrix.h"
42 
43 #include <string>
44 #include <sstream>
45 #include <iostream>
46 
47 using std::cout;
48 using std::endl;
49 using std::ostringstream;
50 
51 // ----- Default constructor -------------------------------------------
53  : FairDetector(), fSciTCollection(0)
54  {
55  fSciTCollection = new TClonesArray("PndSciTPoint");
56  fVerboseLevel = 0;
57  fThreshold = 0.0001; // Standard Threshold set to 100 keV
58  fGeoH = NULL;
60 
61  // Volumes containing "SENSOR" in the name will be processed in the process hit funktion
62  fListOfSensitives.push_back("SENSOR");
63 
64 }
65 // -------------------------------------------------------------------------
66 
67 // ----- Standard constructor ------------------------------------------
68 PndSciT::PndSciT(const char* name, Bool_t active)
69  : FairDetector(name, active), fSciTCollection(0)
70 {
71  fSciTCollection = new TClonesArray("PndSciTPoint");
72  fVerboseLevel = 0;
73  fThreshold = 0.0001; // Standard Threshold set to 100 keV
74 
75  fGeoH = NULL;
76  std::cout << "ScitTil fGeoH is loading" << std::endl;
78  if ( fGeoH == NULL ){
79  std::cout << "ScitTil fGeoH was loaded but is still NULL" << std::endl;
80  }
81 
82  // Volumes containing "SENSOR" in the name will be processed in the process hit funktion
83  fListOfSensitives.push_back("SENSOR");
84 
85 }
86 // -------------------------------------------------------------------------
87 
88 
89 
90 // ----- Destructor ----------------------------------------------------
92  if (fSciTCollection) {
93  fSciTCollection->Delete();
94  delete fSciTCollection;
95  }
96 
97 }
98 // -------------------------------------------------------------------------
99 
100 
101 
102 // ----- Public method Intialize ---------------------------------------
104 
105  std::cout<<" -I- Initializing PndSciT()"<<std::endl;
107  std::cout<<" Fairdetector geht"<<std::endl;
108  // not mandatory ,but may someone can make use out of the stored parameters
109  FairRun* sim = FairRun::Instance();
110  FairRuntimeDb* rtdb=sim->GetRuntimeDb();
111  par=(PndGeoSciTPar*)(rtdb->getContainer("PndGeoSciTPar"));
112  par->setChanged();
113  par->setInputVersion(sim->GetRunId(),1);
114  //-----------------------------------------------------------------
115 
116  if(0==gGeoManager) {
117  std::cout<<" -E- No gGeoManager in PndSciT::Initialize()!"<<std::endl;
118  abort();
119  }
120 
122  if(fVerboseLevel>0) fGeoH->PrintSensorNames();
123 
124  std::cout<<" -I- Initialized PndSciT()"<<std::endl;
125 }
126 // -------------------------------------------------------------------------
128  // Begin of the event
129 
130 }
131 
132 // ----- Public method ProcessHits --------------------------------------
133 
134 Bool_t PndSciT::ProcessHits(FairVolume* ) // vol //[R.K.03/2017] unused variable(s)
135 {
136 
137  if(0==fGeoH) {
138  std::cout<<" -E- No PndGeoHandling loaded."<<std::endl;
139  abort();
140  }
141 
142  // Set parameters at entrance of volume. Reset ELoss.
143  if ( gMC->IsTrackEntering() )
144  {
145  fELoss = 0.;
146  fEventID = gMC->CurrentEvent();
147  fTime = gMC->TrackTime() * 1.0e09;
148  fLength = gMC->TrackLength();
149  gMC->TrackPosition(fPosIn);
150  gMC->TrackMomentum(fMomIn);
151  }
152 
153  // Sum energy loss for all steps in the active volume
154  fELoss += gMC->Edep();
155 
156  // Set additional parameters at exit of active volume.
157  // And create the PndSciTPoint.
158  if ( (gMC->IsTrackExiting() ||
159  gMC->IsTrackStop() ||
160  gMC->IsTrackDisappeared() ))
161  {
162  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
163 
164  fdetPath = gMC->CurrentVolPath();
165  fSensorID = fGeoH->GetShortID(gMC->CurrentVolPath());
166 
167  //fSensorID = vol->getCopyNo();
168 
169  gMC->TrackPosition(fPosOut);
170  gMC->TrackMomentum(fMomOut);
171 
172  //Cut on energy loss to reduce stored data Elos < 100 keV
173  if (fELoss < fThreshold) return kFALSE;
174 
176  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
177  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
178  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
179  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
180  fTime, fLength,fELoss);
181 
182  PndStack* stack = (PndStack*) gMC->GetStack();
183  stack->AddPoint(kTOF);
184 
185  ResetParameters();
186  }
187 
188  return kTRUE;
189 
190 }//ProcessHits
191 
192 // ----------------------------------------------------------------------------
193 
194 // ----- Public method EndOfEvent -----------------------------------------
196  if (fVerboseLevel) Print();
197 
198  Reset();
199 }
200 // ----------------------------------------------------------------------------
201 
202 // ----- Public method Register -------------------------------------------
204  FairRootManager::Instance()->Register("SciTPoint","PndSciT", fSciTCollection, kTRUE);
205 
206 
207 }
208 // ----------------------------------------------------------------------------
209 
210 // ----- Public method GetCollection --------------------------------------
211 TClonesArray* PndSciT::GetCollection(Int_t iColl) const {
212  if (iColl == 0)
213  return fSciTCollection;
214  else
215  return NULL;
216 }
217 // ----------------------------------------------------------------------------
218 
219 // ----- Public method Print ----------------------------------------------
220 void PndSciT::Print() const {
221  Int_t nHits = fSciTCollection->GetEntriesFast();
222  cout << "-I- PndSciT: " << nHits << " points registered in this event."
223  << endl;
224 
225  if (fVerboseLevel>1)
226  for (Int_t i=0; i<nHits; i++) (*fSciTCollection)[i]->Print();
227 }
228 // ----------------------------------------------------------------------------
229 
230 
231 
232 // ----- Public method Reset ----------------------------------------------
234  fSciTCollection->Clear();
235 
236 
237  fPosIndex = 0;
238 }
239 // ----------------------------------------------------------------------------
240 
241 
242 
243 // ----- Public method CopyClones -----------------------------------------
244 void PndSciT::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
245  Int_t nEntries = cl1->GetEntriesFast();
246  //cout << "-I- PndSciT: " << nEntries << " entries to add." << endl;
247  TClonesArray& clref = *cl2;
248  PndSciTPoint* oldpoint = NULL;
249  for (Int_t i=0; i<nEntries; i++) {
250  oldpoint = (PndSciTPoint*) cl1->At(i);
251  Int_t index = oldpoint->GetTrackID() + offset;
252  oldpoint->SetTrackID(index);
253  new (clref[fPosIndex]) PndSciTPoint(*oldpoint);
254  fPosIndex++;
255  }
256  cout << " -I- PndSciT: " << cl2->GetEntriesFast() << " merged entries."
257  << endl;
258 }
259 // ----------------------------------------------------------------------------
260  // ----- Public method ConstructGeometry ----------------------------------
262 
263  TString fileName=GetGeometryFileName();
264 
265  if(fileName.EndsWith(".root")){
266  ConstructRootGeometry();
267  }else {
268  cout<<" geometry format not supported"<<endl;}
269 
270 }
271 
272 
273 // -------------------------------------------------------------------------
275 {
276  for (size_t i = 0; i < fListOfSensitives.size(); i++){
277  if (name.find(fListOfSensitives[i]) != std::string::npos)
278  return true;
279  }
280  return false;
281 }
282 
283 
284 // ----- Private method AddHit --------------------------------------------
285 
286 PndSciTPoint* PndSciT::AddHit(Int_t eventID, Int_t trackID, Int_t sensorID, TString detName,
287  TVector3 pos, TVector3 mom,
288  TVector3 posout,
289  TVector3 momout,
290  Double_t time,
291  Double_t length,
292  Double_t eLoss) {
293  TClonesArray& clref = *fSciTCollection;
294  Int_t size = clref.GetEntriesFast();
295  return new(clref[size]) PndSciTPoint( eventID, trackID, sensorID, detName,pos, mom,
296  posout, momout,
297  time, length, eLoss);
298  }
299 
300 // --------
301 
302 
Int_t fPosIndex
for saving parameters, although not mandatory, may someone can make use out of the stored parameters ...
Definition: PndSciT.h:153
virtual void Print() const
Definition: PndSciT.cxx:220
TVector3 pos
Double_t fThreshold
Definition: PndSciT.h:149
sim(Int_t nEvents=1, TString SimEngine="TGeant4", Float_t mom=6.231552)
virtual void Reset()
Definition: PndSciT.cxx:233
Int_t i
Definition: run_full.C:25
virtual void Initialize()
Definition: PndSciT.cxx:103
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: PndSciT.cxx:211
TLorentzVector fMomIn
Definition: PndSciT.h:142
Double_t mom
Definition: plot_dirc.C:14
TVector3 offset(2, 0, 0)
TLorentzVector fMomOut
Definition: PndSciT.h:144
PndGeoHandling * fGeoH
Definition: PndSciT.h:151
TGeoManager * gGeoManager
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
virtual void EndOfEvent()
Definition: PndSciT.cxx:195
void PrintSensorNames()
int nHits
Definition: RiemannTest.C:16
Double_t
TString fdetPath
Definition: PndSciT.h:139
Int_t fSensorID
Definition: PndSciT.h:138
virtual void BeginEvent()
Definition: PndSciT.cxx:127
virtual ~PndSciT()
Definition: PndSciT.cxx:91
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Int_t fEventID
Definition: PndSciT.h:136
PndSciT()
Definition: PndSciT.cxx:52
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
static PndGeoHandling * Instance()
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: PndSciT.cxx:134
TString name
virtual void Register()
Definition: PndSciT.cxx:203
std::vector< std::string > fListOfSensitives
Definition: PndSciT.h:132
Double_t fELoss
Definition: PndSciT.h:148
virtual void ConstructGeometry()
Definition: PndSciT.cxx:261
TLorentzVector fPosOut
Definition: PndSciT.h:143
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: PndSciT.cxx:244
TLorentzVector fPosIn
Definition: PndSciT.h:141
ClassImp(PndAnaContFact)
Double32_t fLength
Definition: PndSciT.h:147
bool CheckIfSensitive(std::string name)
Definition: PndSciT.cxx:274
PndSciTPoint * AddHit(Int_t eventID, Int_t trackID, Int_t sensorID, TString detName, TVector3 posin, TVector3 momin, TVector3 posout, TVector3 momout, Double_t tof, Double_t length, Double_t eLoss)
Definition: PndSciT.cxx:286
Int_t fTrackID
Definition: PndSciT.h:137
PndGeoSciTPar * par
Gives Access to the Path info of a hit.
Definition: PndSciT.h:152
Mvd Initialize()
TClonesArray * fSciTCollection
Definition: PndSciT.h:154
void ResetParameters()
Definition: PndSciT.h:164
Double32_t fTime
Definition: PndSciT.h:146