EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SensitiveVolume.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SensitiveVolume.h
1 //
2 // AYK (ayk@bnl.gov), 2014/09/19
3 //
4 // Re-mastered RegisteringPlane class;
5 //
6 
7 #include <TGeoShape.h>
8 #include <TGeoNode.h>
9 #include <TGeoBBox.h>
10 
11 #include <3d.h>
12 #include <EicHtcTask.h>
13 
14 #include <EicTrackingDigiHit.h>
16 
17 #ifndef _SENSITIVE_VOLUME_
18 #define _SENSITIVE_VOLUME_
19 
20 class FwdHoughNodeGroup;
21 
23  public:
24  KalmanNodeWrapper(KalmanNode *node, EicKfNodeTemplate *kftmpl, TGeoMatrix *sv2master): mKFtmpl(kftmpl) {
25  mKfNodes.push_back(node);
26 
27  // Calculate complete 3D transformation from KF node to MARS; THINK: why the order
28  // of 3D transformations should be reversed to work properly?!;
29 #if 1
30  //{
31  //TGeoMatrix *m1 = new TGeoMatrix(), m2;
32  //}
33  //assert(0);
34  //mNodeToMaster = new TGeoHMatrix(kftmpl->mNodeToSensitiveVolume ?
35  // (*sv2master) * (*kftmpl->mNodeToSensitiveVolume) :
36  // *sv2master);
37  //mNodeToMaster = new TGeoHMatrix(kftmpl->mNodeToSensitiveVolume ?
38  // (*(new TGeoHMatrix(*sv2master))) * (*kftmpl->mNodeToSensitiveVolume) :
39  // *sv2master);
40  //if (kftmpl->mNodeToSensitiveVolume)
41  //mNodeToMaster = new TGeoHMatrix(TGeoHMatrix(*sv2master) * (*kftmpl->mNodeToSensitiveVolume));
42  //else
43  //mNodeToMaster = new TGeoHMatrix(*sv2master);
44 
46  new TGeoHMatrix(TGeoHMatrix(*sv2master) * (*kftmpl->mNodeToSensitiveVolume)) :
47  new TGeoHMatrix(*sv2master);
48  //else
49 
50 
51  //(*sv2master) * (*kftmpl->mNodeToSensitiveVolume) :
52  // *sv2master);
53 #else
54  mNodeToMaster = new TGeoHMatrix(kftmpl->mNodeToSensitiveVolume ?
55  (*kftmpl->mNodeToSensitiveVolume) * (*sv2master) :
56  *sv2master);
57 #endif
58 
59  // Calculate KF template origin in MARS;
60  TVector3 xnode(0,0,0);
62 
63  // Calculate basis vectors in MARS;
64  TVector3 nxnode(1,0,0), nznode(0,0,1);
67  mBasis[1] = mBasis[2].Cross(mBasis[0]);
68 
69  mNodeGroup = 0;
70  };
72 
74 
75  KalmanNode *GetKfNode(unsigned id) const { return (id < mKfNodes.size() ? mKfNodes[id] : 0); }
76 
78  assert(mKfNodes.size());
79 
80  char name[1024];
81  TrKalmanNode *node = dynamic_cast<TrKalmanNode*>(mKfNodes[0]);
82 
83  snprintf(name, 1024-1, "%s-%03d", node->GetName(), (unsigned)mKfNodes.size());
84  TrKalmanNode *clone =
85  dynamic_cast<TrKalmanNode*>(kf->AddNodeWrapper(name, NULL, node->GetZ(), node->GetMdim()));
86  clone->SetSensitiveVolume(sv);
87 
88  // FIXME: all this stuff should be encapsulated in KF node class;
89  clone->SetActiveFlag(false);
90  clone->SetLocation(node->GetLocation());
91  clone->CopyOverGroupInfo(node);
92  node->GetLocation()->AddNode(clone);
93 
94  mKfNodes.push_back(clone);
95  };
96 
97  const TVector3& GetOrigin() const { return mOrigin; };
98  const TVector3 *GetAxis(unsigned iq) const { return (iq < 3 ? mBasis + iq : 0); };
99  double GetAxisComponent(unsigned iq, unsigned xyz) const {
100  return (iq < 3 && xyz < 3 ? mBasis[iq][xyz] : 0.0); };
101  const TGeoHMatrix *GetNodeToMasterMtx() const { return mNodeToMaster; };
102 
103  void SetNodeGroup(FwdHoughNodeGroup *ngroup) { mNodeGroup = ngroup; };
105 
106  unsigned GetMdim() const { return mKFtmpl->GetMdim(); };
107 
108  private:
110 
112 
113  // A vector here to be able to accomodate several hits independently;
114  std::vector<KalmanNode*> mKfNodes;
115 
116  TGeoHMatrix *mNodeToMaster; // transformation from KF node directly to MARS
117 
118  TVector3 mOrigin, mBasis[3]; // KF node origin and 3 basis vectore in MARS system
119 };
120 
122  // FIXME: pleeease!;
123  friend class EicKfNodeTemplate;
124  friend class EicHtcTask;
125 
126  public:
127  SensitiveVolume(LogicalVolumeLookupTableEntry *lNode, const TGeoNode *node, double z0):
128  mLogicalNode(lNode) /*mXmin(0.0), mXmax(0.0), mYmin(0.0), mYmax(0.0)*/ {
129  // Calculate bounding box in XY projection in MARS; FIXME: this will work only
130  // if KF axis is a MARS Z-axis;
131  TGeoVolume *volume = node->GetVolume();
132  TGeoShape *shape = volume->GetShape();
133  //shape->ComputeBBox();
134 
135  TGeoBBox *box = dynamic_cast<TGeoBBox*>(shape);
136 
137  // NB: do NOT move bounding box corners to MARS; this will be done in FwdTrackFinder::Init()
138  // taking back transformation to KF node template coord.system;
139  mXmin = -box->GetDX();
140  mXmax = box->GetDX();
141  mYmin = -box->GetDY();
142  mYmax = box->GetDY();
143  };
145 
146  int TrackToHitDistance(t_3d_line *line, EicTrackingDigiHit *hit, double qdist[]);
147 
148  unsigned GetKfNodeWrapperCount() const { return mKfNodeWrappers.size(); };
150  return (id < mKfNodeWrappers.size() ? &mKfNodeWrappers[id] : 0);
151  };
152 
153  void SetNodeGroup(unsigned wr, FwdHoughNodeGroup *ngroup) {
154  if (wr < mKfNodeWrappers.size()) mKfNodeWrappers[wr].SetNodeGroup(ngroup);
155  };
157  return (wr < mKfNodeWrappers.size() ? mKfNodeWrappers[wr].GetNodeGroup() : 0);
158  };
159 
160  // No reason to make arrays, etc?;
161  double GetXmin() const { return mXmin; };
162  double GetXmax() const { return mXmax; };
163  double GetYmin() const { return mYmin; };
164  double GetYmax() const { return mYmax; };
165 
167 
168  private:
169  // Kalman filter wrapper nodes associated with this sensitive volume;
170  std::vector<KalmanNodeWrapper> mKfNodeWrappers;
171 
172  // std::map<unsigned, EicKfNodeTemplateOrth2D::CoordinateModel> mCoordinateModels2D;
173 
174  // Bounding box in MARS coordinate system;
175  double mXmin, mXmax, mYmin, mYmax;
176 
178 };
179 
180 #endif