Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:09

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Authors: Susanna Guatelli and Francesco Romano
0027 // susanna@uow.edu.au, francesco.romano@ct.infn.it
0028 //
0029 
0030 #include <stdlib.h>
0031 #include "AnalysisManager.hh"
0032 #include "G4UnitsTable.hh"
0033 #include "G4SystemOfUnits.hh"
0034 
0035 #include "AnalysisMessenger.hh"
0036 
0037 AnalysisManager::AnalysisManager(AnalysisMessenger* analysisMessenger) 
0038 {
0039   factoryOn = false;
0040 
0041 // Initialization
0042 // histograms
0043   //for (G4int k=0; k<MaxHisto; k++) fHistId[k] = 0;
0044 
0045 // Initialization ntuple
0046   for (G4int k=0; k<MaxNtCol; k++) fNtColId[k] = 0;
0047 
0048   //h10 = 0;
0049   //h20 = 0;
0050   
0051   messenger = analysisMessenger;
0052 }
0053 
0054 AnalysisManager::~AnalysisManager() 
0055 {
0056 }
0057 
0058 void AnalysisManager::book(G4bool addExtraNt) 
0059 { 
0060   G4AnalysisManager* manager = G4AnalysisManager::Instance();
0061   
0062   manager->SetVerboseLevel(2);
0063  
0064   extraNt = addExtraNt;
0065   
0066   usingRoot = messenger -> IsRootOutput();
0067   
0068   // Create an output file
0069   G4String fileName;
0070   if( usingRoot == true ) fileName = "experimental_microdosimetry.root";
0071   else fileName = "experimental_microdosimetry.csv";
0072 
0073   // Create directories (not supported by csv)
0074   if( usingRoot == true ) manager->SetNtupleDirectoryName("experimental_microdosimetry_ntuple");
0075   
0076 
0077   G4bool fileOpen = manager->OpenFile(fileName);
0078   if (!fileOpen) {
0079     G4cout << "\n---> HistoManager::book(): cannot open " 
0080            << fileName << G4endl;
0081     return;
0082   }
0083 
0084   manager->SetFirstNtupleId(1);
0085 
0086   //Create Primary Energy Ntuple
0087   manager -> CreateNtuple("101", "Primary Energy");
0088   fNtColId[0] = manager -> CreateNtupleDColumn("Ek");
0089   manager -> FinishNtuple();
0090 
0091   //Create Energy Deposition and Path Length within SV Ntuple
0092   manager -> CreateNtuple("102", "Edep");
0093   fNtColId[1] = manager -> CreateNtupleDColumn("edep");
0094   fNtColId[2] = manager -> CreateNtupleDColumn("len");
0095   if( extraNt == true ) fNtColId[3] = manager -> CreateNtupleIColumn("eventID");
0096   manager -> FinishNtuple();
0097 
0098   //creating a ntuple, containing the information about secondary particles
0099   manager -> CreateNtuple("103", "secondary");
0100   fNtColId[4] = manager -> CreateNtupleDColumn("AA");
0101   fNtColId[5] = manager -> CreateNtupleDColumn("ZZ");
0102   fNtColId[6] = manager -> CreateNtupleDColumn("KE");
0103   manager -> FinishNtuple();
0104   
0105   // if the telescope is in use, add an exta ntuple for its information
0106   if( extraNt == true)
0107   {
0108       manager -> CreateNtuple("104", "secondStageE");
0109       fNtColId[7] = manager -> CreateNtupleDColumn("edep");
0110       fNtColId[8] = manager -> CreateNtupleIColumn("eventID");
0111       manager -> FinishNtuple();
0112   }
0113   
0114   factoryOn = true;    
0115 }
0116 
0117 
0118 void AnalysisManager::SetPrimaryEnergy(G4double energy)
0119 {
0120   G4AnalysisManager* manager = G4AnalysisManager::Instance();
0121   manager -> FillNtupleDColumn(1, fNtColId[0], energy);
0122   manager -> AddNtupleRow(1); 
0123 }
0124 
0125 void AnalysisManager::StoreEnergyDeposition(G4double edep, G4double len, G4int eid)
0126 {
0127   G4AnalysisManager* manager = G4AnalysisManager::Instance();
0128   manager -> FillNtupleDColumn(2, fNtColId[1], edep);
0129   manager -> FillNtupleDColumn(2, fNtColId[2], len);
0130   if( extraNt == true ) manager -> FillNtupleIColumn(2, fNtColId[3], eid);
0131     // the event ID is only useful when the 4th ntuple is enabled
0132   manager -> AddNtupleRow(2); 
0133 }
0134 
0135 void AnalysisManager::FillSecondaries(G4int AA, G4double charge, G4double energy)
0136 {
0137 
0138   G4AnalysisManager* manager = G4AnalysisManager::Instance();
0139   manager -> FillNtupleDColumn(3, fNtColId[4], AA);
0140   manager -> FillNtupleDColumn(3, fNtColId[5], charge);
0141   manager -> FillNtupleDColumn(3, fNtColId[6], energy);
0142   manager -> AddNtupleRow(3);  
0143 }
0144 
0145 void AnalysisManager::StoreSecondStageEnergyDeposition(G4double edep, G4int eid)
0146 {
0147   if( extraNt == true )
0148   {
0149     G4AnalysisManager* manager = G4AnalysisManager::Instance();
0150     manager -> FillNtupleDColumn(4, fNtColId[7], edep);
0151     manager -> FillNtupleIColumn(4, fNtColId[8], eid);
0152     manager -> AddNtupleRow(4);
0153   }
0154 }
0155 
0156 void AnalysisManager::finish() 
0157 {   
0158  if (factoryOn) 
0159    {
0160     G4AnalysisManager* manager = G4AnalysisManager::Instance();    
0161     manager -> Write();
0162     manager -> CloseFile();  
0163     factoryOn = false;
0164    }
0165 }
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174 
0175 
0176 
0177 
0178