TCShTree.cxx
Go to the documentation of this file.
4 
5 #include <array>
6 #include <bitset>
7 #include <math.h>
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,
15  std::string stageName) {
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, stageName);
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  if(!tcc.modes[kSaveShowerTree]) return;
58  int stageNum = GetStageNum(stv, stageName);
59 
60  // killed shower?
61  if(ss.ID == 0) return;
62 
63  bool noMatch = true;
64 
65  for(unsigned short it1 = 0; it1 < slc.tjs.size(); ++it1) {
66 
67  Trajectory& tj1 = slc.tjs[it1];
68 
69  if(tj1.AlgMod[kKilled]) continue;
70 
71  int trajID = tj1.ID;
72 
73  // check if this tj has already been added to the list
74  // for this particular stage and plane
75  int tjIndex = -1;
76  bool isShowerTj = false;
77  for (size_t i = 0; i < stv.TjID.size(); ++i) {
78  if (stv.StageNum.at(i) != (int)stageNum) continue;
79  if (stv.PlaneNum.at(i) != (short)DecodeCTP(ss.CTP).Plane) continue;
80 
81  if (stv.TjID.at(i) == trajID) {
82  tjIndex = i;
83  if (stv.IsShowerTj.at(tjIndex) == 1) isShowerTj = true;
84  //beenDoneBefore = true;
85  break;
86  }
87  }
88 
89  if (isShowerTj) continue;
90  if (tjIndex == -1) SaveTjInfoStuff(slc, tj1, stageNum, stageName);
91 
92  for (size_t i = 0; i < ss.TjIDs.size(); ++i) {
93  if (trajID == ss.TjIDs[i]) {
94  noMatch = false;
95  if (tjIndex == -1) stv.ShowerID.back() = ss.ID;
96  else stv.ShowerID.at(tjIndex) = ss.ID;
97  }
98 
99  if (it1 == (ss.ShowerTjID - 1)) stv.IsShowerTj.back() = 1;
100  else if (tj1.AlgMod[kShowerTj]) stv.IsShowerTj.back() = 1; // this is a better check
101  // check if tj is shower parent. if so, add to ttree
102  // and mark parent flag
103  if (trajID == ss.ParentID) {
104  if (tjIndex == -1) {
105  stv.ShowerID.back() = ss.ID;
106  stv.IsShowerParent.back() = 1;
107  }
108  else {
109  stv.ShowerID.at(tjIndex) = ss.ID;
110  stv.IsShowerParent.at(tjIndex) = 1;
111  }
112  break;
113 
114  }
115  } // ss TjID loop
116  } // end tjs loop
117 
118  if (noMatch) return;
119 
120  // add envelope information to showertreevars
121  geo::PlaneID iPlnID = DecodeCTP(ss.CTP);
122 
123  for (int i = 0; i < 8; i++) {
124  stv.EnvStage.push_back(stageNum);
125  stv.EnvPlane.push_back(iPlnID.Plane);
126  stv.EnvShowerID.push_back(ss.ID);
127  }
128 
129  stv.Envelope.push_back(ss.Envelope[0][0]);
130  stv.Envelope.push_back(ss.Envelope[0][1]/tcc.unitsPerTick);
131  stv.Envelope.push_back(ss.Envelope[1][0]);
132  stv.Envelope.push_back(ss.Envelope[1][1]/tcc.unitsPerTick);
133  stv.Envelope.push_back(ss.Envelope[2][0]);
134  stv.Envelope.push_back(ss.Envelope[2][1]/tcc.unitsPerTick);
135  stv.Envelope.push_back(ss.Envelope[3][0]);
136  stv.Envelope.push_back(ss.Envelope[3][1]/tcc.unitsPerTick);
137 
138  } // SaveTjInfo (cots)
139 
140  void SaveTjInfoStuff(TCSlice& slc, Trajectory& tj, int stageNum, std::string stageName) {
141  if(!tcc.modes[kSaveShowerTree]) return;
142 
143  TrajPoint& beginPoint = tj.Pts[tj.EndPt[0]];
144  TrajPoint& endPoint = tj.Pts[tj.EndPt[1]];
145 
146  stv.BeginWir.push_back(std::nearbyint(beginPoint.Pos[0]));
147  stv.BeginTim.push_back(std::nearbyint(beginPoint.Pos[1]/tcc.unitsPerTick));
148  stv.BeginAng.push_back(beginPoint.Ang);
149  stv.BeginChg.push_back(beginPoint.Chg);
150  stv.BeginVtx.push_back(tj.VtxID[0]);
151 
152  stv.EndWir.push_back(std::nearbyint(endPoint.Pos[0]));
153  stv.EndTim.push_back(std::nearbyint(endPoint.Pos[1]/tcc.unitsPerTick));
154  stv.EndAng.push_back(endPoint.Ang);
155  stv.EndChg.push_back(endPoint.Chg);
156  stv.EndVtx.push_back(tj.VtxID[1]);
157 
158  stv.MCSMom.push_back(tj.MCSMom);
159  stv.TjID.push_back(tj.ID);
160  stv.IsShowerTj.push_back(-1);
161 
162  stv.ShowerID.push_back(-1);
163  stv.IsShowerParent.push_back(-1);
164  stv.StageNum.push_back(stageNum);
165  stv.nStages = stageNum;
166  geo::PlaneID iPlnID = DecodeCTP(tj.CTP);
167  stv.PlaneNum.push_back(iPlnID.Plane);
168 
169  stv.nPlanes = slc.nPlanes;
170 
171  } // SaveTjInfoStuff
172 
173  ////////////////////////////////////////////////
174  void SaveAllCots(TCSlice& slc, const CTP_t& inCTP, std::string someText) {
175  if(!tcc.modes[kSaveShowerTree]) return;
176  for(unsigned short cotIndex = 0; cotIndex < slc.cots.size(); ++cotIndex) {
177  auto& ss = slc.cots[cotIndex];
178  if (ss.CTP != inCTP) continue;
179  if(ss.ID == 0) continue;
180  SaveTjInfo(slc, ss, someText);
181  } // cotIndex
182  } // SaveAllCots
183 
184 
185  void SaveAllCots(TCSlice& slc, std::string someText) {
186  if(!tcc.modes[kSaveShowerTree]) return;
187  for(unsigned short cotIndex = 0; cotIndex < slc.cots.size(); ++cotIndex) {
188  auto& ss = slc.cots[cotIndex];
189  if(ss.ID == 0) continue;
190  SaveTjInfo(slc, ss, someText);
191  } // cotIndex
192  }
193 
195  int stageNum;
196  bool existingStage = false;
197  for (unsigned short i = 0; i < stv.StageName.size(); ++i) {
198  if (stv.StageName.at(i) == stageName) {
199  existingStage = true;
200  stageNum = i+1;
201  }
202  }
203 
204  if (!existingStage) {
205  stv.StageName.push_back(stageName);
206  stageNum = stv.StageName.size();
207  }
208 
209  return stageNum;
210  }
211 
213  stv.BeginWir.clear();
214  stv.BeginTim.clear();
215  stv.BeginAng.clear();
216  stv.BeginChg.clear();
217  stv.BeginVtx.clear();
218  stv.EndWir.clear();
219  stv.EndTim.clear();
220  stv.EndAng.clear();
221  stv.EndChg.clear();
222  stv.EndVtx.clear();
223  stv.MCSMom.clear();
224  stv.PlaneNum.clear();
225  stv.TjID.clear();
226  stv.IsShowerTj.clear();
227  stv.ShowerID.clear();
228  stv.IsShowerParent.clear();
229  stv.StageNum.clear();
230  stv.Envelope.clear();
231  stv.EnvPlane.clear();
232  stv.EnvStage.clear();
233  stv.EnvShowerID.clear();
234 
235  return;
236 
237  } // ClearShowerTree
238 
239 } // namespace tca
std::vector< int > EnvStage
Definition: DataStructs.h:413
Point2_t Pos
Definition: DataStructs.h:157
void SaveTjInfoStuff(TCSlice &slc, Trajectory &tj, int stageNum, std::string stageName)
Definition: TCShTree.cxx:140
std::vector< int > IsShowerParent
Definition: DataStructs.h:406
std::vector< Trajectory > tjs
vector of all trajectories in each plane
Definition: DataStructs.h:672
std::vector< float > EndWir
Definition: DataStructs.h:393
std::vector< float > EndAng
Definition: DataStructs.h:395
std::vector< ShowerStruct > cots
Definition: DataStructs.h:681
std::vector< float > BeginTim
Definition: DataStructs.h:389
std::vector< Point2_t > Envelope
Definition: DataStructs.h:334
std::string string
Definition: nybbler.cc:12
TCConfig tcc
Definition: DataStructs.cxx:8
std::vector< float > BeginAng
Definition: DataStructs.h:390
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
std::vector< int > TjIDs
Definition: DataStructs.h:327
void ClearShowerTree(ShowerTreeVars &stv)
Definition: TCShTree.cxx:212
short MCSMom
Normalized RMS using ALL hits. Assume it is 50% to start.
Definition: DataStructs.h:202
struct vector vector
void SaveAllCots(TCSlice &slc, const CTP_t &inCTP, std::string someText)
Definition: TCShTree.cxx:174
std::vector< float > EndTim
Definition: DataStructs.h:394
std::vector< int > ShowerID
Definition: DataStructs.h:405
ShowerTreeVars stv
Definition: DataStructs.cxx:10
save shower tree
Definition: DataStructs.h:542
std::vector< std::string > StageName
Definition: DataStructs.h:408
std::vector< int > TjID
Definition: DataStructs.h:403
float unitsPerTick
scale factor from Tick to WSE equivalent units
Definition: DataStructs.h:573
std::vector< short > BeginVtx
Definition: DataStructs.h:392
CTP_t CTP
Cryostat, TPC, Plane code.
Definition: DataStructs.h:194
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:193
std::vector< short > EndVtx
Definition: DataStructs.h:397
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:205
std::vector< float > Envelope
Definition: DataStructs.h:411
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Definition of data types for geometry description.
std::vector< float > BeginChg
Definition: DataStructs.h:391
int ID
ID that is local to one slice.
Definition: DataStructs.h:207
std::array< unsigned short, 2 > VtxID
ID of 2D vertex.
Definition: DataStructs.h:204
std::bitset< 16 > modes
number of points to find AveChg
Definition: DataStructs.h:609
std::vector< int > EnvPlane
Definition: DataStructs.h:412
std::vector< short > MCSMom
Definition: DataStructs.h:399
unsigned int CTP_t
Definition: DataStructs.h:49
std::vector< int > StageNum
Definition: DataStructs.h:407
unsigned short nPlanes
Definition: DataStructs.h:417
std::bitset< 128 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
Definition: DataStructs.h:195
std::vector< float > BeginWir
Definition: DataStructs.h:388
geo::PlaneID DecodeCTP(CTP_t CTP)
std::vector< float > EndChg
Definition: DataStructs.h:396
int GetStageNum(ShowerTreeVars &stv, std::string stageName)
Definition: TCShTree.cxx:194
unsigned short nPlanes
Definition: DataStructs.h:665
std::vector< int > EnvShowerID
Definition: DataStructs.h:414
std::vector< int > IsShowerTj
Definition: DataStructs.h:404
std::vector< short > PlaneNum
Definition: DataStructs.h:401