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"

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 
)

Definition at line 268 of file gtestROOTGeometry.cxx.

269 {
270  CmdLnArgParser parser(argc,argv);
271 
272  // geometry file
273  if( parser.OptionExists('f') ) {
274  LOG("test", pINFO) << "Getting ROOT geometry filename";
275  gOptGeomFile = parser.ArgAsString('f');
276  } else {
277  string base_dir = string( gSystem->Getenv("GENIE") );
278  string filename = base_dir +
279  string("/data/geo/samples/BoxWithLArPbLayers.root");
281  }
282 
283  // check whether an event generation volume name has been
284  // specified -- default is the 'top volume'
285  if( parser.OptionExists('v') ) {
286  LOG("test", pDEBUG) << "Checking for input volume name";
287  gOptRootGeomTopVol = parser.ArgAsString('v');
288  } else {
289  LOG("test", pDEBUG) << "Using the <master volume>";
290  }
291 
292  // direction
293  if( parser.OptionExists('d') ) {
294  LOG("test", pINFO) << "Reading ray direction";
295  // split the comma separated list
296  vector<double> dirv = parser.ArgAsDoubleTokens('d', ",");
297  assert(dirv.size() == 3);
298  gOptRayDirection.SetXYZ(dirv[0],dirv[1],dirv[2]);
299  } else {
300  LOG("test", pINFO) << "No input ray direction - Using default";
302  }
303 
304  // ray surface:
305  if( parser.OptionExists('s') ) {
306  LOG("test", pINFO) << "Reading ray generation surface";
307  // split the comma separated list
308  vector<double> rsv = parser.ArgAsDoubleTokens('s', ",");
309  assert(rsv.size() == 3);
310  gOptRaySurf.SetXYZ(rsv[0],rsv[1],rsv[2]);
311  } else {
312  LOG("test", pINFO) << "No input ray generation surface - Using default";
314  }
315 
316  // ray generation area radius:
317  if( parser.OptionExists('r') ) {
318  LOG("test", pINFO) << "Reading radius of ray generation area";
319  gOptRayR = parser.ArgAsDouble('r');
320  } else {
321  LOG("test", pINFO) << "No input radius of ray generation area - Using default";
323  }
324  gOptRayR = TMath::Abs(gOptRayR); // must be positive
325 
326  // number of vertices to generate:
327  if( parser.OptionExists('n') ) {
328  LOG("test", pINFO) << "Getting number of vertices to generate";
329  gOptNVtx = parser.ArgAsInt('n');
330  } else {
331  gOptNVtx = 0;
332  }
333 
334  // 'forced' target pdg:
335  if( parser.OptionExists('p') ) {
336  LOG("test", pINFO) << "Getting 'forced' target pdg";
337  gOptTgtPdg = parser.ArgAsInt('p');
338  } else {
339  gOptTgtPdg = -1;
340  }
341 
342  LOG("test", pNOTICE)
343  << "\n Options: "
344  << "\n ROOT geometry file: " << gOptGeomFile
345  << "\n ROOT geometry top volume: " << gOptRootGeomTopVol
346  << "\n Ray direction: ("
347  << gOptRayDirection.X() << ", "
348  << gOptRayDirection.Y() << ", "
349  << gOptRayDirection.Z() << ") "
350  << "\n Ray generation surface : ("
351  << gOptRaySurf.X() << ", "
352  << gOptRaySurf.Y() << ", "
353  << gOptRaySurf.Z() << ") "
354  << "\n Ray generation area radius : " << gOptRayR
355  << "\n Number of vertices : " << gOptNVtx
356  << "\n Forced targer PDG : " << gOptTgtPdg;
357 
358 }
string gOptGeomFile
std::string string
Definition: nybbler.cc:12
string filename
Definition: train.py:213
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
string gOptRootGeomTopVol
size_t size
Definition: lodepng.cpp:55
double kDefOptRayR
TVector3 kDefOptRaySurf(0, 0, 0)
int gOptNVtx
#define pINFO
Definition: Messenger.h:62
TVector3 kDefOptRayDirection(1, 0, 0)
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
int gOptTgtPdg
#define pDEBUG
Definition: Messenger.h:63
void GetRandomRay ( TLorentzVector &  x,
TLorentzVector &  p 
)

Definition at line 200 of file gtestROOTGeometry.cxx.

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
p
Definition: test.py:223
list x
Definition: train.py:276
#define pNOTICE
Definition: Messenger.h:61
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:71
static const double kPi
Definition: Constants.h:37
int GetTargetMaterial ( const PathLengthList pl)

Definition at line 241 of file gtestROOTGeometry.cxx.

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 
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
intermediate_table::const_iterator const_iterator
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.

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:60
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
std::void_t< T > n
p
Definition: test.py:223
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)
list x
Definition: train.py:276
int IonPdgCodeToZ(int pdgc)
Definition: PDGUtils.cxx:52
void GetCommandLineArgs(int argc, char **argv)
#define pNOTICE
Definition: Messenger.h:61
virtual TGeoManager * GetGeometry(void) const

Variable Documentation

string gOptGeomFile

Definition at line 93 of file gtestROOTGeometry.cxx.

int gOptNVtx

Definition at line 98 of file gtestROOTGeometry.cxx.

TVector3 gOptRayDirection

Definition at line 95 of file gtestROOTGeometry.cxx.

double gOptRayR

Definition at line 97 of file gtestROOTGeometry.cxx.

TVector3 gOptRaySurf

Definition at line 96 of file gtestROOTGeometry.cxx.

string gOptRootGeomTopVol

Definition at line 94 of file gtestROOTGeometry.cxx.

int gOptTgtPdg

Definition at line 99 of file gtestROOTGeometry.cxx.

double kDefOptRayR = 100

Definition at line 101 of file gtestROOTGeometry.cxx.