EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_TPC.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_TPC.C
1 #ifndef MACRO_G4TPC_C
2 #define MACRO_G4TPC_C
3 
4 #include <GlobalVariables.C>
5 #include <QA.C>
6 
7 #include <G4_Intt.C>
8 #include <G4_Mvtx.C>
9 
11 #include <g4tpc/PHG4TpcDigitizer.h>
16 #include <g4tpc/PHG4TpcPadPlane.h>
18 #include <g4tpc/PHG4TpcSubsystem.h>
19 
20 #include <g4main/PHG4Reco.h>
21 
22 #include <tpc/TpcClusterizer.h>
23 #include <tpc/TpcClusterCleaner.h>
25 
27 
28 #include <qa_modules/QAG4SimulationTpc.h>
29 
30 #include <fun4all/Fun4AllServer.h>
31 
32 R__LOAD_LIBRARY(libg4tpc.so)
33 R__LOAD_LIBRARY(libtpc.so)
34 R__LOAD_LIBRARY(libqa_modules.so)
35 
36 namespace Enable
37 {
38  bool TPC = false;
39  bool TPC_ABSORBER = false;
40  bool TPC_OVERLAPCHECK = false;
41  bool TPC_CELL = false;
42  bool TPC_CLUSTER = false;
43  bool TPC_QA = false;
44 
45  bool TPC_ENDCAP = true;
46 
47  int TPC_VERBOSITY = 0;
48 } // namespace Enable
49 
50 namespace G4TPC
51 {
52  int n_tpc_layer_inner = 16;
53  int tpc_layer_rphi_count_inner = 1152;
54  int n_tpc_layer_mid = 16;
55  int n_tpc_layer_outer = 16;
57  double tpc_outer_radius = 77. + 2.;
58 
59  // TPC drift velocity scale
60  double drift_velocity_scale = 1.0;
61 
62  // distortions
64  auto static_distortion_filename = std::string(getenv("CALIBRATIONROOT")) + "/TPC/DistortionMaps/fluct_average.rev3.1side.3d.file0.h_negz.real_B1.4_E-400.0.ross_phi1_sphenix_phislice_lookup_r26xp40xz40.distortion_map.hist.root";
65 
67  std::string time_ordered_distortion_filename = "/gpfs/mnt/gpfs02/sphenix/user/klest/TimeOrderedDistortions.root";
68 
69  // distortion corrections
70  bool ENABLE_CORRECTIONS = false;
71  auto correction_filename = std::string(getenv("CALIBRATIONROOT")) + "/TPC/DistortionMaps/fluct_average.rev3.1side.3d.file0.h_negz.real_B1.4_E-400.0.ross_phi1_sphenix_phislice_lookup_r26xp40xz40.distortion_map.hist.root";
72 
73  // enable central membrane g4hits generation
75 
76  // enable direct laser g4hits generation
78 
79  // save histograms
81 
82  // space charge calibration output file
83  std::string DIRECT_LASER_ROOTOUTPUT_FILENAME = "TpcSpaceChargeMatrices.root";
84  std::string DIRECT_LASER_HISTOGRAMOUTPUT_FILENAME = "TpcDirectLaserReconstruction.root";
85 
86 } // namespace G4TPC
87 
88 void TPCInit()
89 {
91 
93  {
96  }
97  else
98  {
101  }
102 
103  // the mvtx is not called if disabled but the default number of layers is set to 3,
104  // so we need to set it to zero
105  if (!Enable::MVTX)
106  {
108  }
109  // same for the INTT
110  if (!Enable::INTT)
111  {
113  }
114 }
115 
117 void TPC_Endcaps(PHG4Reco* g4Reco)
118 {
119  bool OverlapCheck = Enable::OVERLAPCHECK || Enable::TPC_OVERLAPCHECK;
120  bool AbsorberActive = Enable::ABSORBER || Enable::TPC_ABSORBER;
121 
122  PHG4TpcEndCapSubsystem* tpc_endcap = new PHG4TpcEndCapSubsystem("TPC_ENDCAP");
123  tpc_endcap->SuperDetector("TPC_ENDCAP");
124 
125  if (AbsorberActive) tpc_endcap->SetActive();
126  tpc_endcap->OverlapCheck(OverlapCheck);
127 
128  // tpc_endcap->set_int_param("construction_verbosity", 2);
129 
130  g4Reco->registerSubsystem(tpc_endcap);
131 
132  return;
133 }
134 
135 double TPC(PHG4Reco* g4Reco,
136  double radius)
137 {
138  bool OverlapCheck = Enable::OVERLAPCHECK || Enable::TPC_OVERLAPCHECK;
139  bool AbsorberActive = Enable::ABSORBER || Enable::TPC_ABSORBER;
140 
141  PHG4TpcSubsystem* tpc = new PHG4TpcSubsystem("TPC");
142  tpc->SetActive();
143  tpc->SuperDetector("TPC");
144  tpc->set_double_param("steplimits", 1); // 1cm steps
145 
146  if (AbsorberActive)
147  {
148  tpc->SetAbsorberActive();
149  }
150  tpc->OverlapCheck(OverlapCheck);
151 
152  g4Reco->registerSubsystem(tpc);
153 
154  if (Enable::TPC_ENDCAP)
155  {
156  TPC_Endcaps(g4Reco);
157  }
158 
159  radius = G4TPC::tpc_outer_radius;
160 
161  radius += no_overlapp;
162 
163  return radius;
164 }
165 
166 void TPC_Cells()
167 {
169  auto se = Fun4AllServer::instance();
170 
171  // central membrane G4Hit generation
173  {
174  auto centralMembrane = new PHG4TpcCentralMembrane;
175  centralMembrane->setCentralMembraneDelay(0);
176  se->registerSubsystem(centralMembrane);
177  }
178 
179  // direct laser G4Hit generation
181  {
182  auto directLaser = new PHG4TpcDirectLaser;
183 
184  // setup phi and theta steps
185  /* use 5deg steps */
186  static constexpr double deg_to_rad = M_PI/180.;
187  directLaser->SetPhiStepping( 72, 0*deg_to_rad, 360*deg_to_rad );
188  directLaser->SetThetaStepping( 17, 5*deg_to_rad, 90*deg_to_rad );
189  directLaser->SetDirectLaserAuto( true );
190  se->registerSubsystem(directLaser);
191  }
192 
193  //=========================
194  // setup Tpc readout for filling cells
195  // g4tpc/PHG4TpcElectronDrift uses
196  // g4tpc/PHG4TpcPadPlaneReadout
197  //=========================
198 
199  auto padplane = new PHG4TpcPadPlaneReadout;
200  padplane->Verbosity(verbosity);
201 
202  auto edrift = new PHG4TpcElectronDrift;
203  edrift->Detector("TPC");
204  edrift->Verbosity(verbosity);
206  {
207  auto distortionMap = new PHG4TpcDistortion;
209  distortionMap->set_static_distortion_filename( G4TPC::static_distortion_filename );
210 
211  distortionMap->set_do_time_ordered_distortions( G4TPC::ENABLE_TIME_ORDERED_DISTORTIONS );
212  distortionMap->set_time_ordered_distortion_filename( G4TPC::time_ordered_distortion_filename );
213 
214  distortionMap->Init();
215  edrift->setTpcDistortion( distortionMap );
216  }
217 
218  // fudge factors to get drphi 150 microns (in mid and outer Tpc) and dz 500 microns cluster resolution
219  // They represent effects not due to ideal gas properties and ideal readout plane behavior
220  // defaults are 0.085 and 0.105, they can be changed here to get a different resolution
221  edrift->registerPadPlane(padplane);
222  se->registerSubsystem(edrift);
223 
224  // The pad plane readout default is set in PHG4TpcPadPlaneReadout
225  // We may want to change the number of inner layers, and can do that here
226  padplane->set_int_param("tpc_minlayer_inner", G4MVTX::n_maps_layer + G4INTT::n_intt_layer); // sPHENIX layer number of first Tpc readout layer
227  padplane->set_int_param("ntpc_layers_inner", G4TPC::n_tpc_layer_inner);
228  padplane->set_int_param("ntpc_phibins_inner", G4TPC::tpc_layer_rphi_count_inner);
229 
230  // Tpc digitizer
231  //=========
232  PHG4TpcDigitizer* digitpc = new PHG4TpcDigitizer();
234  double ENC = 670.0; // standard
235  digitpc->SetENC(ENC);
236  double ADC_threshold = 4.0 * ENC;
237  digitpc->SetADCThreshold(ADC_threshold); // 4 * ENC seems OK
238  digitpc->Verbosity(verbosity);
239  cout << " Tpc digitizer: Setting ENC to " << ENC << " ADC threshold to " << ADC_threshold
240  << " maps+Intt layers set to " << G4MVTX::n_maps_layer + G4INTT::n_intt_layer << endl;
241 
242  se->registerSubsystem(digitpc);
243 
244 }
245 
247 {
249 
251 
252  //-------------
253  // Cluster Hits
254  //-------------
255 
256  // For the Tpc
257  //==========
258  auto tpcclusterizer = new TpcClusterizer;
260  tpcclusterizer->Verbosity(verbosity);
261  se->registerSubsystem(tpcclusterizer);
262 
263 
265  {
266  auto tpcclustercleaner = new TpcClusterCleaner;
267  tpcclustercleaner->Verbosity(verbosity);
268  se->registerSubsystem(tpcclustercleaner);
269  }
270 
271  // space charge correction
273  {
274  auto tpcLoadDistortionCorrection = new TpcLoadDistortionCorrection;
275  tpcLoadDistortionCorrection->set_distortion_filename( G4TPC::correction_filename );
276  se->registerSubsystem(tpcLoadDistortionCorrection);
277  }
278 
279  // direct laser reconstruction
281  {
282  auto directLaserReconstruction = new TpcDirectLaserReconstruction;
283  directLaserReconstruction->set_outputfile( G4TPC::DIRECT_LASER_ROOTOUTPUT_FILENAME );
284  directLaserReconstruction->set_savehistograms( G4TPC::DIRECT_LASER_SAVEHISTOGRAMS );
285  directLaserReconstruction->set_histogram_outputfile( G4TPC::DIRECT_LASER_HISTOGRAMOUTPUT_FILENAME );
286  se->registerSubsystem(directLaserReconstruction);
287  }
288 
289 }
290 
291 
292 void TPC_QA()
293 {
295 
298  qa->Verbosity(verbosity);
299  se->registerSubsystem(qa);
300 }
301 
302 
303 #endif