ROOT logo
#ifndef __HPARTICLECAND_H__
#define __HPARTICLECAND_H__

#include "TMath.h"
#include "TObject.h"
#include "TClonesArray.h"
#include "TLorentzVector.h"

#include "hvirtualcand.h"
#include "hparticledef.h"

using namespace Particle;



#define Cloc 299.792458   // from TMath

class HParticleCand : public HVirtualCand
{
protected:
    Int_t       fFlags;		             // bit flags for cleaning
    //Int_t sumval;
    //  |32|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|
    //                                                                       |r|tof|c|sys|sec  |
    Char_t      fPID;                        // PID of particle
    Short_t     fSector;                     // sector information from MDC (0..5)                              (3bit) 0-7
    Short_t     fSystem;                     // 0 == TOFino, 1 == TOF                                           (2bit) 0-3

    UShort_t    fRingCorr;                   // ring - mdc correlation
    Short_t     fIndex;                      // index in category

    SmallFloat  fDistanceToMetaHit;          // track's distance to meta hit [mm]

    SmallFloat  fMdcdEdx;                    // Mdc dE/dx for inner and outer segment
    SmallFloat  fTofdEdx;                    // Tof dE/dx


    // MDC related track properties
    SmallFloat  fInnerSegmentChi2;           // MDC segment fitter chi^2 (-1 if not fitted)
    SmallFloat  fOuterSegmentChi2;           // MDC segment fitter chi^2 (-1 if not fitted)
    SmallFloat  fAngleToNearbyFittedInner;   // angle to closest fitted inner segment (negative angles indicate segments which belong to hadrons or neighbouring tracks) [deg]
    SmallFloat  fAngleToNearbyUnfittedInner; // angle to closest unfitted inner segment (negative angles indicate segments which belong to hadrons or neighbouring tracks) [deg]

    // properties of the RICH ring
    Char_t      fRingNumPads;                // number of fired pads typ. (-1 - 100) (OLD) | number of Cal objects (NEW)
    Short_t     fRingAmplitude;              // typ. (-1 - 4000)
    Short_t     fRingHouTra;                 // typ. (-1 - 5000)
    Short_t     fRingPatternMatrix;          // pattern matrix of ring
    SmallFloat  fRingCentroid;               // ring centroid (OLD) | radius (NEW)
    SmallFloat  fRichPhi;
    SmallFloat  fRichTheta;
    Float_t     fRingChi2;                   // chi2 of ring fit (NEW)

    // properties of meta hits
    SmallFloat  fMetaMatchQuality;      // distance of the outer segment to the meta hit
    SmallFloat  fMetaMatchQualityShower;// distance of the outer segment to the shower hit
    SmallFloat  fMetaMatchRadius;       // distance of the outer segment to the meta hit   [mm]
    SmallFloat  fMetaMatchRadiusShower; // distance of the outer segment to the shower hit [mm]
    SmallFloat  fRkMetaDx;              // distance in X of outer segment to used Meta  [mm]
    SmallFloat  fRkMetaDy;              // distance in Y of outer segment to used Meta  [mm]
    SmallFloat  fRkMetaDxShower;        // distance in X of outer segment to shower hit  [mm]
    SmallFloat  fRkMetaDyShower;        // distance in Y of outer segment to shower hit  [mm]

    // backup before recalc
    SmallFloat  fBetaOrg;               // particle's beta  before recalc
    SmallFloat  fMomentumOrg;           // particle's momentum [MeV]  before correction
    SmallFloat  fDistanceToMetaHitOrg;  // track's distance to meta hit [mm]  before correction

    //properties of shower hits | EMC cluster
    SmallFloat  fShowerSum0;          // charge sum of PreShower cluster (0)  | EMC:energy
    SmallFloat  fShowerSum1;          // charge sum of PreShower cluster (1)  | EMC:time
    SmallFloat  fShowerSum2;          // charge sum of PreShower cluster (2)  | EMC:cellPath
    UShort_t    fEmcFlags;            // |16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|
                                      //                        |s|m| ncells  |u|    s=rpc ind is same, m=cluster is matched in time with rpc, u=isEMC

