- Float_t ntr = fSpBinWidth*fSpectrum->Integral();
- // Number of TR photons from Poisson distribution with mean <ntr>
- nPhoton = gRandom->Poisson(ntr);
- // Energy of the TR photons
- for (Int_t iPhoton = 0; iPhoton < nPhoton; iPhoton++) {
- ePhoton[iPhoton] = fSpectrum->GetRandom();
+ Float_t nTr = fSpBinWidth * fSpectrum->Integral();
+ // Number of TR photons from Poisson distribution with mean <nTr>
+ Int_t nPhCand = gRandom->Poisson(nTr);
+
+ // Link the MC stack and get info about parent electron
+ TVirtualMCStack *stack = gMC->GetStack();
+ TParticle *trGenerator = stack->GetCurrentTrack();
+ Int_t track = stack->GetCurrentTrackNumber();
+ Double_t px = trGenerator->Px() / trGenerator->P();
+ Double_t py = trGenerator->Py() / trGenerator->P();
+ Double_t pz = trGenerator->Pz() / trGenerator->P();
+
+ // Current position of electron
+ Double_t x;
+ Double_t y;
+ Double_t z;
+ gMC->TrackPosition(x,y,z);
+
+ // Counter for TR analysed in custom code (e < 15keV)
+ nPhoton = 0;
+
+ for (Int_t iPhoton = 0; iPhoton < nPhCand; iPhoton++) {
+
+ // Energy of the TR photon
+ Double_t e = fSpectrum->GetRandom();
+
+ // Put TR photon on particle stack
+ if (e > 15.0 ) {
+
+ e *= 1.0e-6; // Convert it to GeV
+
+ Int_t phtrack;
+ stack-> PushTrack(1 // Must be 1
+ ,track // Identifier of the parent track, -1 for a primary
+ ,22 // Particle code.
+ ,px*e // 4 momentum (The photon is generated on the same
+ ,py*e // direction as the parent. For irregular radiator one
+ ,pz*e // can calculate also the angle but this is a secondary
+ ,e // order effect)
+ ,x,y,z,0.0 // 4 vertex
+ ,0.0,0.0,0.0 // Polarisation
+ ,kPFeedBackPhoton // Production mechanism (there is no TR in G3 so one
+ // has to make some convention)
+ ,phtrack // On output the number of the track stored
+ ,1.0
+ ,1);
+
+ }
+ // Custom treatment of TR photons
+ else {
+
+ ePhoton[nPhoton++] = e;
+
+ }
+