Public Member Functions | Private Attributes | List of all members
LBNEStackingAction Class Reference

#include <LBNEStackingAction.hh>

Inheritance diagram for LBNEStackingAction:

Public Member Functions

 LBNEStackingAction ()
 
virtual ~LBNEStackingAction ()
 
virtual G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *aTrack)
 
virtual void NewStage ()
 
virtual void PrepareNewEvent ()
 
void KillEMParticles (G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
 
void KillltZeroPzParticles (G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
 
void KillThresholdParticles (G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
 
void KillUnimportantParticles (G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
 
void UnKillMuonAlcoveParticles (G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
 
void OpenHadronAtVertex () const
 
void SetDoImportanceWeightSelection (bool t) const
 
bool GetDoImportanceWeightSelection () const
 
void SetStackingKillingThreshold (double v) const
 
double GetStackingKillingThreshold () const
 

Private Attributes

LBNERunManagerpRunManager
 
double fStackingKillingThreshold
 
std::ofstream fOutHadronAtVectex
 
std::ofstream fOutHadronAtVectexCl
 
bool doImportanceWeightSelection
 

Detailed Description

Definition at line 15 of file LBNEStackingAction.hh.

Constructor & Destructor Documentation

LBNEStackingAction::LBNEStackingAction ( )

Definition at line 24 of file LBNEStackingAction.cc.

25 {
26  pRunManager=(LBNERunManager*)LBNERunManager::GetRunManager();
27  std::cout << "LBNEStackingAction Constructor Called." << std::endl;
28  doImportanceWeightSelection = true; // Per G4Numi tradition..
29  fStackingKillingThreshold = 0.050*CLHEP::GeV;
30 }
LBNERunManager * pRunManager
QTextStream & endl(QTextStream &s)
LBNEStackingAction::~LBNEStackingAction ( )
virtual

Definition at line 33 of file LBNEStackingAction.cc.

34 {
35  int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
36  if(verboseLevel > 0)
37  {
38  std::cout << "LBNEStackingAction Destructor Called." << std::endl;
39  }
40 }
QTextStream & endl(QTextStream &s)

Member Function Documentation

G4ClassificationOfNewTrack LBNEStackingAction::ClassifyNewTrack ( const G4Track *  aTrack)
virtual

Definition at line 85 of file LBNEStackingAction.cc.

86 {
87  //
88  // v410.2: Rare bug somewhere, we have track with bad parameters, we do not want them..
89  //
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;
95  return fKill;
96  }
97  if (std::isnan(momTmp[k])) {
98  std::cerr << " LBNEStackingAction::ClassifyNewTrack, momentum has NaN, rejected " << std::endl;
99  return fKill;
100  }
101  }
102  if (std::isnan(aTrack->GetTotalEnergy()) || std::isnan(aTrack->GetKineticEnergy())) {
103  std::cerr << " LBNEStackingAction::ClassifyNewTrack, Energy is NaN, rejected " << std::endl;
104  return fKill;
105  }
106 
107  if (fOutHadronAtVectex.is_open()) {
108  int myPid = aTrack->GetParticleDefinition()->GetPDGEncoding();
109  if ((std::abs(myPid) == 211) || (myPid == 2212) ||
110  (std::abs(myPid) == 321) || (std::abs(myPid) == 311) ||
111  (std::abs(myPid) == 130) || (std::abs(myPid) == 310)) {
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;
114 // if ((myPid == 2212) || ((pTot > fStackingKillingThreshold) && (pTot < 15.))) { // take all the proton, to check we are on target, and the relevant pions
115  if ((myPid == 2212) || ((pTot > 0.001) && (pTot < 50.))) { // take all the proton, to check we are on target, and the relevant pions
116  int evtId = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
117  fOutHadronAtVectex << " " << evtId;
118  for (int k=0; k != 3; k++) fOutHadronAtVectex << " " << aTrack->GetPosition()[k];
119  for (int k=0; k != 3; k++) fOutHadronAtVectex << " " << (aTrack->GetMomentum()[k])/CLHEP::GeV;
120  fOutHadronAtVectex << " " << myPid << std::endl;
121  }
122 
123  }
124  }
125 // const LBNETrackInformation *oldTrInfo = reinterpret_cast<const LBNETrackInformation*>(aTrack->GetUserInformation());
126 // std::cerr << " G4ClassificationOfNewTrack LBNEStackingAction::ClassifyNewTrack, ptr track "
127 // << (void*) aTrack << " info " << (void*) oldTrInfo << std::endl;
128 // if (oldTrInfo != 0) std::cerr << " ... PFFlag " << oldTrInfo->GetPFFlag() << std::endl;
129 
130  G4ClassificationOfNewTrack classification = fUrgent;
131  G4ParticleDefinition * particleType = aTrack->GetDefinition();
132 
133  int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
134  if(verboseLevel > 0)
135  {
136  G4int evtno = pRunManager->GetCurrentEvent()->GetEventID();
137  std::cout << "Event " << evtno << ": LBNEStackingAction::ClassifyNewTrack for Particle "
138  << "\"" << particleType->GetParticleName() << "\"" << " Called." << std::endl;
139  }
140  if (LBNEQuickPiToNuVect::Instance()->doIt() && (std::abs(particleType->GetPDGEncoding()) == 211)) {
141  int sign = (particleType->GetPDGEncoding() > 0) ? 1 : -1;
142  LBNEQuickPiToNuVect::Instance()->addPion(aTrack->GetTrackID(), sign, aTrack->GetTotalEnergy(), aTrack->GetMomentum());
143  }
144  const LBNERunAction *runUserAction = reinterpret_cast<const LBNERunAction *>(G4RunManager::GetRunManager()->GetUserRunAction());
145  //
146  // If we are in the target, and tally the energy deposition, skip the re-classification done below..
147  //
148  if (runUserAction->GetDoComputeEDepInGraphite() && (aTrack->GetVolume() != 0)) {
149  const std::string vName = aTrack->GetVolume()->GetName();
150  if(vName.find("Target") != std::string::npos) return classification;
151  }
152  if (runUserAction->GetDoComputeEDepInArgonGas()) {
153  if (aTrack->GetPosition()[2] < 9900.) return classification; // rough Z- cut
154  }
155  //
156  // Now do the reclassification, for CPU speed optimization..
157  //
158  LBNEStackingAction::KillEMParticles(classification, aTrack);
159  //LBNEStackingAction::KillltZeroPzParticles(classification, aTrack);
160  LBNEStackingAction::KillThresholdParticles(classification, aTrack);
161 // LBNEStackingAction::KillOutOfWorldParticles(classification, aTrack); Obsolete in G4
162  LBNEStackingAction::KillUnimportantParticles(classification, aTrack);
163 //
164  if (fOutHadronAtVectexCl.is_open() && (classification == fUrgent)) {
165  int myPid = aTrack->GetParticleDefinition()->GetPDGEncoding();
166  if (std::abs(myPid) == 211) {
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;
169  if ((myPid == 2212) || ((pTot > fStackingKillingThreshold) && (pTot < 15.))) { // take all the proton, to check we are on target, and the relevant pions
170  int evtId = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
171  fOutHadronAtVectexCl << " " << evtId;
172  for (int k=0; k != 3; k++) fOutHadronAtVectexCl << " " << aTrack->GetPosition()[k];
173  for (int k=0; k != 3; k++) fOutHadronAtVectexCl << " " << (aTrack->GetMomentum()[k])/CLHEP::GeV;
174  fOutHadronAtVectexCl << " " << myPid << std::endl;
175  }
176 
177  }
178  }
179 
180  LBNEStackingAction::UnKillMuonAlcoveParticles(classification,aTrack);
181 //
182 // specific checks for impotance weight.
183 //
184 // if (std::abs(aTrack->GetParticleDefinition()->GetPDGEncoding()) == 211) {
185 // LBNETrackInformation *trInfo = reinterpret_cast<LBNETrackInformation*> (aTrack->GetUserInformation());
186 // if (trInfo != 0) std::cerr << "LBNEStackingAction::classifyNewTrack, Track ID " << aTrack->GetTrackID()
187 // << " Imp Weight " << trInfo->GetNImpWt() << std::endl;
188 // else std::cerr << "LBNEStackingAction::classifyNewTrack, Track ID " << aTrack->GetTrackID()
189 // << " has no weight ... " << std::endl;
190 // }
191 
192  return classification;
193 }
void UnKillMuonAlcoveParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
bool GetDoComputeEDepInGraphite() const
bool GetDoComputeEDepInArgonGas() const
std::string string
Definition: nybbler.cc:12
std::ofstream fOutHadronAtVectexCl
LBNERunManager * pRunManager
void KillUnimportantParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
T abs(T value)
static LBNEQuickPiToNuVect * Instance()
int sign(double val)
Definition: UtilFunc.cxx:103
std::ofstream fOutHadronAtVectex
void KillEMParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
void KillThresholdParticles(G4ClassificationOfNewTrack &classification, const G4Track *aTrack)
void addPion(int trNum1, int sign1, double e, G4ThreeVector p)
QTextStream & endl(QTextStream &s)
bool LBNEStackingAction::GetDoImportanceWeightSelection ( ) const
inline

Definition at line 52 of file LBNEStackingAction.hh.

double LBNEStackingAction::GetStackingKillingThreshold ( ) const
inline

Definition at line 54 of file LBNEStackingAction.hh.

void LBNEStackingAction::KillEMParticles ( G4ClassificationOfNewTrack &  classification,
const G4Track *  aTrack 
)

Definition at line 244 of file LBNEStackingAction.cc.

246 {
247  const LBNERunAction * runAct = dynamic_cast<const LBNERunAction*>(pRunManager->GetUserRunAction());
248  if (runAct->GetDoComputeEDepInHorns() || runAct->GetDoComputeEDepInGraphite ()
249  || runAct->GetDoComputeEDepInArgonGas()) return;
250  G4ParticleDefinition * particleType = aTrack->GetDefinition();
251  // Discard Gammas, Electrons, ...
252  if ( (particleType==G4Gamma::GammaDefinition() ||
253  particleType==G4Electron::ElectronDefinition() ||
254  particleType==G4Positron::PositronDefinition() ) &&
255  (classification != fKill) )
256  {classification = fKill;}
257 
258 }
bool GetDoComputeEDepInGraphite() const
bool GetDoComputeEDepInArgonGas() const
LBNERunManager * pRunManager
bool GetDoComputeEDepInHorns() const
void LBNEStackingAction::KillltZeroPzParticles ( G4ClassificationOfNewTrack &  classification,
const G4Track *  aTrack 
)

Definition at line 261 of file LBNEStackingAction.cc.

263 {
264  const LBNERunAction *runUserAction = reinterpret_cast<const LBNERunAction *>(G4RunManager::GetRunManager()->GetUserRunAction());
265  if (runUserAction->GetDoComputeEDepInHorns()) return;
266  if (runUserAction->GetDoComputeEDepInGraphite() && (aTrack->GetMaterial() != 0)) {
267  const std::string tgt("Target");
268  const std::string tg = aTrack->GetMaterial()->GetName();
269  if (tg == tgt) return; // Don't loose any track, computing E-Loss...
270  }
271  //Discard particles with pz<0
272  G4ThreeVector momentum=aTrack->GetMomentumDirection();
273  if (momentum[2]<0 && (classification != fKill)) {classification = fKill;}
274 
275 }
bool GetDoComputeEDepInGraphite() const
std::string string
Definition: nybbler.cc:12
bool GetDoComputeEDepInHorns() const
void LBNEStackingAction::KillThresholdParticles ( G4ClassificationOfNewTrack &  classification,
const G4Track *  aTrack 
)

Definition at line 278 of file LBNEStackingAction.cc.

281 {
282 
283  const LBNERunAction * runAct = dynamic_cast<const LBNERunAction*>(pRunManager->GetUserRunAction());
284  if (runAct->GetDoComputeEDepInHorns() || runAct->GetDoComputeEDepInGraphite ()
285  || runAct->GetDoComputeEDepInArgonGas()) return;
286  G4ParticleDefinition * particleType = aTrack->GetDefinition();
287  //Discard particles with kinetic energy < KillTracking Threshold.GeV (that are not neutrinos)
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()))
294  {
295  G4double energy = aTrack->GetKineticEnergy();
296 //
297 // We hard code this cut, as the LBNEDataInput obsolete.. Could become a data card
298 //
299  if ((energy < fStackingKillingThreshold ) && (classification != fKill))
300  {classification = fKill;}
301  }
302 
303 
304 }
bool GetDoComputeEDepInGraphite() const
bool GetDoComputeEDepInArgonGas() const
LBNERunManager * pRunManager
bool GetDoComputeEDepInHorns() const
void LBNEStackingAction::KillUnimportantParticles ( G4ClassificationOfNewTrack &  classification,
const G4Track *  aTrack 
)

Definition at line 337 of file LBNEStackingAction.cc.

339 {
340  const LBNERunAction * runAct = dynamic_cast<const LBNERunAction*>(pRunManager->GetUserRunAction());
341  if (runAct->GetDoComputeEDepInHorns() || runAct->GetDoComputeEDepInGraphite ()
342  || runAct->GetDoComputeEDepInArgonGas()) return;
343  //If importance weighting might be on:
344  if ((classification != fKill))
345  {
346  LBNETrackInformation* trackInfo=(LBNETrackInformation*)(aTrack->GetUserInformation());
348  if (trackInfo!=0)
349  {
350  G4double Nimpweight=LBNEImpWeight::CalculateImpWeight(aTrack);
351 // std::cerr << " LBNEStackingAction::KillUnimportantParticles, E "
352 // << aTrack->GetTotalEnergy() << " Imp weight " << Nimpweight << std::endl;
353  if(Nimpweight==0.) { classification = fKill; }
354  else { trackInfo->SetNImpWt(Nimpweight); }
355  }
356  } else {
357  // We do not change the classification..
358  if (trackInfo!=0) trackInfo->SetNImpWt(1.0);
359  }
360  }
361 }
bool GetDoComputeEDepInGraphite() const
bool GetDoComputeEDepInArgonGas() const
LBNERunManager * pRunManager
bool GetDoComputeEDepInHorns() const
void SetNImpWt(G4double nimpweight)
static G4double CalculateImpWeight(const G4Track *aTrack)
void LBNEStackingAction::NewStage ( )
virtual