    Char_t      fSelectedMeta;        // which Metahit has been used  kNoUse,kTofClst,kTofHit1,kTofHit2,kRpcClst,kShowerHit,kEmcClst
    Short_t     fMetaInd;             // index of Metamatch
    Short_t     fRichInd;             // index of RICH hit
    Short_t     fRichBTInd;           // index of RICH BT hit
    Short_t     fInnerSegInd;         // index of inner MDC Segment
    Short_t     fOuterSegInd;         // index of outer MDC Segment
    Short_t     fRpcInd;              // index of RPC Hit
    Short_t     fShowerInd;           // index of SHOWER hit | EMC cluster
    Short_t     fTofHitInd;           // index of TOF hit
    Short_t     fTofClstInd;          // index of TOF cluster
    UInt_t      fLayers;              // bit array for fired MDC layers  (1-24 bit layers + 31-29 bit fake reject + 28,27,26 bit clusOffvertex,vertex,primary)
    UShort_t    fWires;               // lower 10bits for wires per segment , 11,12,13,14 at edge
    UInt_t      fmetaAddress;         // store adress (mod+cell / col+cell for TOF+RPC hit 0 and 1)
                                      //  |32|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|
                                      //                                |             cell2  |    mod2   |  cell1        | mod1  |

public:
    HParticleCand() :
	 fFlags(0)
        ,fPID(-1)
	,fSector(-1)
	,fSystem(-1)
	,fRingCorr(0)
	,fIndex(-1)
	,fDistanceToMetaHit(-1)
	,fMdcdEdx(-1)
	,fTofdEdx(-1)
	,fInnerSegmentChi2(-1)
	,fOuterSegmentChi2(-1)
	,fAngleToNearbyFittedInner(0)
	,fAngleToNearbyUnfittedInner(0)
	,fRingNumPads(0)
	,fRingAmplitude(0)
	,fRingHouTra(0)
	,fRingPatternMatrix(-1)
	,fRingCentroid(-1)
	,fRichPhi(-1)
	,fRichTheta(-1)
	,fRingChi2(-1000)
	,fMetaMatchQuality(-1)
	,fMetaMatchQualityShower(-1)
	,fMetaMatchRadius(-1)
	,fMetaMatchRadiusShower(-1)
	,fRkMetaDx(-1000)
	,fRkMetaDy(-1000)
	,fRkMetaDxShower(-1000)
	,fRkMetaDyShower(-1000)
	,fBetaOrg(-1)
	,fMomentumOrg(-1)
	,fDistanceToMetaHitOrg(-1)
 	,fShowerSum0 (-1)
	,fShowerSum1(-1)
	,fShowerSum2(-1)
	,fEmcFlags(0)
	,fSelectedMeta(-1)
	,fMetaInd(-1)
	,fRichInd(-1)
	,fRichBTInd(-1)
	,fInnerSegInd(-1)
	,fOuterSegInd(-1)
	,fRpcInd(-1)
	,fShowerInd(-1)
	,fTofHitInd(-1)
	,fTofClstInd(-1)
	,fLayers(0)
	,fWires(0)
	,fmetaAddress(0)
			
    {
    }
	~HParticleCand() {}
	// -------------------------------------------------------------------------
	//  flag manipulations
	void   setFlagBit   (eFlagBits bit)  { fFlags |=  ( 0x01 << bit ); }
	void   unsetFlagBit (eFlagBits bit)  { fFlags &= ~( 0x01 << bit ); }
	Bool_t isFlagBit    (eFlagBits bit)  { return (fFlags >> bit ) & 0x01 ; }
	void   setFlagBit   (Int_t bit);
	void   unsetFlagBit (Int_t bit);
	Bool_t isFlagBit    (Int_t bit);
	void   setFlagBitByValue(eFlagBits bit, Bool_t val)  { val ? setFlagBit(bit) : unsetFlagBit(bit); }
	void   setFlagBitByValue(Int_t     bit, Bool_t val)  { val ? setFlagBit(bit) : unsetFlagBit(bit); }
	Bool_t isFlagDoubleHit ()            { return (fFlags & 0xF) == 0x0 ? kFALSE : kTRUE; }
	Bool_t isFlagAllBestHit()            { return ((fFlags >> 4 ) & 0xF) == 0xF ? kTRUE : kFALSE; }
	Bool_t isFlagNoBestHit ()            { return ((fFlags >> 4 ) & 0xF) == 0x0 ? kTRUE : kFALSE; }
	Int_t  getFlagField()                { return fFlags;  }
	void   setFlagField(Int_t field)     { fFlags = field; }
	Bool_t isFlagAND(Int_t num, ...);
	Bool_t isFlagOR (Int_t num, ...);
	Int_t  getDoubleHitsLeptons()        { return (fFlags & 0xF);}
	Int_t  getDoubleHitsHadrons()        { return ((fFlags >> 1) & 0x7);}
	void   printFlags(TString comment="");
	virtual void   print(UInt_t selection=31);
	Bool_t select(Bool_t (*function)(HParticleCand* )) { return  (*function)(this); }
	// -------------------------------------------------------------------------


