10#include "G4DigiManager.hh"
11#include "BesMdcHit.hh"
12#include "BesTofHit.hh"
13#include "BesEmcHit.hh"
14#include "BesMucHit.hh"
15#include "BesTruthTrack.hh"
16#include "BesTruthVertex.hh"
17#include "BesSensitiveManager.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"
31#include "McTruth/DecayMode.h"
32#include "McTruth/MdcMcHit.h"
33#include "McTruth/TofMcHit.h"
34#include "McTruth/EmcMcHit.h"
35#include "McTruth/MucMcHit.h"
37#include "Identifier/Identifier.h"
38#include "Identifier/MdcID.h"
39#include "Identifier/TofID.h"
40#include "Identifier/EmcID.h"
41#include "Identifier/MucID.h"
43#include "McTruth/McEvent.h"
44#include "EventModel/EventModel.h"
46#include "GaudiKernel/SmartDataPtr.h"
47#include "BesMcTruthWriter.hh"
51 m_DigiMan = G4DigiManager::GetDMpointer();
62 ISvcLocator* svcLocator = Gaudi::svcLocator();
63 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
65 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
68 m_evtSvc->findObject(
"/Event/MC",aMcEvent);
71 sc = m_evtSvc->registerObject(
"/Event/MC",aMcEvent);
72 if(sc!=StatusCode::SUCCESS)
73 G4cout<<
"Could not register McEvent" <<G4endl;
87 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
88 G4int nTrack = trackList->size();
91 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
92 G4int nVertex = vertexList->size();
96 for(
int i=0;i<nTrack-1;i++)
97 for(
int j=i+1;j<nTrack;j++)
98 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
100 track=(*trackList)[i];
101 (*trackList)[i]=(*trackList)[j];
102 (*trackList)[j]=track;
108 for(
int i=0;i<nTrack;i++)
110 track = (*trackList) [i];
113 bool isPrimary =
false;
114 bool startPointFound =
false;
117 for (
int i=0;i<nVertex;i++)
119 vertex = (*vertexList) [i];
123 startPointFound =
true;
129 if (!startPointFound)
130 std::cout <<
"error in finding the start point of a track" <<std::endl;
133 bool endPointFound =
false;
135 for (
int i=0;i<nVertex;i++)
137 vertex = (*vertexList) [i];
146 HepLorentzVector initialMomentum(track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
180 mcParticle->
finalize(finalPosition);
183 particleCol->push_back(mcParticle);
185 endPointFound =
true;
198 HepLorentzVector initialMomentum( track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
229 particleCol->push_back(mcParticle);
236 SmartRefVector<Event::McParticle> primaryParticleCol;
237 Event::McParticleCol::iterator iter_particle;
238 for ( iter_particle = particleCol->begin();
239 iter_particle != particleCol->end(); iter_particle++) {
241 if ((*iter_particle)->primaryParticle()) {
243 primaryParticleCol.push_back(mcPart);
247 if (primaryParticleCol.empty())
248 std::cout <<
"no primary particle found!" << std::endl;
251 SmartRefVector<Event::McParticle>::iterator iter_primary;
252 for ( iter_primary = primaryParticleCol.begin();
253 iter_primary != primaryParticleCol.end(); iter_primary++) {
254 if ( !((*iter_primary)->leafParticle()) )
259 StatusCode sc = m_evtSvc->registerObject(
"/Event/MC/McParticleCol", particleCol);
260 if(sc!=StatusCode::SUCCESS)
261 G4cout<<
"Could not register McParticle collection" <<G4endl;
293 Event::McParticleCol::iterator
iter;
295 for (
iter = particleCol->begin();
iter != particleCol->end();
iter++) {
296 if (currentParticle->
vertexIndex1() == (*iter)->vertexIndex0()) {
298 (*iter)->setMother(currentParticle);
303 if (!found) std::cout <<
"AddMother: inconsistency was found!" << std::endl;
309 SmartDataPtr<DecayMode> decayMode(m_evtSvc,
"/Event/MC/DecayMode");
315 int dm[10]={0,0,0,0,0,0,0,0,0,0};
317 StatusCode scDM = m_evtSvc->registerObject(
"/Event/MC/DecayMode", aDecayMode);
318 if(scDM!=StatusCode::SUCCESS)
319 G4cout<<
"Could not register DecayMode" <<G4endl;
329 HCID = m_DigiMan->GetHitsCollectionID(
"BesMdcTruthCollection");
334 G4int n_hit = HC->entries();
339 vector<BesMdcHit*>* vecHC = HC->GetVector();
340 for(
int i=0;i<n_hit-1;i++)
341 for(
int j=i+1;j<n_hit;j++)
342 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
345 (*vecHC)[i] = (*vecHC)[j];
350 for(G4int i=0;i<n_hit;i++)
357 aMdcMcHitCol->push_back(mdcMcHit);
364 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/MC/MdcMcHitCol", aMdcMcHitCol);
365 if(scMdc!=StatusCode::SUCCESS)
366 G4cout<<
"Could not register MDC McTruth collection" <<G4endl;
397 HCID = m_DigiMan->GetHitsCollectionID(
"BesTofHitsList");
402 G4int n_hit = HC->entries();
407 vector<BesTofHit*>* vecHC = HC->GetVector();
408 for(
int i=0; i<n_hit-1; i++ ) {
409 for(
int j=i+1; j<n_hit; j++ ) {
410 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
412 (*vecHC)[i] = (*vecHC)[j];
419 for( G4int i=0; i<n_hit; i++ ) {
422 unsigned int barrel_ec = hit->
GetPartId();
426 unsigned int layer = 0;
435 if( barrel_ec==3 || barrel_ec==4 ) {
436 unsigned int endcap = 0;
438 unsigned int strip = hit->
GetStrip();
445 if( barrel_ec>=0 && barrel_ec<=4 ) {
449 aTofMcHitCol->push_back(tofMcHit);
456 StatusCode scTof = m_evtSvc->registerObject(
"/Event/MC/TofMcHitCol", aTofMcHitCol);
457 if(scTof!=StatusCode::SUCCESS)
458 G4cout<<
"Could not register TOF McTruth collection" <<G4endl;
495 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcTruthHitsList");
500 G4int n_hit = HC->entries();
505 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
506 for(
int i=0;i<n_hit-1;i++) {
507 for(
int j=i+1;j<n_hit;j++) {
508 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
510 (*vecHC)[i] = (*vecHC)[j];
516 for(G4int i=0;i<n_hit;i++)
521 std::map<Identifier,double> hitMap;
522 std::map<Identifier,double>::const_iterator iHitMap;
524 for(iHitMap=hit->
Begin();iHitMap!=hit->
End();iHitMap++) {
525 hitMap[iHitMap->first]=iHitMap->second;
539 aEmcMcHitCol->push_back(emcMcHit);
545 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcHitsList");
550 G4int n_hit = HC->entries();
555 vector<BesEmcHit*>* vecHC = HC->GetVector();
556 for(
int i=0;i<n_hit-1;i++)
557 for(
int j=i+1;j<n_hit;j++)
558 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
561 (*vecHC)[i] = (*vecHC)[j];
568 for(G4int i=0;i<n_hit;i++)
573 std::map<Identifier,double> hitMap;
579 aEmcMcHitCol->push_back(emcMcHit);
586 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/MC/EmcMcHitCol", aEmcMcHitCol);
587 if(scEmc!=StatusCode::SUCCESS)
588 G4cout<<
"Could not register EMC McTruth collection" <<G4endl;
622 HCID = m_DigiMan->GetHitsCollectionID(
"BesMucHitsList");
627 G4int n_hit = HC->entries();
632 vector<BesMucHit*>* vecHC = HC->GetVector();
633 for(
int i=0;i<n_hit-1;i++)
634 for(
int j=i+1;j<n_hit;j++)
635 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
638 (*vecHC)[i] = (*vecHC)[j];
642 for(G4int i=0;i<n_hit;i++)
650 aMucMcHitCol->push_back(mucMcHit);
657 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/MC/MucMcHitCol", aMucMcHitCol);
658 if(scMuc!=StatusCode::SUCCESS)
659 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()
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
@ DECAYFLT
Decayed by generator.
@ PRIMARY
Decayed in flight.
@ ERROR
this particle is a leaf in the particle tree
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 bool is_scin(const Identifier &id)
static value_type getPHI_BARREL_MAX()
static bool is_barrel(const Identifier &id)
Test for barrel.
ObjectVector< MucMcHit > MucMcHitCol
ObjectList< McParticle > McParticleCol
ObjectVector< EmcMcHit > EmcMcHitCol
ObjectVector< TofMcHit > TofMcHitCol
ObjectVector< MdcMcHit > MdcMcHitCol