// Author: M.A. Kagarlis
// Written: 31.01.99
// Revised: (IF)
// PDataUtil Class Header

#ifndef _PSTATICDATA_H_
#define _PSTATICDATA_H_

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

#include "PDataBase.h"
#include "PMesh.h"


#define MAX_DAUGHTERS 7

using namespace std;

class PStaticData;
PStaticData *makeStaticData();
PStaticData &fStaticData();


void listParticle(int id = -1);
void listParticle(const char *id);
void listModes(int id = -1);
void listModes(const char *id);

class PStaticData : public TObject {
      
 public:

    PStaticData();

    //Freeze out -> Important to check this
    void SetFreezeOut(void) {
	freeze = kTRUE;
    };

    void clearFreezeOut(void) {
	//re-loop PStdModels
	freeze = kFALSE;
    };
    
    bool GetFreezeOut(void) {
	return freeze;
    }

    //Common stuff
    int   AddAlias(const char *old_name,
		   const char *new_name); //adds an alias, ret value is alias key
    int   GetAliasParent(const char *alias_name);
    int   GetAliasParent(int key);
    
    int   MakeDirectoryEntry(const char *name, const char *n, const char *l,
			     const char *ename);  //adds a directory, ret value is key
    Double_t *GetBatchValue(const char *name, Int_t make_val=1);
    bool SetBatchValue(const char *name, Double_t val) {
	Double_t *tmp = GetBatchValue(name);
	if (!tmp) return kFALSE;
	(*tmp) = val;
	return kTRUE;
    }

    int   GetSecondaryKey(int key, int defkey); //Loops over the alias entries and look for matching defkey

    //Particle get methods
    int   GetParticleID(const char *id, int warn=1);     // pid by name
    int   GetParticleIDByKey(int key);        // pid by key
    const char *GetParticleName(const int &id);  // name by pid
    int   GetParticleKey(const int &id);     // data base key by pid
    int   GetParticleKey(const char *id) {
	return GetParticleKey(GetParticleID(id));
    };
    int   IsParticle(const int &id, const char *name); // does pid correspond to given name?
    int   IsParticleValid(const int &id);          // check id range by id
    int   IsParticleValid(const char *n);    // check id range by name

    int   AddParticle(int pid, const char *name, double mass);
    void  PrintParticle(int pid);
    void  PrintParticleByKey(int pid);
    void  PrintParticle(const char *id) {
	PrintParticle(GetParticleID(id));
    };

    int   GetParticleKF(const int Id);     // return Pythia6 kf code
    int   GetParticleIDbyKF(const int kf); // return Id corresponding to Pythia6 kf code

    int   IsParticleMeson(const int &id);   // is meson?, by pid
    void  SetParticleMeson(const char* id, Int_t num=1);   // set meson number

    int   IsParticleHadron(const int &id);  // is hadron?, by pid
    int   GetParticleBaryon(const int &id);    // baryon number by pid
    void  SetParticleBaryon(const char *id, Int_t num=1);    // baryon number by name

    int   GetParticleLepton(const int &id);    // lepton number by pid
    void  SetParticleLepton(const char *id, Int_t num=1);

    int   GetParticleCharge(const int &id);    // charge by pid
    int   GetParticleCharge(const char *id);   // charge by name
    void  SetParticleCharge(const char *id, Int_t charge);

    int   GetParticleSpin(const int &id);      // 2 x J by pid
    int   GetParticleSpin(const char *id);     // 2 x J by name
    void  SetParticleSpin(const char *id, Int_t spin);

    int   GetParticleIsospin(const int &id);   // 2 x I by pid
    int   GetParticleIsospin(const char *id);  // 2 x I by name
    void  SetParticleIsospin(const char *id, Int_t isospin);

    int   GetParticleParity(const int &id);    // parity (0 if irrelevant)
    int   GetParticleParity(const char *id);   // parity (0 if irrelevant)
    void  SetParticleParity(const char *id, Int_t parity);

    double GetParticleMass(const int &id);   // mass by id  
    double GetParticleMass(const char *id);  // mass by name
    double GetParticleMassByKey(const int &id);
    void SetParticleMass(Int_t id, Float_t mass); //reset mass
    void SetParticleMass(const char *id, Float_t mass); //reset mass

    int GetParticleNChannels(const int &id); // number of decay channels by pid  
    int GetParticleNChannels(const char *id);// number of decay channels by name
    int GetParticleNChannelsByKey(int id);

    void   SetParticleTotalWidth(Int_t id, Float_t wid);
    void   SetParticleTotalWidth(const char *id, Float_t wid);
    double GetParticleTotalWidth(const int &id); // -->PWidth[id]
    double GetParticleTotalWidth(const char *id) {
	return GetParticleTotalWidth(GetParticleID(id));
    };
    double GetParticleTotalWidthByKey(const int &id); 

