#include "hhyplistfiller.h"
#include "hrktrackB.h"
#include "hmdctrackgdef.h"
using namespace std;
ClassImp(HHypListFiller)
HHypListFiller::HHypListFiller(const Text_t * name,const Text_t * title):
HReconstructor(name, title)
{
nPlus = 0;
nMinus = 0;
numberOfParticles = 0;
nPlusReal = 0;
nMinusReal = 0;
numberOfRealParticles = 0;
numberOfPossibleMissing = 0;
pid_real_array = 0;
pid_full_array = 0;
particleArrayPlus.Set(0);
particleArrayMinus.Set(0);
particleArrayMissing.Set(0);
}
HHypListFiller::HHypListFiller()
{
nPlus = 0;
nMinus = 0;
numberOfParticles = 0;
nPlusReal = 0;
nMinusReal = 0;
numberOfRealParticles = 0;
numberOfPossibleMissing = 0;
pid_real_array = 0;
pid_full_array = 0;
particleArrayPlus.Set(0);
particleArrayMinus.Set(0);
particleArrayMissing.Set(0);
}
HHypListFiller::~HHypListFiller(void)
{
}
Bool_t HHypListFiller::SetExitList(Int_t e_list)
{
exitList = e_list;
return kTRUE;
}
Bool_t HHypListFiller::init()
{
if (numberOfPossibleMissing == 0) {
AddOneMissing(HPidPhysicsConstants::pid("dummy"));
}
generateNumberOfCombinations();
create_pid_table();
m_pContCatComb = gHades->getCurrentEvent()->getCategory(catHypComb);
if (!m_pContCatComb) {
m_pContCatComb = HHypComb::buildLinearCat("HHypComb");
if (!m_pContCatComb)
return kFALSE;
gHades->getCurrentEvent()->addCategory(catHypComb, m_pContCatComb,
"HypComb");
}
m_pContCatList = gHades->getCurrentEvent()->getCategory(catHypList);
if (!m_pContCatList) {
m_pContCatList = HHypList::buildLinearCat("HHypList");
if (!m_pContCatList)
return kFALSE;
gHades->getCurrentEvent()->addCategory(catHypList, m_pContCatList,
"HypList");
}
m_pContItTrackCand = NULL;
m_pContCatTrackCand = NULL;
if ((m_pContCatTrackCand =
gHades->getCurrentEvent()->getCategory(catPidTrackCand)) == NULL) {
Error("init", "Cannot get catPidTrackCand cat");
return kFALSE;
}
m_pContItTrackCand = (HIterator *) m_pContCatTrackCand->MakeIterator();
if (m_pContItTrackCand == NULL) {
Error("init", "Cannot get catPidTrackCand Iterator");
return kFALSE;
}
return kTRUE;
}
Int_t HHypListFiller::execute()
{
Int_t index_comb = 0;
Int_t index_list = 0;
HLocation locDummy;
Int_t counterMinus = 0;
Int_t counterPlus = 0;
Int_t counter = 0;
Int_t Charge[HYP_MAX_PARTICLES];
Int_t numpidtracks[MAX_USER_VALUES];
HPidTrackCand *pPidTrackCand = NULL;
m_pContItTrackCand->Reset();
Int_t iCount = 0;
while (((pPidTrackCand = (HPidTrackCand *) m_pContItTrackCand->Next()) != NULL)
&& (counter < HYP_MAX_PARTICLES) && (iCount < HYP_MAX_TRACKCLEAN)) {
Int_t charge;
charge=pPidTrackCand->getTrackData()->getPolarity(ALG_RUNGEKUTTA);
is_valid[iCount]=pPidTrackCand->isFlagBit(HPidTrackCand::kIsUsed);
if(is_valid[iCount] && charge==0){
cerr << "valid particle without charge???" << endl;
is_valid[iCount]=false;
}
if (!is_valid[iCount++])
continue;
Charge[counter] = charge;
if (Charge[counter] == 1){
counterPlus++;
}else if (Charge[counter] == -1){
counterMinus++;
}
counter++;
}
if (counterPlus == nPlus && counterMinus == nMinus) {
HHypComb *hypcomb = NULL;
hypcomb = (HHypComb *) m_pContCatComb->getNewSlot(locDummy, &index_comb);
if (hypcomb != 0)
hypcomb =
new(hypcomb) HHypComb(numberOfCombinations * numberOfPossibleMissing,
numberOfRealParticles);
else
return ERROR_IDX;
fill_pid_table(hypcomb);
fill_pid_idx(hypcomb);
if (!fill_pid_fprob(hypcomb, numpidtracks))
return (ERROR_IDX);
HHypList *hyplist = NULL;
hyplist = (HHypList *) m_pContCatList->getNewSlot(locDummy, &index_list);
if (hyplist != 0)
hyplist = new(hyplist) HHypList(index_comb);
else
return ERROR_IDX;
hyplist->setListId(exitList);
for (Int_t Icomb = 0; Icomb < numberOfCombinations; Icomb++) {
if (Icomb < MAX_USER_VALUES) {
for (Int_t k = 0; k < numberOfPossibleMissing; k++) {
hyplist->setUserValue(FILLER_VALID_PIDTRACKS, numberOfParticles,
Icomb + k * numberOfCombinations);
hyplist->setUserValue(FILLER_MISSING_PID, particleArrayMissing[k],
Icomb + k * numberOfCombinations);
}
} else {
Error("wasauchimmer", "mist");
exit(0);
}
}
}
else {
return ERROR_IDX;
}
return index_list;
}
Bool_t HHypListFiller::finalize()
{
if (pid_real_array) {
for (Int_t i = 0; i < numberOfCombinations; i++)
delete[]pid_real_array[i];
delete[]pid_real_array;
}
if (pid_full_array) {
for (Int_t i = 0; i < numberOfCombinations; i++)
delete[]pid_full_array[i];
delete[]pid_full_array;
}
return kTRUE;
}
Bool_t HHypListFiller::AddTrack(Int_t particle)
{
Int_t q;
q = HPidPhysicsConstants::charge(particle);
if (-1 == q) {
particleArrayMinus.Set(nMinus + 1);
particleArrayMinus.AddAt(particle, nMinus);
nMinus++;
if (particle != HPidPhysicsConstants::fakeNeg())
nMinusReal++;
} else if (1 == q) {
particleArrayPlus.Set(nPlus + 1);
particleArrayPlus.AddAt(particle, nPlus);
nPlus++;
if (particle != HPidPhysicsConstants::fakePos())
nPlusReal++;
} else {
return kFALSE;
}
return kTRUE;
}
Bool_t HHypListFiller::AddOneMissing(Int_t particle)
{
particleArrayMissing.Set(numberOfPossibleMissing + 1);
particleArrayMissing.AddAt(particle, numberOfPossibleMissing);
numberOfPossibleMissing++;
return kTRUE;
}
#if 1
void HHypListFiller::just_a_test_for_debugging(void)
{
if (numberOfPossibleMissing == 0) {
cout <<
"[Debug]\tno missing particle defined? Lets add a \"dummy\" particle!" <<
endl;
AddOneMissing(HPidPhysicsConstants::pid("dummy"));
}
cout << "[Debug]\tnMinus = " << nMinus << "\n\tnPlus = " << nPlus << endl;
cout << "[Debug]\tnMinusReal = " << nMinusReal << "\n\tnPlusReal = " <<
nPlusReal << endl;
generateNumberOfCombinations();
cout << "[Debug]\tnumberOfPart = " << numberOfParticles << endl;
cout << "[Debug]\tnumberOfRealPart = " << numberOfRealParticles << endl;
cout << "[Debug]\tnumberOfPossibleMissing = " << numberOfPossibleMissing <<
endl;
cout << "[Debug]\tnegCombin = " << numberOfNegCombinations <<
"\n\tposCombin = " << numberOfPosCombinations << "\n\tallCombin = " <<
numberOfCombinations << endl;
create_pid_table();
cout << "--- PID REAL Array ---" << endl;
for (Int_t i = 0; i < numberOfCombinations; i++) {
for (Int_t j = 0; j < numberOfRealParticles; j++) {
cout << "\t" << pid_real_array[i][j];
}
cout << endl;
}
cout << "--- END ---" << endl;
cout << "--- PID FULL Array ---" << endl;
for (Int_t i = 0; i < numberOfCombinations; i++) {
for (Int_t j = 0; j < numberOfParticles; j++) {
cout << "\t" << pid_full_array[i][j];
}
cout << endl;
}
cout << "--- END ---" << endl;
HHypComb *hc =
new HHypComb(numberOfCombinations * numberOfPossibleMissing,
numberOfRealParticles);
fill_pid_table(hc);
hc->print();
delete hc;
if (pid_real_array) {
for (Int_t i = 0; i < numberOfCombinations; i++)
delete[]pid_real_array[i];
delete[]pid_real_array;
}
if (pid_full_array) {
for (Int_t i = 0; i < numberOfCombinations; i++)
delete[]pid_full_array[i];
delete[]pid_full_array;
}
}
#endif
Bool_t HHypListFiller::generateNumberOfCombinations()
{
numberOfParticles = nMinus + nPlus;
numberOfRealParticles = nMinusReal + nPlusReal;
if (numberOfParticles > HYP_MAX_PARTICLES) {
Error("generateNumberOfCombinations",
"HHypListFiller: we do not support more than HYP_MAX_PARTICLES particles in one reaction");
numberOfCombinations = 0;
return kFALSE;
}
Int_t sort;
do {
sort = kFALSE;
for (Int_t loop = 1; loop < nPlus; loop++) {
if (particleArrayPlus.At(loop - 1) > particleArrayPlus.At(loop)) {
Int_t swap;
swap = particleArrayPlus.At(loop - 1);
particleArrayPlus.AddAt(particleArrayPlus.At(loop), (loop - 1));
particleArrayPlus.AddAt(swap, loop);
sort = kTRUE;
}
}
} while (sort );
do {
Int_t swap;
sort = kFALSE;
for (Int_t loop = 1; loop < nMinus; loop++) {
if (particleArrayMinus.At(loop - 1) > particleArrayMinus.At(loop)) {
swap = particleArrayMinus.At(loop - 1);
particleArrayMinus.AddAt(particleArrayMinus.At(loop), (loop - 1));
particleArrayMinus.AddAt(swap, loop);
sort = kTRUE;
}
}
} while (sort );
#if HYP_MAX_PARTICLES!=10
#error "Filler: only HYP_MAX_PARTICLES=10 supported here!!!"
#endif
static Int_t faculties[11] = {
1, 1, 2, 6,
24,
120,
720,
5040,
40320,
362880,
3628800
};
Int_t product_ks_pos = 1;
Int_t product_ks_neg = 1;
Int_t last_index;
last_index = 0;
for (Int_t loop = 1; loop < nPlus; loop++) {
if (particleArrayPlus.At(loop - 1) != particleArrayPlus.At(loop)) {
product_ks_pos *= faculties[loop - last_index];
last_index = loop;
}
}
product_ks_pos *= faculties[nPlus - last_index];
last_index = 0;
for (Int_t loop = 1; loop < nMinus; loop++) {
if (particleArrayMinus.At(loop - 1) != particleArrayMinus.At(loop)) {
product_ks_neg *= faculties[loop - last_index];
last_index = loop;
}
}
product_ks_neg *= faculties[nMinus - last_index];
numberOfNegCombinations = faculties[nMinus] / product_ks_neg;
numberOfPosCombinations = faculties[nPlus] / product_ks_pos;
numberOfCombinations = numberOfNegCombinations * numberOfPosCombinations;
return kTRUE;
}
void HHypListFiller::PermSwapper(Int_t * array, Int_t a, Int_t b)
{
Int_t s;
s = array[a];
array[a] = array[b];
array[b] = s;
}
void HHypListFiller::PermReverser(Int_t * array, Int_t a, Int_t b)
{
while (a < b) {
PermSwapper(array, a, b);
a++;
b--;
}
}
#if 0
void HHypListFiller::print_array(Int_t * array, Int_t count)
{
for (Int_t i = 0; i < count; i++) {
cout << array[i] << ",";
}
cout << endl;
}
#endif
Bool_t HHypListFiller::FindNextPermutation(Int_t * array, Int_t count)
{
Int_t next = count - 1;
if (count == 0 || next == 0)
return (false);
do {
Int_t next1 = next;
next--;
if (array[next] < array[next1]) {
Int_t mid = count;
while (!(array[next] < array[--mid]));
PermSwapper(array, next, mid);
PermReverser(array, next1, count - 1);
return (true);
}
} while (next);
PermReverser(array, 0, count - 1);
return (false);
}
void HHypListFiller::create_pid_table(void)
{
pid_real_array = new Int_t *[numberOfCombinations];
for (Int_t i = 0; i < numberOfCombinations; i++)
pid_real_array[i] = new Int_t[numberOfRealParticles];
pid_full_array = new Int_t *[numberOfCombinations];
for (Int_t i = 0; i < numberOfCombinations; i++)
pid_full_array[i] = new Int_t[numberOfParticles];
Int_t array_pos[HYP_MAX_PARTICLES], array_neg[HYP_MAX_PARTICLES];
for (Int_t j = 0; j < nMinus; j++) {
array_neg[j] = particleArrayMinus.At(j);
}
for (Int_t j = 0; j < nPlus; j++) {
array_pos[j] = particleArrayPlus.At(j);
}
Int_t i;
i = 0;
do {
Int_t i2;
i2 = i;
for (Int_t k = 0; k < numberOfPosCombinations;
k++, i2 += numberOfNegCombinations) {
if (i2 > numberOfCombinations) {
Error("create_pid_table", "HHypListFiller: neg i2 overflow");
break;
}
for (Int_t j = 0; j < nMinus; j++) {
pid_full_array[i2][(numberOfParticles - 1) - j] = array_neg[j];
}
}
i++;
if (i > numberOfNegCombinations) {
Error("create_pid_table", "HHypListFiller: neg i overflow");
break;
}
} while (FindNextPermutation(array_neg, nMinus));
if (i != numberOfNegCombinations) {
Error("create_pid_table",
"crosscheck: numberOfNegCombinations something fishy here; eigther permuations or calculations wrong!");
}
i = 0;
do {
Int_t i2;
i2 = i * numberOfNegCombinations;
for (Int_t k = 0; k < numberOfNegCombinations; k++, i2++) {
if (i2 > numberOfCombinations) {
Error("create_pid_table", "HHypListFiller: pos i2 overflow");
break;
}
for (Int_t j = 0; j < nPlus; j++) {
pid_full_array[i2][j] = array_pos[j];
}
}
i++;
if (i > numberOfPosCombinations) {
Error("create_pid_table", "HHypListFiller: pos i overflow");
break;
}
} while (FindNextPermutation(array_pos, nPlus));
if (i != numberOfPosCombinations) {
Error("create_pid_table",
"crosscheck: numberOfPosCombinations something fishy here; eigther permuations or calculations wrong!");
}
remove_fakes_pid_table();
}
void HHypListFiller::remove_fakes_pid_table(void)
{
for (Int_t i = 0; i < numberOfCombinations; i++) {
Int_t j2;
j2 = 0;
for (Int_t j = 0; j < numberOfParticles; j++) {
if (pid_full_array[i][j] != HPidPhysicsConstants::fakeNeg()
&& pid_full_array[i][j] != HPidPhysicsConstants::fakePos()) {
pid_real_array[i][j2] = pid_full_array[i][j];
j2++;
}
}
if (j2 != numberOfRealParticles) {
Error("remove_fakes_pid_table",
"[ERROR] crosscheck: number of REAL particles (j2) != numberOfRealParticles");
cerr <<
"[ERROR] crosscheck: number of REAL particles (j2) != numberOfRealParticles "
<< j2 << " " << numberOfRealParticles << endl;
}
}
#if 0
cout << "----------------------------------------" << endl;
for (Int_t i = 0; i < numberOfCombinations; i++) {
for (Int_t j = 0; j < numberOfParticles; j++) {
cout << pid_full_array[i][j] << "\t";
}
cout << endl;
for (Int_t j = 0; j < numberOfRealParticles; j++) {
cout << pid_real_array[i][j] << "\t";
}
cout << endl;
}
cout << "----------------------------------------" << endl;
#endif
}
void HHypListFiller::fill_pid_table(HHypComb * hypcomb)
{
for (Int_t i = 0; i < numberOfCombinations; i++) {
for (Int_t k = 0; k < numberOfPossibleMissing; k++) {
for (Int_t j = 0; j < numberOfRealParticles; j++) {
hypcomb->setPid(i + k * numberOfCombinations, j, pid_real_array[i][j]);
}
}
}
}
void HHypListFiller::fill_pid_idx(HHypComb * hypcomb)
{
Int_t idx = 0;
Int_t *iPosPlus;
Int_t *iPosMinus;
Int_t *iPosPlusF;
Int_t *iPosMinusF;
HPidTrackCand *pPidTrackCand = NULL;
if( numberOfParticles >HYP_MAX_PARTICLES){
cerr << "!!!!fill_pid_idx: numberOfParticles >HYP_MAX_PARTICLES!!"<<endl;
exit(0);
}
if(pid_full_array==0){
cerr << "!!!!fill_pid_idx: pid_full_array==0!!"<<endl;
exit(0);
}
iPosPlus = new Int_t[numberOfCombinations];
iPosMinus = new Int_t[numberOfCombinations];
iPosPlusF = new Int_t[numberOfCombinations];
iPosMinusF = new Int_t[numberOfCombinations];
for (Int_t i = 0; i < numberOfCombinations; i++) {
iPosPlus[i] = 0;
iPosMinus[i] = 0;
iPosPlusF[i] = 0;
iPosMinusF[i] = 0;
}
m_pContItTrackCand->Reset();
while ((pPidTrackCand = (HPidTrackCand *) m_pContItTrackCand->Next()) != NULL && idx<HYP_MAX_TRACKCLEAN) {
if (is_valid[idx]) {
if (pPidTrackCand->getTrackData()->getPolarity(ALG_RUNGEKUTTA) == -1)
{
for (Int_t i = 0; i < numberOfCombinations; i++) {
if (pid_full_array[i][(numberOfParticles - 1) - iPosMinusF[i]] !=
HPidPhysicsConstants::fakeNeg()) {
for (Int_t k = 0; k < numberOfPossibleMissing; k++) {
hypcomb->setIdxPidTrackCand(i + k * numberOfCombinations,
(numberOfRealParticles - 1) - iPosMinus[i],
idx);
}
iPosMinus[i]++;
}
iPosMinusF[i]++;
}
} else if (pPidTrackCand->getTrackData()->getPolarity(ALG_RUNGEKUTTA) == 1)
{
for (Int_t i = 0; i < numberOfCombinations; i++) {
if (pid_full_array[i][iPosPlusF[i]] !=
HPidPhysicsConstants::fakePos()) {
for (Int_t k = 0; k < numberOfPossibleMissing; k++) {
hypcomb->setIdxPidTrackCand(i + k * numberOfCombinations, iPosPlus[i],
idx);
}
iPosPlus[i]++;
}
iPosPlusF[i]++;
}
} else {
Error("fill_pid_idx", "crosscheck: neutral particles not allowed");
cerr << "[ERROR] crosscheck: neutral particles not allowed"<< endl;
}
}
idx++;
}
for (Int_t i = 0; i < numberOfCombinations; i++) {
if (iPosPlus[i] != nPlusReal) {
Error("fill_pid_idx", "crosscheck: iPosPlus[i] != nPlusReal");
cerr << "[ERROR] crosscheck: iPosPlus[i] != nPlusReal "
<< iPosPlus[i] << " " << nPlusReal << endl;
}
if (iPosMinus[i] != nMinusReal) {
Error("fill_pid_idx", "crosscheck: iPosMinus[i] != nMinusReal");
cerr << "[ERROR] crosscheck: iPosMinus[i] != nMinusReal "
<< iPosMinus[i] << " " << nMinusReal << endl;
}
if (iPosPlusF[i] != nPlus) {
Error("fill_pid_idx", "crosscheck: iPosPlusF[i] != nPlus");
cerr << "[ERROR] crosscheck: iPosPlusF[i] != nPlus "
<< iPosPlusF[i] << " " << nPlus << endl;
}
if (iPosMinusF[i] != nMinus) {
Error("fill_pid_idx", "crosscheck: iPosMinusF[i] != nMinus");
cerr << "[ERROR] crosscheck: iPosMinusF[i] != nMinus "
<< iPosMinusF[i] << " " << nMinus << endl;
}
}
delete[]iPosMinus;
delete[]iPosPlus;
delete[]iPosMinusF;
delete[]iPosPlusF;
}
Bool_t HHypListFiller::fill_pid_fprob(HHypComb * hypcomb, Int_t * numpidtracks)
{
HPidTrackCand *pPidTrackCand = NULL;
HCategory *PidTrackCandCat =
gHades->getCurrentEvent()->getCategory(catPidTrackCand);
for (Int_t Icomb = 0; Icomb < numberOfCombinations; Icomb++) {
Float_t ProbComb = 1.0;
if (Icomb < MAX_USER_VALUES)
numpidtracks[Icomb] = 0;
for (Int_t Ipart = 0; Ipart < numberOfRealParticles; Ipart++) {
Int_t Idx = hypcomb->getIdxPidTrackCand(Icomb, Ipart);
pPidTrackCand = (HPidTrackCand *) PidTrackCandCat->getObject(Idx);
if (pPidTrackCand == NULL) {
Error("fill_pid_fprob",
"[ERROR] HHypListFiller::execute() setProbComb");
return kFALSE;
}
Float_t Prob = 1.0;
if (Icomb < MAX_USER_VALUES) {
numpidtracks[Icomb]++;
}
ProbComb *= Prob;
}
if (ProbComb < 0)
ProbComb = 0.0;
for (Int_t k = 0; k < numberOfPossibleMissing; k++) {
hypcomb->setProbComb(Icomb + k * numberOfCombinations, ProbComb);
}
}
return kTRUE;
}
Last change: Sat May 22 12:57:50 2010
Last generated: 2010-05-22 12:57
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.