FiberSD.cc 5.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
// Author: Michael Phipps

#include "FiberSD.hh"
29
#include "SteppingAction.hh"
30
31
32
33
34
35
36

#include "G4HCofThisEvent.hh"
#include "G4Step.hh"
#include "G4ThreeVector.hh"
#include "G4SDManager.hh"
#include "G4ios.hh"
#include "G4Poisson.hh"
37
38
#include "G4ParticleTypes.hh"
#include "G4ParticleDefinition.hh"
39
40
41
42
43
44
45

#include <string>
#include <iostream>
#include <cmath>

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

46
47
FiberSD::FiberSD(G4String sdName, G4int modNum, G4bool optical)
  :G4VSensitiveDetector(sdName), m_modNum(modNum), OPTICAL(optical) {
48
  collectionName.insert(sdName);
49
50
  HCID = -1;

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

FiberSD::~FiberSD(){ }

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void FiberSD::HistInitialize(){
  std::string name = GetName();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void FiberSD::Initialize(G4HCofThisEvent* HCE){
66

67
  fiberCollection = new FiberHitsCollection(SensitiveDetectorName,
68
69
70
					      m_modNum);

  std::string name = collectionName[0];
71
72
73

  if(HCID<0)
    { HCID = G4SDManager::GetSDMpointer()->GetCollectionID( name );}
74

75
76
77
78
79
80
81
  HCE->AddHitsCollection( HCID, fiberCollection );
  G4cout << " HCID " << HCID << " name " << name << G4endl;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

G4bool FiberSD::ProcessHits(G4Step* aStep,G4TouchableHistory*){
82
  G4double eDep   = aStep->GetTotalEnergyDeposit();
83
84


85
86
  //      Figure out if this is necessary
  //
87
  G4int    totalRodNum = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(0);
88
  G4String radNum_s = "7" +  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() + "0";
89
90
  G4int    rodNum;
  G4int    radNum;
aricct2's avatar
aricct2 committed
91

92
	rodNum = totalRodNum;
93
	radNum = (std::stoi (radNum_s)*100)+rodNum;
94
  // ^^^^ Figure out if this is necessary ^^^^
95

96
97
98
99
100
  G4double energy = aStep->GetPreStepPoint()->GetTotalEnergy();
  G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
  G4ParticleDefinition *particle = aStep->GetTrack()->GetDefinition();
  G4double charge = aStep->GetPreStepPoint()->GetCharge();

101
102
  //Get the number of Cherenkov photons created in this step
  //If optical is off, stop that track
103
104
  int capturedPhotons = 0;
  const std::vector<const G4Track*>* secVec = aStep->GetSecondaryInCurrentStep();
105
  for(uint i = 0; i < secVec->size(); i++){
106
    if( secVec->at(i)->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()){
107
108
109
      capturedPhotons++;
    }//end if pid==0
  }//end secondary track loop
110
111
112

  FiberHit* newHit = new FiberHit();

113
114
115
116
117
118
119
120
121
122
123
124
125
  newHit->setCharge      ( charge );
  newHit->setTrackID     ( aStep->GetTrack()->GetTrackID() );
  newHit->setModNb       ( m_modNum );
  newHit->setRadNb       ( radNum );
  newHit->setRodNb       ( rodNum );
  newHit->setEdep        ( eDep );
  newHit->setPos         ( aStep->GetTrack()->GetVertexPosition() );
  newHit->setParticle    ( particle );
  newHit->setEnergy      ( energy );
  newHit->setMomentum    ( momentum );
  newHit->setNCherenkovs ( capturedPhotons );

  fiberCollection->insert ( newHit );
126

127
  // only want to record photons if optical flag is on
128
129
  //if( OPTICAL && particle->GetPDGEncoding() == 0 ) fiberCollection->insert (newHit );

130
131
132
133
134
135
136
137
138
139
140
141
142
  return true;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void FiberSD::EndOfEvent(G4HCofThisEvent*)
{

  //  G4int NbHits = fiberCollection->entries();

  /*
  if(verboseLevel>0) {
      std::cout << " if verbose loop" << std::endl;
143
      std::cout << "\n-------->Hits Collection: in this event they are " << NbHits
144
145
146
147
148
149
150
151
152
153
154
		<< " hits in the calorimeter cells: " << std::endl;
      for (G4int i=0;i<NbHits;i++) {
	if (i %100 == 0) std::cout << " i " << i << std::endl;
	(*fiberCollection)[i]->Print();
      }
  }
  */

}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......