    double GetParticleEmin(const int &id); // Returns the energy threshold for the particle
    void   SetParticleEmin(const int &id, const double v);

    //Change particle range:
    double GetParticleLMass(const int &id); // Returns lower mass (used in all samplings)
    double GetParticleLMass(const char *id) {
	return GetParticleLMass(GetParticleID(id));
    };
    double GetParticleUMass(const int &id); // Returns upper mass (used in all samplings)
    double GetParticleUMass(const char *id) {
	return GetParticleUMass(GetParticleID(id));
    };
    void SetParticleLMass(const int &id, const double v) { // Set lower mass (used in all samplings)
	SetParticleLMass(GetParticleName(id),v);
    };
    void SetParticleLMass(const char *id, const double v); // Set lower mass (used in all samplings)

    void SetParticleUMass(const int &id, const double v) { // Set upper mass (used in all samplings)
	SetParticleUMass(GetParticleName(id),v);
    };
    void SetParticleUMass(const char *id, const double v);// Set upper mass (used in all samplings)

    bool NormParticleBR(Int_t id); // normalize branching ratios for particle id
    bool NormParticleBRbyKey(Int_t key);
    void SetTotalNormalization(char *p,int flag=1);

    //Decay methods
    void FreezeDecayBR(Int_t id, Int_t brn); // Set BR  (BUGBUG->brn nomally unknown)
    bool SetDecayBR(int didx, double br, int mode);
    bool SetDecayBR(const char *parent, const char *daughters, double br, int mode);
    bool SetDecayBRByKey(int key, double br, int mode);

    Double_t GetDecayBR(Int_t id);
    Double_t GetDecayPartialWidth(Int_t id);
    Double_t GetDecayPartialWidthByKey(Int_t id);
    const char *GetDecayName(Int_t id);
    const char *GetDecayNameByKey(Int_t key);

    Int_t IsDecayHadronic(Int_t didx);
    
    int  AddDecay(int didx, const char *name, const char *parent, 
		  const char *daughters , double br);
    int  AddDecay(const char *name, const char *parent, 
		  const char *daughters , double br) {
	return AddDecay(-1, name, parent, 
			daughters , br); };
    int  AddDecay(int *ipid, int n);
    void PrintDecayByKey(int key);

    int GetDecayNProducts(const int &); // retrieve number of products by mode index 
    int GetDecayNProducts(const char *);// number of products by name 
    int GetDecayNProductsByKey(const int &key);

    int GetDecayParent(const int &); // parent pid from decay mode index
    int GetDecayParentByKey(const int &); 
    void GetDecayMode(const int, int *n); // retrieve product number, pids, by mode index
    void GetDecayModeByKey(const int, int *n); 

    int GetDecayIdx(int *pid, int n); // decay-mode index from parent and product ids; ->getChannel
    int GetDecayIdx(const char *parent, const char *daughters);
    int GetDecayKey(int *pid, int n); 
    int GetDecayKey(const int &id);
    int GetDecayIdxByKey(int key);
     
    int GetDecayBRFlag(int didx);
    void SetDecayBRFlag(int didx, int flag);
     
    double GetDecayEmin(const int &idx); // Returns the energy threshold for the decay mode with index=idx
    void   SetDecayEmin(const int &idx, const double v);

    void SetEnhanceChannelBR(const int id, const double factor); //enhance the BR for PickDecayChannel
    void SetEnhanceChannelBR(const char *parent, const char *decay, Double_t factor = 1.);
    void DisableAllChannelBR(const char *parent);
    Double_t GetEnhanceChannelBR(const int id);

    //for dynamic stuff
    int GetTWidx(const int &); // total width flag from index
    int GetPWidx(const int &); // partial width flag from index
    void SetTWidx(const int &, const int &); // total width flag from index
    void SetPWidx(const int &, const int &); // partial width flag from index

    int GetTDepth(const int &); 
    void SetTDepth(const int &, const int &); 
    int GetHDepth(const int &); 
    void SetHDepth(const int &, const int &); 

    void SetTWidthMesh(const int &, PMesh *mesh);
    PMesh * GetTWidthMesh(const int &);

    void SetPWidthMesh(const int &, PMesh *mesh);
    PMesh * GetPWidthMesh(const int &);

    void SetTF1(const int &, TF1 *mesh);
    TF1 * GetTF1(const int &);

    //global friend functions
    //Keeping for backward compatibility
  
    friend void listParticle(int id);
    // list particles in data base and their properties, by particle pid

