Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:19:40

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 ///////////////////////////////////////////////////////////////////////////////
0027 // File: CCalRunAction.cc
0028 // Description: A class for providing user actions at begin and end of run
0029 ///////////////////////////////////////////////////////////////////////////////
0030 #include "CCalRunAction.hh"
0031 
0032 #include "globals.hh"
0033 #include "G4Run.hh"
0034 
0035 #include "G4ios.hh"
0036 
0037 #include "G4AnalysisManager.hh"
0038 #include "G4Threading.hh"
0039 
0040 
0041 CCalRunAction::CCalRunAction()
0042 {
0043   numberOfTimeSlices = 200;
0044   Book();
0045 }
0046 
0047 
0048 CCalRunAction::~CCalRunAction()
0049 {
0050 }
0051 
0052 
0053 void CCalRunAction::BeginOfRunAction(const G4Run* aRun) 
0054 {
0055   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0056 
0057   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0058   analysis->SetDefaultFileType("root");
0059 
0060   //cleanup
0061   G4int timeHist = analysis->GetH1Id("h300");
0062   for (G4int i=0; i<numberOfTimeSlices; ++i) {
0063     analysis->GetH1(timeHist+i)->reset();
0064   }
0065 
0066   // Open an output file
0067   analysis->OpenFile("ccal");
0068   G4cout << "********************************************" << G4endl
0069          << "* o/p file ccal"  << G4endl
0070          << "********************************************" << G4endl 
0071          << G4endl;
0072 }
0073 
0074 
0075 void CCalRunAction::EndOfRunAction(const G4Run* aRun) 
0076 {
0077   G4cout << "### Run " << aRun->GetRunID() << " end." << G4endl;
0078 
0079   // Close-out analysis: save histograms and ntuple
0080   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0081   analysisManager->Write();
0082   analysisManager->CloseFile();
0083 }   
0084 
0085 
0086 void CCalRunAction::Book()
0087 {
0088   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0089   analysisManager->SetVerboseLevel(1);
0090   analysisManager->SetFirstHistoId(1);
0091   analysisManager->SetFirstNtupleId(1);
0092 
0093   // Note: merging ntuples is available only with Root output
0094   if ( G4Threading::IsMultithreadedApplication() ) analysisManager->SetNtupleMerging(true);
0095  
0096   // Create ntuple
0097   analysisManager->CreateNtuple("ntuple1", "Event info");
0098   for (G4int i=0;i<28;++i) {
0099       G4String tupleidString = "hcal" + std::to_string( i );
0100       analysisManager->CreateNtupleFColumn( tupleidString.c_str() );
0101   }
0102   for (G4int i=0; i<49; ++i) {
0103       G4String tupleidString = "ecal" + std::to_string( i );
0104       analysisManager->CreateNtupleFColumn( tupleidString.c_str() );
0105   }
0106   analysisManager->CreateNtupleFColumn("ELAB");
0107   analysisManager->CreateNtupleFColumn("XPOS");
0108   analysisManager->CreateNtupleFColumn("YPOS");
0109   analysisManager->CreateNtupleFColumn("ZPOS");
0110   analysisManager->CreateNtupleFColumn("EDEP");
0111   analysisManager->CreateNtupleFColumn("EDEC");
0112   analysisManager->CreateNtupleFColumn("EHDC");
0113   analysisManager->FinishNtuple();
0114 
0115   //
0116   //Create histograms. Save the ID of the first histogram in each block
0117   //
0118   //Energy deposit in Hcal layers 
0119   for (G4int i = 0; i<28; ++i) {
0120     G4String idString = "h" + std::to_string( i+100 );
0121     G4String ntupletagString = "Energy Deposit in Hcal Layer" + std::to_string( i ) + "  in GeV";
0122     analysisManager->CreateH1( idString.c_str(), ntupletagString.c_str(), 100, 0., 1.0 );    
0123   }
0124   // Energy deposits in Ecal towers
0125   for (G4int i = 0; i<49; ++i) {
0126     G4String idString = "h" + std::to_string( i+200 );
0127     G4String ntupletagString = "Energy Deposit in Ecal Tower" + std::to_string( i ) + "  in GeV";
0128     analysisManager->CreateH1( idString.c_str(), ntupletagString.c_str(), 100, 0., 1.0 );      
0129   }
0130   // Total energy deposit
0131   analysisManager->CreateH1( "h4000", "Total energy deposited in GeV", 100, 0., 100.0 );
0132 
0133   // Time slices          
0134   for (G4int i=0; i<numberOfTimeSlices; ++i){
0135     G4String idString = "h" + std::to_string( i+300 );
0136     G4String ntupletagString = "Time slice " + std::to_string( i ) + " nsec energy profile in GeV";
0137     analysisManager->CreateH1( idString.c_str(), ntupletagString.c_str(), 100, 0., 100.0 );   
0138   }
0139 
0140   // Profile of lateral energy deposit in Hcal
0141   for (G4int i = 0; i<70; ++i) {
0142     G4String idString = "h" + std::to_string( i+500 );
0143     G4String ntupletagString = "Lateral energy profile at " + std::to_string( i ) + " cm  in GeV";
0144     analysisManager->CreateH1( idString.c_str(), ntupletagString.c_str(), 100, 0., 10.0 );    
0145   }
0146 
0147   // Time profile 
0148   analysisManager->CreateH1( "h901", "Time Profile in Sensitive Detector", 200, 0., 200. );
0149   analysisManager->CreateH1( "h902", "Time Profile in Sensitive+Passive",  200, 0., 200. );
0150 
0151   return;
0152 }