using namespace std;
#include <iostream>
#include "hcategory.h"
#include "hiterator.h"
#include "hpidparticlefiller.h"
#include "hpidcandidate.h"
#include "hpidtrackcand.h"
#include "hpidtrackdata.h"
#include "hades.h"
#include "hevent.h"
#include "hlinearcategory.h"
#include "kickdef.h"
#include "piddef.h"
#include "hpidphysicsconstants.h"
#include "hpidtrackfiller.h"
#include "TMethodCall.h"
#include <Api.h>
#include "TROOT.h"
#include "TArrayF.h"
#include "hpidparticlesim.h"
#include "hpidhitdata.h"
#include "hpidgeanttrackset.h"
ClassImp(HPidParticleFiller)
HPidParticleFiller *HPidParticleFiller::pCurPartFiller = NULL;
#define SAFE_DELETE(A) { if(A) { delete (A); A = NULL; }}
HPidParticleFiller::HPidParticleFiller(const Option_t par[])
: HReconstructor("PidPartFiller",
"Filler of HPidParticle category")
{
setDefault();
setParameters(par);
pCurPartFiller = this;
}
HPidParticleFiller::HPidParticleFiller(const Text_t name[],const Text_t title[],
const Option_t par[])
: HReconstructor(name, title)
{
setDefault();
setParameters(par);
pCurPartFiller = this;
}
HPidParticleFiller::~HPidParticleFiller(void)
{
SAFE_DELETE(pitInput);
aCandValues.Set(0);
aAlgorithms.Set(0);
if(pCurPartFiller == this)
pCurPartFiller = NULL;
}
void HPidParticleFiller::setDefault(void)
{
pInputCat = NULL;
pitInput = NULL;
pOutCat = NULL;
iAlgorithm = algBayes;
bIncludeFakes = kFALSE;
bMakeSimCategory = kFALSE;
bUseMassExp=kTRUE;
aAlgorithms.Set(0);
aCandValues.Set(0);
iMomAlg = -1;
iDebug = 0;
}
Bool_t HPidParticleFiller::init(void)
{
if(iDebug)
Warning("init", "begin");
HCategory* pGeantKineCat = gHades->getCurrentEvent()->getCategory(catGeantKine);
if(pGeantKineCat) bMakeSimCategory = kTRUE;
else bMakeSimCategory = kFALSE;
if(buildOutputCategory(bMakeSimCategory) == kFALSE)
return kFALSE;
if((pInputCat = gHades->getCurrentEvent()->getCategory(catPidCandidate))
== NULL)
{
Error("init", "No category catPidCandidate");
return kFALSE;
}
if((pitInput = (HIterator *)pInputCat->MakeIterator()) == NULL)
{
Error("init", "Cannot make an iterator for HPidCandidate category");
return kFALSE;
}
if(iDebug)
Warning("init", "end");
return kTRUE;
}
Bool_t HPidParticleFiller::reinit(void)
{
if((iAlgorithm < 0))
{
Error("reinit", "No algorithm defined");
return kFALSE;
}
return kTRUE;
}
Bool_t HPidParticleFiller::buildOutputCategory(Bool_t makeSimCategory)
{
HEvent *pEvent;
if((gHades == NULL) || ((pEvent = gHades->getCurrentEvent()) == NULL))
{
Error("buildOutputCategory", "Cannot access current event");
return kFALSE;
}
if(bMakeSimCategory)
{
pOutCat = HPidParticleSim::buildPidParticleSimCategory();
}
else
{
pOutCat = HPidParticle::buildPidParticleCategory();
}
if(pOutCat == NULL)
{
Error("buildOutputCategory", "Cannot create new category");
return kFALSE;
}
((HLinearCategory*)pOutCat)->setDynamicObjects(kTRUE);
pEvent->addCategory(catPidPart, pOutCat, "Pid");
return kTRUE;
}
void HPidParticleFiller::setParameters(const Option_t par[])
{
TString s = par;
Char_t *p;
s.ToUpper();
iDebug = 0;
if((p = strstr(s.Data(), "DEBUG")) != NULL)
{
if(sscanf(p + strlen("DEBUG"), "%d", &iDebug) <= 0)
iDebug = 1;
}
bUseMassExp = (strstr(s.Data(), "MASSEXP") != NULL);
bIncludeFakes = (strstr(s.Data(), "INCLUDEFAKES") != NULL);
if(s.Contains("ALGLIKELIHOOD")) iAlgorithm=algLikelihood;
if(s.Contains("ALGBAYES")) iAlgorithm=algBayes;
if(s.Contains("ALGRICH")) iAlgorithm=algRich;
if(s.Contains("ALGTOF")) iAlgorithm=algTof;
if(s.Contains("ALGSHOWER")) iAlgorithm=algShower;
if(s.Contains("ALGMOMVSBETA")) iAlgorithm=algMomVsBeta;
if(s.Contains("ALGSTANDCUTS")) iAlgorithm=algStandCuts;
if(s.Contains("ALGMOMVSELOSS")) iAlgorithm=algMomVsEloss;
if(s.Contains("ALGHARDCUTS")) iAlgorithm=algHardCuts;
if(s.Contains("ALGMDCELOSS")) iAlgorithm=algMdcEloss;
Int_t nMomAlgsDefined=0;
if(s.Contains("SPLINE"))
{
iMomAlg=ALG_SPLINE;
nMomAlgsDefined++;
}
if(s.Contains("RUNGEKUTTA"))
{
iMomAlg=ALG_RUNGEKUTTA;
nMomAlgsDefined++;
}
if(s.Contains("KICK"))
{
iMomAlg=ALG_KICK;
nMomAlgsDefined++;
}
if(s.Contains("KICK123"))
{
iMomAlg=ALG_KICK123;
nMomAlgsDefined++;
}
if(nMomAlgsDefined>1)
{
Error("HPidParticleFiller::setParameters()","Too many momentum algorithms selected");
exit(-1);
}
if(nMomAlgsDefined==0)
{
cout << "No momentum algorithm selected for HPidParticleFiller - switching to default: kickplane momentum reconstruction!" << endl;
iMomAlg=ALG_KICK;
}
}
void HPidParticleFiller::addAlgorithm(Int_t iAId)
{
aAlgorithms.Set(aAlgorithms.GetSize() + 1);
aAlgorithms[aAlgorithms.GetSize() - 1] = iAId;
}
void HPidParticleFiller::removeAlgorithm(Int_t iAId)
{
Int_t iIn, iOut;
for(iIn = 0, iOut = 0; iIn < aAlgorithms.GetSize(); iIn++)
{
if(aAlgorithms[iIn] != iAId)
{
if(iOut != iIn)
aAlgorithms[iOut] = aAlgorithms[iIn];
iOut++;
}
}
aAlgorithms.Set(iOut);
}
Int_t HPidParticleFiller::execute(void)
{
HPidCandidate *pCand;
Int_t i;
Int_t iSum = 0;
pOutCat->Clear();
pitInput->Reset();
while((pCand = (HPidCandidate *)pitInput->Next()) != NULL)
{
i = checkCandidate(pCand);
if(iDebug)
printf("%d ", i);
}
if(iDebug)
printf("(%d)\n", iSum);
return 0;
}
HPidParticle* HPidParticleFiller::getNextSlot(void)
{
static HLocation locDummy;
HPidParticle *pOut = NULL;
if(pOutCat == NULL)
{
Error("getNextSlot", "Output category not set: use init/reinit");
return NULL;
}
if((pOut = (HPidParticle *) pOutCat->getNewSlot(locDummy)) == NULL)
{
Error("getNextSlot", "No new slot");
return NULL;
}
return pOut;
}
Int_t HPidParticleFiller::checkCandidate(HPidCandidate *pCand)
{
Int_t iReturn = 0;
Int_t i;
if(aCandValues.GetSize() < (Int_t) pCand->getNParticles())
{
aCandValues.Set(pCand->getNParticles());
}
aCandValues.Reset(-1);
switch(iAlgorithm)
{
case algLikelihood:
pCand->calcMergedPDFVector(aCandValues.GetArray(),
aAlgorithms.GetArray(), aAlgorithms.GetSize());
break;
case algBayes:
pCand->calcBayesVector(aCandValues.GetArray(),
aAlgorithms.GetArray(), aAlgorithms.GetSize());
break;
default:
if((i = pCand->getAlgorithmIndexById(iAlgorithm)) < 0)
{
::Error("HPidParticleFiller::checkCandidate",
"No algorithm %d in the HPidCandidate", iAlgorithm);
return kFALSE;
}
aCandValues.Set(pCand->getNParticles(), pCand->getValuesVectorByIndex(i));
break;
}
if(! bIncludeFakes ){
Int_t nPart = (Int_t) pCand->getNParticles();
for(i = 0; i < nPart; i++){
if(HPidPhysicsConstants::isFake(pCand->getParticleIdByIndex(i))){
aCandValues[i] = -1.0f;
}
}
Float_t fSum=0.0;
for(i = 0; i< nPart; i++){
if(HPidPhysicsConstants::isFake(pCand->getParticleIdByIndex(i)) && !bIncludeFakes)
{
continue;
}
if(aCandValues[i]<0.0)
{
continue;
}
fSum += aCandValues[i];
}
if(fSum>0.0){
for(i = 0; i< nPart; i++){
aCandValues[i] /= fSum;
}
}
}
HPidParticle* pParticle = getNextSlot();
if(bMakeSimCategory)
{
pParticle = new (pParticle) HPidParticleSim(pCand, aCandValues.GetArray());
}
else
{
pParticle = new (pParticle) HPidParticle(pCand, aCandValues.GetArray());
}
iReturn++;
return iReturn;
}
void HPidParticleFiller::print(void) const
{
}
Last change: Sat May 22 13:07:16 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.