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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/CaTS/src/EventAction.cc (Version 11.3.0) and /examples/advanced/CaTS/src/EventAction.cc (Version 10.3.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // *******************************************    
 27 //                                                
 28 //  CaTS (Calorimetry and Tracking Simulation)    
 29 //                                                
 30 //  Authors : Hans Wenzel                         
 31 //            Soon Yung Jun                       
 32 //            (Fermi National Accelerator Labo    
 33 //                                                
 34 // History                                        
 35 //   October 18th, 2021 : first implementation    
 36 //                                                
 37 // *******************************************    
 38 //                                                
 39 /// \file EventAction.cc                          
 40 /// \brief Implementation of the CaTS::EventAc    
 41                                                   
 42 // Geant4 headers                                 
 43 #include <G4UserEventAction.hh>                   
 44 #include <G4ios.hh>                               
 45 #include "G4Event.hh"                             
 46 #include "G4HCofThisEvent.hh"                     
 47 #include <G4String.hh>                            
 48 #include <G4Types.hh>                             
 49 #include <G4VHit.hh>                              
 50 #include <G4VHitsCollection.hh>                   
 51 #include "G4SDManager.hh"                         
 52                                                   
 53 // project headers:                               
 54 #include "EventAction.hh"                         
 55 #include "ConfigurationManager.hh"                
 56 #include "Event.hh"                               
 57 #include "PhotonSD.hh"                            
 58 #include "PhotonHit.hh"                           
 59 #include "InteractionHit.hh"                      
 60 #include "lArTPCHit.hh"                           
 61 #include "TrackerHit.hh"                          
 62 #include "MscHit.hh"                              
 63 #include "CalorimeterHit.hh"                      
 64 #include "DRCalorimeterHit.hh"                    
 65 #ifdef WITH_ROOT                                  
 66 #include "RootIO.hh"                              
 67 #endif                                            
 68 // stl headers                                    
 69 #include <map>                                    
 70 #include <utility>                                
 71 #include <algorithm>                              
 72 #include <istream>                                
 73 #ifdef WITH_G4OPTICKS                             
 74 #include ""                                       
 75 #include ""                                       
 76 #include ""                                       
 77 #endif                                            
 78                                                   
 79 #ifdef WITH_ROOT                                  
 80 namespace {                                       
 81     // Mutex to lock updating the global ion m    
 82     G4Mutex ionIdMapMutex = G4MUTEX_INITIALIZE    
 83 } // namespace                                    
 84 #endif                                            
 85                                                   
 86 EventAction::EventAction()                        
 87 : G4UserEventAction() {                           
 88 #ifdef WITH_ROOT                                  
 89     RootIO::GetInstance();                        
 90 #endif                                            
 91 }                                                 
 92                                                   
 93 void EventAction::BeginOfEventAction(const G4E    
 94 }                                                 
 95                                                   
 96 void EventAction::EndOfEventAction(const G4Eve    
 97     G4bool verbose = ConfigurationManager::get    
 98     if (verbose)                                  
 99         G4cout << "EventAction::EndOfEventActi    
100         << G4endl;                                
101     G4HCofThisEvent* HCE = event->GetHCofThisE    
102     if (HCE == nullptr)                           
103         return;                                   
104 #ifdef WITH_ROOT                                  
105     Event* CaTSEvt = new Event();                 
106     CaTSEvt->SetEventNr(event->GetEventID());     
107     std::map<G4String, std::vector < G4VHit*>>    
108 #endif  // end WITH_ROOT                          
109 #ifdef WITH_G4OPTICKS                             
110     if (ConfigurationManager::getInstance()->i    
111         G4Opticks* g4ok = G4Opticks::Get();       
112         G4int eventid = event->GetEventID();      
113         g4ok->propagateOpticalPhotons(eventid)    
114         unsigned num_hits = g4ok->getNumHit();    
115         G4cout << "EndOfEventAction: num_hits:    
116         if (num_hits > 0) {                       
117             G4HCtable* hctable = G4SDManager::    
118             for (G4int i = 0; i < hctable->ent    
119                 std::string sdn = hctable->Get    
120                 std::size_t found = sdn.find("    
121                 if (found != std::string::npos    
122                     PhotonSD* aSD =               
123                             (PhotonSD*) G4SDMa    
124                             sdn);                 
125                     aSD->AddOpticksHits();        
126                 }                                 
127             }                                     
128         }                                         
129         if (verbose) {                            
130             G4cout << "***********************    
131                     "*************************    
132                     << G4endl;                    
133             G4cout << " EndOfEventAction: nump    
134                     << " Gensteps: " << g4ok->    
135                     << "  Maxgensteps:  " << g    
136             G4cout << " EndOfEventAction: num_    
137             G4cout << g4ok->dbgdesc() << G4end    
138         }                                         
139         g4ok->reset();                            
140         if (verbose) {                            
141             G4cout << "=======================    
142             G4cout << " EndOfEventAction: nump    
143                     << " Gensteps: " << g4ok->    
144                     << "  Maxgensteps:  " << g    
145             G4cout << "EndOfEventAction: num_h    
146             G4cout << g4ok->dbgdesc() << G4end    
147             G4cout << "***********************    
148                     "*************************    
149                     << G4endl;                    
150         }                                         
151     } // end isEnable_opticks                     
152 #endif  // end   WITH_G4OPTICKS                   
153     //                                            
154     // Now we deal with the Geant4 Hit collect    
155     //                                            
156     if (verbose)                                  
157         G4cout << "Number of collections:  " <    
158         << G4endl;                                
159 #ifdef WITH_ROOT                                  
160     if (ConfigurationManager::getInstance()->i    
161         for (int i = 0; i < HCE->GetNumberOfCo    
162             G4VHitsCollection* hc = HCE->GetHC    
163             G4String hcname = hc->GetName();      
164             std::vector<std::string> y = split    
165             std::string Classname = y[1];         
166             if (verbose)                          
167                 G4cout << "Classname: " << Cla    
168             if (Classname == "lArTPC") {          
169                 std::vector<G4VHit*> hitsVecto    
170                 G4int NbHits = hc->GetSize();     
171                 for (G4int ii = 0; ii < NbHits    
172                     G4VHit* hit = hc->GetHit(i    
173                     lArTPCHit* tpcHit = dynami    
174                     hitsVector.push_back(tpcHi    
175                 }                                 
176                 hcmap->insert(std::make_pair(h    
177             } else if (Classname == "Photondet    
178                 std::vector<G4VHit*> hitsVecto    
179                 G4int NbHits = hc->GetSize();     
180                 if (verbose)                      
181                     G4cout << "Photondetector     
182                 for (G4int ii = 0; ii < NbHits    
183                     G4VHit* hit = hc->GetHit(i    
184                     PhotonHit* pHit = dynamic_    
185                     hitsVector.push_back(pHit)    
186                 }                                 
187                 hcmap->insert(std::make_pair(h    
188             } else if (Classname == "Target")     
189                 std::vector<G4VHit*> hitsVecto    
190                 G4int NbHits = hc->GetSize();     
191                 if (verbose)                      
192                     G4cout << "Interaction siz    
193                 for (G4int ii = 0; ii < NbHits    
194                     G4VHit* hit = hc->GetHit(i    
195                     InteractionHit* iaHit = dy    
196                     hitsVector.push_back(iaHit    
197                 }                                 
198                 hcmap->insert(std::make_pair(h    
199             } else if (Classname == "Tracker")    
200                 std::vector<G4VHit*> hitsVecto    
201                 G4int NbHits = hc->GetSize();     
202                 if (verbose)                      
203                     G4cout << "Tracker size: "    
204                 for (G4int ii = 0; ii < NbHits    
205                     G4VHit* hit = hc->GetHit(i    
206                     TrackerHit* tHit = dynamic    
207                     hitsVector.push_back(tHit)    
208                 }                                 
209                 hcmap->insert(std::make_pair(h    
210             } else if (Classname == "Msc") {      
211                 std::vector<G4VHit*> hitsVecto    
212                 G4int NbHits = hc->GetSize();     
213                 if (verbose)                      
214                     G4cout << "Msc size: " <<     
215                 for (G4int ii = 0; ii < NbHits    
216                     G4VHit* hit = hc->GetHit(i    
217                     MscHit* mscHit = dynamic_c    
218                     hitsVector.push_back(mscHi    
219                 }                                 
220                 hcmap->insert(std::make_pair(h    
221             } else if (Classname == "Calorimet    
222                 std::vector<G4VHit*> hitsVecto    
223                 G4int NbHits = hc->GetSize();     
224                 if (verbose)                      
225                     G4cout << "Calorimeter siz    
226                 for (G4int ii = 0; ii < NbHits    
227                     G4VHit* hit = hc->GetHit(i    
228                     CalorimeterHit* cHit = dyn    
229                     hitsVector.push_back(cHit)    
230                 }                                 
231                 hcmap->insert(std::make_pair(h    
232             } else if (Classname == "DRCalorim    
233                 std::vector<G4VHit*> hitsVecto    
234                 G4int NbHits = hc->GetSize();     
235                 if (verbose)                      
236                     G4cout << "DRCalorimeter s    
237                 for (G4int ii = 0; ii < NbHits    
238                     G4VHit* hit = hc->GetHit(i    
239                     DRCalorimeterHit* drHit =     
240                     hitsVector.push_back(drHit    
241                 }                                 
242                 hcmap->insert(std::make_pair(h    
243             } else {                              
244                 G4cout << "SD type: " << Class    
245             }                                     
246         }                                         
247         G4AutoLock lock(&ionIdMapMutex);          
248         RootIO::GetInstance()->Write(CaTSEvt);    
249         CaTSEvt->Reset();                         
250         delete CaTSEvt;                           
251     } // end enableio                             
252 #endif                                            
253 }                                                 
254                                                   
255 std::vector<std::string>& EventAction::split(c    
256         std::vector<std::string>& elems) {        
257     std::stringstream ss(s);                      
258     std::string item;                             
259     while (std::getline(ss, item, delim)) {       
260         elems.push_back(item);                    
261     }                                             
262     return elems;                                 
263 }                                                 
264                                                   
265 std::vector<std::string> EventAction::split(co    
266     std::vector<std::string> elems;               
267     return split(s, delim, elems);                
268 }                                                 
269