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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 //
 26 #include "EventAction.hh"
 27 
 28 #include "SiPMHit.hh"
 29 #include "SiliconPixelHit.hh"
 30 
 31 #include "G4Event.hh"
 32 #include "G4SDManager.hh"
 33 #include "G4GenericMessenger.hh"
 34 #include "G4AnalysisManager.hh"
 35 
 36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 37 
 38 EventAction::EventAction() : G4UserEventAction() { DefineCommands(); }
 39 
 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 41 
 42 EventAction::~EventAction() {}
 43 
 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 45 
 46 void EventAction::BeginOfEventAction(const G4Event *) {
 47   fPrimariesPDG.clear();
 48   fPrimariesEnergy.clear();
 49   fPrimariesX.clear();
 50   fPrimariesY.clear();
 51   fPrimariesZ.clear();
 52 
 53   fSiHitsID.clear();
 54   fSiHitsX.clear();
 55   fSiHitsY.clear();
 56   fSiHitsZ.clear();
 57   fSiHitsEdep.clear();
 58   fSiHitsEdepNonIonising.clear();
 59   fSiHitsTOA.clear();
 60   fSiHitsTOAlast.clear();
 61   fSiHitsType.clear();
 62 
 63   fSiPMhitsID.clear();
 64   fSiPMhitsX.clear();
 65   fSiPMhitsY.clear();
 66   fSiPMhitsZ.clear();
 67   fSiPMhitsEdep.clear();
 68   fSiPMhitsEdepNonIonising.clear();
 69   fSiPMhitsTOA.clear();
 70   fSiPMhitsType.clear();
 71 }
 72 
 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 74 
 75 void EventAction::EndOfEventAction(const G4Event *event) {
 76   // sanity check
 77   if (event->GetNumberOfPrimaryVertex() == 0)
 78     return;
 79 
 80   auto analysisManager = G4AnalysisManager::Instance();
 81   analysisManager->FillNtupleIColumn(0, event->GetEventID());
 82   // fill for all primary input particles
 83   for (G4int iVertex = 0; iVertex < event->GetNumberOfPrimaryVertex();
 84        iVertex++) {
 85     auto vertex = event->GetPrimaryVertex(iVertex);
 86     fPrimariesX.push_back(vertex->GetX0() / CLHEP::cm);
 87     fPrimariesY.push_back(vertex->GetY0() / CLHEP::cm);
 88     fPrimariesZ.push_back(vertex->GetZ0() / CLHEP::cm);
 89     for (G4int iParticle = 0; iParticle < vertex->GetNumberOfParticle();
 90          iParticle++) {
 91       auto particle = vertex->GetPrimary(iParticle);
 92       fPrimariesPDG.push_back(particle->GetPDGcode());
 93       fPrimariesEnergy.push_back(particle->GetTotalEnergy() / CLHEP::GeV);
 94     }
 95   }
 96 
 97   auto hce = event->GetHCofThisEvent();
 98   auto sdManager = G4SDManager::GetSDMpointer();
 99   G4int collId;
100 
101   // HGCAL EE + FH
102   collId = sdManager->GetCollectionID("SiliconPixelHitCollection");
103   auto hc = hce->GetHC(collId);
104   if (!hc)
105     return;
106   double esumHGCAL = 0;
107   double cogzHGCAL = 0;
108   int NhitsHGCAL = 0;
109   for (unsigned int i = 0; i < hc->GetSize(); ++i) {
110     auto hit = static_cast<SiliconPixelHit *>(hc->GetHit(i));
111     hit->Digitise(fHitTimeCut / CLHEP::ns, fToaThreshold / CLHEP::keV);
112 
113     if (hit->isValidHit()) {
114       fSiHitsID.push_back(hit->ID());
115       fSiHitsX.push_back(hit->GetX());
116       fSiHitsY.push_back(hit->GetY());
117       fSiHitsZ.push_back(hit->GetZ());
118       fSiHitsEdep.push_back(hit->GetEdep());
119       fSiHitsEdepNonIonising.push_back(hit->GetEdepNonIonizing());
120       fSiHitsTOA.push_back(hit->GetTOA());
121       fSiHitsTOAlast.push_back(hit->GetLastTOA());
122       fSiHitsType.push_back(0);
123 
124       NhitsHGCAL++;
125       esumHGCAL += hit->GetEdep() * CLHEP::keV / CLHEP::MeV;
126       cogzHGCAL += hit->GetZ() * hit->GetEdep();
127     }
128   }
129   if (esumHGCAL > 0)
130     cogzHGCAL /= esumHGCAL;
131 
132   analysisManager->FillNtupleDColumn(23, esumHGCAL / CLHEP::GeV);
133   analysisManager->FillNtupleDColumn(24, cogzHGCAL);
134   analysisManager->FillNtupleIColumn(25, NhitsHGCAL);
135 
136   // AHCAL
137   collId = sdManager->GetCollectionID("SiPMHitCollection");
138   hc = hce->GetHC(collId);
139   if (!hc)
140     return;
141   double esumAHCAL = 0;
142   double cogzAHCAL = 0;
143   int NhitsAHCAL = 0;
144   for (unsigned int i = 0; i < hc->GetSize(); ++i) {
145     auto hit = static_cast<SiPMHit *>(hc->GetHit(i));
146     hit->Digitise(-1, 0);
147 
148     if (hit->isValidHit()) {
149       fSiPMhitsID.push_back(hit->ID());
150       fSiPMhitsX.push_back(hit->GetX());
151       fSiPMhitsY.push_back(hit->GetY());
152       fSiPMhitsZ.push_back(hit->GetZ());
153       fSiPMhitsEdep.push_back(hit->GetEdep());
154       fSiPMhitsEdepNonIonising.push_back(hit->GetEdepNonIonizing());
155       fSiPMhitsTOA.push_back(hit->GetTOA());
156       fSiPMhitsType.push_back(1);
157 
158       NhitsAHCAL++;
159       esumAHCAL += hit->GetEdep() * CLHEP::keV / CLHEP::MeV;
160       cogzAHCAL += hit->GetZ() * hit->GetEdep();
161     }
162   }
163   if (esumAHCAL > 0)
164     cogzAHCAL /= esumAHCAL;
165 
166   analysisManager->FillNtupleDColumn(26, esumAHCAL / CLHEP::GeV);
167   analysisManager->FillNtupleDColumn(27, cogzAHCAL);
168   analysisManager->FillNtupleIColumn(28, NhitsAHCAL);
169 
170   analysisManager->AddNtupleRow();
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174 
175 void EventAction::DefineCommands() {
176 
177   fMessenger = new G4GenericMessenger(this, "/HGCalTestbeam/hits/",
178                                       "Primary generator control");
179 
180   // time cut command
181   auto &timeCutCmd = fMessenger->DeclarePropertyWithUnit(
182       "timeCut", "ns", fHitTimeCut,
183       "Size of time window for hit digitalisation");
184   timeCutCmd.SetParameterName("timeCut", true);
185   timeCutCmd.SetRange("timeCut>=-1");
186   timeCutCmd.SetDefaultValue("-1");
187 
188   // toa threshold command
189   auto &toaThresholdCmd = fMessenger->DeclarePropertyWithUnit(
190       "toaThreshold", "keV", fToaThreshold, "Threshold for TOA activation");
191   toaThresholdCmd.SetParameterName("toaThreshold", true);
192   toaThresholdCmd.SetRange("toaThreshold>=0");
193   toaThresholdCmd.SetDefaultValue("0");
194 }
195 
196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197