LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TCCR.cxx
Go to the documentation of this file.
10 
12 
13 #include <algorithm>
14 #include <array>
15 #include <bitset>
16 #include <cfloat>
17 #include <cmath>
18 #include <map>
19 #include <utility>
20 #include <vector>
21 
22 namespace tca {
23 
25  void SaveCRInfo(detinfo::DetectorClocksData const& clockData,
26  TCSlice& slc,
27  PFPStruct& pfp,
28  bool fIsRealData)
29  {
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  //std::cout<<startPos[1]<<" "<<startPos[2]<<" "<<endPos[1]<<" "<<endPos[2]<<" "<<tpc.MinY()<<" "<<tpc.MaxY()<<" "<<tpc.MinZ()<<" "<<tpc.MaxZ()<<" "<<mindis0<<" "<<mindis1<<" "<<mindis0+mindis1<<std::endl;
58  slc.crt.cr_pfpyzmindis.push_back(mindis0 + mindis1);
59 
60  if (slc.crt.cr_pfpxmin.back() < -2 || slc.crt.cr_pfpxmax.back() > 260 ||
61  slc.crt.cr_pfpyzmindis.back() < 30) {
62  pfp.CosmicScore = 1.;
63  }
64  else
65  pfp.CosmicScore = 0;
66  }
67 
69  int GetOrigin(detinfo::DetectorClocksData const& clockData, TCSlice& slc, PFPStruct& pfp)
70  {
71 
74 
75  std::map<int, float> omap; //<origin, energy>
76 
77  for (auto& tjID : pfp.TjIDs) {
78 
79  Trajectory& tj = slc.tjs[tjID - 1];
80  for (auto& tp : tj.Pts) {
81  for (unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
82  if (!tp.UseHit[ii]) continue;
83  unsigned int iht = tp.Hits[ii];
84  TCHit& slhit = slc.slHits[iht];
85  auto& hit = (*evt.allHits)[slhit.allHitsIndex];
86  raw::ChannelID_t channel = tcc.geom->PlaneWireToChannel(hit.WireID());
87  double startTick = hit.PeakTime() - hit.RMS();
88  double endTick = hit.PeakTime() + hit.RMS();
89  // get a list of track IDEs that are close to this hit
90  std::vector<sim::TrackIDE> tides;
91  tides = bt_serv->ChannelToTrackIDEs(clockData, channel, startTick, endTick);
92  for (auto itide = tides.begin(); itide != tides.end(); ++itide) {
93  omap[pi_serv->TrackIdToMCTruth_P(itide->trackID)->Origin()] += itide->energy;
94  }
95  }
96  }
97  }
98 
99  float maxe = -1;
100  int origin = 0;
101  for (auto& i : omap) {
102  if (i.second > maxe) {
103  maxe = i.second;
104  origin = i.first;
105  }
106  }
107  return origin;
108  }
109 
111  void ClearCRInfo(TCSlice& slc)
112  {
113  slc.crt.cr_origin.clear();
114  slc.crt.cr_pfpxmin.clear();
115  slc.crt.cr_pfpxmax.clear();
116  slc.crt.cr_pfpyzmindis.clear();
117  }
118 }
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:663
std::vector< float > cr_pfpyzmindis
Definition: DataStructs.h:415
std::vector< float > cr_pfpxmax
Definition: DataStructs.h:414
TCConfig tcc
Definition: DataStructs.cxx:9
simb::Origin_t Origin() const
Definition: MCTruth.h:74
Geometry information for a single TPC.
Definition: TPCGeo.h:36
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:69
CRTreeVars crt
Definition: DataStructs.h:661
TPCGeo const & TPC(TPCID const &tpcid=tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:722
Access the description of 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:25
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:188
double MinZ() const
Returns the world z coordinate of the start of the box.
std::vector< int > cr_origin
Definition: DataStructs.h:412
const geo::GeometryCore * geom
Definition: DataStructs.h:569
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:600
std::vector< TCHit > slHits
Definition: DataStructs.h:662
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
Contains all timing reference information for the detector.
save cosmic ray tree
Definition: DataStructs.h:531
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< int > TjIDs
Definition: DataStructs.h:280
std::vector< recob::Hit > const * allHits
Definition: DataStructs.h:615
std::vector< TP3D > TP3Ds
Definition: DataStructs.h:282
std::vector< float > cr_pfpxmin
Definition: DataStructs.h:413
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:606
double MinY() const
Returns the world y coordinate of the start of the box.
void ClearCRInfo(TCSlice &slc)
Definition: TCCR.cxx:111
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.