ROOT logo
#ifndef ROOT_TreeSearch_MWDC
#define ROOT_TreeSearch_MWDC

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// TreeSearch::MWDC                                                          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "THaTrackingDetector.h"
#include "THaDetMap.h"
#include "Types.h"
#include "TMatrixDSym.h"
#include <vector>
#include <utility>
#include <set>
#include <list>
#include <cassert>

class THaTrack;
class THaBenchmark;
class TClonesArray;
class THashTable;

using std::vector;

namespace TreeSearch {
  class WirePlane;
  class Projection;
  class Road;
  class ThreadCtrl;  // Defined in implementation

  typedef std::vector<Road*> Rvec_t;
  typedef std::set<Road*>    Rset_t;

  extern const Double_t kBig;

  class MWDC : public THaTrackingDetector {
  public:
    MWDC( const char* name, const char* description = "", 
	  THaApparatus* app = 0 );
    virtual ~MWDC();

    virtual void    Clear( Option_t* opt="" );
    virtual Int_t   Decode( const THaEvData& );
    virtual EStatus Init( const TDatime& date );
    virtual Int_t   CoarseTrack( TClonesArray& tracks );
    virtual Int_t   FineTrack( TClonesArray& tracks );
    virtual Int_t   DefineVariables( EMode mode = kDefine );
    virtual void    Print(const Option_t* opt) const;
    virtual void    SetDebug( Int_t level );

    void            EnableEventDisplay( Bool_t enable = true );
    const pdbl_t&   GetChisqLimits( UInt_t i ) const;
    Double_t        GetRefTime( UInt_t i ) const 
    { return (i<(UInt_t)fRefMap->GetSize()) ? fRefTime[i] : kBig; }

    EProjType       NameToType( const char* name );

#ifdef TESTCODE
    Int_t           GetEvNum() const { return fEvNum; }
    vector<TreeSearch::WirePlane*>& GetListOfPlanes() { return fPlanes; }
    vector<TreeSearch::Projection*>& GetListOfProjections() { return fProj; }
#endif
    // Analysis control flags. Set via database.
    enum {
      kDoTimeCut  = BIT(14), // Use TDC time cut in decoder (defined in planes)
      kPairsOnly  = BIT(15), // Accept only pairs of hits from plane pairs
      kMCdata     = BIT(16), // Assume input is Monte Carlo data
      kNoPartner  = BIT(17), // Never partner wire planes
      k3dFastMatch= BIT(18), // Use fast 3D matching algorithm (auto detected)
      kEventDisplay = BIT(19), // Support event display
      kDoCoarse   = BIT(20), // Do coarse tracking (if disabled, decode only)
      kDoFine     = BIT(21)  // Do fine tracking (implies kDoCoarse)
    };

  protected:
    friend class WirePlane;
    class TrackFitWeight;
    struct FitRes_t {
      vector<Double_t> coef;
      Double_t matchval;
      Double_t chi2;
      Int_t    ndof;
      Rvec_t*  roads;
      FitRes_t() : roads(0) {}
    };

    typedef std::vector<WirePlane*>  Wpvec_t;
    typedef std::vector<Projection*> Prvec_t;

    Wpvec_t        fPlanes;      // Wire planes
    Prvec_t        fProj;        // Plane projections
    Wpvec_t        fCalibPlanes; // Planes in calibration mode

    THaDetMap*     fRefMap;      // Map of reference channels for VME readout
    vector<float>  fRefTime;     // [fRefMap->GetSize()] ref channel data

    THashTable*    fCrateMap;    // Map of MWDC DAQ modules

    // Multithread support
    Int_t          fMaxThreads;  // Maximum simultaneously active threads
    ThreadCtrl*    fThreads;     //! Thread controller

    // Paremeters for 3D projection matching
    Double_t       f3dMatchvalScalefact; // Correction for fast 3D matchval
    Double_t       f3dMatchCut;          // Maximum allowed 3D match error

    // Track fit cut parameters
    Int_t          fMinNdof;     // Minimum number of points in fit - 4
    vec_pdbl_t     fChisqLimits; // lo/hi onfidence interval limits on Chi2

    // Event data
    Int_t          fFailNhits; // Too many hits in wire plane(s)
    Int_t          fFailNpat;  // Too many treesearch patterns found
#ifdef TESTCODE
    UInt_t         fNcombos;   // Number of road combinations tried
    UInt_t         fN3dFits;   // Number of track fits done (=good road combos)
    Int_t          fEvNum;     // Current event number
    Double_t       t_track, t_3dmatch, t_3dfit, t_coarse; // times in us
#endif

    void      Add3dMatch( const Rvec_t& selected, Double_t matchval,
			  std::list<std::pair<Double_t,Rvec_t> >& combos_found,
			  Rset_t& unique_found ) const;
    void      FindNearestHits( WirePlane* wp, const THaTrack* track,
			       const Rvec_t& roads ) const;
    void      FitErrPrint( Int_t err ) const;
    Int_t     FitTrack( const Rvec_t& roads, vector<Double_t>& coef,
			Double_t& chi2, TMatrixDSym* coef_covar = 0 ) const;
    template< typename Action > static
    Action    ForAllTrackPoints( const Rvec_t& roads, 
				 const vector<Double_t>& coef, Action action );
    UInt_t    MatchRoads( vector<Rvec_t>& roads,
			  std::list<std::pair<Double_t,Rvec_t> >& combos_found,
			  Rset_t& unique_found );
			  
