#include "hpidhitdata.h"
#include "hpidparticle.h"
#include "hpidcandidate.h"
#include "hpidtrackcand.h"
#include "hpidphysicsconstants.h"
#include "hades.h"
#include "hevent.h"
#include "hlinearcategory.h"
#include "hpidfl.h"
#include "TError.h"
#include <iostream>
#include "piddef.h"
using namespace std;
ClassImp(HPidParticle)
HPidParticle::HPidParticle(HPidCandidate* pCandidate,Float_t* VectorOfWeights,
Bool_t useMassIdeal, Int_t userDefSpecies, Float_t userWeight):
itsHitData(*(pCandidate->getTrackCandidate()->getHitData())),
itsTrackData(*(pCandidate->getTrackCandidate()->getTrackData()))
{
setDefault();
nPossibleSpecies = pCandidate->getNParticles();
possibleSpecies.Set(nPossibleSpecies,pCandidate->getParticleIds()->GetArray());
assignedWeights.Set(nPossibleSpecies,VectorOfWeights);
nPidCandidateIndex = HPidFL::getCategory(catPidCandidate)->getIndex(pCandidate);
setMomAlg(pCandidate->getMomAlg());
setPidParams(0.0,userDefSpecies, userWeight);
const HPidHitData* pHitData = getHitData();
const HPidTrackData* pTrackData = getTrackData();
Double_t tMomentum = pTrackData->fMomenta[getMomAlg()];
Double_t tMass = -1.0;
Double_t tTheta;
Double_t tPhi;
if(getMomAlg()!=ALG_RUNGEKUTTA)
{
tTheta = pHitData->fMdcTheta;
tPhi = pHitData->fMdcPhi;
}
else
{
tTheta = pTrackData->fRKTheta;
tPhi = pTrackData->fRKPhi;
}
if(useMassIdeal)
{
tMass=HPidPhysicsConstants::mass(getPid());
kUsesIdealMass=kTRUE;
}
else
{
tMass = TMath::Sqrt(pTrackData->fMassSquared[momAlgIndex]);
}
SetXYZM(tMomentum * TMath::Sin(TMath::DegToRad()*tTheta) *
TMath::Cos(TMath::DegToRad()*tPhi),
tMomentum * TMath::Sin(TMath::DegToRad()*tTheta) *
TMath::Sin(TMath::DegToRad()*tPhi),
tMomentum * TMath::Cos(TMath::DegToRad()*tTheta),
tMass);
flags = pCandidate->getFlagField();
}
HPidParticle::HPidParticle(const HPidParticle& source):
TLorentzVector(source),
itsHitData(*(source.getHitData())),
itsTrackData(*(source.getTrackData()))
{
kUsesIdealMass = source.kUsesIdealMass;
nPossibleSpecies=source.nPossibleSpecies;
momAlgIndex=source.momAlgIndex;
nPidCandidateIndex=source.nPidCandidateIndex;
possibleSpecies=source.possibleSpecies;
assignedWeights=source.assignedWeights;
nAssignedPID=source.nAssignedPID;
fTestVal=source.fTestVal;
fWeight=source.fWeight;
fMomRescal=source.fMomRescal;
flags=source.flags;
}
void HPidParticle::setFlagBit (Int_t bit)
{
if(bit >= 0 && bit < 32 ) flags |= ( 0x01 << bit );
else {
Error("HPidParticle::setFlagBit(Int_t)","Bit number out of range : %i!",bit);
}
}
void HPidParticle::unsetFlagBit (Int_t bit)
{
if(bit >= 0 && bit < 32 ) flags &= ~( 0x01 << bit );
else {
Error("HPidParticle::unsetFlagBit(Int_t)","Bit number out of range : %i!",bit);
}
}
Bool_t HPidParticle::isFlagBit (Int_t bit)
{
if (bit >= 0 && bit < 32 ) return (flags >> bit ) & 0x01;
else {
Error("HPidParticle::isFlagBit(Int_t)","Bit number out of range : %i!",bit);
return kFALSE;
}
}
Bool_t HPidParticle::isFlagOR(Int_t num,...)
{
va_list ap;
va_start(ap,num);
for(Int_t i=0;i<num;i++){
Int_t bit=va_arg(ap,Int_t);
if(bit < 0 || bit > 31)
{
Error("HPidParticle::isFlagOR()","Bit number out of range : i=%i ,%i!",i,bit);
va_end(ap);
return kFALSE;
}
if(isFlagBit(bit)) {
va_end(ap);
return kTRUE;
}
}
va_end(ap);
return kFALSE;
}
Bool_t HPidParticle::isFlagAND(Int_t num, ...)
{
va_list ap;
va_start(ap,num);
for(Int_t i=0;i<num;i++){
Int_t bit=va_arg(ap,Int_t);
if(bit < 0 || bit > 31)
{
Error("HPidParticle::isFlagAND()","Bit number out of range : i=%i ,%i!",i,bit);
va_end(ap);
return kFALSE;
}
if(!isFlagBit(bit)) {
va_end(ap);
return kFALSE;
}
}
va_end(ap);
return kTRUE;
}
void HPidParticle::printFlags(TString comment)
{
TString out="";
for(Int_t i=32;i>0;i--){
if(i%4==0) out+=" ";
out+= ( (flags>>(i-1)) & 0x1 );
}
cout<<"bin "<<out.Data()<<" "<<comment.Data()<<endl;
}
void HPidParticle::setPidParams(Float_t fTV, Int_t userDefSpecies, Float_t userWeight)
{
if(userDefSpecies!=-99)
{
nAssignedPID=userDefSpecies;
if(userWeight!=-99.0)
{
fWeight=userWeight;
}
else
{
::Error("HPidParticle::SetPidParams()","User defined a species for this particle by hand, but no weight");
exit(-1);
}
}
else
{
Float_t currentMaxWeight=0.0;
for(Int_t i=0;i<nPossibleSpecies;i++)
{
if(assignedWeights[i]>currentMaxWeight)
{
currentMaxWeight=assignedWeights[i];
nAssignedPID=possibleSpecies[i];
fWeight = currentMaxWeight;
}
}
if(currentMaxWeight==0.0){
if( getTrackData()->nPolarity[momAlgIndex]<0){
nAssignedPID =HPidPhysicsConstants::artificialNeg();
}
else if (getTrackData()->nPolarity[momAlgIndex]>0){
nAssignedPID =HPidPhysicsConstants::artificialPos();
}
}
}
}
Float_t HPidParticle::getWeightForPID(Short_t pid) const
{
Int_t i = getSpeciesIndex(pid);
if(i>-1) return assignedWeights[i];
return -1.0;
}
Int_t HPidParticle::getSpeciesIndex(Short_t pid) const
{
for(Int_t i=0;i<nPossibleSpecies;i++)
{if(possibleSpecies[i]==pid) return i;}
return -1;
}
void HPidParticle::setDefault(void)
{
momAlgIndex=-1;
nPossibleSpecies=0;
nAssignedPID=-99;
nPidCandidateIndex = -1;
possibleSpecies.Set(0);
assignedWeights.Set(0);
fTestVal = 0.0f;
fWeight = 0.0f;
fMomRescal = 1.0f;
kUsesIdealMass=kTRUE;
SetXYZT(0.0, 0.0, 0.0, 0.0);
flags = 0;
}
void HPidParticle::Clear(Option_t *opt)
{
possibleSpecies.Set(0);
assignedWeights.Set(0);
}
void HPidParticle::print(void) const
{
printf("Particle : %d \"%s\"\n", getPid(), HPidPhysicsConstants::pid(getPid()));
printf("4Momentum : (%8.4f, %8.4f, %8.4f, %8.4f)\nMom. mag.: %8.4f MeV/c\n",
X(), Y(), Z(), T(), P());
printf("Theta/Phi : %8.4f %8.4f\n", thetaDeg(), phiDeg());
printf("R, Z, Pull: %8.4f %8.4f %8.4f\n", getR(), getZ(), getTrackData()->fPull);
printf("Beta calc : %8.4f Exp: %8.4f\n", Beta(), getBetaExp());
printf("Mass ideal: %8.4f Exp: %8.4f\n", getMassIdeal(), getMassExp());
printf("TestVal : %8.4f\n", fTestVal);
printf("Weight : %8.4f\n", fWeight);
}
HPidCandidate* HPidParticle::getPidCandidate(HCategory *pCat) const
{
if(nPidCandidateIndex < 0)
return NULL;
return HPidFL::getPidCandidate(nPidCandidateIndex, pCat);
}
HCategory* HPidParticle::buildPidParticleCategory(void)
{
HCategory *pCat;
HEvent *pEvent;
if((gHades == NULL) || ((pEvent = gHades->getCurrentEvent()) == NULL))
{
::Error("HPidParticle::buildPidParticleCategory",
"Cannot access current event");
return NULL;
}
if((pCat = pEvent->getCategory(catPidPart)) != NULL)
{
((HLinearCategory*)pCat)->setDynamicObjects(kTRUE);
return pCat;
}
if((pCat = new HLinearCategory("HPidParticle", 1000)) == NULL)
{
::Error("HPidParticle::buildPidParticleCategory",
"Cannot create new category");
return NULL;
}
((HLinearCategory*)pCat)->setDynamicObjects(kTRUE);
pEvent->addCategory(catPidPart, pCat, "Pid");
return pCat;
}
Int_t HPidParticle::getMostProbablePID(void) const
{
Float_t currentMax=0.0;
Int_t pid=-99;
for(Int_t j =0;j<nPossibleSpecies;j++)
{
if(assignedWeights[j]>currentMax)
{
currentMax=assignedWeights[j];
pid=possibleSpecies[j];
}
}
if( !(currentMax>0.0)){
if( getTrackData()->nPolarity[momAlgIndex]<0){
pid =HPidPhysicsConstants::artificialNeg();
}
else if (getTrackData()->nPolarity[momAlgIndex]>0){
pid =HPidPhysicsConstants::artificialPos();
}
}
return pid;
}
Int_t HPidParticle::getIndex(HCategory *pCat)
{
if((pCat == NULL) && ((pCat = HPidFL::getCategory(
catPidPart, kFALSE)) == NULL))
{
Error("getIndex", "Cannot get category");
return -2;
}
return pCat->getIndex(this);
}
HPidTrackCand* HPidParticle::getTrackCand(void) const
{
if(nPidCandidateIndex >= 0)
{
HPidCandidate *pCand;
if((pCand = getPidCandidate()) == NULL)
{
Error("HPidParticle::getTrackCand()", "Cannot get HPidCandidate");
return NULL;
}
if(pCand->getTrackCandIndex() < 0)
{
Error("HPidParticle::getTrackCand()","Track Candidate Index for PidCandidate is %d",pCand->getTrackCandIndex());
return NULL;
}
return pCand->getTrackCandidate();
}
if(nPidCandidateIndex <= kTrackCandOffset)
return HPidFL::getTrackCand(kTrackCandOffset - nPidCandidateIndex);
return NULL;
}
TLorentzVector HPidParticle::getRescaledVector(void) const
{
TLorentzVector v = *this;
if(fMomRescal != 1.0f)
{
TVector3 v3 = v.Vect();
v3.SetMag(fMomRescal * v3.Mag());
v.SetVectM(v3, M());
}
return v;
}
void HPidParticle::Streamer(TBuffer &R__b)
{
UInt_t R__s, R__c;
if (R__b.IsReading()) {
Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
TLorentzVector::Streamer(R__b);
R__b >> kUsesIdealMass;
R__b >> nPossibleSpecies;
R__b >> momAlgIndex;
R__b >> nPidCandidateIndex;
possibleSpecies.Streamer(R__b);
assignedWeights.Streamer(R__b);
R__b >> nAssignedPID;
R__b >> fTestVal;
R__b >> fWeight;
R__b >> fMomRescal;
itsHitData.Streamer(R__b);
itsTrackData.Streamer(R__b);
if(R__v > 1){
R__b >> flags;
} else { flags = 0; }
R__b.CheckByteCount(R__s, R__c, HPidParticle::IsA());
} else {
R__c = R__b.WriteVersion(HPidParticle::IsA(), kTRUE);
TLorentzVector::Streamer(R__b);
R__b << kUsesIdealMass;
R__b << nPossibleSpecies;
R__b << momAlgIndex;
R__b << nPidCandidateIndex;
possibleSpecies.Streamer(R__b);
assignedWeights.Streamer(R__b);
R__b << nAssignedPID;
R__b << fTestVal;
R__b << fWeight;
R__b << fMomRescal;
itsHitData.Streamer(R__b);
itsTrackData.Streamer(R__b);
R__b << flags;
R__b.SetByteCount(R__c, kTRUE);
}
}
Last change: Sat May 22 13:07:15 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.