FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pixel.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 "Pixel.h"
9 
10 #include "FairDetectorList.h" // for DetectorId::kTutDet
11 #include "FairLogger.h" // for logging
12 #include "FairRootManager.h" // for FairRootManager
13 #include "FairRunSim.h" // for FairRunSim
14 #include "FairStack.h" // for FairStack
15 #include "FairVolume.h" // for FairVolume
16 #include "PixelGeo.h"
17 #include "PixelGeoPar.h"
18 #include "PixelPoint.h"
19 
20 #include <TClonesArray.h> // for TClonesArray
21 #include <TGeoManager.h>
22 #include <TGeoMatrix.h>
23 #include <TGeoPhysicalNode.h>
24 #include <TString.h> // for TString
25 #include <TVirtualMC.h> // for TVirtualMC
26 #include <TVirtualMCStack.h> // for TVirtualMCStack
27 #include <iostream>
28 
29 using std::cout;
30 using std::endl;
31 
33  : FairDetector("Pixel", kTRUE, kPixel)
34  , fTrackID(-1)
35  , fVolumeID(-1)
36  , fPos()
37  , fMom()
38  , fTime(-1.)
39  , fLength(-1.)
40  , fELoss(-1)
41  , fPixelPointCollection(new TClonesArray("PixelPoint"))
42 {}
43 
44 Pixel::Pixel(const char* name, Bool_t active)
45  : FairDetector(name, active, kPixel)
46  , fTrackID(-1)
47  , fVolumeID(-1)
48  , fPos()
49  , fMom()
50  , fTime(-1.)
51  , fLength(-1.)
52  , fELoss(-1)
53  , fPixelPointCollection(new TClonesArray("PixelPoint"))
54 {}
55 
56 Pixel::Pixel(const Pixel& rhs)
57  : FairDetector(rhs)
58  , fTrackID(-1)
59  , fVolumeID(-1)
60  , fPos()
61  , fMom()
62  , fTime(-1.)
63  , fLength(-1.)
64  , fELoss(-1)
65  , fPixelPointCollection(new TClonesArray("PixelPoint"))
66 {}
67 
69 {
70  if (fPixelPointCollection) {
71  fPixelPointCollection->Delete();
72  delete fPixelPointCollection;
73  }
74 }
75 
77 
79 {
81  // Set parameters at entrance of volume. Reset ELoss.
82  if (TVirtualMC::GetMC()->IsTrackEntering()) {
83  fELoss = 0.;
84  fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09;
85  fLength = TVirtualMC::GetMC()->TrackLength();
86  TVirtualMC::GetMC()->TrackPosition(fPos);
87  TVirtualMC::GetMC()->TrackMomentum(fMom);
88  }
89 
90  // Sum energy loss for all steps in the active volume
91  fELoss += TVirtualMC::GetMC()->Edep();
92 
93  // Create PixelPoint at exit of active volume
94  if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
95  || TVirtualMC::GetMC()->IsTrackDisappeared()) {
96  fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
97  fVolumeID = vol->getMCid();
98 
99  if (fELoss == 0.) {
100  return kFALSE;
101  }
102 
103  // Taking stationNr and sectorNr from string is almost effortless.
104  // Simulation of 100k events with 5 pions without magnetic field takes:
105  // - Real time 142.366 s, CPU time 140.32s WITH USING VolPath TO GET fVolumeID
106  // - Real time 142.407 s, CPU time 140.64s WITHOUT THE FOLLOWING TString OPERATIONS
107  {
108  TString detPath = TVirtualMC::GetMC()->CurrentVolPath();
109  detPath.Remove(0, detPath.Last('/') + 1);
110  detPath.Remove(0, detPath.First("Pixel") + 5);
111  Int_t stationNr = detPath.Atoi();
112  detPath.Remove(0, detPath.First("_") + 1);
113  Int_t sectorNr = detPath.Atoi();
114  fVolumeID = stationNr * 256 + sectorNr;
115  }
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 Pixel det points in TParticle
126  FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
127  stack->AddPoint(kPixel);
128  }
129 
130  return kTRUE;
131 }
132 
133 void Pixel::EndOfEvent() { fPixelPointCollection->Clear(); }
134 
136 {
143  FairRootManager::Instance()->Register("PixelPoint", "Pixel", fPixelPointCollection, kTRUE);
144 }
145 
146 TClonesArray* Pixel::GetCollection(Int_t iColl) const
147 {
148  if (iColl == 0) {
149  return fPixelPointCollection;
150  } else {
151  return nullptr;
152  }
153 }
154 
155 void Pixel::Reset() { fPixelPointCollection->Clear(); }
156 
158 {
163  PixelGeo* Geo = new PixelGeo();
164  ConstructASCIIGeometry<PixelGeo, PixelGeoPar>(Geo, "PixelGeoPar");
165 }
166 
167 Bool_t Pixel::IsSensitive(const std::string& name)
168 {
169  if (name.find("Pixel") != std::string::npos) {
170  return kTRUE;
171  }
172  return kFALSE;
173 }
174 
175 PixelPoint* Pixel::AddHit(Int_t trackID,
176  Int_t detID,
177  TVector3 pos,
178  TVector3 mom,
179  Double_t time,
180  Double_t length,
181  Double_t eLoss)
182 {
183  TClonesArray& clref = *fPixelPointCollection;
184  Int_t size = clref.GetEntriesFast();
185  return new (clref[size]) PixelPoint(trackID, detID, pos, mom, time, length, eLoss);
186 }
187 
188 FairModule* Pixel::CloneModule() const { return new Pixel(*this); }
189 
190 extern "C" void ExternCreateDetector()
191 {
192  using std::cout;
193  using std::endl;
194 
195  cout << "-- ExternCreateDetector() START --" << endl;
197 
198  Pixel* det = new Pixel("PixelDetector", kTRUE);
199  det->SetGeometryFileName("pixel.geo");
200  run->AddModule(det);
201  cout << "-- ExternCreateDetector(" << det->GetName() << ") DONE --" << endl;
202 }
203 
204 ClassImp(Pixel);
virtual void SetGeometryFileName(TString fname, TString geoVer="0")
Definition: FairModule.cxx:199
virtual void Reset()
Definition: Pixel.cxx:155
virtual FairModule * CloneModule() const
Definition: Pixel.cxx:188
Pixel()
Definition: Pixel.cxx:32
virtual Bool_t ProcessHits(FairVolume *v=0)
Definition: Pixel.cxx:78
static FairRootManager * Instance()
static FairRunSim * Instance()
Definition: FairRunSim.cxx:116
ClassImp(FairEventBuilder)
virtual Bool_t IsSensitive(const std::string &name)
Definition: Pixel.cxx:167
void ConstructGeometry()
Definition: Pixel.cxx:157
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: Pixel.cxx:146
virtual void Initialize()
Definition: Pixel.h:21
virtual void Initialize()
Definition: Pixel.cxx:76
virtual void EndOfEvent()
Definition: Pixel.cxx:133
PixelPoint * AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss)
Definition: Pixel.cxx:175
virtual ~Pixel()
Definition: Pixel.cxx:68
Int_t getMCid()
Definition: FairVolume.h:57
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
void ExternCreateDetector()
Definition: Pixel.cxx:190
void AddModule(FairModule *Mod)
Definition: FairRunSim.cxx:118
void AddPoint(DetectorId iDet)
Definition: FairStack.cxx:344
virtual void Register()
Definition: Pixel.cxx:135