using namespace std;
#include "TArrayI.h"
#include "hpidgeanttrackset.h"
#include "hshowerhittof.h"
#include "hshowerhittoftrack.h"
#include "hmetamatch.h"
#include "hpidfl.h"
#include "hlinearcategory.h"
#include "hpidtrackcand.h"
#include "hmdctrkcand.h"
#include "hmdcsegsim.h"
#include "hrichhitsim.h"
#include "hrichhitIPUSim.h"
#include "htofhitsim.h"
#include "htofclustersim.h"
#include "TError.h"
#include <map>
#include "hgeantdef.h"
#include "hgeantkine.h"
#include "hgeanttof.h"
#include "hpidphysicsconstants.h"
ClassImp(HPidGeantTrackSet)
Int_t HPidGeantTrackSet::nullparent=0;
HPidGeantTrackSet::HPidGeantTrackSet(const HPidGeantTrackSet& source)
{
isSorted = source.isSorted;
sNCorrTrackIds = source.getNCorrelatedTrackIds();
nRICHTracks = source.getNRichTracks();
nRICHIPUTracks = source.getNRichIPUTracks();
nInnerMdcTracks = source.getNInnerMdcTracks();
nOuterMdcTracks = source.getNOuterMdcTracks();
nShowerTracks = source.getNShowerTracks();
nTOFTracks = source.getNTOFTracks();
bIsLepFromPrimary = source.getPrimaryFlag();
correlatedTrackIds.Set(sNCorrTrackIds);
correlationFlags.Set(sNCorrTrackIds);
ProcessIds.Set(sNCorrTrackIds);
ParentIds.Set(sNCorrTrackIds);
Parents.Set(sNCorrTrackIds);
GrandParentIds.Set(sNCorrTrackIds);
GrandParents.Set(sNCorrTrackIds);
GenInfo.Set(sNCorrTrackIds);
GenInfo1.Set(sNCorrTrackIds);
GenInfo2.Set(sNCorrTrackIds);
GenWeight.Set(sNCorrTrackIds);
VertexX.Set(sNCorrTrackIds);
VertexY.Set(sNCorrTrackIds);
VertexZ.Set(sNCorrTrackIds);
GeantPIDs.Set(sNCorrTrackIds);
MediumIds.Set(sNCorrTrackIds);
GeantMomX.Set(sNCorrTrackIds);
GeantMomY.Set(sNCorrTrackIds);
GeantMomZ.Set(sNCorrTrackIds);
ShowerWeights.Set(sNCorrTrackIds);
TOFWeights.Set(sNCorrTrackIds);
RICHWeights.Set(sNCorrTrackIds);
RICHIPUWeights.Set(sNCorrTrackIds);
InnerMDCWeights.Set(sNCorrTrackIds);
OuterMDCWeights.Set(sNCorrTrackIds);
hasHitInShower.Set(sNCorrTrackIds);
hasHitInTOF.Set(sNCorrTrackIds);
for(Int_t i=0;i<sNCorrTrackIds;i++)
{
correlatedTrackIds[i]=source.getGeantTrackID(i);
correlationFlags[i]=source.getCorrelationFlag(i);
ProcessIds[i]=source.getGeantProcessID(i);
ParentIds[i]=source.getGeantParentID(i);
Parents[i]=source.getGeantParentTrackID(i);
GrandParentIds[i]=source.getGeantGrandParentID(i);
GrandParents[i]=source.getGeantGrandParentTrackID(i);
GenInfo[i]=source.getGenInfo(i);
GenInfo1[i]=source.getGenInfo1(i);
GenInfo2[i]=source.getGenInfo2(i);
GenWeight[i]=source.getGenWeight(i);
VertexX[i]=source.getGeantVertexX(i);
VertexY[i]=source.getGeantVertexY(i);
VertexZ[i]=source.getGeantVertexZ(i);
GeantPIDs[i]=source.getGeantPID(i);
MediumIds[i]=source.getGeantMediumID(i);
GeantMomX[i]=source.getGeantMomX(i);
GeantMomY[i]=source.getGeantMomY(i);
GeantMomZ[i]=source.getGeantMomZ(i);
ShowerWeights[i]=source.getShowerWeight(i);
TOFWeights[i]=source.getTOFWeight(i);
RICHWeights[i]=source.getRichWeight(i);
RICHIPUWeights[i]=source.getRichIPUWeight(i);
InnerMDCWeights[i]=source.getInnerMdcWeight(i);
OuterMDCWeights[i]=source.getOuterMdcWeight(i);
hasHitInShower[i]=source.hasHitInShower[i];
hasHitInTOF[i]=source.hasHitInTOF[i];
}
}
void HPidGeantTrackSet::reset(void)
{
Clear();
}
Bool_t HPidGeantTrackSet::wasSeenInDetector(const UInt_t flag, const UInt_t detector,Bool_t verbose) const
{
if(verbose)
{
cout << "Testing function input : detector=" <<detector<<" flag="<<flag <<endl;
cout << "Output: " << (detector & flag)<<endl;
}
if((detector & flag)==detector)
{
if(verbose){
cout <<" same" <<endl;
}
return kTRUE;
}
if(verbose)
{cout << "detector: " << detector<<endl;
cout << "flag:" <<flag << endl;
}
return kFALSE;
}
Short_t HPidGeantTrackSet::getRichTrack(UInt_t iIdx) const
{
if( iIdx >= nRICHTracks)
{
::Error("HPidGeantTrackSet::getRichTrack","index for rich track greater than number of contributing particles in ring");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if(wasSeenInDetector(correlationFlags[i], kSeenInRICH))
{
if (counter==iIdx) return correlatedTrackIds[i];
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getRichIPUTrack(UInt_t iIdx) const
{
if( iIdx >= nRICHIPUTracks)
{
::Error("HPidGeantTrackSet::getRichIPUTrack","index for rich ipu track greater than number of contributing particles in IPU ring");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInRICHIPU))
{
if (counter==iIdx) return correlatedTrackIds[i];
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getInnerMdcTrack(UInt_t iIdx) const
{
if( iIdx >= nInnerMdcTracks)
{
::Error("HPidGeantTrackSet::getInnerMdcTrack","index for inner mdc track greater than number of contributing particles in inner mdc");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInInnerMDC))
{
if (counter==iIdx) return correlatedTrackIds[i];
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getOuterMdcTrack(UInt_t iIdx) const
{
if( iIdx >= nOuterMdcTracks)
{
::Error("HPidGeantTrackSet::getOutMdcTrack","index for outer mdc track greater than number of contributing particles in outer mdc");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInOuterMDC))
{
if (counter==iIdx) return correlatedTrackIds[i];
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getTOFTrack(UInt_t iIdx) const
{
if( iIdx >= nTOFTracks)
{
::Error("HPidGeantTrackSet::getTOFTrack","index for TOF track greater than number of contributing particles in TOF");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInMETA) && hasHitInTOF.At(i)>0)
{
if (counter==iIdx)
{
return correlatedTrackIds[i];
}
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getShowerTrack(UInt_t iIdx) const
{
if( iIdx >= nShowerTracks)
{
::Error("HPidGeantTrackSet::getShowerTrack","index for Shower track greater than number of contributing particles in Shower");
return kOutOfBound;
}
UInt_t counter = 0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInMETA) && hasHitInShower.At(i)>0)
{
if (counter==iIdx)
{
return correlatedTrackIds[i];
}
counter++;
}
}
return kOutOfBound;
}
Short_t HPidGeantTrackSet::getMetaTrack(UInt_t iIdx) const
{
if(nTOFTracks>0 && nShowerTracks>0)
{
UInt_t counter = 0;
if(iIdx >= getNMetaTracks())
{
::Error("HPidGeantTrackSet::getMEtaTrack",
"index for Meta track greater than number of contributing particles in Meta");
return kOutOfBound;
}
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInMETA))
{
if (counter==iIdx) return correlatedTrackIds[i];
counter++;
}
}
return kOutOfBound;
}
return kOutOfBound;
}
HGeantKine* HPidGeantTrackSet::getGeantKine(Int_t iTrack, HCategory *pCat)
{
if(iTrack <= 0)
return NULL;
if((pCat == NULL) && ((pCat = HPidFL::getCategory(
catGeantKine, kFALSE)) == NULL))
{
::Error("HPidGeantTrackSet::getGeantKine", "No catGeantKine category");
return NULL;
}
HGeantKine *pKine;
Int_t iT, iMin, iMax, iC, iP;
if((iMax = pCat->getEntries()) <= 0)
return NULL;
if((iMax > iTrack - 1)
&& (pKine = (HGeantKine *) pCat->getObject(iTrack - 1)) != NULL)
{
pKine->getParticle(iT, iP);
if(iT == iTrack)
return pKine;
}
iMin = -1;
do
{
iC = (iMax + iMin) / 2;
if((pKine = (HGeantKine *) pCat->getObject(iC)) == NULL)
{
::Error("HPidGeantTrackSet::getGeantKine",
"Hole in HGeantKine branch (%d)", iC);
return NULL;
}
pKine->getParticle(iT, iP);
if(iT == iTrack)
return pKine;
if(iTrack < iT)
iMax = iC;
else
iMin = iC;
} while(iMax - iMin > 1);
return NULL;
}
void HPidGeantTrackSet::swapVectors(Int_t i, Int_t j)
{
swap(i,j,correlatedTrackIds);
swap(i,j,correlationFlags);
swap(i,j,ProcessIds);
swap(i,j,ParentIds);
swap(i,j,Parents);
swap(i,j,GrandParentIds);
swap(i,j,GrandParents);
swap(i,j,GenInfo);
swap(i,j,GenInfo1);
swap(i,j,GenInfo2);
swap(i,j,GenWeight);
swap(i,j,VertexX);
swap(i,j,VertexY);
swap(i,j,VertexZ);
swap(i,j,GeantPIDs);
swap(i,j,MediumIds);
swap(i,j,GeantMomX);
swap(i,j,GeantMomY);
swap(i,j,GeantMomZ);
swap(i,j,ShowerWeights);
swap(i,j,TOFWeights);
swap(i,j,RICHWeights);
swap(i,j,RICHIPUWeights);
swap(i,j,InnerMDCWeights);
swap(i,j,OuterMDCWeights);
swap(i,j,hasHitInShower);
swap(i,j,hasHitInTOF);
}
void HPidGeantTrackSet::swap(Int_t i, Int_t j, TArrayI& array)
{
Int_t tmp = array[i];
array[i]=array[j];
array[j]=tmp;
}
void HPidGeantTrackSet::swap(Int_t i, Int_t j, TArrayF& array)
{
Float_t tmp = array[i];
array[i]=array[j];
array[j]=tmp;
}
void HPidGeantTrackSet::sortsmart(void)
{
bringCorrelatedDetectorsToFront();
sortCorrelatedDetectors();
sortSingleDetectors();
isSorted=kTRUE;
}
void HPidGeantTrackSet::bringCorrelatedDetectorsToFront()
{
for(Int_t i = 0;i<sNCorrTrackIds;i++)
{
if(!isSingleDetector(correlationFlags[i]))
{
continue;
}
else
{
for(Int_t j=i+1; j<sNCorrTrackIds;j++)
{
if(!isSingleDetector(correlationFlags[j]))
{
swapVectors(i,j);
break;
}
}
}
}
}
void HPidGeantTrackSet::sortCorrelatedDetectors()
{
Short_t currentMaxPosition=0;
Int_t currentMax=0;
for(Int_t i = 0;i<sNCorrTrackIds;i++)
{
if(isSingleDetector(correlationFlags[i]))
{
break;
}
currentMaxPosition=i;
currentMax=correlationFlags[i];
for(Int_t j=i+1;j<sNCorrTrackIds;j++)
{
if(isSingleDetector(correlationFlags[j]))
{
break;
}
if(correlationFlags[j]>currentMax )
{
currentMaxPosition=j;
currentMax=correlationFlags[j];
}
}
if(i!=currentMaxPosition) swapVectors(i,currentMaxPosition);
}
}
void HPidGeantTrackSet::sortSingleDetectors()
{
Short_t currentMaxPosition=0;
Int_t currentMax=0;
for(Int_t i = 0;i<sNCorrTrackIds;i++)
{
if(!isSingleDetector(correlationFlags[i]))
{
continue;
}
currentMaxPosition=i;
currentMax=correlationFlags[i];
for(Int_t j=i+1;j<sNCorrTrackIds;j++)
{
if(correlationFlags[j]>currentMax )
{
currentMaxPosition=j;
currentMax=correlationFlags[j];
}
}
if(i!=currentMaxPosition) swapVectors(i,currentMaxPosition);
}
}
Bool_t HPidGeantTrackSet::isSingleDetector(UInt_t flag)
{
if(flag==kSeenInRICH ||
flag==kSeenInRICHIPU ||
flag==kSeenInInnerMDC ||
flag==kSeenInOuterMDC ||
flag==kSeenInMETA)
return kTRUE;
return kFALSE;
}
Bool_t HPidGeantTrackSet::getMomentumComponents(Float_t& momx, Float_t& momy, Float_t& momz, Int_t index)
{
if(index>sNCorrTrackIds-1){
::Error("HPidGeanTrackSet::getMomentumComponents","requested momenta for particle beyond index!");
momx=-1.0;
momy=-1.0;
momz=-1.0;
return kFALSE;
}
momx=GeantMomX[index];
momy=GeantMomY[index];
momz=GeantMomZ[index];
return kTRUE;
}
Float_t HPidGeantTrackSet::getTotalMomentum(Int_t index) const
{
if(index>sNCorrTrackIds-1){
::Error("HPidGeantTrackSet::getTotalMomentum","requested momentum for particle beyond index!");
return kFALSE;
}
Float_t totalMomentum=GeantMomX[index]*GeantMomX[index]+GeantMomY[index]*GeantMomY[index]+GeantMomZ[index]*GeantMomZ[index];
return sqrt(totalMomentum);
}
void HPidGeantTrackSet::fillFromMetaMatch(HMetaMatch* pMetaMatch)
{
Bool_t debugoutput=kFALSE;
HMdcSegSim* pInnerMdcSeg=NULL;
HMdcSegSim* pOuterMdcSeg=NULL;
HRichHitSim* pRichHit=NULL;
HRichHitIPUSim* pRichHitIPU=NULL;
HShowerHitTofTrack* pShwTof = NULL;
HTofHitSim* pTofHitSim=NULL;
HTofClusterSim* pTofClsSim=NULL;
HMdcTrkCand* pTrkCand = NULL;
reset();
Int_t i=0;
if(debugoutput) cout << "Starting to fill geant info!"<<endl;
if(pMetaMatch->getSystem()==0)
{
if(debugoutput) cout << "System is ShowerTofino";
pShwTof = HPidFL::getShowerHitTofTrack(pMetaMatch->getShowerHitInd());
if(pShwTof != NULL)
{
Int_t nTr = pShwTof->getNTracks();
for(Int_t i = 0; i < nTr; i ++)
{
if(pShwTof->getTrack(i) >= 0 || pShwTof->getTrack(i) == gHades->getEmbeddingRealTrackId())
{
nShowerTracks++;
addToContributingTracks(pShwTof->getTrack(i),kSeenInShower);
addTrackWeightToDetector(1.0/nTr,pShwTof->getTrack(i),kSeenInShower);
if(debugoutput&&sNCorrTrackIds) cout <<"Geant Track id in Shower: " << pShwTof->getTrack(i)<<endl;
}
else
{
::Error("HPidGeantTrackSet::fillFromMetaMatch","Shower hit does not have valid geant track id");
}
}
} else {
::Error("HPidGeantTrackSet::fillFromMetaMatch","System 0 marked in MetaMatch object, but no Hit with corresponding index");
}
}
if(pMetaMatch->getSystem()==1)
{
if(debugoutput) cout << "System is Tof" << endl;
Int_t nClsSize = (Int_t)pMetaMatch->getTofClusterSize();
Int_t nTrc0=-1;
Int_t nTrc1=-1;
if( nClsSize <= 0 )
{
pTofHitSim = HPidFL::getTofHitSim(pMetaMatch->getMetaHitInd());
if(NULL!=pTofHitSim)
{
nTrc0 = pTofHitSim ->getNTrack1();
nTrc1 = pTofHitSim ->getNTrack2();
if(nTrc1==-1){nTrc1=nTrc0;}
Int_t mode=2;
Int_t count =0;
Int_t tempTrack;
tempTrack=findFirstHitInTof(nTrc0,&count,mode);
if (nTrc0 != nTrc1){
count =0;
nTrc1=findFirstHitInTof(nTrc1,&count,mode);
}
else {nTrc1=tempTrack;}
nTrc0=tempTrack;
if( nTrc0 == nTrc1 && ( nTrc0 >0 || nTrc0==gHades->getEmbeddingRealTrackId() ))
{
nTOFTracks++;
addToContributingTracks(nTrc0,kSeenInTOF);
addTrackWeightToDetector(1.0,nTrc0,kSeenInTOF);
}
if( nTrc0 != nTrc1 && ( nTrc1 >0 || nTrc1==gHades->getEmbeddingRealTrackId() ))
{
nTOFTracks++;
addToContributingTracks(nTrc0,kSeenInTOF);
addTrackWeightToDetector(0.5,nTrc0,kSeenInTOF);
nTOFTracks++;
addToContributingTracks(nTrc1,kSeenInTOF);
addTrackWeightToDetector(0.5,nTrc1,kSeenInTOF);
#warning The computation of track weights in TOF needs to be checked
}
}
else
{
::Error("HPidGeantTrackSet::fillFromMetaMatch","System 1 marked in MetaMatch object, but no Hit with corresponding index");
}
}
else if ( nClsSize >= 1 )
{
pTofClsSim = HPidFL::getTofClusterSim(pMetaMatch->getMetaHitInd());
if(NULL!=pTofClsSim)
{
std::map<int,int> m;
std::map<int,int>::iterator pos;
for(Int_t i=0;i<pTofClsSim->getNParticipants()&&i<3;i++)
{
nTrc0 = pTofClsSim ->getNTrack1(i);
nTrc1 = pTofClsSim ->getNTrack2(i);
if(nTrc0==-1 && nTrc1==-1)
{
continue;
}
if(nTrc1==-1){nTrc1=nTrc0;}
Int_t mode =2;
Int_t count=0;
nTrc0=findFirstHitInTof(nTrc0,&count,mode);
nTrc1=findFirstHitInTof(nTrc1,&count,mode);
if (nTrc0 != nTrc1){
if((pos=m.find(nTrc0))!=m.end()){
pos->second ++;
} else {
m.insert(make_pair(nTrc0,1));}
if((pos=m.find(nTrc1))!=m.end()){
pos->second ++;
} else {
m.insert(make_pair(nTrc1,1));}
}
else {
if((pos=m.find(nTrc0))!=m.end()){
pos->second ++;
} else {m.insert(make_pair(nTrc0,1));}
};
}
Int_t nTimesSum=0;
for(pos = m.begin(); pos != m.end(); ++pos){
nTimesSum+=pos->second;
}
for(pos = m.begin(); pos != m.end(); ++pos){
nTOFTracks++;
addToContributingTracks(pos->first,kSeenInTOF);
addTrackWeightToDetector(pos->second/(Float_t)(nTimesSum),pos->first,kSeenInTOF);
}
}
else
{
::Error("HPidGeantTrackSet::fillFromMetaMatch","System 1 marked in MetaMatch object, but no Hit with corresponding index");
}
}
else
{
Warning("fillFromMetaMatch",
"What should I do with cluster size=%d?", nClsSize);
}
if(nTOFTracks==0)
{
::Error("fillFromMetaMatch","Should be at least one track in TOF!");
}
}
if(debugoutput&&sNCorrTrackIds) {cout << "Corrflag for track " << correlatedTrackIds[0] <<" after meta: " <<correlationFlags[0] << endl;}
if(pMetaMatch->getTrkCandInd()>-1)
{
pTrkCand = HPidFL::getMdcTrkCand(pMetaMatch->getTrkCandInd());
}
if(pTrkCand == NULL)
{
Warning("getGeantTrackSet", "no track cand: tracks should be taken"
" from HMdcSegs, but this is not implemented");
Warning("getGeantTrackSet", "no track cand found but index given!");
}
else
{
if(debugoutput) cout << "Track Candidate index:" << pMetaMatch->getTrkCandInd() << endl;
if(pTrkCand->getSeg1Ind()>-1)
pInnerMdcSeg = HPidFL::getMdcSegSim(pTrkCand->getSeg1Ind());
if(pTrkCand->getSeg2Ind()>-1)
pOuterMdcSeg = HPidFL::getMdcSegSim(pTrkCand->getSeg2Ind());
if(debugoutput) cout << "Inner segment index:" << pTrkCand->getSeg1Ind() <<endl;
if(debugoutput) cout << "Outer segment index:" << pTrkCand->getSeg2Ind() <<endl;
Int_t nDriftTimes=0;
Float_t weight=0;
nInnerMdcTracks=0;
if(pInnerMdcSeg != NULL)
{
for(i = 0; i < pInnerMdcSeg->getNTracks(); i++)
{
if(pInnerMdcSeg->getTrack(i) < 1 &&
pInnerMdcSeg->getTrack(i) != gHades->getEmbeddingRealTrackId() ) continue;
nDriftTimes+=pInnerMdcSeg->getNTimes(i);
nInnerMdcTracks++;
addToContributingTracks(pInnerMdcSeg->getTrack(i), kSeenInInnerMDC);
if(debugoutput) cout << "Geant Track ID number " << i << "in inner Segment is " << pInnerMdcSeg->getTrack(i) << endl;
}
for( i = 0; i < pInnerMdcSeg->getNTracks(); i++)
{
if(pInnerMdcSeg->getTrack(i) < 1 &&
pInnerMdcSeg->getTrack(i) != gHades->getEmbeddingRealTrackId() ) continue;
weight=(Float_t)pInnerMdcSeg->getNTimes(i)/(Float_t)nDriftTimes;
if(weight==-1) ::Error("HPidGeantTrackSet::fillFromMetaMatch","negative MDC segment weight");
addTrackWeightToDetector(weight,pInnerMdcSeg->getTrack(i),kSeenInInnerMDC);
}
}
else
{
::Error("HPidGeantTrackSet::fillFromMetaMatch","No inner segment in this trk cand!");
}
if(debugoutput&&sNCorrTrackIds) {cout << "Corrflag for track " << correlatedTrackIds[0] <<" after mdc1: " <<correlationFlags[0] << endl;}
nDriftTimes=0;
nOuterMdcTracks=0;
if(pOuterMdcSeg != NULL)
{
for(i = 0; i < pOuterMdcSeg->getNTracks(); i++)
{
if(pOuterMdcSeg->getTrack(i) < 1 &&
pOuterMdcSeg->getTrack(i) != gHades->getEmbeddingRealTrackId() ) continue;
nDriftTimes+=pOuterMdcSeg->getNTimes(i);
nOuterMdcTracks++;
addToContributingTracks(pOuterMdcSeg->getTrack(i),kSeenInOuterMDC);
if(debugoutput) cout << "Geant Track ID number " << i << "in outer Segment is " << pOuterMdcSeg->getTrack(i) << endl;
}
for(i = 0; i < pOuterMdcSeg->getNTracks(); i++)
{
if(pOuterMdcSeg->getTrack(i) < 1 &&
pOuterMdcSeg->getTrack(i) != gHades->getEmbeddingRealTrackId() ) continue;
weight=(Float_t)pOuterMdcSeg->getNTimes(i)/(Float_t)nDriftTimes;
if(weight==-1) ::Error("HPidGeantTrackSet::fillFromMetaMatch","negative MDC segment weight");
addTrackWeightToDetector(weight,pOuterMdcSeg->getTrack(i),kSeenInOuterMDC);
}
}
}
if(debugoutput&&sNCorrTrackIds) {cout << "Corrflag for track " << correlatedTrackIds[0] <<" after mdc2: " <<correlationFlags[0] << endl;}
if(pMetaMatch->getARichInd(0)>-1)
{
pRichHit = HPidFL::getRichHitSim(pMetaMatch->getARichInd(0));
if(pRichHit==NULL)
::Error("HPidGeantTrackSet::fillFromMetaMatch","Warning! NO rich hit for given index!");
}
if(pRichHit != NULL)
{
if(debugoutput) cout << "rich hit found"<<endl;
i = 0;
Float_t npads =(Float_t)(pRichHit->weigTrack1 + pRichHit->weigTrack2 + pRichHit->weigTrack3);
if(pRichHit->weigTrack1 > 0.0 && (pRichHit->track1>0 || pRichHit->track1==gHades->getEmbeddingRealTrackId()))
{
nRICHTracks++;
addToContributingTracks(pRichHit->track1, kSeenInRICH);
addTrackWeightToDetector((Float_t)(pRichHit->weigTrack1)/npads,pRichHit->track1,kSeenInRICH);
if(debugoutput) cout << "Geant Track ID number 1 in RICH is " << pRichHit->track1 << endl;
}
if(pRichHit->weigTrack2 > 0.0 && (pRichHit->track2>0 || pRichHit->track2==gHades->getEmbeddingRealTrackId()))
{
if(debugoutput) cout << "second track id found - booking it" << endl;
nRICHTracks++;
addToContributingTracks(pRichHit->track2, kSeenInRICH);
addTrackWeightToDetector((Float_t)(pRichHit->weigTrack2)/npads,pRichHit->track2,kSeenInRICH);
if(debugoutput) cout << "Geant Track ID number 2 in RICH is " << pRichHit->track2 << endl;
}
if(pRichHit->weigTrack3 > 0.0 && (pRichHit->track3>0 || pRichHit->track3==gHades->getEmbeddingRealTrackId()))
{
if(debugoutput) cout << "third track id found - booking it" << endl;
nRICHTracks++;
addToContributingTracks(pRichHit->track3, kSeenInRICH);
addTrackWeightToDetector((Float_t)(pRichHit->weigTrack3)/npads,pRichHit->track3,kSeenInRICH);
if(debugoutput) cout << "Geant Track ID number 3 in RICH is " << pRichHit->track3 << endl;
}
}
if(debugoutput&&sNCorrTrackIds) {cout << "Corrflag for track " << correlatedTrackIds[0] <<" after rich: " <<correlationFlags[0] << endl;}
if(debugoutput) cout << "After RICH " << endl;
sortsmart();
checkPrimaryOrigin();
shrinkArrays();
diagnosis();
}
void HPidGeantTrackSet::checkPrimaryOrigin(void)
{
bIsLepFromPrimary=kFALSE;
if(GeantPIDs[0]!=2 && GeantPIDs[0]!=3)
return;
if(ParentIds[0]==0)
{
bIsLepFromPrimary=kTRUE;
return;
}
if(ParentIds[0]!=1)
{
if(GrandParents[0]==0)
{
bIsLepFromPrimary=kTRUE;
}
else
{
bIsLepFromPrimary=kFALSE;
}
return;
}
if(ParentIds[0]==1)
{
if(GrandParentIds[0]==0)
{
bIsLepFromPrimary=kTRUE;
return;
}
else
{
Int_t ggp_medium, ggp_process;
Int_t grandGrandParent=0;
HGeantKine* pKineGrandParent = getGeantKine(GrandParents[0]);
if(!pKineGrandParent)
{
Error("HPidGeantTrackSet::checkPrimaryOrigin(void)","GrandParent has no pointer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
pKineGrandParent->getCreator(grandGrandParent, ggp_medium,ggp_process);
if(grandGrandParent==0)
{
bIsLepFromPrimary=kTRUE;
}
else
{
bIsLepFromPrimary=kFALSE;
}
}
}
}
Int_t HPidGeantTrackSet::shrinkArrays(void)
{
correlatedTrackIds.Set(sNCorrTrackIds);
correlationFlags.Set(sNCorrTrackIds);
ProcessIds.Set(sNCorrTrackIds);
ParentIds.Set(sNCorrTrackIds);
Parents.Set(sNCorrTrackIds);
GrandParentIds.Set(sNCorrTrackIds);
GrandParents.Set(sNCorrTrackIds);
GenInfo.Set(sNCorrTrackIds);
GenInfo1.Set(sNCorrTrackIds);
GenInfo2.Set(sNCorrTrackIds);
GenWeight.Set(sNCorrTrackIds);
VertexX.Set(sNCorrTrackIds);
VertexY.Set(sNCorrTrackIds);
VertexZ.Set(sNCorrTrackIds);
GeantPIDs.Set(sNCorrTrackIds);
MediumIds.Set(sNCorrTrackIds);
GeantMomX.Set(sNCorrTrackIds);
GeantMomY.Set(sNCorrTrackIds);
GeantMomZ.Set(sNCorrTrackIds);
ShowerWeights.Set(sNCorrTrackIds);
TOFWeights.Set(sNCorrTrackIds);
RICHWeights.Set(sNCorrTrackIds);
RICHIPUWeights.Set(sNCorrTrackIds);
InnerMDCWeights.Set(sNCorrTrackIds);
OuterMDCWeights.Set(sNCorrTrackIds);
hasHitInShower.Set(sNCorrTrackIds);
hasHitInTOF.Set(sNCorrTrackIds);
return sNCorrTrackIds;
}
Int_t HPidGeantTrackSet::enlargeArrays(void)
{
Int_t newsize=correlatedTrackIds.GetSize()+1;
correlatedTrackIds.Set(newsize);
correlationFlags.Set(newsize);
ProcessIds.Set(newsize);
ParentIds.Set(newsize);
Parents.Set(newsize);
GrandParents.Set(newsize);
GrandParentIds.Set(newsize);
GenInfo.Set(newsize);
GenInfo1.Set(newsize);
GenInfo2.Set(newsize);
GenWeight.Set(newsize);
VertexX.Set(newsize);
VertexY.Set(newsize);
VertexZ.Set(newsize);
GeantPIDs.Set(newsize);
MediumIds.Set(newsize);
GeantMomX.Set(newsize);
GeantMomY.Set(newsize);
GeantMomZ.Set(newsize);
ShowerWeights.Set(newsize);
TOFWeights.Set(newsize);
RICHWeights.Set(newsize);
RICHIPUWeights.Set(newsize);
InnerMDCWeights.Set(newsize);
OuterMDCWeights.Set(newsize);
hasHitInShower.Set(newsize);
hasHitInTOF.Set(newsize);
return newsize;
}
void HPidGeantTrackSet::diagnosis()
{
if(getNCorrelatedTrackIds()>0)
{
for (UInt_t i =0;i<getNCorrelatedTrackIds()-1;i++)
{
UInt_t j;
j= i+1;
if(isSingleDetector(correlationFlags[i])==isSingleDetector(correlationFlags[j]))
{
if(correlationFlags[j]>correlationFlags[i])
{
Error("HPidGeantTrackSet::diagnosis()","Correlation-flag %d (%d) is bigger than flag %d (%d)",
j,correlationFlags[j],i,correlationFlags[i]);
exit(-1);
}
}
if(isSingleDetector(correlationFlags[i]) && !isSingleDetector(correlationFlags[j]))
{
Error("HPidGeantTrackSet::diagnosis()","There is a correlated particle sorted BEHIND an uncorrelated one!");
}
if(correlatedTrackIds[i]==correlatedTrackIds[j])
{
Error("HPidGeantTrackSet::diagnosis()","Particle %d (%d) is idential to particle %d (%d)",
j,correlatedTrackIds[j],i,correlatedTrackIds[i]);
}
}
}
}
void HPidGeantTrackSet::Clear(Option_t *opt)
{
isSorted=kFALSE;
sNCorrTrackIds=0;
nRICHTracks=0;
nRICHIPUTracks=0;
nInnerMdcTracks=0;
nOuterMdcTracks=0;
nShowerTracks=0;
nTOFTracks=0;
bIsLepFromPrimary=kFALSE;
correlatedTrackIds.Set(0);
correlationFlags.Set(0);
ProcessIds.Set(0);
ParentIds.Set(0);
Parents.Set(0);
GrandParentIds.Set(0);
GrandParents.Set(0);
GenInfo.Set(0);
GenInfo1.Set(0);
GenInfo2.Set(0);
GenWeight.Set(0);
VertexX.Set(0);
VertexY.Set(0);
VertexZ.Set(0);
GeantPIDs.Set(0);
MediumIds.Set(0);
GeantMomX.Set(0);
GeantMomY.Set(0);
GeantMomZ.Set(0);
ShowerWeights.Set(0);
TOFWeights.Set(0);
RICHWeights.Set(0);
RICHIPUWeights.Set(0);
InnerMDCWeights.Set(0);
OuterMDCWeights.Set(0);
hasHitInShower.Set(0);
hasHitInTOF.Set(0);
}
void HPidGeantTrackSet::addTrackWeightToDetector(Float_t weight, Int_t trackID, UInt_t detector)
{
Int_t particleIndex=getParticleIndex(trackID);
if(particleIndex==-1) {
::Error("HPidGeantTrackSet::addTrackWeightToDetector","This particle is not yet part of the track set!");
}
else
{
switch (detector) {
case kSeenInRICHIPU:
RICHIPUWeights[particleIndex]=weight;
break;
case kSeenInRICH:
RICHWeights[particleIndex]=weight;
break;
case kSeenInInnerMDC:
InnerMDCWeights[particleIndex]=weight;
break;
case kSeenInOuterMDC:
OuterMDCWeights[particleIndex]=weight;
break;
case kSeenInShower:
ShowerWeights[particleIndex]=weight;
break;
case kSeenInTOF:
TOFWeights[particleIndex]=weight;
break;
default:
::Error("HPidGeantTrackSet::addTrackWeightToDetector","This detector does NOT EXIST!");
break;
}
}
}
Int_t HPidGeantTrackSet::getParticleIndex(Int_t trackID)
{
for(Int_t i = 0; i<sNCorrTrackIds;i++)
{
if(correlatedTrackIds[i]==trackID)
{
return i;
}
}
return -1;
}
Bool_t HPidGeantTrackSet::isPartOfTrackSet(Int_t trackID)
{
if(getParticleIndex(trackID)==-1)
return kFALSE;
return kTRUE;
}
TLorentzVector* HPidGeantTrackSet::buildGeantLorentzVector(Int_t iPos) const
{
TLorentzVector* v = NULL;
#warning This can be made safer
if(correlationFlags[iPos] != kTrackNotSet)
{
Double_t Energy = TMath::Sqrt(pow(GeantMomX[iPos],2)+
pow(GeantMomY[iPos],2)+
pow(GeantMomZ[iPos],2)+
pow(HPidPhysicsConstants::mass(GeantPIDs[iPos]),2));
v=new TLorentzVector(GeantMomX[iPos],GeantMomY[iPos],GeantMomZ[iPos],Energy);
}
return v;
}
TVector3* HPidGeantTrackSet::buildGeantMomentumVector(Int_t iPos) const
{
TVector3* vPtr = NULL;
vPtr = new TVector3(GeantMomX[iPos],GeantMomY[iPos],GeantMomZ[iPos]);
return vPtr;
}
Int_t HPidGeantTrackSet::addToContributingTracks(Int_t trackID, UInt_t detector)
{
Int_t grandparent, parent, medium, process, parentId, grandparentId;
Int_t gp_process, gp_medium;
Float_t momx, momy, momz;
Float_t vertx, verty, vertz;
Float_t fGgeninfo,fGgeninfo1,fGgeninfo2,fGgenweight;
HGeantKine* pKineGrandParent = NULL;
HGeantKine* pKineParent= NULL;
parent=grandparent=parentId=grandparentId=0;
medium=process=gp_process=gp_medium=-1;
fGgeninfo=fGgeninfo1=fGgeninfo2=fGgenweight=-1.0;
momx=momy=momz=0.0;
vertx=verty=vertz=-999.0;
if(!isPartOfTrackSet(trackID))
{
if(sNCorrTrackIds==correlatedTrackIds.GetSize())
{
enlargeArrays();
}
correlatedTrackIds[sNCorrTrackIds]=trackID;
if(detector==kSeenInShower)
{
correlationFlags[sNCorrTrackIds]|=kSeenInMETA;
hasHitInShower[sNCorrTrackIds]=kTRUE;
}
if(detector==kSeenInTOF)
{
correlationFlags[sNCorrTrackIds]|=kSeenInMETA;
hasHitInTOF[sNCorrTrackIds]=kTRUE;
}
if(detector!=kSeenInTOF && detector!=kSeenInShower)
{
correlationFlags[sNCorrTrackIds]|=detector;
}
if(trackID>0)
{
HGeantKine* pKine = getGeantKine(trackID);
pKine->getCreator(parent,medium,process);
if(parent)
{
}
else
{
nullparent++;
}
pKine->getGenerator(fGgeninfo,fGgenweight);
pKine->getGenerator(fGgeninfo,fGgeninfo1,fGgeninfo2);
pKine->getVertex(vertx,verty,vertz);
if(parent!=0)
{
pKineParent = getGeantKine(parent);
if(NULL!=pKineParent)
{
pKineParent->getParticle(parent,parentId);
}
else
{
::Error("HPidGeantTrackSet::addToContributiingTracks","No pKineObject for track id %d",parent);
}
if(pKineParent)
{
pKineParent->getCreator(grandparent,gp_medium,gp_process);
if(grandparent!=0)
{
pKineGrandParent = getGeantKine(grandparent);
if(NULL!=pKineGrandParent)
{
pKineGrandParent->getParticle(grandparent, grandparentId);
}
else
{
::Error("HPidGeantTrackSet::addToContributingTracks","No pKineObject for track id %d",grandparent);
}
}
}
}
Parents[sNCorrTrackIds]=parent;
ParentIds[sNCorrTrackIds]=parentId;
GrandParents[sNCorrTrackIds]=grandparent;
GrandParentIds[sNCorrTrackIds]=grandparentId;
MediumIds[sNCorrTrackIds]=medium;
ProcessIds[sNCorrTrackIds]=process;
GenInfo[sNCorrTrackIds]=fGgeninfo;
GenInfo1[sNCorrTrackIds]=fGgeninfo1;
GenInfo2[sNCorrTrackIds]=fGgeninfo2;
GenWeight[sNCorrTrackIds]=fGgenweight;
pKine->getMomentum(momx,momy,momz);
GeantMomX[sNCorrTrackIds]=momx;
GeantMomY[sNCorrTrackIds]=momy;
GeantMomZ[sNCorrTrackIds]=momz;
VertexX[sNCorrTrackIds]=vertx;
VertexY[sNCorrTrackIds]=verty;
VertexZ[sNCorrTrackIds]=vertz;
GeantPIDs[sNCorrTrackIds]=pKine->getID();
sNCorrTrackIds++;
}
else{
if(trackID==gHades->getEmbeddingRealTrackId())
{
Parents[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
ParentIds[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GrandParents[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GrandParentIds[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
MediumIds[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
ProcessIds[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GenInfo[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GenInfo1[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GenInfo2[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GenWeight[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
GeantMomX[sNCorrTrackIds]=0;
GeantMomY[sNCorrTrackIds]=0;
GeantMomZ[sNCorrTrackIds]=0;
VertexX[sNCorrTrackIds]=0;
VertexY[sNCorrTrackIds]=0;
VertexZ[sNCorrTrackIds]=0;
GeantPIDs[sNCorrTrackIds]=gHades->getEmbeddingRealTrackId();
sNCorrTrackIds++;
}
else {
Error("addToContributingTracks()","detected negative trackId other than embedding ID :%i! ",trackID);
}
}
}
else
{
Int_t index = getParticleIndex(trackID);
if(detector==kSeenInShower)
{
correlationFlags[index]|=kSeenInMETA;
hasHitInShower[index]=kTRUE;
}
if(detector==kSeenInTOF)
{
correlationFlags[index]|=kSeenInMETA;
hasHitInTOF[index]=kTRUE;
}
if(detector!=kSeenInTOF && detector!=kSeenInShower)
{
correlationFlags[index]|=detector;
}
}
return sNCorrTrackIds;
}
UInt_t HPidGeantTrackSet::getNMetaTracks(void) const
{
Int_t nDistinctMetaTracks=0;
for(Int_t i = 0;i < sNCorrTrackIds; i++)
{
if (wasSeenInDetector(correlationFlags[i], kSeenInMETA) && hasHitInShower.At(i)>0)
{
nDistinctMetaTracks++;
}
else if(wasSeenInDetector(correlationFlags[i], kSeenInMETA) && hasHitInTOF.At(i)>0)
{
nDistinctMetaTracks++;
}
}
return nDistinctMetaTracks;
}
void HPidGeantTrackSet::print(void) const
{
UInt_t i;
printf("HPidGeantTrackSet tracks:\nRICH (%d) :", getNRichTracks());
for(i = 0; i < getNRichTracks(); i++)
printf(" %3d", getRichTrack(i));
printf("HPidGeantTrackSet tracks:\nRICHIPU (%d) :", getNRichIPUTracks());
for(i = 0; i < getNRichIPUTracks(); i++)
printf(" %3d", getRichIPUTrack(i));
printf("\nMDC (%d) :", getNInnerMdcTracks());
for(i = 0; i < getNInnerMdcTracks(); i++)
printf(" %3d", getInnerMdcTrack(i));
printf("\nMDC (%d) :", getNOuterMdcTracks());
for(i = 0; i < getNOuterMdcTracks(); i++)
printf(" %3d", getOuterMdcTrack(i));
printf("\nMeta (%d) :", getNMetaTracks());
for(i = 0; i < getNMetaTracks(); i++)
printf(" %3d", getMetaTrack(i));
printf("\nShower (%d) :", getNShowerTracks());
for(i = 0; i < getNShowerTracks(); i++)
printf(" %3d", getShowerTrack(i));
printf("\nTOF (%d) :", getNTOFTracks());
for(i = 0; i < getNTOFTracks(); i++)
printf(" %3d", getTOFTrack(i));
printf("\n");
}
Int_t HPidGeantTrackSet::findFirstHitInTof(Int_t trackID,Int_t* count,Int_t storeFirstTrack)
{
Int_t numTrack=trackID;
*count=0;
if(numTrack<=0) return numTrack;
HLinearCategory* fGeantKineCat = (HLinearCategory*)HPidFL::getCategory(catGeantKine, kFALSE);
if(!fGeantKineCat){
::Error("HPidGeantTrackSet::findFirstHitInTof()","Received Zero pointer for catGeantKine!");
return trackID;
}
HLinearCategory* fGeantCat = (HLinearCategory*)gHades->getCurrentEvent()->getCategory(catTofGeantRaw);
if(!fGeantCat){
::Error("HPidGeantTrackSet::findFirstHitInTof()","Received Zero pointer for catGeantTof!");
return trackID;
}
HGeantTof *poldTof, *pnewTof;
Int_t first=0;
HGeantKine* kine=(HGeantKine*)fGeantKineCat->getObject(numTrack-1);
if(kine){
first=kine->getFirstTofHit();
if(first!=-1){
poldTof=(HGeantTof*)fGeantCat->getObject(first);
pnewTof=poldTof;
} else {
::Error("HPidGeantTrackSet::findFirstHitInTof()","No first tof hit!");
return numTrack;
}
} else {
::Error("HPidGeantTrackSet::findFirstHitInTof()","Received Zero pointer for kine!");
return numTrack;
}
if(numTrack!=poldTof->getTrack()){
::Error("HPidGeantTrackSet::findFirstHitInTof()","First tof hit not same trackID!");
return numTrack;
}
if(storeFirstTrack==0) return numTrack;
if(storeFirstTrack==1)
{
kine=(HGeantKine*)fGeantKineCat->getObject(numTrack-1);
Int_t parent=kine->getParentTrack();
kine=HGeantKine::getPrimary(numTrack,fGeantKineCat);
if(parent>0)(*count)--;
return kine->getTrack();
}
kine=(HGeantKine*)fGeantKineCat->getObject(numTrack-1);
if(kine->getParentTrack()==0){return numTrack;}
Int_t s,m,c;
s= poldTof->getSector();
m= 21-poldTof->getModule();
c= 7 -poldTof->getCell();
first=0;
Int_t tempTrack=numTrack;
while((kine=kine->getParent(tempTrack,fGeantKineCat))!=0)
{
first=kine->getFirstTofHit();
if(first!=-1)
{
HGeantTof* gtof=(HGeantTof*)fGeantCat->getObject(first);
Int_t s1,m1,c1;
s1=m1=c1=0;
m1 = 21-gtof->getModule();
if(m1>=0)
{
s1= gtof->getSector();
c1= 7-gtof->getCell();
if(storeFirstTrack==2&&
s==s1)
{
tempTrack =kine->getTrack();
pnewTof=gtof;
(*count)--;
}
if(storeFirstTrack==3&&
s==s1&&m==m1)
{
tempTrack =kine->getTrack();
pnewTof=gtof;
(*count)--;
}
else if(storeFirstTrack==4&&
s==s1&&m==m1&&c==c1)
{
tempTrack =kine->getTrack();
pnewTof=gtof;
(*count)--;
}
else {
break;
}
} else {
break;
}
}
else {
break;
}
}
return tempTrack;
}
Last change: Sat May 22 13:07:07 2010
Last generated: 2010-05-22 13:07
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.