LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
TCCR.cxx
Go to the documentation of this file.
11 
13 
14 #include <algorithm>
15 #include <array>
16 #include <bitset>
17 #include <cfloat>
18 #include <cmath>
19 #include <map>
20 #include <utility>
21 #include <vector>
22 
23 namespace tca {
24 
26  void SaveCRInfo(detinfo::DetectorClocksData const& clockData,
27  TCSlice& slc,
28  PFPStruct& pfp,
29  bool fIsRealData)
30  {
31  //Check the origin of pfp
32  if (tcc.modes[kSaveCRTree]) {
33  if (fIsRealData) { slc.crt.cr_origin.push_back(-1); }
34  else {
35  slc.crt.cr_origin.push_back(GetOrigin(clockData, slc, pfp));
36  }
37  }
38 
39  // save the xmin and xmax of each pfp
40  auto& startPos = pfp.TP3Ds[0].Pos;
41  auto& endPos = pfp.TP3Ds[pfp.TP3Ds.size() - 1].Pos;
42  slc.crt.cr_pfpxmin.push_back(std::min(startPos[0], endPos[0]));
43  slc.crt.cr_pfpxmax.push_back(std::max(startPos[0], endPos[0]));
44 
45  //find max
46  const geo::TPCGeo& tpc = tcc.geom->TPC();
47  float mindis0 = FLT_MAX;
48  float mindis1 = FLT_MAX;
49  if (std::abs(startPos[1] - tpc.MinY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MinY());
50  if (std::abs(startPos[1] - tpc.MaxY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MaxY());
51  if (std::abs(startPos[2] - tpc.MinZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MinZ());
52  if (std::abs(startPos[2] - tpc.MaxZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MaxZ());
53  if (std::abs(endPos[1] - tpc.MinY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MinY());
54  if (std::abs(endPos[1] - tpc.MaxY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MaxY());
55  if (std::abs(endPos[2] - tpc.MinZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MinZ());
56  if (std::abs(endPos[2] - tpc.MaxZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MaxZ());
57  slc.crt.cr_pfpyzmindis.push_back(mindis0 + mindis1);
58 
59  if (slc.crt.cr_pfpxmin.back() < -2 || slc.crt.cr_pfpxmax.back() > 260 ||
60  slc.crt.cr_pfpyzmindis.back() < 30) {
61  pfp.CosmicScore = 1.;
62  }
63  else
64  pfp.CosmicScore = 0;
65  }
66 
68  int GetOrigin(detinfo::DetectorClocksData const& clockData, TCSlice& slc, PFPStruct& pfp)
69  {
72 
73  std::map<int, float> omap; //<origin, energy>
74 
75  for (auto& tjID : pfp.TjIDs) {
76  Trajectory& tj = slc.tjs[tjID - 1];
77  for (auto& tp : tj.Pts) {
78  for (unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
79  if (!tp.UseHit[ii]) continue;
80  unsigned int iht = tp.Hits[ii];
81  TCHit& slhit = slc.slHits[iht];
82  auto& hit = (*evt.allHits)[slhit.allHitsIndex];
84  double startTick = hit.PeakTime() - hit.RMS();
85  double endTick = hit.PeakTime() + hit.RMS();
86  // get a list of track IDEs that are close to this hit
87  std::vector<sim::TrackIDE> tides;
88  tides = bt_serv->ChannelToTrackIDEs(clockData, channel, startTick, endTick);
89  for (auto itide = tides.begin(); itide != tides.end(); ++itide) {
90  omap[pi_serv->TrackIdToMCTruth_P(itide->trackID)->Origin()] += itide->energy;
91  }
92  }
93  }
94  }
95 
96  float maxe = -1;
97  int origin = 0;
98  for (auto& i : omap) {
99  if (i.second > maxe) {
100  maxe = i.second;
101  origin = i.first;
102  }
103  }
104  return origin;
105  }
106 
108  void ClearCRInfo(TCSlice& slc)
109  {
110  slc.crt.cr_origin.clear();
111  slc.crt.cr_pfpxmin.clear();
112  slc.crt.cr_pfpxmax.clear();
113  slc.crt.cr_pfpyzmindis.clear();
114  }
115 }
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:662
std::vector< float > cr_pfpyzmindis
Definition: DataStructs.h:413
std::vector< float > cr_pfpxmax
Definition: DataStructs.h:412
const geo::WireReadoutGeom * wireReadoutGeom
Definition: DataStructs.h:568
TCConfig tcc
Definition: DataStructs.cxx:9
simb::Origin_t Origin() const
Definition: MCTruth.h:74
Geometry information for a single TPC.
Definition: TPCGeo.h:33
constexpr auto abs(T v)
Returns the absolute value of the argument.
int GetOrigin(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp)
Definition: TCCR.cxx:68
CRTreeVars crt
Definition: DataStructs.h:660
Access the description of the physical detector geometry.
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
void SaveCRInfo(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp, bool fIsRealData)
Definition: TCCR.cxx:26
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:186
double MinZ() const
Returns the world z coordinate of the start of the box.
std::vector< int > cr_origin
Definition: DataStructs.h:410
virtual raw::ChannelID_t PlaneWireToChannel(WireID const &wireID) const =0
Returns the channel ID a wire is connected to.
const geo::GeometryCore * geom
Definition: DataStructs.h:567
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
double MaxY() const
Returns the world y coordinate of the end of the box.
std::bitset< 16 > modes
number of points to find AveChg
Definition: DataStructs.h:599
std::vector< TCHit > slHits
Definition: DataStructs.h:661
Contains all timing reference information for the detector.
save cosmic ray tree
Definition: DataStructs.h:529
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< int > TjIDs
Definition: DataStructs.h:278
std::vector< recob::Hit > const * allHits
Definition: DataStructs.h:614
std::vector< TP3D > TP3Ds
Definition: DataStructs.h:280
std::vector< float > cr_pfpxmin
Definition: DataStructs.h:411
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
unsigned int allHitsIndex
Definition: DataStructs.h:605
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:448
double MinY() const
Returns the world y coordinate of the start of the box.
void ClearCRInfo(TCSlice &slc)
Definition: TCCR.cxx:108
Interface to geometry for wire readouts .
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:229
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
Encapsulate the construction of a single detector plane .