LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TCShTree.cxx
Go to the documentation of this file.
2 
3 namespace tca {
4 
5  void SaveTjInfo(TjStuff& tjs, std::vector<std::vector<int>>& tjList,
6  std::string stageName) {
7  if(!tjs.SaveShowerTree) return;
8  if(tjList.empty()) return;
9  int stageNum = GetStageNum(tjs.stv, stageName);
10 
11  // get the CTP from the first tj
12  CTP_t inCTP = tjs.allTraj[tjList[0][0] - 1].CTP;
13  for(unsigned short it1 = 0; it1 < tjs.allTraj.size(); ++it1) {
14  Trajectory& tj1 = tjs.allTraj[it1];
15  if(tj1.CTP != inCTP) continue;
16  if(tj1.AlgMod[kKilled]) continue;
17 
18  SaveTjInfoStuff(tjs, tj1, stageNum, stageName);
19 
20  int trajID = tj1.ID;
21  bool inShower = false;
22 
23  for (size_t l1 = 0; l1 < tjList.size(); ++l1) {
24  if (inShower) break;
25  for (size_t l2 = 0; l2 < tjList[l1].size(); ++l2) {
26 
27  if (trajID == tjList[l1][l2]) {
28  tjs.stv.ShowerID.back() = l1;
29  inShower = true;
30  break;
31  }
32  } // end list loop 2
33  } // end list loop 1
34  } // end tjs loop
35  // add meaningless envelope to list for counting purposes
36  // envelopes are defined once DefineShower is called
37  // fill four times, one for each side of polygon
38  for (int i = 0; i < 8; i++) {
39  tjs.stv.Envelope.push_back(-999);
40  tjs.stv.EnvStage.push_back(stageNum);
41  tjs.stv.EnvPlane.push_back(-1);
42  tjs.stv.EnvShowerID.push_back(-1);
43  }
44 
45  } // SaveTjInfo (tjlist)
46 
47  void SaveTjInfo(TjStuff& tjs, const ShowerStruct& ss, std::string stageName) {
48  if(!tjs.SaveShowerTree) return;
49  int stageNum = GetStageNum(tjs.stv, stageName);
50 
51  // killed shower?
52  if(ss.ID == 0) return;
53 
54  bool noMatch = true;
55 
56  for(unsigned short it1 = 0; it1 < tjs.allTraj.size(); ++it1) {
57 
58  Trajectory& tj1 = tjs.allTraj[it1];
59 
60  if(tj1.AlgMod[kKilled]) continue;
61 
62  int trajID = tj1.ID;
63 
64  // check if this tj has already been added to the list
65  // for this particular stage and plane
66  int tjIndex = -1;
67  bool isShowerTj = false;
68  for (size_t i = 0; i < tjs.stv.TjID.size(); ++i) {
69  if (tjs.stv.StageNum.at(i) != (int)stageNum) continue;
70  if (tjs.stv.PlaneNum.at(i) != (short)DecodeCTP(ss.CTP).Plane) continue;
71 
72  if (tjs.stv.TjID.at(i) == trajID) {
73  tjIndex = i;
74  if (tjs.stv.IsShowerTj.at(tjIndex) == 1) isShowerTj = true;
75  //beenDoneBefore = true;
76  break;
77  }
78  }
79 
80  if (isShowerTj) continue;
81  if (tjIndex == -1) SaveTjInfoStuff(tjs, tj1, stageNum, stageName);
82 
83  for (size_t i = 0; i < ss.TjIDs.size(); ++i) {
84  if (trajID == ss.TjIDs[i]) {
85  noMatch = false;
86  if (tjIndex == -1) tjs.stv.ShowerID.back() = ss.ID;
87  else tjs.stv.ShowerID.at(tjIndex) = ss.ID;
88  }
89 
90  if (it1 == (ss.ShowerTjID - 1)) tjs.stv.IsShowerTj.back() = 1;
91  else if (tj1.AlgMod[kShowerTj]) tjs.stv.IsShowerTj.back() = 1; // this is a better check
92  // check if tj is shower parent. if so, add to ttree
93  // and mark parent flag
94  if (trajID == ss.ParentID) {
95  if (tjIndex == -1) {
96  tjs.stv.ShowerID.back() = ss.ID;
97  tjs.stv.IsShowerParent.back() = 1;
98  }
99  else {
100  tjs.stv.ShowerID.at(tjIndex) = ss.ID;
101  tjs.stv.IsShowerParent.at(tjIndex) = 1;
102  }
103  break;
104 
105  }
106  } // ss TjID loop
107  } // end tjs loop
108 
109  if (noMatch) return;
110 
111  // add envelope information to showertreevars
112  geo::PlaneID iPlnID = DecodeCTP(ss.CTP);
113 
114  for (int i = 0; i < 8; i++) {
115  tjs.stv.EnvStage.push_back(stageNum);
116  tjs.stv.EnvPlane.push_back(iPlnID.Plane);
117  tjs.stv.EnvShowerID.push_back(ss.ID);
118  }
119 
120  tjs.stv.Envelope.push_back(ss.Envelope[0][0]);
121  tjs.stv.Envelope.push_back(ss.Envelope[0][1]/tjs.UnitsPerTick);
122  tjs.stv.Envelope.push_back(ss.Envelope[1][0]);
123  tjs.stv.Envelope.push_back(ss.Envelope[1][1]/tjs.UnitsPerTick);
124  tjs.stv.Envelope.push_back(ss.Envelope[2][0]);
125  tjs.stv.Envelope.push_back(ss.Envelope[2][1]/tjs.UnitsPerTick);
126  tjs.stv.Envelope.push_back(ss.Envelope[3][0]);
127  tjs.stv.Envelope.push_back(ss.Envelope[3][1]/tjs.UnitsPerTick);
128 
129  } // SaveTjInfo (cots)
130 
131  void SaveTjInfoStuff(TjStuff& tjs, Trajectory& tj, int stageNum, std::string stageName) {
132  if(!tjs.SaveShowerTree) return;
133 
134  TrajPoint& beginPoint = tj.Pts[tj.EndPt[0]];
135  TrajPoint& endPoint = tj.Pts[tj.EndPt[1]];
136 
137  tjs.stv.BeginWir.push_back(std::nearbyint(beginPoint.Pos[0]));
138  tjs.stv.BeginTim.push_back(std::nearbyint(beginPoint.Pos[1]/tjs.UnitsPerTick));
139  tjs.stv.BeginAng.push_back(beginPoint.Ang);
140  tjs.stv.BeginChg.push_back(beginPoint.Chg);
141  tjs.stv.BeginVtx.push_back(tj.VtxID[0]);
142 
143  tjs.stv.EndWir.push_back(std::nearbyint(endPoint.Pos[0]));
144  tjs.stv.EndTim.push_back(std::nearbyint(endPoint.Pos[1]/tjs.UnitsPerTick));
145  tjs.stv.EndAng.push_back(endPoint.Ang);
146  tjs.stv.EndChg.push_back(endPoint.Chg);
147  tjs.stv.EndVtx.push_back(tj.VtxID[1]);
148 
149  tjs.stv.MCSMom.push_back(tj.MCSMom);
150  tjs.stv.TjID.push_back(tj.ID);
151  tjs.stv.IsShowerTj.push_back(-1);
152 
153  tjs.stv.ShowerID.push_back(-1);
154  tjs.stv.IsShowerParent.push_back(-1);
155  tjs.stv.StageNum.push_back(stageNum);
156  tjs.stv.nStages = stageNum;
157  geo::PlaneID iPlnID = DecodeCTP(tj.CTP);
158  tjs.stv.PlaneNum.push_back(iPlnID.Plane);
159 
160  tjs.stv.nPlanes = tjs.NumPlanes;
161 
162  } // SaveTjInfoStuff
163 
165  void SaveAllCots(TjStuff& tjs, const CTP_t& inCTP, std::string someText) {
166  if(!tjs.SaveShowerTree) return;
167  for(unsigned short cotIndex = 0; cotIndex < tjs.cots.size(); ++cotIndex) {
168  auto& ss = tjs.cots[cotIndex];
169  if (ss.CTP != inCTP) continue;
170  if(ss.ID == 0) continue;
171  SaveTjInfo(tjs, ss, someText);
172  } // cotIndex
173  } // SaveAllCots
174 
175 
176  void SaveAllCots(TjStuff& tjs, std::string someText) {
177  if(!tjs.SaveShowerTree) return;
178  for(unsigned short cotIndex = 0; cotIndex < tjs.cots.size(); ++cotIndex) {
179  auto& ss = tjs.cots[cotIndex];
180  if(ss.ID == 0) continue;
181  SaveTjInfo(tjs, ss, someText);
182  } // cotIndex
183  }
184 
185  int GetStageNum(ShowerTreeVars& stv, std::string stageName) {
186  int stageNum;
187  bool existingStage = false;
188  for (unsigned short i = 0; i < stv.StageName.size(); ++i) {
189  if (stv.StageName.at(i) == stageName) {
190  existingStage = true;
191  stageNum = i+1;
192  }
193  }
194 
195  if (!existingStage) {
196  stv.StageName.push_back(stageName);
197  stageNum = stv.StageName.size();
198  }
199 
200  return stageNum;
201  }
202 
204  stv.BeginWir.clear();
205  stv.BeginTim.clear();
206  stv.BeginAng.clear();
207  stv.BeginChg.clear();
208  stv.BeginVtx.clear();
209  stv.EndWir.clear();
210  stv.EndTim.clear();
211  stv.EndAng.clear();
212  stv.EndChg.clear();
213  stv.EndVtx.clear();
214  stv.MCSMom.clear();
215  stv.PlaneNum.clear();
216  stv.TjID.clear();
217  stv.IsShowerTj.clear();
218  stv.ShowerID.clear();
219  stv.IsShowerParent.clear();
220  stv.StageNum.clear();
221  stv.Envelope.clear();
222  stv.EnvPlane.clear();
223  stv.EnvStage.clear();
224  stv.EnvShowerID.clear();
225 
226  return;
227 
228  } // ClearShowerTree
229 
230 } // namespace tca
std::vector< int > EnvStage
Definition: DataStructs.h:358
Point2_t Pos
Definition: DataStructs.h:147
std::vector< int > IsShowerParent
Definition: DataStructs.h:351
std::vector< float > EndWir
Definition: DataStructs.h:338
std::vector< float > EndAng
Definition: DataStructs.h:340
std::bitset< 64 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
Definition: DataStructs.h:171
std::vector< float > BeginTim
Definition: DataStructs.h:334
std::vector< Point2_t > Envelope
Definition: DataStructs.h:282
std::vector< float > BeginAng
Definition: DataStructs.h:335
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
std::vector< int > TjIDs
Definition: DataStructs.h:275
void ClearShowerTree(ShowerTreeVars &stv)
Definition: TCShTree.cxx:203
Float_t ss
Definition: plot.C:23
ShowerTreeVars stv
Definition: DataStructs.h:485
unsigned short NumPlanes
Definition: DataStructs.h:475
std::vector< float > EndTim
Definition: DataStructs.h:339
std::vector< int > ShowerID
Definition: DataStructs.h:350
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< ShowerStruct > cots
Definition: DataStructs.h:506
std::vector< std::string > StageName
Definition: DataStructs.h:353
std::vector< int > TjID
Definition: DataStructs.h:348
std::vector< short > BeginVtx
Definition: DataStructs.h:337
CTP_t CTP
Cryostat, TPC, Plane code.
Definition: DataStructs.h:170
std::vector< TrajPoint > Pts
Trajectory points.
Definition: DataStructs.h:169
std::vector< Trajectory > allTraj
vector of all trajectories in each plane
Definition: DataStructs.h:493
std::vector< short > EndVtx
Definition: DataStructs.h:342
std::array< unsigned short, 2 > EndPt
First and last point in the trajectory that has charge.
Definition: DataStructs.h:182
bool SaveShowerTree
Definition: DataStructs.h:486
void SaveTjInfo(TjStuff &tjs, std::vector< std::vector< int >> &tjList, std::string stageName)
Definition: TCShTree.cxx:5
std::vector< float > Envelope
Definition: DataStructs.h:356
float UnitsPerTick
scale factor from Tick to WSE equivalent units
Definition: DataStructs.h:468
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
std::vector< float > BeginChg
Definition: DataStructs.h:336
std::array< unsigned short, 2 > VtxID
ID of 2D vertex.
Definition: DataStructs.h:181
std::vector< int > EnvPlane
Definition: DataStructs.h:357
std::vector< short > MCSMom
Definition: DataStructs.h:344
void SaveAllCots(TjStuff &tjs, const CTP_t &inCTP, std::string someText)
Definition: TCShTree.cxx:165
unsigned int CTP_t
Definition: DataStructs.h:41
std::vector< int > StageNum
Definition: DataStructs.h:352
void SaveTjInfoStuff(TjStuff &tjs, Trajectory &tj, int stageNum, std::string stageName)
Definition: TCShTree.cxx:131
unsigned short nPlanes
Definition: DataStructs.h:362
std::vector< float > BeginWir
Definition: DataStructs.h:333
geo::PlaneID DecodeCTP(CTP_t CTP)
Definition: DataStructs.cxx:89
std::vector< float > EndChg
Definition: DataStructs.h:341
int GetStageNum(ShowerTreeVars &stv, std::string stageName)
Definition: TCShTree.cxx:185
std::vector< int > EnvShowerID
Definition: DataStructs.h:359
std::vector< int > IsShowerTj
Definition: DataStructs.h:349
std::vector< short > PlaneNum
Definition: DataStructs.h:346