ROOT logo
#ifndef __HPARTICLEPAIRMAKER_H__
#define __HPARTICLEPAIRMAKER_H__


#include "hparticledef.h"
#include "hparticlepair.h"
#include "hparticlecand.h"
#include "hparticletool.h"
#include "hphysicsconstants.h"
#include "heventheader.h"


#include "TObject.h"
#include "TLorentzVector.h"


#include <vector>
#include <map>
#include <iostream>
#include <iomanip>

using namespace std;

class HParticlePairMaker : public TObject
{
private:

    vector<HParticleCand*> freference;                    //! reference candidates (kIsLepton flagged)
    vector<HParticleCand*> fothers;                       //! other candidates (not KIsLepton flagged)
    vector<HParticleCand*> ffullrecoOthers;               //! full reco cands (inner/outer MDC + META) inside others
    vector<HParticleCand*> fnofullrecoOthers;             //! not full reco cands (inner/outer MDC or META missing) inside others
    vector<HParticlePair>  fpairs;                        //! all pair combinations freference x fothers


    map<Int_t, vector<HParticleCand*> > mTofHittoCand;       //!  TOF hit     lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mTofClsttoCand;      //!  TOF cluster lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mRpcClsttoCand;      //!  RPC cluster lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mShowertoCand;       //!  SHOWER hit  lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mEmctoCand;          //!  EMC Cluster lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mInnerMdctoCand;     //!  inner Seg   lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mOuterMdctoCand;     //!  outer Seg   lookup   detector hit ind -> list of candidates using this hit
    map<Int_t, vector<HParticleCand*> > mRichtoCand;         //!  RICH hit    lookup   detector hit ind -> list of candidates using this hit
    map<HVirtualCand*,vector<HParticlePair*> > mCandtoPair; //!  candidate   lookup   candidate        -> list of pairs using this candidate



    Bool_t (*fselectPID1)(HParticleCand*);                 //! selection function pid1 (default positrons)
    Bool_t (*fselectPID2)(HParticleCand*);                 //! selection function pid2 (default electrons)
    Bool_t (*fuserFilter)(HParticleCand*);                 //! user filter function to avoid unneeded combinatorics

    Int_t fPID1;                                           //!  pid1 (default positrons)
    Int_t fPID2;                                           //!  pid2 (default electrons)
    Int_t fMotherPID;                                      //!  default dilepton

    Bool_t fuse_kIsLepton;                                 //! == kTRUE use kIsLepton as refererence selection (default)
    Bool_t fdoSkippedFullCandPairs;                        //! == kTRUE build also pairs of skipped full reco cands (inner/outer MDC+META) with others
    static Bool_t frequireRich;                            //! ask for rich index in selctPos/selectNeg function

    Int_t         fVertexCase;                            //! which eventvertex to use (see eVertex in hparticledef.h)
    HGeomVector   fVertex;                                // vertex for  current event

    vector<UInt_t>  fCaseCt;                              //! counter array for cases
    vector<UInt_t>  fCaseVec;                             //! vector for pair cases
    Int_t           richCandCt;                           //! counter for all pair cases with both candidates matching a Rich (check)

    void clearVectors();
    void bookHits(HParticleCand* cand1);
    void selectPID(HParticleCand* cand1,Int_t& pid1,Bool_t warn=kTRUE);
public:

    HParticlePairMaker();
    ~HParticlePairMaker();

    //--------------------------------------------------------------------------
    // setters
    void setPIDs(Int_t pid1,Int_t pid2,Int_t motherpid) {
	fPID1      = pid1;
	fPID2      = pid2;
	fMotherPID = motherpid;
    }

    void setPIDsSelection(Bool_t (*selPID1)(HParticleCand*), Bool_t (*selPID2)(HParticleCand*)) {
	fselectPID1=selPID1;
        fselectPID2=selPID2;
    }
    void setUserFilter(Bool_t (*userfilter)(HParticleCand*)) {
	fuserFilter=userfilter;
    }
    void          setDoSkippedFullCandPairs(Bool_t doit) { fdoSkippedFullCandPairs = doit; }
    void          setUseLeptons (Bool_t use) { fuse_kIsLepton = use;}
    static void   setRequireRich(Bool_t use) { frequireRich = use;}
    static Bool_t getRequireRich()           { return frequireRich ;}
    void          setVertexCase(Particle::eVertex vertexCase) { fVertexCase =  vertexCase; };
    void          setVertex(HGeomVector& v)  { fVertex = v; fVertexCase = kVertexUser;}
    void          setVertex(HVertex& v)      { fVertex = v.getPos(); fVertexCase = kVertexUser;}

    static Bool_t selectPos(HParticleCand*);
    static Bool_t selectNeg(HParticleCand*);

    //--------------------------------------------------------------------------
    //  event action
    void nextEvent();

    vector<HParticleCand*>& getReferenceVector() { return freference; }
    vector<HParticleCand*>& getOthersVector   () { return fothers;    }
    vector<HParticlePair>&  getPairsVector    () { return fpairs;     }

    //--------------------------------------------------------------------------
    // filter functions
    void  filterPairsVector(vector<HParticlePair*>& filterpairs,UInt_t flag=0);
    void  filterPairsVector(vector<HParticlePair*>& filterpairs,vector<UInt_t>& flags);
    Int_t filterCandidates (HVirtualCand* cand,vector<HVirtualCand*>& candidates,UInt_t flag=0,Float_t oAngle=-1);
    Int_t filterCandidates (HVirtualCand* cand,vector<HParticlePair*>& filterpairs,UInt_t flag=0,Float_t oAngle=-1);

