BOSS 7.0.1
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)
 
- Public Member Functions inherited from BesSensitiveDetector
 BesSensitiveDetector (const G4String name)
 
virtual ~BesSensitiveDetector ()
 
virtual void BeginOfTruthEvent (const G4Event *)
 
virtual void EndOfTruthEvent (const G4Event *)
 
virtual void BeginOfTrack (const G4Track *)
 
virtual void EndOfTrack (const G4Track *)
 
 BesSensitiveDetector (const G4String name)
 
virtual ~BesSensitiveDetector ()
 
virtual void BeginOfTruthEvent (const G4Event *)
 
virtual void EndOfTruthEvent (const G4Event *)
 
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
 

Detailed Description

Constructor & Destructor Documentation

◆ BesMdcSD() [1/2]

BesMdcSD::BesMdcSD ( G4String  name)

Definition at line 29 of file BesMdcSD.cc.

31{
32 collectionName.insert("BesMdcHitsCollection");
33 collectionName.insert("BesMdcTruthCollection");
34
35 mdcGeoPointer=BesMdcGeoParameter::GetGeo();
36 mdcCalPointer=new BesMdcCalTransfer;
37
38 IMdcGeomSvc* ISvc;
39 StatusCode sc=Gaudi::svcLocator()->service("MdcGeomSvc", ISvc);
40 if (!sc.isSuccess())
41 std::cout<<"BesMdcSD::Could not open MdcGeomSvc"<<std::endl;
42 mdcGeomSvc=dynamic_cast<MdcGeomSvc *>(ISvc);
43
44 IG4Svc* tmpSvc;
45 sc=Gaudi::svcLocator()->service("G4Svc", tmpSvc);
46 if (!sc.isSuccess())
47 G4cout <<" MdcSD::Error,could not open G4Svc"<<G4endl;
48 m_G4Svc=dynamic_cast<G4Svc *>(tmpSvc);
49
50 if(m_G4Svc->GetMdcDedxFlag()==1){
51 G4cout <<" MdcSD: Use sampled dedx instead of Geant4 value"<<G4endl;
53 }
54
55 ////dedx sim
56
57 //get DedxSimData
58 std::string dedxTDSPath = "/Calib/DedxSim";
59 IDataProviderSvc* pCalibDataSvc;
60 sc = Gaudi::svcLocator()->service("CalibDataSvc", pCalibDataSvc, true);
61 if (!sc.isSuccess())
62 std::cout << "BesMdcSD::Could not open CalibDataSvc" << std::endl;
63 m_calibDataSvc = dynamic_cast<CalibDataSvc*>(pCalibDataSvc);
64 if (!sc.isSuccess())
65 {
66 std::cout << "Could not get CalibDataSvc"
67 << std::endl;
68 }
69 SmartDataPtr<CalibData::DedxSimData> pDedxSimData(m_calibDataSvc, dedxTDSPath);
70 m_version = pDedxSimData->getVersion();
71 m_numDedxHists = pDedxSimData->gethistNo();
72 m_numBg = pDedxSimData->getRangeNo();
73 m_dedx_hists = new TH1F[m_numDedxHists];
74 for (G4int i = 0; i < m_numBg; i++)
75 {
76 m_bgRange.push_back(pDedxSimData->getRange(i));
77 }
78 for (G4int i = 0; i < m_numDedxHists; i++)
79 {
80 m_dedx_hists[i] = pDedxSimData->getHist(i);
81 }
82
83 //get CalibCurSvc
84 IDedxCurSvc* tmp_dedxCurSvc;
85 sc = Gaudi::svcLocator()->service("DedxCurSvc", tmp_dedxCurSvc, true);
86 if (!sc.isSuccess())
87 {
88 std::cout << "Could not get DedxCurSvc"
89 << std::endl;
90 }
91 m_pDedxCurSvc = dynamic_cast<DedxCurSvc*>(tmp_dedxCurSvc);
92
93 if(m_G4Svc->MdcRootFlag())
94 {
95 m_tupleMdc = m_G4Svc->GetTupleMdc();
96 sc = m_tupleMdc->addItem("betaGamma",m_betaGamma);
97 sc = m_tupleMdc->addItem("fitval",m_fitval);
98 sc = m_tupleMdc->addItem("dedx",m_dedx);
99 sc = m_tupleMdc->addItem("de",m_de);
100 //sc = m_tupleMdc->addItem("length",m_length);
101 //sc = m_tupleMdc->addItem("random",m_random);
102 sc = m_tupleMdc->addItem("charge", m_charge);
103 sc = m_tupleMdc->addItem("costheta", m_costheta);
104 }
105}
static BesMdcGeoParameter * GetGeo(void)
void dedxFuncInti(void)
Definition: BesMdcSD.cc:434
NTuple::Tuple * GetTupleMdc()

◆ ~BesMdcSD() [1/2]

BesMdcSD::~BesMdcSD ( )

Definition at line 107 of file BesMdcSD.cc.

107 {
108 delete []m_dedx_hists;
109}

◆ BesMdcSD() [2/2]

BesMdcSD::BesMdcSD ( G4String  )

◆ ~BesMdcSD() [2/2]

BesMdcSD::~BesMdcSD ( )

Member Function Documentation

◆ BeginOfTruthEvent() [1/2]

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

Reimplemented from BesSensitiveDetector.

Definition at line 129 of file BesMdcSD.cc.

130{
131 truthCollection = new BesMdcHitsCollection
132 (SensitiveDetectorName,collectionName[1]);
133 // G4cout<<" begin event "<<evt->GetEventID()<<G4endl;
134}
G4THitsCollection< BesMdcHit > BesMdcHitsCollection

◆ BeginOfTruthEvent() [2/2]

void BesMdcSD::BeginOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

◆ dedxFuncInti() [1/2]

void BesMdcSD::dedxFuncInti ( void  )

Definition at line 434 of file BesMdcSD.cc.

435{
436 dEdE_mylanfunc = new TF1("dEdE_mylanfunc",
437 "[3]*TMath::Exp([2]*((x[0]-[0])/[1]+TMath::Exp(-1*((x[0]-[0])/[1]))))",
438 0,
439 7500);
440 //dEdE_mylanfunc->SetParameters(2009.35,559.776,-1.0932,6327.38);
441 dEdE_mylanfunc->SetParNames("MPV","Sigma","constant1","constant2");
442}

Referenced by BesMdcSD().

◆ dedxFuncInti() [2/2]

void BesMdcSD::dedxFuncInti ( void  )

◆ Distance() [1/2]

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

Definition at line 373 of file BesMdcSD.cc.

