Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BesMucSD Class Reference

#include <BesMucSD.hh>

Inheritance diagram for BesMucSD:

BesSensitiveDetector BesSensitiveDetector List of all members.

Public Member Functions

virtual void BeginOfTrack (const G4Track *)
virtual void BeginOfTrack (const G4Track *)
void BeginOfTruthEvent (const G4Event *)
void BeginOfTruthEvent (const G4Event *)
 BesMucSD (G4String, BesMucConstruction *)
 BesMucSD (G4String, BesMucConstruction *)
void EndOfEvent (G4HCofThisEvent *)
void EndOfEvent (G4HCofThisEvent *)
virtual void EndOfTrack (const G4Track *)
virtual void EndOfTrack (const G4Track *)
void EndOfTruthEvent (const G4Event *)
void EndOfTruthEvent (const G4Event *)
void Initialize (G4HCofThisEvent *)
void Initialize (G4HCofThisEvent *)
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
 ~BesMucSD ()
 ~BesMucSD ()

Protected Member Functions

void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const

Private Member Functions

G4VTrajectory * GetTrajFromID (G4int id)
G4VTrajectory * GetTrajFromID (G4int id)
bool IsChildOf (G4Track *curTrack, G4int primaryG4TrackID)
bool IsChildOf (G4Track *curTrack, G4int primaryG4TrackID)

Private Attributes

G4double DeltaEnergy
BesMucConstructiondetector
BesMucConstructiondetector
G4int * HitID
G4int * HitID
const G4Event * m_CurEvent
const G4Event * m_CurEvent
BesMucEfficiencym_effi
BesMucEfficiencym_effi
G4Svcm_G4Svc
G4Svcm_G4Svc
BesMucNoisem_noise
BesMucNoisem_noise
int m_noiseMode
G4int m_preGap
G4int m_prePart
G4int m_preSeg
G4int m_preStrip
G4int m_PreviousPrimaryTrackG4Id
G4TrajectoryContainer * m_TrackCon
G4TrajectoryContainer * m_TrackCon
G4int m_trackIndex
vector< G4int > m_trackIndexes
vector< G4int > m_trackIndexes
BesMucHitsCollectionMucHitCollection
BesMucHitsCollectionMucHitCollection
BesMucHitsCollectionMucHitList
BesMucHitsCollectionMucHitList
G4double TotEneDeposit

Constructor & Destructor Documentation

BesMucSD::BesMucSD G4String  ,
BesMucConstruction
 

00041 :BesSensitiveDetector(name),detector(Det)
00042 {
00043   collectionName.insert("BesMucHitsCollection");
00044   collectionName.insert("BesMucHitsList");
00045   HitID = new G4int[500];
00046 
00047   //liangyt 2006.3.1 initialize muc-efficiency;
00048   G4String GeometryPath = ReadBoostRoot::GetBoostRoot(); 
00049   G4String GeometryPath2 = GeometryPath;
00050   if(!GeometryPath){ 
00051     G4Exception("BOOST environment not set!");
00052   }
00053   GeometryPath += "/dat/muc-effi.dat";
00054   GeometryPath2 += "/dat/muc-noise.dat";
00055 
00056   m_effi=BesMucEfficiency::Instance();
00057   //  m_effi->Initialize(GeometryPath);  
00058   
00059   //retrieve G4Svc
00060   ISvcLocator* svcLocator = Gaudi::svcLocator();
00061   IG4Svc* iG4Svc;
00062   StatusCode sc=svcLocator->service("G4Svc", iG4Svc);
00063   m_G4Svc = dynamic_cast<G4Svc *>(iG4Svc);
00064   m_noiseMode = m_G4Svc->MucNoiseMode();  
00065   G4cout << "MucNoiseMode:\t"<<m_noiseMode<<G4endl;
00066   
00067   if( m_noiseMode != 0 ) 
00068   {
00069     m_noise=BesMucNoise::Instance();
00070     G4LogicalVolume* logicalMuc = detector->GetPhysicalMuc()->GetLogicalVolume();
00071     m_noise->Initialize(GeometryPath2,logicalMuc);
00072     //m_noise->Initialize(GeometryPath2,logicalMuc,"ROOT");
00073   }
00074 
00075   m_PreviousPrimaryTrackG4Id = 0;
00076   m_CurEvent = 0;
00077   m_TrackCon = 0;
00078 
00079 }

BesMucSD::~BesMucSD  ) 
 

00081                    { 
00082   delete [] HitID;
00083 }

BesMucSD::BesMucSD G4String  ,
BesMucConstruction
 

