GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gtestROOTGeometry.cxx File Reference
#include <string>
#include <vector>
#include <cassert>
#include <TFile.h>
#include <TNtupleD.h>
#include <TSystem.h>
#include <TLorentzVector.h>
#include <TVector3.h>
#include <TApplication.h>
#include <TPolyMarker3D.h>
#include "Framework/Conventions/Constants.h"
#include "Tools/Geometry/ROOTGeomAnalyzer.h"
#include "Framework/EventGen/PathLengthList.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"
Include dependency graph for gtestROOTGeometry.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void GetRandomRay (TLorentzVector &x, TLorentzVector &p)
 
int GetTargetMaterial (const PathLengthList &pl)
 
TVector3 kDefOptRayDirection (1, 0, 0)
 
TVector3 kDefOptRaySurf (0, 0, 0)
 
int main (int argc, char **argv)
 

Variables

string gOptGeomFile
 
string gOptRootGeomTopVol
 
TVector3 gOptRayDirection
 
TVector3 gOptRaySurf
 
double gOptRayR
 
int gOptNVtx
 
int gOptTgtPdg
 
double kDefOptRayR = 100
 

Function Documentation

void GetCommandLineArgs ( int  argc,
char **  argv 
)
void GetRandomRay ( TLorentzVector &  x,
TLorentzVector &  p 
)

Definition at line 200 of file gtestROOTGeometry.cxx.

References gOptRayDirection, gOptRayR, gOptRaySurf, genie::RandomGen::Instance(), genie::constants::kPi, LOG, pNOTICE, and genie::RandomGen::RndFlux().

Referenced by main().

201 {
202 // generate a random ray (~flux neutrino)
203 //
204  RandomGen * rnd = RandomGen::Instance();
205 
206  TVector3 vec0(gOptRayDirection);
207  TVector3 vec = vec0.Orthogonal();
208 
209  double phi = 2.*kPi * rnd->RndFlux().Rndm();
210  double Rt = -1;
211  bool accept = false;
212  while(!accept) {
213  double r = gOptRayR * rnd->RndFlux().Rndm();
214  double y = gOptRayR * rnd->RndFlux().Rndm();
215  if(y<r) {
216  accept = true;
217  Rt = r;
218  }
219  }
220 
221  vec.Rotate(phi,vec0);
222  vec.SetMag(Rt);
223 
224  vec = vec + gOptRaySurf;
225 
226  TLorentzVector xx(vec, 0.);
227  TLorentzVector pp(gOptRayDirection, gOptRayDirection.Mag());
228 
229  x = xx;
230  p = pp;
231 
232  LOG("test", pNOTICE)
233  << "** Curr ray:";
234  LOG("test", pNOTICE)
235  << " x = " << x.X() << ", y = " << x.Y() << ", z = " << x.Z();
236  LOG("test", pNOTICE)
237  << " px = " << p.X() << ", py = " << p.Y() << ", pz = " << p.Z();
238 
239 }
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
double gOptRayR
TVector3 gOptRayDirection
TVector3 gOptRaySurf
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:71
int GetTargetMaterial ( const PathLengthList pl)

Definition at line 241 of file gtestROOTGeometry.cxx.

References genie::PathLengthList::AreAllZero(), gOptTgtPdg, genie::RandomGen::Instance(), genie::PathLengthList::PathLength(), and genie::RandomGen::RndFlux().

Referenced by main().

242 {
243  if(pl.AreAllZero()) return -1;
244 
245  if(gOptTgtPdg > 0) {
246  if(pl.PathLength(gOptTgtPdg) > 0) return gOptTgtPdg;
247  }
248  else {
249  RandomGen * rnd = RandomGen::Instance();
250 
251  PathLengthList::const_iterator pliter;
252  double sum = 0;
253  for(pliter = pl.begin(); pliter != pl.end(); ++pliter) {
254  sum += pliter->second;
255  }
256  double cpl = sum * rnd->RndFlux().Rndm();
257  sum = 0;
258  for(pliter = pl.begin(); pliter != pl.end(); ++pliter) {
259  sum += pliter->second;
260  if(cpl < sum) {
261  return pliter->first;
262  }
263  }
264  }
265  return -1;
266 }
double PathLength(int pdgc) const
bool AreAllZero(void) const
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:71
int gOptTgtPdg
TVector3 kDefOptRayDirection ( ,
,
 
)
TVector3 kDefOptRaySurf ( ,
,
 
)
int main ( int  argc,
char **  argv 
)

Definition at line 106 of file gtestROOTGeometry.cxx.

References genie::geometry::ROOTGeomAnalyzer::ComputeMaxPathLengths(), genie::geometry::ROOTGeomAnalyzer::ComputePathLengths(), genie::geometry::ROOTGeomAnalyzer::GenerateVertex(), GetCommandLineArgs(), genie::geometry::ROOTGeomAnalyzer::GetGeometry(), GetRandomRay(), GetTargetMaterial(), gOptGeomFile, gOptNVtx, gOptRootGeomTopVol, genie::pdg::IonPdgCodeToA(), genie::pdg::IonPdgCodeToZ(), LOG, pERROR, pINFO, pNOTICE, and genie::geometry::ROOTGeomAnalyzer::SetTopVolName().

