EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTRun.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTRun.cc
1 // ********************************************************************
2 //
3 // eASTRun.cc
4 // eAST Run class that handles filling histograms and profile plots
5 // with scores accumulated by scoeres for each event.
6 //
7 // History
8 // May 8th, 2021 : first implementation
9 //
10 // ********************************************************************
11 
12 #include "eASTRun.hh"
13 #include "eASTRunAction.hh"
14 #include "eASTAnalysis.hh"
15 
16 #include "G4MultiFunctionalDetector.hh"
17 #include "G4VPrimitiveScorer.hh"
18 #include "G4PrimaryVertex.hh"
19 #include "G4PrimaryParticle.hh"
20 
21 eASTRun::eASTRun(eASTRunAction* ra) : G4Run(),pRA(ra)
22 {
23  ;
24 }
25 
27 {
28  ;
29 }
30 
31 void eASTRun::RecordEvent(const G4Event* anEvent)
32 {
33 
34  numberOfEvent++; // This is an original line.
35 
36  G4HCofThisEvent* pHCE = anEvent->GetHCofThisEvent();
37 
38  auto analysisManager = G4AnalysisManager::Instance();
39  auto map = pRA->IDMap;
40  for(auto itr : map)
41  {
42  if(itr.second->pplotter!=nullptr) continue; // directly plotted by the PrimitivePlotter
43 
44  auto cID = itr.second->collID;
45  auto hID = itr.second->histID;
46  auto hTyp = itr.second->histType;
47 
48  if(hTyp==1) // 1D histogram
49  {
50  if(cID>=0) // scorer
51  {
52  if(!pHCE) continue;
53  auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
54  G4double val = 0.;
55  for(auto hItr : *score)
56  {
57  if(itr.second->idx==-1 || itr.second->idx==hItr.first)
58  { val += *(hItr.second); }
59  }
60  analysisManager->FillH1(hID,val);
61  }
62  else // primary particle
63  {
64  auto pv = anEvent->GetPrimaryVertex();
65  while(pv)
66  {
67  auto pp = pv->GetPrimary();
68  while(pp)
69  {
70  auto primE = pp->GetKineticEnergy();
71  G4double weight = 1.0;
72  if(itr.second->biasf) weight = pp->GetWeight();
73  analysisManager->FillH1(hID,primE,weight);
74  pp = pp->GetNext();
75  }
76  pv = pv->GetNext();
77  }
78  }
79  }
80 
81  else if(hTyp==2) // 1D profile plot
82  {
83  if(!pHCE) continue;
84  auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
85  for(auto hItr : *score)
86  { analysisManager->FillP1(hID,G4double(hItr.first),*(hItr.second)); }
87  }
88 
89  }
90 
91  auto ntmap = pRA->NTMap;
92  if(ntmap.size()>0)
93  {
94  for(auto ntitr : ntmap)
95  {
96  auto colID = ntitr.first;
97  auto cID = ntitr.second->collID;
98  G4double val = 0.;
99  if(cID>=0)
100  {
101  if(!pHCE) continue;
102  auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
103  for(auto hItr : *score)
104  {
105  if(ntitr.second->idx==-1 || ntitr.second->idx==hItr.first)
106  { val += *(hItr.second); }
107  }
108  }
109  else
110  {
111  auto pv = anEvent->GetPrimaryVertex();
112  auto pp = pv->GetPrimary();
113  val = pp->GetKineticEnergy();
114  }
115  analysisManager->FillNtupleDColumn(colID,val*(ntitr.second->fuct));
116  }
117  analysisManager->AddNtupleRow();
118  }
119 
120 }
121 
122 void eASTRun::Merge(const G4Run * aRun)
123 {
124  G4Run::Merge(aRun);
125 }
126 
127