| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DsG4GdCaptureGammas.cc File Reference

#include "DsG4GdCaptureGammas.h"
#include "Randomize.hh"
#include <TRandom.h>
#include <vector>
#include "G4Gamma.hh"
#include "TROOT.h"
#include "TFile.h"
#include "TH1F.h"
#include "TMath.h"

Include dependency graph for DsG4GdCaptureGammas.cc:

Go to the source code of this file.


Functions

static double getRandomCLHEP (TH1 *hh)

Function Documentation

static double getRandomCLHEP ( TH1 *  hh  )  [static]

Definition at line 105 of file DsG4GdCaptureGammas.cc.

00106 {
00107     // return a random number distributed according the histogram bin contents.
00108     // This function checks if the bins integral exists. If not, the integral
00109     // is evaluated, normalized to one.
00110     // The integral is automatically recomputed if the number of entries
00111     // is not the same then when the integral was computed.
00112     // NB Only valid for 1-d histograms. Use GetRandom2 or 3 otherwise.
00113   
00114     if (hh->GetDimension()> 1) {
00115         G4cout << "Error in getRandomCLHEP: Function only valid for 1-d histograms"
00116                <<endl;
00117         return 0;
00118     }
00119     int nbinsx = hh->GetNbinsX();
00120     double integral;
00121   
00122     double *myIntegral = 0; //array
00123     myIntegral = hh->GetIntegral();
00124   
00125     if (myIntegral) {
00126         if (myIntegral[nbinsx+1] != hh->GetEntries()) {
00127             integral = hh->ComputeIntegral();
00128             //get the pointer to the integral array again
00129             myIntegral = hh->GetIntegral();
00130         } 
00131     } else {
00132         integral = hh->ComputeIntegral();
00133         //get the pointer to the integral array again
00134         myIntegral = hh->GetIntegral(); 
00135         if (integral == 0 || myIntegral == 0) return 0;
00136     }
00137   
00138     //Here enforce the CLHEP random number generator!
00139     //Double_t r1 = gRandom->Rndm();
00140     double r1 = HepRandom::getTheEngine()->flat();
00141   
00142     int ibin = TMath::BinarySearch(nbinsx,myIntegral,r1);
00143     double x = hh->GetBinLowEdge(ibin+1);
00144     if (r1 > myIntegral[ibin]) 
00145         x +=
00146             hh->GetBinWidth(ibin+1)*(r1-myIntegral[ibin])
00147             /(myIntegral[ibin+1] - myIntegral[ibin]);
00148     return x;
00149 }

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:53:25 2011 for DetSim by doxygen 1.4.7