CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMdcSD.cc
Go to the documentation of this file.
1//#include "DedxPar.hh"
2#include "BesMdcSD.hh"
3#include "G4HCofThisEvent.hh"
4#include "G4Step.hh"
5#include "G4ThreeVector.hh"
6#include "G4SDManager.hh"
7#include "G4UnitsTable.hh"
8#include "G4ios.hh"
9#include "G4RunManager.hh"
10#include "ReadBoostRoot.hh"
11#include "G4Svc/IG4Svc.h"
12#include "G4Svc/G4Svc.h"
16#include "GaudiKernel/DataSvc.h"
17#include "TFile.h"
18#include "TH1F.h"
19#include "TH2D.h"
20
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IService.h"
23#include "GaudiKernel/Service.h"
24#include "GaudiKernel/SmartDataPtr.h"
25
26#include <iostream>
27
28
29BesMdcSD::BesMdcSD(G4String name)
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}
105
107 delete []m_dedx_hists;
108}
109
110void BesMdcSD::Initialize(G4HCofThisEvent* HCE)
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}
126
127//for MC Truth
128void BesMdcSD::BeginOfTruthEvent(const G4Event* evt)
129{
130 truthCollection = new BesMdcHitsCollection
131 (SensitiveDetectorName,collectionName[1]);
132 // G4cout<<" begin event "<<evt->GetEventID()<<G4endl;
133}
134
135void BesMdcSD::EndOfTruthEvent(const G4Event* evt)
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}
145
146G4bool BesMdcSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
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 // --- get more information (11 Jan, 2021, llwang)
237 G4int pdg_code = gTrack->GetDefinition()->GetPDGEncoding();
238 G4String process_name="Generator";
239 if(NULL != gTrack->GetCreatorProcess()) process_name = gTrack->GetCreatorProcess()->GetProcessName();
240 G4double trkLen = gTrack->GetTrackLength();// track length at post point?
241 G4int isSecondary = (trackID==g4TrackID)? 0:1;
242 G4ThreeVector p3_pre = prePoint->GetMomentum();
243 G4ThreeVector p3_post = postPoint->GetMomentum();
244 G4ThreeVector p3_hit = 0.5*(p3_pre+p3_post);
245
246
247 if(m_G4Svc->GetMdcDedxFlag()==1){
248 G4double betaGamma=aStep->GetPreStepPoint()->GetBeta() * aStep->GetPreStepPoint()->GetGamma();
249 if(betaGamma<0.01)return false;//too low momentum
250 //if (betaGamma < 10.0) betaGamma = 10.0;
251
252 G4double eCount=dedxSample(betaGamma, charge, theta);
253 edep=eCount;
254 }
255
256 BesMdcHit* newHit = new BesMdcHit();
257 newHit->SetTrackID(truthID);
258 //newHit->SetTrkID(trackID);
259 newHit->SetLayerNo(layerId);
260 newHit->SetCellNo(cellId);
261 newHit->SetEdep(edep);
262 newHit->SetPos(hitPosition);
263 newHit->SetDriftD(driftD);
264 newHit->SetTheta(theta);
265 newHit->SetPosFlag(posFlag);
266 newHit->SetEnterAngle(enterAngle);
267 newHit->SetMomentum(p3_hit);
268 newHit->SetFlightLength(trkLen);
269 newHit->SetPDGCode(pdg_code);
270 newHit->SetIsSecondary(isSecondary);
271 newHit->SetCreatorProcess(process_name);
272 newHit->SetDigiId(-9999);
273
274 //Transfer hit pointer to BesMdcCalTransfer
275 mdcCalPointer->SetHitPointer(newHit);
276
277 driftT=mdcCalPointer->D2T(driftD);
278 globalT+=transferT;
279 driftT+=globalT;
280
281 newHit->SetDriftT (driftT);
282 newHit->SetGlobalT(globalT);
283
284 if (hitPointer[layerId][cellId] == -1) {
285 hitsCollection->insert(newHit);
286 G4int NbHits = hitsCollection->entries();
287 hitPointer[layerId][cellId]=NbHits-1;
288 }
289 else
290 {
291 G4int pointer=hitPointer[layerId][cellId];
292 if (g4TrackID == trackID) {
293 G4double preDriftT=(*hitsCollection)[pointer]->GetDriftT();
294 }
295
296 G4double preDriftT = (*hitsCollection)[pointer]->GetDriftT();
297 if (driftT < preDriftT) {
298 /*
299 (*hitsCollection)[pointer]->SetTrackID(truthID);
300 //(*hitsCollection)[pointer]->SetTrkID(trackID);
301 (*hitsCollection)[pointer]->SetDriftD(driftD);
302 (*hitsCollection)[pointer]->SetDriftT(driftT);
303 (*hitsCollection)[pointer]->SetPos(hitPosition);
304 (*hitsCollection)[pointer]->SetGlobalT(globalT);
305 (*hitsCollection)[pointer]->SetTheta(theta);
306 (*hitsCollection)[pointer]->SetPosFlag(posFlag);
307 (*hitsCollection)[pointer]->SetEnterAngle(enterAngle);
308 */
309 *((*hitsCollection)[pointer])=*newHit;
310 }
311
312 delete newHit;
313 }
314
315 //for mc truth
316 if(truthCollection){
317 if(g4TrackID==trackID){ //This track is the primary track & will appear in MC truth
318 G4int pointer=truthPointer[layerId][cellId];
319 if(pointer==-1){
320 BesMdcHit* truthHit = new BesMdcHit();
321 truthHit->SetTrackID (truthID);
322 truthHit->SetLayerNo(layerId);
323 truthHit->SetCellNo(cellId);
324 truthHit->SetEdep (edep);
325 truthHit->SetPos (hitPosition);
326 truthHit->SetDriftD (driftD);
327 truthHit->SetDriftT (driftT);
328 truthHit->SetGlobalT(globalT);
329 truthHit->SetTheta(theta);
330 truthHit->SetPosFlag(posFlag);
331 truthHit->SetEnterAngle(enterAngle);
332
333 truthCollection->insert(truthHit);
334 G4int NbHits = truthCollection->entries();
335 truthPointer[layerId][cellId]=NbHits-1;
336 }
337 else {
338 if(truthID == (*truthCollection)[pointer]->GetTrackID()){
339 G4double preDriftT=(*truthCollection)[pointer]->GetDriftT();
340 if(driftT<preDriftT){
341 (*truthCollection)[pointer]->SetDriftD(driftD);
342 (*truthCollection)[pointer]->SetDriftT(driftT);
343 (*truthCollection)[pointer]->SetPos(hitPosition);
344 (*truthCollection)[pointer]->SetGlobalT(globalT);
345 (*truthCollection)[pointer]->SetTheta(theta);
346 (*truthCollection)[pointer]->SetPosFlag(posFlag);
347 (*truthCollection)[pointer]->SetEnterAngle(enterAngle);
348 }
349 edepTemp=(*truthCollection)[pointer]->GetEdep();
350 (*truthCollection)[pointer]->SetEdep(edepTemp+edep);
351 } else {
352 BesMdcHit* truthHit = new BesMdcHit();
353 truthHit->SetTrackID (truthID);
354 truthHit->SetLayerNo(layerId);
355 truthHit->SetCellNo(cellId);
356 truthHit->SetEdep(edep);
357 truthHit->SetPos(hitPosition);
358 truthHit->SetDriftD (driftD);
359 truthHit->SetDriftT (driftT);
360 truthHit->SetGlobalT(globalT);
361 truthHit->SetTheta(theta);
362 truthHit->SetPosFlag(posFlag);
363 truthHit->SetEnterAngle(enterAngle);
364
365 truthCollection->insert(truthHit);
366 G4int NbHits = truthCollection->entries();
367 truthPointer[layerId][cellId]=NbHits-1;
368 }
369 }
370 }
371 }
372
373 //newHit->Print();
374// newHit->Draw();
375
376 return true;
377}
378
379void BesMdcSD::EndOfEvent(G4HCofThisEvent*)
380{
381 if (verboseLevel>0) {
382 hitsCollection->PrintAllHits();
383 /*
384 G4int NbHits = hitsCollection->entries();
385 G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
386 << " hits in the MDC chambers: " << G4endl;
387 for (G4int i=0;i<NbHits;i++) (*hitsCollection)[i]->Print();
388 */
389 }
390}
391
392G4double BesMdcSD::Distance(G4int layerId, G4int cellId, G4ThreeVector pointIn, G4ThreeVector pointOut,G4ThreeVector& hitPosition,G4double& transferT)
393{
394 //For two lines r=r1+t1.v1 & r=r2+t2.v2
395 //the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
396 //the point where closest approach are
397 //t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
398 //t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
399 //if v1 x v2=0 means two lines are parallel
400 //d=|(r2-r1) x v1|/|v1|
401
402 G4double t1,distance,dInOut,dHitIn,dHitOut;
403 //Get wirepoint @ endplate
404 G4ThreeVector east=mdcGeomSvc->Wire(layerId,cellId)->Backward();
405 G4ThreeVector west=mdcGeomSvc->Wire(layerId,cellId)->Forward();
406 G4ThreeVector wireLine=east-west;
407 G4ThreeVector hitLine=pointOut-pointIn;
408
409 G4ThreeVector hitXwire=hitLine.cross(wireLine);
410 G4ThreeVector wire2hit=east-pointOut;
411 //Hitposition is the position on hit line where closest approach
412 //of two lines, but it may out the area from pointIn to pointOut
413 if(hitXwire.mag()==0){
414 distance=wireLine.cross(wire2hit).mag()/wireLine.mag();
415 hitPosition=pointIn;
416 }else{
417 t1=hitXwire.dot(wire2hit.cross(wireLine))/hitXwire.mag2();
418 hitPosition=pointOut+t1*hitLine;
419
420 dInOut=(pointOut-pointIn).mag();
421 dHitIn=(hitPosition-pointIn).mag();
422 dHitOut=(hitPosition-pointOut).mag();
423 if(dHitIn<=dInOut && dHitOut<=dInOut){ //Between point in & out
424 distance=fabs(wire2hit.dot(hitXwire)/hitXwire.mag());
425 }else if(dHitOut>dHitIn){ // out pointIn
426 distance=wireLine.cross(pointIn-east).mag()/wireLine.mag();
427 hitPosition=pointIn;
428 }else{ // out pointOut
429 distance=wireLine.cross(pointOut-east).mag()/wireLine.mag();
430 hitPosition=pointOut;
431 }
432 }
433
434 //Calculate signal transferT on wire
435 G4double halfLayerLength=mdcGeomSvc->Layer(layerId)->Length()/2.;
436 G4double halfWireLength=wireLine.mag()/2.;
437 G4double transferZ=0;
438 if(layerId%2==0){
439 transferZ=halfLayerLength+hitPosition.z(); //West readout
440 }else{
441 transferZ=halfLayerLength-hitPosition.z(); //East readout
442 }
443 if(layerId<8){
444 transferT=transferZ*halfWireLength/halfLayerLength/220;
445 }else{
446 transferT=transferZ*halfWireLength/halfLayerLength/240;
447 }
448
449 return distance;
450
451}
452
454{
455 dEdE_mylanfunc = new TF1("dEdE_mylanfunc",
456 "[3]*TMath::Exp([2]*((x[0]-[0])/[1]+TMath::Exp(-1*((x[0]-[0])/[1]))))",
457 0,
458 7500);
459 //dEdE_mylanfunc->SetParameters(2009.35,559.776,-1.0932,6327.38);
460 dEdE_mylanfunc->SetParNames("MPV","Sigma","constant1","constant2");
461}
462
463G4double BesMdcSD::dedxSample(G4double betagamma, G4double charge, G4double theta)
464{
465 G4double x = betagamma;
466 G4double fitval = GetValDedxCurve(x, charge);
467 if(fitval <= 0)return 0;
468
469 G4double random1, random2, dedx1, dedx2, de;
470 G4double standard1, standard2, beta_temp1, beta_temp2;
471 G4double dedx = -1;
472
473 G4int range_idx, bg_idx, angle_idx, charge_idx, hist_idx;
474 range_idx = GetBetagammaIndex(betagamma);
475 angle_idx = GetAngleIndex(theta);
476 charge_idx = GetChargeIndex(charge);
477
478 if (range_idx == -1)
479 {
480 while (dedx <= 0)
481 {
482 bg_idx = 0;
483 hist_idx = bg_idx * 2 * 10 + angle_idx * 2 + charge_idx;
484 random1 = m_dedx_hists[hist_idx].GetRandom();
485 beta_temp1 = (m_bgRange[0] + m_bgRange[1]) / 2;
486 standard1 = GetValDedxCurve(beta_temp1, charge);
487 dedx = random1 + fitval - standard1;
488 }
489 }
490 else if (range_idx == m_numBg - 1)
491 {
492 while (dedx <= 0)
493 {
494 bg_idx = (G4int)(range_idx / 2);
495 hist_idx = bg_idx * 2 * 10 + angle_idx * 2 + charge_idx;
496 random1 = m_dedx_hists[hist_idx].GetRandom();
497 beta_temp1 = (m_bgRange[m_numBg - 2] +
498 m_bgRange[m_numBg - 1]) / 2;
499 standard1 = GetValDedxCurve(beta_temp1, charge);
500 dedx = random1 + fitval - standard1;
501 }
502 }
503 else
504 {
505 //case 1: Given betagamma fall in one histograph range
506 if (range_idx % 2 == 0)
507 {
508 while (dedx <= 0)
509 {
510 bg_idx = (G4int)(range_idx / 2);
511 hist_idx = bg_idx * 2 * 10 + angle_idx * 2 + charge_idx;
512 random1 = m_dedx_hists[hist_idx].GetRandom();
513 beta_temp1 = (m_bgRange[range_idx] +
514 m_bgRange[range_idx + 1]) / 2;
515 standard1 = GetValDedxCurve(beta_temp1, charge);
516 dedx1 = random1 + fitval - standard1;
517 dedx = dedx1;
518 }
519 }
520 //case 2: Given betagamma fall in interval between
521 // two histographs.
522 else
523 {
524 while (dedx <= 0)
525 {
526 //standard1
527 beta_temp1 = (m_bgRange[range_idx - 1] +
528 m_bgRange[range_idx]) / 2;
529 standard1 = GetValDedxCurve(beta_temp1, charge);
530
531 //stardard2
532 beta_temp2 = (m_bgRange[range_idx + 1] +
533 m_bgRange[range_idx + 2]) / 2;
534 standard2 = GetValDedxCurve(beta_temp2, charge);
535
536 //random1
537 bg_idx = (G4int)(range_idx / 2);
538 hist_idx = bg_idx * 2 * 10 + angle_idx * 2 + charge_idx;
539 random1 = m_dedx_hists[hist_idx].GetRandom();
540
541 //random2
542 bg_idx++;
543 hist_idx = bg_idx * 2 * 10 + angle_idx * 2 + charge_idx;
544 random2 = m_dedx_hists[hist_idx].GetRandom();
545
546 //combine dedx1 and dedx2
547 dedx1 = random1 + fitval - standard1;
548 dedx2 = random2 + fitval - standard2;
549 dedx = (dedx2 * (x - m_bgRange[range_idx]) +
550 dedx1 * (m_bgRange[range_idx + 1] - x)) /
551 (m_bgRange[range_idx + 1] - m_bgRange[range_idx]);
552 }
553 }
554 }
555
556
557 de= dedx;// * y/10./1.5;// stepLength unit is mm in Geant4, cm in Rec.& Cal. software
558 // dedx counts *1.5 in dedx Cal.
559
560 if(m_G4Svc->MdcRootFlag())
561 {
562 m_betaGamma= x;
563 m_fitval= fitval;
564 //m_trackId = trackId;
565 //m_layer = layerId;
566 //m_wire = cellId;
567 //m_random= random;
568 m_dedx= dedx;
569 m_de= de;
570 //m_length=y;
571 m_charge = charge;
572 m_costheta = cos(theta);
573 m_tupleMdc->write();
574 }
575 return de;
576}
577
578/*-----------------------------------------------------
579Func: GetValDedxCurve
580Pre: A betagamma is given.
581Post: Return dE/dx value from betagamma~dE/dx curve.
582-----------------------------------------------------*/
583G4double BesMdcSD::GetValDedxCurve(G4double x, G4double charge)
584{
585 G4int dedxflag = -1;
586 G4int size = -1;
587 G4double A = 0.;
588 G4double B = 0.;
589 G4double C = 0.;
590 std::vector<G4double> par;
591 G4double val;
592 G4int index = -1;
593
594 par.clear();
595 dedxflag = m_pDedxCurSvc->getCurve(0);
596 size = m_pDedxCurSvc->getCurveSize();
597 for (G4int i = 1; i < size; i++) {
598 par.push_back(m_pDedxCurSvc->getCurve(i));
599 }
600
601 if (x < 4.5)
602 A = 1;
603 else if(x < 10)
604 B = 1;
605 else
606 C = 1;
607
608 G4double partA = par[0] * pow(sqrt(x * x + 1), par[2]) / pow(x, par[2]) *
609 (par[1] - par[5] * log(pow(1 / x, par[3]))) -
610 par[4] + exp(par[6] + par[7] * x);
611 G4double partB = par[8] * pow(x, 3) + par[9] * pow(x, 2) + par[10] * x + par[11];
612 G4double partC = - par[12] * log(par[15] + pow(1 / x, par[13])) + par[14];
613
614 val = 550 * (A * partA + B * partB + C * partC);
615 return val;
616
617}
618
619/*-----------------------------------------------------
620Func: GetBetagammaIndex
621Pre : A betagamma of a track is given.
622Post: Return index of the betagamma range.
623-----------------------------------------------------*/
624G4int BesMdcSD::GetBetagammaIndex(G4double bg)
625{
626 if (bg < m_bgRange[0]) return -1;
627 for (G4int i = 0; i < m_numBg - 1; i++)
628 {
629 if (bg > m_bgRange[i] && bg < m_bgRange[i + 1])
630 {
631 return i;
632 }
633 }
634 if (bg > m_bgRange[m_numBg - 1])
635 return (m_numBg - 1);
636}
637
638/*-----------------------------------------------------
639Func: GetAngleIndex
640Pre : A theta of a track is given.
641Post: Return index of the angle (floor(|cos(theta)| * 10)).
642-----------------------------------------------------*/
643G4int BesMdcSD::GetAngleIndex(G4double theta)
644{
645 if (fabs(cos(theta)) >= 0.93) return 9;
646 return (G4int)(fabs(cos(theta)) * 10 / 0.93);
647}
648
649/*-----------------------------------------------------
650Func: GetChargeIndex
651Pre : A charge of a track is given.
652Post: Return index of charge (pos->0 ~ neg->1).
653-----------------------------------------------------*/
654G4int BesMdcSD::GetChargeIndex(G4int charge)
655{
656 if (charge > 0) return 0;
657 if (charge == 0) return -1; // warning: -1 is illegal, for charged tracks are expected.
658 if (charge < 0) return 1;
659}
660
double cos(const BesAngle a)
Definition BesAngle.h:213
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
Definition BesMdcHit.hh:97
Double_t x[10]
EvtComplex exp(const EvtComplex &c)
***************************************************************************************Pseudo Class RRes *****************************************************************************************Parameters and physical constants **Maarten sept ************************************************************************DOUBLE PRECISION xsmu **************************************************************************PARTICLE DATA all others are from PDG *Only resonances with known widths into electron pairs are sept ************************************************************************C Declarations C
Definition RRes.h:29
void bg(int i, double p)
Definition betagamma.cxx:1
double D2T(double driftDNew)
void SetHitPointer(BesMdcHit *hit)
static BesMdcGeoParameter * GetGeo(void)
BesMdcWire SignalWire(int, int)
void SetEdep(G4double de)
Definition BesMdcHit.hh:41
void SetDigiId(G4int id)
Definition BesMdcHit.hh:54
void SetPDGCode(G4int code)
Definition BesMdcHit.hh:51
void SetDriftT(G4double time)
Definition BesMdcHit.hh:44
void SetEnterAngle(G4double angle)
Definition BesMdcHit.hh:47
void SetIsSecondary(G4int isSec)
Definition BesMdcHit.hh:52
void SetCellNo(G4int cell)
Definition BesMdcHit.hh:40
void SetCreatorProcess(G4String proName)
Definition BesMdcHit.hh:53
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 SetMomentum(G4ThreeVector xyz)
Definition BesMdcHit.hh:49
void SetGlobalT(G4double time)
Definition BesMdcHit.hh:45
void SetPosFlag(G4int flag)
Definition BesMdcHit.hh:48
void SetFlightLength(G4double len)
Definition BesMdcHit.hh:50
void dedxFuncInti(void)
Definition BesMdcSD.cc:453
void BeginOfTruthEvent(const G4Event *)
Definition BesMdcSD.cc:128
void EndOfTruthEvent(const G4Event *)
Definition BesMdcSD.cc:135
G4double Distance(G4int, G4int, G4ThreeVector, G4ThreeVector, G4ThreeVector &, G4double &)
Definition BesMdcSD.cc:392
G4bool ProcessHits(G4Step *, G4TouchableHistory *)
Definition BesMdcSD.cc:146
void EndOfEvent(G4HCofThisEvent *)
Definition BesMdcSD.cc:379
BesMdcSD(G4String)
Definition BesMdcSD.cc:29
void Initialize(G4HCofThisEvent *)
Definition BesMdcSD.cc:110
double Phi(void) const
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
Definition G4Svc.h:32
bool MdcRootFlag()
Definition G4Svc.h:125
NTuple::Tuple * GetTupleMdc()
Definition G4Svc.h:97
int GetMdcDedxFlag()
Definition G4Svc.h:94
virtual const int getCurveSize()=0
virtual const double getCurve(int i)=0
const MdcGeoWire *const Wire(unsigned id)
const MdcGeoLayer *const Layer(unsigned id)
static G4int GetMdc()
const float pi
Definition vector3.h:133