MarlinTrkProcessors  2.4.1
CellsAutomatonMV.h
1 #ifndef CellsAutomatonMV_h
2 #define CellsAutomatonMV_h 1
3 
4 #include <algorithm>
5 #include "Math/ProbFunc.h"
6 
7 #include <marlin/Processor.h>
8 #include <marlin/Global.h>
9 #include "marlin/VerbosityLevels.h"
10 #include <marlin/Exceptions.h>
11 
12 #include <EVENT/LCCollection.h>
13 #include <EVENT/TrackerHit.h>
14 #include <EVENT/TrackerHitPlane.h>
15 #include <IMPL/TrackerHitImpl.h>
16 #include <EVENT/TrackerHitZCylinder.h>
17 #include <IMPL/LCCollectionVec.h>
18 #include <IMPL/TrackImpl.h>
19 #include <IMPL/TrackerHitPlaneImpl.h>
20 #include <UTIL/BitField64.h>
21 #include <UTIL/ILDConf.h>
22 
23 // KiTrack tools
24 #include "KiTrack/SubsetHopfieldNN.h"
25 #include "KiTrack/SubsetSimple.h"
26 #include "KiTrack/SegmentBuilder.h"
27 #include "KiTrack/Automaton.h"
28 #include "KiTrack/Segment.h"
29 
30 // KiTrackMarlin toools
31 #include "ILDImpl/VXDTrack.h"
32 #include "ILDImpl/VXDHit01.h"
33 #include "ILDImpl/VXDSectorConnector.h"
34 #include "Tools/KiTrackMarlinTools.h"
35 #include "Tools/KiTrackMarlinCEDTools.h"
36 #include "KiTrack/ITrack.h"
37 #include "Criteria/Criteria.h"
38 #include "ILDImpl/SectorSystemVXD.h"
39 #include "Tools/VXDHelixFitter.h"
40 #include "ILDImpl/MiniVectorHit01.h"
41 
42 // IMarlin tools
43 #include "MarlinTrk/IMarlinTrkSystem.h"
44 #include "MarlinTrk/IMarlinTrack.h"
45 #include "MarlinTrk/Factory.h"
46 #include "MarlinTrk/MarlinTrkUtils.h"
47 
48 // GEAR tools
49 #include <gear/GEAR.h>
50 #include <gear/GearParameters.h>
51 #include <gear/VXDLayerLayout.h>
52 #include <gear/VXDParameters.h>
53 #include <gear/BField.h>
54 #include "gear/gearsurf/MeasurementSurfaceStore.h"
55 #include "gear/gearsurf/MeasurementSurface.h"
56 #include "gear/gearsurf/ICoordinateSystem.h"
57 #include "gear/gearsurf/CartesianCoordinateSystem.h"
58 
59 //#include "SpacePointBuilder.h"
60 // CLHEP tools
61 #include "CLHEP/Vector/ThreeVector.h"
62 #include "CLHEP/Matrix/SymMatrix.h"
63 #include "CLHEP/Matrix/Matrix.h"
64 
65 
66 using namespace lcio ;
67 using namespace marlin ;
68 using namespace std ;
69 using namespace gear ;
70 using namespace KiTrack;
71 using namespace KiTrackMarlin;
72 namespace MarlinTrk{
73  class IMarlinTrkSystem ;
74 }
75 
76 namespace gear{
77 class GearMgr ;
78 }
81 typedef std::vector< IHit* > RawTrack;
82 
83 class CellsAutomatonMV : public Processor {
84 
85  public:
86 
87  virtual Processor* newProcessor() { return new CellsAutomatonMV ; }
88 
89 
91 
95  virtual void init();
96 
99  virtual void processRunHeader( LCRunHeader* run ) ;
100 
103  virtual void processEvent( LCEvent * evt ) ;
104 
105 
106  virtual void check( LCEvent * evt ) ;
107 
108 
111  virtual void end() ;
112 
113  /*
114  private:
115 
116  unsigned _nOutOfBoundary;
117  unsigned _nStripsTooParallel;
118  unsigned _nPlanesNotParallel;
119 
120  // functions copied from spacepointbuilder
121  static int calculatePointBetweenTwoLines_UsingVertex(
122  const CLHEP::Hep3Vector& PA,
123  const CLHEP::Hep3Vector& PB,
124  const CLHEP::Hep3Vector& PC,
125  const CLHEP::Hep3Vector& PD,
126  const CLHEP::Hep3Vector& Vertex,
127  CLHEP::Hep3Vector& point);
128 
129 
130  // @return a spacepoint (in the form of a TrackerHitImpl* ) created from two TrackerHitPlane* which stand for si-strips
131  TrackerHitImpl* createSpacePoint( TrackerHitPlane* a , TrackerHitPlane* b, double stripLength );
132 */
133 
134  protected:
135 
136  int nEvt;
137 
138  int _nDivisionsInPhi;
139  int _nDivisionsInTheta;
140  int _nDivisionsInPhiMV;
141  int _nDivisionsInThetaMV;
142  int _nLayers;
143 
144  float _bField;
145 
146  // two pi is not a constant in cmath. Calculate it, once!
147  static const double TWOPI;
148  double _dPhi;
149  double _dTheta;
150 
151  UTIL::BitField64* _encoder;
152  int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::subdet]; }
153  int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::side]; };
154  int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::layer]; };
155  int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::module]; };
156  int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::sensor]; };
157 
158 
159  void InitialiseVTX(LCEvent * evt, EVENT::TrackerHitVec HitsTemp);
160  void setupGearGeom( const gear::GearMgr* gearMgr ) ;
161  bool setCriteria( unsigned round );
162  void RawTrackFit( std::vector < MarlinTrk::IMarlinTrack* > candMarlinTracks, std::vector< IMPL::TrackImpl* > &finalTracks ) ;
163  void FitFunc2( std::vector < RawTrack > rawTracks, std::vector < MarlinTrk::IMarlinTrack* > &candMarlinTracks ) ;
164  void finaliseTrack( TrackImpl* newTrackImpl, LCCollectionVec* trackVec ) ;
165  //void finaliseTrack( TrackImpl* trackImpl, LCCollectionVec* trackVec, const EVENT::TrackState * init_ts, const EVENT::FloatVec covMatrix ) ;
166  void CreateMiniVectors( int sector ) ;
167  bool thetaAgreement( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ;
168  bool thetaAgreementImproved( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit, int layer ) ;
169  double Dist( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ;
170  //IMPL::TrackImpl* Refit( TrackImpl* track_to_refit ) ;
171 
172 
173  unsigned int _nLayersVTX;
174  unsigned int _nLayersSIT;
175 
177  std::map< int , EVENT::TrackerHitVec > _map_sector_spacepoints;
178  std::map< int , std::vector< IHit* > > _map_sector_hits;
179  std::map< int , EVENT::TrackerHit* > _map_1dhits_spacepoints ;
180 
182  std::pair <EVENT::TrackerHit*, EVENT::TrackerHit* > _pairs_1dhits_spacepoints ;
183 
185  std::vector< std::string > _criteriaNames;
186 
188  std::map< std::string , std::vector<float> > _critMinima;
189 
191  std::map< std::string , std::vector<float> > _critMaxima;
192 
195 
197  std::vector <ICriterion*> _crit2Vec;
198 
200  std::vector <ICriterion*> _crit3Vec;
201 
203  std::vector <ICriterion*> _crit4Vec;
204 
205  std::vector< IHit* > MiniVectorsTemp;
206  std::vector< IHit* > TestMiniVectorsTemp;
207 
209  double _chi2ProbCut;
210 
211  double _helixFitMax ;
212 
213  double _chi2OverNdfCut ;
214 
215  const SectorSystemVXD * _sectorSystemVXD;
216 
220 
223  MarlinTrk::IMarlinTrkSystem* _trkSystem;
224  std::string _trkSystemName ;
225 
226  bool _MSOn, _ElossOn, _SmoothOn, _middleLayer ;
227 
228  int _useSIT ;
229  int _ipHit ;
230 
231  int _layerStepMax ;
232 
233  int _lastLayerToIP ;
234 
235  int _neighPhi ;
236  int _neighTheta ;
237  int _layerMax ;
238 
239  int _nHitsChi2 ;
240 
241  int MiniVectors_sectors ;
242  int MiniVectors_CutSelection ;
243 
244  FloatVec _resU ;
245 
246  double _maxDist ;
247  double _hitPairThDiff ;
248  double _hitPairThDiffInner ;
249  double _hitPairThDiffSIT ;
250 
251  //std::vector< MarlinTrk::IMarlinTrack* > GoodTracks;
252  //std::vector< MarlinTrk::IMarlinTrack* > RejectedTracks;
253 
254 
255 
256  float _initialTrackError_d0;
257  float _initialTrackError_phi0;
258  float _initialTrackError_omega;
259  float _initialTrackError_z0;
260  float _initialTrackError_tanL;
261  float _maxChi2PerHit;
262 
263  int _initialTrackState;
264  int _fitDirection ;
265 
266  int _maxHitsPerSector ;
267 
270  std::string _VTXHitCollection;
271  std::string _SITHitCollection;
272  std::string _CATrackCollection;
273 
274  std::map< LCCollection*, std::string > _colNamesTrackerHits;
275 
276  std::string _bestSubsetFinder;
277 
280 
281  static const int _output_track_col_quality_GOOD;
282  static const int _output_track_col_quality_FAIR;
283  static const int _output_track_col_quality_POOR;
284 
285 
286 } ;
287 
288 
289 
290 //****************************************************************************************************
291 // Quality - compatibility for ITrack version
292 
293 
296 
297 public:
298 
299  inline bool operator()( ITrack* trackA, ITrack* trackB ){
300 
301 
302  std::vector< IHit* > hitsA = trackA->getHits();
303  std::vector< IHit* > hitsB = trackB->getHits();
304 
305  for( unsigned i=0; i < hitsA.size(); i++){
306 
307  for( unsigned j=0; j < hitsB.size(); j++){
308 
309  if ( hitsA[i] == hitsB[j] ) return false; // a hit is shared -> incompatible
310 
311  }
312 
313  }
314 
315  return true;
316 
317  }
318 
319 };
320 
321 
324 
325 public:
326 
327  inline double operator()( ITrack* track ){ return track->getChi2Prob(); }
328 
329 
330 };
331 
335 class TrackQI{
336 
337 public:
338 
339  inline double operator()( ITrack* track ){
340 
341  float NoOfHits = 4.0*( track->getHits().size());
342 
343  return (1.0*NoOfHits)/(track->getChi2()/track->getNdf()); }
344 
345 
346 };
347 
348 
351 class MaxHits{
352 
353 public:
354 
355  inline double operator()( ITrack* track ){
356 
357  return track->getHits().size();
358  }
359 
360 };
361 
362 
371 
372 public:
373 
374  inline double operator()( ITrack* track ){
375 
376  if( track->getHits().size() > 2 ){
377 
378  return track->getChi2Prob()/2. +0.5;
379 
380  }
381  else{
382 
383  return 1/( log( 7.3890561 + track->getChi2() ) ); //e^2 = 7.3890561
384 
385  }
386 
387  }
388 
389 
390 };
391 
392 
393 
394 #endif
std::vector< ICriterion * > _crit4Vec
A vector of criteria for 4 hits (2 3-hit segments)
Definition: CellsAutomatonMV.h:203
std::vector< ICriterion * > _crit2Vec
A vector of criteria for 2 hits (2 1-hit segments)
Definition: CellsAutomatonMV.h:197
Definition: CellsAutomatonMV.h:83
std::map< std::string, std::vector< float > > _critMinima
Map containing the name of a criterion and a vector of the minimum cut offs for it.
Definition: CellsAutomatonMV.h:188
std::pair< EVENT::TrackerHit *, EVENT::TrackerHit * > _pairs_1dhits_spacepoints
A pair to keep information for composite spacepoints.
Definition: CellsAutomatonMV.h:182
int _hitsPerTrackMin
Minimum number of hits a track has to have in order to be stored.
Definition: CellsAutomatonMV.h:194
std::vector< ICriterion * > _crit3Vec
A vector of criteria for 3 hits (2 2-hit segments)
Definition: CellsAutomatonMV.h:200
A functor to return the quality of a track, which is the number of associated hits.
Definition: CellsAutomatonMV.h:351
std::vector< std::string > _criteriaNames
Names of the used criteria.
Definition: CellsAutomatonMV.h:185
A functor to return the quality of a track, which is the ratio chi2 over degrees of freedom...
Definition: CellsAutomatonMV.h:335
std::string _VTXHitCollection
Input collection name.
Definition: CellsAutomatonMV.h:270
A functor to return the quality of a track.
Definition: CellsAutomatonMV.h:370
A functor to return the quality of a track, which is currently the chi2 probability.
Definition: CellsAutomatonMV.h:323
std::map< int, EVENT::TrackerHitVec > _map_sector_spacepoints
A map to store the hits according to their sectors.
Definition: CellsAutomatonMV.h:177
int _output_track_col_quality
The quality of the output track collection.
Definition: CellsAutomatonMV.h:279
MarlinTrk::IMarlinTrkSystem * _trkSystem
pointer to the IMarlinTrkSystem instance
Definition: CellsAutomatonMV.h:223
int _maxConnectionsAutomaton
the maximum number of connections that are allowed in the automaton, if this value is surpassed...
Definition: CellsAutomatonMV.h:219
double _chi2ProbCut
Cut for the Kalman Fit (the chi squared probability)
Definition: CellsAutomatonMV.h:209
A functor to return whether two tracks are compatible: The criterion is if they share a MiniVector or...
Definition: CellsAutomatonMV.h:295
std::map< std::string, std::vector< float > > _critMaxima
Map containing the name of a criterion and a vector of the maximum cut offs for it.
Definition: CellsAutomatonMV.h:191