TCCR.cxx
Go to the documentation of this file.
12 
15 
16 #include <algorithm>
17 #include <array>
18 #include <bitset>
19 #include <float.h>
20 #include <map>
21 #include <math.h>
22 #include <utility>
23 #include <vector>
24 
25 namespace tca {
26 
27  ////////////////////////////////////////////////
28  void
30  TCSlice& slc,
31  PFPStruct& pfp,
32  bool prt,
33  bool fIsRealData)
34  {
35 
36  //Check the origin of pfp
37  if (tcc.modes[kSaveCRTree]) {
38  if (fIsRealData) { slc.crt.cr_origin.push_back(-1); }
39  else {
40  slc.crt.cr_origin.push_back(GetOrigin(clockData, slc, pfp));
41  }
42  }
43 
44  // save the xmin and xmax of each pfp
45  auto& startPos = pfp.TP3Ds[0].Pos;
46  auto& endPos = pfp.TP3Ds[pfp.TP3Ds.size() - 1].Pos;
47  slc.crt.cr_pfpxmin.push_back(std::min(startPos[0], endPos[0]));
48  slc.crt.cr_pfpxmax.push_back(std::max(startPos[0], endPos[0]));
49 
50  //find max
51  const geo::TPCGeo& tpc = tcc.geom->TPC(0);
52  float mindis0 = FLT_MAX;
53  float mindis1 = FLT_MAX;
54  if (std::abs(startPos[1] - tpc.MinY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MinY());
55  if (std::abs(startPos[1] - tpc.MaxY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MaxY());
56  if (std::abs(startPos[2] - tpc.MinZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MinZ());
57  if (std::abs(startPos[2] - tpc.MaxZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MaxZ());
58  if (std::abs(endPos[1] - tpc.MinY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MinY());
59  if (std::abs(endPos[1] - tpc.MaxY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MaxY());
60  if (std::abs(endPos[2] - tpc.MinZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MinZ());
61  if (std::abs(endPos[2] - tpc.MaxZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MaxZ());
62  //std::cout<<startPos[1]<<" "<<startPos[2]<<" "<<endPos[1]<<" "<<endPos[2]<<" "<<tpc.MinY()<<" "<<tpc.MaxY()<<" "<<tpc.MinZ()<<" "<<tpc.MaxZ()<<" "<<mindis0<<" "<<mindis1<<" "<<mindis0+mindis1<<std::endl;
63  slc.crt.cr_pfpyzmindis.push_back(mindis0 + mindis1);
64 
65  if (slc.crt.cr_pfpxmin.back() < -2 || slc.crt.cr_pfpxmax.back() > 260 ||
66  slc.crt.cr_pfpyzmindis.back() < 30) {
67  pfp.CosmicScore = 1.;
68  }
69  else
70  pfp.CosmicScore = 0;
71  }
72 
73  ////////////////////////////////////////////////
74  int
76  {
77 
80 
81  std::map<int, float> omap; //<origin, energy>
82 
83  for (auto& tjID : pfp.TjIDs) {
84 
85  Trajectory& tj = slc.tjs[tjID - 1];
86  for (auto& tp : tj.Pts) {
87  for (unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
88  if (!tp.UseHit[ii]) continue;
89  unsigned int iht = tp.Hits[ii];
90  TCHit& slhit = slc.slHits[iht];
91  auto& hit = (*evt.allHits)[slhit.allHitsIndex];
92  raw::ChannelID_t channel = tcc.geom->PlaneWireToChannel((int)hit.WireID().Plane,
93  (int)hit.WireID().Wire,
94  (int)hit.WireID().TPC,
95  (int)hit.WireID().Cryostat);
96  double startTick = hit.PeakTime() - hit.RMS();
97  double endTick = hit.PeakTime() + hit.RMS();
98  // get a list of track IDEs that are close to this hit
99  std::vector<sim::TrackIDE> tides;
100  tides = bt_serv->ChannelToTrackIDEs(clockData, channel, startTick, endTick);
101  for (auto itide = tides.begin(); itide != tides.end(); ++itide) {
102  omap[pi_serv->TrackIdToMCTruth_P(itide->trackID)->Origin()] += itide->energy;
103  }
104  }
105  }
106  }
107 
108  float maxe = -1;
109  int origin = 0;
110  for (auto& i : omap) {
111  if (i.second > maxe) {
112  maxe = i.second;
113  origin = i.first;
114  }
115  }
116  return origin;
117  }
118 
119  ////////////////////////////////////////////////
120  void
122  {
123  slc.crt.cr_origin.clear();
124  slc.crt.cr_pfpxmin.clear();
125  slc.crt.cr_pfpxmax.clear();
126  slc.crt.cr_pfpyzmindis.clear();
127  }
128 }
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:672
std::vector< float > cr_pfpyzmindis
Definition: DataStructs.h:424
std::vector< float > cr_pfpxmax
Definition: DataStructs.h:423
TCConfig tcc
Definition: DataStructs.cxx:8
simb::Origin_t Origin() const
Definition: MCTruth.h:74
Geometry information for a single TPC.
Definition: TPCGeo.h:38
uint8_t channel
Definition: CRTFragment.hh:201
int GetOrigin(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp)
Definition: TCCR.cxx:75
CRTreeVars crt
Definition: DataStructs.h:670
T abs(T value)
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:193
double MinZ() const
Returns the world z coordinate of the start of the box.
std::vector< int > cr_origin
Definition: DataStructs.h:421
const geo::GeometryCore * geom
Definition: DataStructs.h:578
static int max(int a, int b)
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:609
std::vector< TCHit > slHits
Definition: DataStructs.h:671
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
Declaration of signal hit object.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
Contains all timing reference information for the detector.
save cosmic ray tree
Definition: DataStructs.h:540
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< int > TjIDs
Definition: DataStructs.h:285
void SaveCRInfo(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp, bool prt, bool fIsRealData)
Definition: TCCR.cxx:29
std::vector< recob::Hit > const * allHits
Definition: DataStructs.h:624
std::vector< TP3D > TP3Ds
Definition: DataStructs.h:287
std::vector< float > cr_pfpxmin
Definition: DataStructs.h:422
Access the description of detector geometry.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
unsigned int allHitsIndex
Definition: DataStructs.h:615
double MinY() const
Returns the world y coordinate of the start of the box.
void ClearCRInfo(TCSlice &slc)
Definition: TCCR.cxx:121
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
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.