// Author: IF
// Written: 25.05.2007
// Revised: 
// PDynamicData Class Header

#ifndef _PDYNAMICDATA_H_
#define _PDYNAMICDATA_H_

#define MAX_PCHANNEL_OBJECTS 10000

#include "TROOT.h"
#include "TF1.h"
#include <iostream>

#include "PDataBase.h"
#include "PDistribution.h"
#include "PMesh.h"
#include "PChannelModel.h"
#include "PParticle.h"


class PDynamicData;
PDynamicData *makeDynamicData();
PDynamicData &fDynamicData();

class PDynamicData : public TObject {
      
 public:

    PDynamicData();

    //**** Decays
    Double_t GetDecayPartialWidth(Double_t mass,Int_t didx);
   
    PChannelModel *GetDecayModel(Int_t didx);
    PChannelModel *GetDecayModelByKey(Int_t key);
    PChannelModel *GetDecayModelByKey(Int_t key, Int_t defkey);
    bool SetDecayModel(Int_t didx,      PChannelModel *model);
    bool SetDecayModelByKey(Int_t didx, PChannelModel *model);
    Double_t GetDecaySCFactor(Int_t didx);
    void SetDecaySCFactor(Int_t didx, Double_t factor);
    bool CheckSCAbort(Int_t didx);  //to stop endless loops
    double GetDecayBR(int , double); 
    // branching ratio by mode index & mass (GeV/c^2) 
    
    void ListDecayBR(const Char_t *pid, double mass) { 
	ListDecayBR(makeStaticData()->IsParticleValid(pid), mass); 
    } 
    void ListDecayBR(int pid, double mass); 
    // list branching ratios by particle id & mass (GeV/c^2) 
  
    int PickDecayChannel(const int &, const double &);
    // decay index for particle pid of given mass (GeV/c**2),
    // randomly selected consistent with the branching ratios

    int PickDecayChannel(const char *id, const double &m) {
	// as above, by particle name
	return PickDecayChannel(makeStaticData()->IsParticleValid(id), m); 
    }

    int PickDecayChannel(const int &, const double &, int *);
    // number and pids of decay products for the decay of particle 
    // pid of given mass(GeV/c**2), via a randomly selected mode 
    
    int PickDecayChannel(const char *id, const double &m, int *array) {
	// as above, by particle name
	return PickDecayChannel(makeStaticData()->IsParticleValid(id), m, array);
    }
    
    //**** Particles
    PChannelModel *GetParticleModel(Int_t pid);
    PChannelModel *GetParticleSecondaryModel(const char *name, const char *modelname);

    Double_t GetParticleTotalWidth(Double_t mass, Int_t pid);
    // mass-dependent total resonance decay width by id (units GeV/c**2)

    Double_t GetParticleTotalWidthSum(Double_t mass, Int_t id, Int_t flag=0);
    // same as above but by resumming the partial width (slower but more precise)
    // flag=1: take into account only hadronic decays

    Double_t GetParticleTotalWeight(Double_t mass, Int_t pid, Int_t didx=-1);
    Double_t GetParticleScalingFactor(Int_t didx);
    void SetParticleScalingFactor(Int_t didx, Double_t factor);

    int GetParticleDepth(const int &id, int flag=0);
    
    int GetParticleDepth(const char *id, int i=0) { 
	return GetParticleDepth(makeStaticData()->IsParticleValid(id), i);
    }
      
    double GetParticleLife(const int &id, double m=0, int idx=-1);
    // mean life
    // Arguments: 1. id=particle id 
    //            2. m=mass (GeV/c**2)
    //            3. idx=decay-mode index
    
    double GetParticleLife(const char *id, double m=0, int idx=-1) {
	// as above, by particle name
	return GetParticleLife(makeStaticData()->IsParticleValid(id), m, idx);
    }

    //Debug info... similar to PStaticData
    void PrintParticle(int pid);
    void PrintParticleByKey(int key);
    void PrintDecayByKey(int key);

    PParticle * GetBatchParticle(const char *name, Int_t make_val=1);
    TH1   *GetBatchHistogram(const char *name);
    Bool_t SetBatchHistogram(const char *name, TH1 *histo);

    void PushPChannel(TObject *obj) {
        if (num_pchannels == MAX_PCHANNEL_OBJECTS) {
            Warning("Push", "MAX_PCHANNEL_OBJECTS reached");
            return;
        }
        pchannel_list[num_pchannels++]=obj;
    };

    TObject **GetPChannels(Int_t *num) {
        *num = num_pchannels;
        if (num_pchannels) return pchannel_list;
        return NULL;
    };

    void DumpPChannels(void) {
        for (int i=0; i<num_pchannels; i++)
            pchannel_list[i]->Print();
    };


