EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Tracking.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Tracking.C
1 
2 //
3 // EicRoot VST & MM barrel geometry creation and tracking;
4 //
5 
7 #include <g4main/PHG4Reco.h>
8 #include <g4main/PHG4Detector.h>
12 #include <phool/recoConsts.h>
13 
14 #include <EicToyModelSubsystem.h>
15 #include <EicRootVstSubsystem.h>
16 #include <EicRootGemSubsystem.h>
18 #include <EtmOrphans.h>
19 
20 #include <TrackFastSimEval.h>
21 
22 R__LOAD_LIBRARY(libeicdetectors.so)
23 // FIXME: add to CMakeLists.txt;
24 R__LOAD_LIBRARY(libg4trackfastsim.so)
25 
26 // This scrip is simple, sorry: either Qt display or tracking; uncomment if want to see the geometry;
27 //#define _QT_DISPLAY_
28 
29 void Fun4All_G4_Tracking(int nEvents = 1000)
30 {
31  // The fun4all Server;
33 
34  // May want to fix the random seed for reproducibility;
35  recoConsts::instance()->set_IntFlag("RANDOMSEED", 12345);
36 
37  // Particle Generator Setup;
38  {
39  auto gen = new PHG4ParticleGenerator();
40 
41  gen->set_name("pi+"); // geantino, pi-, pi+, mu-, mu+, e-., e+, proton, ...
42  gen->set_vtx(0,0,0); // Vertex generation range
43  gen->set_mom_range(10., 10.); // Momentum generation range in GeV/c
44  gen->set_eta_range(-.1,.1); // Detector coverage around theta ~ 90 degrees in this example
45  gen->set_phi_range(0.,2.*TMath::Pi());
46  se->registerSubsystem(gen);
47  }
48 
49  // fun4all Geant4 wrapper;
50  PHG4Reco* g4Reco = new PHG4Reco();
51 
52  // BeAST magnetic field;
53  g4Reco->set_field_map(string(getenv("CALIBRATIONROOT")) + string("/Field/Map/mfield.4col.dat"), PHFieldConfig::kFieldBeast);
54 
55  // EicRoot media import; neither bound to EicToyModel nor to a particular EicRoot detector;
56  EicGeoParData::ImportMediaFile("../../examples/eicroot/media.geo");
57 
58  // EicRoot vertex tracker; be aware: "VST" will also become a SuperDetector name;
59  auto vst = new EicRootVstSubsystem("VST");
60  {
61  vst->SetGeometryType(EicGeoParData::NoStructure);
62  vst->SetActive(true);
63 
64  // Barrel layers; hits belonging to these layers will be labeled internally
65  // according to the sequence of these calls;
66  {
67  auto ibcell = new MapsMimosaAssembly();
68  // See other MapsMimosaAssembly class POD entries in MapsMimosaAssembly.h;
69  ibcell->SetDoubleVariable("mAssemblyBaseWidth", 17.5 * etm::mm);
70 
71  // Compose barrel layers; parameters are:
72  // - cell assembly type;
73  // - number of staves in this layer;
74  // - number of chips in a stave;
75  // - chip center installation radius;
76  // - additional stave slope around beam line direction; [degree];
77  // - layer rotation around beam axis "as a whole"; [degree];
78  vst->AddBarrelLayer(ibcell, 1*3*12, 1*9, 1*3*23.4 * etm::mm, 12.0, 0.0);
79  vst->AddBarrelLayer(ibcell, 2*3*12, 1*9, 2*3*23.4 * etm::mm, 12.0, 0.0);
80  vst->AddBarrelLayer(ibcell, 3*3*12, 2*9, 3*3*23.4 * etm::mm, 12.0, 0.0);
81  vst->AddBarrelLayer(ibcell, 4*3*12, 2*9, 4*3*23.4 * etm::mm, 12.0, 0.0);
82  }
83 
84  g4Reco->registerSubsystem(vst);
85  }
86 
87  // EicRoot micromegas central tracker barrels;
88  auto mmt = new EicRootMuMegasSubsystem("MMT");
89  {
90  mmt->SetActive(true);
91 
92  {
93  auto layer = new MuMegasLayer();
94  // See other MuMegasLayer class POD entries in MuMegasGeoParData.h;
95  layer->SetDoubleVariable("mOuterFrameWidth", 20 * etm::mm);
96 
97  // Compose barrel layers; parameters are:
98  // - layer description (obviously can mix different geometries);
99  // - length along Z;
100  // - segmentation in Z;
101  // - radius;
102  // - segmentation in phi;
103  // - Z offset from 0.0 (default);
104  // - azimuthal rotation from 0.0 (default);
105  mmt->AddBarrel(layer, 600 * etm::mm, 2, 300 * etm::mm, 3, 0.0, 0.0);
106  mmt->AddBarrel(layer, 600 * etm::mm, 3, 400 * etm::mm, 4, 0.0, 0.0);
107 
108  mmt->SetTransparency(50);
109  }
110 
111  g4Reco->registerSubsystem(mmt);
112  }
113 
114  // Forward GEM tracker module(s);
115  auto fgt = new EicRootGemSubsystem("FGT");
116  {
117  fgt->SetActive(true);
118  //fgt->CheckOverlap();
119  //fgt->SetTGeoGeometryCheckPrecision(0.000001 * etm::um);
120 
121  {
122  auto sbs = new GemModule();
123  // See other GemModule class data in GemGeoParData.h;
124  sbs->SetDoubleVariable("mFrameBottomEdgeWidth", 30 * etm::mm);
125 
126  // Compose sectors; parameters are:
127  // - layer description (obviously can mix different geometries);
128  // - azimuthal segmentation;
129  // - gas volume center radius;
130  // - Z offset from 0.0 (default);
131  // - azimuthal rotation from 0.0 (default);
132  fgt->AddWheel(sbs, 12, 420 * etm::mm, 1200 * etm::mm, 0);
133  fgt->AddWheel(sbs, 12, 420 * etm::mm, 1300 * etm::mm, 0);
134  }
135 
136  g4Reco->registerSubsystem(fgt);
137  }
138 
139  // Truth information;
140  g4Reco->registerSubsystem(new PHG4TruthSubsystem());
141  se->registerSubsystem(g4Reco);
142 
143 #ifdef _QT_DISPLAY_
144  g4Reco->InitRun(se->topNode());
145  g4Reco->ApplyDisplayAction();
146  g4Reco->StartGui();
147 #else
148  // Ideal track finder and Kalman filter;
149  {
150  auto kalman = new PHG4TrackFastSim("PHG4TrackFastSim");
151 
152  kalman->set_use_vertex_in_fitting(false);
153 
154  // Silicon tracker hits;
155  kalman->add_phg4hits(vst->GetG4HitName(), // const std::string& phg4hitsNames
156  PHG4TrackFastSim::Cylinder, // const DETECTOR_TYPE phg4dettype
157  999., // radial-resolution [cm] (this number is not used in cylindrical geometry)
158  // 20e-4/sqrt(12) cm = 5.8e-4 cm, to emulate 20x20 um pixels;
159  5.8e-4, // azimuthal (arc-length) resolution [cm]
160  5.8e-4, // longitudinal (z) resolution [cm]
161  1, // efficiency (fraction)
162  0); // hit noise
163 
164  // MM tracker hits;
165  kalman->add_phg4hits(mmt->GetG4HitName(), // const std::string& phg4hitsNames
166  PHG4TrackFastSim::Cylinder, // const DETECTOR_TYPE phg4dettype
167  999., // radial-resolution [cm] (this number is not used in cylindrical geometry)
168  // Say 50um resolution?; [cm];
169  50e-4, // azimuthal (arc-length) resolution [cm]
170  50e-4, // longitudinal (z) resolution [cm]
171  1, // efficiency (fraction)
172  0); // hit noise
173 
174  // GEM tracker hits; should work;
175  kalman->add_phg4hits(fgt->GetG4HitName(), // const std::string& phg4hitsNames
176  PHG4TrackFastSim::Vertical_Plane, // const DETECTOR_TYPE phg4dettype
177  999., // radial-resolution [cm] (this number is not used in cylindrical geometry)
178  // Say 70um resolution?; [cm];
179  70e-4, // azimuthal (arc-length) resolution [cm]
180  70e-4, // longitudinal (z) resolution [cm]
181  1, // efficiency (fraction)
182  0); // hit noise
183 
184  se->registerSubsystem(kalman);
185  }
186 
187  // User analysis code: just a single dp/p histogram;
189 
190  // Run it all, eventually;
191  se->run(nEvents);
192  se->End();
193 #endif
194  delete se;
195  gSystem->Exit(0);
196 } // Fun4All_G4_Sandbox()