BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMdcSD Class Reference

#include <BesMdcSD.hh>

Inheritance diagram for BesMdcSD:

Public Member Functions

 BesMdcSD (G4String)
 ~BesMdcSD ()
void Initialize (G4HCofThisEvent *)
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
void EndOfEvent (G4HCofThisEvent *)
void BeginOfTruthEvent (const G4Event *)
void EndOfTruthEvent (const G4Event *)
G4double Distance (G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
void dedxFuncInti (void)
 BesMdcSD (G4String)
 ~BesMdcSD ()
void Initialize (G4HCofThisEvent *)
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
void EndOfEvent (G4HCofThisEvent *)
void BeginOfTruthEvent (const G4Event *)
void EndOfTruthEvent (const G4Event *)
G4double Distance (G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
void dedxFuncInti (void)
 BesMdcSD (G4String)
 ~BesMdcSD ()
void Initialize (G4HCofThisEvent *)
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
void EndOfEvent (G4HCofThisEvent *)
void BeginOfTruthEvent (const G4Event *)
void EndOfTruthEvent (const G4Event *)
G4double Distance (G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
void dedxFuncInti (void)
Public Member Functions inherited from BesSensitiveDetector
 BesSensitiveDetector (const G4String name)
virtual ~BesSensitiveDetector ()
virtual void BeginOfTrack (const G4Track *)
virtual void EndOfTrack (const G4Track *)
 BesSensitiveDetector (const G4String name)
virtual ~BesSensitiveDetector ()
virtual void BeginOfTrack (const G4Track *)
virtual void EndOfTrack (const G4Track *)
 BesSensitiveDetector (const G4String name)
virtual ~BesSensitiveDetector ()
virtual void BeginOfTrack (const G4Track *)
virtual void EndOfTrack (const G4Track *)

Additional Inherited Members

Protected Member Functions inherited from BesSensitiveDetector
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const

Detailed Description

Constructor & Destructor Documentation

◆ BesMdcSD() [1/3]

BesMdcSD::BesMdcSD ( G4String name)

Definition at line 25 of file BesMdcSD.cc.

25 : BesSensitiveDetector( name ) {
26 collectionName.insert( "BesMdcHitsCollection" );
27 collectionName.insert( "BesMdcTruthCollection" );
28
29 mdcGeoPointer = BesMdcGeoParameter::GetGeo();
30 mdcCalPointer = new BesMdcCalTransfer;
31
32 StatusCode sc = Gaudi::svcLocator()->service( "MdcGeomSvc", mdcGeomSvc );
33 if ( !sc.isSuccess() ) std::cout << "BesMdcSD::Could not open MdcGeomSvc" << std::endl;
34
35 sc = Gaudi::svcLocator()->service( "G4Svc", m_G4Svc );
36 if ( !sc.isSuccess() ) G4cout << " MdcSD::Error,could not open G4Svc" << G4endl;
37
38 if ( m_G4Svc->GetMdcDedxFlag() == 1 )
39 {
40 G4cout << " MdcSD: Use sampled dedx instead of Geant4 value" << G4endl;
42 }
43
44 // get DedxSimSvc
45 sc = Gaudi::svcLocator()->service( "DedxSimSvc", m_pDedxSimSvc, true );
46 if ( !sc.isSuccess() ) { std::cout << "Could not get DedxSimSvc" << std::endl; }
47
48 // get CalibCurSvc
49 IDedxCurSvc* tmp_dedxCurSvc;
50 sc = Gaudi::svcLocator()->service( "DedxCurSvc", m_pDedxCurSvc, true );
51 if ( !sc.isSuccess() ) { std::cout << "Could not get DedxCurSvc" << std::endl; }
52
53 if ( m_G4Svc->MdcRootFlag() )
54 {
55 m_tupleMdc = m_G4Svc->GetTupleMdc();
56 sc = m_tupleMdc->addItem( "betaGamma", m_betaGamma );
57 sc = m_tupleMdc->addItem( "fitval", m_fitval );
58 sc = m_tupleMdc->addItem( "dedx", m_dedx );
59 sc = m_tupleMdc->addItem( "de", m_de );
60 // sc = m_tupleMdc->addItem("length",m_length);
61 // sc = m_tupleMdc->addItem("random",m_random);
62 sc = m_tupleMdc->addItem( "charge", m_charge );
63 sc = m_tupleMdc->addItem( "costheta", m_costheta );
64 }
65}
static BesMdcGeoParameter * GetGeo(void)
void dedxFuncInti(void)
Definition BesMdcSD.cc:405
BesSensitiveDetector(const G4String name)

◆ ~BesMdcSD() [1/3]

BesMdcSD::~BesMdcSD ( )

Definition at line 67 of file BesMdcSD.cc.

67{}

◆ BesMdcSD() [2/3]

BesMdcSD::BesMdcSD ( G4String )

◆ ~BesMdcSD() [2/3]

BesMdcSD::~BesMdcSD ( )

◆ BesMdcSD() [3/3]

BesMdcSD::BesMdcSD ( G4String )

◆ ~BesMdcSD() [3/3]

BesMdcSD::~BesMdcSD ( )

Member Function Documentation

◆ BeginOfTruthEvent() [1/3]

void BesMdcSD::BeginOfTruthEvent ( const G4Event * evt)
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 87 of file BesMdcSD.cc.

87 {
88 truthCollection = new BesMdcHitsCollection( SensitiveDetectorName, collectionName[1] );
89 // G4cout<<" begin event "<<evt->GetEventID()<<G4endl;
90}
G4THitsCollection< BesMdcHit > BesMdcHitsCollection

◆ BeginOfTruthEvent() [2/3]

void BesMdcSD::BeginOfTruthEvent ( const G4Event * )
virtual

Reimplemented from BesSensitiveDetector.

◆ BeginOfTruthEvent() [3/3]

void BesMdcSD::BeginOfTruthEvent ( const G4Event * )
virtual

Reimplemented from BesSensitiveDetector.

◆ dedxFuncInti() [1/3]

void BesMdcSD::dedxFuncInti ( void )

Definition at line 405 of file BesMdcSD.cc.

405 {
406 dEdE_mylanfunc = new TF1(
407 "dEdE_mylanfunc", "[3]*TMath::Exp([2]*((x[0]-[0])/[1]+TMath::Exp(-1*((x[0]-[0])/[1]))))",
408 0, 7500 );
409 // dEdE_mylanfunc->SetParameters(2009.35,559.776,-1.0932,6327.38);
410 dEdE_mylanfunc->SetParNames( "MPV", "Sigma", "constant1", "constant2" );
411}

Referenced by BesMdcSD().

◆ dedxFuncInti() [2/3]

void BesMdcSD::dedxFuncInti ( void )

◆ dedxFuncInti() [3/3]

void BesMdcSD::dedxFuncInti ( void )

◆ Distance() [1/3]

G4double BesMdcSD::Distance ( G4int layerId,
G4int cellId,
G4ThreeVector pointIn,
G4ThreeVector pointOut,
G4ThreeVector & hitPosition,
G4double & transferT )

Definition at line 336 of file BesMdcSD.cc.

338 {
339 // For two lines r=r1+t1.v1 & r=r2+t2.v2
340 // the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
341 // the point where closest approach are
342 // t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
343 // t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
344 // if v1 x v2=0 means two lines are parallel
345 // d=|(r2-r1) x v1|/|v1|
346
347 G4double t1, distance, dInOut, dHitIn, dHitOut;
348 // Get wirepoint @ endplate
349 G4ThreeVector east = mdcGeomSvc->Wire( layerId, cellId )->Backward();
350 G4ThreeVector west = mdcGeomSvc->Wire( layerId, cellId )->Forward();
351 G4ThreeVector wireLine = east - west;
352 G4ThreeVector hitLine = pointOut - pointIn;
353
354 G4ThreeVector hitXwire = hitLine.cross( wireLine );
355 G4ThreeVector wire2hit = east - pointOut;
356 // Hitposition is the position on hit line where closest approach
357 // of two lines, but it may out the area from pointIn to pointOut
358 if ( hitXwire.mag() == 0 )
359 {
360 distance = wireLine.cross( wire2hit ).mag() / wireLine.mag();
361 hitPosition = pointIn;
362 }
363 else
364 {
365 t1 = hitXwire.dot( wire2hit.cross( wireLine ) ) / hitXwire.mag2();
366 hitPosition = pointOut + t1 * hitLine;
367
368 dInOut = ( pointOut - pointIn ).mag();
369 dHitIn = ( hitPosition - pointIn ).mag();
370 dHitOut = ( hitPosition - pointOut ).mag();
371 if ( dHitIn <= dInOut && dHitOut <= dInOut )
372 { // Between point in & out
373 distance = fabs( wire2hit.dot( hitXwire ) / hitXwire.mag() );
374 }
375 else if ( dHitOut > dHitIn )
376 { // out pointIn
377 distance = wireLine.cross( pointIn - east ).mag() / wireLine.mag();
378 hitPosition = pointIn;
379 }
380 else
381 { // out pointOut
382 distance = wireLine.cross( pointOut - east ).mag() / wireLine.mag();
383 hitPosition = pointOut;
384 }
385 }
386
387 // Calculate signal transferT on wire
388 G4double halfLayerLength = mdcGeomSvc->Layer( layerId )->Length() / 2.;
389 G4double halfWireLength = wireLine.mag() / 2.;
390 G4double transferZ = 0;
391 if ( layerId % 2 == 0 )
392 {
393 transferZ = halfLayerLength + hitPosition.z(); // West readout
394 }
395 else
396 {
397 transferZ = halfLayerLength - hitPosition.z(); // East readout
398 }
399 if ( layerId < 8 ) { transferT = transferZ * halfWireLength / halfLayerLength / 220; }
400 else { transferT = transferZ * halfWireLength / halfLayerLength / 240; }
401
402 return distance;
403}

Referenced by ProcessHits().

◆ Distance() [2/3]

G4double BesMdcSD::Distance ( G4int ,
G4int ,
G4ThreeVector ,
G4ThreeVector ,
G4ThreeVector & ,
G4double &  )

◆ Distance() [3/3]

G4double BesMdcSD::Distance ( G4int ,
G4int ,
G4ThreeVector ,
G4ThreeVector ,
G4ThreeVector & ,
G4double &  )

◆ EndOfEvent() [1/3]

void BesMdcSD::EndOfEvent ( G4HCofThisEvent * )

Definition at line 323 of file BesMdcSD.cc.

323 {
324 if ( verboseLevel > 0 )
325 {
326 hitsCollection->PrintAllHits();
327 /*
328 G4int NbHits = hitsCollection->entries();
329 G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
330 << " hits in the MDC chambers: " << G4endl;
331 for (G4int i=0;i<NbHits;i++) (*hitsCollection)[i]->Print();
332 */
333 }
334}

◆ EndOfEvent() [2/3]

void BesMdcSD::EndOfEvent ( G4HCofThisEvent * )

◆ EndOfEvent() [3/3]

void BesMdcSD::EndOfEvent ( G4HCofThisEvent * )

◆ EndOfTruthEvent() [1/3]

void BesMdcSD::EndOfTruthEvent ( const G4Event * evt)
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 92 of file BesMdcSD.cc.

92 {
93 static G4int HLID = -1;
94 if ( HLID < 0 )
95 { HLID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[1] ); }
96 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
97 HCE->AddHitsCollection( HLID, truthCollection );
98}

◆ EndOfTruthEvent() [2/3]

void BesMdcSD::EndOfTruthEvent ( const G4Event * )
virtual

Reimplemented from BesSensitiveDetector.

◆ EndOfTruthEvent() [3/3]

void BesMdcSD::EndOfTruthEvent ( const G4Event * )
virtual

Reimplemented from BesSensitiveDetector.

◆ Initialize() [1/3]

void BesMdcSD::Initialize ( G4HCofThisEvent * HCE)

Definition at line 69 of file BesMdcSD.cc.

69 {
70 hitsCollection = new BesMdcHitsCollection( SensitiveDetectorName, collectionName[0] );
71 static G4int HCID = -1;
72 if ( HCID < 0 )
73 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[0] ); }
74 HCE->AddHitsCollection( HCID, hitsCollection );
75 G4int i, j;
76 for ( i = 0; i < 43; i++ )
77 {
78 for ( j = 0; j < 288; j++ )
79 {
80 hitPointer[i][j] = -1;
81 truthPointer[i][j] = -1;
82 }
83 }
84}

