er  dev
ERSensPlane.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
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 
9 // ------------------------------------------------------------------------------
10 // ----- ERSensPlane detector source file -----
11 // ------------------------------------------------------------------------------
12 
13 #include "ERSensPlane.h"
14 
15 #include "TClonesArray.h"
16 #include "TLorentzVector.h"
17 #include "TParticle.h"
18 #include "TString.h"
19 #include "TVirtualMC.h"
20 #include "TGeoMatrix.h"
21 
22 #include "FairRootManager.h"
23 #include "FairLogger.h"
24 
25 #include "ERSensPlanePoint.h"
26 
27 // ----- Default constructor ------------------------------------------------
29  : FairDetector("ERSensPlane", kTRUE)
30 {
31  fPoints = new TClonesArray("ERSensPlanePoint", 1000);
32  fPositionRotation = new TGeoCombiTrans("ERSensPlanePosRot", 0., 0., 0.,
33  new TGeoRotation("ERSensPlaneRot", 0., 0., 0.));
34 }
35 // ------------------------------------------------------------------------------
36 
37 // ----- Standard constructor -----------------------------------------------
38 ERSensPlane::ERSensPlane(const char* name, Bool_t active)
39  : FairDetector(name, active)
40 {
41  fPoints = new TClonesArray("ERSensPlanePoint", 1000);
42  fPositionRotation = new TGeoCombiTrans("ERSensPlanePosRot", 0., 0., 0.,
43  new TGeoRotation("ERSensPlaneRot", 0., 0., 0.));
44 }
45 // ------------------------------------------------------------------------------
46 
47 // ------------------------------------------------------------------------------
49 {
50  if (fPoints) {
51  fPoints->Delete();
52  delete fPoints;
53  }
54  if (fPositionRotation) {
55  delete fPositionRotation;
56  }
57 }
58 // ------------------------------------------------------------------------------
59 
60 // ------------------------------------------------------------------------------
61 void ERSensPlane::SetDetectorPosition(Double_t x, Double_t y, Double_t z)
62 {
63  fPositionRotation->SetDx(x);
64  fPositionRotation->SetDy(y);
65  fPositionRotation->SetDz(z);
66 }
67 // ------------------------------------------------------------------------------
68 
69 // ------------------------------------------------------------------------------
70 void ERSensPlane::Initialize()
71 {
72  FairDetector::Initialize(); //TODO needed?
73 }
74 // ------------------------------------------------------------------------------
75 
76 // ------------------------------------------------------------------------------
77 Bool_t ERSensPlane::ProcessHits(FairVolume* vol)
78 {
79  static Int_t eventID;
80  static Int_t trackID;
81  static Int_t mot0TrackID;
82  static Double_t mass;
83  static TLorentzVector posIn, posOut;
84  static TLorentzVector momIn, momOut;
85  static Double32_t time;
86  static Double32_t length;
87  static Double32_t eLoss;
88 
89  //LOG(INFO) << "ERSensPlane::ProcessHits" << FairLogger::endl;
90 
91  if (gMC->IsTrackEntering()) {
92  // Return true if this is the first step of the track in the current volume
93  eLoss = 0.;
94  eventID = gMC->CurrentEvent();
95  gMC->TrackPosition(posIn);
96  gMC->TrackMomentum(momIn);
97  trackID = gMC->GetStack()->GetCurrentTrackNumber();
98  time = gMC->TrackTime() * 1.0e09; // Return the current time of flight of the track being transported
99  length = gMC->TrackLength(); // Return the length of the current track from its origin (in cm)
100  mot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
101  mass = gMC->ParticleMass(gMC->TrackPid()); // GeV/c2
102  }
103 
104  eLoss += gMC->Edep(); // GeV // Return the energy lost in the current step
105 
106  if (gMC->IsTrackExiting() || // Return true if this is the last step of the track in the current volume
107  gMC->IsTrackStop() || // Return true if the track energy has fallen below the thresho
108  gMC->IsTrackDisappeared())
109  {
110  gMC->TrackPosition(posOut);
111  gMC->TrackMomentum(momOut);
112  //if (eLoss > 0.) // TODO tune
113  {
114  AddPoint (eventID,
115  trackID,
116  mot0TrackID,
117  mass,
118  TVector3(posIn.X(), posIn.Y(), posIn.Z()),
119  TVector3(posOut.X(), posOut.Y(), posOut.Z()),
120  TVector3(momIn.Px(), momIn.Py(), momIn.Pz()),
121  TVector3(momOut.Px(), momOut.Py(), momOut.Pz()),
122  time,
123  length,
124  eLoss);
125  }
126  }
127 
128  return kTRUE;
129 }
130 // ------------------------------------------------------------------------------
131 
132 // ------------------------------------------------------------------------------
133 void ERSensPlane::BeginEvent() {
134 }
135 // ------------------------------------------------------------------------------
136 
137 // ------------------------------------------------------------------------------
138 void ERSensPlane::EndOfEvent() {
139  Print();
140  Reset();
141 }
142 // ------------------------------------------------------------------------------
143 
144 // ------------------------------------------------------------------------------
145 void ERSensPlane::Register() {
146  FairRootManager* ioman = FairRootManager::Instance();
147  if (!ioman) Fatal("Init", "IO manager is not set");
148  ioman->Register("ERSensPlanePoint", "ERSensPlane", fPoints, kTRUE);
149 }
150 // ------------------------------------------------------------------------------
151 
152 // ------------------------------------------------------------------------------
153 TClonesArray* ERSensPlane::GetCollection(Int_t iColl) const {
154  if (iColl == 0) {
155  return fPoints;
156  } else {
157  return NULL;
158  }
159 }
160 // ------------------------------------------------------------------------------
161 
162 // ----- Public method Print ------------------------------------------------
163 void ERSensPlane::Print(Option_t *option) const {
164 }
165 // ------------------------------------------------------------------------------
166 
167 // ----- Public method Reset ------------------------------------------------
168 void ERSensPlane::Reset() {
169 // LOG(INFO) << "ERSensPlane::Reset()" << FairLogger::endl;
170  fPoints->Clear();
171 }
172 // ------------------------------------------------------------------------------
173 
174 // ----- Public method CopyClones -------------------------------------------
175 void ERSensPlane::CopyClones(TClonesArray* cl1,
176  TClonesArray* cl2,
177  Int_t offset) {
178 }
179 // ------------------------------------------------------------------------------
180 
181 // ----- Public method ConstructGeometry ------------------------------------
182 void ERSensPlane::ConstructGeometry()
183 {
184  TString fileName = GetGeometryFileName();
185  if (fileName == "") {
186  LOG(FATAL) << "ERSensPlane geometry file name is not set." << FairLogger::endl;
187  } else if(fileName.EndsWith(".root")) {
188  LOG(INFO) << "Constructing ERSensPlane geometry from ROOT file " << fileName.Data() << FairLogger::endl;
189  ConstructRootGeometry((TGeoMatrix*)(fPositionRotation));
190  } else if(fileName.EndsWith(".gdml")) {
191  LOG(INFO) << "Constructing ERSensPlane geometry from GDML file " << fileName.Data() << FairLogger::endl;
192  ConstructGDMLGeometry(fPositionRotation);
193  } else {
194  LOG(FATAL) << "ERSensPlane geometry file name is not correct." << FairLogger::endl;
195  }
196 }
197 // ------------------------------------------------------------------------------
198 
199 // ------------------------------------------------------------------------------
200 Bool_t ERSensPlane::CheckIfSensitive(std::string name)
201 {
202  //LOG(INFO) << "ERSensPlane::CheckIfSensitive for " << name << FairLogger::endl;
203  return kTRUE;
204 }
205 // ------------------------------------------------------------------------------
206 
207 // ----- Private method AddPoint --------------------------------------------
208 ERSensPlanePoint* ERSensPlane::AddPoint(Int_t eventID,
209  Int_t trackID,
210  Int_t mot0trackID,
211  Double_t mass,
212  TVector3 posIn,
213  TVector3 posOut,
214  TVector3 momIn,
215  TVector3 momOut,
216  Double_t time,
217  Double_t length,
218  Double_t eLoss)
219 {
220  //LOG(INFO) << "ERSensPlane::AddPoint eventID=" << eventID << FairLogger::endl;
221  TClonesArray& clref = *fPoints;
222  Int_t size = clref.GetEntriesFast();
223  return new(clref[size]) ERSensPlanePoint(eventID,
224  trackID,
225  mot0trackID,
226  mass,
227  posIn,
228  posOut,
229  momIn,
230  momOut,
231  time,
232  length,
233  eLoss);
234 }
235 // ------------------------------------------------------------------------------
236 
237 ClassImp(ERSensPlane)
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition: ERSensPlane.cxx:77
virtual ~ERSensPlane()
Definition: ERSensPlane.cxx:48