Public Member Functions | Private Attributes | List of all members
ShowerRecoTools::ShowerDirectionCheater Class Reference
Inheritance diagram for ShowerRecoTools::ShowerDirectionCheater:
ShowerRecoTools::IShowerTool

Public Member Functions

 ShowerDirectionCheater (const fhicl::ParameterSet &pset)
 
int CalculateElement (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
 

Private Attributes

shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
 
art::ServiceHandle< art::TFileService > tfs
 
const art::InputTag fPFParticleLabel
 
const unsigned int fNSegments
 
const bool fRMSFlip
 
const bool fVertexFlip
 
TTree * Tree
 
float vertexDotProduct
 
float rmsGradient
 
const std::string fShowerStartPositionInputLabel
 
const std::string fTrueParticleInputLabel
 
const std::string fShowerDirectionOutputLabel
 

Additional Inherited Members

- Private Member Functions inherited from ShowerRecoTools::IShowerTool
 IShowerTool (const fhicl::ParameterSet &pset)
 
virtual ~IShowerTool () noexcept=default
 
int RunShowerTool (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, std::string evd_display_name_append="")
 
virtual void InitialiseProducers ()
 
void SetPtr (art::ProducesCollector *collector)
 
void InitaliseProducerPtr (reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
 
virtual int AddAssociations (const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
 
const shower::LArPandoraShowerAlgGetLArPandoraShowerAlg () const
 
template<class T >
art::Ptr< T > GetProducedElementPtr (std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
 
template<class T >
void InitialiseProduct (std::string Name, std::string InstanceName="")
 
template<class T , class A , class B >
void AddSingle (A &a, B &b, std::string Name)
 
int GetVectorPtrSize (std::string Name)
 
void PrintPtrs ()
 
void PrintPtr (std::string Name)
 

Detailed Description

Definition at line 18 of file ShowerDirectionCheater_tool.cc.

Constructor & Destructor Documentation

ShowerRecoTools::ShowerDirectionCheater::ShowerDirectionCheater ( const fhicl::ParameterSet pset)

Definition at line 53 of file ShowerDirectionCheater_tool.cc.

54  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
55  , fLArPandoraShowerCheatingAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerCheatingAlg"))
56  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
57  , fNSegments(pset.get<unsigned int>("NSegments"))
58  , fRMSFlip(pset.get<bool>("RMSFlip"))
59  , fVertexFlip(pset.get<bool>("VertexFlip"))
60  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
61  , fTrueParticleInputLabel(pset.get<std::string>("TrueParticleInputLabel"))
62  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
63  {
64  if (fVertexFlip || fRMSFlip) {
65  Tree = tfs->make<TTree>("DebugTreeDirCheater", "DebugTree from shower direction cheater");
66  if (fVertexFlip) Tree->Branch("vertexDotProduct", &vertexDotProduct);
67  if (fRMSFlip) Tree->Branch("rmsGradient", &rmsGradient);
68  }
69  }
art::ServiceHandle< art::TFileService > tfs
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:271
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:28

Member Function Documentation

int ShowerRecoTools::ShowerDirectionCheater::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 72 of file ShowerDirectionCheater_tool.cc.

75  {
76 
77  const simb::MCParticle* trueParticle;
78 
79  //Get the hits from the shower:
80  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
81 
82  auto const clockData =
84  auto const detProp =
86 
87  if (ShowerEleHolder.CheckElement(fTrueParticleInputLabel)) {
88  ShowerEleHolder.GetElement(fTrueParticleInputLabel, trueParticle);
89  }
90  else {
91 
92  //Could store these in the shower element holder and just calculate once?
93  std::map<int, const simb::MCParticle*> trueParticles =
95  std::map<int, std::vector<int>> showersMothers =
97 
98  //Get the clusters
99  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
100  art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
101  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
102 
103  //Get the hit association
104  art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
105 
106  std::vector<art::Ptr<recob::Hit>> showerHits;
107  for (auto const& cluster : clusters) {
108  //Get the hits
109  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
110  showerHits.insert(showerHits.end(), hits.begin(), hits.end());
111  }
112 
113  //Get the true particle from the shower
114  std::pair<int, double> ShowerTrackInfo =
116  clockData, showersMothers, showerHits, 2);
117 
118  if (ShowerTrackInfo.first == -99999) {
119  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
120  return 1;
121  }
122  trueParticle = trueParticles[ShowerTrackInfo.first];
123  ShowerEleHolder.SetElement(trueParticle, fTrueParticleInputLabel);
124  }
125 
126  if (!trueParticle) {
127  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
128  return 1;
129  }
130 
131  TVector3 trueDir = TVector3{trueParticle->Px(), trueParticle->Py(), trueParticle->Pz()}.Unit();
132 
133  TVector3 trueDirErr = {-999, -999, -999};
134  ShowerEleHolder.SetElement(trueDir, trueDirErr, fShowerDirectionOutputLabel);
135 
136  if (fRMSFlip || fVertexFlip) {
137 
138  // Reset the tree values to defaults
139  rmsGradient = std::numeric_limits<float>::lowest();
140  vertexDotProduct = std::numeric_limits<float>::lowest();
141 
142  //Get the SpacePoints and hits
143  art::FindManyP<recob::SpacePoint> fmspp(pfpHandle, Event, fPFParticleLabel);
144 
145  if (!fmspp.isValid()) {
146  throw cet::exception("ShowerDirectionCheater")
147  << "Trying to get the spacepoint and failed. Something is not configured correctly. "
148  "Stopping ";
149  }
150 
151  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
152  art::FindManyP<recob::Hit> fmh(spHandle, Event, fPFParticleLabel);
153  if (!fmh.isValid()) {
154  throw cet::exception("ShowerDirectionCheater")
155  << "Spacepoint and hit association not valid. Stopping.";
156  }
157  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
158 
159  if (spacePoints.size() < 3) {
160  mf::LogWarning("ShowerDirectionCheater")
161  << spacePoints.size() << " spacepoints in shower, not calculating direction" << std::endl;
162  return 1;
163  }
164 
165  //Get Shower Centre
166  float TotalCharge;
167 
168  const TVector3 ShowerCentre = IShowerTool::GetLArPandoraShowerAlg().ShowerCentre(
169  clockData, detProp, spacePoints, fmh, TotalCharge);
170 
171  //Check if we are pointing the correct direction or not, First try the start position
172  if (ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel) && fVertexFlip) {
173 
174  //Get the General direction as the vector between the start position and the centre
175  TVector3 StartPositionVec = {-999, -999, -999};
176  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPositionVec);
177 
178  TVector3 GeneralDir = (ShowerCentre - StartPositionVec).Unit();
179 
180  //Dot product
181  vertexDotProduct = trueDir.Dot(GeneralDir);
182  }
183 
184  if (fRMSFlip) {
185  //Otherwise Check against the RMS of the shower. Method adapated from EMShower Thanks Mike.
187  spacePoints, ShowerCentre, trueDir, fNSegments);
188  }
189  Tree->Fill();
190  }
191 
192  return 0;
193  }
double Py(const int i=0) const
Definition: MCParticle.h:231
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
double Px(const int i=0) const
Definition: MCParticle.h:230
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
double RMSShowerGradient(std::vector< art::Ptr< recob::SpacePoint >> &sps, const TVector3 &ShowerCentre, const TVector3 &Direction, const unsigned int nSegments) const
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
key_type key() const noexcept
Definition: Ptr.h:216
std::map< int, std::vector< int > > GetTrueChain(std::map< int, const simb::MCParticle * > &trueParticles) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:87
std::pair< int, double > TrueParticleIDFromTrueChain(detinfo::DetectorClocksData const &clockData, std::map< int, std::vector< int >> const &ShowersMothers, std::vector< art::Ptr< recob::Hit >> const &hits, int planeid) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double Pz(const int i=0) const
Definition: MCParticle.h:232
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)