Definition at line 195 of file LBNEStackingAction.cc.

196 {
197  int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
198  if(verboseLevel > 1)
199  {
200  G4int evtno = pRunManager->GetCurrentEvent()->GetEventID();
201  std::cout << "Event " << evtno << ": LBNEStackingAction::NewStage Called." << std::endl;
202  }
203 
204 
205  // stackManager->ReClassify();
206  // return;
207 }
LBNERunManager * pRunManager
QTextStream & endl(QTextStream &s)
void LBNEStackingAction::OpenHadronAtVertex ( ) const

Definition at line 42 of file LBNEStackingAction.cc.

42  { // Pseudo const..
43  if (fOutHadronAtVectex.is_open()) {
44  std::cerr << " From LBNEStackingAction::OpenHadronAtVertex, file already opened, fatal... " << std::endl;
45  exit(2);
46  }
47  // Set a file name that can be unique.. Particularly, tailored for the use on FermiGrid
48  // But not mandated.
49  int clusterNum = 0;
50  int procNum =0;
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);
55  std::string fName("./hadronFluxStackingASCII.txt");
56  if ((clusterNum != 0) || (procNum != 0)) {
57 // const char *userEnv = getenv("USER"); // assume it always works
58 // std::string aUserStr(userEnv);
59  std::ostringstream fNStrStr;
60  fNStrStr << "./hadronFluxStackingASCII_"
61  << clusterNum << "_" << procNum << ".txt";
62  fName = fNStrStr.str();
63  }
64  fOutHadronAtVectex.open(fName.c_str());
65  fOutHadronAtVectex << " Evt X Y Z Px Py Pz Id " << std::endl;
66  std::cout << " LBNEStackingAction::OpenHadronAtVertex, Opening file " <<
67  fName << std::endl;
68  fName = std::string("./hadronFluxStackingASCIICl.txt");
69  if ((clusterNum != 0) || (procNum != 0)) {
70 // const char *userEnv = getenv("USER"); // assume it always works
71 // std::string aUserStr(userEnv);
72  std::ostringstream fNStrStr;
73  fNStrStr << "./hadronFluxStackingASCIICl_"
74  << clusterNum << "_" << procNum << ".txt";
75  fName = fNStrStr.str();
76  }
77  fOutHadronAtVectexCl.open(fName.c_str());
78  fOutHadronAtVectexCl << " Evt X Y Z Px Py Pz Id " << std::endl;
79  std::cout << " LBNEStackingAction::OpenHadronAtVertex, Opening file " <<
80  fName << std::endl;
81 
82 }
std::string string
Definition: nybbler.cc:12
std::ofstream fOutHadronAtVectexCl
std::string getenv(std::string const &name)
Definition: getenv.cc:15
std::ofstream fOutHadronAtVectex
QTextStream & endl(QTextStream &s)
void LBNEStackingAction::PrepareNewEvent ( )
virtual

