EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicHtcTask.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicHtcTask.h
1 //
2 // AYK (ayk@bnl.gov), 2014/02/03
3 //
4 // An attempt to port HERMES & OLYMPUS forward tracking KF code to EicRoot;
5 //
6 
7 //#include <3d.h>
8 //#include <htclib.h>
9 
10 #ifndef _EIC_HTC_TASK_
11 #define _EIC_HTC_TASK_
12 
13 class TGeoNode;
14 
15 // FIXME: save on typing?; really?;
16 #define _EIC_HTC_TREE_ "htc"
17 #define _EIC_HTC_BRANCH_ "EicHtcTrack"
18 #define _EIC_HTC_TRACK_ "track"
19 
20 #include <TGeoMatrix.h>
21 
22 #include <FairTask.h>
23 
24 #include <TrKalmanFilter.h>
25 #include <FairTrackParP.h>
26 
27 class EicTrackingDigiHit;
28 
29 #include <EicIdealTrackingCode.h>
31 
32 class EicHtcHitComponent: public TObject {
33  // No reason to overcomplicate access here;
34  friend class EicHtcHit;
35  friend class EicHtcTask;
36 
37  public:
40  };
42 
43  private:
44  Double_t mLocalCoord1D; // local coordinate
45 
46  Double_t mXsResidual; // smoothed residual (~inclusive in Aiwu's notation)
47  Double_t mXmResidual; // smoothed-subtracted one (~exclusive in Aiwu's notation)
48 
49  Double_t mResolution; // 1D sigma used for track fitting (and smearing in case of MC data)
50 
51  // This is in node-projected space (H*M*H^T); assume only diagonal terms of respective
52  // cov.matrix are of interest; otherwise will have to put full matrix right into
53  // the EicHtcHit class;
54  Double_t mSigmaRS; // sqrt(diagonal term) of H-projected smoother cov.matrix
55  Double_t mSigmaRM; // same as above, without information from this KF node
56 
58 };
59 
60 class EicHtcHit: public TObject {
61  friend class EicHtcTask;
62 
63  public:
64  EicHtcHit(unsigned dim = 0): mDim(dim) {
66 
67  //memset(mSigmaCS, 0x00, sizeof(mSigmaCS));
68  mGlobalCoordXY[0] = mGlobalCoordXY[1] = 0.0;
69 
71  };
72  ~EicHtcHit() {};
73 
74  double ChiSq() const { return mSmootherChiSquare; };
75  double Prob() const { return mSmootherProbability; };
76 
77  // Hit resolution (sqrt of diagonal term);
78  double GetResolution(unsigned what = 0) const {
79  return what < mDim ? mComponents[what].mResolution : 0.0;
80  };
81 
82  // Local coordinate(s);
83  double GetLc(unsigned what = 0) const {
84  return what < mDim ? mComponents[what].mLocalCoord1D : 0.0;
85  };
86  // Global XY-coordinates;
87  double GetGc(unsigned what = 0) const {
88  return what < 2 ? mGlobalCoordXY[what] : 0.0;
89  };
90 
91  // Smoother residuals and estimated error (component onto detector
92  // plane coordinate system); aka "inclusive residual";
93  double GetRs(unsigned what = 0) const {
94  return what < mDim ? mComponents[what].mXsResidual : 0.0;
95  };
96  double GetEs(unsigned what = 0) const {
97  return what < mDim ? mComponents[what].mSigmaRS : 0.0;
98  };
99 
100  // Same as above, but with the present KF node measurement excluded;
101  // aka "exclusive residual";
102  double GetRm(unsigned what = 0) const {
103  return what < mDim ? mComponents[what].mXmResidual : 0.0;
104  };
105  double GetEm(unsigned what = 0) const {
106  return what < mDim ? mComponents[what].mSigmaRM : 0.0;
107  };
108 
109  private:
110  UInt_t mDim;
111  EicHtcHitComponent *mComponents; //[mDim] up to 2 components for now
112 
113  Double_t mSmootherChiSquare; // chi^2 after Kalman smoother pass for this node
114  Double_t mSmootherProbability; // "probability" of this chi^2 value
115 
116  Double_t mGlobalCoordXY[2]; // global XY-coordinates at this node
117 
118  // FIXME: may later want to add both state vector, as well as the full smoother
119  // covariance matrix; not really needed for FLYSUB business right now;
120  //
121  // This is the "global" 3D space, {x,y,sx,sy} or {x,y,sx,sy,1/p} track parameterization;
122  //Double_t mSigmaCS[5]; // sqrt(diagonal terms) of smoother cov.matrix in 3D
123 
124  ClassDef(EicHtcHit,12);
125 };
126 
127 // NB: "tuple" is available in C++ 11 only, sorry;
128 typedef std::pair<const char*, std::pair<unsigned, unsigned> > kEntry;
129 typedef std::map<kEntry, EicHtcHit*, bool(*)(kEntry, kEntry)> hEntry;
131 
132 class EicHtcTrack: public TObject {
133  friend class EicHtcTask;
134 
135  public:
137  mHits = new hEntry(HitKeyCompare);
138 
139  memset(mBeamCoordXY, 0x00, sizeof(mBeamCoordXY));
140  memset(mBeamCoordSigmaXY, 0x00, sizeof(mBeamCoordSigmaXY));
141 
142  memset(mBeamSlopeXY, 0x00, sizeof(mBeamSlopeXY));
143  memset(mBeamSlopeSigmaXY, 0x00, sizeof(mBeamSlopeSigmaXY));
144  };
145  ~EicHtcTrack() { if (mHits) delete mHits; };
146 
147  // Simplify access method names (typing issues);
148  int Ndf() const { return mNdf; };
149  double ChiSquare() const { return mFilterChiSquare; };
150  double ChiSquareCCDF() const { return mFilterChiSquareCCDF; };
151 
152  double BeamX() const { return mBeamCoordXY [0]; };
153  double BeamEX() const { return mBeamCoordSigmaXY[0]; };
154  double BeamY() const { return mBeamCoordXY [1]; };
155  double BeamEY() const { return mBeamCoordSigmaXY[1]; };
156 
157  double BeamSX() const { return mBeamSlopeXY [0]; };
158  double BeamESX() const { return mBeamSlopeSigmaXY[0]; };
159  double BeamSY() const { return mBeamSlopeXY [1]; };
160  double BeamESY() const { return mBeamSlopeSigmaXY[1]; };
161 
162  const EicHtcHit* GetHit(const char *detName, unsigned group, unsigned node = 0) const;
163 
164  Double_t mMomentum;
165 
166  private:
167  // General parameters;
168  Int_t mNdf; // number of degrees of freedom
169  Double_t mFilterChiSquare; // chi^2 after Kalman filter pass for the whole track
170  Double_t mFilterChiSquareCCDF;// respective complement of the cumulative distribution function
171 
172  Double_t mBeamCoordXY[2]; // beam coordinate estimate at the KF head node
173  Double_t mBeamCoordSigmaXY[2];// respective diagonal errors
174  Double_t mBeamSlopeXY[2]; // beam slope estimate at the KF head node
175  Double_t mBeamSlopeSigmaXY[2];// respective diagonal errors
176 
177  // Track/hit info at registering plane locations;
179 
181 };
182 
184  public:
188 
189  int KalmanFilterMagneticField(TVector3 &xx, TVector3 &B);
190 
191  private:
193 
194  MgridSlice *InitializeMgridSlice(double z0);
195 };
196 
197 class EicHtcTask: public FairTask {
198  public:
199 
200  EicHtcTask(): FairTask("EIC HTC Task") { ResetVars(); };
202 
203  void ResetVars() {
204  mMediaBank = 0; mFitTrackArray = 0;
205 
206  mHtcBranch = 0; mHtcTrack = 0; mPersistency = true;
207  mParticleMomentumSeed = 30.0;
208 
210 
211  mKalmanFilter = 0;
212 
213  mMediaScanDirection = TVector3(0.0, 0.0, 1.0);
214  };
215 
217 
218  // Want to propagate detector group names to the Kalman filter initialization;
219  InitStatus Init();
220 
221  void Exec(Option_t* opt);
222 
223  void Print(Option_t* option = "") const;
224 
225  void FinishTask();
226 
227  void SetTrackOutBranchName(const TString& name) { mTrackOutBranchName = name; }
228 
229  // Basically "proton" or "pion"; THINK: momentum = 0.0 means: take
230  // simulated one as a seed; or perhaps the one from EicIdealTrack?;
231  int SetParticleHypothesis(const char *name, double momentumSeed = 0.0) {
232  if (name) mParticleHypothesis = TString(name);
233  mParticleMomentumSeed = momentumSeed;
234 
235  return 0;
236  };
237 
238  // 'virtual': well, let user code an opportunity to explicitely specify both axis
239  // and scan 3D lines in space explicitely;
240  virtual MediaBank *ConfigureMediaBank();
241 
242  void SetMediaScanThetaPhi(double theta, double phi);
243  TVector3 GetMediaScanDirection() const { return mMediaScanDirection; };
244 
245  // May want to change coordinate and residual scale in the encoded hits to
246  // something like [mm] and [um] (default is 1:1, so [cm]);
247  void SetHitOutputCoordinateScaleXY(double scale) { mCoordinateScaleXY = scale; };
248  void SetHitOutputSlopeScale(double scale) { mSlopeScale = scale; };
249  void SetHitOutputResidualScaleXY(double scale) { mResidualScaleXY = scale; };
250 
251  void SetResolutionByHand(const char *plName, double value) {
252  if (plName) mResolutionsByHand[TString(plName)] = value;
253  };
254  double GetResolutionByHand(const char *plName) {
255  //printf("%d\n", mResolutionsByHand.size());
256  if (plName && mResolutionsByHand.find(TString(plName)) != mResolutionsByHand.end())
257  return mResolutionsByHand[TString(plName)];
258  else
259  return 0.0;
260  };
261 
263 
264  virtual unsigned GetMissingHitCounterMax() const { return 0; };
265 
266  protected:
268 
270 
271  //void SetMaxPossibleHitCount(unsigned max) { mMaxPossibleHitCount = max; };
272  unsigned GetMaxPossibleHitCount() const;// {
273  //return mMaxPossibleHitCount;
274  //};
275 
276 private:
278 
279  TClonesArray* mFitTrackArray;
280 
282 
283  TBranch *mHtcBranch;
285  Bool_t mPersistency;
286 
288 
289  public:
290  TString mParticleHypothesis; // particle hypothesis used for fitting
291  // NB: this will remain constant for magnet-off mode;
292  Double_t mParticleMomentumSeed; // particle momentum seed used for fitting
293 
294  //
295  // FIXME: not radians in fact; need atan() somewhere -> check!;
296  //
297  private:
298  // Local 1D spatial detector coordinates (say XY) and beam profile XY-coordinates;
299  Double_t mCoordinateScaleXY; // [cm] may be rescaled to say [mm]
300  // Beam profile XY-slopes;
301  Double_t mSlopeScale; // [rad] may be rescaled to say [urad]
302  // Local 1D spatial detector residuals (say XY);
303  Double_t mResidualScaleXY; // [cm] may be rescaled to say [um]
304 
305  std::map<TString, double> mResolutionsByHand; // resolutions set by hand in reconstruction.C
306 
307  //unsigned mMaxPossibleHitCount;
308 
309  int PerformMediaScan();
311  int ConfigureKalmanFilter();
312 
314 
316 
317  ClassDef(EicHtcTask,22);
318 };
319 
320 #endif