CalibUtil.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CalibUtil.h
3 // \brief Functions of general use in calibration
4 // \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 #ifndef CALIB_CALIBUTIL_H
8 #define CALIB_CALIBUTIL_H
9 
10 #include <vector>
11 #include <map>
12 #include <set>
13 
14 #include "NovaDAQConventions/DAQConventions.h"
16 #include "TVector3.h"
17 
18 namespace calib
19 {
20  /// \brief Utility function to get detector name as a string for file
21  /// manipulations.
23 
24  /// \brief Enumeration for the FEB 4.2 and 5.1 which have different clocks
25  enum EFEBType {
28  };
29 
30 
31 
32  /// \brief Methods used to estimate path length of a track through a cell
33  ///
34  /// The recommended method to perform a calibration is to accumulate separate
35  /// histograms or averages for each cell in each quality level. If there is
36  /// insufficient statistics in "xy" mode (there will be zero for cells along
37  /// the sides of the detector), fall back to the "z" mode calculations. If
38  /// there is insufficient stats here too (should only happen in the detector
39  /// corners) fall back (reluctantly) to the kAverage calculations.
41  /// There are adjacent hits on the same plane. This means the track must
42  /// have entered in one side wall of the cell and gone out the other. The
43  /// path length estimate is likely very precise.
45  /// There are no adjacent cells in the same plane, but the cells of the
46  /// same index in the upstream and downstream planes are hit. There is high
47  /// confidence that the track went in the front wall of the cell and out
48  /// the back. The path length estimate should be good. The kXYAdjacents
49  /// case is preferred only because it is more common.
51  /// The cell has no special properties, and the path length has been
52  /// estimated using the \ref geo::AverageCellPathLength method. The result
53  /// is likely pretty poor. Only use cells with this estimate if you have no
54  /// choice.
56  /// Something was wrong with the track object, the pathlength will be
57  /// zero. Do not use this cell.
59  };
60 
61  /// \brief Calculate the best path length estimate for each hit in a track,
62  /// and indicate how they were obtained.
63  ///
64  /// \param trk The track whose cells should be used
65  /// \param[out] quals How the path length of each hit was determined. Please
66  /// read the documentation for \ref EPathQuality
67  /// \param extra Other cells that should be considered to be on the track
68  /// (optional). Results for these will be at the end of returned
69  /// vectors.
70  /// \return Path lengths (in cm). Indices correspond to those passed to
71  /// \ref rb::Track::Cell
72  std::vector<double> BestPathEstimates(const std::vector<geo::OfflineChan>& chans,
73  const std::map<unsigned int, TVector3>& directions,
74  std::vector<EPathQuality>& quals,
75  const std::vector<geo::OfflineChan>& extras = {});
76 
77  /// \brief Find empty cells that would have contributed to the calibration if
78  /// they'd been hit. We assume they fell below threshold.
79  ///
80  /// TODO: Can only currently find "xy" quality candidates
81  ///
82  /// \param[out] quals How the path length of each cell was determined. Please
83  /// read the documentation for \ref EPathQuality
84  /// \param[out] paths Estimated path length for each selected cell
85  /// \param[out] chans Which cells were selected
86  void FindBelowThresholdCalibCandidates(const std::vector<geo::OfflineChan>& trkchans,
87  const std::map<unsigned int, TVector3>& directions,
88  std::vector<EPathQuality>& quals,
89  std::vector<double>& paths,
90  std::vector<geo::OfflineChan>& chans);
91 
92  /// \brief Return the direction at a plane using the map provided by rb::Track
93  TVector3 const DirectionAtPlane(const std::map<unsigned int, TVector3>& directions,
94  unsigned int plane);
95 
96  /// \brief Return position in world coordninates and distance to the readout
97  ///
98  /// \param cellhit A hit on a track
99  /// \param w The unknown coordinate from the opposite view
100  /// \param xyzd[4] Returns x,y,z,d where d is the distance to readout
102  double w,
103  double *xyzd);
104 
105  // convenient type defs
106  typedef std::pair<TVector3, TVector3> zBounds;
107  typedef std::map<double, zBounds> zBoundMap;
108 
109  /// \brief Find the boundaries in the z direction of planes in the detector
110  /// \param[out] planeZBounds is a set of those values that is filled by the function
111  void FindZBoundaries(std::set<double> & planeZBounds);
112 
113  /// \brief Return a map of the z position of each trajectory point on a track
114  /// to the bounding positions of where the track passes through that plane.
115  /// In the case that a track stops in the plane, then the end of the track is
116  /// the second bounding point
117  /// \param planeZBounds A set of the z positions bounding each plane in the detector
118  /// \param trajectory The trajectory points of the track
119  zBoundMap MakeZBoundaryMap(std::set<double> const& planeZBounds,
120  std::vector<TVector3> const& trajectory);
121 
122  /// \brief Return the bounding points for a given z position along a track
123  /// \param bounds The z position boundaries for each trajectory point on the track
124  /// \param hitZ The z position of the trajectory point in question
125  zBounds ZBounds(zBoundMap const& bounds,
126  double const& hitZ);
127 
128  /// \brief Return the path length of a track in the cell in question
129  /// \param zBounds The z poisition boundaries for each trajectory point on the track
130  /// \param recoHitLoc The 3D position of the rb::RecoHit to ensure the trajectory passes through it
131  /// \param pc A std::pair corresponding to the plane (p) and cell (c) of the hit
132  float PathLengthInCell(zBoundMap const& zBounds,
133  TVector3 const& recoHitLoc,
134  std::pair<uint32_t, uint32_t> const& pc);
135 
136 
137  std::vector<std::string> globWrapper(const std::string& pattern);
138  std::string getCSVFilenameByParsingDirectory(int fCurrentRun, std::string prePattern, std::string postPattern);
139 
140  /// \brief Return true if the path in dirString points to a directory
141  /// \param dirString path to the directory to check
142  bool doesDirectoryExist(std::string dirSting);
143 }
144 
145 
146 #endif // CALIB_CALIBUTIL_H
147 ////////////////////////////////////////////////////////////////////////
148 
zBounds ZBounds(zBoundMap const &bounds, double const &hitZ)
Return the bounding points for a given z position along a track.
Definition: CalibUtil.cxx:462
::xsd::cxx::tree::bounds< char > bounds
Definition: Database.h:226
bool doesDirectoryExist(std::string dirSting)
Return true if the path in dirString points to a directory.
Definition: CalibUtil.cxx:759
zBoundMap MakeZBoundaryMap(std::set< double > const &planeZBounds, std::vector< TVector3 > const &trajectory)
Return a map of the z position of each trajectory point on a track to the bounding positions of where...
Definition: CalibUtil.cxx:354
std::vector< double > BestPathEstimates(std::vector< geo::OfflineChan > const &chans, std::map< unsigned int, TVector3 > const &directions, std::vector< EPathQuality > &quals, std::vector< geo::OfflineChan > const &extras)
Definition: CalibUtil.cxx:98
std::pair< TVector3, TVector3 > zBounds
Definition: CalibUtil.h:106
CDPStorage service.
std::string getCSVFilenameByParsingDirectory(int fCurrentRun, std::string prePattern, std::string postPattern)
Definition: CalibUtil.cxx:706
EFEBType
Enumeration for the FEB 4.2 and 5.1 which have different clocks.
Definition: CalibUtil.h:25
void GetXYZD(geo::OfflineChan chan, double w, double *xyzd)
Return position in world coordninates and distance to the readout.
Definition: CalibUtil.cxx:294
EPathQuality
Methods used to estimate path length of a track through a cell.
Definition: CalibUtil.h:40
std::vector< std::string > globWrapper(const std::string &pattern)
Definition: CalibUtil.cxx:676
void FindBelowThresholdCalibCandidates(const std::vector< geo::OfflineChan > &trkchans, const std::map< unsigned int, TVector3 > &directions, std::vector< EPathQuality > &quals, std::vector< double > &paths, std::vector< geo::OfflineChan > &chans)
Find empty cells that would have contributed to the calibration if they&#39;d been hit. We assume they fell below threshold.
Definition: CalibUtil.cxx:232
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TVector3 const DirectionAtPlane(const std::map< unsigned int, TVector3 > &directions, unsigned int plane)
Return the direction at a plane using the map provided by rb::Track.
Definition: CalibUtil.cxx:188
const char * getDetString(novadaq::cnv::DetId det)
Utility function to get detector name as a string for file manipulations.
Definition: CalibUtil.cxx:29
A (plane, cell) pair.
Definition: OfflineChan.h:17
std::map< double, zBounds > zBoundMap
Definition: CalibUtil.h:107
void FindZBoundaries(std::set< double > &planeZBounds)
Find the boundaries in the z direction of planes in the detector.
Definition: CalibUtil.cxx:332
Float_t w
Definition: plot.C:20
Simple object representing a (plane, cell) pair.
float PathLengthInCell(zBoundMap const &zBounds, TVector3 const &recoHitLoc, std::pair< uint32_t, uint32_t > const &pc)
Return the path length of a track in the cell in question.
Definition: CalibUtil.cxx:498