LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrajClusterAlg.h
Go to the documentation of this file.
1 //
3 //
4 // TrajClusterAlg
5 //
6 // Bruce Baller
7 //
9 #ifndef TRAJCLUSTERALG_H
10 #define TRAJCLUSTERALG_H
11 
15 
16 // C/C++ standard libraries
17 #include <array>
18 #include <vector>
19 #include <utility> // std::pair<>
20 #include <cmath>
21 #include <iostream>
22 #include <fstream>
23 #include <iomanip>
24 #include <algorithm>
25 
26 // framework libraries
27 #include "fhiclcpp/ParameterSet.h"
37 
38 // LArSoft libraries
41 
42 #include "TH1F.h"
43 #include "TH2F.h"
44 #include "TProfile.h"
45 #include "TTree.h"
46 
47 namespace tca {
48 
50  public:
51 
52 
55 
56 
58 
59  virtual void reconfigure(fhicl::ParameterSet const& pset);
60 
61  void RunTrajClusterAlg(const art::Event & evt);
62 
63  void DefineShTree(TTree* t);
64 
65  void DefineCRTree(TTree* t);
66 
67  TjStuff const& GetTJS() const {return tjs;}
68 
69 // std::vector<short> const& GetinClus() const {return tjs.inClus; }
70 
72  std::vector<recob::Hit> YieldHits();
74 
76  std::vector<ClusterStore> const& GetClusters() const { return tjs.tcl; }
77 
79  std::vector<VtxStore> const& GetEndPoints() const { return tjs.vtx; }
80 
82  std::vector<Vtx3Store> const& GetVertices() const { return tjs.vtx3; }
83 
84  // Get the index list of matchVec entries that have PFParticle info defined
85  std::vector<PFPStruct> const& GetPFParticles() const { return tjs.pfps; }
86  // Get the cluster index of a trajectory ID
87  unsigned int GetTjClusterIndex(unsigned int TjID) { return tjs.allTraj[TjID - 1].ClusterIndex; }
88  // Get a ShowerStuct3D entry
89  unsigned short GetShowerStructSize() { return tjs.showers.size(); };
90  ShowerStruct3D const& GetShowerStruct(unsigned short ish) { return tjs.showers[ish]; };
91 
92  std::vector<unsigned int> const& GetAlgModCount() const {return fAlgModCount; }
93  std::vector<std::string> const& GetAlgBitNames() const {return AlgBitNames; }
94 
96  void ClearResults();
97 
101 
102  private:
103 
106 
107  short fMode;
108  std::vector<unsigned short> fMinPtsFit;
109  std::vector<unsigned short> fMinPts;
110  std::vector<unsigned short> fMaxAngleCode;
111  std::vector<short> fMinMCSMom;
112  float fMultHitSep;
113  float fMaxChi;
114  std::vector<float> fQualityCuts;
120 
121  bool fTagAllTraj;
122  float fMaxTrajSep;
123  bool fStudyMode;
124  bool fUseOldBackTracker {false};
125 
126  float fHitErrFac;
127  float fMinAmp;
129 
131  unsigned short fAllowNoHitWire;
132  std::vector<float> fChkStopCuts;
133 
135 
136 
141 
143 
144  // Reco-MC vertex position difference
145  TH1F* fNuVtx_dx;
146  TH1F* fNuVtx_dy;
147  TH1F* fNuVtx_dz;
150 
151  // Vertex score for 2D and 3D vertices
152  TH1F* fVx2_Score;
153  TH1F* fVx3_Score;
154 
155  // Reco-MC stopping wire difference for different MC Particles
156  TH1F* fdWire[5];
157  // EP vs KE for different MC Particles
158  TProfile* fEP_T[5];
159 
160  // SHOWER VARIABLE TREE
161  TTree* showertree;
162 
163  // Cosmic Removal Variable Tree
164  TTree* crtree;
165 
166  // number of primary particles in the event
167  unsigned short nTruPrimary;
169  float fSourceParticleEnergy; //< in MeV
170  // number of reconstructable primary particles in the event
171  unsigned short nTruPrimaryOK;
172  // number of reconstructable neutrino vertices in ALL events
173  unsigned short nTruPrimaryVtxOK;
174  // number of reconstructable neutrino vertices in ALL events that were reconstructed
175  unsigned short nTruPrimaryVtxReco;
176 
177 
178  bool prt;
179  bool mrgPrt;
180  bool didPrt;
181  int TJPrt; // Set to the WorkID of a trajectory that is being debugged
182 
185  TMVA::Reader fMVAReader;
186 
187  int fWorkID;
188 
189 
190  std::string fhitsModuleLabel;
191 
192  // variables for step crawling - updated at each TP
193  // tracking flags
194  bool fGoodTraj; // the working trajectory is good and should be stored
195  bool fTryWithNextPass; // Try with next pass settings
197  bool fQuitAlg; // A significant error occurred. Delete everything and return
198 
199  std::vector<unsigned int> fAlgModCount;
200 
201  static bool SortByMultiplet(TCHit const& a, TCHit const& b);
202 
203 // short watchInTraj;
204  // runs the TrajCluster algorithm on one plane specified by the calling routine
205  void RunStepCrawl();
206  void ReconstructAllTraj(CTP_t inCTP);
207  // Main stepping/crawling routine
208  void StepCrawl(Trajectory& tj);
209  // Add hits on the trajectory point ipt that are close to the trajectory point Pos
210  void AddHits(Trajectory& tj, unsigned short ipt, bool& sigOK);
211  // Large Angle version
212  void AddLAHits(Trajectory& tj, unsigned short ipt, bool& sigOK);
213  // Try to use unused nearby hits in all trajectories after stepping is done
214  void UseUnusedHits();
215  // Finds junk trajectories using unassigned hits
216  void FindJunkTraj(CTP_t inCTP);
217  // Finds junk trajectories using unassigned hits
218  bool MakeJunkTraj(std::vector<unsigned int> tHits, bool prt);
219  // Step through TPs starting at the end and moving to the beginning
220  void ReversePropagate(Trajectory& tj);
221  // Start a trajectory going from fromHit to (toWire, toTick)
222  bool StartTraj(Trajectory& tj, const unsigned int& fromHit, const unsigned int& toHit, const unsigned short& pass);
223  bool StartTraj(Trajectory& tj, const float& fromWire, const float& fromTick, const float& toWire, const float& toTick, const CTP_t& tCTP, const unsigned short& pass);
224  void GetHitMultiplet(unsigned int theHit, std::vector<unsigned int>& hitsInMultiplet);
225  void GetHitMultiplet(unsigned int theHit, std::vector<unsigned int>& hitsInMultiplet, unsigned short& localIndex);
226  // Returns fHits[iht]->RMS() * fScaleF * fHitErrFac * fHits[iht]->Multiplicity();
227  float HitTimeErr(const unsigned int iht);
228  // Estimates the error^2 of the time using all hits in hitVec
229  float HitsTimeErr2(const std::vector<unsigned int>& hitVec);
230  // defines HitPos, HitPosErr2 and Chg for the used hits in the trajectory point
231  void ChkStopEndPts(Trajectory& tj, bool prt);
232  void DefineHitPos(TrajPoint& tp);
233  // Decide which hits to use to determine the trajectory point
234  // fit, charge, etc. This is done by setting UseHit true and
235  // setting inTraj < 0
236  void FindUseHits(Trajectory& tj, unsigned short ipt, float maxDelta, bool useChg);
237  // Print debug output if hit iht exists in work or allTraj
238  void FindHit(std::string someText, unsigned int iht);
239  // Check allTraj -> inTraj associations
240  void ChkInTraj(std::string someText);
241  // Make clusters from all trajectories in allTraj
242  void MakeAllTrajClusters();
243  void FindMissedVxTjs(const geo::TPCID& tpcid);
244  void FindVtxTjs(CTP_t inCTP);
245  void FindVtxTraj(VtxStore& theVtx);
246  // Check the quality of the trajectory and possibly trim it
247  void CheckTraj(Trajectory& tj);
248  // Truncates the trajectory if a soft kink is found in it
249  void FindSoftKink(Trajectory& tj);
250  // Fill gaps in the trajectory
251  void FillGaps(Trajectory& tj);
252  // Check for many unused hits and try to use them
254  void CheckHiMultEndHits(Trajectory& tj);
255  // Check for high values of Delta at the beginning of the trajectory
256  void HiEndDelta(Trajectory& tj);
257  // Check for a TJ that is close to the Large Angle cut
258  void CheckNearLA();
259  // Updates the last added trajectory point fit, average hit rms, etc.
260  void UpdateTraj(Trajectory& tj);
261  // Estimate the Delta RMS of the TPs on the end of tj.
262  void UpdateDeltaRMS(Trajectory& tj);
263  void MaskBadTPs(Trajectory& tj, float const& maxChi);
264  // The hits in the TP at the end of the trajectory were masked off. Decide whether to continue stepping with the
265  // current configuration or whether to stop and possibly try with the next pass settings
266  bool MaskedHitsOK(Trajectory& tj);
267  // Any re-sizing should have been done by the calling routine. This code updates the Pass and adjusts the number of
268  // fitted points to get FitCHi < 2
269  bool StopIfBadFits(Trajectory& tj);
270  void PrepareForNextPass(Trajectory& tj);
271  // Does a local fit of just-added TPs to identify a kink while stepping.
272  // Truncates the vector and returns true if one is found.
273  void GottaKink(Trajectory& tj, unsigned short& killPts);
274  // Update the parameters at the beginning of the trajectory
275  void FixTrajBegin(Trajectory& tj);
276  void FixTrajBegin(Trajectory& tj, unsigned short atPt);
277  void FixTrajEnd(Trajectory& tj, unsigned short atPt);
278  bool IsGhost(std::vector<unsigned int>& tHits, unsigned short& ofTraj);
279  bool IsGhost(Trajectory& tj);
280  void CheckTrajEnd();
281  void EndMerge(CTP_t inCTP, bool lastPass);
282  // Erases delHit and makes corrections to inTraj, allTraj and WireHitRange
283  bool EraseHit(const unsigned int& delHit);
284  // Creates a hit in tjs.fHits using the supplied information. Returns UINT_MAX if there is failure.
285  // Returns the index of the newly created hit
286  void DefineHit(TCHit& tcHit, CTP_t& hitCTP, unsigned int& hitWire);
287  unsigned int CreateHit(TCHit tcHit);
288  // Merges all of the hits used in each TP into one hit
289  void MergeTPHits();
290  void MaskTrajEndPoints(Trajectory& tj, unsigned short nPts);
291  // Sets the StopsAtEnd bits for the trajectory
292  void ChkStop(Trajectory& tj);
293  // Check the Michel electron topology, lastGoodPt is the last point of muon
294  bool ChkMichel(Trajectory& tj, unsigned short& lastGoodPt);
295  // TY: Split high charge hits near the trajectory end
296  void ChkHiChgHits(CTP_t inCTP);
297  void SplitHiChgHits(Trajectory& tj);
298 
299  void GetHitCollection(const art::Event& evt);
300 
301  }; // class TrajClusterAlg
302 
303 } // namespace cluster
304 
305 #endif // ifndef TRAJCLUSTERALG_H
TH1F * fNuVtx_dy
label of module producing input hits
bool fMakeNewHits
label of module producing input hits
void ClearResults()
Deletes all the results.
void UpdateDeltaRMS(Trajectory &tj)
label of module producing input hits
float fMaxChi
label of module producing input hits
TH1F * fVx3_Score
label of module producing input hits
float fHitErrFac
hit time error = fHitErrFac * hit RMS used for cluster fit
void ChkInTraj(std::string someText)
label of module producing input hits
void MergeTPHits()
label of module producing input hits
ShowerStruct3D const & GetShowerStruct(unsigned short ish)
label of module producing input hits
void CheckTrajEnd()
label of module producing input hits
void ChkStopEndPts(Trajectory &tj, bool prt)
label of module producing input hits
TH1F * fdWire[5]
label of module producing input hits
float fMaxWireSkipNoSignal
max number of wires to skip w/o a signal on them
struct of temporary 2D vertices (end points)
Definition: DataStructs.h:83
const std::vector< std::string > AlgBitNames
Definition: DataStructs.cxx:4
std::vector< unsigned short > fMinPtsFit
StepCrawl mode (0 = turn off)
void ChkStop(Trajectory &tj)
label of module producing input hits
bool ChkMichel(Trajectory &tj, unsigned short &lastGoodPt)
label of module producing input hits
void PrepareForNextPass(Trajectory &tj)
label of module producing input hits
void ChkHiChgHits(CTP_t inCTP)
label of module producing input hits
TjStuff tjs
label of module producing input hits
art::InputTag const & GetHitFinderModuleLabel()
label of module producing input hits
void MakeAllTrajClusters()
label of module producing input hits
void FindVtxTraj(VtxStore &theVtx)
label of module producing input hits
TruthMatcher tm
label of module producing input hits
void FindJunkTraj(CTP_t inCTP)
label of module producing input hits
void DefineHitPos(TrajPoint &tp)
label of module producing input hits
unsigned short fAllowNoHitWire
label of module producing input hits
bool mrgPrt
label of module producing input hits
art::InputTag fHitFinderModuleLabel
label of module producing input hits
std::vector< PFPStruct > pfps
Definition: DataStructs.h:505
float fProjectionErrFactor
label of module producing input hits
void UpdateTraj(Trajectory &tj)
label of module producing input hits
float HitsTimeErr2(const std::vector< unsigned int > &hitVec)
label of module producing input hits
bool fTagAllTraj
Max hit separation for making junk trajectories. < 0 to turn off.
calo::CalorimetryAlg fCaloAlg
label of module producing input hits
void FindHit(std::string someText, unsigned int iht)
label of module producing input hits
void CheckHiMultUnusedHits(Trajectory &tj)
label of module producing input hits
std::vector< float > fChkStopCuts
[Min Chg ratio, Chg slope pull cut, Chg fit chi cut]
float fMaxTrajSep
max trajectory point separation for making showers
std::vector< ShowerStruct3D > showers
Definition: DataStructs.h:508
void AddHits(Trajectory &tj, unsigned short ipt, bool &sigOK)
label of module producing input hits
std::vector< unsigned short > fMinPts
min number of Pts required to make a trajectory
TH2F * fMCSMom_TruMom_mu
label of module producing input hits
short fMode
label of module producing input hits
std::vector< std::string > const & GetAlgBitNames() const
label of module producing input hits
void GetHitMultiplet(unsigned int theHit, std::vector< unsigned int > &hitsInMultiplet)
label of module producing input hits
TH2F * fMCSMom_TruMom_p
label of module producing input hits
float fVLAStepSize
label of module producing input hits
void CheckTraj(Trajectory &tj)
label of module producing input hits
void FindSoftKink(Trajectory &tj)
label of module producing input hits
bool StartTraj(Trajectory &tj, const unsigned int &fromHit, const unsigned int &toHit, const unsigned short &pass)
label of module producing input hits
float fLAClusSlopeCut
label of module producing input hits
void FillGaps(Trajectory &tj)
label of module producing input hits
unsigned short nTruPrimaryOK
label of module producing input hits
bool fUseOldBackTracker
label of module producing input hits
void CheckNearLA()
label of module producing input hits
std::vector< unsigned int > fAlgModCount
label of module producing input hits
void DefineShTree(TTree *t)
label of module producing input hits
static bool SortByMultiplet(TCHit const &a, TCHit const &b)
label of module producing input hits
void HiEndDelta(Trajectory &tj)
label of module producing input hits
unsigned short GetShowerStructSize()
label of module producing input hits
bool StopIfBadFits(Trajectory &tj)
label of module producing input hits
void FindUseHits(Trajectory &tj, unsigned short ipt, float maxDelta, bool useChg)
label of module producing input hits
void GetHitCollection(const art::Event &evt)
label of module producing input hits
void RunTrajClusterAlg(const art::Event &evt)
label of module producing input hits
std::vector< VtxStore > vtx
2D vertices
Definition: DataStructs.h:502
bool MakeJunkTraj(std::vector< unsigned int > tHits, bool prt)
label of module producing input hits
unsigned int CreateHit(TCHit tcHit)
label of module producing input hits
std::vector< short > fMinMCSMom
Min MCSMom for each pass.
std::vector< unsigned short > fMaxAngleCode
max allowed angle code for each pass
float fSourceParticleEnergy
label of module producing input hits
TH2F * fMCSMomEP_TruMom_e
label of module producing input hits
std::vector< Trajectory > allTraj
vector of all trajectories in each plane
Definition: DataStructs.h:493
void StepCrawl(Trajectory &tj)
label of module producing input hits
void DefineCRTree(TTree *t)
label of module producing input hits
float HitTimeErr(const unsigned int iht)
label of module producing input hits
virtual void reconfigure(fhicl::ParameterSet const &pset)
label of module producing input hits
std::vector< recob::Hit > YieldHits()
Returns (and loses) the art::Ptr collection of previously reconstructed hits (e.g. gaushit)
trkf::LinFitAlg fLinFitAlg
label of module producing input hits
TjStuff const & GetTJS() const
label of module producing input hits
bool fStudyMode
study cuts
std::vector< float > fQualityCuts
Min points/wire, min consecutive pts after a gap.
void AddLAHits(Trajectory &tj, unsigned short ipt, bool &sigOK)
label of module producing input hits
void ReconstructAllTraj(CTP_t inCTP)
label of module producing input hits
TMVA::Reader fMVAReader
label of module producing input hits
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
std::string fhitsModuleLabel
label of module producing input hits
TProfile * fEP_T[5]
label of module producing input hits
bool fIsRealData
label of module producing input hits
std::vector< Vtx3Store > const & GetVertices() const
Returns a constant reference to the 3D vertices found.
TH1F * fNuVtx_dz
label of module producing input hits
bool fQuitAlg
label of module producing input hits
bool didPrt
label of module producing input hits
void MaskTrajEndPoints(Trajectory &tj, unsigned short nPts)
label of module producing input hits
std::vector< Vtx3Store > vtx3
3D vertices
Definition: DataStructs.h:503
void CheckHiMultEndHits(Trajectory &tj)
label of module producing input hits
void DefineHit(TCHit &tcHit, CTP_t &hitCTP, unsigned int &hitWire)
label of module producing input hits
void EndMerge(CTP_t inCTP, bool lastPass)
label of module producing input hits
float fMinAmp
min amplitude required for declaring a wire signal is present
TH2F * fMCSMom_TruMom_e
label of module producing input hits
void ReversePropagate(Trajectory &tj)
label of module producing input hits
void SplitHiChgHits(Trajectory &tj)
label of module producing input hits
TH1F * fVx2_Score
label of module producing input hits
void FixTrajBegin(Trajectory &tj)
label of module producing input hits
unsigned int GetTjClusterIndex(unsigned int TjID)
label of module producing input hits
unsigned int CTP_t
Definition: DataStructs.h:41
bool fMaskedLastTP
label of module producing input hits
bool fTryWithNextPass
label of module producing input hits
bool fGoodTraj
label of module producing input hits
unsigned short nTruPrimaryVtxReco
label of module producing input hits
TH2F * fMCSMom_TruMom_pi
label of module producing input hits
int TJPrt
label of module producing input hits
TTree * showertree
label of module producing input hits
std::vector< PFPStruct > const & GetPFParticles() const
label of module producing input hits
void FindMissedVxTjs(const geo::TPCID &tpcid)
label of module producing input hits
TrajClusterAlg(fhicl::ParameterSet const &pset)
label of module producing input hits
bool prt
label of module producing input hits
float fNeutrinoEnergy
label of module producing input hits
TH1F * fNuVtx_Score
label of module producing input hits
std::vector< ClusterStore > tcl
the clusters we are creating
Definition: DataStructs.h:501
HistStuff hist
label of module producing input hits
unsigned short nTruPrimary
label of module producing input hits
float fMultHitSep
preferentially "merge" hits with < this separation
bool EraseHit(const unsigned int &delHit)
label of module producing input hits
void MaskBadTPs(Trajectory &tj, float const &maxChi)
label of module producing input hits
void RunStepCrawl()
label of module producing input hits
void FixTrajEnd(Trajectory &tj, unsigned short atPt)
label of module producing input hits
std::vector< VtxStore > const & GetEndPoints() const
Returns a constant reference to the 2D end points found.
TProfile * fNuVtx_Enu_Score_p
label of module producing input hits
float fJTMaxHitSep2
label of module producing input hits
TH1F * fNuVtx_dx
label of module producing input hits
bool MaskedHitsOK(Trajectory &tj)
label of module producing input hits
void GottaKink(Trajectory &tj, unsigned short &killPts)
label of module producing input hits
void FindVtxTjs(CTP_t inCTP)
label of module producing input hits
float fMaxWireSkipWithSignal
max number of wires to skip with a signal on them
void UseUnusedHits()
label of module producing input hits
unsigned short nTruPrimaryVtxOK
label of module producing input hits
art::InputTag fHitTruthModuleLabel
label of module producing MCParticle -> hit associations
TTree * crtree
label of module producing input hits
bool IsGhost(std::vector< unsigned int > &tHits, unsigned short &ofTraj)
label of module producing input hits
std::vector< ClusterStore > const & GetClusters() const
Returns a constant reference to the clusters found.
std::vector< unsigned int > const & GetAlgModCount() const
label of module producing input hits
int fWorkID
label of module producing input hits