#ifndef _PDECAYLIST_H_
#define _PDECAYLIST_H_
#include "TObject.h"
class TTree;
class TClonesArray;
class PReaction;
class PChannel;
class PParticle;
class TPythia6;
#include "PDistributionManager.h"
#include "PReaction.h"
#include "PBulkInterface.h"
#include "PProjector.h"
template<class T>
class PNextList {
public:
T *Curr;
PNextList *Next;
PNextList() : Curr(NULL), Next(NULL) {};
PNextList(T *t) : Curr(t), Next(NULL) {};
~PNextList() { if (Next) delete Next; };
void Add(T *t) {
if (!Curr)
Curr = t;
else if (!Next)
Next = new PNextList<T>(t);
else
Next->Add(t);
}
void Delete() {
delete Curr;
if (Next)
Next->Delete();
}
};
template<class T>
class PStack {
public:
PNextList<T> *top;
Int_t Count;
PStack() : top(NULL), Count(0) {};
~PStack() { delete top; };
void Push(T* t) {
PNextList<T> *temp = new PNextList<T>(t);
temp->Next = top;
top = temp;
Count++;
}
T *Pop() {
if (!top) return NULL;
T *t = top->Curr;
PNextList<T> *t2 = top;
top = top->Next;
t2->Next = NULL;
delete t2;
Count--;
return t;
}
PStack<T> *Clone(PStack<T> *UseThis = NULL) {
PStack<T> *t1;
if (UseThis)
t1 = UseThis;
else
t1 = new PStack();
if (!top)
return t1;
t1->Push(top->Curr);
PNextList<T> *t2 = top;
while (t2->Next) {
t2 = t2->Next;
t1->top->Add(t2->Curr);
}
t1->Count = Count;
return t1;
}
};
class PReactionList {
public:
PStack<PChannel> *Finished;
PStack<PChannel> *ToDo;
Double_t ReactionWeight;
Int_t ID;
static Int_t maxID;
PReactionList() {
Finished = new PStack<PChannel>;
ToDo = new PStack<PChannel>;
ReactionWeight = 1.;
ID = ++maxID;
};
~PReactionList() {
delete Finished;
delete ToDo;
}
PReactionList *Clone() {
PReactionList *newRL = new PReactionList;
Finished->Clone(newRL->Finished);
ToDo->Clone(newRL->ToDo);
newRL->ReactionWeight = ReactionWeight;
return newRL;
}
};
class PDecayManager : public TObject {
private:
Int_t verbose;
Double_t CurrentWeight;
Int_t CurrentReactionNumber;
PNextList<PParticle> *UsedParticles;
PNextList<PParticle*> *UsedParticleArrays;
PNextList<PChannel> *UsedChannels;
PNextList<PReactionList> *ReactionList;
PNextList<PReactionList> *CurrentReactionListPointer;
PChannel **ListForReaction;
PReaction *CurrentReaction;
Int_t NumberOfReactions;
Int_t decaychannel_param;
Bool_t fHGeant;
void* userSelection;
Int_t nTrigCond;
Bool_t fWriteIndex;
TPythia6 *fPythia;
void ConstructPChannel(PParticle *p, PDecayChannel *c1,
PReactionList *RL, Int_t CopyFlag=0);
void PrintReactionListEntry(PReactionList*, ostream &os) const;
void PrintChain(PParticle *p, PChannel **l, Int_t c, ostream &os) const;
using TObject::GetName;
const char *GetName(Int_t id) const;
Int_t maxFileSize;
Float_t tauMax;
PDistributionManager *pdist;
int fileoutput_pos;
PFileOutput *files[MAX_FILEOUTPUT];
int bulkdecay_pos, pro_bulkdecay_pos;
PBulkInterface *bulk[MAX_BULKDECAY];
PBulkInterface *pro_bulk[MAX_BULKDECAY];
PProjector *current_projector;
public:
PDecayManager();
~PDecayManager();
void SetVerbose(Int_t v = 1);
void AddChannel(Int_t id, PDecayChannel *n);
void AddChannel(PParticle *p, PDecayChannel *n);
void AddChannel(const char *p, PDecayChannel *n);
PDecayChannel *GetChannel(Int_t id) const;
PDecayChannel *GetChannel(PParticle *p) const;
PDecayChannel *GetChannel(char *n) const;
void SetDefault(Int_t id, Int_t recursive=0);
void SetDefault(PParticle *p, Int_t recursive=0);
void SetDefault(const char *p, Int_t recursive=0);
void Clear(Int_t id);
void Clear(PParticle *p);
void MyClear(char *);
void Clear(const Option_t *delme=NULL) {
if (delme) MyClear((char*) delme);
};
void InitReaction(PParticle *start, PDecayChannel *c1 = NULL);
PReaction *GetNextReaction(int wf, const char *name, int f0=0, int f1=0,
int f2=0, int f3=0, TTree *tt=NULL);
PReaction *GetNextReaction(const char *name, int f0=0, int f1=0, int f2=0,
int f3=0, TTree *tt=NULL);
Int_t Loop(int num, int wf, const char* name, int f0=0,
int f1=0, int f2=0, int f3=0, int rf=0);
Int_t loop(int num, int wf, const char* name, int f0=0,
int f1=0, int f2=0, int f3=0, int rf=0) {
return Loop(num, wf, name, f0, f1, f2, f3, rf);
}
Double_t GetCurrentWeight();
void Print(const Option_t *delme=NULL) const {
if (delme && strlen(delme)) {
MyPrint((char*) delme);
}
else MyPrint();
};
void MyPrint() const;
void Print(Int_t id) const;
void Print(PParticle *p) const;
void MyPrint(char *name) const;
void SetHGeant(Int_t fH) {
fHGeant = fH;
}
void SetUserSelection(void *f) {
userSelection = f;
}
void SetUserSelection(Int_t (*f)(PParticle*)) {
userSelection = (void*)f;
}
void SetTrigCond(Int_t n) {
nTrigCond = n;
}
void PrintReactionList() const;
void SetPythia(TPythia6 *p) {
fPythia = p;
}
void SetMaxFileSize(Int_t bytes) {
maxFileSize = bytes;
}
void SetDecayAll(Float_t tau=1.) {
tauMax = tau;
}
void DisableHelicityAngle(void) {
pdist->Disable("helicity_angles");
}
PDistributionManager *GetDistributionManager(void) {
return makeDistributionManager();
}
void SetWriteIndex(Bool_t flag) {
fWriteIndex = flag;
}
Bool_t AddFileOutput(PFileOutput *file) {
if (fileoutput_pos == MAX_FILEOUTPUT ) {
Warning("AddFileOutput", "MAX_FILEOUTPUT reached");
return kFALSE;
}
files[fileoutput_pos++] = file;
return kTRUE;
}
Bool_t AddBulk(PBulkInterface *mybulk);
Bool_t AddPrologueBulk(PBulkInterface *mybulk);
Bool_t Do(const char *command) {
return GetCurrentProjector()->AddCommand(command);
}
Bool_t Do(TH1F *f, char *command) {
return GetCurrentProjector()->AddHistogram(f, command);
}
Bool_t Do(TH2F *f, char *command) {
return GetCurrentProjector()->AddHistogram(f, command);
}
Bool_t Output(TNtuple *f, char *command = (char *)"") {
return GetCurrentProjector()->AddOutputTNtuple(f, command);
}
Bool_t Input(TNtuple *f) {
return GetCurrentProjector()->AddInputTNtuple(f);
}
PProjector *GetCurrentProjector(void) {
if (!bulkdecay_pos) {
current_projector = new PProjector();
AddBulk(current_projector);
} else {
if (strcmp("PProjector", bulk[bulkdecay_pos-1]->GetName()) == 0) {
current_projector = (PProjector *) bulk[bulkdecay_pos-1];
} else {
current_projector = new PProjector();
AddBulk(current_projector);
}
}
return current_projector;
}
ClassDef(PDecayManager,0)
};
#endif // _PDECAYLIST_H_