Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HijingShowerSize.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HijingShowerSize.cc
1 #include "HijingShowerSize.h"
2 
4 #include <g4main/PHG4Hit.h>
5 
7 #include <g4main/PHG4Particle.h>
8 #include <g4main/PHG4VtxPoint.h>
9 
11 
12 #include <phool/getClass.h>
13 #include <phool/PHRandomSeed.h>
14 
15 #include <TFile.h>
16 #include <TH1.h>
17 #include <TH2.h>
18 #include <TNtuple.h>
19 
20 #include <gsl/gsl_rng.h>
21 
22 #include<sstream>
23 
24 using namespace std;
25 
27  SubsysReco( name ),
28  nblocks(0),
29  hm(nullptr),
30  _filename(filename),
31  ntups(nullptr),
32  ntupe(nullptr),
33  ntup(nullptr),
34  outfile(nullptr)
35 {
36  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
37  seed = PHRandomSeed(); // fixed seed is handled in this funtcion
38  cout << Name() << " random seed: " << seed << endl;
40  return;
41 }
42 
44 {
45  // delete ntup;
46  gsl_rng_free (RandomGenerator);
47  delete hm;
48 }
49 
50 
51 int
53 {
54  ostringstream hname, htit;
55  hm = new Fun4AllHistoManager(Name());
56  outfile = new TFile(_filename.c_str(), "RECREATE");
57  ntups = new TNtuple("sz"," Shower size","rad:em:hi:ho:mag:bh");
58  ntupe = new TNtuple("truth", "The Absolute Truth", "phi:theta");
59  ntup = new TNtuple("de", "Change in Angles", "ID:dphi:dtheta:dtotal:edep");
60  return 0;
61 }
62 
63 int
65 {
66  float ntvars[5][2] = {0};
67  float tupvars[2];
68  for (int i=0; i<5; i++)
69  {
70  ntvars[i][0] = 4*M_PI*gsl_rng_uniform_pos(RandomGenerator) - 2*M_PI;
71  ntvars[i][1] = (1.62-1.52)*gsl_rng_uniform_pos(RandomGenerator) + 1.52;
72  if (ntvars[i][1] < 0)
73  {
74  ntvars[i][1]+=M_PI;
75  }
76  tupvars[0] = ntvars[i][0];
77  tupvars[1] = ntvars[i][1];
78  ntupe->Fill(tupvars);
79  }
80  PHG4HitContainer *hits = nullptr;
81  double emc[10] = {0};
82  double ih[10] = {0};
83  double oh[10] = {0};
84  double mag[10] = {0};
85  double bh[10] = {0};
86  double eall[5] = {0};
87  float detid[5] = {0};
88  string nodename[2] = {"G4HIT_CEMC","G4HIT_ABSORBER_CEMC"};
89  for (int j=0; j<2;j++)
90  {
91  hits = findNode::getClass<PHG4HitContainer>(topNode,nodename[j]);
92  if (hits)
93  {
94  PHG4HitContainer::ConstRange hit_range = hits->getHits();
95  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
96  {
97  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
98  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
99  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
100  double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
101  double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
102  hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
103  hit_iter->second->get_avg_z());
104 
105 // handle rollover from pi to -pi
106  for (int i = 0; i<5; i++)
107  {
108  double diffphi = phi-ntvars[i][0];
109  if (diffphi > M_PI)
110  {
111  diffphi -= 2*M_PI;
112  }
113  else if (diffphi < - M_PI)
114  {
115  diffphi += 2*M_PI;
116  }
117  // double difftheta = theta-ntvars[1];
118  if (theta < 0)
119  {
120  theta += M_PI;
121  }
122  double difftheta = theta-ntvars[i][1];
123 // theta goes from 0-PI --> no rollover problem
124  double deltasqrt = sqrt(diffphi*diffphi+difftheta*difftheta);
125  if (deltasqrt>0.5)
126  {
127  continue;
128  }
129  double edep = hit_iter->second->get_edep();
130  eall[0] += edep;
131  detid[0] = 0;
132  detid[1] = diffphi;
133  detid[2] = difftheta;
134  detid[3] = deltasqrt;
135  detid[4] = edep;
136  ntup->Fill(detid);
137  for (int i=0; i<10; i++)
138  {
139  if (deltasqrt < (i+1)*0.025)
140  {
141  emc[i]+=edep;
142  }
143  }
144  }
145  }
146  }
147  }
148  nodename[0] = {"G4HIT_HCALIN"};
149  nodename[1] = {"G4HIT_ABSORBER_HCALIN"};
150  for (int j=0; j<2;j++)
151  {
152  hits = findNode::getClass<PHG4HitContainer>(topNode,nodename[j]);
153  if (hits)
154  {
155  PHG4HitContainer::ConstRange hit_range = hits->getHits();
156  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
157  {
158  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
159  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
160  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
161  double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
162  double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
163  hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
164  hit_iter->second->get_avg_z());
165  // handle rollover from pi to -pi
166  for (int i=0; i<5; i++)
167  {
168  double diffphi = phi-ntvars[i][0];
169  if (diffphi > M_PI)
170  {
171  diffphi -= 2*M_PI;
172  }
173  else if (diffphi < - M_PI)
174  {
175  diffphi += 2*M_PI;
176  }
177  // double difftheta = theta-ntvars[1];
178  if (theta < 0)
179  {
180  theta += M_PI;
181  }
182  double difftheta = theta-ntvars[i][1];
183 // theta goes from 0-PI --> no rollover problem
184  double deltasqrt = sqrt(diffphi*diffphi+difftheta*difftheta);
185  if (deltasqrt>0.5)
186  {
187  continue;
188  }
189  double edep = hit_iter->second->get_edep();
190  eall[0] += edep;
191  detid[0] = 1;
192  detid[1] = diffphi;
193  detid[2] = difftheta;
194  detid[3] = deltasqrt;
195  detid[4] = edep;
196  ntup->Fill(detid);
197  for (int i=0; i<10; i++)
198  {
199  if (deltasqrt < (i+1)*0.025)
200  {
201  ih[i]+=edep;
202  }
203  }
204  }
205  }
206  }
207  }
208  nodename[0] = {"G4HIT_HCALOUT"};
209  nodename[1] = {"G4HIT_ABSORBER_HCALOUT"};
210  for (int j=0; j<2;j++)
211  {
212  hits = findNode::getClass<PHG4HitContainer>(topNode,nodename[j]);
213  if (hits)
214  {
215  PHG4HitContainer::ConstRange hit_range = hits->getHits();
216  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
217  {
218  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
219  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
220  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
221  double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
222  double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
223  hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
224  hit_iter->second->get_avg_z());
225 // handle rollover from pi to -pi
226  for (int i=0; i<5; i++)
227  {
228  double diffphi = phi-ntvars[i][0];
229  if (diffphi > M_PI)
230  {
231  diffphi -= 2*M_PI;
232  }
233  else if (diffphi < - M_PI)
234  {
235  diffphi += 2*M_PI;
236  }
237  // double difftheta = theta-ntvars[1];
238  if (theta < 0)
239  {
240  theta += M_PI;
241  }
242  double difftheta = theta-ntvars[i][1];
243 // theta goes from 0-PI --> no rollover problem
244  double deltasqrt = sqrt(diffphi*diffphi+difftheta*difftheta);
245  if (deltasqrt>0.5)
246  {
247  continue;
248  }
249  double edep = hit_iter->second->get_edep();
250  eall[0] += edep;
251  detid[0] = 2;
252  detid[1] = diffphi;
253  detid[2] = difftheta;
254  detid[3] = deltasqrt;
255  detid[4] = edep;
256  ntup->Fill(detid);
257  for (int i=0; i<10; i++)
258  {
259  if (deltasqrt < (i+1)*0.025)
260  {
261  oh[i]+=edep;
262  }
263  }
264  }
265  }
266  }
267  }
268  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_MAGNET");
269  if (hits)
270  {
271  PHG4HitContainer::ConstRange hit_range = hits->getHits();
272  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
273  {
274  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
275  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
276  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
277  double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
278  double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
279  hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
280  hit_iter->second->get_avg_z());
281 // handle rollover from pi to -pi
282  for (int i=0; i<5; i++)
283  {
284  double diffphi = phi-ntvars[i][0];
285  if (diffphi > M_PI)
286  {
287  diffphi -= 2*M_PI;
288  }
289  else if (diffphi < - M_PI)
290  {
291  diffphi += 2*M_PI;
292  }
293  //double difftheta = theta-ntvars[1];
294  if (theta < 0)
295  {
296  theta += M_PI;
297  }
298  double difftheta = theta-ntvars[i][1];
299 // theta goes from 0-PI --> no rollover problem
300  double deltasqrt = sqrt(diffphi*diffphi+difftheta*difftheta);
301  if (deltasqrt>0.5)
302  {
303  continue;
304  }
305  double edep = hit_iter->second->get_edep();
306  eall[0] += edep;
307  detid[0] = 3;
308  detid[1] = diffphi;
309  detid[2] = difftheta;
310  detid[3] = deltasqrt;
311  detid[4] = edep;
312  ntup->Fill(detid);
313  for (int i=0; i<10; i++)
314  {
315  if (deltasqrt < (i+1)*0.025)
316  {
317  mag[i]+=edep;
318  }
319  }
320  }
321  }
322  }
323  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_BH_1");
324  if (hits)
325  {
326  PHG4HitContainer::ConstRange hit_range = hits->getHits();
327  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
328  {
329  // double radius = sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
330  // hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y() +
331  // hit_iter->second->get_avg_z() * hit_iter->second->get_avg_z());
332  double phi = atan2(hit_iter->second->get_avg_y(),hit_iter->second->get_avg_x());
333  double theta = atan(sqrt(hit_iter->second->get_avg_x() * hit_iter->second->get_avg_x() +
334  hit_iter->second->get_avg_y() * hit_iter->second->get_avg_y()) /
335  hit_iter->second->get_avg_z());
336 // handle rollover from pi to -pi
337  for (int i=0; i<5; i++)
338  {
339  double diffphi = phi-ntvars[i][0];
340  if (diffphi > M_PI)
341  {
342  diffphi -= 2*M_PI;
343  }
344  else if (diffphi < - M_PI)
345  {
346  diffphi += 2*M_PI;
347  }
348  // double difftheta = theta-ntvars[1];
349  if (theta < 0)
350  {
351  theta += M_PI;
352  }
353  double difftheta = theta-ntvars[i][1];
354 // theta goes from 0-PI --> no rollover problem
355  double deltasqrt = sqrt(diffphi*diffphi+difftheta*difftheta);
356  if (deltasqrt>0.5)
357  {
358  continue;
359  }
360  double edep = hit_iter->second->get_edep();
361  eall[0] += edep;
362  detid[0] = 4;
363  detid[1] = diffphi;
364  detid[2] = difftheta;
365  detid[3] = deltasqrt;
366  detid[4] = edep;
367  ntup->Fill(detid);
368  for (int i=0; i<10; i++)
369  {
370  if (deltasqrt < (i+1)*0.025)
371  {
372  bh[i]+=edep;
373  }
374  }
375  }
376  }
377  }
378  for (int i=0; i<10;i++)
379  {
380  float nte[6] = {0};
381  nte[0] = i;
382  nte[1] = emc[i];
383  nte[2] = ih[i];
384  nte[3] = oh[i];
385  nte[4] = mag[i];
386  nte[5] = bh[i];
387  ntups->Fill(nte);
388  }
389  float nte[6] = {0};
390  nte[0] = 100;
391  nte[1] = eall[0];
392  nte[2] = eall[1];
393  nte[3] = eall[2];
394  nte[4] = eall[3];
395  nte[5] = eall[4];
396  ntups->Fill(nte);
397 
398  return 0;
399 }
400 
401 int
403 {
404  outfile->cd();
405  // ntup->Write();
406  ntups->Write();
407  ntupe->Write();
408  outfile->Write();
409  outfile->Close();
410  delete outfile;
411  hm->dumpHistos(_filename, "UPDATE");
412  return 0;
413 }
414 
415 void
417 {
418  _node_postfix.insert(name);
419  _detid[name] = detid;
420  return;
421 }