	void    setIndex(Int_t i)                         { fIndex = i;                }
	void    setPID(Int_t id)                          { fPID = (Char_t)id;         }
	void    setSector(Int_t s)                        { fSector = s;               }
	void    setSystem(Int_t s)                        { fSystem = s;               }
	void    setRingCorr(UShort_t rc)                  { fRingCorr = rc;            }
	void    setMdcdEdx(Float_t d)                     { fMdcdEdx = d;              }
	void    setTofdEdx(Float_t d)                     { fTofdEdx = d;              }
	void    setDistanceToMetaHit(Float_t d)           { fDistanceToMetaHit = d;    }
	void    setInnerSegmentChi2(Float_t c)            { fInnerSegmentChi2 = c;    }
	void    setOuterSegmentChi2(Float_t c)            { fOuterSegmentChi2 = c;    }
	void    setAngleToNearbyFittedInner(Float_t a)    { fAngleToNearbyFittedInner = a;       }
	void    setAngleToNearbyUnfittedInner(Float_t a)  { fAngleToNearbyUnfittedInner = a;     }
	void    setRingNumCals(Int_t n)                   { fRingNumPads = n <= 127 ? n: 127;    }  // RICH700
	void    setRingNumPads(Int_t n)                   { fRingNumPads = n <= 127 ? n: 127;    }
	void    setRingAmplitude(Int_t amp)               { fRingAmplitude = (Short_t) amp;      }
	void    setRingHouTra(Int_t a)                    { fRingHouTra = (Short_t)a;            }
	void    setRingPatternMatrix(Int_t p)             { fRingPatternMatrix = (Short_t) p;    }
	void    setRingRadius(Float_t c)                  { fRingCentroid = c;          }     // RICH700
	void    setRingChi2(Float_t c)                    { fRingChi2 = c;              }     // RICH700
	void    setRingCentroid(Float_t c)                { fRingCentroid = c;          }
	void    setRichPhi(Float_t p)                     { fRichPhi = p;               }
	void    setRichTheta(Float_t p)                   { fRichTheta = p;             }
	void    setMetaMatchQuality(Float_t q)            { fMetaMatchQuality = q;      }
	void    setMetaMatchQualityShower(Float_t q)      { fMetaMatchQualityShower = q;}
	void    setMetaMatchQualityEmc(Float_t q)         { fMetaMatchQualityShower = q;} // share with shower
	void    setMetaMatchRadius(Float_t q)             { fMetaMatchRadius = q;       }
	void    setMetaMatchRadiusShower(Float_t q)       { fMetaMatchRadiusShower = q; }
	void    setMetaMatchRadiusEmc(Float_t q)          { fMetaMatchRadiusShower = q; } // share with shower
	void    setRkMetaDx(Float_t q)                    { fRkMetaDx   = q;            }
	void    setRkMetaDy(Float_t q)                    { fRkMetaDy   = q;            }
	void    setRkMetaDxShower(Float_t q)              { fRkMetaDxShower   = q;      }
	void    setRkMetaDyShower(Float_t q)              { fRkMetaDyShower   = q;      }
	void    setRkMetaDxEmc(Float_t q)                 { fRkMetaDxShower   = q;      }
	void    setRkMetaDyEmc(Float_t q)                 { fRkMetaDyShower   = q;      }
	void    setBetaOrg(Float_t b)                     { fBetaOrg = b;               }
	void    setDistanceToMetaHitOrg(Float_t d)        { fDistanceToMetaHitOrg = d;  }
	void    setMomentumOrg(Float_t m)                 { fMomentumOrg = m;           }
	void    setShowerSum0(Float_t q)                  { fShowerSum0 = q;            }
	void    setShowerSum1(Float_t q)                  { fShowerSum1 = q;            }
	void    setShowerSum2(Float_t q)                  { fShowerSum2 = q;            }
	void    setEmcEnergy(Float_t e)                   { fShowerSum0 = e;            } // share with shower
	void    setEmcTime(Float_t t)                     { fShowerSum1 = t;            } // share with shower
	void    setEmcCellPath(Float_t t)                 { fShowerSum2 = t;            } // share with shower
        void    setIsEmc()                                { fEmcFlags |= 0x01; }
        void    setIsEmcMatchedToRpc()                    { fEmcFlags |= (0x01 << 6); }
        void    setIsEmcMatchedToSameRpc()                { fEmcFlags |= (0x01 << 7); }
        void    setEmcNCells(UChar_t n)                   { if( n>31) n=31; fEmcFlags |= (((n&(0x1F))<<1)); }
	void    unsetIsEmc()                              { fEmcFlags &= ~( 0x01 << 0 ); }
	void    unsetIsEmcMatchedToRpc()                  { fEmcFlags &= ~( 0x01 << 6 ); }
	void    unsetIsEmcMatchedToSameRpc()              { fEmcFlags &= ~( 0x01 << 7 ); }
	void    unsetEmcNCells()                          { fEmcFlags &= ~( 0x1F << 1 ); }

	void    setSelectedMeta(Int_t flag)               { fSelectedMeta = (Char_t)flag;}
	void    setMetaInd(Int_t ind)                     { fMetaInd    = ind;          }
	void    setRichInd(Int_t ind)                     { fRichInd    = ind;          }
	void    setRichBTInd(Int_t ind)                   { fRichBTInd  = ind;          }
	void    setInnerSegInd(Int_t ind)                 { fInnerSegInd= ind;          }
	void    setOuterSegInd(Int_t ind)                 { fOuterSegInd= ind;          }
        void    setRpcInd(Int_t ind)                      { fRpcInd     = ind;          }
	void    setShowerInd(Int_t ind)                   { fShowerInd  = ind;          }
	void    setEmcInd(Int_t ind)                      { fShowerInd  = ind;          }  // share with shower
	void    setTofHitInd(Int_t ind)                   { fTofHitInd  = ind;          }
	void    setTofClstInd(Int_t ind)                  { fTofClstInd = ind;          }



