| 1 |
// $Id: PamVMCPrimaryGenerator.h,v 1.0 2007/06/03 |
| 2 |
|
| 3 |
#ifndef PAMVMC_PRIMARY_GENERATOR_H |
| 4 |
#define PAMVMC_PRIMARY_GENERATOR_H |
| 5 |
|
| 6 |
#include <iostream> |
| 7 |
#include <TVirtualMCApplication.h> |
| 8 |
#include <TClonesArray.h> |
| 9 |
#include <TVector3.h> |
| 10 |
#include <TVector2.h> |
| 11 |
#include <TMath.h> |
| 12 |
#include <TRandom.h> |
| 13 |
#include <TF1.h> |
| 14 |
|
| 15 |
#include "PamRootManager.h" |
| 16 |
|
| 17 |
class TVirtualMCStack; |
| 18 |
|
| 19 |
using std::cout; |
| 20 |
using std::endl; |
| 21 |
using TMath::Sqrt; |
| 22 |
|
| 23 |
class PamVMCPrimary : public TObject |
| 24 |
{ |
| 25 |
|
| 26 |
public: |
| 27 |
|
| 28 |
PamVMCPrimary(): fPDG(0), fX0(0.), fY0(0.), fZ0(0.), fTHETA(0.), fPHI(0.), fP0(0.), fGOOD(kFALSE) { }; |
| 29 |
|
| 30 |
|
| 31 |
Int_t fPDG; |
| 32 |
Double_t fX0, fY0, fZ0; |
| 33 |
Double_t fTHETA, fPHI; |
| 34 |
Double_t fP0; |
| 35 |
Bool_t fGOOD; |
| 36 |
|
| 37 |
void Clean() { fPDG=0; fX0=fY0=fZ0=fTHETA=fPHI=fP0=0.; fGOOD=kFALSE;} |
| 38 |
|
| 39 |
void Clear(const Option_t * =""){ Clean(); } |
| 40 |
|
| 41 |
void Print(const Option_t * ="") const |
| 42 |
{ cout<<"PRIMARY particle infromation:"<<endl; |
| 43 |
cout<<"Pdg="<<fPDG<<endl; //add name later |
| 44 |
cout<<"Position: "<<"("<<fX0<<","<<fY0<<","<<fZ0<<")"<<endl; |
| 45 |
cout<<"P0, Theta, Phi: "<<fP0<<","<<fTHETA<<","<<fPHI<<endl; |
| 46 |
cout<<"GOOD Single Track:"<<fGOOD<<endl; |
| 47 |
} |
| 48 |
|
| 49 |
ClassDef(PamVMCPrimary,1); |
| 50 |
}; |
| 51 |
|
| 52 |
PamVMCPrimary & operator+=(PamVMCPrimary &a, const PamVMCPrimary &b); |
| 53 |
|
| 54 |
class PamVMCPrimaryGenerator : public TObject |
| 55 |
{ |
| 56 |
public: |
| 57 |
PamVMCPrimaryGenerator(TVirtualMCStack* stack); |
| 58 |
PamVMCPrimaryGenerator(); |
| 59 |
|
| 60 |
virtual ~PamVMCPrimaryGenerator(); |
| 61 |
|
| 62 |
// methods |
| 63 |
|
| 64 |
void GeneratePrimary(); |
| 65 |
// set methods |
| 66 |
void SetParticle(Int_t pdg); |
| 67 |
void SetPosition(Double_t vx, Double_t vy, Double_t vz) |
| 68 |
{fprim.fX0=vx; fprim.fY0=vy; fprim.fZ0=vz;}; |
| 69 |
|
| 70 |
void SetKinEnergy(Double_t kinEnergy) {fprim.fP0=KinEToMomentum(kinEnergy);}; |
| 71 |
void SetRigidity(Double_t rigidity) {fprim.fP0=RigToMomentum(rigidity);}; |
| 72 |
void SetMomentum(Double_t momentum) {fprim.fP0=momentum; }; |
| 73 |
|
| 74 |
void SetDirection(Double_t theta, Double_t phi) {fprim.fTHETA=theta; fprim.fPHI=phi; }; |
| 75 |
void SetMomentum(Double_t px, Double_t py, Double_t pz); |
| 76 |
|
| 77 |
void SetGood(Bool_t isgood) {fprim.fGOOD=isgood; }; |
| 78 |
|
| 79 |
// gen methods |
| 80 |
|
| 81 |
void GenPosition(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax){ |
| 82 |
SetPosition(frandom->Uniform(xmin,xmax),frandom->Uniform(ymin,ymax),frandom->Uniform(zmin,zmax)); } |
| 83 |
|
| 84 |
void GenDirection(Double_t thetamin, Double_t thetamax, Double_t phimin, Double_t phimax){ |
| 85 |
SetDirection(ftheta->GetRandom(thetamin, thetamax), frandom->Uniform(phimin,phimax)); |
| 86 |
} |
| 87 |
//flat spectra generator |
| 88 |
void GenSpe(Double_t PEmin, Double_t PEmax, Bool_t isEnergy=kFALSE); |
| 89 |
//power law spectra, gamma - differential spectral index |
| 90 |
void GenSpe(Double_t PEmin, Double_t PEmax, Double_t gamma, Bool_t isEnergy=kFALSE); |
| 91 |
|
| 92 |
// get methods |
| 93 |
Int_t GetParticle(){ return fprim.fPDG; }; |
| 94 |
void GetPositon(TVector3 & v){ v.SetXYZ(fprim.fX0,fprim.fY0,fprim.fZ0); }; |
| 95 |
void GetPosition(Double_t X0, Double_t Y0,Double_t Z0) |
| 96 |
{X0=fprim.fX0; Y0=fprim.fY0; Z0=fprim.fZ0;}; |
| 97 |
|
| 98 |
Double_t GetKinEnergy() { return MomentumToKinE(fprim.fP0); }; |
| 99 |
Double_t GetRigidity() { return MomentumToRig(fprim.fP0); }; |
| 100 |
Double_t GetMomentum() { return fprim.fP0; }; |
| 101 |
|
| 102 |
void GetDirection(TVector2 & v) {v.Set(fprim.fTHETA,fprim.fPHI);} |
| 103 |
|
| 104 |
Bool_t Getgood(){ return fprim.fGOOD; }; |
| 105 |
|
| 106 |
//initialize random |
| 107 |
void SetRandom(TRandom* random){ |
| 108 |
frandom = random; |
| 109 |
} |
| 110 |
|
| 111 |
//work with collection of primaries |
| 112 |
|
| 113 |
void Register(){ |
| 114 |
PamRootManager::Instance()-> |
| 115 |
Register("PRIM","TClonesArray", &fprimColl); |
| 116 |
} |
| 117 |
|
| 118 |
void ClearPrimCol(){ |
| 119 |
fevno=0; |
| 120 |
(*fprimColl).Clear(); |
| 121 |
} |
| 122 |
|
| 123 |
private: |
| 124 |
// methods |
| 125 |
|
| 126 |
Double_t MomentumToKinE(Double_t P0); |
| 127 |
Double_t KinEToMomentum(Double_t E0); |
| 128 |
Double_t MomentumToRig(Double_t P0) { return P0/fcharge; }; |
| 129 |
Double_t RigToMomentum(Double_t R0){ return R0*fcharge; }; |
| 130 |
|
| 131 |
// data members |
| 132 |
TVirtualMCStack* fStack; |
| 133 |
Int_t fevno; |
| 134 |
PamVMCPrimary fprim; |
| 135 |
Double_t fmass; |
| 136 |
Double_t fcharge; |
| 137 |
TClonesArray* fprimColl; |
| 138 |
TRandom* frandom; // Class is not a owner of this object |
| 139 |
TF1* ftheta; // To generate sherical distributhin in theta-angle |
| 140 |
|
| 141 |
ClassDef(PamVMCPrimaryGenerator,1) //PamVMCPrimaryGenerator |
| 142 |
}; |
| 143 |
|
| 144 |
// inline functions |
| 145 |
|
| 146 |
|
| 147 |
inline Double_t PamVMCPrimaryGenerator::MomentumToKinE(Double_t P0) |
| 148 |
{ return Sqrt(P0*P0+fmass*fmass)-fmass; } |
| 149 |
|
| 150 |
inline Double_t PamVMCPrimaryGenerator::KinEToMomentum(Double_t E0) |
| 151 |
{ return Sqrt(E0*E0+2.*E0*fmass); } |
| 152 |
|
| 153 |
#endif //PAMVMC_PRIMARY_GENERATOR_H |
| 154 |
|