    THaTrack* NewTrack( TClonesArray& tracks, const FitRes_t& fit_par );
    Bool_t    PassTrackCuts( const FitRes_t& fit_par ) const;

    // Helper functions for getting DAQ module parameters - used by Init
    UInt_t    LoadDAQmodel( THaDetMap::Module* m ) const;
    Double_t  LoadDAQresolution( THaDetMap::Module* m ) const;
    UInt_t    GetDAQnchan( THaDetMap::Module* m ) const;

    // Podd interface
    virtual Int_t   ReadDatabase( const TDatime& date );

    ClassDef(MWDC,0)   // Tree search reconstruction of BigBite MWDCs
  };

  //___________________________________________________________________________
  inline const pdbl_t& MWDC::GetChisqLimits( UInt_t i ) const
  { 
    assert( i < fChisqLimits.size() );
    return fChisqLimits[i];
  }

}

///////////////////////////////////////////////////////////////////////////////

#endif
 MWDC.h:1
 MWDC.h:2
 MWDC.h:3
 MWDC.h:4
 MWDC.h:5
 MWDC.h:6
 MWDC.h:7
 MWDC.h:8
 MWDC.h:9
 MWDC.h:10
 MWDC.h:11
 MWDC.h:12
 MWDC.h:13
 MWDC.h:14
 MWDC.h:15
 MWDC.h:16
 MWDC.h:17
 MWDC.h:18
 MWDC.h:19
 MWDC.h:20
 MWDC.h:21
 MWDC.h:22
 MWDC.h:23
 MWDC.h:24
 MWDC.h:25
 MWDC.h:26
 MWDC.h:27
 MWDC.h:28
 MWDC.h:29
 MWDC.h:30
 MWDC.h:31
 MWDC.h:32
 MWDC.h:33
 MWDC.h:34
 MWDC.h:35
 MWDC.h:36
 MWDC.h:37
 MWDC.h:38
 MWDC.h:39
 MWDC.h:40
 MWDC.h:41
 MWDC.h:42
 MWDC.h:43
 MWDC.h:44
 MWDC.h:45
 MWDC.h:46
 MWDC.h:47
 MWDC.h:48
 MWDC.h:49
 MWDC.h:50
 MWDC.h:51
 MWDC.h:52
 MWDC.h:53
 MWDC.h:54
 MWDC.h:55
 MWDC.h:56
 MWDC.h:57
 MWDC.h:58
 MWDC.h:59
 MWDC.h:60
 MWDC.h:61
 MWDC.h:62
 MWDC.h:63
 MWDC.h:64
 MWDC.h:65
 MWDC.h:66
 MWDC.h:67
 MWDC.h:68
 MWDC.h:69
 MWDC.h:70
 MWDC.h:71
 MWDC.h:72
 MWDC.h:73
 MWDC.h:74
 MWDC.h:75
 MWDC.h:76
 MWDC.h:77
 MWDC.h:78
 MWDC.h:79
 MWDC.h:80
 MWDC.h:81
 MWDC.h:82
 MWDC.h:83
 MWDC.h:84
 MWDC.h:85
 MWDC.h:86
 MWDC.h:87
 MWDC.h:88
 MWDC.h:89
 MWDC.h:90
 MWDC.h:91
 MWDC.h:92
 MWDC.h:93
 MWDC.h:94
 MWDC.h:95
 MWDC.h:96
 MWDC.h:97
 MWDC.h:98
 MWDC.h:99
 MWDC.h:100
 MWDC.h:101
 MWDC.h:102
 MWDC.h:103
 MWDC.h:104
 MWDC.h:105
 MWDC.h:106
 MWDC.h:107
 MWDC.h:108
 MWDC.h:109
 MWDC.h:110
 MWDC.h:111
 MWDC.h:112
 MWDC.h:113
 MWDC.h:114
 MWDC.h:115
 MWDC.h:116
 MWDC.h:117
 MWDC.h:118
 MWDC.h:119
 MWDC.h:120
 MWDC.h:121
 MWDC.h:122
 MWDC.h:123
 MWDC.h:124
 MWDC.h:125
 MWDC.h:126
 MWDC.h:127
 MWDC.h:128
 MWDC.h:129
 MWDC.h:130
 MWDC.h:131
 MWDC.h:132
 MWDC.h:133
 MWDC.h:134
 MWDC.h:135
 MWDC.h:136
 MWDC.h:137
 MWDC.h:138
 MWDC.h:139
 MWDC.h:140
 MWDC.h:141
 MWDC.h:142
 MWDC.h:143
 MWDC.h:144
 MWDC.h:145
 MWDC.h:146
 MWDC.h:147
 MWDC.h:148
 MWDC.h:149
 MWDC.h:150
 MWDC.h:151
 MWDC.h:152
 MWDC.h:153
 MWDC.h:154
 MWDC.h:155
 MWDC.h:156
 MWDC.h:157
 MWDC.h:158
 MWDC.h:159
 MWDC.h:160
 MWDC.h:161
 MWDC.h:162
 MWDC.h:163