	Short_t getIndex()                      const     { return fIndex;             }
	Int_t   getPID()                        const     { return fPID;               }
	Short_t getSector()                     const     { return fSector;            }
	Short_t getSystem()                     const     { return fSystem;            }
	Short_t getSystemUsed()                 const     { return ( isRpcClstUsed() || isShowerUsed() ) ?  0 :  ( ( isTofHitUsed() || isTofClstUsed() ) ? 1 : -1 ); }
	UShort_t getRingCorr()                  const     { return fRingCorr;          }
	Bool_t  isRichMatch(eMatching match)    const     { return (fRingCorr&match) == 0 ? kFALSE:kTRUE; }
	Float_t getMdcdEdx()                    const     { return fMdcdEdx;           }
	Float_t getTofdEdx()                    const     { return fTofdEdx;           }
	Float_t getDistanceToMetaHit()          const     { return fDistanceToMetaHit; }
        Float_t getTof()                        const     { return fBeta>0 ? fDistanceToMetaHit/(fBeta*Cloc) : -1; }
        Float_t getTofNorm(Float_t dist=2100)   const     { return fBeta>0 ? (fDistanceToMetaHit/(fBeta*Cloc)) * dist/fDistanceToMetaHit : -1; }
	Float_t getInnerSegmentChi2()           const     { return fInnerSegmentChi2; }
	Float_t getOuterSegmentChi2()           const     { return fOuterSegmentChi2; }
	Float_t getAngleToNearbyFittedInner()   const     { return fAngleToNearbyFittedInner;    }
	Float_t getAngleToNearbyUnfittedInner() const     { return fAngleToNearbyUnfittedInner;  }
	Int_t   getRingNumCals()                const     { return (Int_t)fRingNumPads;          }
	Int_t   getRingNumPads()                const     { return (Int_t)fRingNumPads;          }
	Int_t   getRingAmplitude()              const     { return (Int_t) fRingAmplitude;       }
        Float_t getAverageRingCharge()          const     { return fRingNumPads == 0 ?  0 : fRingAmplitude/(Float_t)fRingNumPads;}
        Int_t   getRingHouTra()                 const     { return (Int_t) fRingHouTra;          }
	Int_t   getRingPatternMatrix()          const     { return (Int_t)fRingPatternMatrix;    }
	Float_t getRingRadius()                 const     { return fRingCentroid;       }     // RICH700
	Float_t getRingChi2()                   const     { return fRingChi2;           }     // RICH700
	Float_t getRingCentroid()               const     { return fRingCentroid;       }
	Float_t getRichPhi()                    const     { return fRichPhi;            }
	Float_t getRichTheta()                  const     { return fRichTheta;          }
	Float_t getMetaMatchQuality()           const     { return fMetaMatchQuality;   }
	Float_t getMetaMatchQualityShower()     const     { return fMetaMatchQualityShower;}
	Float_t getMetaMatchQualityEmc()        const     { return fMetaMatchQualityShower;} // share with shower
	Float_t getMetaMatchRadius()            const     { return fMetaMatchRadius;   }
	Float_t getMetaMatchRadiusShower()      const     { return fMetaMatchRadiusShower;}
	Float_t getMetaMatchRadiusEmc()         const     { return fMetaMatchRadiusShower;}  // share with shower
	Float_t getRkMetaDx()                   const     { return fRkMetaDx;           }
	Float_t getRkMetaDy()                   const     { return fRkMetaDy;           }
	Float_t getRkMetaDxShower()             const     { return fRkMetaDxShower;     }
	Float_t getRkMetaDyShower()             const     { return fRkMetaDyShower;     }
	Float_t getRkMetaDxEmc()                const     { return fRkMetaDxShower;     }
	Float_t getRkMetaDyEmc()                const     { return fRkMetaDyShower;     }
	Float_t getBetaOrg()                    const     { return fBetaOrg;            }
	Float_t getDistanceToMetaHitOrg()       const     { return fDistanceToMetaHitOrg; }
	Float_t getMomentumOrg()                const     { return fMomentumOrg;        }
        Float_t calcRkMetaMatch(Float_t weightX=1.,Float_t weightY=1.) { return (fRkMetaDx==-1000&&fRkMetaDy==-1000)? -1 : sqrt( (weightX*fRkMetaDx)*(weightX*fRkMetaDx) + (weightY*fRkMetaDy)*(weightY*fRkMetaDy)  );}

        Float_t getShowerSum0()                 const     { return fShowerSum0;         }
	Float_t getShowerSum1()                 const     { return fShowerSum1;         }
	Float_t getShowerSum2()                 const     { return fShowerSum2;         }
        Float_t getShowerDeltaSum()             const     { return fShowerSum0 ==-1 && fShowerSum1 == -1 ? -1 : fShowerSum1+fShowerSum2-fShowerSum0; }
        Float_t getEmcEnergy()                  const     { return fShowerSum0;         }  // share with shower
	Float_t getEmcTime()                    const     { return fShowerSum1;         }  // share with shower
	Float_t getEmcCellPath()                const     { return fShowerSum2;         }  // share with shower
        Bool_t  isEmc()                                   { return fEmcFlags & 0x01;}
        Bool_t  isEmcMatchedToRpc()                       { return (fEmcFlags>>6) & 0x01;}
        Bool_t  isEmcMatchedToSameRpc()                   { return (fEmcFlags>>7) & 0x01;}
        UChar_t getEmcNCells()                            { return (fEmcFlags>>1) & 0x1F;}

        Int_t   getSelectedMeta()               const     { return (Int_t)fSelectedMeta;}  // find the defined enum in hparticledef.h
	Bool_t  isTofHitUsed()                  const     { return (fSelectedMeta == Particle::kTofHit1 || fSelectedMeta == Particle::kTofHit2) ? kTRUE : kFALSE; }
        Bool_t  isTofClstUsed()                 const     { return (fSelectedMeta == Particle::kTofClst)   ? kTRUE : kFALSE; }
        Bool_t  isRpcClstUsed()                 const     { return (fSelectedMeta == Particle::kRpcClst)   ? kTRUE : kFALSE; }
        Bool_t  isShowerUsed()                  const     { return (fSelectedMeta == Particle::kShowerHit) ? kTRUE : kFALSE; }
        Bool_t  isEmcUsed()                     const     { return (fSelectedMeta == Particle::kEmcClst)   ? kTRUE : kFALSE; }
        Bool_t  isMetaUsed()                    const     { return (fSelectedMeta != Particle::kNoUse)     ? kTRUE : kFALSE; }

