Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
LArPandora.cxx
Go to the documentation of this file.
1
9
10#include "art/Framework/Principal/Event.h"
11#include "art/Utilities/make_tool.h"
12#include "art_root_io/TFileService.h"
13#include "cetlib/cpu_timer.h"
14
15#include "lardata/DetectorInfoServices/DetectorClocksService.h"
16#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
17
18#include "larcore/Geometry/Geometry.h"
19
20#include "lardataobj/AnalysisBase/T0.h"
21#include "lardataobj/RecoBase/Cluster.h"
22#include "lardataobj/RecoBase/Hit.h"
23#include "lardataobj/RecoBase/PCAxis.h"
24#include "lardataobj/RecoBase/PFParticle.h"
25#include "lardataobj/RecoBase/Shower.h"
26#include "lardataobj/RecoBase/SpacePoint.h"
27#include "lardataobj/RecoBase/Track.h"
28#include "lardataobj/RecoBase/Vertex.h"
29
30#include "nusimdata/SimulationBase/MCParticle.h"
31
32#include "Api/PandoraApi.h"
33
36
37#include <iostream>
38#include <limits>
39
40namespace lar_pandora {
41
42 LArPandora::LArPandora(fhicl::ParameterSet const& pset)
43 : ILArPandora(pset)
44 , m_configFile(pset.get<std::string>("ConfigFile"))
45 , m_shouldRunAllHitsCosmicReco(pset.get<bool>("ShouldRunAllHitsCosmicReco"))
46 , m_shouldRunStitching(pset.get<bool>("ShouldRunStitching"))
47 , m_shouldRunCosmicHitRemoval(pset.get<bool>("ShouldRunCosmicHitRemoval"))
48 , m_shouldRunSlicing(pset.get<bool>("ShouldRunSlicing"))
49 , m_shouldRunNeutrinoRecoOption(pset.get<bool>("ShouldRunNeutrinoRecoOption"))
50 , m_shouldRunCosmicRecoOption(pset.get<bool>("ShouldRunCosmicRecoOption"))
51 , m_shouldPerformSliceId(pset.get<bool>("ShouldPerformSliceId"))
52 , m_shouldProduceAllOutcomes(pset.get<bool>("ProduceAllOutcomes", false))
53 , m_printOverallRecoStatus(pset.get<bool>("PrintOverallRecoStatus", false))
54 , m_generatorModuleLabel(pset.get<std::string>("GeneratorModuleLabel", ""))
55 , m_geantModuleLabel(pset.get<std::string>("GeantModuleLabel", "largeant"))
56 , m_simChannelModuleLabel(pset.get<std::string>("SimChannelModuleLabel", m_geantModuleLabel))
57 , m_hitfinderModuleLabel(pset.get<std::string>("HitFinderModuleLabel"))
58 , m_backtrackerModuleLabel(pset.get<std::string>("BackTrackerModuleLabel", ""))
59 , m_allOutcomesInstanceLabel(pset.get<std::string>("AllOutcomesInstanceLabel", "allOutcomes"))
60 , m_enableProduction(pset.get<bool>("EnableProduction", true))
61 , m_enableDetectorGaps(pset.get<bool>("EnableLineGaps", true))
62 , m_enableMCParticles(pset.get<bool>("EnableMCParticles", false))
63 , m_disableRealDataCheck(pset.get<bool>("DisableRealDataCheck", false))
64 , m_lineGapsCreated(false)
65 , m_collectHitsTool{
66 art::make_tool<IHitCollectionTool>(this->ConstructHitCollectionToolParameterSet(pset))}
67 {
68 m_inputSettings.m_useHitWidths = pset.get<bool>("UseHitWidths", true);
69 m_inputSettings.m_useBirksCorrection = pset.get<bool>("UseBirksCorrection", false);
70 m_inputSettings.m_useActiveBoundingBox = pset.get<bool>("UseActiveBoundingBox", false);
71 m_inputSettings.m_uidOffset = pset.get<int>("UidOffset", 100000000);
72 m_inputSettings.m_dx_cm = pset.get<double>("DefaultHitWidth", 0.5);
73 m_inputSettings.m_int_cm = pset.get<double>("InteractionLength", 84.);
74 m_inputSettings.m_rad_cm = pset.get<double>("RadiationLength", 14.);
75 m_inputSettings.m_dEdX_mip = pset.get<double>("dEdXmip", 2.);
76 m_inputSettings.m_mips_max = pset.get<double>("MipsMax", 50.);
77 m_inputSettings.m_mips_if_negative = pset.get<double>("MipsIfNegative", 0.);
78 m_inputSettings.m_mips_to_gev = pset.get<double>("MipsToGeV", 3.5e-4);
79 m_inputSettings.m_recombination_factor = pset.get<double>("RecombinationFactor", 0.63);
81 m_outputSettings.m_shouldProduceSlices = pset.get<bool>("ShouldProduceSlices", true);
83 pset.get<bool>("ShouldProduceTestBeamInteractionVertices", false);
85 "TestBeamInteractionVerticesInstanceLabel", "testBeamInteractionVertices");
89
91 // Set up the instance names to produces
92 std::vector<std::string> instanceNames({""});
93 if (m_shouldProduceAllOutcomes) instanceNames.push_back(m_allOutcomesInstanceLabel);
94
95 for (const std::string& instanceName : instanceNames) {
96 produces<std::vector<recob::PFParticle>>(instanceName);
97 produces<std::vector<recob::SpacePoint>>(instanceName);
98 produces<std::vector<recob::Cluster>>(instanceName);
99 produces<std::vector<recob::Vertex>>(instanceName);
100 produces<std::vector<larpandoraobj::PFParticleMetadata>>(instanceName);
101
102 produces<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>(instanceName);
103 produces<art::Assns<recob::PFParticle, recob::SpacePoint>>(instanceName);
104 produces<art::Assns<recob::PFParticle, recob::Cluster>>(instanceName);
105 produces<art::Assns<recob::PFParticle, recob::Vertex>>(instanceName);
106 produces<art::Assns<recob::SpacePoint, recob::Hit>>(instanceName);
107 produces<art::Assns<recob::Cluster, recob::Hit>>(instanceName);
108
110 // ATTN: Test beam interaction vertex instance label appended to current instance name to preserve unique label in multiple instance case
111 produces<std::vector<recob::Vertex>>(
113 produces<art::Assns<recob::PFParticle, recob::Vertex>>(
115 }
116
118 produces<std::vector<anab::T0>>(instanceName);
119 produces<art::Assns<recob::PFParticle, anab::T0>>(instanceName);
120 }
121
123 produces<std::vector<recob::Slice>>(instanceName);
124 produces<art::Assns<recob::Slice, recob::Hit>>(instanceName);
125 produces<art::Assns<recob::PFParticle, recob::Slice>>(instanceName);
126 }
127 }
128 }
129 }
130
131 //------------------------------------------------------------------------------------------------------------------------------------------
132
134 {
135 LArDriftVolumeList driftVolumeList;
138
140
142 throw cet::exception("LArPandora")
143 << " LArPandora::beginJob - failed to create primary Pandora instance " << std::endl;
144
147
148 // Pass basic LArTPC information to pandora instances
150
151 // If using global drift volume approach, pass details of gaps between daughter volumes to the pandora instance
153 LArDetectorGapList listOfGaps;
156 }
157
158 // Parse Pandora settings xml files
160 }
161
162 //------------------------------------------------------------------------------------------------------------------------------------------
163
164 void LArPandora::produce(art::Event& evt)
165 {
166 IdToHitMap idToHitMap;
167 this->CreatePandoraInput(evt, idToHitMap);
168 this->RunPandoraInstances();
169 this->ProcessPandoraOutput(evt, idToHitMap);
170 this->ResetPandoraInstances();
171 }
172
173 //------------------------------------------------------------------------------------------------------------------------------------------
174
175 void LArPandora::CreatePandoraInput(art::Event& evt, IdToHitMap& idToHitMap)
176 {
177 // ATTN Should complete gap creation in begin job callback, but channel status service functionality unavailable at that point
180 m_lineGapsCreated = true;
181 }
182
183 HitVector artHits;
184 SimChannelVector artSimChannels;
185 HitsToTrackIDEs artHitsToTrackIDEs;
186 MCParticleVector artMCParticleVector;
187 RawMCParticleVector generatorArtMCParticleVector;
188 MCTruthToMCParticles artMCTruthToMCParticles;
189 MCParticlesToMCTruth artMCParticlesToMCTruth;
190
191 bool areSimChannelsValid(false);
192
193 m_collectHitsTool->CollectHits(evt, m_hitfinderModuleLabel, artHits);
194
195 if (m_enableMCParticles && (m_disableRealDataCheck || !evt.isRealData())) {
197
198 if (!m_generatorModuleLabel.empty())
200 evt, m_generatorModuleLabel, generatorArtMCParticleVector);
201
203 evt, m_geantModuleLabel, artMCTruthToMCParticles, artMCParticlesToMCTruth);
204
206 evt, m_simChannelModuleLabel, artSimChannels, areSimChannelsValid);
207 if (!artSimChannels.empty()) {
208 LArPandoraHelper::BuildMCParticleHitMaps(evt, artHits, artSimChannels, artHitsToTrackIDEs);
209 }
210 else if (!areSimChannelsValid) {
211 if (m_backtrackerModuleLabel.empty())
212 throw cet::exception("LArPandora")
213 << "LArPandora::CreatePandoraInput - Can't build MCParticle to Hit map." << std::endl
214 << "No SimChannels found with label \"" << m_simChannelModuleLabel
215 << "\", and BackTrackerModuleLabel isn't set in FHiCL." << std::endl;
216
218 evt, m_hitfinderModuleLabel, m_backtrackerModuleLabel, artHitsToTrackIDEs);
219 }
220 else {
221 mf::LogDebug("LArPandora")
222 << " *** LArPandora::CreatePandoraInput - empty list of sim channels found " << std::endl;
223 }
224 }
225
227 evt, m_inputSettings, m_driftVolumeMap, artHits, idToHitMap);
228
229 if (m_enableMCParticles && (m_disableRealDataCheck || !evt.isRealData())) {
231 artMCTruthToMCParticles,
232 artMCParticlesToMCTruth,
233 generatorArtMCParticleVector);
234 LArPandoraInput::CreatePandoraMCLinks2D(m_inputSettings, idToHitMap, artHitsToTrackIDEs);
235 }
236 }
237
238 //------------------------------------------------------------------------------------------------------------------------------------------
239
253
254 //------------------------------------------------------------------------------------------------------------------------------------------
255
257 const fhicl::ParameterSet& pset)
258 {
259 if (pset.has_key("HitCollectionTool")) {
260 return pset.get<fhicl::ParameterSet>("HitCollectionTool");
261 }
262
263 fhicl::ParameterSet psetHitCollection;
264 psetHitCollection.put<std::string>("tool_type", "LArPandoraHitCollectionToolDefault");
265 return psetHitCollection;
266 }
267
268} // namespace lar_pandora
Header file detailing content for use with particle flow reconstruction at liquid argon time projecti...
Base producer module for reconstructing recob::PFParticles from recob::Hits.
Header file for the pfo helper class.
Header file for the pandora api class.
ILArPandora class.
Definition ILArPandora.h:29
virtual void RunPandoraInstances()=0
Run all associated pandora instances.
virtual void CreatePandoraInstances()=0
Create pandora instances.
virtual void ConfigurePandoraInstances()=0
Configure pandora instances.
virtual void ResetPandoraInstances()=0
Reset all associated pandora instances.
const pandora::Pandora * m_pPrimaryPandora
The address of the primary pandora instance.
Definition ILArPandora.h:85
static void LoadDetectorGaps(LArDetectorGapList &listOfGaps, const bool useActiveBoundingBox)
Load the 2D gaps that go with the chosen geometry.
static void LoadGeometry(LArDriftVolumeList &outputVolumeList, LArDriftVolumeMap &outputVolumeMap, const bool useActiveBoundingBox)
Load drift volume geometry.
static void BuildMCParticleHitMaps(const art::Event &evt, const HitVector &hitVector, const SimChannelVector &simChannelVector, HitsToTrackIDEs &hitsToTrackIDEs)
Collect the links from reconstructed hits to their true energy deposits.
static void CollectSimChannels(const art::Event &evt, const std::string &label, SimChannelVector &simChannelVector, bool &areSimChannelsValid)
Collect a vector of SimChannel objects from the ART event record.
static void CollectGeneratorMCParticles(const art::Event &evt, const std::string &label, RawMCParticleVector &particleVector)
Collect a vector of MCParticle objects from the generator in the ART event record....
static void CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
fhicl::ParameterSet ConstructHitCollectionToolParameterSet(const fhicl::ParameterSet &pset)
std::string m_allOutcomesInstanceLabel
The instance label for all outcomes.
Definition LArPandora.h:66
void CreatePandoraInput(art::Event &evt, IdToHitMap &idToHitMap)
Create pandora input hits, mc particles etc.
bool m_enableProduction
Whether to persist output products.
Definition LArPandora.h:68
LArPandoraOutput::Settings m_outputSettings
The lar pandora output settings.
Definition LArPandora.h:79
bool m_shouldProduceAllOutcomes
Steering: whether to produce all reconstruction outcomes.
Definition LArPandora.h:57
bool m_shouldRunCosmicRecoOption
Steering: whether to run cosmic-ray reconstruction for each slice.
Definition LArPandora.h:54
bool m_shouldRunSlicing
Steering: whether to slice events into separate regions for processing.
Definition LArPandora.h:50
std::string m_generatorModuleLabel
The generator module label.
Definition LArPandora.h:60
bool m_lineGapsCreated
Book-keeping: whether line gap creation has been called.
Definition LArPandora.h:74
void ProcessPandoraOutput(art::Event &evt, const IdToHitMap &idToHitMap)
Process pandora output particle flow objects.
bool m_shouldRunNeutrinoRecoOption
Steering: whether to run neutrino reconstruction for each slice.
Definition LArPandora.h:52
std::string m_geantModuleLabel
The geant module label.
Definition LArPandora.h:61
std::string m_backtrackerModuleLabel
The back tracker module label.
Definition LArPandora.h:64
std::unique_ptr< IHitCollectionTool > m_collectHitsTool
art tool used to collect the hits
Definition LArPandora.h:76
std::string m_simChannelModuleLabel
The SimChannel producer module label.
Definition LArPandora.h:62
bool m_enableDetectorGaps
Whether to pass detector gap information to Pandora instances.
Definition LArPandora.h:69
bool m_enableMCParticles
Whether to pass mc information to Pandora instances to aid development.
Definition LArPandora.h:71
LArPandora(fhicl::ParameterSet const &pset)
Constructor.
bool m_disableRealDataCheck
Whether to check if the input file contains real data before accessing MC information.
Definition LArPandora.h:73
LArPandoraInput::Settings m_inputSettings
The lar pandora input settings.
Definition LArPandora.h:78
LArDriftVolumeMap m_driftVolumeMap
The map from volume id to drift volume.
Definition LArPandora.h:81
bool m_shouldRunStitching
Steering: whether to stitch cosmic-ray muons crossing between volumes.
Definition LArPandora.h:47
void produce(art::Event &evt)
std::string m_hitfinderModuleLabel
The hit finder module label.
Definition LArPandora.h:63
const pandora::Pandora * m_pPrimaryPandora
static void CreatePandoraReadoutGaps(const Settings &settings, const LArDriftVolumeMap &driftVolumeMap)
Create pandora line gaps to cover any (continuous regions of) bad channels.
static void CreatePandoraDetectorGaps(const Settings &settings, const LArDriftVolumeList &driftVolumeList, const LArDetectorGapList &listOfGaps)
Create pandora line gaps to cover dead regions between TPCs in a global drift volume approach.
static void CreatePandoraHits2D(const art::Event &evt, const Settings &settings, const LArDriftVolumeMap &driftVolumeMap, const HitVector &hitVector, IdToHitMap &idToHitMap)
Create the Pandora 2D hits from the ART hits.
static void CreatePandoraMCLinks2D(const Settings &settings, const HitMap &hitMap, const HitsToTrackIDEs &hitToParticleMap)
Create links between the 2D hits and Pandora MC particles.
static void CreatePandoraMCParticles(const Settings &settings, const MCTruthToMCParticles &truthToParticles, const MCParticlesToMCTruth &particlesToTruth, const RawMCParticleVector &generatorMCParticleVector)
Create the Pandora MC particles from the MC particles.
static void CreatePandoraLArTPCs(const Settings &settings, const LArDriftVolumeList &driftVolumeList)
Create pandora LArTPCs to represent the different drift volumes in use.
std::string m_testBeamInteractionVerticesInstanceLabel
The label for the test beam interaction vertices.
std::string m_allOutcomesInstanceLabel
The label for the instance producing all outcomes.
std::string m_hitfinderModuleLabel
The hit finder module label.
bool m_shouldProduceTestBeamInteractionVertices
Whether to write the test beam interaction vertices in a separate collection.
bool m_isNeutrinoRecoOnlyNoSlicing
If we are running the neutrino reconstruction only with no slicing.
bool m_shouldProduceAllOutcomes
If all outcomes should be produced in separate collections (choose false if you only require the cons...
const pandora::Pandora * m_pPrimaryPandora
bool m_shouldProduceSlices
Whether to produce output slices e.g. may not want to do this if only (re)processing single slices.
static void ProduceArtOutput(const Settings &settings, const IdToHitMap &idToHitMap, art::Event &evt)
Convert the Pandora PFOs into ART clusters and write into ART event.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
std::map< art::Ptr< recob::Hit >, TrackIDEVector > HitsToTrackIDEs
std::vector< simb::MCParticle > RawMCParticleVector
std::vector< art::Ptr< sim::SimChannel > > SimChannelVector
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
std::vector< art::Ptr< recob::Hit > > HitVector
std::map< int, art::Ptr< recob::Hit > > IdToHitMap
Definition ILArPandora.h:24
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::vector< LArDetectorGap > LArDetectorGapList
std::vector< LArDriftVolume > LArDriftVolumeList