BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofSD.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4//Description:
5//Author: Dengzy
6//Created: Mar, 2004
7//Modified:
8//Comment:
9//---------------------------------------------------------------------------//
10//$Id: BesTofSD.cc
11
12#include "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/Bootstrap.h"
14#include "GaudiKernel/PropertyMgr.h"
15#include "GaudiKernel/IJobOptionsSvc.h"
16#include "GaudiKernel/ISvcLocator.h"
17#include "GaudiKernel/IDataProviderSvc.h"
18#include "G4SystemOfUnits.hh"
19#include "G4PhysicalConstants.hh"
20#include "BesTofSD.hh"
21#include "ReadBoostRoot.hh"
22#include "G4HCofThisEvent.hh"
23#include "G4Step.hh"
24#include "G4ThreeVector.hh"
25#include "G4SDManager.hh"
26#include "G4ios.hh"
27#include "G4UnitsTable.hh"
28#include "G4Event.hh"
29#include "GaudiKernel/ISvcLocator.h"
30#include "GaudiKernel/Bootstrap.h"
31#include "GaudiKernel/MsgStream.h"
32#include "G4LossTableManager.hh"
33#include "G4ElectronIonPair.hh"
34using namespace CLHEP;
35//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36
37BesTofSD::BesTofSD( G4String name ) : BesSensitiveDetector(name), m_besTofList(0) {
38 collectionName.insert("BesTofHitsCollection");
39 collectionName.insert("BesTofHitsList");
40 elIonPair = new G4ElectronIonPair(1);
41
42 PropertyMgr m_propMgr;
43 m_propMgr.declareProperty("FanoFactor", m_fanoFactor = 0.2);
44 m_propMgr.declareProperty("nionOff", m_nionOff = 0.5);
45
46 IJobOptionsSvc* jobSvc;
47 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
48 jobSvc->setMyProperties("BesTofSD", &m_propMgr);
49
50 cout<<"BesTofSD Property:"<<endl
51 <<" FanoFactor= "<<m_fanoFactor
52 <<" nionOff= "<<m_nionOff
53 <<endl;
54}
55
56//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62
63void BesTofSD::Initialize( G4HCofThisEvent* ) {
64 m_besTofCollection = new BesTofHitsCollection( SensitiveDetectorName, collectionName[0] );
65 //elIonPair = G4LossTableManager::Instance()->ElectronIonPair();
66}
67
68//for MC Truth
69void BesTofSD::BeginOfTruthEvent( const G4Event* evt) {
70 m_event = evt->GetEventID();
71 m_besTofList = new BesTofHitsCollection( SensitiveDetectorName, collectionName[1] );
72 m_trackIndexes.clear();
73 m_trackIndex = -99;
74}
75
76void BesTofSD::EndOfTruthEvent( const G4Event* evt ) {
77 static G4int HLID=-1;
78 if( HLID<0 ) {
79 HLID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[1] );
80 }
81 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
82 HCE->AddHitsCollection( HLID, m_besTofList );
83}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86
87G4bool BesTofSD::ProcessHits( G4Step* aStep, G4TouchableHistory* ) {
88
89 G4double chg=aStep->GetTrack()->GetDefinition()->GetPDGCharge();
90 G4double edep = aStep->GetTotalEnergyDeposit();
91 G4double stepL=aStep->GetStepLength();
92 G4double deltaT=aStep->GetDeltaTime();
93 G4StepPoint* preStep = aStep->GetPreStepPoint();
94 G4ThreeVector pDirection=preStep->GetMomentumDirection();
95 G4String particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
96 G4Material* scinMaterial = aStep->GetTrack()->GetMaterial();
97 G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
98 G4int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
99
100 if( chg==0 && edep==0 && stepL==0 ) { return false; }
101
102 BesTofHit *newHit = new BesTofHit();
103 G4int trackId = aStep->GetTrack()->GetTrackID();
104
105 newHit->SetEvent(m_event);
106 newHit->SetTrackIndex(-99);
107 newHit->SetG4Index(aStep->GetTrack()->GetTrackID());
108 newHit->SetEdep(edep);
109 newHit->SetStepL(stepL);
110 //newHit->SetPName(particleName);
111 newHit->SetTrackL(aStep->GetTrack()->GetTrackLength());
112 G4ThreeVector pos=preStep->GetPosition();
113 newHit->SetPos(pos);
114 G4double globalTime=preStep->GetGlobalTime();
115 newHit->SetTime(globalTime);
116 newHit->SetDeltaT(deltaT);
117 newHit->SetPDirection(pDirection);
118 newHit->SetMomentum(preStep->GetMomentum());
119 //newHit->SetMaterial(scinMaterial);
120 newHit->SetCharge(charge);
121 newHit->SetPDGcode(pdgcode);
122
123 //Get local position in sensitive detector, add by anff
124 G4ThreeVector locPos(0,0,0);
125 G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStep->GetTouchable() );
126 //partId: barrel(1), east endcap(0), west endcap(2);
127 //scinNb: barrel(0-175),east endcap(0-47), west endcap(0-47)
128 //partId: mrpc: east(3), west(4),
129
130 G4String name;
131 //for(G4int i=0; i<theTouchable->GetHistoryDepth(); i++)
132 //{
133 // name = theTouchable->GetVolume(i)->GetName();
134 // G4cout<<"********* name of the "<<i<<" volume: "<<name<<" ***************"<<G4endl;
135 //}
136 name = theTouchable->GetVolume(0)->GetName();
137
138 G4int partId=-1, scinNb=-1, gapNb=-1, number=-1;
139 G4int strip = -1;
140 gapNb = theTouchable->GetReplicaNumber(0);
141 number = theTouchable->GetReplicaNumber(2); //This is valid only for scintillator
142
143 //MRPC ENDCAPS construct by geant4 code
144 if(name.contains("physical_gasLayer"))
145 {
146 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
147 number = theTouchable->GetReplicaNumber(3);
148 scinNb = number;
149
150 G4String name1 = theTouchable->GetVolume(4)->GetName();
151 if(name1 == "physicalEcTofEast") partId=3;
152 else if(name1 == "physicalEcTofWest") partId=4;
153 //G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
154 }
155 //MRPC ENDCAPS construct by GDML
156 else if(name=="logical_gasLayer")
157 {
158 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
159 number = theTouchable->GetReplicaNumber(3);
160 scinNb = 35-number;
161
162 G4String name1 = theTouchable->GetVolume(4)->GetName();
163 if(name1 == "logicalEcTofEast") partId=3;
164 else if(name1 == "logicalEcTofWest") partId=4;
165 //G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
166 }
167
168
169 // Scintillator
170 else if( name=="physicalScinBr1" ) {
171 partId = 1;
172 scinNb = number;
173 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
174 }
175 else if( name=="physicalScinBr2" ) {
176 partId = 1;
177 scinNb = number+88;
178 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
179 }
180 else if( name=="physicalScinEcWest" ) {
181 partId = 2;
182 scinNb = number;
183 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
184 }
185 else if( name=="physicalScinEcEast" ) {
186 partId = 0;
187 scinNb = number;
188 //G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
189 }
190
191
192 //if construct by gdml files
193 else if( name=="logicalScinBr1" || name=="logicalScinBr2" ) {
194 partId = 1;
195 scinNb = (527-number)/3;
196 }
197 //copy number: east:1-95(scinNb:47-0), west:1-95(scinNb:47-0)
198 else if( name=="logicalScinEcEast" ) {
199 partId = 0;
200 scinNb = (95-number)/2;
201 }
202 else if( name=="logicalScinEcWest" ) {
203 partId = 2;
204 scinNb = (95-number)/2;
205 }
206 else { return false; }
207
208
209 if(name.contains("physical_gasLayer") || name.contains("logical_gasLayer"))
210 {
211 G4double zz = locPos.z()-0.5*mm+(24+3)*mm*6; //0.5mm is the offset between strip and gasLayer
212 if(zz<=0)
213 {
214 strip=0;
215 }
216 else if(zz>0 && zz<12*27*mm)
217 {
218 for(G4int i=0; i<12; i++)
219 {
220 if(zz>i*27*mm && zz<=(i+1)*27*mm)
221 {
222 strip = i;
223 //G4cout<<"Local z is "<<locPos.z()<<" strip number is: "<<strip<<" !!!"<<G4endl;
224 break;
225 }
226 }
227 }
228 else
229 {
230 strip=11;
231 }
232 if(strip<0) strip=0;
233 if(strip>11) strip=11;
234 }
235
236
237 newHit->SetPartId(partId);
238 newHit->SetScinNb(scinNb);
239 newHit->SetGapNb(gapNb);
240 newHit->SetLocPos(locPos);
241 newHit->SetModule(scinNb);
242 newHit->SetStrip(strip);
243 //newHit->SetIons(elIonPair->SampleNumberOfIonsAlongStep(aStep));
244 newHit->SetIons(SampleNumberOfIonsAlongStep(aStep,elIonPair));
245 //newHit->Draw();
246
247 G4int trackIndex, g4TrackId;
248 GetCurrentTrackIndex( trackIndex, g4TrackId );
249 newHit->SetTrackIndex( trackIndex );
250 //newHit->Print();
251 if( edep>0 ) {
252 m_besTofCollection->insert( newHit );
253 }
254
255 //for mc truth
256 if( m_besTofList ) {
257 G4int trackIndex, g4TrackId;
258 GetCurrentTrackIndex(trackIndex, g4TrackId);
259 newHit->SetTrackIndex(trackIndex);
260 if( m_trackIndex != trackIndex ) {
261 m_trackIndex = trackIndex;
262 //G4int size = m_trackIndexes.size();
263 //G4int flag=1;
264 //if(size>0)
265 //{
266 // for(G4int i=0;i<size;i++)
267 // if(m_trackIndexes[i] == trackIndex )
268 // {flag =0; break;}
269 //}
270 //if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId )
271 G4int flag = 1;
272 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
273 if( pdg==12 || pdg==14 || pdg==16 ) { flag=0; }
274 if( flag && aStep->GetTrack()->GetTrackID()==g4TrackId ) {
275 m_trackIndexes.push_back(trackIndex);
276 BesTofHit* truHit = new BesTofHit();
277 *truHit = *newHit;
278 m_besTofList->insert(truHit);
279 }
280 }
281 }
282 if( edep<=0 ) { delete newHit; }
283
284 return true;
285
286}//Close Process Hits
287
288//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
289
290void BesTofSD::EndOfEvent( G4HCofThisEvent* HCE ) {
291 static G4int HCID=-1;
292 if( HCID<0 ) {
293 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
294 }
295 HCE->AddHitsCollection(HCID,m_besTofCollection);
296}
297
298//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
299
300G4int BesTofSD::SampleNumberOfIonsAlongStep( const G4Step* step, G4ElectronIonPair* eipair ) {
301 G4double FanoFactor = m_fanoFactor; //0.2; //Is this value appropiate?
302 G4double meanion = eipair->MeanNumberOfIonsAlongStep(step);
303 G4double sig = std::sqrt(FanoFactor*meanion); //Be carefull : In originally Geant4 code this calculatin is wrong!
304 G4int nion = G4int(G4RandGauss::shoot(meanion,sig) + m_nionOff); //0.5);
305 return nion;
306}
307
308
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition BesTofHit.hh:116
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
void SetEvent(G4double event)
Definition BesTofHit.hh:41
void SetModule(G4int module)
Definition BesTofHit.hh:60
void SetPos(G4ThreeVector pos)
Definition BesTofHit.hh:50
void SetDeltaT(G4double deltaT)
Definition BesTofHit.hh:52
void SetCharge(G4double charge)
Definition BesTofHit.hh:57
void SetPDGcode(G4int pdgcode)
Definition BesTofHit.hh:58
void SetTrackIndex(G4int trackIndex)
Definition BesTofHit.hh:43
void SetPDirection(G4ThreeVector pDirection)
Definition BesTofHit.hh:53
void SetIons(G4int ions)
Definition BesTofHit.hh:62
void SetPartId(G4int partId)
Definition BesTofHit.hh:45
void SetLocPos(G4ThreeVector locPos)
Definition BesTofHit.hh:63
void SetScinNb(G4int scinNb)
Definition BesTofHit.hh:46
void SetGapNb(G4int gapNb)
Definition BesTofHit.hh:64
void SetStrip(G4int strip)
Definition BesTofHit.hh:61
void SetStepL(G4double stepL)
Definition BesTofHit.hh:48
void SetTrackL(G4double length)
Definition BesTofHit.hh:49
void SetTime(G4double time)
Definition BesTofHit.hh:51
void SetEdep(G4double edep)
Definition BesTofHit.hh:47
void SetMomentum(G4ThreeVector momentum)
Definition BesTofHit.hh:54
void SetG4Index(G4int index)
Definition BesTofHit.hh:44
void BeginOfTruthEvent(const G4Event *)
Definition BesTofSD.cc:69
virtual void Initialize(G4HCofThisEvent *HCE)
Definition BesTofSD.cc:63
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition BesTofSD.cc:290
BesTofSD(G4String name)
Definition BesTofSD.cc:37
virtual ~BesTofSD()
Definition BesTofSD.cc:58
void EndOfTruthEvent(const G4Event *)
Definition BesTofSD.cc:76
G4int SampleNumberOfIonsAlongStep(const G4Step *, G4ElectronIonPair *)
Definition BesTofSD.cc:300
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *)
Definition BesTofSD.cc:87
float charge