#ifndef _PBEAMLINESIMULATION_H_
#define _PBEAMLINESIMULATION_H_
#include "PBeamSmearing.h"
#include "PBulkInterface.h"
#include "PProjector.h"
#define MAX_NUM_BEAM_PARTICLES 1000
class PBeamLineSimulation : public PBeamSmearing  {
  
 public:
    PBeamLineSimulation();
    ~PBeamLineSimulation();
    PBeamLineSimulation(Char_t *id, Char_t *de);
    
    PDistribution *Clone(const char *delme=NULL) const;
    Bool_t Init(void);
    Bool_t Prepare(void);
    Bool_t InitBeamLine(char *filename);
    Int_t  AddDetector (char *name, Double_t distance);
    Bool_t TargetIsElement(Int_t n);
    void   SetGlobalMomentum(Double_t p) {global_p = p;};
    Bool_t AddEquation(char *command);
    Bool_t AddHistogram(TH2 *histo, const char *command = "");
    Bool_t Do(char *command) {return AddEquation(command);};
    Bool_t Do(TH2 *histo, const char *command = "") {return AddHistogram(histo, command);};
    
    void SetBeamtubeSize(Double_t _beamtube_size_x, Double_t _beamtube_size_y) {
	beamtube_size_x = _beamtube_size_x;
	beamtube_size_y = _beamtube_size_y;
    };
    
 private:
    PParticle *beam,   *mybeam;
    PParticle *target, *mytarget;
    PParticle *parent;
    PParticle *beam_particles[MAX_NUM_BEAM_PARTICLES];
    Int_t      beam_id       [MAX_NUM_BEAM_PARTICLES];
    Int_t      beam_counter;
    Double_t  *filter;
    Double_t   beamtube_size_x, beamtube_size_y; 
    char      *detector_name[MAX_NUM_BEAM_PARTICLES];
    Double_t   detector_distance[MAX_NUM_BEAM_PARTICLES];
    Int_t      detector_counter;
    
    Int_t AddBeamParticle(char *name);
    void MakeVars(void);
    PProjector *projector;
    
    long double T11[51],T12[51],T13[51],T14[51],T16[51];
    long double T111[51],T112[51],T113[51],T114[51],T116[51];
    long double T122[51],T123[51],T124[51],T126[51];
    long double T133[51],T134[51],T136[51];
    long double T144[51],T146[51];
    long double T166[51],along[51];
    long double T21[51],T22[51],T23[51],T24[51],T26[51];      
    long double T211[51],T212[51],T213[51],T214[51],T216[51];
    long double T222[51],T223[51],T224[51],T226[51];
    long double T233[51],T234[51],T236[51];
    long double T244[51],T246[51];
    long double T266[51];      
    long double T31[51],T32[51],T33[51],T34[51],T36[51];
    long double T311[51],T312[51],T313[51],T314[51],T316[51];
    long double T322[51],T323[51],T324[51],T326[51];
    long double T333[51],T334[51],T336[51];
    long double T344[51],T346[51];
    long double T366[51];
    long double T41[51],T42[51],T43[51],T44[51],T46[51]; 
    long double T411[51],T412[51],T413[51],T414[51],T416[51];
    long double T422[51],T423[51],T424[51],T426[51];
    long double T433[51],T434[51],T436[51];
    long double T444[51],T446[51];
    long double T466[51];
           
    Int_t nelem; 
    char txt2[3]; 
    char txt5[6]; 
    
    long double z1; 
    long double z2; 
    long double z3; 
    long double z4; 
    long double z5; 
    
    long double xi; 
    long double xpi;
    long double yi; 
    long double ypi; 
    long double dp; 
    
    Int_t iok; 
    long double xf; 
    long double yf; 
    long double xpf; 
    long double ypf; 
    long double xf1; 
    long double yf1; 
    long double xpf1; 
    long double ypf1; 
    long double xf2; 
    long double xpf2; 
    long double yf2; 
    long double ypf2; 
    long double aa;
    long double sig11; 
    long double sig22; 
    long double r12; 
    long double sig33; 
    long double r13; 
    long double r23; 
    long double sig44;
    long double r14; 
    long double r24; 
    long double r34; 
    long double sig55; 
    long double r15; 
    long double r25; 
    long double r35; 
    long double r45; 
    long double sig66; 
    long double r16; 
    long double r26; 
    long double r36; 
    long double r46; 
    long double r56; 
    Int_t ii; 
    Int_t ind1; 
    Int_t ind23; 
    Int_t num_target;
    Double_t *in_xi;
    Double_t *in_yi;
    Double_t *in_dp;
    Double_t *in_xpi;
    Double_t *in_ypi;
    Double_t out_xi[51];
    Double_t out_yi[51];
    Double_t out_dp[51];
    Double_t out_xpi[51];
    Double_t out_ypi[51];
    Double_t global_p;
    ClassDef(PBeamLineSimulation, 0)  
};
#endif
 PBeamLineSimulation.h:100  PBeamLineSimulation.h:101  PBeamLineSimulation.h:102  PBeamLineSimulation.h:103  PBeamLineSimulation.h:104  PBeamLineSimulation.h:105  PBeamLineSimulation.h:106  PBeamLineSimulation.h:107  PBeamLineSimulation.h:108  PBeamLineSimulation.h:109  PBeamLineSimulation.h:110  PBeamLineSimulation.h:111  PBeamLineSimulation.h:112  PBeamLineSimulation.h:113  PBeamLineSimulation.h:114  PBeamLineSimulation.h:115  PBeamLineSimulation.h:116  PBeamLineSimulation.h:117  PBeamLineSimulation.h:118  PBeamLineSimulation.h:119  PBeamLineSimulation.h:120  PBeamLineSimulation.h:121  PBeamLineSimulation.h:122  PBeamLineSimulation.h:123  PBeamLineSimulation.h:124  PBeamLineSimulation.h:125  PBeamLineSimulation.h:126  PBeamLineSimulation.h:127  PBeamLineSimulation.h:128  PBeamLineSimulation.h:129  PBeamLineSimulation.h:130  PBeamLineSimulation.h:131  PBeamLineSimulation.h:132  PBeamLineSimulation.h:133  PBeamLineSimulation.h:134  PBeamLineSimulation.h:135  PBeamLineSimulation.h:136  PBeamLineSimulation.h:137  PBeamLineSimulation.h:138  PBeamLineSimulation.h:139  PBeamLineSimulation.h:140  PBeamLineSimulation.h:141  PBeamLineSimulation.h:142  PBeamLineSimulation.h:143  PBeamLineSimulation.h:144  PBeamLineSimulation.h:145  PBeamLineSimulation.h:146  PBeamLineSimulation.h:147  PBeamLineSimulation.h:148  PBeamLineSimulation.h:149  PBeamLineSimulation.h:150  PBeamLineSimulation.h:151  PBeamLineSimulation.h:152  PBeamLineSimulation.h:153  PBeamLineSimulation.h:154  PBeamLineSimulation.h:155  PBeamLineSimulation.h:156  PBeamLineSimulation.h:157  PBeamLineSimulation.h:158  PBeamLineSimulation.h:159  PBeamLineSimulation.h:160  PBeamLineSimulation.h:161  PBeamLineSimulation.h:162  PBeamLineSimulation.h:163  PBeamLineSimulation.h:164  PBeamLineSimulation.h:165  PBeamLineSimulation.h:166  PBeamLineSimulation.h:167  PBeamLineSimulation.h:168  PBeamLineSimulation.h:169