StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFwdTrackMaker.h
1 #ifndef ST_FWD_TRACK_MAKER_H
2 #define ST_FWD_TRACK_MAKER_H
3 
4 #include "StChain/StMaker.h"
5 
6 #ifndef __CINT__
7 #include "GenFit/Track.h"
8 #endif
9 
10 #include "FwdTrackerConfig.h"
11 #include "TVector3.h"
12 
13 namespace KiTrack {
14 class IHit;
15 };
16 
17 namespace genfit {
18  class Track;
19  class GFRaveVertex;
20 }
21 
22 class ForwardTracker;
23 class ForwardTrackMaker;
24 class FwdDataSource;
25 class FwdHit;
26 class StarFieldAdaptor;
27 
28 class StGlobalTrack;
29 class StRnDHitCollection;
30 class StTrack;
32 class SiRasterizer;
33 class McTrack;
34 
35 // ROOT includes
36 #include "TNtuple.h"
37 #include "TTree.h"
38 // STL includes
39 #include <vector>
40 #include <memory>
41 
42 
43 // 877-369-6347
44 class StFwdTrack;
45 class GenfitTrackResult;
46 
47 
48 
49 const size_t MAX_TREE_ELEMENTS = 4000;
50 struct FwdTreeData {
51 
52  // hits;
53  int fttN;
54  vector<float> fttX, fttY, fttZ;
55  vector<int> fttVolumeId;
56  // Only avalaible for hits if MC
57  vector<float> fttPt;
58  vector<int> fttTrackId, fttVertexId;
59 
60  // hits;
61  int fstN;
62  vector<float> fstX, fstY, fstZ;
63  vector<int> fstTrackId;
64 
65  int fcsN;
66  vector<float> fcsX, fcsY, fcsZ;
67  vector<int> fcsDet;
68 
69  // RC tracks
70  int rcN;
71  vector<float> rcPt, rcEta, rcPhi, rcQuality;
72  vector<int> rcTrackId, rcNumFST, rcCharge, rcNumFTT, rcNumPV;
73 
74  // MC Tracks
75  int mcN;
76  vector<float> mcPt, mcEta, mcPhi;
77  vector<int> mcVertexId, mcCharge;
78 
79  // MC Level vertex info
80  // maybe use also for TPC vertex if available in data
81  int vmcN;
82  vector<float> vmcX, vmcY, vmcZ;
83 
84  int tprojN;
85  vector<float> tprojX, tprojY, tprojZ;
86  vector<float> tprojPx, tprojPy, tprojPz;
87  vector<int> tprojIdD, tprojIdT;
88 
89  // RAVE reco vertices
90  int vrcN;
91  vector<float> vrcX, vrcY, vrcZ;
92 
93  int thdN;
94  vector<float> thdX, thdY, thaX, thaY, thaZ;
95 
96  bool saveCrit = false;
97  std::map<string, std::vector<float>> Crits;
98  std::map<string, std::vector<int>> CritTrackIds;
99 
100 };
101 
102 class StFwdTrackMaker : public StMaker {
103 
104  ClassDef(StFwdTrackMaker, 0);
105 
106  public:
107  StFwdTrackMaker();
108  ~StFwdTrackMaker(){/* nada */};
109 
110  int Init();
111  int Finish();
112  int Make();
113  void Clear(const Option_t *opts = "");
114 
115  enum { kInnerGeometry,
116  kOuterGeometry };
117 
118  void SetConfigFile(std::string n) {
119  mConfigFile = n;
120  LoadConfiguration();
121  }
122  void LoadConfiguration();
123  void SetGenerateHistograms( bool _genHisto ){ mGenHistograms = _genHisto; }
124  void SetGenerateTree(bool _genTree) { mGenTree = _genTree; }
125  void SetVisualize( bool _viz ) { mVisualize = _viz; }
126 
127  vector<StFwdTrack*> mFwdTracks;
128 
129  private:
130  protected:
131 
132  // Track Seed typdef
133  typedef std::vector<KiTrack::IHit *> Seed_t;
134 
135 
136  // for Wavefront OBJ export
137  size_t eventIndex = 0;
138 
139 
140  bool mGenHistograms = false;
141  bool mGenTree = false;
142  std::string mConfigFile;
143 
144 
145  std::map<std::string, TH1 *> mHistograms;
146  TFile *mTreeFile = nullptr;
147  TTree *mTree = nullptr;
148  FwdTreeData mTreeData;
149 
150  bool mVisualize = false;
151  vector<TVector3> mFttHits;
152  vector<TVector3> mFstHits;
153  vector<TVector3> mFcsClusters;
154  vector<float> mFcsClusterEnergy;
155  vector<TVector3> mFcsPreHits;
156 
157  std::vector< genfit::GFRaveVertex * > mRaveVertices;
158 
159  void ProcessFwdTracks();
160  void FillEvent();
161  void FillTrackDeltas();
162 
163  StFwdTrack * makeStFwdTrack( GenfitTrackResult &gtr, size_t indexTrack );
164 
165  // I could not get the library generation to succeed with these.
166  // so I have removed them
167  #ifndef __CINT__
168  std::shared_ptr<SiRasterizer> mSiRasterizer;
169  FwdTrackerConfig mFwdConfig;
170  std::shared_ptr<ForwardTracker> mForwardTracker;
171  std::shared_ptr<FwdDataSource> mForwardData;
172 
173  size_t loadMcTracks( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap );
174  void loadFcs();
175  void loadFttHits( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
176  void loadFttHitsFromStEvent( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
177  void loadFttHitsFromGEANT( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
178 
179  void loadFstHits( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
180  void loadFstHitsFromGEANT( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
181  void loadFstHitsFromStEvent( std::map<int, std::shared_ptr<McTrack>> &mcTrackMap, std::map<int, std::vector<KiTrack::IHit *>> &hitMap, int count = 0 );
182  #endif
183 
184  void FillTTree(); // if debugging ttree is turned on (mGenTree)
185  void FitVertex();
186 
187  static std::string defaultConfigIdealSim;
188  static std::string defaultConfigData;
189  std::string defaultConfig;
190  bool configLoaded = false;
191 
192  // Helper functions for modifying configuration
193  // NOTE: to override configuration, call individual functions after setConfigForXXX
194  public:
199  void setConfigForData() { defaultConfig = defaultConfigData; LoadConfiguration(); }
208  void setConfigForIdealSim() { defaultConfig = defaultConfigIdealSim; LoadConfiguration(); }
209 
216  defaultConfig = defaultConfigData;
217  LoadConfiguration();
218  // Note: Once the slow sims work this override will not be needed
219  // because the slow sims will put hits into StEvent just like (data) reco chain
220  setFttHitSource( "GEANT" );
221  }
222 
223 
227  void setOutputFilename( std::string fn ) { mFwdConfig.set( "Output:url", fn ); }
232  void setFttHitSource( std::string source ) { mFwdConfig.set( "Source:ftt", source ); }
233 
237  void setUseFstRasteredGeantHits( bool use = true ){ mFwdConfig.set<bool>( "SiRasterizer:active", use ); }
242  void setFstRasterR( double r = 3.0 /*cm*/ ){ mFwdConfig.set<double>( "SiRasterizer:r", r ); }
247  void setFstRasterPhi( double phi = 0.00409 /*2*pi/(12*128)*/ ){ mFwdConfig.set<double>( "SiRasterizer:phi", phi ); }
248 
249  //Track Finding
253  void setSeedFindingWithFtt() { mFwdConfig.set( "TrackFinder:source", "ftt" ); }
257  void setSeedFindingWithFst() { mFwdConfig.set( "TrackFinder:source", "fst" ); }
261  void setSeedFindingNumInterations( int n = 1 ) { mFwdConfig.set<int>("TrackFinder:nIterations", n); }
265  void setSeedFindingNumPhiSlices( int n = 8 ) { mFwdConfig.set<int>("TrackFinder.Iteration:nPhiSlices", n); }
269  void setSeedFindingConnectorDistance( int d = 1 ) { mFwdConfig.set<int>( "TrackFinder.Connector:distance", d ); }
274  void setSeedFindingUseSubsetNN( bool use = true ) { mFwdConfig.set<bool>( "TrackFinder.SubsetNN:active", use ); }
278  void setSeedFindingMinHitsOnTrack( int n = 3 ) { mFwdConfig.set<int>( "TrackFinder.SubsetNN:min-hits-on-track", n ); }
283  void setSeedFindingUseHitRemover( bool use = true ) { mFwdConfig.set<bool>( "TrackFinder.HitRemover:active", use ); }
288  void setUseTruthSeedFinding( bool use = true ) { mFwdConfig.set<bool>( "TrackFinder:active", !use ); }
289 
290  // Track Fitting
294  void setTrackFittingOff() { mFwdConfig.set( "TrackFitter:active", "false" ); }
298  void setFittingMaterialEffects( bool mat = true) { mFwdConfig.set<bool>( "TrackFitter:materialEffects", mat ); }
302  void setPrimaryVertexSigmaXY( double sXY ) { mFwdConfig.set<double>( "TrackFitter.Vertex:sigmaXY", sXY ); }
306  void setPrimaryVertexSigmaZ( double sZ ) { mFwdConfig.set<double>( "TrackFitter.Vertex:sigmaZ", sZ ); }
307  // TODO: add options for beamline constraint
308 
312  void setIncludePrimaryVertexInFit( bool pvf = true ) { mFwdConfig.set<bool>( "TrackFitter.Vertex:includeInFit", pvf ); }
316  void setZeroB( bool zeroB = true ) { mFwdConfig.set<bool>( "TrackFitter:zeroB", zeroB ); }
320  void setConstB( bool constB = true ) { mFwdConfig.set<bool>( "TrackFitter:constB", constB ); }
324  void setUseMcSeedForFit( bool mcSeed = true ) { mFwdConfig.set<bool>( "TrackFitter:mcSeed", mcSeed ); }
325 
332  void setTrackRefit( bool refit = true) { mFwdConfig.set<bool>( "TrackFitter:refit", refit ); }
333 
337  void setMaxFailedHitsInFit( int n = -1 /*no lim*/ ) {mFwdConfig.set<int>("TrackFitter.KalmanFitterRefTrack:MaxFailedHits", n);}
341  void setFitDebugLvl( int level = 0 /*0=no output*/ ) {mFwdConfig.set<int>("TrackFitter.KalmanFitterRefTrack:DebugLvl", level); }
345  void setFitMaxIterations( int n=4 ) {mFwdConfig.set<int>("TrackFitter.KalmanFitterRefTrack:MaxIterations", n); }
349  void setFitMinIterations( int n = 1) {mFwdConfig.set<int>("TrackFitter.KalmanFitterRefTrack:MinIterations", n); }
350 
354  void setSmearMcPrimaryVertex( bool pvs = true ) { mFwdConfig.set<bool>( "TrackFitter.Vertex:smearMcVertex", pvs ); }
355 
356 };
357 
358 #endif
void setConfigForIdealSim()
Setup the StFwdTrackMaker for running on Data Load the default configuration for IDEAL simulation...
void setConfigForData()
Setup the StFwdTrackMaker for running on Data Load the default configuration for Data. Note: Apply any overrides after calling this.
void setSmearMcPrimaryVertex(bool pvs=true)
Enables smearing of the MC Primary Vertex according to sigmaXY,Z.
void setZeroB(bool zeroB=true)
Set B-field to zero (for zero field running)
void setPrimaryVertexSigmaZ(double sZ)
Set the resolution for the Primary Vertex in Z sZ : sigma in Z (cm)
void setSeedFindingUseHitRemover(bool use=true)
Enable or disable the HitRemover.
void setConfigForRealisticSim()
Setup the StFwdTrackMaker for running on Data Load the default configuration for Realistic simulation...
void setFittingMaterialEffects(bool mat=true)
Enable / disable material effects Material effects in kalman filter.
void setIncludePrimaryVertexInFit(bool pvf=true)
Include or exclude the Primary Vertex in fit.
Definition: FwdHit.h:68
void setFttHitSource(std::string source)
Set the data source for FTT hits.
void setUseMcSeedForFit(bool mcSeed=true)
Force the use of McSeed for fit.
void setMaxFailedHitsInFit(int n=-1)
Sets the maximum number of hits that can be considered failed before the entire track fit fails...
void setSeedFindingConnectorDistance(int d=1)
Set the connector distance for track finding.
void setUseFstRasteredGeantHits(bool use=true)
Enable or disable the Fst Rasterizer.
void setSeedFindingUseSubsetNN(bool use=true)
Enable or disable the SubsetNN.
void setConstB(bool constB=true)
Set B-field to constant (even outside of TPC)
void setTrackFittingOff()
Turn off track fitting Useful if you want to speed up the run but dont need fitting (testing seed fin...
Definition: FwdHit.h:35
void setSeedFindingWithFtt()
Use Ftt hits in the Seed Finding.
void set(std::string path, T v)
Writes a value of type T to the map Uses convertTo&lt;T&gt; to convert type T to a string rep...
void setSeedFindingNumInterations(int n=1)
Set the number of track finding iterations.
void setFstRasterPhi(double phi=0.00409)
Set the resolution in phi for rasterizing FST hits (from fast sim) Only used when the Rasterizer is e...
void setFitMaxIterations(int n=4)
Sets Max fit iterations before failing.
void setFstRasterR(double r=3.0)
Set the resolution in R for rasterizing FST hits (from fast sim) Only used when the Rasterizer is ena...
void setSeedFindingMinHitsOnTrack(int n=3)
Enable or disable the SubsetNN.
void setUseTruthSeedFinding(bool use=true)
Enable or disable the Truth Seed finding.
void setOutputFilename(std::string fn)
Set the filename for output ROOT file.
void setFitDebugLvl(int level=0)
Sets Fitter debug level.
void setTrackRefit(bool refit=true)
Sets the tracking to refit This adds compatible hits from whichever detector was NOT used in seed fin...
void setSeedFindingNumPhiSlices(int n=8)
Set the number of phi slices to split the track iterations into.
void setFitMinIterations(int n=1)
Sets Min fit iterations before converging.
void setPrimaryVertexSigmaXY(double sXY)
Set the resolution for the Primary Vertex in XY sXY : sigma in XY (cm)
C++ STL includes.
Definition: AgUStep.h:47
void setSeedFindingWithFst()
Use Fst hits in the Seed Finding.