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[ 10.5 ] [ 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 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 ///////////////////////////////////////////////////////////////////////////////
 27 // File: CCalStackingAction.cc
 28 // Description: Stacking action needed for the application
 29 ///////////////////////////////////////////////////////////////////////////////
 30 #include "CCalStackingAction.hh"
 31 #include "G4StackManager.hh"
 32 
 33 #include "G4SystemOfUnits.hh"
 34 #include "G4SDManager.hh"
 35 #include "CCaloSD.hh"
 36 #include "CCalSDList.hh"
 37 #include "G4RunManager.hh"
 38 #include "G4Navigator.hh"
 39 
 40 //#define debug
 41 //#define ddebug
 42 
 43 CCalStackingAction::CCalStackingAction()
 44   : fTimeLimit(10000*CLHEP::ns),isInitialized(false) 
 45 {}
 46 
 47 CCalStackingAction::~CCalStackingAction(){}
 48 
 49 void CCalStackingAction::PrepareNewEvent(){
 50 
 51   if(!isInitialized)   initialize();
 52   stage = firstStage;
 53   nurgent = 0;
 54   acceptSecondaries = 1;
 55 }
 56 
 57 void CCalStackingAction::initialize(){
 58 
 59   isInitialized = true;
 60  
 61   numberOfSD = CCalSDList::getInstance()->getNumberOfCaloSD();
 62 #ifdef debug
 63   G4cout << "CCalStackingAction look for " << numberOfSD 
 64          << " calorimeter-like SD" << G4endl;
 65 #endif
 66   G4int i = 0;
 67   for (i=0; i<numberOfSD; i++) {
 68     G4String theName(CCalSDList::getInstance()->getCaloSDName(i));
 69     SDName[i] = theName;
 70 #ifdef debug
 71     G4cout << "Found SD  name " << theName << G4endl;
 72 #endif
 73     theCaloSD[i] = 0;
 74   }   
 75 
 76   G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
 77   if (sd != 0) {
 78     
 79     for (i=0; i<numberOfSD; i++){
 80 
 81       G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(SDName[i]);
 82       if (aSD==0) {
 83 #ifdef debug
 84         G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i]
 85                << " in this Setup " << G4endl;
 86 #endif
 87       } else {
 88         theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD);
 89         theCaloSD[i]->SetPrimaryID(0);
 90       }           
 91     }
 92 #ifdef debug
 93     G4cout << "CCalStackingAction::initialize: Could not get SD Manager !" 
 94            << G4endl;
 95 #endif
 96   }   
 97 }
 98 
 99 G4ClassificationOfNewTrack CCalStackingAction::ClassifyNewTrack(const G4Track* aTrack){
100 
101   G4ClassificationOfNewTrack classification=fKill;
102   G4int parentID = aTrack->GetParentID();
103 #ifdef ddebug
104   G4TrackStatus status = aTrack->GetTrackStatus();
105   G4cout << "Classifying track " << aTrack->GetTrackID()
106          << " with status " << aTrack->GetTrackStatus() << G4endl;  
107 #endif
108     
109   if (aTrack->GetGlobalTime() > fTimeLimit) {
110 #ifdef debug
111     G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName() 
112            << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV" 
113            << G4endl;
114 #endif
115     return classification = fKill;
116   }
117     
118   if (stage<end) {
119     /////////////////
120     /// PRIMARIES ///
121     /////////////////
122     if (parentID == 0 ) {
123       if ( nurgent == 0) {
124         nurgent++;
125         classification = fUrgent;
126         setPrimaryID(aTrack->GetTrackID());
127       }
128       else  classification = fWaiting;   
129     }
130 
131     ///////////////////
132     /// SECONDARIES ///
133     ///////////////////
134        
135     if (parentID > 0) {
136       if (acceptSecondaries == 1) {
137         if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
138           classification = fUrgent;
139         else
140           classification = fWaiting; 
141       } else {
142         if(nurgent == 0){                     
143           nurgent++;
144           classification = fUrgent;
145           setPrimaryID(aTrack->GetTrackID());
146         } else
147           classification = fWaiting;        
148       }       
149     }
150        
151        
152   } else 
153     classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
154 
155 #ifdef ddebug
156   G4cout << " returning classification= " << classification
157          << " for track "<< aTrack->GetTrackID() << G4endl;
158 #endif
159   return classification;
160 
161 }
162 
163 
164 void CCalStackingAction::NewStage(){
165 
166 #ifdef ddebug
167   G4cout << "In NewStage with stage = " << stage << G4endl;
168 #endif
169   if (stage <end) {
170     nurgent = 0;                    
171     setPrimaryID(0);
172     acceptSecondaries = 0;
173     stackManager->ReClassify();
174     acceptSecondaries = 1;
175     if (stackManager->GetNUrgentTrack() == 0) {
176       stage = stageLevel(stage+1);
177     }
178         
179   }
180 }
181 
182 G4bool CCalStackingAction::trackStartsInCalo(const G4Track* ){
183 
184  /// This method should check that the secondary particle
185  /// was produced inside the detector calorimeter and 
186  /// really is part of the shower.
187  /// If it has been produced before the calorimeter 
188  /// for ex. Bremsstrahlung, it should be treated as a new
189  /// particle producing a new shower.
190 
191  return true;
192 }
193 
194 void CCalStackingAction::setPrimaryID(G4int id){
195   
196   for (G4int i=0; i<numberOfSD; i++){
197     if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
198   }
199 
200 }
201