107 {
108  GetCommandLineArgs(argc, argv);
109 
110 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__
111 
112  TApplication theApp("App", &argc, argv);
113 
114  // Create & configure the geometry driver
115  //
116  LOG("test", pINFO)
117  << "Creating a geometry driver for ROOT geometry at: "
118  << gOptGeomFile;
119  geometry::ROOTGeomAnalyzer * geom_driver =
121  geom_driver ->SetTopVolName(gOptRootGeomTopVol);
122 
123  // Draw the geometry
124  // & define TPolyMarker3D for drawing vertices later on
125  //
126  LOG("test", pINFO)
127  << "Drawing the ROOT geometry";
128  geom_driver->GetGeometry()->GetTopVolume()->Draw();
129 
130  TPolyMarker3D * vtxp = new TPolyMarker3D();
131  vtxp->SetMarkerColor(kRed);
132  vtxp->SetMarkerStyle(8);
133  vtxp->SetMarkerSize(0.4);
134 
135  // Compute & Printout the (density weighted) max path lengths
136  //
137  LOG("test", pINFO)
138  << "Computing max {density-weighted path lengths}";
139  const PathLengthList & maxpl = geom_driver->ComputeMaxPathLengths();
140 
141  LOG("test", pINFO) << "Maximum math lengths: " << maxpl;
142 
143  TFile f("geomtest.root","recreate");
144  TNtupleD vtxnt("vtxnt","","x:y:z:A:Z");
145 
146  TLorentzVector x(0,0,0,0);
147  TLorentzVector p(0,0,0,0);
148 
149  int n = 0;
150  while (n < gOptNVtx) {
151 
152  // generate a random ray
153  GetRandomRay(x,p);
154 
155  // compute density-weighted path lengths for each geometry
156  // material for the current ray
157  const PathLengthList & pl = geom_driver->ComputePathLengths(x,p);
158  LOG("test",pINFO)
159  << "Current path lengths: " << pl;
160 
161  // select detector material (amongst all materials defined in the
162  // detector geometry -- do so based on density-weighted path lengths)
163  // or force it to the user-selected material
164  int tpdg = GetTargetMaterial(pl);
165  if (tpdg == -1) continue;
166  LOG("test",pINFO) << "Selected target material: " << tpdg;
167 
168  // generate an 'interaction vertex' in the selected material
169  const TVector3 & vtx = geom_driver->GenerateVertex(x,p,tpdg);
170  LOG("test",pINFO)
171  << "Generated vtx: (x = " << vtx.X()
172  << ", y = " << vtx.Y() << ", z = " <<vtx.Z() << ")";
173 
174  // add it at the ntuple & at the vtx marker
175  vtxnt.Fill(vtx.X(),vtx.Y(),vtx.Z(),
177  vtxp->SetNextPoint(vtx.X(),vtx.Y(),vtx.Z());
178 
179  n++;
180  LOG("test", pNOTICE)
181  << " *** Vertices generated so far: " << n;
182  }
183 
184  // draw vertices
185  vtxp->Draw("same");
186 
187  vtxnt.Write();
188  f.Close();
189 
190  theApp.Run(kTRUE);
191 
192 #else
193  LOG("test", pERROR)
194  << "*** You should have enabled the geometry drivers first!";
195 #endif
196 
197  return 0;
198 }
virtual const PathLengthList & ComputeMaxPathLengths(void)
#define pERROR
Definition: Messenger.h:59
string gOptGeomFile
int IonPdgCodeToA(int pdgc)
Definition: PDGUtils.cxx:63
virtual const PathLengthList & ComputePathLengths(const TLorentzVector &x, const TLorentzVector &p)
Object to be filled with the neutrino path-length, for all detector geometry materials, when starting from a position x and travelling along the direction of the neutrino 4-momentum.
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string gOptRootGeomTopVol
Definition: gAtmoEvGen.cxx:301
A ROOT/GEANT4 geometry driver.
void GetRandomRay(TLorentzVector &x, TLorentzVector &p)
int gOptNVtx
#define pINFO
Definition: Messenger.h:62
virtual const TVector3 & GenerateVertex(const TLorentzVector &x, const TLorentzVector &p, int tgtpdg)
virtual void SetTopVolName(string nm)
int GetTargetMaterial(const PathLengthList &pl)
int IonPdgCodeToZ(int pdgc)
Definition: PDGUtils.cxx:55
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
virtual TGeoManager * GetGeometry(void) const

Variable Documentation

string gOptGeomFile

Definition at line 93 of file gtestROOTGeometry.cxx.

Referenced by main().

int gOptNVtx

Definition at line 98 of file gtestROOTGeometry.cxx.

Referenced by main().

TVector3 gOptRayDirection

Definition at line 95 of file gtestROOTGeometry.cxx.

Referenced by GetRandomRay().

double gOptRayR

Definition at line 97 of file gtestROOTGeometry.cxx.

Referenced by GetRandomRay().

TVector3 gOptRaySurf

Definition at line 96 of file gtestROOTGeometry.cxx.

Referenced by GetRandomRay().

string gOptRootGeomTopVol

Definition at line 94 of file gtestROOTGeometry.cxx.

int gOptTgtPdg

Definition at line 99 of file gtestROOTGeometry.cxx.

Referenced by GetTargetMaterial().

double kDefOptRayR = 100

Definition at line 101 of file gtestROOTGeometry.cxx.