Project
Loading...
Searching...
No Matches
FairTrajFilter.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// ********************************************* //
9// *** D. Kresan 2004-Sep-14 *** //
10// *** D.Kresan@gsi.de *** //
11// ********************************************* //
12
13#include "FairTrajFilter.h"
14
15#include "FairRootManager.h" // for FairRootManager
16
17#include <TClonesArray.h> // for TClonesArray
18#include <TError.h> // for Fatal
19#include <TGeoBBox.h>
20#include <TGeoManager.h>
21#include <TGeoVolume.h>
22#include <TMath.h> // for Pi, TwoPi, Log
23#include <TMathBase.h> // for Abs
24#include <TParticle.h> // for TParticle
25#include <iostream> // for operator<<, basic_ostream, etc
26
27using namespace std;
28
30
31TMCThreadLocal FairTrajFilter* FairTrajFilter::fgInstance = nullptr;
32
34
36 : fVxMin(-2000.)
37 , fVxMax(2000.)
38 , fVyMin(-2000.)
39 , fVyMax(2000.)
40 , fVzMin(-2000.)
41 , fVzMax(2000.)
42 , fPMin(0.)
43 , fPMax(1e10)
44 , fThetaMin(0.)
45 , fThetaMax(TMath::Pi())
46 , fPhiMin(0.)
47 , fPhiMax(TMath::TwoPi())
48 , fPxMin(-1e10)
49 , fPxMax(1e10)
50 , fPyMin(-1e10)
51 , fPyMax(1e10)
52 , fPzMin(-1e10)
53 , fPzMax(1e10)
54 , fPtMin(0.)
55 , fPtMax(1e10)
56 , fRapidityMin(-1e10)
57 , fRapidityMax(1e10)
58 , fKinCutType(0)
59 , // polar system by default
60 fEtotMin(0.)
61 , fEtotMax(1e10)
62 , fStorePrim(kTRUE)
63 , fStoreSec(kTRUE)
64 , fStepSizeMin(0.1)
65 , // 1mm by default
66 fTrackCollection(new TClonesArray("TGeoTrack"))
67 , fCurrentTrk(nullptr)
68{
69 if (nullptr != fgInstance) {
70 Fatal("FairTrajFilter", "Singleton class already exists.");
71 return;
72 }
73
74 fgInstance = this;
75}
76
77FairTrajFilter::~FairTrajFilter() { fgInstance = nullptr; }
78
79void FairTrajFilter::Init(TString brName, TString folderName)
80{
81 FairRootManager::Instance()->Register(brName.Data(), folderName.Data(), fTrackCollection, kTRUE);
82}
83
84void FairTrajFilter::Reset() { fTrackCollection->Delete(); }
85
86Bool_t FairTrajFilter::IsAccepted(const TParticle* p) const
87{
88 if (nullptr == p) {
89 return kFALSE;
90 }
91
92 // Apply vertex cut
93 if ((p->Vx() < fVxMin) || (p->Vx() > fVxMax) || (p->Vy() < fVyMin) || (p->Vy() > fVyMax) || (p->Vz() < fVzMin)
94 || (p->Vz() > fVzMax)) {
95 return kFALSE;
96 }
97
98 // Apply cut on kinematics
99 if (0 == fKinCutType) {
100 if ((p->P() < fPMin) || (p->P() > fPMax) || (p->Theta() < fThetaMin) || (p->Theta() > fThetaMax)
101 || (p->Phi() < fPhiMin) || (p->Phi() > fPhiMax)) {
102 return kFALSE;
103 }
104 } else if (1 == fKinCutType) {
105 if ((p->Px() < fPxMin) || (p->Px() > fPxMax) || (p->Py() < fPyMin) || (p->Py() > fPyMax) || (p->Pz() < fPzMin)
106 || (p->Pz() > fPzMax)) {
107 return kFALSE;
108 }
109 } else {
110 Double_t rapidity = 0.5 * TMath::Log((p->Energy() + p->Pz()) / (p->Energy() - p->Pz()));
111 if ((p->Pt() < fPtMin) || (p->Pt() > fPtMax) || (rapidity < fRapidityMin) || (rapidity > fRapidityMax)) {
112 return kFALSE;
113 }
114 }
115
116 // Apply energy cut
117 if ((p->Energy() < fEtotMin) || (p->Energy() > fEtotMax)) {
118 return kFALSE;
119 }
120
121 // Apply generation cut
122 if (-1 == p->GetFirstMother()) {
123 if (kFALSE == fStorePrim) {
124 return kFALSE;
125 }
126 } else {
127 if (kFALSE == fStoreSec) {
128 return kFALSE;
129 }
130 }
131
132 return kTRUE;
133}
134
136 Double_t vyMin,
137 Double_t vzMin,
138 Double_t vxMax,
139 Double_t vyMax,
140 Double_t vzMax)
141{
142 TGeoBBox* cave = static_cast<TGeoBBox*>(gGeoManager->GetTopVolume()->GetShape());
143 cave->ComputeBBox();
144 Double_t caveX = 2. * cave->GetDX();
145 Double_t caveY = 2. * cave->GetDY();
146 Double_t caveZ = 2. * cave->GetDZ();
147 if ((vxMax < vxMin) || (vyMax < vyMin) || (vzMax < vzMin) || (TMath::Abs(vxMin) > caveX)
148 || (TMath::Abs(vxMax) > caveX) || (TMath::Abs(vyMin) > caveY) || (TMath::Abs(vyMax) > caveY)
149 || (TMath::Abs(vzMin) > caveZ) || (TMath::Abs(vzMax) > caveZ)) {
150 cout << "-E- FairTrajFilter::SetVertexCut() : invalid region, ignoring." << endl;
151 return;
152 }
153 fVxMin = vxMin;
154 fVxMax = vxMax;
155 fVyMin = vyMin;
156 fVyMax = vyMax;
157 fVzMin = vzMin;
158 fVzMax = vzMax;
159}
160
162 Double_t thetaMin,
163 Double_t phiMin,
164 Double_t pMax,
165 Double_t thetaMax,
166 Double_t phiMax)
167{
168 if ((pMax < pMin) || (thetaMax < thetaMin) || (phiMax < phiMin) || (pMin < 0.) || (pMax < 0.) || (thetaMin < 0.)
169 || (thetaMax > TMath::Pi()) || (phiMin < 0.) || (phiMax > TMath::TwoPi())) {
170 cout << "-E- FairTrajFilter::SetMomentumCutP() : invalid region, ignoring." << endl;
171 return;
172 }
173 fPMin = pMin;
174 fPMax = pMax;
175 fThetaMin = thetaMin;
176 fThetaMax = thetaMax;
177 fPhiMin = phiMin;
178 fPhiMax = phiMax;
179 fKinCutType = 0;
180}
181
183 Double_t pyMin,
184 Double_t pzMin,
185 Double_t pxMax,
186 Double_t pyMax,
187 Double_t pzMax)
188{
189 if ((pxMax < pxMin) || (pyMax < pyMin) || (pzMax < pzMin)) {
190 cout << "-E- FairTrajFilter::SetMomentumCutD() : invalid region, ignoring." << endl;
191 return;
192 }
193 fPxMin = pxMin;
194 fPxMax = pxMax;
195 fPyMin = pyMin;
196 fPyMax = pyMax;
197 fPzMin = pzMin;
198 fPzMax = pzMax;
199 fKinCutType = 1;
200}
201
202void FairTrajFilter::SetPtRapidityCut(Double_t ptMin, Double_t ptMax, Double_t rapidityMin, Double_t rapidityMax)
203{
204 if ((ptMax < ptMin) || (rapidityMax < rapidityMin) || (ptMin < 0.) || (ptMax < 0.)) {
205 cout << "-E- FairTrajFilter::SetPtRapidityCut() : invalid region, ignoring." << endl;
206 return;
207 }
208 fPtMin = ptMin;
209 fPtMax = ptMax;
210 fRapidityMin = rapidityMin;
211 fRapidityMax = rapidityMax;
212 fKinCutType = 2;
213}
214
215void FairTrajFilter::SetEnergyCut(Double_t etotMin, Double_t etotMax)
216{
217 if ((etotMax < etotMin) || (etotMin < 0.) || (etotMax < 0.)) {
218 cout << "-E- FairTrajFilter::SetEnergyCut() : invalid region, ignoring." << endl;
219 return;
220 }
221 fEtotMin = etotMin;
222 fEtotMax = etotMax;
223}
224
225void FairTrajFilter::SetStepSizeCut(Double_t stepSizeMin)
226{
227 if (stepSizeMin < 0.) {
228 cout << "-E- FairTrajFilter::SetStepSizeCut() : invalid value, ignoring." << endl;
229 return;
230 }
231 fStepSizeMin = stepSizeMin;
232}
233
234void FairTrajFilter::GetVertexCut(Double_t& vxMin,
235 Double_t& vyMin,
236 Double_t& vzMin,
237 Double_t& vxMax,
238 Double_t& vyMax,
239 Double_t& vzMax) const
240{
241 vxMin = fVxMin;
242 vxMax = fVxMax;
243 vyMin = fVyMin;
244 vyMax = fVyMax;
245 vzMin = fVzMin;
246 vzMax = fVzMax;
247}
248
250 Double_t& thetaMin,
251 Double_t& phiMin,
252 Double_t& pMax,
253 Double_t& thetaMax,
254 Double_t& phiMax) const
255{
256 pMin = fPMin;
257 pMax = fPMax;
258 thetaMin = fThetaMin;
259 thetaMax = fThetaMax;
260 phiMin = fPhiMin;
261 phiMax = fPhiMax;
262}
263
265 Double_t& pyMin,
266 Double_t& pzMin,
267 Double_t& pxMax,
268 Double_t& pyMax,
269 Double_t& pzMax) const
270{
271 pxMin = fPxMin;
272 pxMax = fPxMax;
273 pyMin = fPyMin;
274 pyMax = fPyMax;
275 pzMin = fPzMin;
276 pzMax = fPzMax;
277}
278
280 Double_t& ptMax,
281 Double_t& rapidityMin,
282 Double_t& rapidityMax) const
283{
284 ptMin = fPtMin;
285 ptMax = fPtMax;
286 rapidityMin = fRapidityMin;
287 rapidityMax = fRapidityMax;
288}
289
290void FairTrajFilter::GetEnergyCut(Double_t& etotMin, Double_t& etotMax) const
291{
292 etotMin = fEtotMin;
293 etotMax = fEtotMax;
294}
295
296TGeoTrack* FairTrajFilter::AddTrack(Int_t trackId, Int_t pdgCode)
297{
298
299 // cout << "FairTrajFilter::AddTrack" << endl;
300 TClonesArray& clref = *fTrackCollection;
301 Int_t tsize = clref.GetEntriesFast();
302 fCurrentTrk = new (clref[tsize]) TGeoTrack(trackId, pdgCode);
303 return fCurrentTrk;
304}
305
306TGeoTrack* FairTrajFilter::AddTrack(TParticle* p)
307{
308 Int_t trackId = 0;
309 // cout << "FairTrajFilter::AddTrack" << endl;
310 if (fCurrentTrk) {
311 trackId = fCurrentTrk->GetId();
312 }
313 Int_t pdgCode = p->GetPdgCode();
314 TClonesArray& clref = *fTrackCollection;
315 Int_t tsize = clref.GetEntriesFast();
316 fCurrentTrk = new (clref[tsize]) TGeoTrack(++trackId, pdgCode, 0, p);
317 return fCurrentTrk;
318}
319
320TGeoTrack* FairTrajFilter::CheckAddTrack(Int_t trackId, TParticle* p)
321{
322 TClonesArray& clref = *fTrackCollection;
323 Int_t tsize = clref.GetEntriesFast();
324 for (Int_t itr = tsize - 1; itr >= 0; --itr) {
325 TGeoTrack* tempTrack = dynamic_cast<TGeoTrack*>(clref.At(itr));
326 if (tempTrack->GetId() == trackId) {
327 fCurrentTrk = tempTrack;
328 return fCurrentTrk;
329 }
330 }
331 // track with given trackId not found, creating new one
332 Int_t pdgCode = p->GetPdgCode();
333 fCurrentTrk = new (clref[tsize]) TGeoTrack(trackId, pdgCode, 0, p);
334 return fCurrentTrk;
335}
336
337TGeoTrack* FairTrajFilter::GetTrack(Int_t trackId) { return static_cast<TGeoTrack*>(fTrackCollection->At(trackId)); }
ClassImp(FairTrajFilter)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
static FairRootManager * Instance()
void GetMomentumCutP(Double_t &pMin, Double_t &thetaMin, Double_t &phiMin, Double_t &pMax, Double_t &thetaMax, Double_t &phiMax) const
Bool_t IsAccepted(const TParticle *p) const
void Init(TString brName="GeoTracks", TString folderName="MCGeoTrack")
static FairTrajFilter * Instance()
void SetVertexCut(Double_t vxMin=-2000., Double_t vyMin=-2000., Double_t vzMin=-2000., Double_t vxMax=2000., Double_t vyMax=2000., Double_t vzMax=2000.)
void SetPtRapidityCut(Double_t ptMin=0., Double_t ptMax=1e10, Double_t rapidityMin=-1e10, Double_t rapidityMax=1e10)
void GetMomentumCutD(Double_t &pxMin, Double_t &pyMin, Double_t &pzMin, Double_t &pxMax, Double_t &pyMax, Double_t &pzMax) const
void GetPtRapidityCut(Double_t &ptMin, Double_t &ptMax, Double_t &rapidityMin, Double_t &rapidityMax) const
TGeoTrack * AddTrack(Int_t trackId, Int_t pdgCode)
void SetStepSizeCut(Double_t stepSizeMin=0.)
virtual ~FairTrajFilter()
void SetMomentumCutP(Double_t pMin=0., Double_t thetaMin=0., Double_t phiMin=0., Double_t pMax=1e10, Double_t thetaMax=TMath::Pi(), Double_t phiMax=TMath::TwoPi())
TGeoTrack * GetTrack(Int_t trackId)
void SetMomentumCutD(Double_t pxMin=-1e10, Double_t pyMin=-1e10, Double_t pzMin=-1e10, Double_t pxMax=1e10, Double_t pyMax=1e10, Double_t pzMax=1e10)
void SetEnergyCut(Double_t etotMin=0., Double_t etotMax=1e10)
TGeoTrack * CheckAddTrack(Int_t trackId, TParticle *p)
void GetVertexCut(Double_t &vxMin, Double_t &vyMin, Double_t &vzMin, Double_t &vxMax, Double_t &vyMax, Double_t &vzMax) const
void GetEnergyCut(Double_t &etotMin, Double_t &etotMax) const