10#include "G4DigiManager.hh"
23#include "GaudiKernel/IDataProviderSvc.h"
24#include "GaudiKernel/ISvcLocator.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/RegistryEntry.h"
27#include "GaudiKernel/MsgStream.h"
28#include "CLHEP/Vector/LorentzVector.h"
29#include "CLHEP/Geometry/Point3D.h"
49#include "GaudiKernel/SmartDataPtr.h"
54 m_DigiMan = G4DigiManager::GetDMpointer();
65 ISvcLocator* svcLocator = Gaudi::svcLocator();
66 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
68 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
71 m_evtSvc->findObject(
"/Event/MC",aMcEvent);
74 sc = m_evtSvc->registerObject(
"/Event/MC",aMcEvent);
75 if(sc!=StatusCode::SUCCESS)
76 G4cout<<
"Could not register McEvent" <<G4endl;
90 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
91 G4int nTrack = trackList->size();
94 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
95 G4int nVertex = vertexList->size();
99 for(
int i=0;i<nTrack-1;i++)
100 for(
int j=i+1;j<nTrack;j++)
101 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
103 track=(*trackList)[i];
104 (*trackList)[i]=(*trackList)[j];
105 (*trackList)[j]=track;
111 for(
int i=0;i<nTrack;i++)
113 track = (*trackList) [i];
116 bool isPrimary =
false;
117 bool startPointFound =
false;
120 for (
int i=0;i<nVertex;i++)
122 vertex = (*vertexList) [i];
126 startPointFound =
true;
132 if (!startPointFound)
133 std::cout <<
"error in finding the start point of a track" <<std::endl;
136 bool endPointFound =
false;
138 for (
int i=0;i<nVertex;i++)
140 vertex = (*vertexList) [i];
149 HepLorentzVector initialMomentum(track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
183 mcParticle->
finalize(finalPosition);
186 particleCol->push_back(mcParticle);
188 endPointFound =
true;
201 HepLorentzVector initialMomentum( track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
232 particleCol->push_back(mcParticle);
239 SmartRefVector<Event::McParticle> primaryParticleCol;
240 Event::McParticleCol::iterator iter_particle;
241 for ( iter_particle = particleCol->begin();
242 iter_particle != particleCol->end(); iter_particle++) {
244 if ((*iter_particle)->primaryParticle()) {
246 primaryParticleCol.push_back(mcPart);
250 if (primaryParticleCol.empty())
251 std::cout <<
"no primary particle found!" << std::endl;
254 SmartRefVector<Event::McParticle>::iterator iter_primary;
255 for ( iter_primary = primaryParticleCol.begin();
256 iter_primary != primaryParticleCol.end(); iter_primary++) {
257 if ( !((*iter_primary)->leafParticle()) )
262 StatusCode sc = m_evtSvc->registerObject(
"/Event/MC/McParticleCol", particleCol);
263 if(sc!=StatusCode::SUCCESS)
264 G4cout<<
"Could not register McParticle collection" <<G4endl;
296 Event::McParticleCol::iterator
iter;
298 for (
iter = particleCol->begin();
iter != particleCol->end();
iter++) {
299 if (currentParticle->
vertexIndex1() == (*iter)->vertexIndex0()) {
301 (*iter)->setMother(currentParticle);
306 if (!found) std::cout <<
"AddMother: inconsistency was found!" << std::endl;
312 SmartDataPtr<DecayMode> decayMode(m_evtSvc,
"/Event/MC/DecayMode");
318 int dm[10]={0,0,0,0,0,0,0,0,0,0};
320 StatusCode scDM = m_evtSvc->registerObject(
"/Event/MC/DecayMode", aDecayMode);
321 if(scDM!=StatusCode::SUCCESS)
322 G4cout<<
"Could not register DecayMode" <<G4endl;
332 HCID = m_DigiMan->GetHitsCollectionID(
"BesMdcTruthCollection");
337 G4int n_hit = HC->entries();
342 vector<BesMdcHit*>* vecHC = HC->GetVector();
343 for(
int i=0;i<n_hit-1;i++)
344 for(
int j=i+1;j<n_hit;j++)
345 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
348 (*vecHC)[i] = (*vecHC)[j];
353 for(G4int i=0;i<n_hit;i++)
360 aMdcMcHitCol->push_back(mdcMcHit);
367 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/MC/MdcMcHitCol", aMdcMcHitCol);
368 if(scMdc!=StatusCode::SUCCESS)
369 G4cout<<
"Could not register MDC McTruth collection" <<G4endl;
400 HCID = m_DigiMan->GetHitsCollectionID(
"BesTofHitsList");
405 G4int n_hit = HC->entries();
410 vector<BesTofHit*>* vecHC = HC->GetVector();
411 for(
int i=0;i<n_hit-1;i++)
412 for(
int j=i+1;j<n_hit;j++)
413 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
416 (*vecHC)[i] = (*vecHC)[j];
421 for(G4int i=0;i<n_hit;i++)
424 unsigned int scinNum, barrel_ec, layer = 0;
441 if(barrel_ec==0 || barrel_ec==1 || barrel_ec==2 )
460 aTofMcHitCol->push_back(tofMcHit);
466 StatusCode scTof = m_evtSvc->registerObject(
"/Event/MC/TofMcHitCol", aTofMcHitCol);
467 if(scTof!=StatusCode::SUCCESS)
468 G4cout<<
"Could not register TOF McTruth collection" <<G4endl;
505 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcTruthHitsList");
510 G4int n_hit = HC->entries();
515 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
516 for(
int i=0;i<n_hit-1;i++) {
517 for(
int j=i+1;j<n_hit;j++) {
518 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
520 (*vecHC)[i] = (*vecHC)[j];
526 for(G4int i=0;i<n_hit;i++)
531 std::map<Identifier,double> hitMap;
532 std::map<Identifier,double>::const_iterator iHitMap;
534 for(iHitMap=hit->
Begin();iHitMap!=hit->
End();iHitMap++) {
535 hitMap[iHitMap->first]=iHitMap->second;
549 aEmcMcHitCol->push_back(emcMcHit);
555 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcHitsList");
560 G4int n_hit = HC->entries();
565 vector<BesEmcHit*>* vecHC = HC->GetVector();
566 for(
int i=0;i<n_hit-1;i++)
567 for(
int j=i+1;j<n_hit;j++)
568 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
571 (*vecHC)[i] = (*vecHC)[j];
578 for(G4int i=0;i<n_hit;i++)
583 std::map<Identifier,double> hitMap;
589 aEmcMcHitCol->push_back(emcMcHit);
596 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/MC/EmcMcHitCol", aEmcMcHitCol);
597 if(scEmc!=StatusCode::SUCCESS)
598 G4cout<<
"Could not register EMC McTruth collection" <<G4endl;
632 HCID = m_DigiMan->GetHitsCollectionID(
"BesMucHitsList");
637 G4int n_hit = HC->entries();
642 vector<BesMucHit*>* vecHC = HC->GetVector();
643 for(
int i=0;i<n_hit-1;i++)
644 for(
int j=i+1;j<n_hit;j++)
645 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
648 (*vecHC)[i] = (*vecHC)[j];
652 for(G4int i=0;i<n_hit;i++)
660 aMucMcHitCol->push_back(mucMcHit);
667 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/MC/MucMcHitCol", aMucMcHitCol);
668 if(scMuc!=StatusCode::SUCCESS)
669 G4cout<<
"Could not register MUC McTruth collection" <<G4endl;
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
G4ThreeVector GetPosCrystal()
G4double GetEdepCrystal()
G4ThreeVector GetMomentum()
G4int GetNumThetaCrystal()
G4int GetTrackIndex() const
G4ThreeVector GetPosition() const
std::map< Identifier, G4double >::const_iterator End() const
G4double GetPDGCharge() const
std::map< Identifier, G4double >::const_iterator Begin() const
G4ThreeVector GetMomentum() const
Identifier GetIdentify() const
void AddMother(Event::McParticle *, Event::McParticleCol *)
G4ThreeVector GetMomentum()
std::vector< BesTruthVertex * > * GetVertexList()
std::vector< BesTruthTrack * > * GetTrackList()
static BesSensitiveManager * GetSensitiveManager()
static G4int Produce_unique_identifier(G4int module_mrpc_f, G4int readoutstripnumber_f)
static G4int Calculate_Readoutstrip_number_continuum(G4double x_mm, G4double y_mm, G4int partId_f, G4int module_mrpc_f)
G4ThreeVector GetMomentum()
HepLorentzVector GetP4() const
BesTruthVertex * GetTerminalVertex() const
BesTruthVertex * GetVertex() const
vector< int > GetDaughterIndexes() const
BesTruthTrack * GetParentTrack() const
G4ThreeVector GetPosition() const
void putData(int *data, unsigned int size)
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
void setPDGCode(int code)
void setPDGCharge(double charge)
void setTime(double time)
void setHitMap(std::map< Identifier, double > &hitMap)
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
@ PRIMARY
Decayed in flight.
@ ERROR
this particle is a leaf in the particle tree
@ DECAYFLT
Decayed by generator.
void initialize(StdHepId id, unsigned int statusBits, const HepLorentzVector &initialMomentum, const HepLorentzVector &initialPosition, const std::string process="")
Set the initial attributes of the McParticle.
bool leafParticle() const
Retrieve whether this is a leaf particle.
void addStatusFlag(unsigned int flag)
add a new flag to the status flags
void finalize(const HepLorentzVector &finalPosition)
Set the final attributes of the McParticle.
void setVertexIndex1(int index1)
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle
void setTrackIndex(int trackIndex)
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
static value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.
static Identifier cell_id_mrpc_mc(int partID, int scinNum)
ObjectVector< MdcMcHit > MdcMcHitCol
ObjectVector< MucMcHit > MucMcHitCol
ObjectList< McParticle > McParticleCol
ObjectVector< TofMcHit > TofMcHitCol
ObjectVector< EmcMcHit > EmcMcHitCol