Member Data Documentation

shower::LArPandoraShowerCheatingAlg ShowerRecoTools::ShowerDirectionCheater::fLArPandoraShowerCheatingAlg
private

Definition at line 30 of file ShowerDirectionCheater_tool.cc.

const unsigned int ShowerRecoTools::ShowerDirectionCheater::fNSegments
private

Definition at line 38 of file ShowerDirectionCheater_tool.cc.

const art::InputTag ShowerRecoTools::ShowerDirectionCheater::fPFParticleLabel
private

Definition at line 36 of file ShowerDirectionCheater_tool.cc.

const bool ShowerRecoTools::ShowerDirectionCheater::fRMSFlip
private

Definition at line 39 of file ShowerDirectionCheater_tool.cc.

const std::string ShowerRecoTools::ShowerDirectionCheater::fShowerDirectionOutputLabel
private

Definition at line 50 of file ShowerDirectionCheater_tool.cc.

const std::string ShowerRecoTools::ShowerDirectionCheater::fShowerStartPositionInputLabel
private

Definition at line 48 of file ShowerDirectionCheater_tool.cc.

const std::string ShowerRecoTools::ShowerDirectionCheater::fTrueParticleInputLabel
private

Definition at line 49 of file ShowerDirectionCheater_tool.cc.

const bool ShowerRecoTools::ShowerDirectionCheater::fVertexFlip
private

Definition at line 41 of file ShowerDirectionCheater_tool.cc.

float ShowerRecoTools::ShowerDirectionCheater::rmsGradient
private

Definition at line 46 of file ShowerDirectionCheater_tool.cc.

art::ServiceHandle<art::TFileService> ShowerRecoTools::ShowerDirectionCheater::tfs
private

Definition at line 33 of file ShowerDirectionCheater_tool.cc.

TTree* ShowerRecoTools::ShowerDirectionCheater::Tree
private

Definition at line 44 of file ShowerDirectionCheater_tool.cc.

float ShowerRecoTools::ShowerDirectionCheater::vertexDotProduct
private

Definition at line 45 of file ShowerDirectionCheater_tool.cc.


The documentation for this class was generated from the following file: