All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TCCR.cxx
Go to the documentation of this file.
9 #include "nusimdata/SimulationBase/MCTruth.h"
10 
11 #include "art/Framework/Services/Registry/ServiceHandle.h"
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 
24  ////////////////////////////////////////////////
25  void
27  TCSlice& slc,
28  PFPStruct& pfp,
29  bool prt,
30  bool fIsRealData)
31  {
32 
33  //Check the origin of pfp
34  if (tcc.modes[kSaveCRTree]) {
35  if (fIsRealData) { slc.crt.cr_origin.push_back(-1); }
36  else {
37  slc.crt.cr_origin.push_back(GetOrigin(clockData, slc, pfp));
38  }
39  }
40 
41  // save the xmin and xmax of each pfp
42  auto& startPos = pfp.TP3Ds[0].Pos;
43  auto& endPos = pfp.TP3Ds[pfp.TP3Ds.size() - 1].Pos;
44  slc.crt.cr_pfpxmin.push_back(std::min(startPos[0], endPos[0]));
45  slc.crt.cr_pfpxmax.push_back(std::max(startPos[0], endPos[0]));
46 
47  //find max
48  const geo::TPCGeo& tpc = tcc.geom->TPC(0);
49  float mindis0 = FLT_MAX;
50  float mindis1 = FLT_MAX;
51  if (std::abs(startPos[1] - tpc.MinY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MinY());
52  if (std::abs(startPos[1] - tpc.MaxY()) < mindis0) mindis0 = std::abs(startPos[1] - tpc.MaxY());
53  if (std::abs(startPos[2] - tpc.MinZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MinZ());
54  if (std::abs(startPos[2] - tpc.MaxZ()) < mindis0) mindis0 = std::abs(startPos[2] - tpc.MaxZ());
55  if (std::abs(endPos[1] - tpc.MinY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MinY());
56  if (std::abs(endPos[1] - tpc.MaxY()) < mindis1) mindis1 = std::abs(endPos[1] - tpc.MaxY());
57  if (std::abs(endPos[2] - tpc.MinZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MinZ());
58  if (std::abs(endPos[2] - tpc.MaxZ()) < mindis1) mindis1 = std::abs(endPos[2] - tpc.MaxZ());
59  //std::cout<<startPos[1]<<" "<<startPos[2]<<" "<<endPos[1]<<" "<<endPos[2]<<" "<<tpc.MinY()<<" "<<tpc.MaxY()<<" "<<tpc.MinZ()<<" "<<tpc.MaxZ()<<" "<<mindis0<<" "<<mindis1<<" "<<mindis0+mindis1<<std::endl;
60  slc.crt.cr_pfpyzmindis.push_back(mindis0 + mindis1);
61 
62  if (slc.crt.cr_pfpxmin.back() < -2 || slc.crt.cr_pfpxmax.back() > 260 ||
63  slc.crt.cr_pfpyzmindis.back() < 30) {
64  pfp.CosmicScore = 1.;
65  }
66  else
67  pfp.CosmicScore = 0;
68  }
69 
70  ////////////////////////////////////////////////
71  int
73  {
74 
75  art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
76  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
77 
78  std::map<int, float> omap; //<origin, energy>
79 
80  for (auto& tjID : pfp.TjIDs) {
81 
82  Trajectory& tj = slc.tjs[tjID - 1];
83  for (auto& tp : tj.Pts) {
84  for (unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
85  if (!tp.UseHit[ii]) continue;
86  unsigned int iht = tp.Hits[ii];
87  TCHit& slhit = slc.slHits[iht];
88  auto& hit = (*evt.allHits)[slhit.allHitsIndex];
89  raw::ChannelID_t channel = tcc.geom->PlaneWireToChannel((int)hit.WireID().Plane,
90  (int)hit.WireID().Wire,
91  (int)hit.WireID().TPC,
92  (int)hit.WireID().Cryostat);
93  double startTick = hit.PeakTime() - hit.RMS();
94  double endTick = hit.PeakTime() + hit.RMS();
95  // get a list of track IDEs that are close to this hit
96  std::vector<sim::TrackIDE> tides;
97  tides = bt_serv->ChannelToTrackIDEs(clockData, channel, startTick, endTick);
98  for (auto itide = tides.begin(); itide != tides.end(); ++itide) {
99  omap[pi_serv->TrackIdToMCTruth_P(itide->trackID)->Origin()] += itide->energy;
100  }
101  }
102  }
103  }
104 
105  float maxe = -1;
106  int origin = 0;
107  for (auto& i : omap) {
108  if (i.second > maxe) {
109  maxe = i.second;
110  origin = i.first;
111  }
112  }
113  return origin;
114  }
115 
116  ////////////////////////////////////////////////
117  void
119  {
120  slc.crt.cr_origin.clear();
121  slc.crt.cr_pfpxmin.clear();
122  slc.crt.cr_pfpxmax.clear();
123  slc.crt.cr_pfpyzmindis.clear();
124  }
125 }
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:670
std::vector< float > cr_pfpyzmindis
Definition: DataStructs.h:422
std::vector< float > cr_pfpxmax
Definition: DataStructs.h:421
TCConfig tcc
Definition: DataStructs.cxx:9
Geometry information for a single TPC.
Definition: TPCGeo.h:38
process_name hit
Definition: cheaterreco.fcl:51
int GetOrigin(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp)
Definition: TCCR.cxx:72
CRTreeVars crt
Definition: DataStructs.h:668
Access the description of detector geometry.
T abs(T value)
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:191
double MinZ() const
Returns the world z coordinate of the start of the box.
std::vector< int > cr_origin
Definition: DataStructs.h:419
const geo::GeometryCore * geom
Definition: DataStructs.h:576
Definition of data types for geometry description.
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:607
std::vector< TCHit > slHits
Definition: DataStructs.h:669
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:538
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< int > TjIDs
Definition: DataStructs.h:283
void SaveCRInfo(detinfo::DetectorClocksData const &clockData, TCSlice &slc, PFPStruct &pfp, bool prt, bool fIsRealData)
Definition: TCCR.cxx:26
std::vector< recob::Hit > const * allHits
Definition: DataStructs.h:622
std::vector< TP3D > TP3Ds
Definition: DataStructs.h:285
std::vector< float > cr_pfpxmin
Definition: DataStructs.h:420
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
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:613
double MinY() const
Returns the world y coordinate of the start of the box.
void ClearCRInfo(TCSlice &slc)
Definition: TCCR.cxx:118
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
Encapsulate the construction of a single detector plane.