BesMucSD::~BesMucSD  ) 
 


Member Function Documentation

virtual void BesSensitiveDetector::BeginOfTrack const G4Track *   )  [inline, virtual, inherited]
 

00072 {;}

virtual void BesSensitiveDetector::BeginOfTrack const G4Track *   )  [inline, virtual, inherited]
 

00072 {;}

void BesMucSD::BeginOfTruthEvent const G4Event *   )  [virtual]
 

Reimplemented from BesSensitiveDetector.

void BesMucSD::BeginOfTruthEvent const G4Event *   )  [virtual]
 

Reimplemented from BesSensitiveDetector.

00094 {
00095   MucHitList = new BesMucHitsCollection(SensitiveDetectorName, collectionName[1]);
00096   m_trackIndex = -99;
00097   m_trackIndexes.clear();
00098   m_prePart  = -99;
00099   m_preSeg   = -99;
00100   m_preGap   = -99;
00101   m_preStrip = -99;
00102   //G4cout<<"---in BesMucSD::BeginOfTruthEvent()---"<<MucHitCollection->entries()<<" "<<MucHitList->entries()<<G4endl;
00103   
00104   //add oise
00105   if(m_noiseMode != 0) m_noise->AddNoise(m_noiseMode, MucHitCollection, MucHitList);  //commen out 2006.10.21
00106 }

void BesMucSD::EndOfEvent G4HCofThisEvent *   ) 
 

void BesMucSD::EndOfEvent G4HCofThisEvent *   ) 
 

00349   {
00350     static G4int HCID=-1;
00351     if(HCID<0)
00352     {HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
00353     HCE->AddHitsCollection(HCID, MucHitCollection);
00354   }

virtual void BesSensitiveDetector::EndOfTrack const G4Track *   )  [inline, virtual, inherited]
 

00074 {;}

virtual void BesSensitiveDetector::EndOfTrack const G4Track *   )  [inline, virtual, inherited]
 

00074 {;}

void BesMucSD::EndOfTruthEvent const G4Event *   )  [virtual]
 

Reimplemented from BesSensitiveDetector.

void BesMucSD::EndOfTruthEvent const G4Event *   )  [virtual]
 

Reimplemented from BesSensitiveDetector.

00109 {
00110   static G4int HLID=-1;
00111   if(HLID<0)
00112     HLID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]);
00113   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
00114   HCE->AddHitsCollection(HLID,MucHitList);
00115 }

void BesSensitiveDetector::GetCurrentTrackIndex G4int &  trackIndex,
G4int &  g4TrackId
const [protected, inherited]
 

void BesSensitiveDetector::GetCurrentTrackIndex G4int &  trackIndex,
G4int &  g4TrackId
const [protected, inherited]
 

00031 {
00032   BesSensitiveManager* manager = BesSensitiveManager::GetSensitiveManager();
00033   if(manager)
00034   {
00035     trackIndex = manager->GetCurrentTrackIndex();
00036     std::vector<BesTruthTrack*>* trackList = manager->GetTrackList();
00037     if(trackList)
00038     {
00039       G4int size = trackList->size();
00040       if(size>0)
00041       {
00042         for(G4int i=0;i<size;i++)
00043         {
00044           if( (*trackList)[i]->GetIndex() == trackIndex )
00045           {
00046             g4TrackId = (*trackList)[i]->GetG4TrackId();
00047             break;
00048           }
00049         }
00050       } 
00051     }
00052   }
00053 }

G4VTrajectory* BesMucSD::GetTrajFromID G4int  id  )  [private]
 

G4VTrajectory * BesMucSD::GetTrajFromID G4int  id  )  [private]
 

00319   {
00320     // TrajContainer does not contain current track
00321     G4cout << "begin of GetTrajFromID, id : " << id << G4endl;
00322 
00323     if (!m_TrackCon) G4cout << "Trajectory not saved? Set /tracking/storeTrajectory 1" << G4endl;
00324 
00325     if (m_TrackCon->size() == 0) {
00326       G4cout << "BesMucSD::GetTrajFromID, TrackCon size 0" << G4endl;
00327       return 0;
00328     }
00329 
00330     int k = 0;
00331     while( k < (int)m_TrackCon->size() && (*m_TrackCon)[k]->GetTrackID() != id ) {
00332       G4cout << "GetTrajFromID " << k << " : ID " << (*m_TrackCon)[k]->GetTrackID() << G4endl;
00333       k++;
00334       if (!(*m_TrackCon)[k]) {
00335         G4cout << "G4Track ID " << (*m_TrackCon)[k]->GetTrackID() << " doesnt exist in TrajContainer of this event! " << G4endl; 
00336         return 0;
00337       }
00338     }
00339 
00340     if ( k == (int)m_TrackCon->size() ) {
00341       G4cout << "BesMucSD::GetTrajFromID, track with ID " << id << " not found" << G4endl;
00342       return 0;
00343     }
00344 
00345     return (*m_TrackCon)[k];
00346   }

