Geant4 examples
basic/B4/B4c/src/B4cCalorimeterSD.cc
Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00030 
00031 #include "B4cCalorimeterSD.hh"
00032 #include "G4HCofThisEvent.hh"
00033 #include "G4Step.hh"
00034 #include "G4ThreeVector.hh"
00035 #include "G4SDManager.hh"
00036 #include "G4ios.hh"
00037 
00038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00039 
00040 B4cCalorimeterSD::B4cCalorimeterSD(
00041                             const G4String& name, 
00042                             const G4String& hitsCollectionName,
00043                             G4int nofCells)
00044  : G4VSensitiveDetector(name),
00045    fHitsCollection(0),
00046    fNofCells(nofCells)
00047 {
00048   collectionName.insert(hitsCollectionName);
00049 }
00050 
00051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00052 
00053 B4cCalorimeterSD::~B4cCalorimeterSD() 
00054 { 
00055 }
00056 
00057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00058 
00059 void B4cCalorimeterSD::Initialize(G4HCofThisEvent* hce)
00060 {
00061   // Create hits collection
00062   fHitsCollection 
00063     = new B4cCalorHitsCollection(SensitiveDetectorName, collectionName[0]); 
00064 
00065   // Add this collection in hce
00066   G4int hcID 
00067     = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
00068   hce->AddHitsCollection( hcID, fHitsCollection ); 
00069 
00070   // Create hits
00071   // fNofCells for cells + one more for total sums 
00072   for (G4int i=0; i<fNofCells+1; i++ ) {
00073     fHitsCollection->insert(new B4cCalorHit());
00074   }
00075 }
00076 
00077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00078 
00079 G4bool B4cCalorimeterSD::ProcessHits(G4Step* step, 
00080                                      G4TouchableHistory*)
00081 {  
00082   // energy deposit
00083   G4double edep = step->GetTotalEnergyDeposit();
00084   
00085   // step length
00086   G4double stepLength = 0.;
00087   if ( step->GetTrack()->GetDefinition()->GetPDGCharge() != 0. ) {
00088     stepLength = step->GetStepLength();
00089   }
00090 
00091   if ( edep==0. && stepLength == 0. ) return false;      
00092 
00093   G4TouchableHistory* touchable
00094     = (G4TouchableHistory*)(step->GetPreStepPoint()->GetTouchable());
00095     
00096   // Get calorimeter cell id 
00097   G4int layerNumber = touchable->GetReplicaNumber(1);
00098   
00099   // Get hit accounting data for this cell
00100   B4cCalorHit* hit = (*fHitsCollection)[layerNumber];
00101   if ( ! hit ) {
00102     G4cerr << "Cannot access hit " << layerNumber << G4endl;
00103     exit(1);
00104   }         
00105 
00106   // Get hit for total accounting
00107   B4cCalorHit* hitTotal 
00108     = (*fHitsCollection)[fHitsCollection->entries()-1];
00109   
00110   // Add values
00111   hit->Add(edep, stepLength);
00112   hitTotal->Add(edep, stepLength); 
00113       
00114   return true;
00115 }
00116 
00117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00118 
00119 void B4cCalorimeterSD::EndOfEvent(G4HCofThisEvent*)
00120 {
00121   if ( verboseLevel>1 ) { 
00122      G4int nofHits = fHitsCollection->entries();
00123      G4cout << "\n-------->Hits Collection: in this event they are " << nofHits 
00124             << " hits in the tracker chambers: " << G4endl;
00125      for ( G4int i=0; i<nofHits; i++ ) (*fHitsCollection)[i]->Print();
00126   }
00127 }
00128 
00129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines