17 #include <TClonesArray.h>
20 #include <TGeoManager.h>
21 #include <TGeoVolume.h>
23 #include <TMathBase.h>
24 #include <TParticle.h>
31 TMCThreadLocal
FairTrajFilter* FairTrajFilter::fgInstance =
nullptr;
45 , fThetaMax(TMath::Pi())
47 , fPhiMax(TMath::TwoPi())
66 fTrackCollection(new TClonesArray(
"TGeoTrack"))
67 , fCurrentTrk(nullptr)
69 if (
nullptr != fgInstance) {
70 Fatal(
"FairTrajFilter",
"Singleton class already exists.");
93 if ((p->Vx() < fVxMin) || (p->Vx() > fVxMax) || (p->Vy() < fVyMin) || (p->Vy() > fVyMax) || (p->Vz() < fVzMin)
94 || (p->Vz() > fVzMax)) {
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)) {
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)) {
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)) {
117 if ((p->Energy() < fEtotMin) || (p->Energy() > fEtotMax)) {
122 if (-1 == p->GetFirstMother()) {
123 if (kFALSE == fStorePrim) {
127 if (kFALSE == fStoreSec) {
142 TGeoBBox* cave =
static_cast<TGeoBBox*
>(gGeoManager->GetTopVolume()->GetShape());
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;
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;
175 fThetaMin = thetaMin;
176 fThetaMax = thetaMax;
189 if ((pxMax < pxMin) || (pyMax < pyMin) || (pzMax < pzMin)) {
190 cout <<
"-E- FairTrajFilter::SetMomentumCutD() : invalid region, ignoring." << endl;
204 if ((ptMax < ptMin) || (rapidityMax < rapidityMin) || (ptMin < 0.) || (ptMax < 0.)) {
205 cout <<
"-E- FairTrajFilter::SetPtRapidityCut() : invalid region, ignoring." << endl;
210 fRapidityMin = rapidityMin;
211 fRapidityMax = rapidityMax;
217 if ((etotMax < etotMin) || (etotMin < 0.) || (etotMax < 0.)) {
218 cout <<
"-E- FairTrajFilter::SetEnergyCut() : invalid region, ignoring." << endl;
227 if (stepSizeMin < 0.) {
228 cout <<
"-E- FairTrajFilter::SetStepSizeCut() : invalid value, ignoring." << endl;
231 fStepSizeMin = stepSizeMin;
239 Double_t& vzMax)
const
254 Double_t& phiMax)
const
258 thetaMin = fThetaMin;
259 thetaMax = fThetaMax;
269 Double_t& pzMax)
const
281 Double_t& rapidityMin,
282 Double_t& rapidityMax)
const
286 rapidityMin = fRapidityMin;
287 rapidityMax = fRapidityMax;
300 TClonesArray& clref = *fTrackCollection;
301 Int_t tsize = clref.GetEntriesFast();
302 fCurrentTrk =
new (clref[tsize]) TGeoTrack(trackId, pdgCode);
311 trackId = fCurrentTrk->GetId();
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);
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;
332 Int_t pdgCode = p->GetPdgCode();
333 fCurrentTrk =
new (clref[tsize]) TGeoTrack(trackId, pdgCode, 0, p);
void SetStepSizeCut(Double_t stepSizeMin=0.)
void GetMomentumCutP(Double_t &pMin, Double_t &thetaMin, Double_t &phiMin, Double_t &pMax, Double_t &thetaMax, Double_t &phiMax) const
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())
static FairRootManager * Instance()
Bool_t IsAccepted(const TParticle *p) const
ClassImp(FairEventBuilder)
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)
virtual ~FairTrajFilter()
void GetMomentumCutD(Double_t &pxMin, Double_t &pyMin, Double_t &pzMin, Double_t &pxMax, Double_t &pyMax, Double_t &pzMax) const
TGeoTrack * GetTrack(Int_t trackId)
TGeoTrack * CheckAddTrack(Int_t trackId, TParticle *p)
static FairTrajFilter * Instance()
void GetEnergyCut(Double_t &etotMin, Double_t &etotMax) const
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
TGeoTrack * AddTrack(Int_t trackId, Int_t pdgCode)
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 GetPtRapidityCut(Double_t &ptMin, Double_t &ptMax, Double_t &rapidityMin, Double_t &rapidityMax) const
void SetEnergyCut(Double_t etotMin=0., Double_t etotMax=1e10)
void GetVertexCut(Double_t &vxMin, Double_t &vyMin, Double_t &vzMin, Double_t &vxMax, Double_t &vyMax, Double_t &vzMax) const
void SetPtRapidityCut(Double_t ptMin=0., Double_t ptMax=1e10, Double_t rapidityMin=-1e10, Double_t rapidityMax=1e10)
void Init(TString brName="GeoTracks", TString folderName="MCGeoTrack")