void BesMucSD::Initialize G4HCofThisEvent *   ) 
 

void BesMucSD::Initialize G4HCofThisEvent *   ) 
 

00086 {
00087   MucHitCollection = new BesMucHitsCollection(SensitiveDetectorName, collectionName[0]); 
00088   // for (G4int j=0;j<detector->GetBesMucNbOfTraps();j++) {HitID[j] = -1;};  
00089   TotEneDeposit = 0;
00090   // G4cout<<"----------in SD::Init()---  "<<detector->GetPhysicalMuc()->GetLogicalVolume()->GetName()<<G4endl;  
00091 }

bool BesMucSD::IsChildOf G4Track *  curTrack,
G4int  primaryG4TrackID
[private]
 

bool BesMucSD::IsChildOf G4Track *  curTrack,
G4int  primaryG4TrackID
[private]
 

00303   {
00304     G4cout << "IsChildof " << "curTrackID " <<  curTrack->GetTrackID() << G4endl;
00305 
00306     G4VTrajectory* aTraj = GetTrajFromID(curTrack->GetParentID());
00307     G4cout << "IsChildof " << "parentTrackID " <<  aTraj->GetTrackID() << G4endl;
00308 
00309     while ( aTraj->GetTrackID() != 0 && aTraj->GetTrackID() != primaryG4TrackID ) {
00310       //G4cout << "loop: parentID " << aTraj->GetParentID() << G4endl;
00311       aTraj = GetTrajFromID(aTraj->GetParentID());
00312     }
00313 
00314     if (aTraj->GetTrackID() == primaryG4TrackID) return true;
00315     else return false;
00316   }

G4bool BesMucSD::ProcessHits G4Step *  ,
G4TouchableHistory * 
 

G4bool BesMucSD::ProcessHits G4Step *  ,
G4TouchableHistory * 
 

00118 {
00119   G4Track *curTrack = aStep->GetTrack();
00120 
00121   m_CurEvent = G4EventManager::GetEventManager()->GetConstCurrentEvent();
00122   //  if(m_CurEvent->GetEventID()<19565)return true;  // ---del
00123   if (m_CurEvent) {
00124     m_TrackCon = m_CurEvent->GetTrajectoryContainer();
00125 
00126     //  if (!m_TrackCon) G4cout << "m_TrackCon does not exist " << G4endl;
00127     //  else {
00128     //  G4cout << "m_TrackCon size " << m_TrackCon->size() << G4endl;
00129     //  for (int i = 0; i < (int)m_TrackCon->size(); i++) {
00130     //  G4cout << "track " << i << " g4TrackId " << (*m_TrackCon)[i]->GetTrackID() << " parent ID " << (*m_TrackCon)[i]->GetParentID() << G4endl;
00131     //  }
00132     //  }
00133   }
00134 
00135 
00136   if (curTrack->GetDefinition()->GetPDGCharge() == 0.) return false;
00137 
00138   G4double edep = aStep->GetTotalEnergyDeposit();
00139   //if(edep == 0.) return false;
00140 
00141   //TotEneDeposit+=edep;
00142   G4int trackIndex = -99, g4TrackId = -99;
00143   GetCurrentTrackIndex(trackIndex, g4TrackId);
00144 
00145   G4TouchableHistory* theTouchable
00146     = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
00147 
00148   BesMucHit *newHit = new BesMucHit();
00149 
00150   G4int trackID = curTrack->GetTrackID(); //G4 track ID of current track.
00151   G4int parentID = curTrack->GetParentID(); //G4 track ID of parent track.
00152   newHit->SetTrackID(trackID);
00153   newHit->SetTrackIndex(trackIndex); // MC truth track index
00154 
00155   G4int pdg = curTrack->GetDefinition()->GetPDGEncoding();
00156   newHit->SetPDGCode(pdg);
00157 
00158   newHit->SetEdep(edep);
00159 
00160   G4ThreeVector pos = 0.5*( aStep->GetPostStepPoint()->GetPosition()
00161       + aStep->GetPreStepPoint()->GetPosition() );
00162   newHit->SetPos(pos);
00163 
00164   G4ThreeVector posInGas = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
00165   G4int       stackDepth = theTouchable->GetHistory()->GetDepth();
00166   G4ThreeVector posInBox = theTouchable->GetHistory()->GetTransform(stackDepth-1).TransformPoint(pos);
00167   newHit->SetPosLocal(posInBox);
00168 
00169   G4ThreeVector posInGap = theTouchable->GetHistory()->GetTransform(stackDepth-2).TransformPoint(pos);
00170   // cout<<"  pos  "<<pos.x()<<" "<<pos.y()<<"  "<<pos.z()<<"depth= "<<stackDepth<<endl
00171   //       <<" posInBox(3)"<<posInBox.x()<<"  "<<posInBox.y()<<" "<<posInBox.z()<<endl
00172   //       <<" posInGap(2)"<<posInGap.x()<<"  "<<posInGap.y()<<" "<<posInGap.z()<<endl;
00173 
00174   G4double energy = aStep->GetPreStepPoint()->GetKineticEnergy();
00175   newHit->SetEnergy(energy);
00176 
00177   G4ThreeVector dir = aStep->GetPreStepPoint()->GetMomentumDirection();
00178   newHit->SetDir(dir);
00179 
00180   G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
00181   newHit->SetMomentum(momentum);
00182 
00183   G4double GlobalTime = aStep->GetPostStepPoint()->GetGlobalTime();
00184   newHit->SetTime(GlobalTime);
00185 
00186   G4VPhysicalVolume* vl = theTouchable->GetVolume(0);
00187   newHit->SetVolume(vl);
00188 
00189   //G4cout<<"in SD "<<newHit->GetPart()<<" "<<newHit->GetSeg()<<" "<<newHit->GetGap()<<" "<<newHit->GetGasChamber()<<" "<<newHit->GetPanel()<<endl;
00190 
00191   newHit->Draw();
00192   //newHit->Print();
00193   //MucHitCollection->insert(newHit);
00194   m_PreviousPrimaryTrackG4Id = g4TrackId;
00195 
00196   //-----------add by liangyt for efficiency
00197 
00198   //for MC Truth
00199   if (MucHitList) {
00200 
00201     // cout <<"g4TrackId " << g4TrackId << " trackID " << trackID << " parentID " << parentID << "trackIndex " << trackIndex << endl; 
00202     // g4TrackId:  G4 track ID of previous primary track in trackList,
00203     // trackID:    G4 track ID of current track.
00204     // parentID:   G4 track ID of parent track of current track.
00205     // trackIndex: track ID in MC truth
00206 
00207     // no longer necessary to find the track's ancestor primary track,
00208     // it is kept in trackIndex untill next primary track generated. So IsChildof is uncessary
00209     //if ( g4TrackId == trackID ) { //|| IsChildOf(curTrack, g4TrackId) ) {     // This track is the primary track & will appear in MC truth
00210     G4int newTrackFlag = 0;
00211     newHit->SetTrackIndex(trackIndex);
00212     if(m_trackIndex != trackIndex) {
00213       m_trackIndex = trackIndex;
00214       G4int size = m_trackIndexes.size();
00215       newTrackFlag = 1;
00216       if (size > 0) {
00217         for(G4int i=0;i<size;i++)
00218           if(m_trackIndexes[i] == trackIndex ) {
00219             newTrackFlag = 0; 
00220             break;
00221           }
00222       }
00223     }
00224 
00225     if (newTrackFlag) {
00226       m_trackIndexes.push_back(trackIndex);
00227       m_prePart  = -99;
00228       m_preSeg   = -99;
00229       m_preGap   = -99;
00230       m_preStrip = -99;
00231     }
00232     BesMucHit* truHit = new BesMucHit();
00233     *truHit = *newHit;
00234     if (g4TrackId != trackID) {
00235       //        trackIndex += 1000; // a sencondary track
00236       trackIndex += 0; //2006.12.22 do not indicate secondary track now
00237       truHit->SetTrackIndex(trackIndex);
00238     }
00239     //cout << "trackIndex " << trackIndex << endl;
00240 
00241     BesMucDigit aDigit;
00242     aDigit.SetHit(truHit);
00243     G4int curPart, curSeg, curGap, curStrip;
00244     curPart  = aDigit.GetPart();
00245     curSeg   = aDigit.GetSeg();
00246     curGap   = aDigit.GetGap();
00247     curStrip = aDigit.GetNearestStripNo();
00248 
00249     m_effi->CheckCalibSvc();
00250     m_effi->SetHit(truHit);
00251     G4double need_eff = m_effi->GetEfficiency();
00252 
00253     //G4cout<<"in SD effi= "<<need_eff<<endl;
00254     //need_eff = 1.0;  //2006.12.28
00255     if (curPart == m_prePart && curSeg == m_preSeg &&
00256         curGap  == m_preGap && curStrip == m_preStrip) {
00257       //cout<<MucHitList->entries()<<" "<<MucHitCollection->entries()<<" "<<need_eff<<"---if----curPart "<<curPart<<"curSeg "<<curSeg<<"curGap "<<curGap<<"curStrip "<<curStrip<<" momentum "<<momentum.x()<<" "<<momentum.y()<<" "<<momentum.z()<<" "<<endl;
00258       delete truHit;delete newHit;
00259     }
00260     else {
00261       //cout<<MucHitList->entries()<<"----else--Part "<<curPart<<" Seg "<<curSeg<<" Gap "<<curGap<<" Strip "<<curStrip<<endl;
00262       truHit->SetPart(curPart);
00263       truHit->SetSeg(curSeg);
00264       truHit->SetGap(curGap);
00265       truHit->SetStrip(curStrip);
00266 
00267       // if a truHit with the same id(part, seg, gap, strip) and trackIndex(%1000) exist,
00268       // they belong to the same primary track,(maybe one is primary, the other is secondary), dont add.
00269       bool truHitExist = false;
00270       G4int n_hit = MucHitList->entries();
00271       for(G4int iTru=0;iTru<n_hit;iTru++) {
00272         BesMucHit* aTruHit = (*MucHitList)[iTru];
00273         if ( aTruHit->GetTrackIndex()%1000 == truHit->GetTrackIndex()%1000 &&
00274             aTruHit->GetPart()  == truHit->GetPart() &&
00275             aTruHit->GetSeg()   == truHit->GetSeg()  &&
00276             aTruHit->GetGap()   == truHit->GetGap()  &&
00277             aTruHit->GetStrip() == truHit->GetStrip() ) 
00278         {
00279           truHitExist = true;
00280           break;
00281         }
00282       }
00283       G4float random=G4UniformRand();   //*** use other random
00284       // G4float random=(rand()%100000)/100000.0;
00285       // G4cout<<"---in SD---"<<random<<endl;
00286       if (random<=need_eff){ MucHitCollection->insert(newHit);}
00287       else delete newHit;
00288       if (!truHitExist&&random<=need_eff)
00289       { MucHitList->insert(truHit);}
00290       else delete truHit;
00291       m_prePart  = curPart;
00292       m_preSeg   = curSeg;
00293       m_preGap   = curGap;
00294       m_preStrip = curStrip;
00295     }
00296     //}
00297   }
00298 
00299   return true;
00300   }