Definition at line 209 of file LBNEStackingAction.cc.

210 {
211  int verboseLevel = G4EventManager::GetEventManager()->GetTrackingManager()->GetVerboseLevel();
212  if(verboseLevel > 1)
213  {
214  G4int evtno = pRunManager->GetCurrentEvent()->GetEventID();
215  std::cout << "Event " << evtno << ": LBNEStackingAction::PrepareNewEvent Called." << std::endl;
216  }
217 
218 }
LBNERunManager * pRunManager
QTextStream & endl(QTextStream &s)
void LBNEStackingAction::SetDoImportanceWeightSelection ( bool  t) const
inline

Definition at line 51 of file LBNEStackingAction.hh.

51 { doImportanceWeightSelection = t; } // Pseudo Const..
void LBNEStackingAction::SetStackingKillingThreshold ( double  v) const
inline

Definition at line 53 of file LBNEStackingAction.hh.

53 { fStackingKillingThreshold = v;} //Pseudo const
void LBNEStackingAction::UnKillMuonAlcoveParticles ( G4ClassificationOfNewTrack &  classification,
const G4Track *  aTrack 
)

Definition at line 220 of file LBNEStackingAction.cc.

221 {
222  if (classification != fKill) return;
223 
224  //
225  LBNERunManager* runMan = dynamic_cast<LBNERunManager*>(G4RunManager::GetRunManager());
226  if (!runMan->GetCreateAlcoveTrackingOutput()) return;
227  G4String str = "";
228  if (aTrack->GetVolume()->GetLogicalVolume())
229  str = aTrack->GetVolume()->GetLogicalVolume()->GetName();
230  if (str == "HadronAbsorberSculpAirBuffer" || str =="MuonTrackingBox" || str == "HadronAbsorberSculpBackWall")
231  {
232  classification = fUrgent;
233  }
234 
235 }
bool GetCreateAlcoveTrackingOutput() const
static QCString str

Member Data Documentation

bool LBNEStackingAction::doImportanceWeightSelection
mutableprivate

Definition at line 48 of file LBNEStackingAction.hh.

std::ofstream LBNEStackingAction::fOutHadronAtVectex
mutableprivate

Definition at line 46 of file LBNEStackingAction.hh.

std::ofstream LBNEStackingAction::fOutHadronAtVectexCl
mutableprivate

Definition at line 47 of file LBNEStackingAction.hh.

double LBNEStackingAction::fStackingKillingThreshold
mutableprivate

Definition at line 42 of file LBNEStackingAction.hh.

LBNERunManager* LBNEStackingAction::pRunManager
private

Definition at line 41 of file LBNEStackingAction.hh.


The documentation for this class was generated from the following files: