LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TCShTree.cxx
Go to the documentation of this file.
4 
5 #include <array>
6 #include <bitset>
7 #include <cmath>
8 #include <stddef.h>
9 #include <string>
10 #include <vector>
11 
12 namespace tca {
13 
14  void SaveTjInfo(TCSlice& slc, std::vector<std::vector<int>>& tjList, std::string stageName)
15  {
16  if (!tcc.modes[kSaveShowerTree]) return;
17  if (tjList.empty()) return;
18  int stageNum = GetStageNum(stv, stageName);
19 
20  // get the CTP from the first tj
21  CTP_t inCTP = slc.tjs[tjList[0][0] - 1].CTP;
22  for (unsigned short it1 = 0; it1 < slc.tjs.size(); ++it1) {
23  Trajectory& tj1 = slc.tjs[it1];
24  if (tj1.CTP != inCTP) continue;
25  if (tj1.AlgMod[kKilled]) continue;
26 
27  SaveTjInfoStuff(slc, tj1, stageNum);
28 
29  int trajID = tj1.ID;
30  bool inShower = false;
31 
32  for (size_t l1 = 0; l1 < tjList.size(); ++l1) {
33  if (inShower) break;
34  for (size_t l2 = 0; l2 < tjList[l1].size(); ++l2) {
35 
36  if (trajID == tjList[l1][l2]) {
37  stv.ShowerID.back() = l1;
38  inShower = true;
39  break;
40  }
41  } // end list loop 2
42  } // end list loop 1
43  } // end tjs loop
44  // add meaningless envelope to list for counting purposes
45  // envelopes are defined once DefineShower is called
46  // fill four times, one for each side of polygon
47  for (int i = 0; i < 8; i++) {
48  stv.Envelope.push_back(-999);
49  stv.EnvStage.push_back(stageNum);
50  stv.EnvPlane.push_back(-1);
51  stv.EnvShowerID.push_back(-1);
52  }
53 
54  } // SaveTjInfo (tjlist)
55 
56  void SaveTjInfo(TCSlice& slc, const ShowerStruct& ss, std::string stageName)
57  {
58  if (!tcc.modes[kSaveShowerTree]) return;
59  int stageNum = GetStageNum(stv, stageName);
60 
61  // killed shower?
62  if (ss.ID == 0) return;
63 
64  bool noMatch = true;
65 
66  for (unsigned short it1 = 0; it1 < slc.tjs.size(); ++it1) {
67 
68  Trajectory& tj1 = slc.tjs[it1];
69 
70  if (tj1.AlgMod[kKilled]) continue;
71 
72  int trajID = tj1.ID;
73 
74  // check if this tj has already been added to the list
75  // for this particular stage and plane
76  int tjIndex = -1;
77  bool isShowerTj = false;
78  for (size_t i = 0; i < stv.TjID.size(); ++i) {
79  if (stv.StageNum.at(i) != (int)stageNum) continue;
80  if (stv.PlaneNum.at(i) != (short)DecodeCTP(ss.CTP).Plane) continue;
81 
82  if (stv.TjID.at(i) == trajID) {
83  tjIndex = i;
84  if (stv.IsShowerTj.at(tjIndex) == 1) isShowerTj = true;
85  //beenDoneBefore = true;
86  break;
87  }
88  }
89 
90  if (isShowerTj) continue;
91  if (tjIndex == -1) SaveTjInfoStuff(slc, tj1, stageNum);
92 
93  for (size_t i = 0; i < ss.TjIDs.size(); ++i) {
94  if (trajID == ss.TjIDs[i]) {
95  noMatch = false;
96  if (tjIndex == -1)
97  stv.ShowerID.back() = ss.ID;
98  else
99  stv.ShowerID.at(tjIndex) = ss.ID;
100  }
101 
102  if (it1 == (ss.ShowerTjID - 1))
103  stv.IsShowerTj.back() = 1;
104  else if (tj1.AlgMod[kShowerTj])
105  stv.IsShowerTj.back() = 1; // this is a better check
106  // check if tj is shower parent. if so, add to ttree
107  // and mark parent flag
108  if (trajID == ss.ParentID) {
109  if (tjIndex == -1) {
110  stv.ShowerID.back() = ss.ID;
111  stv.IsShowerParent.back() = 1;
112  }
113  else {
114  stv.ShowerID.at(tjIndex) = ss.ID;
115  stv.IsShowerParent.at(tjIndex) = 1;
116  }
117  break;
118  }
119  } // ss TjID loop
120  } // end tjs loop
121 
122  if (noMatch) return;
123 
124  // add envelope information to showertreevars
125  geo::PlaneID iPlnID = DecodeCTP(ss.CTP);
126 
127  for (int i = 0; i < 8; i++) {
128  stv.EnvStage.push_back(stageNum);
129  stv.EnvPlane.push_back(iPlnID.Plane);
130  stv.EnvShowerID.push_back(ss.ID);
131  }
132 
133  stv.Envelope.push_back(ss.Envelope[0][0]);
134  stv.Envelope.push_back(ss.Envelope[0][1] / tcc.unitsPerTick);
135  stv.Envelope.push_back(ss.Envelope[1][0]);
136  stv.Envelope.push_back(ss.Envelope[1][1] / tcc.unitsPerTick);
137  stv.Envelope.push_back(ss.Envelope[2][0]);
138  stv.Envelope.push_back(ss.Envelope[2][1] / tcc.unitsPerTick);
139  stv.Envelope.push_back(ss.Envelope[3][0]);
140  stv.Envelope.push_back(ss.Envelope[3][1] / tcc.unitsPerTick);
141 
142  } // SaveTjInfo (cots)
143 
144  void SaveTjInfoStuff(TCSlice& slc, Trajectory& tj, int stageNum)
145  {
146  if (!tcc.modes[kSaveShowerTree]) return;
147 
148  TrajPoint& beginPoint = tj.Pts[tj.EndPt[0]];
149  TrajPoint& endPoint = tj.Pts[tj.EndPt[1]];
150 
151  stv.BeginWir.push_back(std::nearbyint(beginPoint.Pos[0]));
152  stv.BeginTim.push_back(std::nearbyint(beginPoint.Pos[1] / tcc.unitsPerTick));
153  stv.BeginAng.push_back(beginPoint.Ang);
154  stv.BeginChg.push_back(beginPoint.Chg);
155  stv.BeginVtx.push_back(tj.VtxID[0]);
156 
157  stv.EndWir.push_back(std::nearbyint(endPoint.Pos[0]));
158  stv.EndTim.push_back(std::nearbyint(endPoint.Pos[1] / tcc.unitsPerTick));
159  stv.EndAng.push_back(endPoint.Ang);
160  stv.EndChg.push_back(endPoint.Chg);
161  stv.EndVtx.push_back(tj.VtxID[1]);
162 
163  stv.MCSMom.push_back(tj.MCSMom);
164  stv.TjID.push_back(tj.ID);
165  stv.IsShowerTj.push_back(-1);
166 
167  stv.ShowerID.push_back(-1);
168  stv.IsShowerParent.push_back(-1);
169  stv.StageNum.push_back(stageNum);
170  stv.nStages = stageNum;
171  geo::PlaneID iPlnID = DecodeCTP(tj.CTP);
172  stv.PlaneNum.push_back(iPlnID.Plane);
173 
174  stv.nPlanes = slc.nPlanes;
175 
176  } // SaveTjInfoStuff
177 
179  void SaveAllCots(TCSlice& slc, const CTP_t& inCTP, std::string someText)
180  {
181  if (!tcc.modes[kSaveShowerTree]) return;
182  for (unsigned short cotIndex = 0; cotIndex < slc.cots.size(); ++cotIndex) {
183  auto& ss = slc.cots[cotIndex];
184  if (ss.CTP != inCTP) continue;
185  if (ss.ID == 0) continue;
186  SaveTjInfo(slc, ss, someText);
187  } // cotIndex
188  } // SaveAllCots
189 
190  void SaveAllCots(TCSlice& slc, std::string someText)
191  {
192  if (!tcc.modes[kSaveShowerTree]) return;
193  for (unsigned short cotIndex = 0; cotIndex < slc.cots.size(); ++cotIndex) {
194  auto& ss = slc.cots[cotIndex];
195  if (ss.ID == 0) continue;
196  SaveTjInfo(slc, ss, someText);
197  } // cotIndex
198  }
199 
200  int GetStageNum(ShowerTreeVars& stv, std::string stageName)
201  {
202  int stageNum;
203  bool existingStage = false;
204  for (unsigned short i = 0; i < stv.StageName.size(); ++i) {
205  if (stv.StageName.at(i) == stageName) {
206  existingStage = true;
207  stageNum = i + 1;
208  }
209  }
210 
211  if (!existingStage) {
212  stv.StageName.push_back(stageName);
213  stageNum = stv.StageName.size();
214  }
215 
216  return stageNum;
217  }
218 
220  {
221  stv.BeginWir.clear();
222  stv.BeginTim.clear();
223  stv.BeginAng.clear();
224  stv.BeginChg.clear();
225  stv.BeginVtx.clear();
226  stv.EndWir.clear();
227  stv.EndTim.clear();
228  stv.EndAng.clear();
229  stv.EndChg.clear();
230  stv.EndVtx.clear();
231  stv.MCSMom.clear();
232  stv.PlaneNum.clear();
233  stv.TjID.clear();
234  stv.IsShowerTj.clear();
235  stv.ShowerID.clear();
236  stv.IsShowerParent.clear();
237  stv.StageNum.clear();
238  stv.Envelope.clear();
239  stv.EnvPlane.clear();
240  stv.EnvStage.clear();
241  stv.EnvShowerID.clear();
242 
243  return;
244 
245  } // ClearShowerTree
246 
247 } // namespace tca
std::vector< int > EnvStage
Definition: DataStructs.h:404
Point2_t Pos
Definition: DataStructs.h:152
std::vector< int > IsShowerParent
Definition: DataStructs.h:397
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:663
std::vector< float > EndWir
Definition: DataStructs.h:384
std::vector< float > EndAng
Definition: DataStructs.h:386
std::vector< ShowerStruct > cots
Definition: DataStructs.h:672
std::vector< float > BeginTim
Definition: DataStructs.h:380
std::vector< Point2_t > Envelope
Definition: DataStructs.h:325
TCConfig tcc
Definition: DataStructs.cxx:9
std::vector< float > BeginAng
Definition: DataStructs.h:381
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
std::vector< int > TjIDs
Definition: DataStructs.h:318
void ClearShowerTree(ShowerTreeVars &stv)
Definition: TCShTree.cxx:219
short MCSMom
Normalized RMS using ALL hits. Assume it is 50% to start.
Definition: DataStructs.h:197
void SaveAllCots(TCSlice &slc, const CTP_t &inCTP, std::string someText)
Definition: TCShTree.cxx:179
std::vector< float > EndTim
Definition: DataStructs.h:385
std::vector< int > ShowerID
Definition: DataStructs.h:396
ShowerTreeVars stv
Definition: DataStructs.cxx:11
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
save shower tree
Definition: DataStructs.h:533
std::vector< std::string > StageName
Definition: DataStructs.h:399
std::vector< int > TjID
Definition: DataStructs.h:394
float unitsPerTick
scale factor from Tick to WSE equivalent units
Definition: DataStructs.h:564
std::vector< short > BeginVtx
Definition: DataStructs.h:383
CTP_t CTP
Cryostat, TPC, Plane code.
Definition: DataStructs.h:189
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:188
std::vector< short > EndVtx
Definition: DataStructs.h:388
void SaveTjInfo(TCSlice &slc, std::vector< std::vector< int >> &tjList, std::string stageName)
Definition: TCShTree.cxx:14
std::array< unsigned short, 2 > EndPt
First and last point in the trajectory that has charge.
Definition: DataStructs.h:200
std::vector< float > Envelope
Definition: DataStructs.h:402
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
Definition of data types for geometry description.
std::vector< float > BeginChg
Definition: DataStructs.h:382
int ID
ID that is local to one slice.
Definition: DataStructs.h:202
std::array< unsigned short, 2 > VtxID
ID of 2D vertex.
Definition: DataStructs.h:199
std::bitset< 16 > modes
number of points to find AveChg
Definition: DataStructs.h:600
std::vector< int > EnvPlane
Definition: DataStructs.h:403
std::vector< short > MCSMom
Definition: DataStructs.h:390
unsigned int CTP_t
Definition: DataStructs.h:47
std::vector< int > StageNum
Definition: DataStructs.h:398
void SaveTjInfoStuff(TCSlice &slc, Trajectory &tj, int stageNum)
Definition: TCShTree.cxx:144
unsigned short nPlanes
Definition: DataStructs.h:408
std::bitset< 128 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
Definition: DataStructs.h:190
std::vector< float > BeginWir
Definition: DataStructs.h:379
geo::PlaneID DecodeCTP(CTP_t CTP)
std::vector< float > EndChg
Definition: DataStructs.h:387
int GetStageNum(ShowerTreeVars &stv, std::string stageName)
Definition: TCShTree.cxx:200
unsigned short nPlanes
Definition: DataStructs.h:656
std::vector< int > EnvShowerID
Definition: DataStructs.h:405
std::vector< int > IsShowerTj
Definition: DataStructs.h:395
std::vector< short > PlaneNum
Definition: DataStructs.h:392