Member Data Documentation

G4double BesMucSD::DeltaEnergy [private]
 

BesMucConstruction* BesMucSD::detector [private]
 

BesMucConstruction* BesMucSD::detector [private]
 

G4int* BesMucSD::HitID [private]
 

G4int* BesMucSD::HitID [private]
 

const G4Event* BesMucSD::m_CurEvent [private]
 

const G4Event* BesMucSD::m_CurEvent [private]
 

BesMucEfficiency* BesMucSD::m_effi [private]
 

BesMucEfficiency* BesMucSD::m_effi [private]
 

G4Svc* BesMucSD::m_G4Svc [private]
 

G4Svc* BesMucSD::m_G4Svc [private]
 

BesMucNoise* BesMucSD::m_noise [private]
 

BesMucNoise* BesMucSD::m_noise [private]
 

int BesMucSD::m_noiseMode [private]
 

G4int BesMucSD::m_preGap [private]
 

G4int BesMucSD::m_prePart [private]
 

G4int BesMucSD::m_preSeg [private]
 

G4int BesMucSD::m_preStrip [private]
 

G4int BesMucSD::m_PreviousPrimaryTrackG4Id [private]
 

G4TrajectoryContainer* BesMucSD::m_TrackCon [private]
 

G4TrajectoryContainer* BesMucSD::m_TrackCon [private]
 

G4int BesMucSD::m_trackIndex [private]
 

vector<G4int> BesMucSD::m_trackIndexes [private]
 

vector<G4int> BesMucSD::m_trackIndexes [private]
 

BesMucHitsCollection* BesMucSD::MucHitCollection [private]
 

BesMucHitsCollection* BesMucSD::MucHitCollection [private]
 

BesMucHitsCollection* BesMucSD::MucHitList [private]
 

BesMucHitsCollection* BesMucSD::MucHitList [private]
 

G4double BesMucSD::TotEneDeposit [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 15:52:59 2011 for BOSS6.5.5 by  doxygen 1.3.9.1