18 #include "art/Framework/Core/EDProducer.h"
19 #include "art/Framework/Core/ModuleMacros.h"
20 #include "art/Utilities/make_tool.h"
32 class LArPandoraModularShowerCreation;
50 const int& iter = -1);
69 std::vector<std::unique_ptr<ShowerRecoTools::IShowerTool>>
fShowerTools;
76 art::ServiceHandle<geo::Geometry>
fGeom;
85 const std::string& InstanceName,
90 bool check_element = ShowerEleHolder.
CheckElement(InstanceName);
92 throw cet::exception(
"LArPandoraModularShowerCreation")
93 <<
"To get a element that does not exist" << std::endl;
98 throw cet::exception(
"LArPandoraModularShowerCreation")
99 <<
"Tried to get a ptr that does not exist" << std::endl;
104 if (iter != -1) { index = iter; }
115 fhicl::ParameterSet
const& pset)
117 , fPFParticleLabel(pset.get<art::InputTag>(
"PFParticleLabel"))
118 , fAllowPartialShowers(pset.get<
bool>(
"AllowPartialShowers"))
119 , fVerbose(pset.get<
int>(
"Verbose", 0))
120 , fUseAllParticles(pset.get<
bool>(
"UseAllParticles",
false))
121 , fShowerStartPositionLabel(pset.get<std::string>(
"ShowerStartPositionLabel"))
122 , fShowerDirectionLabel(pset.get<std::string>(
"ShowerDirectionLabel"))
123 , fShowerEnergyLabel(pset.get<std::string>(
"ShowerEnergyLabel"))
124 , fShowerLengthLabel(pset.get<std::string>(
"ShowerLengthLabel"))
125 , fShowerOpeningAngleLabel(pset.get<std::string>(
"ShowerOpeningAngleLabel"))
126 , fShowerdEdxLabel(pset.get<std::string>(
"ShowerdEdxLabel"))
127 , fShowerBestPlaneLabel(pset.get<std::string>(
"ShowerBestPlaneLabel"))
130 auto tool_psets = pset.get<std::vector<fhicl::ParameterSet>>(
"ShowerFinderTools");
131 for (
auto& tool_pset : tool_psets) {
133 const std::string tool_name(tool_pset.get<std::string>(
"tool_type"));
136 if (!tool_pset.has_key(
"PFParticleLabel")) {
139 const std::string PFParticleLabelString(fPFParticleLabel.label() +
":" +
140 fPFParticleLabel.instance() +
":" +
141 fPFParticleLabel.process());
143 tool_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
144 fhicl::ParameterSet base_pset = tool_pset.get<fhicl::ParameterSet>(
"BaseTools");
145 fhicl::ParameterSet alg_pset = base_pset.get<fhicl::ParameterSet>(
"LArPandoraShowerAlg");
146 alg_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
147 base_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerAlg", alg_pset);
148 tool_pset.put_or_replace<fhicl::ParameterSet>(
"BaseTools", base_pset);
150 if (tool_pset.has_key(
"LArPandoraShowerCheatingAlg")) {
151 fhicl::ParameterSet cheat_alg_pset =
152 tool_pset.get<fhicl::ParameterSet>(
"LArPandoraShowerCheatingAlg");
153 cheat_alg_pset.put<std::string>(
"PFParticleLabel", PFParticleLabelString);
154 cheat_alg_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerAlg", alg_pset);
155 tool_pset.put_or_replace<fhicl::ParameterSet>(
"LArPandoraShowerCheatingAlg",
161 if (!tool_pset.has_key(
"Verbose")) { tool_pset.put<
int>(
"Verbose", fVerbose); }
163 fShowerTools.push_back(art::make_tool<ShowerRecoTools::IShowerTool>(tool_pset));
164 fShowerToolNames.push_back(tool_name);
166 fNumPlanes =
fGeom->Nplanes();
170 std::vector<std::string> SetupTools;
171 for (
unsigned int i = 0; i < fShowerTools.size(); ++i) {
172 if (std::find(SetupTools.begin(), SetupTools.end(), fShowerToolNames[i]) != SetupTools.end()) {
175 fShowerTools[i]->SetPtr(&producesCollector());
176 fShowerTools[i]->InitaliseProducerPtr(uniqueproducerPtrs);
177 fShowerTools[i]->InitialiseProducers();
182 produces<std::vector<recob::Shower>>();
183 produces<art::Assns<recob::Shower, recob::Hit>>();
184 produces<art::Assns<recob::Shower, recob::Cluster>>();
185 produces<art::Assns<recob::Shower, recob::SpacePoint>>();
186 produces<art::Assns<recob::Shower, recob::PFParticle>>();
189 uniqueproducerPtrs.SetShowerUniqueProduerPtr(
type<std::vector<recob::Shower>>(),
"shower");
190 uniqueproducerPtrs.SetShowerUniqueProduerPtr(
type<art::Assns<recob::Shower, recob::Cluster>>(),
191 "clusterAssociationsbase");
192 uniqueproducerPtrs.SetShowerUniqueProduerPtr(
type<art::Assns<recob::Shower, recob::Hit>>(),
193 "hitAssociationsbase");
194 uniqueproducerPtrs.SetShowerUniqueProduerPtr(
type<art::Assns<recob::Shower, recob::SpacePoint>>(),
195 "spShowerAssociationsbase");
196 uniqueproducerPtrs.SetShowerUniqueProduerPtr(
type<art::Assns<recob::Shower, recob::PFParticle>>(),
197 "pfShowerAssociationsbase");
199 uniqueproducerPtrs.PrintPtrs();
207 uniqueproducerPtrs.SetPtrMakers(evt);
211 auto const pfpHandle = evt.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
212 std::vector<art::Ptr<recob::PFParticle>> pfps;
213 art::fill_ptr_vector(pfps, pfpHandle);
216 auto const clusterHandle = evt.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
219 const art::FindManyP<recob::Hit>& fmh =
221 const art::FindManyP<recob::Cluster>& fmcp =
223 const art::FindManyP<recob::SpacePoint>& fmspp =
238 for (
auto const& pfp : pfps) {
244 if (!fUseAllParticles && pfp->PdgCode() != 11 && pfp->PdgCode() != 22)
continue;
247 const std::vector<art::Ptr<recob::Cluster>> showerClusters = fmcp.at(pfp.key());
248 const std::vector<art::Ptr<recob::SpacePoint>> showerSpacePoints = fmspp.at(pfp.key());
251 if (!showerClusters.size())
continue;
254 mf::LogInfo(
"LArPandoraModularShowerCreation")
255 <<
"Running on shower: " << shower_iter << std::endl;
260 for (
unsigned int i = 0; i < fShowerTools.size(); i++) {
264 mf::LogInfo(
"LArPandoraModularShowerCreation")
265 <<
"Running shower tool: " << fShowerToolNames[i] << std::endl;
266 std::string evd_disp_append = fShowerToolNames[i] +
"_iteration" +
std::to_string(0) +
"_" +
267 this->moduleDescription().moduleLabel();
269 err = fShowerTools[i]->RunShowerTool(pfp, evt, showerEleHolder, evd_disp_append);
271 if (err && fVerbose) {
272 mf::LogError(
"LArPandoraModularShowerCreation")
273 <<
"Error in shower tool: " << fShowerToolNames[i] <<
" with code: " << err << std::endl;
278 if (!fAllowPartialShowers) {
282 if (!showerEleHolder.
CheckElement(fShowerStartPositionLabel)) {
284 mf::LogError(
"LArPandoraModularShowerCreation")
285 <<
"The start position is not set in the element holder. bailing" << std::endl;
288 if (!showerEleHolder.
CheckElement(fShowerDirectionLabel)) {
290 mf::LogError(
"LArPandoraModularShowerCreation")
291 <<
"The direction is not set in the element holder. bailing" << std::endl;
294 if (!showerEleHolder.
CheckElement(fShowerEnergyLabel)) {
296 mf::LogError(
"LArPandoraModularShowerCreation")
297 <<
"The energy is not set in the element holder. bailing" << std::endl;
302 mf::LogError(
"LArPandoraModularShowerCreation")
303 <<
"The dEdx is not set in the element holder. bailing" << std::endl;
306 if (!showerEleHolder.
CheckElement(fShowerBestPlaneLabel)) {
308 mf::LogError(
"LArPandoraModularShowerCreation")
309 <<
"The BestPlane is not set in the element holder. bailing" << std::endl;
312 if (!showerEleHolder.
CheckElement(fShowerLengthLabel)) {
314 mf::LogError(
"LArPandoraModularShowerCreation")
315 <<
"The length is not set in the element holder. bailing" << std::endl;
318 if (!showerEleHolder.
CheckElement(fShowerOpeningAngleLabel)) {
320 mf::LogError(
"LArPandoraModularShowerCreation")
321 <<
"The opening angle is not set in the element holder. bailing" << std::endl;
327 if (!elements_are_set) {
329 mf::LogError(
"LArPandoraModularShowerCreation")
330 <<
"Not all the elements in the property holder which should be set are not. Bailing. "
336 bool producers_are_set = uniqueproducerPtrs.CheckAllProducedElements(showerEleHolder);
337 if (!producers_are_set) {
339 mf::LogError(
"LArPandoraModularShowerCreation")
340 <<
"Not all the elements in the property holder which are produced are not set. "
348 TVector3 ShowerStartPosition(-999, -999, -999);
349 TVector3 ShowerDirection(-999, -999, -999);
351 std::vector<double> ShowerdEdx(fNumPlanes, -999);
353 double ShowerLength(-999);
354 double ShowerOpeningAngle(-999);
356 TVector3 ShowerStartPositionErr(-999, -999, -999);
357 TVector3 ShowerDirectionErr(-999, -999, -999);
358 std::vector<double> ShowerEnergyErr(fNumPlanes, -999);
359 std::vector<double> ShowerdEdxErr(fNumPlanes, -999);
362 if (showerEleHolder.
CheckElement(fShowerStartPositionLabel))
364 fShowerStartPositionLabel, ShowerStartPosition, ShowerStartPositionErr);
365 if (showerEleHolder.
CheckElement(fShowerDirectionLabel))
367 fShowerDirectionLabel, ShowerDirection, ShowerDirectionErr);
369 err += showerEleHolder.
GetElementAndError(fShowerEnergyLabel, ShowerEnergy, ShowerEnergyErr);
371 err += showerEleHolder.
GetElementAndError(fShowerdEdxLabel, ShowerdEdx, ShowerdEdxErr);
372 if (showerEleHolder.
CheckElement(fShowerBestPlaneLabel))
373 err += showerEleHolder.
GetElement(fShowerBestPlaneLabel, BestPlane);
375 err += showerEleHolder.
GetElement(fShowerLengthLabel, ShowerLength);
376 if (showerEleHolder.
CheckElement(fShowerOpeningAngleLabel))
377 err += showerEleHolder.
GetElement(fShowerOpeningAngleLabel, ShowerOpeningAngle);
380 throw cet::exception(
"LArPandoraModularShowerCreation")
381 <<
"Error in LArPandoraModularShowerCreation Module. A Check on a shower property failed "
387 std::cout <<
"Shower Vertex: X:" << ShowerStartPosition.X()
388 <<
" Y: " << ShowerStartPosition.Y() <<
" Z: " << ShowerStartPosition.Z()
390 std::cout <<
"Shower Direction: X:" << ShowerDirection.X() <<
" Y: " << ShowerDirection.Y()
391 <<
" Z: " << ShowerDirection.Z() << std::endl;
393 for (
unsigned int i = 0; i < fNumPlanes; i++) {
394 std::cout <<
" Plane " << i <<
": " << ShowerdEdx.at(i);
398 for (
unsigned int i = 0; i < fNumPlanes; i++) {
399 std::cout <<
" Plane " << i <<
": " << ShowerEnergy.at(i);
402 std::cout <<
"Shower Best Plane: " << BestPlane << std::endl;
403 std::cout <<
"Shower Length: " << ShowerLength << std::endl;
404 std::cout <<
"Shower Opening Angle: " << ShowerOpeningAngle << std::endl;
410 if (ShowerdEdx.size() != fNumPlanes) {
411 throw cet::exception(
"LArPandoraModularShowerCreation")
412 <<
"dEdx vector is wrong size: " << ShowerdEdx.size()
413 <<
" compared to Nplanes: " << fNumPlanes << std::endl;
415 if (ShowerEnergy.size() != fNumPlanes) {
416 throw cet::exception(
"LArPandoraModularShowerCreation")
417 <<
"Energy vector is wrong size: " << ShowerEnergy.size()
418 <<
" compared to Nplanes: " << fNumPlanes << std::endl;
436 art::Ptr<recob::Shower> ShowerPtr =
437 this->GetProducedElementPtr<recob::Shower>(
"shower", showerEleHolder);
440 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::PFParticle>>(
441 ShowerPtr, pfp,
"pfShowerAssociationsbase");
444 for (
auto const&
cluster : showerClusters) {
447 std::vector<art::Ptr<recob::Hit>> ClusterHits = fmh.at(
cluster.key());
448 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::Cluster>>(
449 ShowerPtr,
cluster,
"clusterAssociationsbase");
452 for (
auto const&
hit : ClusterHits) {
453 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::Hit>>(
454 ShowerPtr,
hit,
"hitAssociationsbase");
459 for (
auto const& sp : showerSpacePoints) {
460 uniqueproducerPtrs.AddSingle<art::Assns<recob::Shower, recob::SpacePoint>>(
461 ShowerPtr, sp,
"spShowerAssociationsbase");
465 uniqueproducerPtrs.AddDataProducts(showerEleHolder);
469 for (
auto const& fShowerTool : fShowerTools) {
471 assn_err += fShowerTool->AddAssociations(pfp, evt, showerEleHolder);
473 if (!fAllowPartialShowers && assn_err > 0) {
475 mf::LogError(
"LArPandoraModularShowerCreation")
476 <<
"A association failed and not allowing partial showers. The association will not be "
477 "added to the event "
486 uniqueproducerPtrs.MoveAllToEvent(evt);
489 uniqueproducerPtrs.reset();
const std::string fShowerOpeningAngleLabel
art::ServiceHandle< geo::Geometry > fGeom
const std::string fShowerEnergyLabel
const std::string fShowerdEdxLabel
reco::shower::ShowerProducedPtrsHolder uniqueproducerPtrs
int GetShowerNumber() const
LArPandoraModularShowerCreation(fhicl::ParameterSet const &pset)
Declaration of signal hit object.
EResult err(const char *call)
const std::string fShowerDirectionLabel
std::vector< std::string > fShowerToolNames
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
const art::InputTag fPFParticleLabel
const bool fAllowPartialShowers
constexpr int kBogusI
obviously bogus integer value
Set of hits with a 2D structure.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
double ShowerEnergy(const ShowerStruct3D &ss3)
bool CheckUniqueProduerPtr(const std::string &Name) const
art::Ptr< T > GetProducedElementPtr(const std::string &InstanceName, const reco::shower::ShowerElementHolder &ShowerEleHolder, const int &iter=-1)
void PrintElements() const
void produce(art::Event &evt)
const std::string fShowerStartPositionLabel
bool CheckElement(const std::string &Name) const
const std::string fShowerLengthLabel
int GetElement(const std::string &Name, T &Element) const
Declaration of cluster object.
const std::string fShowerBestPlaneLabel
void SetShowerNumber(int &shower_iter)
const bool fUseAllParticles
std::string to_string(WindowPattern const &pattern)
std::vector< std::unique_ptr< ShowerRecoTools::IShowerTool > > fShowerTools
int GetElementAndError(const std::string &Name, T &Element, T2 &ElementErr) const
2D representation of charge deposited in the TDC/wire plane
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
bool CheckAllElementTags() const
BEGIN_PROLOG could also be cout