Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:19:32

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 //---------------------------------------------------------------------
0028 //*            |\___/|                                                *
0029 //*            )     (                                                *
0030 //*           =\     /=                                               *
0031 //*             )===(                                                 *
0032 //*            /     \     CaTS: Calorimeter and Tracker Simulation   *
0033 //*            |     |     is a flexible and extend-able framework    *
0034 //*           /       \    for the simulation of various detector     *
0035 //*       \       /    systems                                    *
0036 //*            \__  _/     https://github.com/hanswenzel/CaTS         *
0037 //*          ( (                                                  *
0038 //*           ) )                                                 *
0039 //*              (_(                                                  *
0040 //* CaTS also serves as an example that demonstrates how to use       *
0041 //* opticks from within Geant4 for the creation and propagation of    *
0042 //* optical photons.                                                  *
0043 //* see https://bitbucket.org/simoncblyth/opticks.git).               *
0044 //* Ascii Art by Joan Stark: https://www.asciiworld.com/-Cats-2-.html *
0045 //---------------------------------------------------------------------
0046 //
0047 /// \file readCalorimeterHits.cc
0048 /// \brief example how to read the CaTS::CalorimeterHits
0049 //
0050 // Root headers
0051 #include "TFile.h"
0052 #include "TSystem.h"
0053 #include "TTree.h"
0054 #include "TH1.h"
0055 // project headers
0056 #include "Event.hh"
0057 #include "CalorimeterHit.hh"
0058 
0059 int main(int argc, char** argv)
0060 {
0061   // initialize ROOT
0062   TSystem ts;
0063   gSystem->Load("libCaTSClassesDict");
0064   if(argc < 3)
0065   {
0066     G4cout
0067       << "Program requires 2 arguments: name of input file, name of output file"
0068       << G4endl;
0069     exit(1);
0070   }
0071   TFile* outfile = new TFile(argv[2], "RECREATE");
0072   TFile fo(argv[1]);
0073   fo.GetListOfKeys()->Print();
0074   Event* event = new Event();
0075   TTree* Tevt  = (TTree*) fo.Get("Events");
0076   Tevt->SetBranchAddress("event.", &event);
0077   TBranch* fevtbranch = Tevt->GetBranch("event.");
0078   Int_t nevent        = fevtbranch->GetEntries();
0079   std::cout << " Nr. of Events:  " << nevent << std::endl;
0080   double max                 = 0.;
0081   double min                 = 1000000;
0082   std::string CollectionName = argv[3];
0083   CollectionName             = CollectionName + "_Calorimeter_HC";
0084   for(Int_t i = 0; i < nevent; i++)
0085   {
0086     fevtbranch->GetEntry(i);
0087     auto* hcmap = event->GetHCMap();
0088     for(const auto& ele : *hcmap)
0089     {
0090       if(ele.first.compare(CollectionName) == 0)
0091       {
0092         auto hits    = ele.second;
0093         G4int NbHits = hits.size();
0094         for(G4int ii = 0; ii < NbHits; ii++)
0095         {
0096           CalorimeterHit* drcaloHit =
0097             dynamic_cast<CalorimeterHit*>(hits.at(ii));
0098           const double ed = drcaloHit->GetEdep();
0099           if(ed > max)
0100             max = ed;
0101           if(ed < min)
0102             min = ed;
0103         }
0104       }
0105     }
0106   }
0107   outfile->cd();
0108   TH1F* hedep =
0109     new TH1F("energy", "edep", 100, min - 0.1 * min, max + 0.1 * max);
0110   for(Int_t i = 0; i < nevent; i++)
0111   {
0112     fevtbranch->GetEntry(i);
0113     auto* hcmap = event->GetHCMap();
0114     for(const auto& ele : *hcmap)
0115     {
0116       if(ele.first.compare(CollectionName) == 0)
0117       {
0118         auto hits    = ele.second;
0119         G4int NbHits = hits.size();
0120         for(G4int ii = 0; ii < NbHits; ii++)
0121         {
0122           CalorimeterHit* drcaloHit =
0123             dynamic_cast<CalorimeterHit*>(hits.at(ii));
0124           hedep->Fill(drcaloHit->GetEdep());
0125         }
0126       }
0127     }
0128   }
0129   // hedep->Fit("gaus");
0130   outfile->Write();
0131 }