#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;
Char_t fPID;
Short_t fSector;
Short_t fSystem;
UShort_t fRingCorr;
Short_t fIndex;
SmallFloat fDistanceToMetaHit;
SmallFloat fMdcdEdx;
SmallFloat fTofdEdx;
SmallFloat fInnerSegmentChi2;
SmallFloat fOuterSegmentChi2;
SmallFloat fAngleToNearbyFittedInner;
SmallFloat fAngleToNearbyUnfittedInner;
Char_t fRingNumPads;
Short_t fRingAmplitude;
Short_t fRingHouTra;
Short_t fRingPatternMatrix;
SmallFloat fRingCentroid;
SmallFloat fRichPhi;
SmallFloat fRichTheta;
Float_t fRingChi2;
SmallFloat fMetaMatchQuality;
SmallFloat fMetaMatchQualityShower;
SmallFloat fMetaMatchRadius;
SmallFloat fMetaMatchRadiusShower;
SmallFloat fRkMetaDx;
SmallFloat fRkMetaDy;
SmallFloat fRkMetaDxShower;
SmallFloat fRkMetaDyShower;
SmallFloat fBetaOrg;
SmallFloat fMomentumOrg;
SmallFloat fDistanceToMetaHitOrg;
SmallFloat fShowerSum0;
SmallFloat fShowerSum1;
SmallFloat fShowerSum2;
UShort_t fEmcFlags;
Char_t fSelectedMeta;
Short_t fMetaInd;
Short_t fRichInd;
Short_t fRichBTInd;
Short_t fInnerSegInd;
Short_t fOuterSegInd;
Short_t fRpcInd;
Short_t fShowerInd;
Short_t fTofHitInd;
Short_t fTofClstInd;
UInt_t fLayers;
UShort_t fWires;
UInt_t fmetaAddress;
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() {}
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; }
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; }
void setRingChi2(Float_t c) { fRingChi2 = c; }
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;}
void setMetaMatchRadius(Float_t q) { fMetaMatchRadius = q; }
void setMetaMatchRadiusShower(Float_t q) { fMetaMatchRadiusShower = q; }
void setMetaMatchRadiusEmc(Float_t q) { fMetaMatchRadiusShower = q; }
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; }
void setEmcTime(Float_t t) { fShowerSum1 = t; }
void setEmcCellPath(Float_t t) { fShowerSum2 = t; }
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; }
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; }
Float_t getRingChi2() const { return fRingChi2; }
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;}
Float_t getMetaMatchRadius() const { return fMetaMatchRadius; }
Float_t getMetaMatchRadiusShower() const { return fMetaMatchRadiusShower;}
Float_t getMetaMatchRadiusEmc() const { return fMetaMatchRadiusShower;}
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; }
Float_t getEmcTime() const { return fShowerSum1; }
Float_t getEmcCellPath() const { return fShowerSum2; }
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;}
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; }
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;
return -1;
}
Float_t getDeltaTheta(){ return (fRichInd ==-1) ? -1000 : fRichTheta - fTheta; }
Float_t getDeltaPhi() {
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);
}
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)
};
#endif // __HPARTICLECAND_H__