    //--------------------------------------------------------------------------
    // lookup functions
    Int_t getSameRich    (HParticleCand* cand,vector<HParticleCand*>& candidates,UInt_t flag=0,Bool_t isReference = kTRUE);
    Int_t getSameInnerMdc(HParticleCand* cand,vector<HParticleCand*>& candidates,UInt_t flag=0,Bool_t isReference = kTRUE);
    Int_t getSameOuterMdc(HParticleCand* cand,vector<HParticleCand*>& candidates,UInt_t flag=0,Bool_t isReference = kTRUE);
    Int_t getSameMeta    (HParticleCand* cand,vector<HParticleCand*>& candidates,UInt_t flag=0,Bool_t isReference = kTRUE);

    void plotPairCaseStat();
    ClassDef(HParticlePairMaker,0)
};


#endif // __HPARTICLEPAIRMAKER_H__
 hparticlepairmaker.h:1
 hparticlepairmaker.h:2
 hparticlepairmaker.h:3
 hparticlepairmaker.h:4
 hparticlepairmaker.h:5
 hparticlepairmaker.h:6
 hparticlepairmaker.h:7
 hparticlepairmaker.h:8
 hparticlepairmaker.h:9
 hparticlepairmaker.h:10
 hparticlepairmaker.h:11
 hparticlepairmaker.h:12
 hparticlepairmaker.h:13
 hparticlepairmaker.h:14
 hparticlepairmaker.h:15
 hparticlepairmaker.h:16
 hparticlepairmaker.h:17
 hparticlepairmaker.h:18
 hparticlepairmaker.h:19
 hparticlepairmaker.h:20
 hparticlepairmaker.h:21
 hparticlepairmaker.h:22
 hparticlepairmaker.h:23
 hparticlepairmaker.h:24
 hparticlepairmaker.h:25
 hparticlepairmaker.h:26
 hparticlepairmaker.h:27
 hparticlepairmaker.h:28
 hparticlepairmaker.h:29
 hparticlepairmaker.h:30
 hparticlepairmaker.h:31
 hparticlepairmaker.h:32
 hparticlepairmaker.h:33
 hparticlepairmaker.h:34
 hparticlepairmaker.h:35
 hparticlepairmaker.h:36
 hparticlepairmaker.h:37
 hparticlepairmaker.h:38
 hparticlepairmaker.h:39
 hparticlepairmaker.h:40
 hparticlepairmaker.h:41
 hparticlepairmaker.h:42
 hparticlepairmaker.h:43
 hparticlepairmaker.h:44
 hparticlepairmaker.h:45
 hparticlepairmaker.h:46
 hparticlepairmaker.h:47
 hparticlepairmaker.h:48
 hparticlepairmaker.h:49
 hparticlepairmaker.h:50
 hparticlepairmaker.h:51
 hparticlepairmaker.h:52
 hparticlepairmaker.h:53
 hparticlepairmaker.h:54
 hparticlepairmaker.h:55
 hparticlepairmaker.h:56
 hparticlepairmaker.h:57
 hparticlepairmaker.h:58
 hparticlepairmaker.h:59
 hparticlepairmaker.h:60
 hparticlepairmaker.h:61
 hparticlepairmaker.h:62
 hparticlepairmaker.h:63
 hparticlepairmaker.h:64
 hparticlepairmaker.h:65
 hparticlepairmaker.h:66
 hparticlepairmaker.h:67
 hparticlepairmaker.h:68
 hparticlepairmaker.h:69
 hparticlepairmaker.h:70
 hparticlepairmaker.h:71
 hparticlepairmaker.h:72
 hparticlepairmaker.h:73
 hparticlepairmaker.h:74
 hparticlepairmaker.h:75
 hparticlepairmaker.h:76
 hparticlepairmaker.h:77
 hparticlepairmaker.h:78
 hparticlepairmaker.h:79
 hparticlepairmaker.h:80
 hparticlepairmaker.h:81
 hparticlepairmaker.h:82
 hparticlepairmaker.h:83
 hparticlepairmaker.h:84
 hparticlepairmaker.h:85
 hparticlepairmaker.h:86
 hparticlepairmaker.h:87
 hparticlepairmaker.h:88
 hparticlepairmaker.h:89
 hparticlepairmaker.h:90
 hparticlepairmaker.h:91
 hparticlepairmaker.h:92
 hparticlepairmaker.h:93
 hparticlepairmaker.h:94
 hparticlepairmaker.h:95
 hparticlepairmaker.h:96
 hparticlepairmaker.h:97
 hparticlepairmaker.h:98
 hparticlepairmaker.h:99
 hparticlepairmaker.h:100
 hparticlepairmaker.h:101
 hparticlepairmaker.h:102
 hparticlepairmaker.h:103
 hparticlepairmaker.h:104
 hparticlepairmaker.h:105
 hparticlepairmaker.h:106
 hparticlepairmaker.h:107
 hparticlepairmaker.h:108
 hparticlepairmaker.h:109
 hparticlepairmaker.h:110
 hparticlepairmaker.h:111
 hparticlepairmaker.h:112
 hparticlepairmaker.h:113
 hparticlepairmaker.h:114
 hparticlepairmaker.h:115
 hparticlepairmaker.h:116
 hparticlepairmaker.h:117
 hparticlepairmaker.h:118
 hparticlepairmaker.h:119
 hparticlepairmaker.h:120
 hparticlepairmaker.h:121
 hparticlepairmaker.h:122
 hparticlepairmaker.h:123
 hparticlepairmaker.h:124
 hparticlepairmaker.h:125
 hparticlepairmaker.h:126
 hparticlepairmaker.h:127