Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
CCalEventAction.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 // File: CCalEndOfEventAction.cc
28 // Description: CCalEndOfEventAction provides User actions at end of event
30 #include "CCalEventAction.hh"
31 #include "CCaloSD.hh"
33 #include "CCalSteppingAction.hh"
34 #include "CCalG4HitCollection.hh"
35 #include "CCalG4Hit.hh"
36 #include "CCaloOrganization.hh"
37 #include "CCalSDList.hh"
38 #include "CCalAnalysis.hh"
39 
40 
41 #include "G4ios.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4Event.hh"
44 #include "G4SDManager.hh"
45 #include "G4HCofThisEvent.hh"
46 #include "G4RunManager.hh"
47 #include "G4UserSteppingAction.hh"
48 
49 #include <iostream>
50 #include <vector>
51 #include <map>
52 
53 #include "CCalAnalysis.hh"
54 
55 //#define debug
56 //#define ddebug
57 
58 
60  CCalSteppingAction* sa):
61  isInitialized(false),fPrimaryGenerator(pg),
62  fSteppingAction(sa),SDnames(nullptr),numberOfSD(0)
63 {
64 #ifdef debug
65  G4cout << "Instantiate CCalEndOfEventAction" << G4endl;
66 #endif
67 
68  G4cout << "Get Calorimter organisation" << G4endl;
70  G4cout << "end of instantiation of EndofEventAction" << G4endl;
71 }
72 
73 
75 
76  if (theOrg)
77  delete theOrg;
78  if (SDnames)
79  delete[] SDnames;
80  G4cout << "CCalOfEventAction deleted" << G4endl;
81 }
82 
83 
85 
86  isInitialized = true;
88 #ifdef debug
89  G4cout << "CCalEndOfEventAction look for " << numberOfSD
90  << " calorimeter-like SD" << G4endl;
91 #endif
92  if (numberOfSD > 0) {
93  G4int n = numberOfSD;
94  if (n < 2) n = 2;
95  SDnames = new nameType[n];
96  }
97  for (int i=0; i<numberOfSD; i++) {
98  SDnames[i] = G4String(CCalSDList::getInstance()->getCaloSDName(i));
99 #ifdef debug
100  G4cout << "CCalEndOfEventAction: found SD " << i << " name "
101  << SDnames[i] << G4endl;
102 #endif
103  }
104 }
105 
106 
108  G4cout << "\n---> Begin of event: " << evt->GetEventID() << G4endl;
109 }
110 
111 
113 
114 #ifdef debug
115  G4cout << G4endl << "=== Begin of EndOfEventAction === " << G4endl;
116 #endif
117 
118  if (!isInitialized) initialize();
119 
121 
122  //
123  // Look for the Hit Collection
124  //
125  G4HCofThisEvent* allHC = evt->GetHCofThisEvent();
126  if (allHC == 0) {
127 #ifdef debug
128  G4cout << "CCalEndOfEventAction: No Hit Collection in this event"
129  << G4endl;
130 #endif
131  return;
132  }
133 
134  //
135  // hits info
136  //
137 
138  //Now make summary
139  float hcalE[28], ecalE[49], fullE=0., edec=0, edhc=0;
140  int i = 0;
141  for (i = 0; i < 28; i++) {hcalE[i]=0.;}
142  for (i = 0; i < 49; i++) {ecalE[i]=0.;}
143 
144  float* edep = new float[numberOfSD];
145  int nhit=0;
146  for (i = 0; i < numberOfSD; i++){
147 
148  //
149  // Look for the Hit Collection
150  //
151  edep[i] = 0;
152  int caloHCid = G4SDManager::GetSDMpointer()->GetCollectionID(SDnames[i]);
153 
154  if (caloHCid >= 0) {
155  CCalG4HitCollection* theHC =
156  (CCalG4HitCollection*) allHC->GetHC(caloHCid);
157 
158  if (theHC != 0) {
159 
160  G4int nentries = theHC->entries();
161 #ifdef debug
162  G4cout << " There are " << nentries << " hits in " << SDnames[i]
163  << " :" << G4endl;
164 #endif
165 
166  if (nentries > 0) {
167 
168  int j;
169  for (j=0; j<nentries; j++){
170 #ifdef ddebug
171  G4cout << "Hit " << j;
172 #endif
173  CCalG4Hit* aHit = (*theHC)[j];
174  float En = aHit->getEnergyDeposit();
175  int unitID = aHit->getUnitID();
176  int id=-1;
177  if (unitID > 0 && unitID < 29) {
178  id = unitID - 1; // HCal
179  hcalE[id] += En/GeV;
180  } else {
181  int i0 = unitID/4096;
182  int i1 = (unitID/64)%64;
183  int i2 = unitID%64;
184  if (i0 == 1 && i1 < 8 && i2 < 8) {
185  id = i1*7 + i2; // ECal
186  ecalE[id] += En/GeV;
187  }
188  }
189 #ifdef ddebug
190  G4cout << " with Energy = " << En/MeV << " MeV in Unit " << unitID
191  << " " << id << G4endl;
192 #endif
193  fullE += En/GeV;
194  edep[i] += En/GeV;
195  nhit++;
196  }
197 #ifdef ddebug
198  G4cout << " ===> Total Energy Deposit in this Calorimeter = "
199  << edep[i]*1000.0 << " MeV " << G4endl;
200 #endif
201  }
202  }
203  }
204  if (SDnames[i] == "HadronCalorimeter") {
205  edhc = edep[i];
206  } else if (SDnames[i] == "CrystalMatrix") {
207  edec = edep[i];
208  }
209  }
210 
211  delete[] edep;
212 
214  float ener = fPrimaryGenerator->GetParticleEnergy()/GeV;
215  float x = pos.x()/mm;
216  float y = pos.y()/mm;
217  float z = pos.z()/mm;
218 
219  //Save results
220  G4AnalysisManager* man = G4AnalysisManager::Instance();
221  //1)
222  static G4int IDenergy = -1;
223  if (IDenergy < 0)
224  IDenergy = man->GetH1Id("h4000");
225  man->FillH1(IDenergy,fullE);
226  //2)
227  G4double totalFilledEnergyHcal = 0.0;
228  static G4int IDhcalE = -1;
229  if (IDhcalE < 0)
230  IDhcalE = man->GetH1Id("h100");
231  for (int j=0; j<28; j++) {
232  man->FillH1(IDhcalE+j,hcalE[j]);
233 #ifdef debug
234  G4cout << "Fill Hcal histo " << j << " with " << hCalE[j] << G4endl;
235 #endif
236  totalFilledEnergyHcal += hcalE[j];
237  }
238 #ifdef debug
239  G4cout <<
240  "CCalAnalysis::InsertEnergyHcal: Total filled Energy Hcal histo "
241  << totalFilledEnergyHcal << G4endl;
242 #endif
243 
244  //3)
245  static G4int IDecalE = -1;
246  if (IDecalE < 0)
247  IDecalE = man->GetH1Id("h200");
248  G4double totalFilledEnergyEcal = 0.0;
249  for (int j=0; j<49; j++) {
250  man->FillH1(IDecalE+j,ecalE[j]);
251 #ifdef debug
252  G4cout << "Fill Ecal histo " << j << " with " << ecalE[j] << G4endl;
253 #endif
254  totalFilledEnergyEcal += ecalE[j];
255  }
256 #ifdef debug
257  G4cout <<
258  "CCalAnalysis::InsertEnergyEal: Total filled Energy Ecal histo "
259  << totalFilledEnergyEcal << G4endl;
260 #endif
261  // 4)
262  G4int counter=0;
263  for (int j=0; j<28; j++)
264  {
265  man->FillNtupleFColumn(counter,hcalE[j]);
266  counter++;
267  }
268  for (int j=0; j<49; j++)
269  {
270  man->FillNtupleFColumn(counter,ecalE[j]);
271  counter++;
272  }
273  man->FillNtupleFColumn(counter,ener);
274  man->FillNtupleFColumn(counter+1,x);
275  man->FillNtupleFColumn(counter+2,y);
276  man->FillNtupleFColumn(counter+3,z);
277  man->FillNtupleFColumn(counter+4,fullE);
278  man->FillNtupleFColumn(counter+5,edec);
279  man->FillNtupleFColumn(counter+6,edhc);
280  man->AddNtupleRow();
281 #ifdef debug
282  G4cout << "CCalAnalysis:: Fill Ntuple " << G4endl;
283 #endif
284 
285 
286  // 5)
287  static G4int IDtimeProfile = -1;
288  if (IDtimeProfile < 0)
289  IDtimeProfile = man->GetH1Id("h901");
290  for (i = 0; i < numberOfSD; i++){
291  int caloHCid = G4SDManager::GetSDMpointer()->GetCollectionID(SDnames[i]);
292  if (caloHCid >= 0) {
293  CCalG4HitCollection* theHC =
294  (CCalG4HitCollection*) allHC->GetHC(caloHCid);
295  if (theHC != 0) {
296  G4int nentries = theHC->entries();
297  if (nentries > 0) {
298  for (G4int k=0; k<nentries; k++) {
299  CCalG4Hit* aHit = (*theHC)[k];
300  man->FillH1(IDtimeProfile,aHit->getTimeSlice(),aHit->getEnergyDeposit()/GeV);
301 
302 #ifdef debug
303  G4cout << "CCalAnalysis:: Fill Time Profile with Hit " << k
304  << " Edeposit " << edep << " Gev at " << time << " ns" << G4endl;
305 #endif
306  }
307  }
308  }
309  }
310  }
311 }
312 
313 
Float_t x
Definition: compare.C:6
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
unsigned int getUnitID() const
Definition: CCalHit.cc:74
static const G4double pos
static constexpr double MeV
Definition: G4SIunits.hh:214
G4int GetEventID() const
Definition: G4Event.hh:151
virtual void StartOfEventAction(const G4Event *evt)
static constexpr double mm
Definition: G4SIunits.hh:115
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
Double_t z
double z() const
G4int GetH1Id(const G4String &name, G4bool warn=true) const
double getTimeSlice() const
Definition: CCalHit.cc:77
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
virtual void EndOfEventAction(const G4Event *evt)
CCalPrimaryGeneratorAction * fPrimaryGenerator
double G4double
Definition: G4Types.hh:76
CCalSteppingAction * fSteppingAction
CCalEventAction(CCalPrimaryGeneratorAction *, CCalSteppingAction *)
Double_t edep
int getNumberOfCaloSD()
Definition: CCalSDList.cc:76
Int_t nentries
Definition: comparison.C:29
double getEnergyDeposit() const
Definition: CCalHit.cc:86
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
int G4int
Definition: G4Types.hh:78
CCaloOrganization * theOrg
G4bool FillNtupleFColumn(G4int id, G4float value)
G4GLOB_DLL std::ostream G4cout
double x() const
Char_t n[5]
double y() const
G4bool isInitialized()
G4bool FillH1(G4int id, G4double value, G4double weight=1.0)
static constexpr double GeV
Definition: G4SIunits.hh:217
nameType * SDnames
static CCalSDList * getInstance()
Definition: CCalSDList.cc:37