114 fhicl::ParameterSet
const& pset)
116 , fPFParticleLabel(pset.get<
art::InputTag>(
"PFParticleLabel"))
117 , fAllowPartialShowers(pset.get<bool>(
"AllowPartialShowers"))
118 , fVerbose(pset.get<int>(
"Verbose", 0))
119 , fUseAllParticles(pset.get<bool>(
"UseAllParticles", false))
120 , fShowerStartPositionLabel(pset.get<std::string>(
"ShowerStartPositionLabel"))
121 , fShowerDirectionLabel(pset.get<std::string>(
"ShowerDirectionLabel"))
122 , fShowerEnergyLabel(pset.get<std::string>(
"ShowerEnergyLabel"))
123 , fShowerLengthLabel(pset.get<std::string>(
"ShowerLengthLabel"))
124 , fShowerOpeningAngleLabel(pset.get<std::string>(
"ShowerOpeningAngleLabel"))
125 , fShowerdEdxLabel(pset.get<std::string>(
"ShowerdEdxLabel"))
126 , fShowerBestPlaneLabel(pset.get<std::string>(
"ShowerBestPlaneLabel"))
129 auto tool_psets = pset.get<std::vector<fhicl::ParameterSet>>(
"ShowerFinderTools");
130 for (
auto& tool_pset : tool_psets) {
132 const std::string tool_name(tool_pset.get<std::string>(
"tool_type"));
135 if (!tool_pset.has_key(
"PFParticleLabel")) {
142 tool_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
143 fhicl::ParameterSet base_pset = tool_pset.get<fhicl::ParameterSet>(
"BaseTools");
144 fhicl::ParameterSet alg_pset = base_pset.get<fhicl::ParameterSet>(
"LArPandoraShowerAlg");
145 alg_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
146 base_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerAlg", alg_pset);
147 tool_pset.put_or_replace<fhicl::ParameterSet>(
"BaseTools", base_pset);
149 if (tool_pset.has_key(
"LArPandoraShowerCheatingAlg")) {
150 fhicl::ParameterSet cheat_alg_pset =
151 tool_pset.get<fhicl::ParameterSet>(
"LArPandoraShowerCheatingAlg");
152 cheat_alg_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
153 cheat_alg_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerAlg", alg_pset);
154 tool_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerCheatingAlg",
160 if (!tool_pset.has_key(
"Verbose")) { tool_pset.put<
int>(
"Verbose",
fVerbose); }
162 fShowerTools.push_back(art::make_tool<ShowerRecoTools::IShowerTool>(tool_pset));
169 std::vector<std::string> SetupTools;
170 for (
unsigned int i = 0; i <
fShowerTools.size(); ++i) {
171 if (std::find(SetupTools.begin(), SetupTools.end(),
fShowerToolNames[i]) != SetupTools.end()) {
181 produces<std::vector<recob::Shower>>();
182 produces<art::Assns<recob::Shower, recob::Hit>>();
183 produces<art::Assns<recob::Shower, recob::Cluster>>();
184 produces<art::Assns<recob::Shower, recob::SpacePoint>>();
185 produces<art::Assns<recob::Shower, recob::PFParticle>>();
190 "clusterAssociationsbase");
192 "hitAssociationsbase");
194 "spShowerAssociationsbase");
196 "pfShowerAssociationsbase");
205 uniqueproducerPtrs.SetPtrMakers(evt);
209 auto const pfpHandle = evt.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
210 std::vector<art::Ptr<recob::PFParticle>> pfps;
211 art::fill_ptr_vector(pfps, pfpHandle);
214 auto const clusterHandle = evt.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
217 const art::FindManyP<recob::Hit>& fmh =
218 showerEleHolder.
GetFindManyP<recob::Hit>(clusterHandle, evt, fPFParticleLabel);
219 const art::FindManyP<recob::Cluster>& fmcp =
220 showerEleHolder.
GetFindManyP<recob::Cluster>(pfpHandle, evt, fPFParticleLabel);
221 const art::FindManyP<recob::SpacePoint>& fmspp =
222 showerEleHolder.
GetFindManyP<recob::SpacePoint>(pfpHandle, evt, fPFParticleLabel);
236 for (
auto const& pfp : pfps) {
242 if (!fUseAllParticles && pfp->PdgCode() != 11 && pfp->PdgCode() != 22)
continue;
245 const std::vector<art::Ptr<recob::Cluster>> showerClusters = fmcp.at(pfp.key());
246 const std::vector<art::Ptr<recob::SpacePoint>> showerSpacePoints = fmspp.at(pfp.key());
249 if (!showerClusters.size())
continue;
252 mf::LogInfo(
"LArPandoraModularShowerCreation")
253 <<
"Running on shower: " << shower_iter << std::endl;
258 for (
unsigned int i = 0; i < fShowerTools.size(); i++) {
262 mf::LogInfo(
"LArPandoraModularShowerCreation")
263 <<
"Running shower tool: " << fShowerToolNames[i] << std::endl;
264 std::string evd_disp_append = fShowerToolNames[i] +
"_iteration" + std::to_string(0) +
"_" +
265 this->moduleDescription().moduleLabel();
267 err = fShowerTools[i]->RunShowerTool(pfp, evt, showerEleHolder, evd_disp_append);
269 if (err && fVerbose) {
270 mf::LogError(
"LArPandoraModularShowerCreation")
271 <<
"Error in shower tool: " << fShowerToolNames[i] <<
" with code: " << err << std::endl;
276 if (!fAllowPartialShowers) {
280 if (!showerEleHolder.
CheckElement(fShowerStartPositionLabel)) {
282 mf::LogError(
"LArPandoraModularShowerCreation")
283 <<
"The start position is not set in the element holder. bailing" << std::endl;
286 if (!showerEleHolder.
CheckElement(fShowerDirectionLabel)) {
288 mf::LogError(
"LArPandoraModularShowerCreation")
289 <<
"The direction is not set in the element holder. bailing" << std::endl;
292 if (!showerEleHolder.
CheckElement(fShowerEnergyLabel)) {
294 mf::LogError(
"LArPandoraModularShowerCreation")
295 <<
"The energy is not set in the element holder. bailing" << std::endl;
300 mf::LogError(
"LArPandoraModularShowerCreation")
301 <<
"The dEdx is not set in the element holder. bailing" << std::endl;
304 if (!showerEleHolder.
CheckElement(fShowerBestPlaneLabel)) {
306 mf::LogError(
"LArPandoraModularShowerCreation")
307 <<
"The BestPlane is not set in the element holder. bailing" << std::endl;
310 if (!showerEleHolder.
CheckElement(fShowerLengthLabel)) {
312 mf::LogError(
"LArPandoraModularShowerCreation")
313 <<
"The length is not set in the element holder. bailing" << std::endl;
316 if (!showerEleHolder.
CheckElement(fShowerOpeningAngleLabel)) {
318 mf::LogError(
"LArPandoraModularShowerCreation")
319 <<
"The opening angle is not set in the element holder. bailing" << std::endl;
325 if (!elements_are_set) {
327 mf::LogError(
"LArPandoraModularShowerCreation")
328 <<
"Not all the elements in the property holder which should be set are not. Bailing. "
334 bool producers_are_set = uniqueproducerPtrs.CheckAllProducedElements(showerEleHolder);
335 if (!producers_are_set) {
337 mf::LogError(
"LArPandoraModularShowerCreation")
338 <<
"Not all the elements in the property holder which are produced are not set. "
346 geo::Point_t ShowerStartPosition(-999, -999, -999);
347 geo::Vector_t ShowerDirection(-999, -999, -999);
348 std::vector<double> ShowerEnergy(fNumPlanes, -999);
349 std::vector<double> ShowerdEdx(fNumPlanes, -999);
351 double ShowerLength(-999);
352 double ShowerOpeningAngle(-999);
354 geo::Point_t ShowerStartPositionErr(-999, -999, -999);
355 geo::Vector_t ShowerDirectionErr(-999, -999, -999);
356 std::vector<double> ShowerEnergyErr(fNumPlanes, -999);
357 std::vector<double> ShowerdEdxErr(fNumPlanes, -999);
360 if (showerEleHolder.
CheckElement(fShowerStartPositionLabel))
362 fShowerStartPositionLabel, ShowerStartPosition, ShowerStartPositionErr);
363 if (showerEleHolder.
CheckElement(fShowerDirectionLabel))
365 fShowerDirectionLabel, ShowerDirection, ShowerDirectionErr);
367 err += showerEleHolder.
GetElementAndError(fShowerEnergyLabel, ShowerEnergy, ShowerEnergyErr);
369 err += showerEleHolder.
GetElementAndError(fShowerdEdxLabel, ShowerdEdx, ShowerdEdxErr);
370 if (showerEleHolder.
CheckElement(fShowerBestPlaneLabel))
371 err += showerEleHolder.
GetElement(fShowerBestPlaneLabel, BestPlane);
373 err += showerEleHolder.
GetElement(fShowerLengthLabel, ShowerLength);
374 if (showerEleHolder.
CheckElement(fShowerOpeningAngleLabel))
375 err += showerEleHolder.
GetElement(fShowerOpeningAngleLabel, ShowerOpeningAngle);
378 throw cet::exception(
"LArPandoraModularShowerCreation")
379 <<
"Error in LArPandoraModularShowerCreation Module. A Check on a shower property failed "
385 std::cout <<
"Shower Vertex: X:" << ShowerStartPosition.X()
386 <<
" Y: " << ShowerStartPosition.Y() <<
" Z: " << ShowerStartPosition.Z()
388 std::cout <<
"Shower Direction: X:" << ShowerDirection.X() <<
" Y: " << ShowerDirection.Y()
389 <<
" Z: " << ShowerDirection.Z() << std::endl;
390 std::cout <<
"Shower dEdx:";
391 for (
unsigned int i = 0; i < fNumPlanes; i++) {
392 std::cout <<
" Plane " << i <<
": " << ShowerdEdx.at(i);
394 std::cout << std::endl;
395 std::cout <<
"Shower Energy:";
396 for (
unsigned int i = 0; i < fNumPlanes; i++) {
397 std::cout <<
" Plane " << i <<
": " << ShowerEnergy.at(i);
399 std::cout << std::endl;
400 std::cout <<
"Shower Best Plane: " << BestPlane << std::endl;
401 std::cout <<
"Shower Length: " << ShowerLength << std::endl;
402 std::cout <<
"Shower Opening Angle: " << ShowerOpeningAngle << std::endl;
408 if (ShowerdEdx.size() != fNumPlanes) {
409 throw cet::exception(
"LArPandoraModularShowerCreation")
410 <<
"dEdx vector is wrong size: " << ShowerdEdx.size()
411 <<
" compared to Nplanes: " << fNumPlanes << std::endl;
413 if (ShowerEnergy.size() != fNumPlanes) {
414 throw cet::exception(
"LArPandoraModularShowerCreation")
415 <<
"Energy vector is wrong size: " << ShowerEnergy.size()
416 <<
" compared to Nplanes: " << fNumPlanes << std::endl;
420 using namespace geo::vect;
421 recob::Shower
shower(convertTo<TVector3>(ShowerDirection),
422 convertTo<TVector3>(ShowerDirectionErr),
423 convertTo<TVector3>(ShowerStartPosition),
424 convertTo<TVector3>(ShowerDirectionErr),
435 art::Ptr<recob::Shower> ShowerPtr =
436 this->GetProducedElementPtr<recob::Shower>(
"shower", showerEleHolder);
439 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::PFParticle>>(
440 ShowerPtr, pfp,
"pfShowerAssociationsbase");
443 for (
auto const&
cluster : showerClusters) {
446 std::vector<art::Ptr<recob::Hit>> ClusterHits = fmh.at(
cluster.key());
447 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::Cluster>>(
448 ShowerPtr,
cluster,
"clusterAssociationsbase");
451 for (
auto const& hit : ClusterHits) {
452 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::Hit>>(
453 ShowerPtr, hit,
"hitAssociationsbase");
458 for (
auto const& sp : showerSpacePoints) {
459 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::SpacePoint>>(
460 ShowerPtr, sp,
"spShowerAssociationsbase");
464 uniqueproducerPtrs.AddDataProducts(showerEleHolder);
468 for (
auto const& fShowerTool : fShowerTools) {
470 assn_err += fShowerTool->AddAssociations(pfp, evt, showerEleHolder);
472 if (!fAllowPartialShowers && assn_err > 0) {
474 mf::LogError(
"LArPandoraModularShowerCreation")
475 <<
"A association failed and not allowing partial showers. The association will not be "
476 "added to the event "
485 uniqueproducerPtrs.MoveAllToEvent(evt);
488 uniqueproducerPtrs.reset();