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