Geant4 Cross Reference |
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 // 27 // ------------------------------------------------------------ 28 // GEANT 4 class implementation file 29 // CERN Geneva Switzerland 30 // 31 // 32 // ------------ GammaRayAnalysisManager ------ 33 // by R.Giannitrapani, F.Longo & G.Santin (03 dic 2000) 34 // 35 // 03.04.2013 F.Longo/L.Pandola 36 // - migrated to G4tools 37 // 38 // 29.05.2003 F.Longo 39 // - Anaphe 5.0.5 compliant 40 // 41 // 18.06.2002 R.Giannitrapani, F.Longo & G.Santin 42 // - new release for Anaphe 4.0.3 43 // 44 // 07.12.2001 A.Pfeiffer 45 // - integrated Guy's addition of the ntuple 46 // 47 // 06.12.2001 A.Pfeiffer 48 // - updating to new design (singleton) 49 // 50 // 22.11.2001 G.Barrand 51 // - Adaptation to AIDA 52 // 53 // ************************************************************ 54 55 #include <fstream> 56 #include <iomanip> 57 58 #include "GammaRayTelAnalysis.hh" 59 #include "GammaRayTelAnalysisMessenger.hh" 60 #include "GammaRayTelDetectorConstruction.hh" 61 62 #include "G4RunManager.hh" 63 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 65 66 GammaRayTelAnalysis *GammaRayTelAnalysis::instance{nullptr}; 67 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 69 70 GammaRayTelAnalysis::GammaRayTelAnalysis() : detector(nullptr), histo2DMode("strip") { 71 detector = static_cast<const GammaRayTelDetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); 72 73 // Define the messenger and the analysis system 74 analysisMessenger = new GammaRayTelAnalysisMessenger(this); 75 histogramFileName = "gammaraytel"; 76 } 77 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 79 80 GammaRayTelAnalysis::~GammaRayTelAnalysis() { 81 Finish(); 82 } 83 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 85 86 void GammaRayTelAnalysis::Init() { 87 } 88 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 90 91 void GammaRayTelAnalysis::Finish() { 92 delete analysisMessenger; 93 analysisMessenger = nullptr; 94 } 95 96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 97 98 auto GammaRayTelAnalysis::getInstance() -> GammaRayTelAnalysis* { 99 if (instance == nullptr) { 100 instance = new GammaRayTelAnalysis(); 101 } 102 return instance; 103 } 104 105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 106 107 // This function fill the 2d histogram of the XZ positions 108 void GammaRayTelAnalysis::InsertPositionXZ(G4double x, G4double z) { 109 auto *manager = G4AnalysisManager::Instance(); 110 manager->FillH2(1, x, z); 111 } 112 113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 114 115 // This function fill the 2d histogram of the YZ positions 116 void GammaRayTelAnalysis::InsertPositionYZ(G4double y, G4double z) { 117 auto *manager = G4AnalysisManager::Instance(); 118 manager->FillH2(2, y, z); 119 } 120 121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 122 123 // This function fill the 1d histogram of the energy released in the last Si plane 124 void GammaRayTelAnalysis::InsertEnergy(G4double energy) { 125 auto *manager = G4AnalysisManager::Instance(); 126 manager->FillH1(1, energy); 127 } 128 129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 130 131 // This function fill the 1d histogram of the hits distribution along the TKR planes 132 void GammaRayTelAnalysis::InsertHits(G4int planeNumber) { 133 auto *manager = G4AnalysisManager::Instance(); 134 manager->FillH1(2, planeNumber); 135 } 136 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 138 139 void GammaRayTelAnalysis::setNtuple(G4double energy, G4int planeNumber, G4double x, G4double y, G4double z) { 140 auto *manager = G4AnalysisManager::Instance(); 141 manager->FillNtupleDColumn(0, energy); 142 manager->FillNtupleDColumn(1, planeNumber); 143 manager->FillNtupleDColumn(2, x); 144 manager->FillNtupleDColumn(3, y); 145 manager->FillNtupleDColumn(4, z); 146 manager->AddNtupleRow(); 147 } 148 149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 150 151 /* 152 This member reset the histograms and it is called at the begin of each run; 153 here we put the inizialization so that the histograms have 154 always the right dimensions depending from the detector geometry 155 */ 156 void GammaRayTelAnalysis::BeginOfRun() { 157 auto *manager = G4AnalysisManager::Instance(); 158 manager->SetDefaultFileType("root"); 159 160 // Open an output file 161 162 G4cout << "Opening output file " << histogramFileName << " ... "; 163 manager->OpenFile(histogramFileName); 164 manager->SetFirstHistoId(1); 165 G4cout << " done" << G4endl; 166 167 auto Nplane = detector->GetNbOfTKRLayers(); 168 auto numberOfStrips = detector->GetNbOfTKRStrips(); 169 auto numberOfTiles = detector->GetNbOfTKRTiles(); 170 auto sizeXY = detector->GetTKRSizeXY(); 171 auto sizeZ = detector->GetTKRSizeZ(); 172 auto N = numberOfStrips * numberOfTiles; 173 174 // Book 1D histograms 175 //------------------- 176 177 constexpr auto NUMBER_OF_BINS{100}; 178 constexpr auto LOWER_BOUND{50}; 179 constexpr auto UPPER_BOUND{200}; 180 181 // 1D histogram that store the energy deposition of the particle in the last (number 0) TKR X-plane 182 manager->CreateH1("1", "Deposited energy in the last X plane (keV)", NUMBER_OF_BINS, LOWER_BOUND, UPPER_BOUND); 183 184 // 1D histogram that store the hits distribution along the TKR X-planes 185 manager->CreateH1("2", "Hits distribution in TKR X planes", Nplane, 0, Nplane - 1); 186 187 // Book 2D histograms 188 //------------------- 189 190 // 2D histogram that store the position (mm) of the hits (XZ projection) 191 192 if (histo2DMode == "strip") { 193 manager->CreateH2("1", "Tracker hits XZ (strip, plane)", N, 0, N - 1, 2 * Nplane, 0, Nplane - 1); 194 } else { 195 manager->CreateH2("1", "Tracker hits XZ (x, z) in mm", G4int(sizeXY / 5), -sizeXY / 2, sizeXY / 2, G4int(sizeZ / 5), -sizeZ / 2, sizeZ / 2); 196 } 197 198 // 2D histogram that store the position (mm) of the hits (YZ projection) 199 if (histo2DMode == "strip") { 200 manager->CreateH2("2", "Tracker hits YZ (strip, plane)", N, 0, N - 1, 2 * Nplane, 0, Nplane - 1); 201 } else { 202 manager->CreateH2("2", "Tracker hits YZ (x, z) in mm", G4int(sizeXY / 5), -sizeXY / 2, sizeXY / 2, G4int(sizeZ / 5), -sizeZ / 2, sizeZ / 2); 203 } 204 205 // Book n-tuple (energy, plane, x, y, z) 206 //------------------------------------------ 207 manager->CreateNtuple("1", "Track n-tuple"); 208 manager->CreateNtupleDColumn("energy"); 209 manager->CreateNtupleDColumn("plane"); 210 manager->CreateNtupleDColumn("x"); 211 manager->CreateNtupleDColumn("y"); 212 manager->CreateNtupleDColumn("z"); 213 manager->FinishNtuple(); 214 } 215 216 /* 217 This member is called at the end of each run 218 */ 219 void GammaRayTelAnalysis::EndOfRun() { 220 // Save histograms 221 auto *manager = G4AnalysisManager::Instance(); 222 manager->Write(); 223 manager->CloseFile(); 224 } 225 226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 227 228 // This member is called at the end of every event 229 void GammaRayTelAnalysis::EndOfEvent(G4int /* flag */) { 230 } 231