 private:
     Int_t *i_result;
     char  *c_result;
     Double_t *d_result;
     TObject *t_result;
     Int_t  pid_param,  enhance_br_param;
     Int_t  name_param, model_param, didx_param, scfactor_param, sccount_param;
     Int_t  pnmodes_param, link_param;

     TObject *pchannel_list[MAX_PCHANNEL_OBJECTS]; //list of all created PChannels for bookkeeping
     Int_t num_pchannels;

  ClassDef(PDynamicData, 0) //Pluto Dynamic Data Interface (for mass-dependent values)
};

#endif // _PDATAUTIL_H_
 PDynamicData.h:1
 PDynamicData.h:2
 PDynamicData.h:3
 PDynamicData.h:4
 PDynamicData.h:5
 PDynamicData.h:6
 PDynamicData.h:7
 PDynamicData.h:8
 PDynamicData.h:9
 PDynamicData.h:10
 PDynamicData.h:11
 PDynamicData.h:12
 PDynamicData.h:13
 PDynamicData.h:14
 PDynamicData.h:15
 PDynamicData.h:16
 PDynamicData.h:17
 PDynamicData.h:18
 PDynamicData.h:19
 PDynamicData.h:20
 PDynamicData.h:21
 PDynamicData.h:22
 PDynamicData.h:23
 PDynamicData.h:24
 PDynamicData.h:25
 PDynamicData.h:26
 PDynamicData.h:27
 PDynamicData.h:28
 PDynamicData.h:29
 PDynamicData.h:30
 PDynamicData.h:31
 PDynamicData.h:32
 PDynamicData.h:33
 PDynamicData.h:34
 PDynamicData.h:35
 PDynamicData.h:36
 PDynamicData.h:37
 PDynamicData.h:38
 PDynamicData.h:39
 PDynamicData.h:40
 PDynamicData.h:41
 PDynamicData.h:42
 PDynamicData.h:43
 PDynamicData.h:44
 PDynamicData.h:45
 PDynamicData.h:46
 PDynamicData.h:47
 PDynamicData.h:48
 PDynamicData.h:49
 PDynamicData.h:50
 PDynamicData.h:51
 PDynamicData.h:52
 PDynamicData.h:53
 PDynamicData.h:54
 PDynamicData.h:55
 PDynamicData.h:56
 PDynamicData.h:57
 PDynamicData.h:58
 PDynamicData.h:59
 PDynamicData.h:60
 PDynamicData.h:61
 PDynamicData.h:62
 PDynamicData.h:63
 PDynamicData.h:64
 PDynamicData.h:65
 PDynamicData.h:66
 PDynamicData.h:67
 PDynamicData.h:68
 PDynamicData.h:69
 PDynamicData.h:70
 PDynamicData.h:71
 PDynamicData.h:72
 PDynamicData.h:73
 PDynamicData.h:74
 PDynamicData.h:75
 PDynamicData.h:76
 PDynamicData.h:77
 PDynamicData.h:78
 PDynamicData.h:79
 PDynamicData.h:80
 PDynamicData.h:81
 PDynamicData.h:82
 PDynamicData.h:83
 PDynamicData.h:84
 PDynamicData.h:85
 PDynamicData.h:86
 PDynamicData.h:87
 PDynamicData.h:88
 PDynamicData.h:89
 PDynamicData.h:90
 PDynamicData.h:91
 PDynamicData.h:92
 PDynamicData.h:93
 PDynamicData.h:94
 PDynamicData.h:95
 PDynamicData.h:96
 PDynamicData.h:97
 PDynamicData.h:98
 PDynamicData.h:99
 PDynamicData.h:100
 PDynamicData.h:101
 PDynamicData.h:102
 PDynamicData.h:103
 PDynamicData.h:104
 PDynamicData.h:105
 PDynamicData.h:106
 PDynamicData.h:107
 PDynamicData.h:108
 PDynamicData.h:109
 PDynamicData.h:110
 PDynamicData.h:111
 PDynamicData.h:112
 PDynamicData.h:113
 PDynamicData.h:114
 PDynamicData.h:115
 PDynamicData.h:116
 PDynamicData.h:117
 PDynamicData.h:118
 PDynamicData.h:119
 PDynamicData.h:120
 PDynamicData.h:121
 PDynamicData.h:122
 PDynamicData.h:123
 PDynamicData.h:124
 PDynamicData.h:125
 PDynamicData.h:126
 PDynamicData.h:127
 PDynamicData.h:128
 PDynamicData.h:129
 PDynamicData.h:130
 PDynamicData.h:131
 PDynamicData.h:132
 PDynamicData.h:133
 PDynamicData.h:134
 PDynamicData.h:135
 PDynamicData.h:136
 PDynamicData.h:137
 PDynamicData.h:138
 PDynamicData.h:139
 PDynamicData.h:140
 PDynamicData.h:141
 PDynamicData.h:142
 PDynamicData.h:143
 PDynamicData.h:144
 PDynamicData.h:145
 PDynamicData.h:146