MarlinTrkProcessors  2.4.1
DDCellsAutomatonMV.h
1 #ifndef DDCellsAutomatonMV_h
2 #define DDCellsAutomatonMV_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 
11 #include <EVENT/LCCollection.h>
12 #include <EVENT/TrackerHit.h>
13 #include <EVENT/TrackerHitPlane.h>
14 #include <EVENT/TrackerHitZCylinder.h>
15 #include <IMPL/LCCollectionVec.h>
16 #include <IMPL/TrackImpl.h>
17 #include <IMPL/TrackerHitPlaneImpl.h>
18 #include <UTIL/BitField64.h>
19 /* #include <UTIL/ILDConf.h> */
20 
21 // KiTrack tools
22 #include "KiTrack/SubsetHopfieldNN.h"
23 #include "KiTrack/SubsetSimple.h"
24 #include "KiTrack/SegmentBuilder.h"
25 #include "KiTrack/Automaton.h"
26 #include "KiTrack/Segment.h"
27 
28 // KiTrackMarlin toools
29 #include "ILDImpl/VXDTrack.h"
30 #include "ILDImpl/VXDHit01.h"
31 #include "ILDImpl/VXDSectorConnector.h"
32 #include "Tools/KiTrackMarlinTools.h"
33 #include "Tools/KiTrackMarlinCEDTools.h"
34 #include "KiTrack/ITrack.h"
35 #include "Criteria/Criteria.h"
36 #include "ILDImpl/SectorSystemVXD.h"
37 #include "Tools/VXDHelixFitter.h"
38 #include "ILDImpl/MiniVectorHit01.h"
39 
40 
41 
42 
43 
44 // IMarlin tools
45 #include "MarlinTrk/IMarlinTrkSystem.h"
46 #include "MarlinTrk/IMarlinTrack.h"
47 /* #include "MarlinTrk/Factory.h" */
48 #include "MarlinTrk/MarlinTrkUtils.h"
49 
50 
51 //DD4HEP
52 /* #include "DDRec/Surface.h" */
53 /* #include "DD4hep/LCDD.h" */
54 /* #include "DD4hep/DD4hepUnits.h" */
55 /* #include "DDRec/SurfaceManager.h" */
56 
57 
58 
60 
61 #include "EVENT/Track.h"
62 #include "EVENT/TrackerHit.h"
63 #include "lcio.h"
64 
65 
66 
67 using namespace lcio;
68 
69 using namespace lcio ;
70 using namespace marlin ;
71 using namespace std ;
72 using namespace KiTrack;
73 using namespace KiTrackMarlin;
74 namespace MarlinTrk{
75  class IMarlinTrkSystem ;
76 }
77 
80 typedef std::vector< IHit* > RawTrack;
81 
82 class DDCellsAutomatonMV : public Processor {
83 
84  public:
85 
86  virtual Processor* newProcessor() { return new DDCellsAutomatonMV ; }
87 
88 
90 
94  virtual void init();
95 
98  virtual void processRunHeader( LCRunHeader* run ) ;
99 
102  virtual void processEvent( LCEvent * evt ) ;
103 
104 
105  virtual void check( LCEvent * evt ) ;
106 
107 
110  virtual void end() ;
111 
112 
113 
114 
115  protected:
116 
117  int nEvt;
118 
119  int _nDivisionsInPhi;
120  int _nDivisionsInTheta;
121  int _nDivisionsInPhiMV;
122  int _nDivisionsInThetaMV;
123  int _nLayers;
124 
125  float _bField;
126 
127  // two pi is not a constant in cmath. Calculate it, once!
128  static const double TWOPI;
129  double _dPhi;
130  double _dTheta;
131 
132  UTIL::BitField64* _encoder;
133  int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::subdet]; }
134  int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::side]; };
135  int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::layer]; };
136  int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::module]; };
137  int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::ILDCellID0::sensor]; };
138 
139 
140  void InitialiseVTX(LCEvent * evt, EVENT::TrackerHitVec HitsTemp);
141  void setupGeom() ;
142  bool setCriteria( unsigned round );
143  void RawTrackFit( std::vector < MarlinTrk::IMarlinTrack* > candMarlinTracks, std::vector< IMPL::TrackImpl* > &finalTracks ) ;
144  void FitFunc2( std::vector < RawTrack > rawTracks, std::vector < MarlinTrk::IMarlinTrack* > &candMarlinTracks ) ;
145  void finaliseTrack( TrackImpl* trackImpl ) ;
146  void CreateMiniVectors( int sector ) ;
147  bool thetaAgreement( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ;
148  bool thetaAgreementImproved( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit, int layer ) ;
149  double Dist( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ;
150 
151  unsigned int _nLayersVTX;
152  unsigned int _nLayersSIT;
153 
155  std::map< int , EVENT::TrackerHitVec > _map_sector_spacepoints;
156  std::map< int , std::vector< IHit* > > _map_sector_hits;
157 
159  std::vector< std::string > _criteriaNames;
160 
162  std::map< std::string , std::vector<float> > _critMinima;
163 
165  std::map< std::string , std::vector<float> > _critMaxima;
166 
169 
171  std::vector <ICriterion*> _crit2Vec;
172 
174  std::vector <ICriterion*> _crit3Vec;
175 
177  std::vector <ICriterion*> _crit4Vec;
178 
179  std::vector< IHit* > MiniVectorsTemp;
180  std::vector< IHit* > TestMiniVectorsTemp;
181 
183  double _chi2ProbCut;
184 
185  double _helixFitMax ;
186 
187  double _chi2OverNdfCut ;
188 
189  const SectorSystemVXD * _sectorSystemVXD;
190 
194 
195  MarlinTrk::IMarlinTrkSystem* _trkSystem;
196 
197  bool _MSOn, _ElossOn, _SmoothOn, _middleLayer ;
198 
199  int _useSIT ;
200 
201  int _layerStepMax ;
202 
203  int _lastLayerToIP ;
204 
205  int _nHitsChi2 ;
206 
207  int MiniVectors_sectors ;
208  int MiniVectors_CutSelection ;
209 
210  FloatVec _resU ;
211 
212  double _maxDist ;
213  double _hitPairThDiff ;
214  double _hitPairThDiffInner ;
215 
216  //std::vector< MarlinTrk::IMarlinTrack* > GoodTracks;
217  //std::vector< MarlinTrk::IMarlinTrack* > RejectedTracks;
218 
219 
220 
221  float _initialTrackError_d0;
222  float _initialTrackError_phi0;
223  float _initialTrackError_omega;
224  float _initialTrackError_z0;
225  float _initialTrackError_tanL;
226  float _maxChi2PerHit;
227 
228  int _maxHitsPerSector ;
229 
232  std::string _VTXHitCollection;
233  std::string _SITHitCollection;
234  std::string _CATrackCollection;
235 
236  std::string _detElVXDName;
237  std::string _detElITName;
238  std::string _detElOTName;
239 
240 
241  std::map< LCCollection*, std::string > _colNamesTrackerHits;
242 
243  std::string _bestSubsetFinder;
244 
247 
248  static const int _output_track_col_quality_GOOD;
249  static const int _output_track_col_quality_FAIR;
250  static const int _output_track_col_quality_POOR;
251 
252 
253 } ;
254 
255 
256 
257 //****************************************************************************************************
258 // Quality - compatibility for ITrack version
259 
260 
263 
264 public:
265 
266  inline bool operator()( ITrack* trackA, ITrack* trackB ){
267 
268 
269  std::vector< IHit* > hitsA = trackA->getHits();
270  std::vector< IHit* > hitsB = trackB->getHits();
271 
272  for( unsigned i=0; i < hitsA.size(); i++){
273 
274  for( unsigned j=0; j < hitsB.size(); j++){
275 
276  if ( hitsA[i] == hitsB[j] ) return false; // a hit is shared -> incompatible
277 
278  }
279 
280  }
281 
282  return true;
283 
284  }
285 
286 };
287 
288 
290 class TrackQIChi2Prob_MV{
291 
292 public:
293 
294  inline double operator()( ITrack* track ){ return track->getChi2Prob(); }
295 
296 
297 };
298 
302 class TrackQI{
303 
304 public:
305 
306  inline double operator()( ITrack* track ){
307 
308  float NoOfHits = 4.0*( track->getHits().size());
309 
310  return (1.0*NoOfHits)/(track->getChi2()/track->getNdf()); }
311 
312 
313 };
314 
315 
316 
317 
318 
319 
322 class MaxHits{
323 
324 public:
325 
326  inline double operator()( ITrack* track ){
327 
328  return track->getHits().size();
329  }
330 
331 };
332 
333 
334 
337 class Test{
338 
339 public:
340 
341  inline double operator()( ITrack* track ){
342 
343  //std::cout<< " ----- track version with nhits = " << track->getHits().size() <<std::endl;
344 
345  if( track->getHits().size() > 2 ){
346 
347  //std::cout<< " -------- getChi2Prob() = " << track->getChi2Prob() <<std::endl;
348  //std::cout<< " -------- track->getChi2Prob()/2. +0.5 = " << track->getChi2Prob()/2. +0.5 <<std::endl;
349  return track->getChi2Prob()/2. +0.5;
350 
351  }
352  else{
353 
354  //std::cout<< " -------- getChi2() = " << track->getChi2() <<std::endl;
355  //std::cout<< " -------- 1/( log( 7.3890561 + track->getChi2() ) ) = " << 1/( log( 7.3890561 + track->getChi2() ) ) <<std::endl;
356  return 1/( log( 7.3890561 + track->getChi2() ) ); //e^2 = 7.3890561
357 
358  }
359 
360  }
361 
362 };
363 
364 
365 
373 class TrackQISpecial_MV{
374 
375 public:
376 
377  inline double operator()( ITrack* track ){
378 
379  if( track->getHits().size() > 3 ){
380 
381  return track->getChi2Prob()/2. +0.5;
382 
383  }
384  else{
385 
386  return 1/( log( 7.3890561 + track->getChi2() ) ); //e^2 = 7.3890561
387 
388  }
389 
390  }
391 
392 
393 };
394 
395 
396 #endif
int _maxConnectionsAutomaton
the maximum number of connections that are allowed in the automaton, if this value is surpassed...
Definition: DDCellsAutomatonMV.h:193
std::map< int, EVENT::TrackerHitVec > _map_sector_spacepoints
A map to store the hits according to their sectors.
Definition: DDCellsAutomatonMV.h:155
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: DDCellsAutomatonMV.h:162
A functor to return the ....
Definition: DDCellsAutomatonMV.h:337
A functor to return the quality of a track, which is the number of associated hits.
Definition: CellsAutomatonMV.h:351
std::vector< ICriterion * > _crit3Vec
A vector of criteria for 3 hits (2 2-hit segments)
Definition: DDCellsAutomatonMV.h:174
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: DDCellsAutomatonMV.h:165
double _chi2ProbCut
Cut for the Kalman Fit (the chi squared probability)
Definition: DDCellsAutomatonMV.h:183
std::string _VTXHitCollection
Input collection name.
Definition: DDCellsAutomatonMV.h:232
A functor to return the quality of a track, which is the ratio chi2 over degrees of freedom...
Definition: CellsAutomatonMV.h:335
A functor to return the quality of a track.
Definition: CellsAutomatonMV.h:370
std::vector< ICriterion * > _crit2Vec
A vector of criteria for 2 hits (2 1-hit segments)
Definition: DDCellsAutomatonMV.h:171
Definition: DDCellsAutomatonMV.h:82
A functor to return the quality of a track, which is currently the chi2 probability.
Definition: CellsAutomatonMV.h:323
std::vector< ICriterion * > _crit4Vec
A vector of criteria for 4 hits (2 3-hit segments)
Definition: DDCellsAutomatonMV.h:177
int _hitsPerTrackMin
Minimum number of hits a track has to have in order to be stored.
Definition: DDCellsAutomatonMV.h:168
std::vector< std::string > _criteriaNames
Names of the used criteria.
Definition: DDCellsAutomatonMV.h:159
A functor to return whether two tracks are compatible: The criterion is if they share a MiniVector or...
Definition: CellsAutomatonMV.h:295
int _output_track_col_quality
The quality of the output track collection.
Definition: DDCellsAutomatonMV.h:246