FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NewDetector.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 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "NewDetector.h"
9 
10 #include "FairGeoInterface.h"
11 #include "FairGeoLoader.h"
12 #include "FairGeoNode.h"
13 #include "FairGeoVolume.h"
14 #include "FairRootManager.h"
15 #include "FairRun.h"
16 #include "FairRuntimeDb.h"
17 #include "FairVolume.h"
18 #include "MyProjDetectorList.h"
19 #include "MyProjStack.h"
20 #include "NewDetectorGeo.h"
21 #include "NewDetectorGeoPar.h"
22 #include "NewDetectorPoint.h"
23 
24 #include <TGeoBBox.h>
25 #include <TGeoCompositeShape.h>
26 #include <TGeoManager.h>
27 #include <TGeoMaterial.h>
28 #include <TGeoMedium.h>
29 #include <TGeoTube.h>
30 #include <TVirtualMC.h>
31 
33  : FairDetector("NewDetector", kTRUE, kNewDetector)
34  , fTrackID(-1)
35  , fVolumeID(-1)
36  , fPos()
37  , fMom()
38  , fTime(-1.)
39  , fLength(-1.)
40  , fELoss(-1)
41  , fVectorPoints(new std::vector<NewDetectorPoint*>)
42 {}
43 
44 NewDetector::NewDetector(const char* name, Bool_t active)
45  : FairDetector(name, active, kNewDetector)
46  , fTrackID(-1)
47  , fVolumeID(-1)
48  , fPos()
49  , fMom()
50  , fTime(-1.)
51  , fLength(-1.)
52  , fELoss(-1)
53  , fVectorPoints(new std::vector<NewDetectorPoint*>)
54 {}
55 
57  : FairDetector(right)
58  , fTrackID(-1)
59  , fVolumeID(-1)
60  , fPos()
61  , fMom()
62  , fTime(-1.)
63  , fLength(-1.)
64  , fELoss(-1)
65  , fVectorPoints(new std::vector<NewDetectorPoint*>)
66 {}
67 
69 {
70  if (fVectorPoints->size()) {
71  for (auto const& x : (*fVectorPoints)) {
72  delete x;
73  }
74  fVectorPoints->clear();
75  delete fVectorPoints;
76  }
77 }
78 
80 {
86  DefineSensitiveVolumes();
87 
90  NewDetectorGeoPar* par = (NewDetectorGeoPar*)(rtdb->getContainer("NewDetectorGeoPar"));
91 }
92 
94 {
97  // Set parameters at entrance of volume. Reset ELoss.
98  if (TVirtualMC::GetMC()->IsTrackEntering()) {
99  fELoss = 0.;
100  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
101  fLength = TVirtualMC::GetMC()->TrackLength();
102  TVirtualMC::GetMC()->TrackPosition(fPos);
103  TVirtualMC::GetMC()->TrackMomentum(fMom);
104  }
105 
106  // Sum energy loss for all steps in the active volume
107  fELoss += TVirtualMC::GetMC()->Edep();
108 
109  // Create NewDetectorPoint at exit of active volume
110  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
111  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
112  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
113  fVolumeID = vol->getMCid();
114  if (fELoss == 0.) {
115  return kFALSE;
116  }
117  AddHit(fTrackID,
118  fVolumeID,
119  TVector3(fPos.X(), fPos.Y(), fPos.Z()),
120  TVector3(fMom.Px(), fMom.Py(), fMom.Pz()),
121  fTime,
122  fLength,
123  fELoss);
124 
125  // Increment number of NewDetector det points in TParticle
126  MyProjStack* stack = (MyProjStack*)TVirtualMC::GetMC()->GetStack();
127  stack->AddPoint(kNewDetector);
128  }
129 
130  return kTRUE;
131 }
132 
134 {
135  LOG(info) << "NewDetector: " << fVectorPoints->size() << " points registered in this event";
136 
137  for (auto const& x : (*fVectorPoints)) {
138  delete x;
139  }
140  fVectorPoints->clear();
141 }
142 
144 {
150  FairRootManager::Instance()->RegisterAny("NewDetectorPoint", fVectorPoints, kTRUE);
151 }
152 
153 void NewDetector::Reset()
154 {
155  for (auto const& x : (*fVectorPoints)) {
156  delete x;
157  }
158  fVectorPoints->clear();
159 }
160 
162 {
163  TGeoVolume* top = gGeoManager->GetTopVolume();
164  TGeoMedium* Si = gGeoManager->GetMedium("Si");
165  TGeoMedium* Carbon = gGeoManager->GetMedium("C");
166 
167  if (Si == 0) {
168  TGeoMaterial* matSi = new TGeoMaterial("Si", 28.0855, 14, 2.33);
169  Si = new TGeoMedium("Si", 2, matSi);
170  }
171  if (Carbon == 0) {
172  TGeoMaterial* matCarbon = new TGeoMaterial("C", 12.011, 6.0, 2.265);
173  Carbon = new TGeoMedium("C", 3, matCarbon);
174  }
175 
176  TGeoVolume* det1 = gGeoManager->MakeTubs("Det1", Si, 5, 80, 0.1, 0, 360);
177  TGeoRotation r1;
178  r1.SetAngles(0, 0, 0);
179  TGeoTranslation t1(0, 0, 0);
180  TGeoCombiTrans c1(t1, r1);
181  TGeoHMatrix* h1 = new TGeoHMatrix(c1);
182  top->AddNode(det1, 1, h1);
183  det1->SetLineColor(kGreen);
184  AddSensitiveVolume(det1);
185 
186  TGeoVolume* passive1 = gGeoManager->MakeTubs("Pass1", Si, 5, 120, 10, 0, 360);
187  TGeoRotation rp1;
188  rp1.SetAngles(0, 0, 0);
189  TGeoTranslation tp1(0, 0, 20);
190  TGeoCombiTrans cp1(tp1, rp1);
191  TGeoHMatrix* hp1 = new TGeoHMatrix(cp1);
192  top->AddNode(passive1, 1, hp1);
193  passive1->SetLineColor(kRed);
194 
195  TGeoVolume* det2 = gGeoManager->MakeTubs("Det2", Si, 5, 150, 0.1, 0, 360);
196  TGeoRotation r2;
197  r2.SetAngles(0, 0, 0);
198  TGeoTranslation t2(0, 0, 70);
199  TGeoCombiTrans c2(t2, r2);
200  TGeoHMatrix* h2 = new TGeoHMatrix(c2);
201  top->AddNode(det2, 1, h2);
202  det2->SetLineColor(kGreen);
203  AddSensitiveVolume(det2);
204 
205  TGeoVolume* det3 = gGeoManager->MakeTubs("Det3", Si, 5, 150, 0.1, 0, 360);
206  TGeoRotation r3;
207  r3.SetAngles(0, 0, 0);
208  TGeoTranslation t3(0, 0, 150);
209  TGeoCombiTrans c3(t3, r3);
210  TGeoHMatrix* h3 = new TGeoHMatrix(c3);
211  top->AddNode(det3, 1, h3);
212  det3->SetLineColor(kGreen);
213  AddSensitiveVolume(det3);
214 }
215 
217  Int_t detID,
218  TVector3 pos,
219  TVector3 mom,
220  Double_t time,
221  Double_t length,
222  Double_t eLoss)
223 {
224  NewDetectorPoint* point = new NewDetectorPoint(trackID, detID, pos, mom, time, length, eLoss);
225  fVectorPoints->push_back(point);
226  return point;
227 }
228 
229 FairModule* NewDetector::CloneModule() const { return new NewDetector(*this); }
230 
231 void NewDetector::DefineSensitiveVolumes()
232 {
233  TObjArray* volumes = gGeoManager->GetListOfVolumes();
234  TIter next(volumes);
235  TGeoVolume* volume;
236  while ((volume = static_cast<TGeoVolume*>(next()))) {
237  if (IsSensitive(volume->GetName())) {
238  LOG(debug2) << "Sensitive Volume " << volume->GetName();
239  AddSensitiveVolume(volume);
240  }
241  }
242 }
243 
244 Bool_t NewDetector::IsSensitive(const std::string& name)
245 {
246  if (name.find("Det") != std::string::npos) {
247  return kTRUE;
248  }
249  return kFALSE;
250 }
251 
void AddSensitiveVolume(TGeoVolume *v)
Definition: FairModule.cxx:294
virtual void see Tutorial4 for examples LOG(warn)<< "This function is deprecated. Use FairAlignmentHandler instead
list of container factories
Definition: FairRuntimeDb.h:24
static FairRun * Instance()
Definition: FairRun.cxx:31
virtual FairModule * CloneModule() const
static FairRootManager * Instance()
virtual void Register()
ClassImp(FairEventBuilder)
virtual ~NewDetector()
Definition: NewDetector.cxx:72
virtual Bool_t ProcessHits(FairVolume *v=0)
Definition: NewDetector.cxx:94
virtual void EndOfEvent()
FairParSet * getContainer(const Text_t *)
virtual void Initialize()
virtual void Initialize()
Definition: NewDetector.cxx:80
FairMQExParamsParOne * par
virtual void Reset()
Int_t getMCid()
Definition: FairVolume.h:57
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
virtual Bool_t IsSensitive(const std::string &name)
void AddPoint(DetectorId iDet)
NewDetectorPoint * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
void RegisterAny(const char *name, T *&obj, Bool_t toFile)
void ConstructGeometry()