    friend void listParticle(const char *id) {
	listParticle(makeStaticData()->GetParticleID(id));
    };
    // list particles in data base and their properties, by particle code name
    
    friend void listModes(int id);
    // list decay modes in data base, by particle pid
    
    friend void listModes(const char *id){
	listModes(makeStaticData()->GetParticleID(id));
    };
    // list decay modes in data base, by particle name
    
    

 private:
    Int_t *i_result;
    const char *c_result;
    Double_t   *d_result;
    TObject    *t_result;
    Int_t  pid_param;
    Int_t  name_param;
    Int_t  meson_param, baryon_param, lepton_param;
    Int_t  charge_param, spin_param, ispin_param;
    Int_t  parity_param, mass_param, width_param;
    Int_t  pkf_param, didx_param, enhance_br_param;
    Int_t  widx_param, mesh_param, tf1_param, ethreshold_param, lmass_param, umass_param;
    Int_t  tdepth_param, hdepth_param, br_param, brorig_param, count_param;
    Int_t  d1_param, d2_param, d3_param, pnmodes_param, ppid_param;
    Int_t  d4_param, d5_param, d6_param, d7_param;
    Int_t  brflag_param;
    Int_t  nalias_param, lalias_param, defkey_param;

    Bool_t freeze;

    Double_t *system_alloc_verbosity;

    ClassDef(PStaticData, 0) //Pluto Static Data Wrapper

};

