LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
LArPandora.cxx
Go to the documentation of this file.
1 
9 
12 #include "art_root_io/TFileService.h"
13 #include "cetlib/cpu_timer.h"
15 
18 
20 
30 
32 
33 #include "Api/PandoraApi.h"
34 
37 
38 #include <iostream>
39 #include <limits>
40 
41 namespace lar_pandora {
42 
44  : ILArPandora(pset)
45  , m_configFile(pset.get<std::string>("ConfigFile"))
46  , m_shouldRunAllHitsCosmicReco(pset.get<bool>("ShouldRunAllHitsCosmicReco"))
47  , m_shouldRunStitching(pset.get<bool>("ShouldRunStitching"))
48  , m_shouldRunCosmicHitRemoval(pset.get<bool>("ShouldRunCosmicHitRemoval"))
49  , m_shouldRunSlicing(pset.get<bool>("ShouldRunSlicing"))
50  , m_shouldRunNeutrinoRecoOption(pset.get<bool>("ShouldRunNeutrinoRecoOption"))
51  , m_shouldRunCosmicRecoOption(pset.get<bool>("ShouldRunCosmicRecoOption"))
52  , m_shouldPerformSliceId(pset.get<bool>("ShouldPerformSliceId"))
53  , m_shouldProduceAllOutcomes(pset.get<bool>("ProduceAllOutcomes", false))
54  , m_printOverallRecoStatus(pset.get<bool>("PrintOverallRecoStatus", false))
55  , m_generatorModuleLabel(pset.get<std::string>("GeneratorModuleLabel", ""))
56  , m_geantModuleLabel(pset.get<std::string>("GeantModuleLabel", "largeant"))
57  , m_simChannelModuleLabel(pset.get<std::string>("SimChannelModuleLabel", m_geantModuleLabel))
58  , m_hitfinderModuleLabel(pset.get<std::string>("HitFinderModuleLabel"))
59  , m_backtrackerModuleLabel(pset.get<std::string>("BackTrackerModuleLabel", ""))
60  , m_allOutcomesInstanceLabel(pset.get<std::string>("AllOutcomesInstanceLabel", "allOutcomes"))
61  , m_enableProduction(pset.get<bool>("EnableProduction", true))
62  , m_enableDetectorGaps(pset.get<bool>("EnableLineGaps", true))
63  , m_enableMCParticles(pset.get<bool>("EnableMCParticles", false))
64  , m_disableRealDataCheck(pset.get<bool>("DisableRealDataCheck", false))
65  , m_lineGapsCreated(false)
66  , m_collectHitsTool{
67  art::make_tool<IHitCollectionTool>(this->ConstructHitCollectionToolParameterSet(pset))}
68  {
69  m_inputSettings.m_useHitWidths = pset.get<bool>("UseHitWidths", true);
70  m_inputSettings.m_useBirksCorrection = pset.get<bool>("UseBirksCorrection", false);
71  m_inputSettings.m_useActiveBoundingBox = pset.get<bool>("UseActiveBoundingBox", false);
72  m_inputSettings.m_uidOffset = pset.get<int>("UidOffset", 100000000);
73  m_inputSettings.m_dx_cm = pset.get<double>("DefaultHitWidth", 0.5);
74  m_inputSettings.m_int_cm = pset.get<double>("InteractionLength", 84.);
75  m_inputSettings.m_rad_cm = pset.get<double>("RadiationLength", 14.);
76  m_inputSettings.m_dEdX_mip = pset.get<double>("dEdXmip", 2.);
77  m_inputSettings.m_mips_max = pset.get<double>("MipsMax", 50.);
78  m_inputSettings.m_mips_if_negative = pset.get<double>("MipsIfNegative", 0.);
79  m_inputSettings.m_mips_to_gev = pset.get<double>("MipsToGeV", 3.5e-4);
80  m_inputSettings.m_recombination_factor = pset.get<double>("RecombinationFactor", 0.63);
82  m_outputSettings.m_shouldProduceSlices = pset.get<bool>("ShouldProduceSlices", true);
84  pset.get<bool>("ShouldProduceTestBeamInteractionVertices", false);
86  "TestBeamInteractionVerticesInstanceLabel", "testBeamInteractionVertices");
90 
91  if (m_enableProduction) {
92  // Set up the instance names to produces
93  std::vector<std::string> instanceNames({""});
94  if (m_shouldProduceAllOutcomes) instanceNames.push_back(m_allOutcomesInstanceLabel);
95 
96  for (const std::string& instanceName : instanceNames) {
97  produces<std::vector<recob::PFParticle>>(instanceName);
98  produces<std::vector<recob::SpacePoint>>(instanceName);
99  produces<std::vector<recob::Cluster>>(instanceName);
100  produces<std::vector<recob::Vertex>>(instanceName);
101  produces<std::vector<larpandoraobj::PFParticleMetadata>>(instanceName);
102 
103  produces<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>(instanceName);
104  produces<art::Assns<recob::PFParticle, recob::SpacePoint>>(instanceName);
105  produces<art::Assns<recob::PFParticle, recob::Cluster>>(instanceName);
106  produces<art::Assns<recob::PFParticle, recob::Vertex>>(instanceName);
107  produces<art::Assns<recob::SpacePoint, recob::Hit>>(instanceName);
108  produces<art::Assns<recob::Cluster, recob::Hit>>(instanceName);
109 
111  // ATTN: Test beam interaction vertex instance label appended to current instance name to preserve unique label in multiple instance case
112  produces<std::vector<recob::Vertex>>(
114  produces<art::Assns<recob::PFParticle, recob::Vertex>>(
116  }
117 
119  produces<std::vector<anab::T0>>(instanceName);
120  produces<art::Assns<recob::PFParticle, anab::T0>>(instanceName);
121  }
122 
124  produces<std::vector<recob::Slice>>(instanceName);
125  produces<art::Assns<recob::Slice, recob::Hit>>(instanceName);
126  produces<art::Assns<recob::PFParticle, recob::Slice>>(instanceName);
127  }
128  }
129  }
130  }
131 
132  //------------------------------------------------------------------------------------------------------------------------------------------
133 
135  {
136  LArDriftVolumeList driftVolumeList;
139 
140  this->CreatePandoraInstances();
141 
142  if (!m_pPrimaryPandora)
143  throw cet::exception("LArPandora")
144  << " LArPandora::beginJob - failed to create primary Pandora instance " << std::endl;
145 
148 
149  // Pass basic LArTPC information to pandora instances
151 
152  // If using global drift volume approach, pass details of gaps between daughter volumes to the pandora instance
153  if (m_enableDetectorGaps) {
154  LArDetectorGapList listOfGaps;
156  LArPandoraInput::CreatePandoraDetectorGaps(m_inputSettings, driftVolumeList, listOfGaps);
157  }
158 
159  // Parse Pandora settings xml files
161  }
162 
163  //------------------------------------------------------------------------------------------------------------------------------------------
164 
166  {
167  IdToHitMap idToHitMap;
168  this->CreatePandoraInput(evt, idToHitMap);
169  this->RunPandoraInstances();
170  this->ProcessPandoraOutput(evt, idToHitMap);
171  this->ResetPandoraInstances();
172  }
173 
174  //------------------------------------------------------------------------------------------------------------------------------------------
175 
177  {
178  // ATTN Should complete gap creation in begin job callback, but channel status service functionality unavailable at that point
181  m_lineGapsCreated = true;
182  }
183 
184  HitVector artHits;
185  SimChannelVector artSimChannels;
186  HitsToTrackIDEs artHitsToTrackIDEs;
187  MCParticleVector artMCParticleVector;
188  RawMCParticleVector generatorArtMCParticleVector;
189  MCTruthToMCParticles artMCTruthToMCParticles;
190  MCParticlesToMCTruth artMCParticlesToMCTruth;
191 
192  bool areSimChannelsValid(false);
193 
194  m_collectHitsTool->CollectHits(evt, m_hitfinderModuleLabel, artHits);
195 
197  LArPandoraHelper::CollectMCParticles(evt, m_geantModuleLabel, artMCParticleVector);
198 
199  if (!m_generatorModuleLabel.empty())
201  evt, m_generatorModuleLabel, generatorArtMCParticleVector);
202 
204  evt, m_geantModuleLabel, artMCTruthToMCParticles, artMCParticlesToMCTruth);
205 
207  evt, m_simChannelModuleLabel, artSimChannels, areSimChannelsValid);
208  if (!artSimChannels.empty()) {
209  LArPandoraHelper::BuildMCParticleHitMaps(evt, artHits, artSimChannels, artHitsToTrackIDEs);
210  }
211  else if (!areSimChannelsValid) {
212  if (m_backtrackerModuleLabel.empty())
213  throw cet::exception("LArPandora")
214  << "LArPandora::CreatePandoraInput - Can't build MCParticle to Hit map." << std::endl
215  << "No SimChannels found with label \"" << m_simChannelModuleLabel
216  << "\", and BackTrackerModuleLabel isn't set in FHiCL." << std::endl;
217 
219  evt, m_hitfinderModuleLabel, m_backtrackerModuleLabel, artHitsToTrackIDEs);
220  }
221  else {
222  mf::LogDebug("LArPandora")
223  << " *** LArPandora::CreatePandoraInput - empty list of sim channels found " << std::endl;
224  }
225  }
226 
228  evt, m_inputSettings, m_driftVolumeMap, artHits, idToHitMap);
229 
232  artMCTruthToMCParticles,
233  artMCParticlesToMCTruth,
234  generatorArtMCParticleVector);
235  LArPandoraInput::CreatePandoraMCLinks2D(m_inputSettings, idToHitMap, artHitsToTrackIDEs);
236  }
237  }
238 
239  //------------------------------------------------------------------------------------------------------------------------------------------
240 
242  {
243  if (m_enableProduction) {
246 
251  }
252  }
253  }
254 
255  //------------------------------------------------------------------------------------------------------------------------------------------
256 
258  const fhicl::ParameterSet& pset)
259  {
260  if (pset.has_key("HitCollectionTool")) {
261  return pset.get<fhicl::ParameterSet>("HitCollectionTool");
262  }
263 
264  fhicl::ParameterSet psetHitCollection;
265  psetHitCollection.put<std::string>("tool_type", "LArPandoraHitCollectionToolDefault");
266  return psetHitCollection;
267  }
268 
269 } // namespace lar_pandora
std::map< int, art::Ptr< recob::Hit > > IdToHitMap
Definition: ILArPandora.h:24
Header file for the pfo helper class.
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.
Definition: LArPandora.cxx:176
Base producer module for reconstructing recob::PFParticles from recob::Hits.
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 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...
const pandora::Pandora * m_pPrimaryPandora
static void LoadGeometry(LArDriftVolumeList &outputVolumeList, LArDriftVolumeMap &outputVolumeMap, const bool useActiveBoundingBox)
Load drift volume geometry.
ILArPandora class.
Definition: ILArPandora.h:29
Declaration of signal hit object.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
std::string m_testBeamInteractionVerticesInstanceLabel
The label for the test beam interaction vertices.
std::vector< LArDriftVolume > LArDriftVolumeList
const pandora::Pandora * m_pPrimaryPandora
std::string m_allOutcomesInstanceLabel
The label for the instance producing all outcomes.
STL namespace.
bool m_disableRealDataCheck
Whether to check if the input file contains real data before accessing MC information.
Definition: LArPandora.h:73
bool m_shouldProduceAllOutcomes
Steering: whether to produce all reconstruction outcomes.
Definition: LArPandora.h:57
bool m_isNeutrinoRecoOnlyNoSlicing
If we are running the neutrino reconstruction only with no slicing.
std::string m_backtrackerModuleLabel
The back tracker module label.
Definition: LArPandora.h:64
bool isRealData() const
Definition: Event.cc:53
Particle class.
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. ATTN: This function is needed as accessing generator (opposed to Geant4) level MCParticles requires use of MCTruth block.
bool m_lineGapsCreated
Book-keeping: whether line gap creation has been called.
Definition: LArPandora.h:74
std::string m_hitfinderModuleLabel
The hit finder module label.
std::map< art::Ptr< recob::Hit >, TrackIDEVector > HitsToTrackIDEs
bool m_shouldRunNeutrinoRecoOption
Steering: whether to run neutrino reconstruction for each slice.
Definition: LArPandora.h:52
fhicl::ParameterSet ConstructHitCollectionToolParameterSet(const fhicl::ParameterSet &pset)
Definition: LArPandora.cxx:257
const pandora::Pandora * m_pPrimaryPandora
The address of the primary pandora instance.
Definition: ILArPandora.h:85
std::vector< simb::MCParticle > RawMCParticleVector
LArDriftVolumeMap m_driftVolumeMap
The map from volume id to drift volume.
Definition: LArPandora.h:81
virtual void CreatePandoraInstances()=0
Create pandora instances.
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
std::string m_generatorModuleLabel
The generator module label.
Definition: LArPandora.h:60
std::string m_geantModuleLabel
The geant module label.
Definition: LArPandora.h:61
T get(std::string const &key) const
Definition: ParameterSet.h:314
static void CreatePandoraMCLinks2D(const Settings &settings, const HitMap &hitMap, const HitsToTrackIDEs &hitToParticleMap)
Create links between the 2D hits and Pandora MC particles.
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
void ProcessPandoraOutput(art::Event &evt, const IdToHitMap &idToHitMap)
Process pandora output particle flow objects.
Definition: LArPandora.cxx:241
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 ProduceArtOutput(const Settings &settings, const IdToHitMap &idToHitMap, art::Event &evt)
Convert the Pandora PFOs into ART clusters and write into ART event.
static void LoadDetectorGaps(LArDetectorGapList &listOfGaps, const bool useActiveBoundingBox)
Load the 2D gaps that go with the chosen geometry.
bool m_shouldRunCosmicRecoOption
Steering: whether to run cosmic-ray reconstruction for each slice.
Definition: LArPandora.h:54
bool has_key(std::string const &key) const
virtual void ResetPandoraInstances()=0
Reset all associated pandora instances.
Declaration of cluster object.
LArPandora(fhicl::ParameterSet const &pset)
Constructor.
Definition: LArPandora.cxx:43
bool m_shouldProduceTestBeamInteractionVertices
Whether to write the test beam interaction vertices in a separate collection.
static void CreatePandoraReadoutGaps(const Settings &settings, const LArDriftVolumeMap &driftVolumeMap)
Create pandora line gaps to cover any (continuous regions of) bad channels.
bool m_enableDetectorGaps
Whether to pass detector gap information to Pandora instances.
Definition: LArPandora.h:69
void produce(art::Event &evt)
Definition: LArPandora.cxx:165
bool m_shouldRunStitching
Steering: whether to stitch cosmic-ray muons crossing between volumes.
Definition: LArPandora.h:47
LArPandoraInput::Settings m_inputSettings
The lar pandora input settings.
Definition: LArPandora.h:78
std::vector< art::Ptr< recob::Hit > > HitVector
static void CreatePandoraLArTPCs(const Settings &settings, const LArDriftVolumeList &driftVolumeList)
Create pandora LArTPCs to represent the different drift volumes in use.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
LArPandoraOutput::Settings m_outputSettings
The lar pandora output settings.
Definition: LArPandora.h:79
Provides recob::Track data product.
std::vector< art::Ptr< sim::SimChannel > > SimChannelVector
bool m_shouldProduceAllOutcomes
If all outcomes should be produced in separate collections (choose false if you only require the cons...
std::unique_ptr< IHitCollectionTool > m_collectHitsTool
art tool used to collect the hits
Definition: LArPandora.h:76
std::vector< LArDetectorGap > LArDetectorGapList
bool m_shouldProduceSlices
Whether to produce output slices e.g. may not want to do this if only (re)processing single slices...
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Header file detailing content for use with particle flow reconstruction at liquid argon time projecti...
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.
bool m_shouldRunSlicing
Steering: whether to slice events into separate regions for processing.
Definition: LArPandora.h:50
virtual void RunPandoraInstances()=0
Run all associated pandora instances.
TCEvent evt
Definition: DataStructs.cxx:8
bool m_enableMCParticles
Whether to pass mc information to Pandora instances to aid development.
Definition: LArPandora.h:71
bool m_enableProduction
Whether to persist output products.
Definition: LArPandora.h:68
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 CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
std::string m_simChannelModuleLabel
The SimChannel producer module label.
Definition: LArPandora.h:62
void put(std::string const &key)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::string m_hitfinderModuleLabel
The hit finder module label.
Definition: LArPandora.h:63
virtual void ConfigurePandoraInstances()=0
Configure pandora instances.