FairRoot/PandaRoot
PndSdsDetector.cxx
Go to the documentation of this file.
1 #include "PndSdsDetector.h"
2 
3 #include "FairGeoInterface.h"
4 #include "FairGeoLoader.h"
5 #include "FairGeoNode.h"
6 #include "FairGeoRootBuilder.h"
7 #include "FairRootManager.h"
8 #include "FairRuntimeDb.h"
9 #include "FairRun.h"
10 #include "FairGeoMedia.h"
11 #include "FairGeoVolume.h"
12 #include "FairRunSim.h"
13 #include "FairVolume.h"
14 #include "FairMCEventHeader.h"
15 
16 #include "TClonesArray.h"
17 #include "TLorentzVector.h"
18 #include "TParticle.h"
19 #include "TVirtualMC.h"
20 #include "TObjArray.h"
21 #include "TList.h"
22 #include "TKey.h"
23 #include "TGeoManager.h"
24 #include "TGeoVoxelFinder.h"
25 #include "TGeoMatrix.h"
26 
27 #include "PndStack.h"
28 #include "PndSdsMCPoint.h"
29 #include "PndSdsGeo.h"
30 #include "PndSdsGeoPar.h"
31 #include "PndGeoHandling.h"
32 
33 #include <iostream>
34 #include <string>
35 #include <sstream>
36 
37 class FairVolume;
38 
39 // ----- Default constructor -------------------------------------------
41  FairDetector(),
42  fPersistance(kTRUE),
43  fTrackID(-1),
44  fVolumeID(-1),
45  fPosIn(),
46  fPosOut(),
47  fMomIn(),
48  fMomOut(),
49  fTime(0.),
50  fLength(0.),
51  fELoss(0.),
52  fGeoH(PndGeoHandling::Instance()),
53  fPosIndex(0),
54  fPndSdsCollection(NULL),
55  fUseRadDamOption(false),
56  fOutBranchName(""),
57  fFolderName(""),
58  fDetectorID(),
59  fListOfSensitives()
60 {
61 // fPndSdsCollection = new TClonesArray("PndSdsMCPoint");
62 }
63 // -------------------------------------------------------------------------
64 
65 
66 
67 // ----- Standard constructor ------------------------------------------
69 : FairDetector(name, active),
70  fPersistance(kTRUE),
71  fTrackID(-1),
72  fVolumeID(-1),
73  fPosIn(),
74  fPosOut(),
75  fMomIn(),
76  fMomOut(),
77  fTime(0.),
78  fLength(0.),
79  fELoss(0.),
80  fGeoH(PndGeoHandling::Instance()),
81  fPosIndex(0),
82  fPndSdsCollection(NULL),
83  fUseRadDamOption(false),
84  fOutBranchName(""),
85  fFolderName(""),
86  fDetectorID(),
87  fListOfSensitives()
88 {
89 // fPndSdsCollection = new TClonesArray("PndSdsMCPoint");
90 }
91 // -------------------------------------------------------------------------
92 
93 
94 
95 
96 // ----- Destructor ----------------------------------------------------
98 {
100  {
101  fPndSdsCollection->Delete();
102  delete fPndSdsCollection;
103  }
104 }
105 // -------------------------------------------------------------------------
107 {
108  std::cout<<" -I- Initializing PndSdsDetector()"<<std::endl;
109  SetBranchNames();
110 
112  if(0==gGeoManager) {
113  std::cout<<" -E- No gGeoManager in PndSdsDetector::Initialize()!"<<std::endl;
114  abort();
115  }
117  if(fVerboseLevel>0) fGeoH->PrintSensorNames();
118 }
119 
120 
121 //overwrite virtual method of FairDetector
123 {
124  // Switched off.
125  return;
126 
127  // FairRun* fRun = FairRun::Instance();
128  //
129  // //check for GEANT3, else abort
130  // if (strcmp(fRun->GetName(),"TGeant3") == 0) {
131  //
132  // //get material ID for customs settings
133  // int matIdVMC = gGeoManager->GetMedium("silicon")->GetId();
134  //
135  // //double cut_el = 1.0E-5; // (GeV)
136  // //double cut_had = 1.0E-3; // (GeV)
137  // double tofmax = 1.E10; // (s)
138  //
139  // // Set new properties, physics cuts etc. for the TPCmixture
140  // gMC->Gstpar(matIdVMC,"PAIR",1); /** pair production*/
141  // gMC->Gstpar(matIdVMC,"COMP",1); /**Compton scattering*/
142  // gMC->Gstpar(matIdVMC,"PHOT",1); /** photo electric effect */
143  // gMC->Gstpar(matIdVMC,"PFIS",0); /**photofission*/
144  // gMC->Gstpar(matIdVMC,"DRAY",1); /**delta-ray*/
145  // gMC->Gstpar(matIdVMC,"ANNI",1); /**annihilation*/
146  // gMC->Gstpar(matIdVMC,"BREM",1); /**bremsstrahlung*/
147  // gMC->Gstpar(matIdVMC,"HADR",1); /**hadronic process*/
148  // gMC->Gstpar(matIdVMC,"MUNU",1); /**muon nuclear interaction*/
149  // gMC->Gstpar(matIdVMC,"DCAY",1); /**decay*/
150  // gMC->Gstpar(matIdVMC,"LOSS",1); /**energy loss*/
151  // gMC->Gstpar(matIdVMC,"MULS",1); /**multiple scattering*/
152  // gMC->Gstpar(matIdVMC,"STRA",0);
153  // gMC->Gstpar(matIdVMC,"RAYL",1);
154  //
155  // gMC->Gstpar(matIdVMC,"CUTGAM",fCut_el); /** gammas (GeV)*/
156  // gMC->Gstpar(matIdVMC,"CUTELE",fCut_el); /** electrons (GeV)*/
157  // gMC->Gstpar(matIdVMC,"CUTNEU",fCut_had); /** neutral hadrons (GeV)*/
158  // gMC->Gstpar(matIdVMC,"CUTHAD",fCut_had); /** charged hadrons (GeV)*/
159  // gMC->Gstpar(matIdVMC,"CUTMUO",fCut_el); /** muons (GeV)*/
160  // gMC->Gstpar(matIdVMC,"BCUTE",fCut_el); /** electron bremsstrahlung (GeV)*/
161  // gMC->Gstpar(matIdVMC,"BCUTM",fCut_el); /** muon and hadron bremsstrahlung(GeV)*/
162  // gMC->Gstpar(matIdVMC,"DCUTE",fCut_el); /** delta-rays by electrons (GeV)*/
163  // gMC->Gstpar(matIdVMC,"DCUTM",fCut_el); /** delta-rays by muons (GeV)*/
164  // gMC->Gstpar(matIdVMC,"PPCUTM",fCut_el); /** direct pair production by muons (GeV)*/
165  //
166  // gMC->SetMaxNStep(1E6);
167  //
168  // Info("SetSpecialPhysicsCuts()","Using special physics cuts in MVD Sensors.");
169  // }
170 }
171 
172 
173 
174 
175 // ----- Public method ProcessHits --------------------------------------
177 {
178  // std::cout<<"-I- PndSdsDetector::ProcessHits() : called. Please remove this line soon."<<std::endl;
179  if ( gMC->IsTrackEntering() )
180  {
181  // Set parameters at entrance of volume. Reset ELoss.
182  fELoss = 0.;
183  fTime = gMC->TrackTime() * 1.0e09;
184  fLength = gMC->TrackLength();
185  gMC->TrackPosition(fPosIn);
186  gMC->TrackMomentum(fMomIn);
187  }
188 
189  // Sum energy loss for all steps in the active volume
190  fELoss += gMC->Edep();
191 
192 
193  // Create PndSdsMCPoint at exit of active volume
194 
195  if ( gMC->IsTrackExiting() ||
196  gMC->IsTrackStop() ||
197  gMC->IsTrackDisappeared() ) {
198 
199  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
200 
201  if(0==fGeoH) {
202  std::cout<<" -E- No PndGeoHandling loaded."<<std::endl;
203  abort();
204  }
205  if (fVerboseLevel > 2){
206  std::cout << "******* Info from gMC *************" << std::endl;
207  std::cout << "Hit in " << gMC->CurrentVolPath() << " with MCiD: " << vol->getMCid() << " PixelDetectorID: " << fVolumeID << std::endl;
208  std::cout<<"VolumeID: "<<fGeoH->GetShortID(gMC->CurrentVolPath())<<std::endl;
209  std::cout << "PosIn: " << fPosIn.X() << " " << fPosIn.Y() << " " << fPosIn.Z() << " " << fELoss << std::endl;
210  }
211 
212  gMC->TrackPosition(fPosOut);
213  gMC->TrackMomentum(fMomOut);
214 
215  if (fUseRadDamOption == false){
216  if (fELoss == 0.) return kFALSE;
217  }
218 
219  TString detPath = gMC->CurrentVolPath();
220  PndSdsMCPoint* myPoint = AddHit(fTrackID, FairRootManager::Instance()->GetBranchId("MCTrack"), fGeoH->GetShortID(detPath),
221  TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
222  TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()),
223  TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
224  TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()),
225  fTime, fLength, fELoss);
226 
227  if(fVerboseLevel>2) std::cout << myPoint << std::endl;
228 
229  // Increment number of PndSds points for TParticle
230  PndStack* stack = (PndStack*) gMC->GetStack();
231  stack->AddPoint(fDetectorID);
232  ResetParameters();
233  }
234 
235  return kTRUE;
236 }
237 // -------------------------------------------------------------------------
238 
239 
240 
241 // ----- Public method EndOfEvent --------------------------------------
243 {
244  if (fVerboseLevel)
245  Print();
246 
247  if (fPndSdsCollection) {
248  fPndSdsCollection->Delete();
249  } else {
250  if (fVerboseLevel > 1) {
251  std::cout << "-W- PndSdsDetector::EndOfEvent: no fPndSdsCollection pointer!" << std::endl;
252  }
253  }
254  fPosIndex = 0;
255 }
256 // -------------------------------------------------------------------------
257 
259 {
260 
261 }
262 
263 // ----- Public method Register ----------------------------------------
265 {
266  fPndSdsCollection = FairRootManager::Instance()->GetTClonesArray(fOutBranchName);
267  if (! fPndSdsCollection){
268  std::cout << "-W- PndSdsDetector: New branch " << fOutBranchName << " created!" << std::endl;
269  FairRootManager::Instance()->Register(fOutBranchName, "PndSdsMCPoint", fFolderName, kTRUE);
270  }
271  //FairRootManager::Instance()->Register(fOutBranchName, fFolderName, fPndSdsCollection, fPersistance);
272 }
273 // -------------------------------------------------------------------------
274 
275 
276 
277 // ----- Public method GetCollection -----------------------------------
278 TClonesArray* PndSdsDetector::GetCollection(Int_t iColl) const
279 {
280  if (iColl == 0)
281  return fPndSdsCollection;
282  else
283  return NULL;
284 }
285 // -------------------------------------------------------------------------
286 
287 
288 
289 // ----- Public method Print -------------------------------------------
291 {
292  Int_t
293  nHits = fPndSdsCollection->GetEntriesFast();
294 
295  std::cout << "-I- PndSdsDetector: " << nHits << " points registered in this event." << std::endl;
296 
297  if (fVerboseLevel>1)
298  for (Int_t i=0; i<nHits; i++)
299  (*fPndSdsCollection)[i]->Print();
300 }
301 // -------------------------------------------------------------------------
302 
303 
304 
305 // ----- Public method Reset -------------------------------------------
307 {
308  fPndSdsCollection->Delete();
309  ResetParameters();
310 }
311 // -------------------------------------------------------------------------
312 
313 
314 
315 // ----- Public method CopyClones --------------------------------------
316 void PndSdsDetector::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
317 {
318  Int_t
319  nEntries = cl1->GetEntriesFast();
320 
321  std::cout << "-I- PndSdsDetector: " << nEntries << " entries to add." << std::endl;
322 
323  TClonesArray& clref = *cl2;
324 
326  *oldpoint = NULL;
327  for (Int_t i=0; i<nEntries; i++)
328  {
329  oldpoint = (PndSdsMCPoint*) cl1->At(i);
330 
331  Int_t
332  index = oldpoint->GetTrackID() + offset;
333 
334  oldpoint->SetTrackID(index);
335  new (clref[fPosIndex]) PndSdsMCPoint(*oldpoint);
336  fPosIndex++;
337  }
338  std::cout << "-I- PndSdsDetector: " << cl2->GetEntriesFast() << " merged entries."
339  << std::endl;
340 }
341 
342 // -------------------------------------------------------------------------
344 {
345  // Set what is sensitive before creating geometry
346  if (fListOfSensitives.size()==0) SetDefaultSensorNames();
347  TString fileName=GetGeometryFileName();
348  if(fileName.EndsWith(".geo")){
350  }else if(fileName.EndsWith(".root")){
351  ConstructRootGeometry();
352  }else{
353  std::cout<< "Geometry format not supported " <<std::endl;
354  }
355 }
356 
357 // -------------------------------------------------------------------------
359 {
360  for (UInt_t i = 0; i < fListOfSensitives.size(); i++){
361  if (name.find(fListOfSensitives[i]) != std::string::npos)
362  return true;
363  }
364  return false;
365 }
366 
367 
368 
369 
370 // ----- Public method ConstructGeometry -------------------------------
372 {
373  // get pointer to the instantons which interface
374  // to monte carlo
375 
376  FairGeoLoader *geoLoad = FairGeoLoader::Instance();
377  FairGeoInterface *geoFace = geoLoad->getGeoInterface();
378  PndSdsGeo *thePndSdsGeo = new PndSdsGeo();
379 
380  thePndSdsGeo->setGeomFile(GetGeometryFileName());
381  geoFace->addGeoModule(thePndSdsGeo);
382 
383  Bool_t rc = geoFace->readSet(thePndSdsGeo);
384 
385  if (rc)
386  thePndSdsGeo->create(geoLoad->getGeoBuilder());
387 
388  TList* volList = thePndSdsGeo->getListOfVolumes();
389 
390  // store geo parameter
391  FairRun *fRun = FairRun::Instance();
392 
393  FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
394 
395  PndSdsGeoPar *par= (PndSdsGeoPar*)(rtdb->getContainer("PndSdsGeoPar"));
396 
397  TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
398 
399  TObjArray *fPassNodes = par->GetGeoPassiveNodes();
400 
401  TListIter iter(volList);
402 
403  FairGeoNode *node = NULL;
404  FairGeoVolume *aVol = NULL;
405 
406  while( (node = (FairGeoNode*)iter.Next()) ) {
407  aVol = dynamic_cast<FairGeoVolume*> ( node );
408  if ( node->isSensitive() ) {
409  fSensNodes->AddLast( aVol );
410  }else{
411  fPassNodes->AddLast( aVol );
412  }
413  }
414 
415  par->setChanged();
416  par->setInputVersion(fRun->GetRunId(),1);
417 
418  ProcessNodes ( volList );
419 }
420 // -------------------------------------------------------------------------
421 
422 // ----- Public method SetExclusiveSensorType -------------------------------
424 {
425  //Set one exclusive sensor type for testing purposes
426  fListOfSensitives.clear();
427  fListOfSensitives.push_back(sens.Data());
428  std::cout<<"-I- PndSdsDetector: Only active sensor type is set to \""<<sens.Data()<<"\","<<std::endl;
429  std::cout<<" this is not a default setting."<<std::endl;
430 }
431 // -------------------------------------------------------------------------
432 
433 
434 
435 // ----- Private method AddHit -----------------------------------------
436 PndSdsMCPoint* PndSdsDetector::AddHit(Int_t trackID, Int_t detID, Int_t sensorID, TVector3 posIn,TVector3 posOut,TVector3 momIn, TVector3 momOut,
437  Double_t time, Double_t length, Double_t eLoss)
438 {
439 // TClonesArray&
440 // clref = *fPndSdsCollection;
441 //
442 // Int_t
443 // size = clref.GetEntriesFast();
444  fPndSdsCollection = FairRootManager::Instance()->GetTClonesArray(fOutBranchName);
445  //FairMCEventHeader* header= (FairMCEventHeader*)FairRootManager::Instance()->GetObject("MCEventHeader.");
446 
447  if (fVerboseLevel >= 2)
448  std::cout << "-I- PndSdsDetector: Adding Point at (" << posIn.X() << ", " << posIn.Y()
449  << ", " << posIn.Z() << ") cm, (" << posOut.X() << ", " << posOut.Y()
450  << ", " << posOut.Z() << ") cm, detector " << fGeoH->GetPath(sensorID) << " " << detID << ", track "
451  << trackID << ", energy loss " << eLoss*1e06 << " keV" << std::endl;
452 
453  PndSdsMCPoint* storedData = new((*fPndSdsCollection)[fPndSdsCollection->GetEntriesFast()]) PndSdsMCPoint(trackID, detID, sensorID, posIn, posOut,
454  momIn, momOut, time, length, eLoss);
455 
456  return storedData;
457 
458 }
459 // -------------------------------------------------------------------------
460 
461 
462 
virtual void SetBranchNames()=0
virtual void SetTrackID(Int_t id)
TClonesArray * fPndSdsCollection
TLorentzVector fPosOut
entry position in global frame
Int_t fVolumeID
track index
FairGeoLoader * geoLoad
Int_t i
Definition: run_full.C:25
void SetExclusiveSensorType(const TString sens)
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
PndGeoHandling * fGeoH
Definition: anasim.C:34
TLorentzVector fMomOut
momentum
TLorentzVector fPosIn
Det id.
void CreateUniqueSensorId(TString startName, std::vector< std::string > listOfSensitives)
Has to be called during simulation to create unique sensor id.
Double_t par[3]
Int_t fPosIndex
Gives Access to the Path info of a hit.
std::vector< std::string > fListOfSensitives
To be set by daughter classes.
TVector3 offset(2, 0, 0)
TGeoManager * gGeoManager
TString GetPath(Int_t shortID)
for a given shortID the path is returned
void AddPoint(DetectorId iDet)
Definition: PndStack.cxx:408
virtual void ConstructGeometry()
FairRunAna * fRun
Definition: hit_dirc.C:58
Class to access the naming information of the MVD.
void PrintSensorNames()
int nHits
Definition: RiemannTest.C:16
Double_t
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
Double32_t fTime
momentum
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
virtual void FinishRun()
PndGeoHandling * fGeoH
energy loss
virtual Bool_t ProcessHits(FairVolume *vol=0)
virtual void SetSpecialPhysicsCuts()
virtual void Register()
TString name
virtual ~PndSdsDetector()
virtual void SetDefaultSensorNames()=0
virtual void Print() const
TObjArray * GetGeoPassiveNodes()
Definition: PndSdsGeoPar.h:27
Double32_t fLength
time
virtual void EndOfEvent()
virtual void Reset()
ClassImp(PndAnaContFact)
TObjArray * GetGeoSensitiveNodes()
Definition: PndSdsGeoPar.h:26
TString fOutBranchName
enables the detection of neutral particles
virtual void ConstructASCIIGeometry()
Double32_t fELoss
length
FairGeoInterface * geoFace
void ResetParameters()
TLorentzVector fMomIn
exit position in global frame
Mvd Initialize()
bool CheckIfSensitive(std::string name)
PndSdsMCPoint * AddHit(Int_t trackID, Int_t detID, Int_t sensorID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
TString fFolderName
To be set by daughter classes.
DetectorId fDetectorID
To be set by daughter classes.
bool fUseRadDamOption
Hit collection.
virtual TClonesArray * GetCollection(Int_t iColl) const
virtual void Initialize()