SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_G4_CopClusterSD.cc
Go to the documentation of this file.
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 #include "SToGS_G4_CopClusterSD.hh"
29 
30 #include "G4Step.hh"
31 #include "G4HCofThisEvent.hh"
32 #include "G4TouchableHistory.hh"
33 #include "G4VProcess.hh"
34 #include "G4ios.hh"
35 
36 SToGS::CopClusterSD::CopClusterSD(G4String name): G4VSensitiveDetector(name)
37 {
38  G4String HCname = "CopClusterHits";
39  collectionName.insert(HCname);
40 }
42 {
43  ;
44 }
45 void SToGS::CopClusterSD::Initialize(G4HCofThisEvent* HCE)
46 {
47 // G4cout << " In SToGS::CopClusterSD::Initialize " << G4endl;
48  static int HCID = -1;
49  caloCollection = new SToGS::CopClusterHitsCollection(SensitiveDetectorName,collectionName[0]);
50 
51  if ( HCID < 0 )
52  HCID = GetCollectionID(0);
53 
54  HCE->AddHitsCollection(HCID,caloCollection);
55 // G4cout << " Out SToGS::CopClusterSD::Initialize " << G4endl;
56 }
57 G4bool SToGS::CopClusterSD::ProcessHits(G4Step* aStep, G4TouchableHistory *touch)
58 {
59 // G4cout << " In SToGS::CopClusterSD::ProcessHits" << G4endl;
60  // nothing to be stored if no energy
61 
62  G4double edep = aStep->GetTotalEnergyDeposit();
63  if ( edep == 0. )
64  return false;
65 
66  // get curent detector number and add offset of the on-top structure
67  const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
68  G4String tmp; G4int depth = touchable->GetHistoryDepth(), detector_number = touchable->GetCopyNumber(0);
69  if ( depth > 1 ) {
70  detector_number += touchable->GetCopyNumber(depth-1);
71  /*
72  G4cout << " 0 " << touchable->GetCopyNumber(0) << G4endl;;
73  G4cout << " 1 " << touchable->GetCopyNumber(1) << G4endl;;
74  G4cout << " 2 " << touchable->GetCopyNumber(2) << G4endl;;
75  G4cout << " 3 " << touchable->GetCopyNumber(3) << G4endl;;
76  */
77  }
78 
79  G4bool anew = true; SToGS::CopClusterHit *newHit;
80 
81  for( unsigned int i = 0; i < caloCollection->GetSize(); i++ ){ // look
82  newHit = (SToGS::CopClusterHit *)caloCollection->GetHit(i);
83  if ( detector_number == newHit->GetDetID() )
84  {
85  anew = false;
86  break;
87  }
88  }
89 
90  if ( anew ) { // a new hit is created
91  newHit = new SToGS::CopClusterHit();
92 
93  newHit->SetEdep( edep );
94  newHit->SetPos( edep, aStep->GetPostStepPoint()->GetPosition() );
95  newHit->SetToF( edep, aStep->GetPostStepPoint()->GetGlobalTime() );
96 
97  newHit->SetDetName (aStep->GetTrack()->GetVolume()->GetName());
98  newHit->SetDetID(detector_number);
99 
100  // newHit->SetMotherDetName(touch->GetVolume()->GetName());
101  newHit->SetMotherID(aStep->GetPreStepPoint()->GetTouchableHandle()->GetReplicaNumber(1));
102  newHit->SetNbHits(1);
103  // add this hit to the collection
104  caloCollection->insert( newHit );
105  }
106  else { // add the informations concerning this hit to the existing one
107  newHit->AddOneHit();
108  newHit->AddEdep( edep );
109  newHit->AddPos ( edep, aStep->GetPostStepPoint()->GetPosition() );
110  newHit->AddToF ( edep, aStep->GetPostStepPoint()->GetGlobalTime() );
111  }
112 
113 // G4cout << " Out SToGS::CopClusterSD::ProcessHits" << G4endl;
114  return true;
115 }
116 void SToGS::CopClusterSD::EndOfEvent(G4HCofThisEvent*)
117 {
118  for( unsigned int i = 0; i < caloCollection->GetSize(); i++ ){ // to calculate properly the mean values
119  SToGS::CopClusterHit *hit = (SToGS::CopClusterHit *)caloCollection->GetHit(i);
120  hit->EndOfEvent();
121  }
122 }
124 {
125 }
127 {
128 }
130 {
131 }
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
void SetDetName(G4String name)
void EndOfEvent()
to be applied at the end of an event to calculate properly the mean values
G4THitsCollection< CopClusterHit > CopClusterHitsCollection
void AddToF(G4double de, G4double t)
void SetToF(G4double de, G4double tf=0.0)
void Initialize(G4HCofThisEvent *HCE)
void AddPos(G4double de, G4ThreeVector xyz)
void SetEdep(G4double de=0.0)
Informations to keep the energy is in a sensitive detector.
void SetPos(G4double de, G4ThreeVector xyz=G4ThreeVector(0., 0., 0.))
void EndOfEvent(G4HCofThisEvent *HCE)