4 #include "MicroStat/MCSampler.h"
5 #include "KVNucleusEvent.h"
8 #include <TMultiGraph.h>
10 #include "TVirtualPad.h"
21 void MCSampler::init()
28 fModifyMasses = kFALSE;
36 void MCSampler::initialiseWeightList()
40 fWeightList =
new TClonesArray(fWeight);
48 MCSampler::MCSampler()
60 MCSampler::MCSampler(
const Char_t* name,
const Char_t* title) :
KVBase(name, title)
75 SafeDelete(fWeightList);
87 fPartitions = t->GetEntries();
88 fBranch = t->GetBranch(branchname);
90 KVError::Error(
this,
"SetEventList",
"cannot find branch %s", branchname.Data());
93 fBranch->SetAddress(&fPartition);
107 fWeight = TClass::GetClass(w);
109 KVError::Error(
this,
"SetStatWeight",
"class %s not found", w.Data());
140 if (!fWeightList) initialiseWeightList();
144 for (
int i = 0; i < fPartitions; i++) {
178 Double_t x = gRandom->Uniform(fSumWeights);
181 for (i = 0; i < fPartitions; i++) {
186 if (i == fPartitions) {
187 fLastPicked =
nullptr;
198 void MCSampler::SetBranch(TTree* theTree,
const TString& bname,
void* variable,
const TString& vartype)
200 TString leaflist = bname +
"/";
202 TBranch* b = theTree->GetBranch(bname);
203 if (!b) theTree->Branch(bname, variable, leaflist);
204 else b->SetAddress(variable);
229 TBranch* b = theTree->GetBranch(bname);
231 theTree->Branch(bname,
"KVEvent", event, 10000000, 0)->SetAutoDelete(kFALSE);
234 b->SetAddress(event);
236 SetBranch(theTree,
"ESTAR", &ESTAR,
"D");
237 SetBranch(theTree,
"EDISP", &EDISP,
"D");
238 SetBranch(theTree,
"IPART", &IPART,
"L");
262 Info(
"GenerateEvents",
"Generating events for E*=%f", Exx);
265 KVError::Error(
this,
"GenerateEvents",
"Excitation energy is too low, no channels are open");
270 while (npartitions--) {
275 for (Long64_t iev = 0; iev < nev_part; iev++) {
302 if (fSumWeights == 0)
return kFALSE;
319 if (IPART < 0)
return kFALSE;
383 Bool_t makeLegend = (fLegendProbaMin > 0.0);
385 TMultiGraph* mg =
new TMultiGraph();
386 TGraph* g[fPartitions];
391 for (; i < fPartitions; i++) {
393 if (!i && !strcmp(opt,
"E*/A")) fac = pt->
GetSum(
"GetA");
396 g[i]->SetMarkerStyle(mark);
397 g[i]->SetMarkerColor((i % 9) + 1);
398 g[i]->SetLineColor((i % 9) + 1);
399 g[i]->SetFillColor(0);
400 g[i]->ResetBit(BIT(20));
405 if (mark > 30) mark = 20;
410 for (
double E = emin; E <= emax; E += estep) {
413 for (i = 0; i < fPartitions; i++) {
421 g[voie]->SetPoint(g[voie]->GetN(), E, proba * 100.);
425 if (makeLegend && proba > fLegendProbaMin) g[voie]->SetBit(BIT(20));
429 if (gPad) gPad->Clear();
431 if (!strcmp(opt,
"E*/A")) {
432 mg->GetHistogram()->SetXTitle(
"E*/A (MeV)");
439 mg->GetHistogram()->SetXTitle(
"E* (MeV)");
445 mg->GetHistogram()->SetYTitle(
"Probability");
447 mg->GetHistogram()->SetAxisRange(fLegendProbaMin * 100, 100.,
"Y");
449 fTheLegend =
new TLegend(.7, 0.12, .88, .88);
450 fTheLegend->SetHeader(Form(
"Channels with P>%4.1f%%", fLegendProbaMin * 100));
451 for (i = 0; i < mg->GetListOfGraphs()->GetSize(); i++) {
452 if (g[i]->TestBit(BIT(20))) {
453 fTheLegend->AddEntry(g[i], g[i]->GetName(),
"pl");
475 TMultiGraph* mg =
new TMultiGraph();
476 const int nparticles = 7;
477 TGraph* g[nparticles];
479 TString particles[] = {
"1n",
"1H",
"2H",
"3H",
"3He",
"4He",
"Z>2"};
484 if (!strcmp(opt,
"E*/A")) {
493 for (
int i = 0; i < nparticles; i++) {
495 g[i]->SetName(particles[i]);
496 g[i]->SetMarkerStyle(mark);
497 g[i]->SetMarkerColor((i % 9) + 1);
498 g[i]->SetLineColor((i % 9) + 1);
499 g[i]->SetFillColor(0);
500 g[i]->ResetBit(BIT(20));
505 if (mark > 30) mark = 20;
514 for (
double E = emin; E <= emax; E += estep) {
517 Double_t multiplicities[nparticles];
518 memset(multiplicities, 0,
sizeof(
double)*nparticles);
520 for (Long64_t i = 0; i < fPartitions; i++) {
526 if (proba > 1.e-06) {
529 for (
int j = 0; j < nparticles - 1; j++) {
530 if (!strcmp(n.GetSymbol(), particles[j].Data())) multiplicities[j] += proba;
532 if (n.GetZ() > 2) multiplicities[nparticles - 1] += proba;
538 for (
int i = 0; i < nparticles; i++) {
539 g[i]->SetPoint(g[i]->GetN(), E, multiplicities[i]);
546 if (gPad) gPad->Clear();
548 if (!strcmp(opt,
"E*/A")) {
549 mg->GetHistogram()->SetXTitle(
"E*/A (MeV)");
552 mg->GetHistogram()->SetXTitle(
"E* (MeV)");
555 mg->GetHistogram()->SetYTitle(
"Multiplicity");
Class for iterating over nuclei in events accessed through base pointer/reference.
Base class for KaliVeda framework.
Abstract base class container for multi-particle events.
virtual Double_t GetSum(const Char_t *, Option_t *="")=0
virtual Double_t GetChannelQValue() const =0
virtual KVString GetPartitionName()=0
Monte-Carlo sampling of events with statistical weights .
virtual ~MCSampler()
Destructor.
void PlotProbabilities(double emin=0., double emax=100., double estep=1., Option_t *opt="")
void PlotMultiplicities(double emin=0., double emax=100., double estep=1., Option_t *opt="")
StatWeight * GetWeight(Int_t i) const
void SetUpTreeBranches(KVEvent *&event, TTree *theTree, const TString &bname)
void SetEventList(TTree *t, const TString &branchname)
Define the TTree or TChain containing all possible events (partitions).
void GenerateEvents(TTree *, KVEvent *event, Double_t, Long64_t npartitions, Long64_t nev_part=10)
Bool_t SetExcitationEnergy(Double_t Exx)
Long64_t PickRandomChannel()
void CalculateWeights(Double_t excitation_energy)
KVEvent * GetPartition(Long64_t i)
void SetStatWeight(const TString &)
void GenerateEvent(TTree *theTree, KVEvent *event)
Double_t GetSumWeights() const
Abstract base class for calculating statistical weights for events .
void SetIndex(Long64_t i)
virtual void SetWeight(KVEvent *e, Double_t E)=0
void GenerateEvent(KVEvent *partition, KVEvent *event)
virtual void initGenerateEvent(KVEvent *partition)=0
Double_t GetAvailableEnergy() const
virtual void resetGenerateEvent()=0
Double_t GetWeight() const
Long64_t GetIndex() const
void Error(UserClass p, const char *location, const char *va_(fmt),...)