er  dev
ERmuSi.cxx
1 // -------------------------------------------------------------------------
2 // ----- ERmuSi source file -----
3 // ----- Created data by developerName -----
4 // -------------------------------------------------------------------------
5 #include "ERmuSi.h"
6 #include "FairRootManager.h"
7 #include "TClonesArray.h"
8 #include "TParticle.h"
9 #include "TVirtualMC.h"
10 #include "TString.h"
11 
12 
13 // ----- Default constructor -------------------------------------------
15  FairDetector("ERmuSi", kTRUE),
16  fERmuSiPoints(new TClonesArray("ERmuSiPoint"))
17 {
19  flGeoPar = new TList();
20  flGeoPar->SetName( GetName());
21  fVerboseLevel = 1;
22  fVersion = 1;
23 }
24 // -------------------------------------------------------------------------
25 
26 // ----- Standard constructor ------------------------------------------
27 ERmuSi::ERmuSi(const char* name, Bool_t active, Int_t verbose)
28  : FairDetector(name, active,verbose),
29  fERmuSiPoints(new TClonesArray("ERmuSiPoint"))
30  {
32  flGeoPar = new TList();
33  flGeoPar->SetName( GetName());
34  fVersion = 1;
35 }
36 
38  if (fERmuSiPoints) {
39  fERmuSiPoints->Delete();
40  delete fERmuSiPoints;
41  }
42 }
43 
45 {
46  FairDetector::Initialize();
47 }
48 
49 
50 Bool_t ERmuSi::ProcessHits(FairVolume* vol) {
51  static Int_t eventID;
52  static Int_t trackID;
53  static Int_t mot0TrackID;
54  static Double_t mass;
55  static TLorentzVector posIn, posOut;
56  static TLorentzVector momIn, momOut;
57  static Double32_t time;
58  static Double32_t length;
59  static Double32_t eLoss;
60  static Int_t station;
61 
62  if ( gMC->IsTrackEntering() ) { // Return true if this is the first step of the track in the current volume
63  eLoss = 0.;
64  eventID = gMC->CurrentEvent();
65  gMC->TrackPosition(posIn);
66  gMC->TrackMomentum(momIn);
67  trackID = gMC->GetStack()->GetCurrentTrackNumber();
68  time = gMC->TrackTime() * 1.0e09; // Return the current time of flight of the track being transported
69  length = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
70  mot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
71  mass = gMC->ParticleMass(gMC->TrackPid()); // GeV/c2
72  Int_t curVolId = gMC->CurrentVolID(station);
73  }
74 
75  eLoss += gMC->Edep(); // keV //Return the energy lost in the current step
76 
77  if (gMC->IsTrackExiting() || //Return true if this is the last step of the track in the current volume
78  gMC->IsTrackStop() || //Return true if the track energy has fallen below the threshold
79  gMC->IsTrackDisappeared())
80  {
81  gMC->TrackPosition(posOut);
82  gMC->TrackMomentum(momOut);
83 
84  if (eLoss > 0.){
85  AddPoint( eventID, trackID, mot0TrackID, mass,
86  TVector3(posIn.X(), posIn.Y(), posIn.Z()),
87  TVector3(posOut.X(), posOut.Y(), posOut.Z()),
88  TVector3(momIn.Px(), momIn.Py(), momIn.Pz()),
89  TVector3(momOut.Px(), momOut.Py(), momOut.Pz()),
90  time, length, eLoss, station);
91  }
92  }
93 
94  return kTRUE;
95 }
96 
97 // ----- Public method EndOfEvent -----------------------------------------
99 }
100 
101 
103  if (fVerboseLevel > 1) {
104  Print();
105  }
106  Reset();
107 
108 }
109 
110 // ----- Public method Register -------------------------------------------
112  FairRootManager* ioman = FairRootManager::Instance();
113  if (!ioman)
114  Fatal("Init", "IO manager is not set");
115  ioman->Register("muSiPoint","ERmuSi", fERmuSiPoints, kTRUE);
116 }
117 // ----------------------------------------------------------------------------
118 
119 // ----- Public method GetCollection --------------------------------------
120 TClonesArray* ERmuSi::GetCollection(Int_t iColl) const {
121  if (iColl == 0)
122  return fERmuSiPoints;
123  else
124  return NULL;
125 }
126 // ----------------------------------------------------------------------------
127 
128 
129 
130 // ----- Public method Print ----------------------------------------------
131 void ERmuSi::Print(Option_t *option) const
132 {
133  /*
134  for (Int_t i_point = 0; i_point < fERmuSiPoints->GetEntriesFast(); i_point++){
135  ERmuSiPoint* point = (ERmuSiPoint*)fERmuSiPoints->At(i_point);
136  point->Print();
137  }
138  */
139 }
140 // ----------------------------------------------------------------------------
141 
142 // ----- Public method Reset ----------------------------------------------
144 
145  fERmuSiPoints->Clear();
146  ResetParameters();
147 }
148 // ----------------------------------------------------------------------------
149 
150 // ----- Public method CopyClones -----------------------------------------
151 void ERmuSi::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset) {
152  Int_t nEntries = cl1->GetEntriesFast();
153  std::cout << "decector: " << nEntries << " entries to add" << std::endl;
154  TClonesArray& clref = *cl2;
155  ERmuSiPoint* oldpoint = NULL;
156  for (Int_t i=0; i<nEntries; i++) {
157  oldpoint = (ERmuSiPoint*) cl1->At(i);
158  Int_t index = oldpoint->GetTrackID() + offset;
159  oldpoint->SetTrackID(index);
160  new (clref[cl2->GetEntriesFast()]) ERmuSiPoint(*oldpoint);
161  }
162  std::cout << "decector: " << cl2->GetEntriesFast() << " merged entries" << std::endl;
163 
164 }
165 // ----------------------------------------------------------------------------
166 
167 // ----- Private method AddPoint --------------------------------------------
168 ERmuSiPoint* ERmuSi::AddPoint(Int_t eventID, Int_t trackID,
169  Int_t mot0trackID,
170  Double_t mass,
171  TVector3 posIn,
172  TVector3 posOut, TVector3 momIn,
173  TVector3 momOut, Double_t time,
174  Double_t length, Double_t eLoss, Int_t station) {
175  TClonesArray& clref = *fERmuSiPoints;
176  Int_t size = clref.GetEntriesFast();
177  return new(clref[size]) ERmuSiPoint(size, eventID, trackID, mot0trackID, mass,
178  posIn, posOut, momIn, momOut, time, length, eLoss, station);
179 
180 }
181 
182 // ----------------------------------------------------------------------------
183 
184 // ----- Public method ConstructGeometry ----------------------------------
186  TString fileName = GetGeometryFileName();
187  if(fileName.EndsWith(".root")) {
188  std::cout << "Constructing ERmuSi geometry from ROOT file " << fileName.Data() << std::endl;
189  ConstructRootGeometry();
190  } else {
191  LOG(FATAL) << "Geometry file name is not set" << std::endl;
192  }
193 
194 }
195 // ----------------------------------------------------------------------------
196 
197 // ----------------------------------------------------------------------------
198 Bool_t ERmuSi::CheckIfSensitive(std::string name)
199 {
200  TString volName = name;
201  if(volName.Contains("station")) {
202  return kTRUE;
203  }
204  return kFALSE;
205 }
206 // ----------------------------------------------------------------------------
207 
208 // ----------------------------------------------------------------------------
210 };
211 // ----------------------------------------------------------------------------
212 ClassImp(ERmuSi)
Definition: ERmuSi.h:22
virtual void BeginEvent()
Definition: ERmuSi.cxx:98
void ResetParameters()
Definition: ERmuSi.cxx:209
virtual void Initialize()
Definition: ERmuSi.cxx:44
virtual void ConstructGeometry()
Definition: ERmuSi.cxx:185
Int_t fVersion
The point collection.
Definition: ERmuSi.h:128
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition: ERmuSi.cxx:151
virtual void EndOfEvent()
Definition: ERmuSi.cxx:102
virtual ~ERmuSi()
Definition: ERmuSi.cxx:37
ERmuSi()
Definition: ERmuSi.cxx:14
virtual void Register()
Definition: ERmuSi.cxx:111
virtual void Reset()
Definition: ERmuSi.cxx:143
virtual void Print(Option_t *option="") const
Definition: ERmuSi.cxx:131
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: ERmuSi.cxx:50
virtual Bool_t CheckIfSensitive(std::string name)
Definition: ERmuSi.cxx:198
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition: ERmuSi.cxx:120
ERmuSiPoint * AddPoint(Int_t eventID, Int_t trackID, Int_t mot0trackID, Double_t mass, TVector3 posIn, TVector3 pos_out, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss, Int_t station)
geometry version
Definition: ERmuSi.cxx:168