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 readPhotonHits.cc
0047 /// \brief example how to read the  CaTS::PhotonHits
0048 //
0049 // Root headers
0050 #include "TFile.h"
0051 #include "TSystem.h"
0052 #include "TTree.h"
0053 #include "TH1.h"
0054 #include "TH2.h"
0055 // Project headers
0056 #include "Event.hh"
0057 #include "lArTPCHit.hh"
0058 #include "PhotonHit.hh"
0059 
0060 int main(int argc, char** argv)
0061 {
0062   // initialize ROOT
0063   TSystem ts;
0064   gSystem->Load("libCaTSClassesDict");
0065   if(argc < 4)
0066   {
0067     G4cout << "Program requires 3 arguments: name of input file, name of "
0068               "output file, Volume that sensitive detector is attached to"
0069            << G4endl;
0070     exit(1);
0071   }
0072   TFile* outfile = new TFile(argv[2], "RECREATE");
0073   outfile->cd();
0074   TH2F* pos2  = new TH2F("position", "position of Photon Hits", 400, -1000.,
0075                         1000., 400, -500, 500);
0076   TH1F* time  = new TH1F("time", "timing of photon hits", 1000, 0., 250.);
0077   TH1F* time0 = new TH1F("time0", "timing of photon hits", 1000, 0., 250.);
0078   TH1F* time1 = new TH1F("time1", "timing of photon hits", 1000, 0., 250.);
0079   TH1F* time2 = new TH1F("time2", "timing of photon hits", 1000, 0., 250.);
0080   TH1F* wl = new TH1F("wl", "wavelength of detected photons", 1000, 0., 250.);
0081   TH1F* np = new TH1F("np", "number of detected photons", 100, 0., 50.);
0082   TFile fo(argv[1]);
0083   fo.GetListOfKeys()->Print();
0084   Event* event = new Event();
0085   TTree* Tevt  = (TTree*) fo.Get("Events");
0086   Tevt->SetBranchAddress("event.", &event);
0087   TBranch* fevtbranch = Tevt->GetBranch("event.");
0088   Int_t nevent        = fevtbranch->GetEntries();
0089   G4cout << "Nr. of Events:  " << nevent << G4endl;
0090   std::string CollectionName = argv[3];
0091   CollectionName             = CollectionName + "_Photondetector_HC";
0092   for(Int_t i = 0; i < nevent; i++)
0093   {
0094     fevtbranch->GetEntry(i);
0095     auto* hcmap = event->GetHCMap();
0096     for(const auto& ele : *hcmap)
0097     {
0098       auto hits = ele.second;
0099       if(ele.first.compare(CollectionName) == 0)
0100       {
0101         auto hits    = ele.second;
0102         G4int NbHits = hits.size();
0103         G4cout << "Event: " << i << "  Number of Hits:  " << NbHits << G4endl;
0104         np->Fill(NbHits);
0105         for(G4int ii = 0; ii < NbHits; ii++)
0106         {
0107           PhotonHit* photonHit = dynamic_cast<PhotonHit*>(hits.at(ii));
0108           time->Fill(photonHit->GetTime());
0109           wl->Fill(photonHit->GetWavelength());
0110           if(photonHit->GetPosition().getZ() < -100.)
0111             time0->Fill(photonHit->GetTime());
0112           if(photonHit->GetPosition().getZ() > -100. &&
0113              photonHit->GetPosition().getZ() < 100)
0114             time1->Fill(photonHit->GetTime());
0115           if(photonHit->GetPosition().getZ() < 100.)
0116             time2->Fill(photonHit->GetTime());
0117           pos2->Fill(photonHit->GetPosition().getZ(),
0118                      photonHit->GetPosition().getY());
0119         }
0120       }
0121     }
0122   }
0123   outfile->cd();
0124   outfile->Write();
0125 }