	Int_t   getMetaInd()                    const     { return fMetaInd;            }
        Int_t   getRichInd()                    const     { return fRichInd;            }
        Int_t   getRichBTInd()                  const     { return fRichBTInd;          }
	Int_t   getInnerSegInd()                const     { return fInnerSegInd;        }
	Int_t   getOuterSegInd()                const     { return fOuterSegInd;        }
	Int_t   getRpcInd()                     const     { return fRpcInd;             }
	Int_t   getShowerInd()                  const     { return fShowerInd;          }
	Int_t   getEmcInd()                     const     { return fShowerInd;          } // share with shower
	Int_t   getTofHitInd()                  const     { return fTofHitInd;          }
	Int_t   getTofClstInd()                 const     { return fTofClstInd;         }
        Int_t   getMetaHitInd()                 const     {
	    if      (fSelectedMeta == Particle::kNoUse)     return -1 ;
            else if (fSelectedMeta == Particle::kTofHit1 || fSelectedMeta == Particle::kTofHit2)   return fTofHitInd;
            else if (fSelectedMeta == Particle::kTofClst)   return fTofClstInd;
	    else if (fSelectedMeta == Particle::kRpcClst)   return fRpcInd;
            else if (fSelectedMeta == Particle::kShowerHit) return fShowerInd;
            else if (fSelectedMeta == Particle::kEmcClst)   return fShowerInd;   // share with shower
            return -1;
	}

        Float_t getDeltaTheta(){ return  (fRichInd ==-1) ? -1000 : fRichTheta - fTheta; }                                         // delta theta Rich-RK
        Float_t getDeltaPhi()  {
	    //return  (fRichInd ==-1) ? -1000 : ( fRichPhi - fPhi ) * TMath::Sin(TMath::DegToRad() * fTheta);
            if(fRichInd ==-1) return -1000;
            Float_t dPhi_uncorr = (fRichPhi - fPhi);
	    if     (dPhi_uncorr >  180.) dPhi_uncorr -= 360.;
	    else if(dPhi_uncorr < -180.) dPhi_uncorr += 360.;
	    return dPhi_uncorr * TMath::Sin(TMath::DegToRad() * fTheta);
        } // delta phi Rich-RK
        Float_t getRichMatchingQuality() {
            if(fRichInd ==-1) return -1;
	    else {
		Float_t dPhi   = getDeltaPhi();
		Float_t dTheta = getDeltaTheta();
		return sqrt(dPhi*dPhi + dTheta*dTheta);
	    }
	}
        Float_t getRichMatchingQualityNorm();
	Bool_t  isNewRich()              { return fRingChi2 !=1000 ? kTRUE : kFALSE;}

	Float_t getZprime(Float_t xBeam,Float_t yBeam,Float_t& rPrime);
	Float_t getZprime(Float_t xBeam,Float_t yBeam);
	Float_t getRprime(Float_t xBeam,Float_t yBeam);

        Float_t getMomentumCorrectionPID(Int_t pid);
        Float_t getCorrectedMomentumPID (Int_t pid);
        Float_t getMass2PID(Int_t pid);
        Float_t getMass2CorrectionPID(Int_t pid);
        Float_t getCorrectedMass2PID(Int_t pid);
	void    setLayers(UInt_t io,UInt_t layers) { fLayers|=(layers&(0xFFF<<(io*12)));}
	void    setLayer(UInt_t io,UInt_t lay) { fLayers |=  ( 0x01 << (io*12+lay) );          }
	void    unsetAllLayers()               { fLayers &= ~0xFFFFFF; }
	static void setLayer(UInt_t io,UInt_t lay,UInt_t& layers) { layers |=  ( 0x01 << (io*12+lay) ); }
	Bool_t  getLayer(UInt_t io,UInt_t lay) { return ( fLayers &  ( 0x01 << (io*12+lay) )); }
	Int_t   getNLayer(UInt_t io);
	Int_t   getNLayerMod(UInt_t mod);
	Bool_t  hasLayers(UInt_t io,UInt_t layerstest) { return (((fLayers>>(io*12))&0xFFF)==((layerstest>>(io*12))&0xFFF));}
	Bool_t  isFakeRejected(Int_t io=-1) {
            if     (io==-1) return ( fLayers &  ( 0x01 << 31 ));
            else if(io==0 ) return ( fLayers &  ( 0x01 << 30 ));
            else if(io==1 ) return ( fLayers &  ( 0x01 << 29 ));
            else return kFALSE;
	}
        void  setFakeRejected(Int_t io=-1) {
            if     (io==-1) fLayers |=  ( 0x01 << 31 );
            else if(io==0 ) fLayers |=  ( 0x01 << 30 );
            else if(io==1 ) fLayers |=  ( 0x01 << 29 );
	}
        void  unsetFakeRejected(Int_t io=-1) {
            if     (io==-1) fLayers &= ~( 0x01 << 31 );
            else if(io==0 ) fLayers &= ~( 0x01 << 30 );
            else if(io==1 ) fLayers &= ~( 0x01 << 29 );
	}
        void  unsetAllFakeRejected() {
            fLayers &= ~( 0x07 << 29 );
	}
	void   setOffVertexClust()   { fLayers |=  ( 0x01 << 28 );}
	void   unsetOffVertexClust() { fLayers &= ~( 0x01 << 28 );}
	Bool_t isOffVertexClust()    { return ( fLayers &  ( 0x01 << 28 ));}

	void   setUsedVertex()       { fLayers |=  ( 0x01 << 27 );}
	void   unsetUsedVertex()     { fLayers &= ~( 0x01 << 27 );}
	Bool_t isUsedVertex()        { return ( fLayers &  ( 0x01 << 27 ));}

	void   setPrimaryVertex()       { fLayers |=  ( 0x01 << 26 );}
	void   unsetPrimaryVertex()     { fLayers &= ~( 0x01 << 26 );}
	Bool_t isPrimaryVertex()        { return ( fLayers &  ( 0x01 << 26 ));}