◆ Initialize() [2/3]

void BesMdcSD::Initialize ( G4HCofThisEvent * )

◆ Initialize() [3/3]

void BesMdcSD::Initialize ( G4HCofThisEvent * )

◆ ProcessHits() [1/3]

G4bool BesMdcSD::ProcessHits ( G4Step * aStep,
G4TouchableHistory *  )

Definition at line 100 of file BesMdcSD.cc.

100 {
101 G4Track* gTrack = aStep->GetTrack();
102
103 G4double globalT =
104 gTrack->GetGlobalTime(); // Time since the event in which the track belongs is created
105 if ( std::isnan( globalT ) )
106 {
107 G4cout << "MdcSD:error, globalT is nan " << G4endl;
108 return false;
109 }
110 if ( globalT > 2000 ) return false; // MDC T window is 2 microsecond
111
112 // skip neutral tracks
113 G4int charge = gTrack->GetDefinition()->GetPDGCharge();
114 if ( charge == 0 ) return false;
115
116 // skip no energy deposit tracks
117 G4double stepLength = aStep->GetStepLength();
118 if ( stepLength == 0 )
119 {
120 // G4cout<<"step length equal 0!!"<<G4endl;
121 return false;
122 }
123
124 G4double edep = aStep->GetTotalEnergyDeposit() / stepLength;
125 if ( edep == 0. ) return false;
126
127 // get position of the track at the beginning and at the end of step
128 G4StepPoint* prePoint = aStep->GetPreStepPoint();
129 G4StepPoint* postPoint = aStep->GetPostStepPoint();
130
131 // get position coordinate
132 G4ThreeVector pointIn = prePoint->GetPosition();
133 G4ThreeVector pointOut = postPoint->GetPosition();
134
135 // get physical volumes
136 const G4VTouchable* touchable = prePoint->GetTouchable();
137 G4VPhysicalVolume* volume = touchable->GetVolume( 0 );
138
139 G4double driftD = 0;
140 G4double driftT = 0;
141 G4double edepTemp = 0;
142 G4double lengthTemp = 0;
143 G4int cellId = 0;
144 G4int layerId = touchable->GetVolume( 1 )->GetCopyNo();
145 if ( volume->IsReplicated() ) { cellId = touchable->GetReplicaNumber(); }
146 else { cellId = touchable->GetVolume( 0 )->GetCopyNo(); }
147 if ( layerId == 18 && ( cellId == 27 || cellId == 42 ) ) return false; // no sense wire
148
149 if ( ReadBoostRoot::GetMdc() == 2 )
150 { // gdml
151 // layerId 0-35 -> CopyNo 0-35 in gdml
152 // layerId 36-42 -> CopyNo (36,37),(38,39),...(48,49)
153 if ( layerId >= 36 ) layerId = 36 + ( layerId - 36 ) / 2;
154 }
155
156 G4double halfLayerLength = mdcGeomSvc->Layer( layerId )->Length() / 2.;
157 if ( ( ( fabs( pointIn.z() ) - halfLayerLength ) > -7. ) &&
158 ( ( fabs( pointOut.z() ) - halfLayerLength ) > -7. ) )
159 return false; // Out sensitive area
160
161 G4int trackID = gTrack->GetTrackID(); // G4 track ID of current track.
162 G4int truthID, g4TrackID;
163 GetCurrentTrackIndex( truthID, g4TrackID ); // ID of current primary track.
164
165 G4double theta = gTrack->GetMomentumDirection().theta();
166
167 G4ThreeVector hitPosition( 0, 0, 0 );
168 G4double transferT = 0;
169 driftD = Distance( layerId, cellId, pointIn, pointOut, hitPosition, transferT );
170
171 G4double posPhi, wirePhi;
172 posPhi = hitPosition.phi(); // from -pi to pi
173 if ( posPhi < 0 ) posPhi += 2 * pi;
174 wirePhi =
175 mdcGeoPointer->SignalWire( layerId, cellId ).Phi( hitPosition.z() ); // from 0 to 2pi
176
177 G4int posFlag;
178 if ( posPhi <= wirePhi ) { posFlag = 0; }
179 else { posFlag = 1; }
180 // if x axis is between pos and wire, phi will has a jump of one of them.
181 if ( posPhi < 1. && wirePhi > 5. ) posFlag = 1;
182 if ( posPhi > 5. && wirePhi < 1. ) posFlag = 0;
183
184 G4ThreeVector hitLine = pointOut - pointIn;
185 G4double enterAngle = hitLine.phi() - wirePhi;
186 while ( enterAngle < -pi / 2. ) enterAngle += pi;
187 while ( enterAngle > pi / 2. ) enterAngle -= pi;
188
189 if ( m_G4Svc->GetMdcDedxFlag() == 1 )
190 {
191 G4double betaGamma =
192 aStep->GetPreStepPoint()->GetBeta() * aStep->GetPreStepPoint()->GetGamma();
193 if ( betaGamma < 0.01 ) return false; // too low momentum
194 // if (betaGamma < 10.0) betaGamma = 10.0;
195
196 G4double eCount = dedxSample( betaGamma, charge, theta );
197 edep = eCount;
198 }
199
200 BesMdcHit* newHit = new BesMdcHit();
201 newHit->SetTrackID( truthID );
202 // newHit->SetTrkID(trackID);
203 newHit->SetLayerNo( layerId );
204 newHit->SetCellNo( cellId );
205 newHit->SetEdep( edep );
206 newHit->SetPos( hitPosition );
207 newHit->SetDriftD( driftD );
208 newHit->SetTheta( theta );
209 newHit->SetPosFlag( posFlag );
210 newHit->SetEnterAngle( enterAngle );
211
212 // Transfer hit pointer to BesMdcCalTransfer
213 mdcCalPointer->SetHitPointer( newHit );
214
215 driftT = mdcCalPointer->D2T( driftD );
216 globalT += transferT;
217 driftT += globalT;
218
219 newHit->SetDriftT( driftT );
220 newHit->SetGlobalT( globalT );
221
222 if ( hitPointer[layerId][cellId] == -1 )
223 {
224 hitsCollection->insert( newHit );
225 G4int NbHits = hitsCollection->entries();
226 hitPointer[layerId][cellId] = NbHits - 1;
227 }
228 else
229 {
230 G4int pointer = hitPointer[layerId][cellId];
231 if ( g4TrackID == trackID )
232 { G4double preDriftT = ( *hitsCollection )[pointer]->GetDriftT(); }
233
234 G4double preDriftT = ( *hitsCollection )[pointer]->GetDriftT();
235 if ( driftT < preDriftT )
236 {
237 ( *hitsCollection )[pointer]->SetTrackID( truthID );
238 //(*hitsCollection)[pointer]->SetTrkID(trackID);
239 ( *hitsCollection )[pointer]->SetDriftD( driftD );
240 ( *hitsCollection )[pointer]->SetDriftT( driftT );
241 ( *hitsCollection )[pointer]->SetPos( hitPosition );
242 ( *hitsCollection )[pointer]->SetGlobalT( globalT );
243 ( *hitsCollection )[pointer]->SetTheta( theta );
244 ( *hitsCollection )[pointer]->SetPosFlag( posFlag );
245 ( *hitsCollection )[pointer]->SetEnterAngle( enterAngle );
246 }
247
248 delete newHit;
249 }
250
251 // for mc truth
252 if ( truthCollection )
253 {
254 if ( g4TrackID == trackID )
255 { // This track is the primary track & will appear in MC truth
256 G4int pointer = truthPointer[layerId][cellId];
257 if ( pointer == -1 )
258 {
259 BesMdcHit* truthHit = new BesMdcHit();
260 truthHit->SetTrackID( truthID );
261 truthHit->SetLayerNo( layerId );
262 truthHit->SetCellNo( cellId );
263 truthHit->SetEdep( edep );
264 truthHit->SetPos( hitPosition );
265 truthHit->SetDriftD( driftD );
266 truthHit->SetDriftT( driftT );
267 truthHit->SetGlobalT( globalT );
268 truthHit->SetTheta( theta );
269 truthHit->SetPosFlag( posFlag );
270 truthHit->SetEnterAngle( enterAngle );
271
272 truthCollection->insert( truthHit );
273 G4int NbHits = truthCollection->entries();
274 truthPointer[layerId][cellId] = NbHits - 1;
275 }
276 else
277 {
278 if ( truthID == ( *truthCollection )[pointer]->GetTrackID() )
279 {
280 G4double preDriftT = ( *truthCollection )[pointer]->GetDriftT();
281 if ( driftT < preDriftT )
282 {
283 ( *truthCollection )[pointer]->SetDriftD( driftD );
284 ( *truthCollection )[pointer]->SetDriftT( driftT );
285 ( *truthCollection )[pointer]->SetPos( hitPosition );
286 ( *truthCollection )[pointer]->SetGlobalT( globalT );
287 ( *truthCollection )[pointer]->SetTheta( theta );
288 ( *truthCollection )[pointer]->SetPosFlag( posFlag );
289 ( *truthCollection )[pointer]->SetEnterAngle( enterAngle );
290 }
291 edepTemp = ( *truthCollection )[pointer]->GetEdep();
292 ( *truthCollection )[pointer]->SetEdep( edepTemp + edep );
293 }
294 else
295 {
296 BesMdcHit* truthHit = new BesMdcHit();
297 truthHit->SetTrackID( truthID );
298 truthHit->SetLayerNo( layerId );
299 truthHit->SetCellNo( cellId );
300 truthHit->SetEdep( edep );
301 truthHit->SetPos( hitPosition );
302 truthHit->SetDriftD( driftD );
303 truthHit->SetDriftT( driftT );
304 truthHit->SetGlobalT( globalT );
305 truthHit->SetTheta( theta );
306 truthHit->SetPosFlag( posFlag );
307 truthHit->SetEnterAngle( enterAngle );
308
309 truthCollection->insert( truthHit );
310 G4int NbHits = truthCollection->entries();
311 truthPointer[layerId][cellId] = NbHits - 1;
312 }
313 }
314 }
315 }
316
317 // newHit->Print();
318 // newHit->Draw();
319
320 return true;
321}
double pi
G4double Distance(G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
Definition BesMdcSD.cc:336
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const

◆ ProcessHits() [2/3]

G4bool BesMdcSD::ProcessHits ( G4Step * ,
G4TouchableHistory *  )

◆ ProcessHits() [3/3]

G4bool BesMdcSD::ProcessHits ( G4Step * ,
G4TouchableHistory *  )

The documentation for this class was generated from the following files: