7 #include "G4SDManager.hh" 8 #include "G4RunManager.hh" 10 #include "G4HCofThisEvent.hh" 12 #include "G4TrackStatus.hh" 13 #include "G4ParticleDefinition.hh" 14 #include "G4ParticleTypes.hh" 27 std::cout <<
"LBNEStackingAction Constructor Called." <<
std::endl;
35 int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
38 std::cout <<
"LBNEStackingAction Destructor Called." <<
std::endl;
44 std::cerr <<
" From LBNEStackingAction::OpenHadronAtVertex, file already opened, fatal... " <<
std::endl;
51 const char *clusterEnv =
getenv(
"CLUSTER");
52 if (clusterEnv != 0) clusterNum = atoi(clusterEnv);
53 const char *procEnv =
getenv(
"PROCESS");
54 if (procEnv != 0) procNum = atoi(procEnv);
56 if ((clusterNum != 0) || (procNum != 0)) {
59 std::ostringstream fNStrStr;
60 fNStrStr <<
"./hadronFluxStackingASCII_" 61 << clusterNum <<
"_" << procNum <<
".txt";
62 fName = fNStrStr.str();
66 std::cout <<
" LBNEStackingAction::OpenHadronAtVertex, Opening file " <<
68 fName =
std::string(
"./hadronFluxStackingASCIICl.txt");
69 if ((clusterNum != 0) || (procNum != 0)) {
72 std::ostringstream fNStrStr;
73 fNStrStr <<
"./hadronFluxStackingASCIICl_" 74 << clusterNum <<
"_" << procNum <<
".txt";
75 fName = fNStrStr.str();
79 std::cout <<
" LBNEStackingAction::OpenHadronAtVertex, Opening file " <<
90 G4ThreeVector posTmp = aTrack->GetPosition();
91 G4ThreeVector momTmp = aTrack->GetMomentum();
92 for (
size_t k=0;
k != 3;
k++) {
93 if (std::isnan(posTmp[
k])) {
94 std::cerr <<
" LBNEStackingAction::ClassifyNewTrack, position has NaN, rejected " <<
std::endl;
97 if (std::isnan(momTmp[k])) {
98 std::cerr <<
" LBNEStackingAction::ClassifyNewTrack, momentum has NaN, rejected " <<
std::endl;
102 if (std::isnan(aTrack->GetTotalEnergy()) || std::isnan(aTrack->GetKineticEnergy())) {
103 std::cerr <<
" LBNEStackingAction::ClassifyNewTrack, Energy is NaN, rejected " <<
std::endl;
108 int myPid = aTrack->GetParticleDefinition()->GetPDGEncoding();
109 if ((
std::abs(myPid) == 211) || (myPid == 2212) ||
112 double pTotSq = 0;
for (
int k=0;
k != 3;
k++) pTotSq += aTrack->GetMomentum()[
k]*aTrack->GetMomentum()[
k];
113 double pTot = std::sqrt(pTotSq)/CLHEP::GeV;
115 if ((myPid == 2212) || ((pTot > 0.001) && (pTot < 50.))) {
116 int evtId = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
130 G4ClassificationOfNewTrack classification = fUrgent;
131 G4ParticleDefinition * particleType = aTrack->GetDefinition();
133 int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
136 G4int evtno =
pRunManager->GetCurrentEvent()->GetEventID();
137 std::cout <<
"Event " << evtno <<
": LBNEStackingAction::ClassifyNewTrack for Particle " 138 <<
"\"" << particleType->GetParticleName() <<
"\"" <<
" Called." <<
std::endl;
141 int sign = (particleType->GetPDGEncoding() > 0) ? 1 : -1;
144 const LBNERunAction *runUserAction =
reinterpret_cast<const LBNERunAction *
>(G4RunManager::GetRunManager()->GetUserRunAction());
149 const std::string vName = aTrack->GetVolume()->GetName();
150 if(vName.find(
"Target") != std::string::npos)
return classification;
153 if (aTrack->GetPosition()[2] < 9900.)
return classification;
165 int myPid = aTrack->GetParticleDefinition()->GetPDGEncoding();
167 double pTotSq = 0;
for (
int k=0;
k != 3;
k++) pTotSq += aTrack->GetMomentum()[
k]*aTrack->GetMomentum()[
k];
168 double pTot = std::sqrt(pTotSq)/CLHEP::GeV;
170 int evtId = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
192 return classification;
197 int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
200 G4int evtno =
pRunManager->GetCurrentEvent()->GetEventID();
201 std::cout <<
"Event " << evtno <<
": LBNEStackingAction::NewStage Called." <<
std::endl;
211 int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
214 G4int evtno =
pRunManager->GetCurrentEvent()->GetEventID();
215 std::cout <<
"Event " << evtno <<
": LBNEStackingAction::PrepareNewEvent Called." <<
std::endl;
222 if (classification != fKill)
return;
228 if (aTrack->GetVolume()->GetLogicalVolume())
229 str = aTrack->GetVolume()->GetLogicalVolume()->GetName();
230 if (str ==
"HadronAbsorberSculpAirBuffer" || str ==
"MuonTrackingBox" || str ==
"HadronAbsorberSculpBackWall")
232 classification = fUrgent;
245 const G4Track * aTrack)
250 G4ParticleDefinition * particleType = aTrack->GetDefinition();
252 if ( (particleType==G4Gamma::GammaDefinition() ||
253 particleType==G4Electron::ElectronDefinition() ||
254 particleType==G4Positron::PositronDefinition() ) &&
255 (classification != fKill) )
256 {classification = fKill;}
262 const G4Track * aTrack)
264 const LBNERunAction *runUserAction =
reinterpret_cast<const LBNERunAction *
>(G4RunManager::GetRunManager()->GetUserRunAction());
268 const std::string tg = aTrack->GetMaterial()->GetName();
269 if (tg == tgt)
return;
272 G4ThreeVector momentum=aTrack->GetMomentumDirection();
273 if (momentum[2]<0 && (classification != fKill)) {classification = fKill;}
279 const G4Track * aTrack)
286 G4ParticleDefinition * particleType = aTrack->GetDefinition();
288 if ((particleType!=G4NeutrinoE::NeutrinoEDefinition())&&
289 (particleType!=G4NeutrinoMu::NeutrinoMuDefinition())&&
290 (particleType!=G4NeutrinoTau::NeutrinoTauDefinition())&&
291 (particleType!=G4AntiNeutrinoE::AntiNeutrinoEDefinition())&&
292 (particleType!=G4AntiNeutrinoMu::AntiNeutrinoMuDefinition())&&
293 (particleType!=G4AntiNeutrinoTau::AntiNeutrinoTauDefinition()))
295 G4double
energy = aTrack->GetKineticEnergy();
300 {classification = fKill;}
338 const G4Track * aTrack)
344 if ((classification != fKill))
353 if(Nimpweight==0.) { classification = fKill; }
354 else { trackInfo->
SetNImpWt(Nimpweight); }
358 if (trackInfo!=0) trackInfo->
SetNImpWt(1.0);
void UnKillMuonAlcoveParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
bool GetDoComputeEDepInGraphite() const
bool GetDoComputeEDepInArgonGas() const
bool GetCreateAlcoveTrackingOutput() const
std::ofstream fOutHadronAtVectexCl
void OpenHadronAtVertex() const
LBNERunManager * pRunManager
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
void KillUnimportantParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
bool GetDoComputeEDepInHorns() const
static G4double CalculateImpWeight(const G4Track *aTrack)
std::string getenv(std::string const &name)
double fStackingKillingThreshold
static LBNEQuickPiToNuVect * Instance()
virtual void PrepareNewEvent()
virtual ~LBNEStackingAction()
std::ofstream fOutHadronAtVectex
void KillEMParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
void KillThresholdParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
bool doImportanceWeightSelection
void KillltZeroPzParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
void addPion(int trNum1, int sign1, double e, G4ThreeVector p)
QTextStream & endl(QTextStream &s)