	void    printLayers();

	void  setNWSeg(UInt_t io,UInt_t nw) {
	    if(io<2){
		if(nw>31) nw = 31;
		fWires&= ~(0x1F<<(io*5));
		fWires|=((nw&0x1F)<<(io*5));
	    }
	}
	Int_t getNWSeg(UInt_t io){ if(io<2){ return  (fWires>>(io*5))&0x1F; } else { Int_t n = (fWires>>(0*5))&0x1F; n+= (fWires>>(1*5))&0x1F; return n;} }



	void setAtMdcEdge(UInt_t i){
	    if(i<4) {
                fWires|=((0x1)<<(i+10));
	    }
	}
	void unsetAtMdcEdge(UInt_t i){
	    if(i<4) {
                fWires&=~((0x1)<<(i+10));
	    }
	}
	Bool_t isAtMdcEdge(UInt_t i){
	    if(i<4){
		return ( fWires &  ( 0x01 << (10+i) ));
	    } else return kFALSE;
	}
        Bool_t isAtAnyMdcEdge(UInt_t io=2){
	    if(io<3){
		if(io==0||io==2){
		    if( fWires &  ( 0x01 << (10+0) )) return kTRUE;
		    if( fWires &  ( 0x01 << (10+1) )) return kTRUE;
		}
		if(io>=1){
		    if( fWires &  ( 0x01 << (10+2) )) return kTRUE;
		    if( fWires &  ( 0x01 << (10+3) )) return kTRUE;
		}
                return kFALSE;
	    } else return kFALSE;
	}

	void setMetaModule(UInt_t hit,UInt_t mod){
	    if(hit<2 && mod < 8){
		mod++;
		fmetaAddress&= ~(0xF<<(hit*11+7));
		fmetaAddress|=(mod&0xF)<<(hit*11+7);
	    }
	}
	void unsetMetaModule(UInt_t hit) { if(hit<2) fmetaAddress&= ~(0xF<<(hit*11+7)); }
	void setMetaCell(UInt_t hit,UInt_t cell) {
	    if(hit<2 && cell < 33){
		cell++;
		fmetaAddress&= ~(0x7F<<(hit*11));
		fmetaAddress|=(cell&0x7F)<<(hit*11);
	    }
	}
	void  unsetMetaCell(UInt_t hit) { if(hit<2) fmetaAddress&= ~(0x7F<<(hit*11)); }

	Int_t getMetaModule(UInt_t hit) {  if(hit<2){ return (fmetaAddress>>(hit*11+7)&(0xF))-1; } else return -1; }
	Int_t getMetaCell  (UInt_t hit) {  if(hit<2){ return (fmetaAddress>>(hit*11)&(0x7F))-1;  } else return -1; }

    void OldStreamer(TBuffer &R__b, Int_t version);
	ClassDef(HParticleCand,12)  // A simple track of a particle
};


#endif // __HPARTICLECAND_H__
 hparticlecand.h:1
 hparticlecand.h:2
 hparticlecand.h:3
 hparticlecand.h:4
 hparticlecand.h:5
 hparticlecand.h:6
 hparticlecand.h:7
 hparticlecand.h:8
 hparticlecand.h:9
 hparticlecand.h:10
 hparticlecand.h:11
 hparticlecand.h:12
 hparticlecand.h:13
 hparticlecand.h:14
 hparticlecand.h:15
 hparticlecand.h:16
 hparticlecand.h:17
 hparticlecand.h:18
 hparticlecand.h:19
 hparticlecand.h:20
 hparticlecand.h:21
 hparticlecand.h:22
 hparticlecand.h:23
 hparticlecand.h:24
 hparticlecand.h:25
 hparticlecand.h:26
 hparticlecand.h:27
 hparticlecand.h:28
 hparticlecand.h:29
 hparticlecand.h:30
 hparticlecand.h:31
 hparticlecand.h:32
 hparticlecand.h:33
 hparticlecand.h:34
 hparticlecand.h:35
 hparticlecand.h:36
 hparticlecand.h:37
 hparticlecand.h:38
 hparticlecand.h:39
 hparticlecand.h:40
 hparticlecand.h:41
 hparticlecand.h:42
 hparticlecand.h:43
 hparticlecand.h:44
 hparticlecand.h:45
 hparticlecand.h:46
 hparticlecand.h:47
 hparticlecand.h:48
 hparticlecand.h:49
 hparticlecand.h:50
 hparticlecand.h:51
 hparticlecand.h:52
 hparticlecand.h:53
 hparticlecand.h:54
 hparticlecand.h:55
 hparticlecand.h:56
 hparticlecand.h:57
 hparticlecand.h:58
 hparticlecand.h:59
 hparticlecand.h:60
 hparticlecand.h:61
 hparticlecand.h:62
 hparticlecand.h:63
 hparticlecand.h:64
 hparticlecand.h:65
 hparticlecand.h:66
 hparticlecand.h:67
 hparticlecand.h:68
 hparticlecand.h:69
 hparticlecand.h:70
 hparticlecand.h:71
 hparticlecand.h:72
 hparticlecand.h:73
 hparticlecand.h:74
 hparticlecand.h:75
 hparticlecand.h:76
 hparticlecand.h:77
 hparticlecand.h:78
 hparticlecand.h:79
 hparticlecand.h:80
 hparticlecand.h:81
 hparticlecand.h:82
 hparticlecand.h:83
 hparticlecand.h:84
 hparticlecand.h:85
 hparticlecand.h:86
 hparticlecand.h:87
 hparticlecand.h:88
 hparticlecand.h:89
 hparticlecand.h:90
 hparticlecand.h:91
 hparticlecand.h:92
 hparticlecand.h:93
 hparticlecand.h:94
 hparticlecand.h:95
 hparticlecand.h:96
 hparticlecand.h:97
 hparticlecand.h:98
 hparticlecand.h:99
 hparticlecand.h:100
 hparticlecand.h:101
 hparticlecand.h:102
 hparticlecand.h:103
 hparticlecand.h:104
 hparticlecand.h:105
 hparticlecand.h:106
 hparticlecand.h:107
 hparticlecand.h:108
 hparticlecand.h:109
 hparticlecand.h:110
 hparticlecand.h:111
 hparticlecand.h:112
 hparticlecand.h:113
 hparticlecand.h:114
 hparticlecand.h:115
 hparticlecand.h:116
 hparticlecand.h:117
 hparticlecand.h:118
 hparticlecand.h:119
 hparticlecand.h:120
 hparticlecand.h:121
 hparticlecand.h:122
 hparticlecand.h:123
 hparticlecand.h:124
 hparticlecand.h:125
 hparticlecand.h:126
 hparticlecand.h:127
 hparticlecand.h:128
 hparticlecand.h:129
 hparticlecand.h:130
 hparticlecand.h:131
 hparticlecand.h:132
 hparticlecand.h:133
 hparticlecand.h:134
 hparticlecand.h:135
 hparticlecand.h:136
 hparticlecand.h:137
 hparticlecand.h:138
 hparticlecand.h:139
 hparticlecand.h:140
 hparticlecand.h:141
 hparticlecand.h:142
 hparticlecand.h:143
 hparticlecand.h:144
 hparticlecand.h:145
 hparticlecand.h:146
 hparticlecand.h:147
 hparticlecand.h:148
 hparticlecand.h:149
 hparticlecand.h:150
 hparticlecand.h:151
 hparticlecand.h:152
 hparticlecand.h:153
 hparticlecand.h:154
 hparticlecand.h:155
 hparticlecand.h:156
 hparticlecand.h:157
 hparticlecand.h:158
 hparticlecand.h:159
 hparticlecand.h:160
 hparticlecand.h:161
 hparticlecand.h:162
 hparticlecand.h:163
 hparticlecand.h:164
 hparticlecand.h:165
 hparticlecand.h:166
 hparticlecand.h:167
 hparticlecand.h:168
 hparticlecand.h:169
 hparticlecand.h:170
 hparticlecand.h:171
 hparticlecand.h:172
 hparticlecand.h:173
 hparticlecand.h:174
 hparticlecand.h:175
 hparticlecand.h:176
 hparticlecand.h:177
 hparticlecand.h:178
 hparticlecand.h:179
 hparticlecand.h:180
 hparticlecand.h:181
 hparticlecand.h:182
 hparticlecand.h:183
 hparticlecand.h:184
 hparticlecand.h:185
 hparticlecand.h:186
 hparticlecand.h:187
 hparticlecand.h:188
 hparticlecand.h:189
 hparticlecand.h:190
 hparticlecand.h:191
 hparticlecand.h:192
 hparticlecand.h:193
 hparticlecand.h:194
 hparticlecand.h:195
 hparticlecand.h:196
 hparticlecand.h:197
 hparticlecand.h:198
 hparticlecand.h:199
 hparticlecand.h:200
 hparticlecand.h:201
 hparticlecand.h:202
 hparticlecand.h:203
 hparticlecand.h:204
 hparticlecand.h:205
 hparticlecand.h:206
 hparticlecand.h:207
 hparticlecand.h:208
 hparticlecand.h:209
 hparticlecand.h:210
 hparticlecand.h:211
 hparticlecand.h:212
 hparticlecand.h:213
 hparticlecand.h:214
 hparticlecand.h:215
 hparticlecand.h:216
 hparticlecand.h:217
 hparticlecand.h:218
 hparticlecand.h:219
 hparticlecand.h:220
 hparticlecand.h:221
 hparticlecand.h:222
 hparticlecand.h:223
 hparticlecand.h:224
 hparticlecand.h:225
 hparticlecand.h:226
 hparticlecand.h:227
 hparticlecand.h:228
 hparticlecand.h:229
 hparticlecand.h:230
 hparticlecand.h:231
 hparticlecand.h:232
 hparticlecand.h:233
 hparticlecand.h:234
 hparticlecand.h:235
 hparticlecand.h:236
 hparticlecand.h:237
 hparticlecand.h:238
 hparticlecand.h:239
 hparticlecand.h:240
 hparticlecand.h:241
 hparticlecand.h:242
 hparticlecand.h:243
 hparticlecand.h:244
 hparticlecand.h:245
 hparticlecand.h:246
 hparticlecand.h:247
 hparticlecand.h:248
 hparticlecand.h:249
 hparticlecand.h:250
 hparticlecand.h:251
 hparticlecand.h:252
 hparticlecand.h:253
 hparticlecand.h:254
 hparticlecand.h:255
 hparticlecand.h:256
 hparticlecand.h:257
 hparticlecand.h:258
 hparticlecand.h:259
 hparticlecand.h:260
 hparticlecand.h:261
 hparticlecand.h:262
 hparticlecand.h:263
 hparticlecand.h:264
 hparticlecand.h:265
 hparticlecand.h:266
 hparticlecand.h:267
 hparticlecand.h:268
 hparticlecand.h:269
 hparticlecand.h:270
 hparticlecand.h:271
 hparticlecand.h:272
 hparticlecand.h:273
 hparticlecand.h:274
 hparticlecand.h:275
 hparticlecand.h:276
 hparticlecand.h:277
 hparticlecand.h:278
 hparticlecand.h:279
 hparticlecand.h:280
 hparticlecand.h:281
 hparticlecand.h:282
 hparticlecand.h:283
 hparticlecand.h:284
 hparticlecand.h:285
 hparticlecand.h:286
 hparticlecand.h:287
 hparticlecand.h:288
 hparticlecand.h:289
 hparticlecand.h:290
 hparticlecand.h:291
 hparticlecand.h:292
 hparticlecand.h:293
 hparticlecand.h:294
 hparticlecand.h:295
 hparticlecand.h:296
 hparticlecand.h:297
 hparticlecand.h:298
 hparticlecand.h:299
 hparticlecand.h:300
 hparticlecand.h:301
 hparticlecand.h:302
 hparticlecand.h:303
 hparticlecand.h:304
 hparticlecand.h:305
 hparticlecand.h:306
 hparticlecand.h:307
 hparticlecand.h:308
 hparticlecand.h:309
 hparticlecand.h:310
 hparticlecand.h:311
 hparticlecand.h:312
 hparticlecand.h:313
 hparticlecand.h:314
 hparticlecand.h:315
 hparticlecand.h:316
 hparticlecand.h:317
 hparticlecand.h:318
 hparticlecand.h:319
 hparticlecand.h:320
 hparticlecand.h:321
 hparticlecand.h:322
 hparticlecand.h:323
 hparticlecand.h:324
 hparticlecand.h:325
 hparticlecand.h:326
 hparticlecand.h:327
 hparticlecand.h:328
 hparticlecand.h:329
 hparticlecand.h:330
 hparticlecand.h:331
 hparticlecand.h:332
 hparticlecand.h:333
 hparticlecand.h:334
 hparticlecand.h:335
 hparticlecand.h:336
 hparticlecand.h:337
 hparticlecand.h:338
 hparticlecand.h:339
 hparticlecand.h:340
 hparticlecand.h:341
 hparticlecand.h:342
 hparticlecand.h:343
 hparticlecand.h:344
 hparticlecand.h:345
 hparticlecand.h:346
 hparticlecand.h:347
 hparticlecand.h:348
 hparticlecand.h:349
 hparticlecand.h:350
 hparticlecand.h:351
 hparticlecand.h:352
 hparticlecand.h:353
 hparticlecand.h:354
 hparticlecand.h:355
 hparticlecand.h:356
 hparticlecand.h:357
 hparticlecand.h:358
 hparticlecand.h:359
 hparticlecand.h:360
 hparticlecand.h:361
 hparticlecand.h:362
 hparticlecand.h:363
 hparticlecand.h:364
 hparticlecand.h:365
 hparticlecand.h:366
 hparticlecand.h:367
 hparticlecand.h:368
 hparticlecand.h:369
 hparticlecand.h:370
 hparticlecand.h:371
 hparticlecand.h:372
 hparticlecand.h:373
 hparticlecand.h:374
 hparticlecand.h:375
 hparticlecand.h:376
 hparticlecand.h:377
 hparticlecand.h:378
 hparticlecand.h:379
 hparticlecand.h:380
 hparticlecand.h:381
 hparticlecand.h:382
 hparticlecand.h:383
 hparticlecand.h:384
 hparticlecand.h:385
 hparticlecand.h:386
 hparticlecand.h:387
 hparticlecand.h:388
 hparticlecand.h:389
 hparticlecand.h:390
 hparticlecand.h:391
 hparticlecand.h:392
 hparticlecand.h:393
 hparticlecand.h:394
 hparticlecand.h:395
 hparticlecand.h:396
 hparticlecand.h:397
 hparticlecand.h:398
 hparticlecand.h:399
 hparticlecand.h:400
 hparticlecand.h:401
 hparticlecand.h:402
 hparticlecand.h:403
 hparticlecand.h:404
 hparticlecand.h:405
 hparticlecand.h:406
 hparticlecand.h:407
 hparticlecand.h:408
 hparticlecand.h:409
 hparticlecand.h:410
 hparticlecand.h:411
 hparticlecand.h:412
 hparticlecand.h:413
 hparticlecand.h:414
 hparticlecand.h:415
 hparticlecand.h:416
 hparticlecand.h:417
 hparticlecand.h:418
 hparticlecand.h:419
 hparticlecand.h:420
 hparticlecand.h:421
 hparticlecand.h:422
 hparticlecand.h:423
 hparticlecand.h:424
 hparticlecand.h:425
 hparticlecand.h:426
 hparticlecand.h:427
 hparticlecand.h:428
 hparticlecand.h:429
 hparticlecand.h:430
 hparticlecand.h:431
 hparticlecand.h:432
 hparticlecand.h:433
 hparticlecand.h:434
 hparticlecand.h:435
 hparticlecand.h:436
 hparticlecand.h:437
 hparticlecand.h:438
 hparticlecand.h:439
 hparticlecand.h:440
 hparticlecand.h:441
 hparticlecand.h:442
 hparticlecand.h:443
 hparticlecand.h:444
 hparticlecand.h:445
 hparticlecand.h:446
 hparticlecand.h:447
 hparticlecand.h:448
 hparticlecand.h:449
 hparticlecand.h:450
 hparticlecand.h:451
 hparticlecand.h:452
 hparticlecand.h:453
 hparticlecand.h:454
 hparticlecand.h:455
 hparticlecand.h:456
 hparticlecand.h:457