#endif // _PDATAUTIL_H_







	
 PStaticData.h:1
 PStaticData.h:2
 PStaticData.h:3
 PStaticData.h:4
 PStaticData.h:5
 PStaticData.h:6
 PStaticData.h:7
 PStaticData.h:8
 PStaticData.h:9
 PStaticData.h:10
 PStaticData.h:11
 PStaticData.h:12
 PStaticData.h:13
 PStaticData.h:14
 PStaticData.h:15
 PStaticData.h:16
 PStaticData.h:17
 PStaticData.h:18
 PStaticData.h:19
 PStaticData.h:20
 PStaticData.h:21
 PStaticData.h:22
 PStaticData.h:23
 PStaticData.h:24
 PStaticData.h:25
 PStaticData.h:26
 PStaticData.h:27
 PStaticData.h:28
 PStaticData.h:29
 PStaticData.h:30
 PStaticData.h:31
 PStaticData.h:32
 PStaticData.h:33
 PStaticData.h:34
 PStaticData.h:35
 PStaticData.h:36
 PStaticData.h:37
 PStaticData.h:38
 PStaticData.h:39
 PStaticData.h:40
 PStaticData.h:41
 PStaticData.h:42
 PStaticData.h:43
 PStaticData.h:44
 PStaticData.h:45
 PStaticData.h:46
 PStaticData.h:47
 PStaticData.h:48
 PStaticData.h:49
 PStaticData.h:50
 PStaticData.h:51
 PStaticData.h:52
 PStaticData.h:53
 PStaticData.h:54
 PStaticData.h:55
 PStaticData.h:56
 PStaticData.h:57
 PStaticData.h:58
 PStaticData.h:59
 PStaticData.h:60
 PStaticData.h:61
 PStaticData.h:62
 PStaticData.h:63
 PStaticData.h:64
 PStaticData.h:65
 PStaticData.h:66
 PStaticData.h:67
 PStaticData.h:68
 PStaticData.h:69
 PStaticData.h:70
 PStaticData.h:71
 PStaticData.h:72
 PStaticData.h:73
 PStaticData.h:74
 PStaticData.h:75
 PStaticData.h:76
 PStaticData.h:77
 PStaticData.h:78
 PStaticData.h:79
 PStaticData.h:80
 PStaticData.h:81
 PStaticData.h:82
 PStaticData.h:83
 PStaticData.h:84
 PStaticData.h:85
 PStaticData.h:86
 PStaticData.h:87
 PStaticData.h:88
 PStaticData.h:89
 PStaticData.h:90
 PStaticData.h:91
 PStaticData.h:92
 PStaticData.h:93
 PStaticData.h:94
 PStaticData.h:95
 PStaticData.h:96
 PStaticData.h:97
 PStaticData.h:98
 PStaticData.h:99
 PStaticData.h:100
 PStaticData.h:101
 PStaticData.h:102
 PStaticData.h:103
 PStaticData.h:104
 PStaticData.h:105
 PStaticData.h:106
 PStaticData.h:107
 PStaticData.h:108
 PStaticData.h:109
 PStaticData.h:110
 PStaticData.h:111
 PStaticData.h:112
 PStaticData.h:113
 PStaticData.h:114
 PStaticData.h:115
 PStaticData.h:116
 PStaticData.h:117
 PStaticData.h:118
 PStaticData.h:119
 PStaticData.h:120
 PStaticData.h:121
 PStaticData.h:122
 PStaticData.h:123
 PStaticData.h:124
 PStaticData.h:125
 PStaticData.h:126
 PStaticData.h:127
 PStaticData.h:128
 PStaticData.h:129
 PStaticData.h:130
 PStaticData.h:131
 PStaticData.h:132
 PStaticData.h:133
 PStaticData.h:134
 PStaticData.h:135
 PStaticData.h:136
 PStaticData.h:137
 PStaticData.h:138
 PStaticData.h:139
 PStaticData.h:140
 PStaticData.h:141
 PStaticData.h:142
 PStaticData.h:143
 PStaticData.h:144
 PStaticData.h:145
 PStaticData.h:146
 PStaticData.h:147
 PStaticData.h:148
 PStaticData.h:149
 PStaticData.h:150
 PStaticData.h:151
 PStaticData.h:152
 PStaticData.h:153
 PStaticData.h:154
 PStaticData.h:155
 PStaticData.h:156
 PStaticData.h:157
 PStaticData.h:158
 PStaticData.h:159
 PStaticData.h:160
 PStaticData.h:161
 PStaticData.h:162
 PStaticData.h:163
 PStaticData.h:164
 PStaticData.h:165
 PStaticData.h:166
 PStaticData.h:167
 PStaticData.h:168
 PStaticData.h:169
 PStaticData.h:170
 PStaticData.h:171
 PStaticData.h:172
 PStaticData.h:173
 PStaticData.h:174
 PStaticData.h:175
 PStaticData.h:176
 PStaticData.h:177
 PStaticData.h:178
 PStaticData.h:179
 PStaticData.h:180
 PStaticData.h:181
 PStaticData.h:182
 PStaticData.h:183
 PStaticData.h:184
 PStaticData.h:185
 PStaticData.h:186
 PStaticData.h:187
 PStaticData.h:188
 PStaticData.h:189
 PStaticData.h:190
 PStaticData.h:191
 PStaticData.h:192
 PStaticData.h:193
 PStaticData.h:194
 PStaticData.h:195
 PStaticData.h:196
 PStaticData.h:197
 PStaticData.h:198
 PStaticData.h:199
 PStaticData.h:200
 PStaticData.h:201
 PStaticData.h:202
 PStaticData.h:203
 PStaticData.h:204
 PStaticData.h:205
 PStaticData.h:206
 PStaticData.h:207
 PStaticData.h:208
 PStaticData.h:209
 PStaticData.h:210
 PStaticData.h:211
 PStaticData.h:212
 PStaticData.h:213
 PStaticData.h:214
 PStaticData.h:215
 PStaticData.h:216
 PStaticData.h:217
 PStaticData.h:218
 PStaticData.h:219
 PStaticData.h:220
 PStaticData.h:221
 PStaticData.h:222
 PStaticData.h:223
 PStaticData.h:224
 PStaticData.h:225
 PStaticData.h:226
 PStaticData.h:227
 PStaticData.h:228
 PStaticData.h:229
 PStaticData.h:230
 PStaticData.h:231
 PStaticData.h:232
 PStaticData.h:233
 PStaticData.h:234
 PStaticData.h:235
 PStaticData.h:236
 PStaticData.h:237
 PStaticData.h:238
 PStaticData.h:239
 PStaticData.h:240
 PStaticData.h:241
 PStaticData.h:242
 PStaticData.h:243
 PStaticData.h:244
 PStaticData.h:245
 PStaticData.h:246
 PStaticData.h:247
 PStaticData.h:248
 PStaticData.h:249
 PStaticData.h:250
 PStaticData.h:251
 PStaticData.h:252
 PStaticData.h:253
 PStaticData.h:254
 PStaticData.h:255
 PStaticData.h:256
 PStaticData.h:257
 PStaticData.h:258
 PStaticData.h:259
 PStaticData.h:260
 PStaticData.h:261
 PStaticData.h:262
 PStaticData.h:263
 PStaticData.h:264
 PStaticData.h:265
 PStaticData.h:266
 PStaticData.h:267
 PStaticData.h:268
 PStaticData.h:269
 PStaticData.h:270
 PStaticData.h:271
 PStaticData.h:272
 PStaticData.h:273
 PStaticData.h:274
 PStaticData.h:275
 PStaticData.h:276
 PStaticData.h:277
 PStaticData.h:278
 PStaticData.h:279
 PStaticData.h:280
 PStaticData.h:281
 PStaticData.h:282
 PStaticData.h:283
 PStaticData.h:284
 PStaticData.h:285