Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:19:40

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 // File: CCalStackingAction.cc
0028 // Description: Stacking action needed for the application
0029 ///////////////////////////////////////////////////////////////////////////////
0030 #include "CCalStackingAction.hh"
0031 #include "G4StackManager.hh"
0032 
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4SDManager.hh"
0035 #include "CCaloSD.hh"
0036 #include "CCalSDList.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4Navigator.hh"
0039 
0040 //#define debug
0041 //#define ddebug
0042 
0043 CCalStackingAction::CCalStackingAction()
0044   : fTimeLimit(10000*CLHEP::ns),isInitialized(false) 
0045 {}
0046 
0047 CCalStackingAction::~CCalStackingAction(){}
0048 
0049 void CCalStackingAction::PrepareNewEvent(){
0050 
0051   if(!isInitialized)   initialize();
0052   stage = firstStage;
0053   nurgent = 0;
0054   acceptSecondaries = 1;
0055 }
0056 
0057 void CCalStackingAction::initialize(){
0058 
0059   isInitialized = true;
0060  
0061   numberOfSD = CCalSDList::getInstance()->getNumberOfCaloSD();
0062 #ifdef debug
0063   G4cout << "CCalStackingAction look for " << numberOfSD 
0064          << " calorimeter-like SD" << G4endl;
0065 #endif
0066   G4int i = 0;
0067   for (i=0; i<numberOfSD; i++) {
0068     G4String theName(CCalSDList::getInstance()->getCaloSDName(i));
0069     SDName[i] = theName;
0070 #ifdef debug
0071     G4cout << "Found SD  name " << theName << G4endl;
0072 #endif
0073     theCaloSD[i] = 0;
0074   }   
0075 
0076   G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
0077   if (sd != 0) {
0078     
0079     for (i=0; i<numberOfSD; i++){
0080 
0081       G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(SDName[i]);
0082       if (aSD==0) {
0083 #ifdef debug
0084         G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i]
0085                << " in this Setup " << G4endl;
0086 #endif
0087       } else {
0088         theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD);
0089         theCaloSD[i]->SetPrimaryID(0);
0090       }           
0091     }
0092 #ifdef debug
0093     G4cout << "CCalStackingAction::initialize: Could not get SD Manager !" 
0094            << G4endl;
0095 #endif
0096   }   
0097 }
0098 
0099 G4ClassificationOfNewTrack CCalStackingAction::ClassifyNewTrack(const G4Track* aTrack){
0100 
0101   G4ClassificationOfNewTrack classification=fKill;
0102   G4int parentID = aTrack->GetParentID();
0103 #ifdef ddebug
0104   G4TrackStatus status = aTrack->GetTrackStatus();
0105   G4cout << "Classifying track " << aTrack->GetTrackID()
0106          << " with status " << aTrack->GetTrackStatus() << G4endl;  
0107 #endif
0108     
0109   if (aTrack->GetGlobalTime() > fTimeLimit) {
0110 #ifdef debug
0111     G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName() 
0112            << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV" 
0113            << G4endl;
0114 #endif
0115     return classification = fKill;
0116   }
0117     
0118   if (stage<end) {
0119     /////////////////
0120     /// PRIMARIES ///
0121     /////////////////
0122     if (parentID == 0 ) {
0123       if ( nurgent == 0) {
0124         nurgent++;
0125         classification = fUrgent;
0126         setPrimaryID(aTrack->GetTrackID());
0127       }
0128       else  classification = fWaiting;   
0129     }
0130 
0131     ///////////////////
0132     /// SECONDARIES ///
0133     ///////////////////
0134        
0135     if (parentID > 0) {
0136       if (acceptSecondaries == 1) {
0137         if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
0138           classification = fUrgent;
0139         else
0140           classification = fWaiting; 
0141       } else {
0142         if(nurgent == 0){                     
0143           nurgent++;
0144           classification = fUrgent;
0145           setPrimaryID(aTrack->GetTrackID());
0146         } else
0147           classification = fWaiting;        
0148       }       
0149     }
0150        
0151        
0152   } else 
0153     classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
0154 
0155 #ifdef ddebug
0156   G4cout << " returning classification= " << classification
0157          << " for track "<< aTrack->GetTrackID() << G4endl;
0158 #endif
0159   return classification;
0160 
0161 }
0162 
0163 
0164 void CCalStackingAction::NewStage(){
0165 
0166 #ifdef ddebug
0167   G4cout << "In NewStage with stage = " << stage << G4endl;
0168 #endif
0169   if (stage <end) {
0170     nurgent = 0;                    
0171     setPrimaryID(0);
0172     acceptSecondaries = 0;
0173     stackManager->ReClassify();
0174     acceptSecondaries = 1;
0175     if (stackManager->GetNUrgentTrack() == 0) {
0176       stage = stageLevel(stage+1);
0177     }
0178         
0179   }
0180 }
0181 
0182 G4bool CCalStackingAction::trackStartsInCalo(const G4Track* ){
0183 
0184  /// This method should check that the secondary particle
0185  /// was produced inside the detector calorimeter and 
0186  /// really is part of the shower.
0187  /// If it has been produced before the calorimeter 
0188  /// for ex. Bremsstrahlung, it should be treated as a new
0189  /// particle producing a new shower.
0190 
0191  return true;
0192 }
0193 
0194 void CCalStackingAction::setPrimaryID(G4int id){
0195   
0196   for (G4int i=0; i<numberOfSD; i++){
0197     if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
0198   }
0199 
0200 }