374{
375 //For two lines r=r1+t1.v1 & r=r2+t2.v2
376 //the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
377 //the point where closest approach are
378 //t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
379 //t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
380 //if v1 x v2=0 means two lines are parallel
381 //d=|(r2-r1) x v1|/|v1|
382
383 G4double t1,distance,dInOut,dHitIn,dHitOut;
384 //Get wirepoint @ endplate
385 G4ThreeVector east=mdcGeomSvc->Wire(layerId,cellId)->Backward();
386 G4ThreeVector west=mdcGeomSvc->Wire(layerId,cellId)->Forward();
387 G4ThreeVector wireLine=east-west;
388 G4ThreeVector hitLine=pointOut-pointIn;
389
390 G4ThreeVector hitXwire=hitLine.cross(wireLine);
391 G4ThreeVector wire2hit=east-pointOut;
392 //Hitposition is the position on hit line where closest approach
393 //of two lines, but it may out the area from pointIn to pointOut
394 if(hitXwire.mag()==0){
395 distance=wireLine.cross(wire2hit).mag()/wireLine.mag();
396 hitPosition=pointIn;
397 }else{
398 t1=hitXwire.dot(wire2hit.cross(wireLine))/hitXwire.mag2();
399 hitPosition=pointOut+t1*hitLine;
400
401 dInOut=(pointOut-pointIn).mag();
402 dHitIn=(hitPosition-pointIn).mag();
403 dHitOut=(hitPosition-pointOut).mag();
404 if(dHitIn<=dInOut && dHitOut<=dInOut){ //Between point in & out
405 distance=fabs(wire2hit.dot(hitXwire)/hitXwire.mag());
406 }else if(dHitOut>dHitIn){ // out pointIn
407 distance=wireLine.cross(pointIn-east).mag()/wireLine.mag();
408 hitPosition=pointIn;
409 }else{ // out pointOut
410 distance=wireLine.cross(pointOut-east).mag()/wireLine.mag();
411 hitPosition=pointOut;
412 }
413 }
414
415 //Calculate signal transferT on wire
416 G4double halfLayerLength=mdcGeomSvc->Layer(layerId)->Length()/2.;
417 G4double halfWireLength=wireLine.mag()/2.;
418 G4double transferZ=0;
419 if(layerId%2==0){
420 transferZ=halfLayerLength+hitPosition.z(); //West readout
421 }else{
422 transferZ=halfLayerLength-hitPosition.z(); //East readout
423 }
424 if(layerId<8){
425 transferT=transferZ*halfWireLength/halfLayerLength/220;
426 }else{
427 transferT=transferZ*halfWireLength/halfLayerLength/240;
428 }
429
430 return distance;
431
432}
const MdcGeoWire *const Wire(unsigned id)
Definition: MdcGeomSvc.cxx:768
const MdcGeoLayer *const Layer(unsigned id)
Definition: MdcGeomSvc.cxx:784

Referenced by ProcessHits().

◆ Distance() [2/2]

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

◆ EndOfEvent() [1/2]

void BesMdcSD::EndOfEvent ( G4HCofThisEvent *  )

Definition at line 360 of file BesMdcSD.cc.

361{
362 if (verboseLevel>0) {
363 hitsCollection->PrintAllHits();
364 /*
365 G4int NbHits = hitsCollection->entries();
366 G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
367 << " hits in the MDC chambers: " << G4endl;
368 for (G4int i=0;i<NbHits;i++) (*hitsCollection)[i]->Print();
369 */
370 }
371}

◆ EndOfEvent() [2/2]

void BesMdcSD::EndOfEvent ( G4HCofThisEvent *  )

◆ EndOfTruthEvent() [1/2]

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

Reimplemented from BesSensitiveDetector.

Definition at line 136 of file BesMdcSD.cc.

137{ static G4int HLID=-1;
138 if(HLID<0)
139 {
140 HLID = G4SDManager::GetSDMpointer()->
141 GetCollectionID(collectionName[1]);
142 }
143 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
144 HCE->AddHitsCollection(HLID,truthCollection);
145}

◆ EndOfTruthEvent() [2/2]

void BesMdcSD::EndOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

◆ Initialize() [1/2]

void BesMdcSD::Initialize ( G4HCofThisEvent *  HCE)

Definition at line 111 of file BesMdcSD.cc.

112{
113 hitsCollection = new BesMdcHitsCollection
114 (SensitiveDetectorName,collectionName[0]);
115 static G4int HCID = -1;
116 if(HCID<0)
117 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
118 HCE->AddHitsCollection( HCID, hitsCollection );
119 G4int i,j;
120 for(i=0; i<43;i++){
121 for(j=0;j<288;j++){
122 hitPointer[i][j]=-1;
123 truthPointer[i][j]=-1;
124 }
125 }
126}

◆ Initialize() [2/2]

void BesMdcSD::Initialize ( G4HCofThisEvent *  )

◆ ProcessHits() [1/2]

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

Definition at line 147 of file BesMdcSD.cc.

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

◆ ProcessHits() [2/2]

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

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