Skip to content

Commit bfca3b8

Browse files
committed
New feature: Keep record of where a track originates
This allows to see which volumes have a (source) influence on which other volumes.
1 parent 515d2ae commit bfca3b8

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

include/MCStepLogger/SimpleStepAnalysis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class SimpleStepAnalysis : public MCAnalysis
5858
TH1I* histNStepsPerPDG;
5959
TH1I* histNStepsPerVolSorted;
6060

61+
// track production origins per module and volume
62+
TH1I* histOriginPerMod;
63+
TH1I* histOriginPerVol;
64+
TH1I* histOriginPerVolSorted;
65+
6166
// accumulated number of secondaries produced per volume
6267
TH1I* histNSecondariesPerVol;
6368
// accumulated number of secondaries produces per module

include/MCStepLogger/StepInfo.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ struct StepLookups {
6060
std::vector<int> tracktopdg;
6161
std::vector<int> tracktoparent; // when parent is -1 we mean primary
6262
std::vector<int> stepcounterpertrack;
63-
std::vector<float> tracktoenergy; // mapping of trackID to the track energy
63+
64+
std::vector<int> trackorigin; // the volumeID where the track originates
65+
std::vector<float> tracktoenergy; // mapping of trackID to the track energy
6466
std::vector<bool> crossedboundary; // if track every crossed a geometry boundary
6567
std::vector<bool> producedsecondary; // if track ever produced a secondary
6668

@@ -117,6 +119,14 @@ struct StepLookups {
117119
}
118120
}
119121

122+
void setTrackOrigin(int trackindex, int volID)
123+
{
124+
if (trackindex >= trackorigin.size()) {
125+
trackorigin.resize(trackindex + 1, -1);
126+
}
127+
trackorigin[trackindex] = volID;
128+
}
129+
120130
bool initSensitiveVolLookup(std::string const& filename);
121131

122132
void insertParent(int trackindex, int parent)

src/SimpleStepAnalysis.cxx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ void SimpleStepAnalysis::initialize()
3434
histNStepsPerMod = getHistogram<TH1I>("nStepsPerMod", 1, 2., 1.);
3535
// accumulated number of steps per volume
3636
histNStepsPerVol = getHistogram<TH1I>("nStepsPerVol", 1, 2., 1.);
37+
38+
histOriginPerMod = getHistogram<TH1I>("OriginsPerMod", 1, 2., 1.);
39+
histOriginPerVol = getHistogram<TH1I>("OriginsPerVol", 1, 2., 1.);
40+
histOriginPerVolSorted = getHistogram<TH1I>("OriginsPerVolSorted", 1, 2., 1.);
41+
3742
// accumulated number of steps per pdg
3843
histNStepsPerPDG = getHistogram<TH1I>("nStepsPerPDG", 1, 2., 1.);
3944
histNStepsPerVolSorted = getHistogram<TH1I>("nStepsPerVolSorted", 1, 2., 1.);
@@ -115,9 +120,7 @@ void SimpleStepAnalysis::analyze(const std::vector<StepInfo>* const steps, const
115120

116121
// loop over all steps in an event
117122
for (const auto& step : *steps) {
118-
int currentTrackID = step.trackID;
119-
bool newtrack = (currentTrackID != oldTrackID);
120-
if (newtrack) oldTrackID = currentTrackID;
123+
121124

122125
// prepare for PDG ids and volume names
123126
mAnalysisManager->getLookupPDG(step.trackID, pdgId);
@@ -133,6 +136,12 @@ void SimpleStepAnalysis::analyze(const std::vector<StepInfo>* const steps, const
133136
continue;
134137
}
135138

139+
int currentTrackID = step.trackID;
140+
bool newtrack = (currentTrackID != oldTrackID);
141+
if (newtrack) {
142+
oldTrackID = currentTrackID;
143+
}
144+
136145
if (keepsteps) {
137146
stepptr = &step;
138147
steptree->Fill();
@@ -145,6 +154,16 @@ void SimpleStepAnalysis::analyze(const std::vector<StepInfo>* const steps, const
145154
histTrackEnergySpectrum->Fill(log10f(step.E));
146155
histTrackPDGSpectrum->Fill(pdgasstring.c_str(),1);
147156
histTrackProdProcess->Fill(step.getProdProcessAsString(),1);
157+
158+
auto originid = mAnalysisManager->getLookups()->trackorigin[step.trackID];
159+
std::string originVolName;
160+
// to store the module name
161+
std::string originModName;
162+
mAnalysisManager->getLookupVolName(originid, originVolName);
163+
mAnalysisManager->getLookupModName(originid, originModName);
164+
165+
histOriginPerMod->Fill(originModName.c_str(), 1);
166+
histOriginPerVol->Fill(originVolName.c_str(), 1);
148167
}
149168

150169
// record number of steps per module
@@ -169,6 +188,11 @@ void SimpleStepAnalysis::finalize()
169188
histNStepsPerVolSorted->SetName("nStepsPerVolSorted");
170189
histNStepsPerVolSorted->LabelsOption(">", "X");
171190

191+
*histOriginPerVolSorted = *histOriginPerVol;
192+
histOriginPerVolSorted->SetName("OriginPerVolSorted");
193+
histOriginPerVolSorted->LabelsOption(">", "X");
194+
histOriginPerVolSorted->SetBins(30, 0, 30);
195+
172196
std::cerr << "MOD have " << histNStepsPerMod->GetEntries() << " entries \n";
173197

174198
*histTrackPDGSpectrumSorted = *histTrackPDGSpectrum;

src/StepInfo.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ StepInfo::StepInfo(TVirtualMC* mc)
118118
if (mc->IsTrackExiting()) {
119119
lookupstructures.setCrossedBoundary(trackID, true);
120120
}
121-
121+
122+
if (mc->IsNewTrack()) {
123+
lookupstructures.setTrackOrigin(trackID, volId);
124+
}
125+
122126
prodprocess = stack->GetCurrentTrack()->GetUniqueID();
123127

124128
TArrayI procs;

0 commit comments

Comments
 (0)