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