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3 ] [ 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 ]

Diff markup

Differences between /examples/advanced/gammaray_telescope/src/GammaRayTelAnalysis.cc (Version 11.3.0) and /examples/advanced/gammaray_telescope/src/GammaRayTelAnalysis.cc (Version 10.5)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                             << 
 27 // -------------------------------------------     26 // ------------------------------------------------------------
 28 //      GEANT 4 class implementation file          27 //      GEANT 4 class implementation file
 29 //      CERN Geneva Switzerland                    28 //      CERN Geneva Switzerland
 30 //                                                 29 //
 31 //                                                 30 //
 32 //      ------------ GammaRayAnalysisManager       31 //      ------------ GammaRayAnalysisManager  ------
 33 //           by R.Giannitrapani, F.Longo & G.S     32 //           by R.Giannitrapani, F.Longo & G.Santin (03 dic 2000)
 34 //                                                 33 //
 35 // 03.04.2013 F.Longo/L.Pandola                    34 // 03.04.2013 F.Longo/L.Pandola
 36 // - migrated to G4tools                           35 // - migrated to G4tools
 37 //                                                 36 //
 38 // 29.05.2003 F.Longo                              37 // 29.05.2003 F.Longo 
 39 // - Anaphe 5.0.5 compliant                    <<  38 // - anaphe 5.0.5 compliant
 40 //                                                 39 //
 41 // 18.06.2002 R.Giannitrapani, F.Longo & G.San     40 // 18.06.2002 R.Giannitrapani, F.Longo & G.Santin
 42 // - new release for Anaphe 4.0.3                  41 // - new release for Anaphe 4.0.3
 43 //                                                 42 //
 44 // 07.12.2001 A.Pfeiffer                           43 // 07.12.2001 A.Pfeiffer
 45 // - integrated Guy's addition of the ntuple       44 // - integrated Guy's addition of the ntuple
 46 //                                                 45 //
 47 // 06.12.2001 A.Pfeiffer                           46 // 06.12.2001 A.Pfeiffer
 48 // - updating to new design (singleton)            47 // - updating to new design (singleton)
 49 //                                                 48 //
 50 // 22.11.2001 G.Barrand                            49 // 22.11.2001 G.Barrand
 51 // - Adaptation to AIDA                            50 // - Adaptation to AIDA
 52 //                                                 51 //
 53 // *******************************************     52 // ************************************************************
 54                                                << 
 55 #include <fstream>                                 53 #include <fstream>
 56 #include <iomanip>                                 54 #include <iomanip>
 57                                                    55 
                                                   >>  56 #include "G4RunManager.hh" 
                                                   >>  57 
 58 #include "GammaRayTelAnalysis.hh"                  58 #include "GammaRayTelAnalysis.hh"
 59 #include "GammaRayTelAnalysisMessenger.hh"     << 
 60 #include "GammaRayTelDetectorConstruction.hh"      59 #include "GammaRayTelDetectorConstruction.hh"
                                                   >>  60 #include "GammaRayTelAnalysisMessenger.hh"
 61                                                    61 
 62 #include "G4RunManager.hh"                     <<  62 GammaRayTelAnalysis* GammaRayTelAnalysis::instance = 0;
 63                                                << 
 64 //....oooOO0OOooo........oooOO0OOooo........oo << 
 65                                                << 
 66 GammaRayTelAnalysis *GammaRayTelAnalysis::inst << 
 67                                                    63 
                                                   >>  64 //-------------------------------------------------------------------------------- 
 68 //....oooOO0OOooo........oooOO0OOooo........oo     65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 69                                                    66 
 70 GammaRayTelAnalysis::GammaRayTelAnalysis() : d <<  67 GammaRayTelAnalysis::GammaRayTelAnalysis()
 71     detector = static_cast<const GammaRayTelDe <<  68   :GammaRayTelDetector(0),histo2DMode("strip")
                                                   >>  69 {
                                                   >>  70   GammaRayTelDetector =
                                                   >>  71     static_cast<const GammaRayTelDetectorConstruction*>
                                                   >>  72         (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
 72                                                    73 
 73     // Define the messenger and the analysis s <<  74   // Define the messenger and the analysis system
 74     analysisMessenger = new GammaRayTelAnalysi <<  75   analysisMessenger = new GammaRayTelAnalysisMessenger(this);  
 75     histogramFileName = "gammaraytel";         <<  76   histoFileName = "gammaraytel";
 76 }                                                  77 }
 77                                                    78 
 78 //....oooOO0OOooo........oooOO0OOooo........oo << 
 79                                                    79 
 80 GammaRayTelAnalysis::~GammaRayTelAnalysis() {      80 GammaRayTelAnalysis::~GammaRayTelAnalysis() {
 81     Finish();                                  <<  81   Finish();
 82 }                                              <<  82   // Complete clean-up
 83                                                <<  83   delete G4AnalysisManager::Instance();
 84 //....oooOO0OOooo........oooOO0OOooo........oo << 
 85                                                << 
 86 void GammaRayTelAnalysis::Init() {             << 
 87 }                                                  84 }
 88                                                    85 
 89 //....oooOO0OOooo........oooOO0OOooo........oo << 
 90                                                    86 
 91 void GammaRayTelAnalysis::Finish() {           <<  87 void GammaRayTelAnalysis::Init()
 92     delete analysisMessenger;                  <<  88 {;}                       
 93     analysisMessenger = nullptr;               << 
 94 }                                              << 
 95                                                    89 
 96 //....oooOO0OOooo........oooOO0OOooo........oo <<  90 void GammaRayTelAnalysis::Finish()
                                                   >>  91 {
                                                   >>  92   delete analysisMessenger;
                                                   >>  93   analysisMessenger = 0;
                                                   >>  94 }             
 97                                                    95 
 98 auto GammaRayTelAnalysis::getInstance() -> Gam <<  96 GammaRayTelAnalysis* GammaRayTelAnalysis::getInstance()
 99   if (instance == nullptr) {                   <<  97 {
100     instance = new GammaRayTelAnalysis();      <<  98   if (instance == 0) instance = new GammaRayTelAnalysis();
101   }                                            <<  99   return instance;
102   return instance;                             << 
103 }                                                 100 }
104                                                   101 
105 //....oooOO0OOooo........oooOO0OOooo........oo << 
106                                                << 
107 // This function fill the 2d histogram of the     102 // This function fill the 2d histogram of the XZ positions
108 void GammaRayTelAnalysis::InsertPositionXZ(G4d << 103 void GammaRayTelAnalysis::InsertPositionXZ(double x, double z)
109   auto *manager = G4AnalysisManager::Instance( << 104 {
110   manager->FillH2(1, x, z);                    << 105   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 106   man->FillH2(1,x,z);
111 }                                                 107 }
112                                                   108 
113 //....oooOO0OOooo........oooOO0OOooo........oo << 
114                                                << 
115 // This function fill the 2d histogram of the     109 // This function fill the 2d histogram of the YZ positions
116 void GammaRayTelAnalysis::InsertPositionYZ(G4d << 110 void GammaRayTelAnalysis::InsertPositionYZ(double y, double z)
117   auto *manager = G4AnalysisManager::Instance( << 111 {
118   manager->FillH2(2, y, z);                    << 112   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 113   man->FillH2(2,y,z);
119 }                                                 114 }
120                                                   115 
121 //....oooOO0OOooo........oooOO0OOooo........oo << 
122                                                << 
123 // This function fill the 1d histogram of the     116 // This function fill the 1d histogram of the energy released in the last Si plane
124 void GammaRayTelAnalysis::InsertEnergy(G4doubl << 117 void GammaRayTelAnalysis::InsertEnergy(double en)
125   auto *manager = G4AnalysisManager::Instance( << 118 {
126   manager->FillH1(1, energy);                  << 119   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 120   man->FillH1(1,en);
127 }                                                 121 }
128                                                   122 
129 //....oooOO0OOooo........oooOO0OOooo........oo << 
130                                                << 
131 // This function fill the 1d histogram of the     123 // This function fill the 1d histogram of the hits distribution along the TKR planes
132 void GammaRayTelAnalysis::InsertHits(G4int pla << 124 void GammaRayTelAnalysis::InsertHits(int nplane)
133   auto *manager = G4AnalysisManager::Instance( << 125 {
134   manager->FillH1(2, planeNumber);             << 126   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 127   man->FillH1(2,nplane);
                                                   >> 128 }
                                                   >> 129 
                                                   >> 130 void GammaRayTelAnalysis::setNtuple(float E, float p, float x, 
                                                   >> 131             float y, float z)
                                                   >> 132 {
                                                   >> 133   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 134   man->FillNtupleDColumn(0,E);
                                                   >> 135   man->FillNtupleDColumn(1,p);
                                                   >> 136   man->FillNtupleDColumn(2,x);
                                                   >> 137   man->FillNtupleDColumn(3,y);
                                                   >> 138   man->FillNtupleDColumn(4,z);
                                                   >> 139   man->AddNtupleRow();
135 }                                                 140 }
136                                                   141 
137 //....oooOO0OOooo........oooOO0OOooo........oo    142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
                                                   >> 143 /* 
                                                   >> 144    This member reset the histograms and it is called at the begin
                                                   >> 145    of each run; here we put the inizialization so that the histograms have 
                                                   >> 146    always the right dimensions depending from the detector geometry
                                                   >> 147 */
                                                   >> 148 
                                                   >> 149 void GammaRayTelAnalysis::BeginOfRun() 
                                                   >> 150 { 
                                                   >> 151   G4AnalysisManager* man = G4AnalysisManager::Instance();
                                                   >> 152 
                                                   >> 153   // Open an output file
                                                   >> 154 
                                                   >> 155   G4cout << "Opening output file " << histoFileName << " ... ";
                                                   >> 156   man->OpenFile(histoFileName);
                                                   >> 157   man->SetFirstHistoId(1);
                                                   >> 158   G4cout << " done" << G4endl;
                                                   >> 159   
                                                   >> 160 
                                                   >> 161   int Nplane = GammaRayTelDetector->GetNbOfTKRLayers();
                                                   >> 162   int Nstrip = GammaRayTelDetector->GetNbOfTKRStrips();
                                                   >> 163   int Ntile = GammaRayTelDetector->GetNbOfTKRTiles();
                                                   >> 164   double sizexy = GammaRayTelDetector->GetTKRSizeXY();
                                                   >> 165   double sizez = GammaRayTelDetector->GetTKRSizeZ();
                                                   >> 166   int N = Nstrip*Ntile;      
                                                   >> 167 
                                                   >> 168   // Book1D histograms 
                                                   >> 169   //------------------
                                                   >> 170 
                                                   >> 171   // 1D histogram that store the energy deposition of the
                                                   >> 172   // particle in the last (number 0) TKR X-plane
                                                   >> 173   man->CreateH1("1","Edep in the last X plane (keV)", 100, 50, 200);
                                                   >> 174 
                                                   >> 175   // 1D histogram that store the hits distribution along the TKR X-planes
                                                   >> 176   man->CreateH1("2","Hits dist in TKR X planes",Nplane, 0, Nplane-1);
                                                   >> 177 
                                                   >> 178   // Book 2D histograms 
                                                   >> 179   //-------------------
                                                   >> 180 
                                                   >> 181   // 2D histogram that store the position (mm) of the hits (XZ projection)
                                                   >> 182 
                                                   >> 183   if (histo2DMode == "strip")
                                                   >> 184     {
                                                   >> 185       man->CreateH2("1","Tracker Hits XZ (strip,plane)", 
                                                   >> 186         N, 0, N-1, 
                                                   >> 187         2*Nplane, 0, Nplane-1); 
                                                   >> 188     }
                                                   >> 189   else
                                                   >> 190     {
                                                   >> 191       man->CreateH2("1","Tracker Hits XZ (x,z) in mm", 
                                                   >> 192         int(sizexy/5), -sizexy/2, sizexy/2, 
                                                   >> 193         int(sizez/5), -sizez/2, sizez/2);
                                                   >> 194     }  
                                                   >> 195 
                                                   >> 196   // 2D histogram that store the position (mm) of the hits (YZ projection)  
                                                   >> 197   if (histo2DMode == "strip")
                                                   >> 198     {
                                                   >> 199       man->CreateH2("2","Tracker Hits YZ (strip,plane)", 
                                                   >> 200         N, 0, N-1, 
                                                   >> 201         2*Nplane, 0, Nplane-1); 
                                                   >> 202     }
                                                   >> 203   else
                                                   >> 204     {
                                                   >> 205       man->CreateH2("2","Tracker Hits YZ (x,z) in mm", 
                                                   >> 206         int(sizexy/5), -sizexy/2, sizexy/2, 
                                                   >> 207         int(sizez/5), -sizez/2, sizez/2);
                                                   >> 208     }  
                                                   >> 209   
                                                   >> 210     
                                                   >> 211   // Book Ntuples (energy / plane/ x / y / z)
                                                   >> 212   //------------------------------------------  
                                                   >> 213   man->CreateNtuple("1","Track ntuple");
                                                   >> 214   man->CreateNtupleDColumn("energy");
                                                   >> 215   man->CreateNtupleDColumn("plane"); // can I use Int values? 
                                                   >> 216   man->CreateNtupleDColumn("x"); // can I use Int values?
                                                   >> 217   man->CreateNtupleDColumn("y"); // can I use Int values?
                                                   >> 218   man->CreateNtupleDColumn("z"); // can I use Int values?
                                                   >> 219   man->FinishNtuple();
138                                                   220 
139 void GammaRayTelAnalysis::setNtuple(G4double e << 
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 }                                                 221 }
148                                                   222 
149 //....oooOO0OOooo........oooOO0OOooo........oo    223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
150                                                   224 
151 /*                                                225 /* 
152  This member reset the histograms and it is ca << 226    This member is called at the end of each run 
153  here we put the inizialization so that the hi << 227 */
154  always the right dimensions depending from th << 228 void GammaRayTelAnalysis::EndOfRun() 
155  */                                            << 229 {
156 void GammaRayTelAnalysis::BeginOfRun() {       << 230   //Save histograms
157   auto *manager = G4AnalysisManager::Instance( << 231   G4AnalysisManager* man = G4AnalysisManager::Instance();
158   manager->SetDefaultFileType("root");         << 232   man->Write();
159                                                << 233   man->CloseFile();
160   // Open an output file                       << 234 }
161                                                << 235 
162   G4cout << "Opening output file " << histogra << 236 /* This member is called at the end of every event */
163   manager->OpenFile(histogramFileName);        << 237 
164   manager->SetFirstHistoId(1);                 << 238 void GammaRayTelAnalysis::EndOfEvent(G4int /* flag */ ) 
165   G4cout << " done" << G4endl;                 << 239 {;}
166                                                << 240 
167   auto Nplane = detector->GetNbOfTKRLayers();  << 241 
168   auto numberOfStrips = detector->GetNbOfTKRSt << 
169   auto numberOfTiles = detector->GetNbOfTKRTil << 
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 deposi << 
182   manager->CreateH1("1", "Deposited energy in  << 
183                                                << 
184   // 1D histogram that store the hits distribu << 
185   manager->CreateH1("2", "Hits distribution in << 
186                                                << 
187   // Book 2D histograms                        << 
188   //-------------------                        << 
189                                                << 
190   // 2D histogram that store the position (mm) << 
191                                                << 
192     if (histo2DMode == "strip") {              << 
193         manager->CreateH2("1", "Tracker hits X << 
194     } else {                                   << 
195         manager->CreateH2("1", "Tracker hits X << 
196     }                                          << 
197                                                   242 
198     // 2D histogram that store the position (m << 
199     if (histo2DMode == "strip") {              << 
200         manager->CreateH2("2", "Tracker hits Y << 
201     } else {                                   << 
202         manager->CreateH2("2", "Tracker hits Y << 
203     }                                          << 
204                                                   243 
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                                                   244 
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                                                   245 
226 //....oooOO0OOooo........oooOO0OOooo........oo << 
227                                                   246 
228 // This member is called at the end of every e << 
229 void GammaRayTelAnalysis::EndOfEvent(G4int /*  << 
230 }                                              << 
231                                                   247