ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtSeGA.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "AtSeGA.h"
9 
10 #include "AtDetectorList.h"
11 #include "AtMCPoint.h"
12 #include "AtStack.h"
13 
14 #include <FairLogger.h> // for Logger, LOG
15 #include <FairRootManager.h>
16 #include <FairVolume.h>
17 
18 #include <TClonesArray.h>
19 #include <TLorentzVector.h>
20 #include <TVirtualMC.h>
21 #include <TVirtualMCStack.h> // for TVirtualMCStack
22 
23 #include <iostream>
24 using std::cout;
25 using std::endl;
26 
28  : FairDetector("AtSeGA", kTRUE, kAtSeGA), fTrackID(-1), fVolumeID(-1), fDetCopyID(-1), fTime(-1.), fLength(-1.),
29  fELoss(-1), fAtSeGAPointCollection(new TClonesArray("AtMCPoint")), fELossAcc(-1)
30 {
31 }
32 
33 AtSeGA::AtSeGA(const char *name, Bool_t active)
34  : FairDetector(name, active, kAtSeGA), fTrackID(-1), fVolumeID(-1), fDetCopyID(-1), fTime(-1.), fLength(-1.),
35  fELoss(-1), fAtSeGAPointCollection(new TClonesArray("AtMCPoint")), fELossAcc(-1)
36 {
37 }
38 
40 {
41  if (fAtSeGAPointCollection) {
42  fAtSeGAPointCollection->Delete();
43  delete fAtSeGAPointCollection;
44  }
45 }
46 
48 {
49  FairDetector::Initialize();
50  // AtSeGAGeoPar* par=(AtSeGAGeoPar*)(rtdb->getContainer("AtSeGAGeoPar"));
51  LOG(INFO) << "AtSeGA: initialisation";
52 }
53 
54 Bool_t AtSeGA::ProcessHits(FairVolume *vol)
55 {
58  auto *stack = dynamic_cast<AtStack *>(gMC->GetStack());
59  fVolName = gMC->CurrentVolName();
60 
61  TLorentzVector fPosIn;
62  TLorentzVector fMomIn;
63 
64  if (gMC->IsTrackEntering()) {
65  fELoss = 0.;
66  fELossAcc = 0.;
67  fTime = gMC->TrackTime() * 1.0e09;
68  }
69 
70  //
71  fELoss = gMC->Edep(); // in GeV
72  fELossAcc += fELoss;
73 
74  // Set additional parameters at exit of active volume. Create Point.
75  if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
76  fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
77  fVolumeID = vol->getMCid();
78  fDetCopyID = vol->getCopyNo();
79  fLength = gMC->TrackLength();
80  gMC->TrackPosition(fPosIn);
81  gMC->TrackMomentum(fMomIn);
82 
83  if (fELossAcc == 0.)
84  return kFALSE;
85 
86  AddPoint(fTrackID, fVolumeID, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
87  TVector3(fMomIn.X(), fMomIn.Y(), fMomIn.Z()), fTime, fLength, fELossAcc);
88 
89  stack->AddPoint(kAtSeGA);
90  }
91  return kTRUE;
92 }
93 
95 {
96  Print();
97  Reset();
98 }
99 
101 {
102 
109  FairRootManager::Instance()->Register("AtMCPoint", "AtSeGA", fAtSeGAPointCollection, kTRUE);
110 }
111 
112 TClonesArray *AtSeGA::GetCollection(Int_t iColl) const
113 {
114  if (iColl == 0) {
115  return fAtSeGAPointCollection;
116  } else {
117  return nullptr;
118  }
119 }
120 
122 {
123  fAtSeGAPointCollection->Clear();
124 }
125 
126 void AtSeGA::Print(Option_t *option) const
127 {
128  Int_t nHits = fAtSeGAPointCollection->GetEntriesFast();
129  LOG(INFO) << "SEGA: " << nHits << " points registered in this event";
130 }
131 
133 {
134  TString fileName = GetGeometryFileName();
135  if (fileName.EndsWith(".geo")) {
136  LOG(INFO) << "Constructing SEGA geometry from ASCII file " << fileName;
137  // ConstructASCIIGeometry();
138  } else if (fileName.EndsWith(".root")) {
139  LOG(INFO) << "Constructing SEGA geometry from ROOT file " << fileName;
140  ConstructRootGeometry();
141  } else {
142  std::cout << "Geometry format not supported." << std::endl;
143  }
144 }
145 
146 Bool_t AtSeGA::CheckIfSensitive(std::string name)
147 {
148  TString tsname = name;
149  if (tsname.Contains("Crystal_")) {
150  LOG(INFO) << " SeGA geometry: Sensitive volume found: " << tsname;
151  return kTRUE;
152  }
153  return kFALSE;
154 }
155 
156 // ----- Private method AddPoint --------------------------------------------
157 AtMCPoint *
158 AtSeGA::AddPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
159 {
160  TClonesArray &clref = *fAtSeGAPointCollection;
161  Int_t size = clref.GetEntriesFast();
162  if (fVerboseLevel > 1)
163  LOG(INFO) << "SEGA: Adding Point in detector " << detID << ", track " << trackID << ", energy loss "
164  << eLoss * 1e06 << " keV";
165 
166  auto point = new (clref[size]) AtMCPoint(trackID, detID, pos, mom, time, length, eLoss);
167  point->SetVolName(fVolName);
168  point->SetDetCopyID(fDetCopyID);
169  return point;
170 }
171 
AtDetectorList.h
AtSeGA::GetCollection
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: AtSeGA.cxx:112
AtSeGA::AtSeGA
AtSeGA()
Definition: AtSeGA.cxx:27
ClassImp
ClassImp(AtFindVertex)
AtSeGA::EndOfEvent
virtual void EndOfEvent()
Definition: AtSeGA.cxx:94
AtSeGA
Definition: AtSeGA.h:25
AtSeGA::Initialize
virtual void Initialize()
Definition: AtSeGA.cxx:47
AtMCPoint::SetVolName
void SetVolName(TString VolName)
Definition: AtMCPoint.h:75
AtSeGA::Register
virtual void Register()
Definition: AtSeGA.cxx:100
AtSeGA::ProcessHits
virtual Bool_t ProcessHits(FairVolume *v=0)
Definition: AtSeGA.cxx:54
AtSeGA.h
AtSeGA::CheckIfSensitive
Bool_t CheckIfSensitive(std::string name)
Definition: AtSeGA.cxx:146
AtStack.h
AtMCPoint.h
AtSeGA::Print
virtual void Print(Option_t *option="") const
Definition: AtSeGA.cxx:126
AtSeGA::Reset
virtual void Reset()
Definition: AtSeGA.cxx:121
AtSeGA::ConstructGeometry
void ConstructGeometry()
Definition: AtSeGA.cxx:132
AtMCPoint
Definition: AtMCPoint.h:26
AtStack
Definition: AtStack.h:54
kAtSeGA
@ kAtSeGA
Definition: AtDetectorList.h:30
AtSeGA::~AtSeGA
virtual ~AtSeGA()
Definition: AtSeGA.cxx:39