10#include "G4DigiManager.hh"
12#include "BesCgemHit.hh"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/ISvcLocator.h"
26#include "GaudiKernel/Bootstrap.h"
27#include "GaudiKernel/RegistryEntry.h"
28#include "GaudiKernel/MsgStream.h"
29#include "CLHEP/Vector/LorentzVector.h"
30#include "CLHEP/Geometry/Point3D.h"
52#include "GaudiKernel/SmartDataPtr.h"
53#include "GaudiKernel/IJobOptionsSvc.h"
60 m_DigiMan = G4DigiManager::GetDMpointer();
65 ISvcLocator* svcLocator = Gaudi::svcLocator();
66 static IJobOptionsSvc* jobSvc = 0;
67 StatusCode sc = svcLocator->service(
"JobOptionsSvc", jobSvc);
68 if ( sc.isFailure() ) {
69 std::cout <<
"BesMcTruthWriter: Can't get the JobOptionsSvc " << std::endl;
74 const vector<const Property*>* properties = jobSvc->getProperties(
"BesSim");
75 if ( properties != NULL ) {
76 for (
unsigned int i = 0; i < properties->size(); ++i ) {
77 if ( properties->at(i)->name() ==
"CgemMisAligned" ) {
78 string strRnd = properties->at(i)->toString();
79 sscanf(strRnd.c_str(),
"%i", &m_cgem_misAligned);
80 cout<<
"BesMcTruthWriter: cgem_misAligned is set to "<<m_cgem_misAligned<<
" by jobOptions"<<endl;
97 ISvcLocator* svcLocator = Gaudi::svcLocator();
98 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
100 G4cout<<
"Could not accesss EventDataSvc!"<<G4endl;
102 DataObject *aMcEvent;
103 m_evtSvc->findObject(
"/Event/MC",aMcEvent);
106 sc = m_evtSvc->registerObject(
"/Event/MC",aMcEvent);
107 if(sc!=StatusCode::SUCCESS)
108 G4cout<<
"Could not register McEvent" <<G4endl;
123 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
124 G4int nTrack = trackList->size();
127 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
128 G4int nVertex = vertexList->size();
132 for(
int i=0;i<nTrack-1;i++)
133 for(
int j=i+1;j<nTrack;j++)
134 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
136 track=(*trackList)[i];
137 (*trackList)[i]=(*trackList)[j];
138 (*trackList)[j]=track;
144 for(
int i=0;i<nTrack;i++)
146 track = (*trackList) [i];
149 bool isPrimary =
false;
150 bool startPointFound =
false;
153 for (
int i=0;i<nVertex;i++)
155 vertex = (*vertexList) [i];
159 startPointFound =
true;
165 if (!startPointFound)
166 std::cout <<
"error in finding the start point of a track" <<std::endl;
169 bool endPointFound =
false;
171 for (
int i=0;i<nVertex;i++)
173 vertex = (*vertexList) [i];
182 HepLorentzVector initialMomentum(track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
216 mcParticle->
finalize(finalPosition);
219 particleCol->push_back(mcParticle);
221 endPointFound =
true;
234 HepLorentzVector initialMomentum( track->
GetP4().x()/1000., track->
GetP4().y()/1000., track->
GetP4().z()/1000., track->
GetP4().t()/1000.);
265 particleCol->push_back(mcParticle);
272 SmartRefVector<Event::McParticle> primaryParticleCol;
273 Event::McParticleCol::iterator iter_particle;
274 for ( iter_particle = particleCol->begin();
275 iter_particle != particleCol->end(); iter_particle++) {
277 if ((*iter_particle)->primaryParticle()) {
279 primaryParticleCol.push_back(mcPart);
283 if (primaryParticleCol.empty())
284 std::cout <<
"no primary particle found!" << std::endl;
287 SmartRefVector<Event::McParticle>::iterator iter_primary;
288 for ( iter_primary = primaryParticleCol.begin();
289 iter_primary != primaryParticleCol.end(); iter_primary++) {
290 if ( !((*iter_primary)->leafParticle()) )
295 StatusCode sc = m_evtSvc->registerObject(
"/Event/MC/McParticleCol", particleCol);
296 if(sc!=StatusCode::SUCCESS)
297 G4cout<<
"Could not register McParticle collection" <<G4endl;
329 Event::McParticleCol::iterator
iter;
331 for (
iter = particleCol->begin();
iter != particleCol->end();
iter++) {
332 if (currentParticle->
vertexIndex1() == (*iter)->vertexIndex0()) {
334 (*iter)->setMother(currentParticle);
339 if (!found) std::cout <<
"AddMother: inconsistency was found!" << std::endl;
345 SmartDataPtr<DecayMode> decayMode(m_evtSvc,
"/Event/MC/DecayMode");
351 int dm[10]={0,0,0,0,0,0,0,0,0,0};
353 StatusCode scDM = m_evtSvc->registerObject(
"/Event/MC/DecayMode", aDecayMode);
354 if(scDM!=StatusCode::SUCCESS)
355 G4cout<<
"Could not register DecayMode" <<G4endl;
366 HCID = m_DigiMan->GetHitsCollectionID(
"BesMdcHitsCollection");
372 G4int n_hit = HC->entries();
391 for(G4int i=0;i<n_hit;i++)
408 aMdcMcHitCol->push_back(mdcMcHit);
415 StatusCode scMdc = m_evtSvc->registerObject(
"/Event/MC/MdcMcHitCol", aMdcMcHitCol);
416 if(scMdc!=StatusCode::SUCCESS)
417 G4cout<<
"Could not register MDC McTruth collection" <<G4endl;
451 HCID = m_DigiMan->GetHitsCollectionID(
"BesCgemTruthCollection");
452 BESID = m_DigiMan->GetHitsCollectionID(
"BesCgemHitsCollection");
460 G4int n_hit = HC->entries();
461 G4int n_BEShit = BES->entries();
467 vector<BesCgemHit*>* vecHC = HC->GetVector();
468 for(
int i=0; i<n_hit-1; i++)
469 for(
int j=i+1; j<n_hit; j++)
470 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
473 (*vecHC)[i] = (*vecHC)[j];
504 for(G4int i=0;i<n_hit;i++)
529 if(m_cgem_misAligned==1)
543 for(G4int j=0;j<n_BEShit;j++)
549 for(
int ii = 0; ii < hit_ID.GetSize(); ii++){
550 if(hit_ID.GetAt(ii) != BEShit->
GetHitID())
continue;
554 for(
int jj = 0; jj < BES_Ident.GetSize(); jj++){
555 tmp[size] = BES_Ident.GetAt(jj);
563 aCgemMcHitCol->push_back(cgemMcHit);
571 StatusCode scCgem = m_evtSvc->registerObject(
"/Event/MC/CgemMcHitCol", aCgemMcHitCol);
572 if(scCgem!=StatusCode::SUCCESS)
574 G4cout <<
"ERROR : BesSim::BesMcTruthWriter::SaveCgemTruth(), Could not register CGEM McTruth collection!" << G4endl;
608 HCID = m_DigiMan->GetHitsCollectionID(
"BesTofHitsList");
613 G4int n_hit = HC->entries();
618 vector<BesTofHit*>* vecHC = HC->GetVector();
619 for(
int i=0;i<n_hit-1;i++)
620 for(
int j=i+1;j<n_hit;j++)
621 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
624 (*vecHC)[i] = (*vecHC)[j];
629 for(G4int i=0;i<n_hit;i++)
632 unsigned int scinNum, barrel_ec, layer = 0;
649 if(barrel_ec==0 || barrel_ec==1 || barrel_ec==2 )
668 aTofMcHitCol->push_back(tofMcHit);
674 StatusCode scTof = m_evtSvc->registerObject(
"/Event/MC/TofMcHitCol", aTofMcHitCol);
675 if(scTof!=StatusCode::SUCCESS)
676 G4cout<<
"Could not register TOF McTruth collection" <<G4endl;
713 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcTruthHitsList");
718 G4int n_hit = HC->entries();
723 vector<BesEmcTruthHit*>* vecHC = HC->GetVector();
724 for(
int i=0;i<n_hit-1;i++) {
725 for(
int j=i+1;j<n_hit;j++) {
726 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex()) {
728 (*vecHC)[i] = (*vecHC)[j];
734 for(G4int i=0;i<n_hit;i++)
739 std::map<Identifier,double> hitMap;
740 std::map<Identifier,double>::const_iterator iHitMap;
742 for(iHitMap=hit->
Begin();iHitMap!=hit->
End();iHitMap++) {
743 hitMap[iHitMap->first]=iHitMap->second;
757 aEmcMcHitCol->push_back(emcMcHit);
763 HCID = m_DigiMan->GetHitsCollectionID(
"BesEmcHitsList");
768 G4int n_hit = HC->entries();
773 vector<BesEmcHit*>* vecHC = HC->GetVector();
774 for(
int i=0;i<n_hit-1;i++)
775 for(
int j=i+1;j<n_hit;j++)
776 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
779 (*vecHC)[i] = (*vecHC)[j];
786 for(G4int i=0;i<n_hit;i++)
791 std::map<Identifier,double> hitMap;
797 aEmcMcHitCol->push_back(emcMcHit);
804 StatusCode scEmc = m_evtSvc->registerObject(
"/Event/MC/EmcMcHitCol", aEmcMcHitCol);
805 if(scEmc!=StatusCode::SUCCESS)
806 G4cout<<
"Could not register EMC McTruth collection" <<G4endl;
840 HCID = m_DigiMan->GetHitsCollectionID(
"BesMucHitsList");
845 G4int n_hit = HC->entries();
850 vector<BesMucHit*>* vecHC = HC->GetVector();
851 for(
int i=0;i<n_hit-1;i++)
852 for(
int j=i+1;j<n_hit;j++)
853 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
856 (*vecHC)[i] = (*vecHC)[j];
860 for(G4int i=0;i<n_hit;i++)
868 aMucMcHitCol->push_back(mucMcHit);
875 StatusCode scMuc = m_evtSvc->registerObject(
"/Event/MC/MucMcHitCol", aMucMcHitCol);
876 if(scMuc!=StatusCode::SUCCESS)
877 G4cout<<
"Could not register MUC McTruth collection" <<G4endl;
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
G4THitsCollection< BesCgemHit > BesCgemHitsCollection
G4ThreeVector GetPositionOfPrePoint() const
G4ThreeVector GetMomentumOfPostPoint() const
TArrayI GetIdentifier() const
G4ThreeVector GetPositionOfPostPointAlign() const
G4ThreeVector GetPositionOfPrePointAlign() const
G4int GetIsSecondary() const
G4ThreeVector GetPositionOfPostPoint() const
G4double GetTotalEnergyDeposit() const
G4ThreeVector GetMomentumOfPrePoint() const
G4String GetCreatorProcess() const
G4int GetParentID() const
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 *)
G4String GetCreatorProcess()
G4ThreeVector GetMomentum()
G4double GetFlightLength()
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 AddIdentifier(Int_t f_ID_Identifier[2000], Int_t N_dim)
void SetPositionXOfPrePoint(double f_XYZ_pre_x)
void SetPositionZOfPrePoint(double f_XYZ_pre_z)
void SetIsSecondary(int isSec)
void SetPositionXOfPostPoint(double f_XYZ_post_x)
void SetPositionYOfPrePoint(double f_XYZ_pre_y)
void SetCreatorProcess(string creatorProcess)
void SetPositionYOfPostPoint(double f_XYZ_post_y)
void SetPositionZOfPostPoint(double f_XYZ_post_z)
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.
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)
bool leafParticle() const
Retrieve whether this is a leaf particle.
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle
void setTrackIndex(int trackIndex)
void setMomentumZ(double momentumZ)
void setCreatorProcess(string creatorProcess)
void setMomentumY(double momentumY)
void setFlightLength(double flightLength)
void setMomentumX(double momentumX)
void setIsSecondary(int isSec)
void setCurrentTrackPID(int currentTrackPID)
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< CgemMcHit > CgemMcHitCol
ObjectVector< MucMcHit > MucMcHitCol
ObjectList< McParticle > McParticleCol
ObjectVector< TofMcHit > TofMcHitCol
ObjectVector< EmcMcHit > EmcMcHitCol