GENIEGenerator
Loading...
Searching...
No Matches
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

◆ GetCommandLineArgs()

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");
280 gOptGeomFile = filename;
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}
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pDEBUG
Definition Messenger.h:63
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
Command line argument parser.
string gOptRootGeomTopVol
int gOptTgtPdg
double kDefOptRayR
TVector3 gOptRaySurf
TVector3 gOptRayDirection
string gOptGeomFile
int gOptNVtx
double gOptRayR
TVector3 kDefOptRaySurf(0, 0, 0)
TVector3 kDefOptRayDirection(1, 0, 0)

References genie::CmdLnArgParser::ArgAsDouble(), genie::CmdLnArgParser::ArgAsDoubleTokens(), genie::CmdLnArgParser::ArgAsInt(), genie::CmdLnArgParser::ArgAsString(), gOptGeomFile, gOptNVtx, gOptRayDirection, gOptRayR, gOptRaySurf, gOptRootGeomTopVol, gOptTgtPdg, kDefOptRayDirection(), kDefOptRayR, kDefOptRaySurf(), LOG, genie::CmdLnArgParser::OptionExists(), pDEBUG, pINFO, and pNOTICE.

Referenced by main().

◆ GetRandomRay()

void GetRandomRay ( TLorentzVector & x,
TLorentzVector & p )

Definition at line 200 of file gtestROOTGeometry.cxx.

201{
202// generate a random ray (~flux neutrino)
203//
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
static RandomGen * Instance()
Access instance.
Definition RandomGen.cxx:74
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition RandomGen.h:71

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

Referenced by main().

◆ GetTargetMaterial()

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 {
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

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

Referenced by main().

◆ kDefOptRayDirection()

TVector3 kDefOptRayDirection ( 1 ,
0 ,
0  )

Referenced by GetCommandLineArgs().

◆ kDefOptRaySurf()

TVector3 kDefOptRaySurf ( 0 ,
0 ,
0  )

Referenced by GetCommandLineArgs().

◆ main()

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}
#define pERROR
Definition Messenger.h:59
Object to be filled with the neutrino path-length, for all detector geometry materials,...
A ROOT/GEANT4 geometry driver.
virtual void SetTopVolName(string nm)
virtual TGeoManager * GetGeometry(void) const
virtual const PathLengthList & ComputeMaxPathLengths(void)
virtual const PathLengthList & ComputePathLengths(const TLorentzVector &x, const TLorentzVector &p)
virtual const TVector3 & GenerateVertex(const TLorentzVector &x, const TLorentzVector &p, int tgtpdg)
void GetCommandLineArgs(int argc, char **argv)
int GetTargetMaterial(const PathLengthList &pl)
void GetRandomRay(TLorentzVector &x, TLorentzVector &p)
int IonPdgCodeToZ(int pdgc)
Definition PDGUtils.cxx:55
int IonPdgCodeToA(int pdgc)
Definition PDGUtils.cxx:63

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().

Variable Documentation

◆ gOptGeomFile

string gOptGeomFile

Definition at line 93 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptNVtx

int gOptNVtx

Definition at line 98 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptRayDirection

TVector3 gOptRayDirection

Definition at line 95 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and GetRandomRay().

◆ gOptRayR

double gOptRayR

Definition at line 97 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and GetRandomRay().

◆ gOptRaySurf

TVector3 gOptRaySurf

Definition at line 96 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and GetRandomRay().

◆ gOptRootGeomTopVol

string gOptRootGeomTopVol

Definition at line 94 of file gtestROOTGeometry.cxx.

◆ gOptTgtPdg

int gOptTgtPdg

Definition at line 99 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs(), and GetTargetMaterial().

◆ kDefOptRayR

double kDefOptRayR = 100

Definition at line 101 of file gtestROOTGeometry.cxx.

Referenced by GetCommandLineArgs().