source: trunk/examples/advanced/raredecay_calorimetry/src/PhotInCalorimeterSD.cc @ 1319

Last change on this file since 1319 was 807, checked in by garnier, 16 years ago

update

File size: 7.7 KB
Line 
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// $Id: PhotInCalorimeterSD.cc,v 1.6 2006/06/29 16:25:07 gunter Exp $
28// GEANT4 tag $Name:  $
29//
30
31//#define debug
32//#define errors
33
34#include "PhotInCalorimeterSD.hh"
35
36G4int PhotInCalorimeterSD::numberOfLayers = PhotInNOfLayers;
37G4int PhotInCalorimeterSD::numberOfSlabs  = PhotInNOfSlabs;
38
39PhotInCalorimeterSD::PhotInCalorimeterSD(G4String name):G4VSensitiveDetector(name),
40  SlabsCollection(0),AbsorberCollection(0),SlabsCollID(-1),AbsorberCollID(-1)
41{
42  for(G4int i=0; i<PhotInNumCollections; i++) collectionName.insert(PhotInCollect[i]);
43#ifdef debug
44  G4cout<<"PhotInCalorimeterSD::Const: nCol="<<PhotInNumCollections<<G4endl;
45#endif
46}
47
48PhotInCalorimeterSD::~PhotInCalorimeterSD()
49{
50#ifdef debug
51  G4cout<<"PhotInCalorimeterSD::~:S="<<SlabsCollection<<", L="<<AbsorberCollection<<G4endl;
52#endif
53  //delete SlabsCollection;    // Try to open later to be sure that it is not delited by G4
54  //delete AbsorberCollection; // Try to open later to be sure that it is not delited by G4
55}
56
57void PhotInCalorimeterSD::Initialize(G4HCofThisEvent* HCE)
58{
59  // Just gives "SlabsCollection" name to the SensitiveDetectorName of the basic class
60  SlabsCollection = new PhotInCalorHitsCollection(SensitiveDetectorName,collectionName[1]);
61  // Why one empty hit per slab (? M.K. What for?): One Collection for all slabs!
62  for(G4int i=0; i<numberOfLayers; i++)
63    for(G4int j=0; j<numberOfSlabs; j++)
64      SlabsCollection->insert(new PhotInCalorHit); // How to delete in the distructor?(M.K)
65  if(SlabsCollID<0) SlabsCollID = GetCollectionID(0);  // If not initialized -> Initialise
66#ifdef debug
67  G4cout<<"PhotInCalorimeterSD::Initialize: slabsCollectionID="<<SlabsCollID<<G4endl;
68#endif
69  HCE->AddHitsCollection(SlabsCollID,SlabsCollection);
70
71  // This is not good to make the absorber active @@ in future make a flag (M.K.)
72  // Just gives "AbsorberCollection" name to the SensitiveDetectorName of the basic class
73  AbsorberCollection =
74                    new PhotInCalorHitsCollection(SensitiveDetectorName,collectionName[0]);
75  for(G4int k=0; k<numberOfLayers; k++) AbsorberCollection->insert(new PhotInCalorHit);
76  if(AbsorberCollID<0) AbsorberCollID = GetCollectionID(1);// If notInitialized->Initialise
77#ifdef debug
78  G4cout<<"PhotInCalorimeterSD::Initialize: layersCollectionID="<<AbsorberCollID<<G4endl;
79#endif
80  HCE->AddHitsCollection(AbsorberCollID, AbsorberCollection);
81}
82
83G4bool PhotInCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
84{
85  G4double edep = aStep->GetTotalEnergyDeposit(); // Energy deposition in the SensitiveSlab
86 
87  G4double stepl = aStep->GetStepLength(); // StepLength in the SensitiveSlab (can be many)
88#ifdef debug
89  G4cout<<"PhotInCalorimeterSD::ProcessHits: E="<<edep<<",stepL="<<stepl<<G4endl;
90#endif
91  G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
92     
93  // @@ G4TouchableHistoryHandler can be used
94  G4TouchableHistory* theTouchable = (G4TouchableHistory*)
95                                                (aStep->GetPreStepPoint()->GetTouchable());
96  //G4int LayerSlabNumber = theTouchable->GetReplicaNumber();// nL*(1+nS) (1 - absorber)
97  G4int LayerNumber = theTouchable->GetReplicaNumber();    // replica # on level 0
98  G4int histDepth = theTouchable->GetHistoryDepth();       // depth of enclosion
99  G4int SlabNumber = -1;                                   // absorber
100  if(histDepth>1) SlabNumber = theTouchable->GetReplicaNumber(1); // replica # on level 1
101#ifdef debug
102  G4cout<<"PhotInCalorimeterSD:::ProcessHits: historyDepth="<<histDepth<<", L# "
103        <<LayerNumber<<", S# "<<SlabNumber<<G4endl;
104#endif
105                //G4int NoVolumesInLayer = 1+numberOfSlabs; // User should calculate created volumes (!)
106  //G4int LayerNumber = LayerSlabNumber/NoVolumesInLayer;    // # in the AbsorberCollection
107  //G4int SlabNumber  = LayerSlabNumber%NoVolumesInLayer -1; // -1 = absorber
108  G4int CopyNumber = LayerNumber*numberOfSlabs+SlabNumber; // # in the SlabsCollection
109  // @@ In future trac length can be defined by a flag (electrons, muons, mesons, protons)
110  //G4bool charged = particle==G4Electron::ElectronDefinition()   ||
111  //                 particle==G4Positron::PositronDefinition()   ||
112  //                 particle==G4PionPlus::PionPlusDefinition()   ||
113  //                 particle==G4PionMinus::PionMinusDefinition() ||
114  //                 particle==G4MuonPlus::MuonPlusDefinition()   ||
115  //                 particle==G4MuonMinus::MuonMinusDefinition() ||
116  //                 particle==G4KaonPlus::KaonPlusDefinition()   ||
117  //                 particle==G4KaonMinus::KaonMinusDefinition() ||
118  //                                            particle==G4Proton::ProtonDefinition();
119  G4bool neutr   = particle==G4Neutron::NeutronDefinition();
120  if(SlabNumber>-1 && LayerNumber>-1 && LayerNumber<numberOfLayers &&
121     SlabNumber<numberOfSlabs) // Sensetive Slab
122  {
123#ifdef debug
124  G4cout<<"PhotInCalorimeterSD:::ProcessHits: write in (L# "<<LayerNumber
125        <<", S# "<<SlabNumber<<"): dE="<<edep<<",stepL="<<stepl<<G4endl;
126#endif
127    (*SlabsCollection)[CopyNumber]->AddEnergy(edep);
128    //if(charged) (*SlabsCollection)[CopyNumber]->AddStep(stepl);
129    if(neutr) (*SlabsCollection)[CopyNumber]->AddStep(stepl);
130  }
131  else if(SlabNumber==-1 && LayerNumber>-1 && LayerNumber<numberOfLayers) // Sens. Absorber
132  {
133    (*AbsorberCollection)[LayerNumber]->AddEnergy(edep);
134    //if(charged) (*AbsorberCollection)[LayerNumber]->AddStep(stepl);
135    if(neutr) (*AbsorberCollection)[LayerNumber]->AddStep(stepl);
136  }
137  else
138  {
139#ifdef errors
140    G4cerr<<"-Warning-PhotInCalorimeterSD::ProcH: S#"<<SlabNumber<<" < "<<numberOfSlabs
141          <<", L#"<<LayerNumber<<" < "<<numberOfLayers<<G4endl;
142#endif
143    return false;
144  }
145  return true;
146}
147
148void PhotInCalorimeterSD::EndOfEvent(G4HCofThisEvent*)
149{
150#ifdef debug
151  G4cout<<"PhotInCalorimeterSD::EndOfEvent: at present it's doing nothing"<<G4endl;
152#endif
153  // Here something can be done in the end of the Event to summerize the information
154}
155
156void PhotInCalorimeterSD::clear()   {} // User can clean up unnecessary information
157
158void PhotInCalorimeterSD::DrawAll() {} // User draw the collected information
159
160void PhotInCalorimeterSD::PrintAll(){} // User print the collected information
161
162
Note: See TracBrowser for help on using the repository browser.