|
||||
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 readMscHits.cc 0047 /// \brief example how to read the CaTS::MscHits 0048 // 0049 // Root headers 0050 #include "TFile.h" 0051 #include "TSystem.h" 0052 #include "TTree.h" 0053 #include "TH1.h" 0054 #include <string> 0055 // project headers 0056 #include "Event.hh" 0057 #include "MscHit.hh" 0058 #include "G4ThreeVector.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 TFile fo(argv[1]); 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 outfile->cd(); 0080 TH1F* theta = new TH1F("angle", "angle", 100, 0.0, 0.15); 0081 std::string CollectionName = argv[3]; 0082 CollectionName = CollectionName + "_Msc_HC"; 0083 for(Int_t i = 0; i < nevent; i++) 0084 { 0085 fevtbranch->GetEntry(i); 0086 auto* hcmap = event->GetHCMap(); 0087 for(const auto& ele : *hcmap) 0088 { 0089 if(ele.first.compare(CollectionName) == 0) 0090 { 0091 auto hits = ele.second; 0092 G4int NbHits = hits.size(); 0093 for(G4int ii = 0; ii < NbHits; ii++) 0094 { 0095 MscHit* mscHit = dynamic_cast<MscHit*>(hits.at(ii)); 0096 G4ThreeVector invec(0, 0, 1.); 0097 std::cout << std::setprecision(12) << mscHit->GetKinE() << " " 0098 << std::setprecision(12) << mscHit->GetMomentum().getX() 0099 << " " << std::setprecision(12) 0100 << mscHit->GetMomentum().getY() << " " 0101 << std::setprecision(12) << mscHit->GetMomentum().getZ() 0102 << std::endl; 0103 theta->Fill(invec.angle(mscHit->GetMomentum()) * 57.3); 0104 } 0105 } 0106 } 0107 } 0108 outfile->Write(); 0109 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |