12 #ifndef PARTICLELISTACTION_SERVICE_H 13 #define PARTICLELISTACTION_SERVICE_H 42 class EDProductGetter;
47 #include "Geant4/globals.hh" 59 #include <unordered_map> 74 void preUserTrackingAction(
const G4Track*)
override;
75 void postUserTrackingAction(
const G4Track*)
override;
76 void userSteppingAction(
const G4Step*)
override;
83 void beginOfEventAction(
const G4Event*)
override;
88 void endOfEventAction(
const G4Event*)
override;
99 productGetter_ = productGetter;
104 return std::move(partCol_);
108 return std::move(droppedPartCol_);
112 return std::move(droppedCol_);
115 std::unique_ptr<art::Assns<simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo>>
118 return std::move(tpassn_);
125 std::unique_ptr<util::PositionInVolumeFilter>&
filter)
128 std::set<std::string> vol_names(keepParticlesInVolumes.begin(), keepParticlesInVolumes.end());
130 if (
empty(vol_names)) filter = {};
134 std::vector<std::vector<TGeoNode const*>> node_paths = geom.FindAllVolumePaths(vol_names);
138 GeoVolumePairs.reserve(node_paths.size());
142 for (
size_t iVolume = 0; iVolume < node_paths.size(); ++iVolume) {
143 std::vector<TGeoNode const*> path = node_paths[iVolume];
145 auto pTransl =
new TGeoTranslation(0., 0., 0.);
146 auto pRot =
new TGeoRotation();
147 for (TGeoNode
const* node : path) {
148 TGeoTranslation thistranslate(*node->GetMatrix());
149 TGeoRotation thisrotate(*node->GetMatrix());
150 pTransl->Add(&thistranslate);
151 *pRot = *pRot * thisrotate;
156 auto pTransl2 =
new TGeoTranslation(
157 pTransl->GetTranslation()[0], pTransl->GetTranslation()[1], pTransl->GetTranslation()[2]);
158 double phi = 0., theta = 0., psi = 0.;
159 pRot->GetAngles(phi, theta, psi);
160 auto pRot2 =
new TGeoRotation();
161 pRot2->SetAngles(phi, theta, psi);
163 auto pTransf =
new TGeoCombiTrans(*pTransl2, *pRot2);
164 GeoVolumePairs.emplace_back(node_paths[iVolume].back()->GetVolume(), pTransf);
167 filter = std::make_unique<util::PositionInVolumeFilter>(std::move(GeoVolumePairs));
169 void ParticleFilter() { CreateParticleFilter(fKeepParticlesInVolumes, fFilter); }
172 CreateParticleFilter(fKeepDroppedParticlesInVolumes, fDroppedFilter);
180 bool keepFullTrajectory =
false;
181 bool isInVolume =
false;
182 bool isDropped =
false;
191 keepFullTrajectory =
false;
209 std::cout <<
"ParticleInfo_t: " << std::endl;
210 std::cout <<
" particle: " << particle << std::endl;
211 std::cout <<
" keepFullTrajectory: " << keepFullTrajectory << std::endl;
212 std::cout <<
" isInVolume: " << isInVolume << std::endl;
213 std::cout <<
" isDropped: " << isDropped << std::endl;
214 std::cout <<
" truthIndex: " << truthIndex << std::endl;
230 int GetParentage(
int trackid)
const;
237 G4bool fstoreTrajectories;
239 std::vector<std::string>
241 std::map<int, int> fParentIDMap;
249 mutable int fTrackIDOffset;
251 bool fKeepEMShowerDaughters;
255 bool fSparsifyTrajectories;
261 std::vector<std::string>
269 std::unique_ptr<sim::ParticleList>
271 std::vector<art::Handle<std::vector<simb::MCTruth>>>
const*
293 std::unique_ptr<std::vector<simb::MCParticle>>
partCol_;
297 std::unique_ptr<art::Assns<simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo>>
301 std::unique_ptr<util::PositionInVolumeFilter>
fFilter;
302 std::unique_ptr<util::PositionInVolumeFilter>
304 void AddPointToCurrentParticle(TLorentzVector
const& pos,
306 TLorentzVector
const& mom,
307 std::string
const& process);
314 #endif // PARTICLELISTACTION_SERVICE_H
std::map< int, std::set< int > > fdroppedTracksMap
map <ParentID, set: list of track ids for which no MCParticle was created>
std::unique_ptr< sim::ParticleList > fdroppedParticleList
bool fKeepSecondToLast
tell whether or not to force keeping the second to last point
std::unique_ptr< art::Assns< simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo > > tpassn_
std::vector< VolumeInfo_t > AllVolumeInfo_t
std::unique_ptr< util::PositionInVolumeFilter > fFilter
filter for particles to be kept
void CreateParticleFilter(std::vector< std::string > keepParticlesInVolumes, std::unique_ptr< util::PositionInVolumeFilter > &filter)
Grabs a particle filter.
double fSparsifyMargin
set the sparsification margin
Contains data associated to particles from detector simulation.
std::unique_ptr< std::vector< simb::MCParticle > > ParticleCollection()
void DroppedParticleFilter()
bool fKeepTransportation
tell whether or not to keep the transportation process
std::unique_ptr< art::Assns< simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo > > AssnsMCTruthToMCParticle()
std::unique_ptr< std::vector< simb::MCParticle > > partCol_
std::map< int, size_t > fMCTIndexMap
Map: particle track ID -> index of primary parent in std::vector<simb::MCTruth> object.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< std::string > fKeepParticlesInVolumes
Only write particles that have trajectories through these volumes.
constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
std::unique_ptr< std::vector< simb::MCParticle > > DroppedParticleCollection()
void setInputCollections(std::vector< art::Handle< std::vector< simb::MCTruth >>> const &mclists)
#define DECLARE_ART_SERVICE(svc, scope)
std::map< size_t, std::pair< std::string, G4bool > > fMCTIndexToGeneratorMap
Map: MCTruthIndex -> generator, input label of generator and keepGenerator decision.
std::unordered_map< std::string, int > fNotStoredCounterUMap
Map: not stored process and counter.
bool fStoreDroppedMCParticles
Whether to keep a sim::MCParticle list of dropped particles.
std::unique_ptr< sim::ParticleAncestryMap > DroppedTracksCollection()
std::unique_ptr< sim::ParticleAncestryMap > droppedCol_
bool storeDropped() const
Return whether dropped particles are stored.
std::map< int, int > fTargetIDMap
key is original track ID, value is ID to assign for downstream objs (e.g. SimEdeps) ...
std::unique_ptr< std::vector< simb::MCParticle > > droppedPartCol_
This collection will hold the MCParticleLite objects created from dropped particles.
bool isGeneratedParticleIndex(GeneratedParticleIndex_t index)
Returns whether the specified one is an acceptable generator index.
std::vector< std::string > fKeepDroppedParticlesInVolumes
std::unique_ptr< util::PositionInVolumeFilter > fDroppedFilter
bool isPrimary() const
Returns whether there is a particle.
std::vector< std::string > fNotStoredPhysics
Physics processes that will not be stored.
std::map< int, int > GetTargetIDMap()
simb::GeneratedParticleIndex_t truthInfoIndex() const
Returns the index of the particle in the generator truth record.
void clear()
Resets the information (does not release memory it does not own)
std::vector< std::string > fkeepGenTrajectories
std::map< int, bool > fMCTPrimProcessKeepMap
Map: particle trakc ID -> boolean decision to keep or not full trajectory points. ...
bool hasParticle() const
Returns whether there is a particle.
static constexpr ProductID invalid() noexcept
bool fkeepOnlyPrimaryFullTraj
std::map< int, simb::GeneratedParticleIndex_t > fPrimaryTruthMap
Map: particle track ID -> index of primary information in MC truth.
Defines classes to filter particles based on their trajectory.
Particle list in DetSim contains Monte Carlo particle information.
std::vector< art::Handle< std::vector< simb::MCTruth > > > const * fMCLists
MCTruthCollection input lists.
void setPtrInfo(art::ProductID pid, art::EDProductGetter const *productGetter)
Common type definitions for data products (and a bit beyond).
art framework interface to geometry description
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
std::size_t GeneratedParticleIndex_t
Type of particle index in the generator truth record (simb::MCTruth).