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