EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicMCApplication.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicMCApplication.cxx
1 //
2 // AYK (ayk@bnl.gov), 2015/08/04
3 //
4 // A derived class with the only purpose to expand functionality
5 // of FairMCApplication::Stepping() call; basically want to bypass
6 // FairMCApplication sensitive volume branch (say avoid declaring
7 // killer volumes sensitive with th eonly purpose to enter
8 // EicDetector::ProcessHits();
9 //
10 
11 #include <TVirtualMC.h>
12 #include <TParticle.h>
13 
14 #include <FairRunSim.h>
15 #include <FairModule.h>
16 
17 #include <PndStack.h>
18 
19 #include <EicDetector.h>
20 #include <EicRunSim.h>
21 #include <EicMCApplication.h>
22 
23 // ---------------------------------------------------------------------------------------
24 
25 //
26 // NB: functionality has not been checked thoroughly after moving the codes from
27 // EicDetector::ProcessHits() to this call; do LATER;
28 //
29 
31 {
32  bool stopped = false;
33  int copyNo, volumeID = gMC->CurrentVolID(copyNo);
34  fModVolIter =fModVolMap.find(volumeID);
35  //printf("%3d -> %s\n", fModVolIter->second, GetModule(fModVolIter->second)->GetName());
36 
38  //printf("-> %s (%s)\n", module->GetName(), gMC->CurrentVolName());
39 
40  Int_t trackID = gMC->GetStack()->GetCurrentTrackNumber();
41  TParticle *particle = ((PndStack*)gMC->GetStack())->GetParticle(trackID);
42 
43  // Theoretically EicRunSim singleton may be NULL (simulation started via FairRunSim
44  // rather than EicRunSim); practically EicMCApplication is only instantiated from
45  // EicRunSim::Init(); yet check that pointer is not NULL in all places;
47 
48  // Well, yes, it looks like this call should be here, next to AddMoCaPoint();
49  // FIXME: check what's wrong with small steps;
50  //if (fStep > 0.001) {
51  if (/*gMC->TrackStep() > 0.001 &&*/ fRun) {
52  FluxMonitorGrid *flgrid = fRun->GetFluxMonitorGrid();
53 
54  // Let FluxMonitorGrid class do the actual job;
55  if (flgrid) {
56  TLorentzVector fPosOut, fMomOut;
57  gMC->TrackPosition(fPosOut);
58  gMC->TrackMomentum(fMomOut);
59  //double step = gMC->TrackStep();
60 
61 #if _OFF_
62  {
63  static int last = -1;
64 
65  if (particle->GetPdgCode() == 2212) {
66  //if (trackID != last) printf("\n");
67  last = trackID;
68 
69  //printf("track#%4d (%d %d %d %d %d -> E: %9.4f) -> XYZ: %8.2f %8.2f %8.2f -> step %8.5f\n", trackID,
70  // 1000*(gMC->Etot() - particle->GetMass()),
71  // gMC->IsNewTrack(), gMC->IsTrackEntering(), gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(),
72  // fPosOut.Vect()[0], fPosOut.Vect()[1], fPosOut.Vect()[2], gMC->TrackStep());
73  } //if
74  }
75 #endif
76 
77  //if (1E9*gMC->TrackTime() > 1E7 && particle->GetPdgCode() == 2112 &&
78  // 1E9*(gMC->Etot() - particle->GetMass()) > 1E5)
79  //printf("%3d (%4d)-> %7.1f ms, eKin: %7.1f eV\n", particle->GetPdgCode(), trackID,
80  // 1E3*gMC->TrackTime(), 1E9*(gMC->Etot() - particle->GetMass()));
81  flgrid->AddEntry(particle->GetPdgCode(), gMC->Etot() - particle->GetMass(), gMC->Edep(),
82  //fPosIn.Vect(), fPosOut.Vect());
83  // FIXME: this assumes ~straight track (or small step);
84  fPosOut.Vect() - gMC->TrackStep() * fMomOut.Vect().Unit(),
85  fPosOut.Vect());
86  } //if
87  } //if
88 
89  // If this is a valid EicDetector, few more actions;
90  EicDetector *detector = dynamic_cast<EicDetector*> (module);
91  if (detector) {
92  //printf(" -> %s\n", detector->GetName());
93 
94  // Check 1) secondary kill flag, 2) whether this volume kills such particles (for now
95  // do not distinguish PDG codes; extend functionality later if necessary);
96  if ((!particle->IsPrimary() && fRun && fRun->SuppressSecondariesFlag()) ||
97  detector->IsKillerVolume(gMC->CurrentVolName())) {
98  gMC->StopTrack();
99  stopped = true;
100  } //if
101 
102  // Check energy monitor volumes;
103  detector->CheckEnergyMonitors(gMC->CurrentVolName(), trackID, particle->GetPdgCode(),
104  particle->IsPrimary(),
105  gMC->IsTrackEntering(), gMC->IsTrackExiting(), gMC->Etot());
106 
107  // Record track ID in the global list;
108  if (fRun && !fRun->IgnoreBlackHoleVolumesFlag() &&
109  detector->gptr && detector->gptr->IsBlackHoleVolume(gMC->CurrentVolName()))
110  // Yes, primary particle(s) are parents anyway?; THINK on this later;
111  /*if (!particle->IsPrimary())*/ EicBlackHole::InsertIntoTrackList(trackID);
112  } //if
113 
114  // THINK: so, do not call FairMCApplication stepper at all; it looks I can ignore FLUKA
115  // PreTrack() workaround as well (see FairMCApplication::Stepping() call);
116  if (!stopped && (!fRun || !fRun->SuppressFairRootSteppingCallFlag()))
118 } // EicMCApplication::Stepping()
119 
120 // ---------------------------------------------------------------------------------------
121