BOSS 6.6.4.p03
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)
 
- 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 *)
 

Additional Inherited Members

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

Detailed Description

Definition at line 35 of file BesMdcSD.hh.

Constructor & Destructor Documentation

◆ BesMdcSD()

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_numDedxHists = pDedxSimData->gethistNo();
71 m_numBg = pDedxSimData->getRangeNo();
72 m_dedx_hists = new TH1F[m_numDedxHists];
73 for (G4int i = 0; i < m_numBg; i++)
74 {
75 m_bgRange.push_back(pDedxSimData->getRange(i));
76 }
77 for (G4int i = 0; i < m_numDedxHists; i++)
78 {
79 m_dedx_hists[i] = pDedxSimData->getHist(i);
80 }
81
82 //get CalibCurSvc
83 IDedxCurSvc* tmp_dedxCurSvc;
84 sc = Gaudi::svcLocator()->service("DedxCurSvc", tmp_dedxCurSvc, true);
85 if (!sc.isSuccess())
86 {
87 std::cout << "Could not get DedxCurSvc"
88 << std::endl;
89 }
90 m_pDedxCurSvc = dynamic_cast<DedxCurSvc*>(tmp_dedxCurSvc);
91
92 if(m_G4Svc->MdcRootFlag())
93 {
94 m_tupleMdc = m_G4Svc->GetTupleMdc();
95 sc = m_tupleMdc->addItem("betaGamma",m_betaGamma);
96 sc = m_tupleMdc->addItem("fitval",m_fitval);
97 sc = m_tupleMdc->addItem("dedx",m_dedx);
98 sc = m_tupleMdc->addItem("de",m_de);
99 //sc = m_tupleMdc->addItem("length",m_length);
100 //sc = m_tupleMdc->addItem("random",m_random);
101 sc = m_tupleMdc->addItem("charge", m_charge);
102 sc = m_tupleMdc->addItem("costheta", m_costheta);
103 }
104}
static BesMdcGeoParameter * GetGeo(void)
void dedxFuncInti(void)
Definition: BesMdcSD.cc:433
Definition: G4Svc.h:32
bool MdcRootFlag()
Definition: G4Svc.h:117
NTuple::Tuple * GetTupleMdc()
Definition: G4Svc.h:96
int GetMdcDedxFlag()
Definition: G4Svc.h:94
Definition: IG4Svc.h:30

◆ ~BesMdcSD()

BesMdcSD::~BesMdcSD ( )

Definition at line 106 of file BesMdcSD.cc.

106 {
107 delete []m_dedx_hists;
108}

Member Function Documentation

◆ BeginOfTruthEvent()

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

Reimplemented from BesSensitiveDetector.

Definition at line 128 of file BesMdcSD.cc.

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

◆ dedxFuncInti()

void BesMdcSD::dedxFuncInti ( void  )

Definition at line 433 of file BesMdcSD.cc.

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

Referenced by BesMdcSD().

◆ Distance()

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

Definition at line 372 of file BesMdcSD.cc.

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

Referenced by ProcessHits().

◆ EndOfEvent()

void BesMdcSD::EndOfEvent ( G4HCofThisEvent *  )

Definition at line 359 of file BesMdcSD.cc.

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

◆ EndOfTruthEvent()

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

Reimplemented from BesSensitiveDetector.

Definition at line 135 of file BesMdcSD.cc.

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

◆ Initialize()

void BesMdcSD::Initialize ( G4HCofThisEvent *  HCE)

Definition at line 110 of file BesMdcSD.cc.

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

◆ ProcessHits()

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

Definition at line 146 of file BesMdcSD.cc.

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

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