00001 #include <mcRootData/McPositionHit.h>
00002 #include <commonRootData/RootDataUtil.h>
00003 #include "Riostream.h"
00004
00005 #include "McObjectManager.h"
00006
00007 ClassImp(McPositionHit)
00008
00009 McPositionHit::McPositionHit() :
00010 m_depositedEnergy(0.), m_timeOfFlight(0.),
00011 m_statusFlags(0), m_particleFourMomentum(0.,0.,0.,0.)
00012 {
00013 }
00014
00015 McPositionHit::~McPositionHit()
00016 {
00017 Clear();
00018 }
00019
00020 void McPositionHit::Clear(Option_t *)
00021 {
00022 m_depositedEnergy = 0.;
00023 m_particleFourMomentum = TLorentzVector(0.,0.,0.,0.);
00024 m_timeOfFlight = 0.;
00025 m_statusFlags = 0;
00026 m_entry = TVector3(0., 0., 0.);
00027 m_exit = TVector3(0., 0., 0.);
00028 m_globalEntry = TVector3(0., 0., 0.);
00029 m_globalExit = TVector3(0., 0., 0.);
00030 m_volumeId.Clear();
00031 }
00032
00033 void* McPositionHit::operator new(size_t size)
00034 {
00035 McPositionHit* temp = McObjectManager::getPointer()->getNewMcPositionHit();
00036
00037 return temp;
00038 }
00039
00040 void* McPositionHit::operator new(size_t size, void* vp)
00041 {
00042 return vp;
00043 }
00044
00045 McPositionHit& McPositionHit::operator =(const McPositionHit& rhs)
00046 {
00047 m_depositedEnergy = rhs.m_depositedEnergy;
00048 m_particleEnergy = rhs.m_particleEnergy;
00049 m_timeOfFlight = rhs.m_timeOfFlight;
00050 m_statusFlags = rhs.m_statusFlags;
00051 m_mcParticleId = rhs.m_mcParticleId;
00052 m_originMcParticleId = rhs.m_originMcParticleId;
00053 m_entry = rhs.m_entry;
00054 m_exit = rhs.m_exit;
00055 m_globalEntry = rhs.m_globalEntry;
00056 m_globalExit = rhs.m_globalExit;
00057 m_mcParticle = rhs.m_mcParticle;
00058 m_originMcParticle = rhs.m_originMcParticle;
00059 m_volumeId = rhs.m_volumeId;
00060 m_particleFourMomentum = rhs.m_particleFourMomentum;
00061
00062 return *this;
00063 }
00064
00065
00066 void McPositionHit::Fake( Int_t , UInt_t rank, Float_t randNum ) {
00067
00068 Clear() ;
00069
00070 Float_t f = Float_t(rank);
00071 Float_t fr = f*randNum;
00072 TVector3 entry(1., 1., 1.);
00073 TVector3 exit(fr, fr, fr);
00074 TVector3 gEntry(3., 3., 3.);
00075 TVector3 gExit(fr*2., fr*2., fr*2.);
00076
00077 VolumeIdentifier id ;
00078 id.append(1) ;
00079
00080 Double_t depE = randNum;
00081 Double_t partE = randNum*0.1 ;
00082 TVector3 partMom = entry-exit ;
00083 TLorentzVector part4Mom(partMom,partE) ;
00084 Double_t tof = randNum*0.4 ;
00085 UInt_t flags = 0 ;
00086 McParticle * mcPart = 0 ;
00087 McParticle * originMcPart = 0 ;
00088 Int_t particleId = 7 ;
00089 Int_t originId = -13 ;
00090
00091 initialize(particleId,originId,depE,id,
00092 entry,exit,gEntry,gExit,
00093 mcPart,originMcPart,part4Mom,tof,flags) ;
00094
00095 }
00096
00097 #define COMPARE_IN_RANGE(att) rootdatautil::CompareInRange(get ## att(),ref.get ## att(),#att)
00098
00099 Bool_t McPositionHit::CompareInRange( const McPositionHit & ref, const std::string & name ) const {
00100
00101 Bool_t result = true ;
00102
00103
00104 result = COMPARE_IN_RANGE(McParticleId) && result ;
00105 result = COMPARE_IN_RANGE(OriginMcParticleId) && result ;
00106
00107 result = COMPARE_IN_RANGE(VolumeId) && result ;
00108
00109
00110 result = rootdatautil::CompareInRange(getVolumeId().name(),ref.getVolumeId().name(),"VolumeId Name") && result ;
00111
00112 result = COMPARE_IN_RANGE(EntryPosition) && result ;
00113 result = COMPARE_IN_RANGE(ExitPosition) && result ;
00114 result = COMPARE_IN_RANGE(GlobalEntryPosition) && result ;
00115 result = COMPARE_IN_RANGE(GlobalExitPosition) && result ;
00116
00117 result = COMPARE_IN_RANGE(DepositedEnergy) && result ;
00118 result = COMPARE_IN_RANGE(ParticleEnergy) && result ;
00119 result = COMPARE_IN_RANGE(TimeOfFlight) && result ;
00120
00121 if (!result) {
00122 if ( name == "" ) {
00123 std::cout<<"Comparison ERROR for "<<ClassName()<<std::endl ;
00124 }
00125 else {
00126 std::cout<<"Comparison ERROR for "<<name<<std::endl ;
00127 }
00128 }
00129 return result ;
00130
00131 }
00132
00133 void McPositionHit::Print(Option_t *option) const {
00134 using namespace std;
00135 TObject::Print(option);
00136 m_volumeId.Print(option);
00137 std::cout.precision(2);
00138 std::cout << "Flags: " << m_statusFlags
00139 << " Dep Energy: " << m_depositedEnergy
00140 << " Part Energy: " << m_particleFourMomentum.E()
00141 << " TOF: " << m_timeOfFlight << std::endl;
00142 std::cout << "Local Entry: (" << m_entry.X() << ","
00143 << m_entry.Y() << "," << m_entry.Z() << ")"
00144 << " Local Exit: (" << m_exit.X() << ","
00145 << m_exit.Y() << "," << m_exit.Z() << ") Direction Cosine: "
00146 << getDirectionCosine() << std::endl;
00147 std::cout << "Global Entry: (" << m_globalEntry.X() << ","
00148 << m_globalEntry.Y() << "," << m_globalEntry.Z() << ")"
00149 << " Global Entry: (" << m_globalExit.X() << ","
00150 << m_globalExit.Y() << "," << m_globalExit.Z() << ")" << std::endl;
00151 std::cout << "McParticleId " << m_mcParticleId << std::endl;
00152 if (getMcParticle() != 0) {
00153 cout << "McParticle Ref" << std::endl;
00154 getMcParticle()->Print();
00155 }
00156 std::cout << "Origin ParticleId " << m_originMcParticleId << endl;
00157 if (getOriginMcParticle() != 0) {
00158 cout << "Origin Particle Ref" << std::endl;
00159 getOriginMcParticle()->Print();
00160 }
00161
00162 }
00163
00164 Double_t McPositionHit::getDirectionCosine() const
00165 {
00166 TVector3 dir = (m_exit - m_entry).Unit();
00167 return dir.Z();
00168 }
00169
00170
00171 void McPositionHit::initialize(Int_t particleId, Double_t edep,
00172 const VolumeIdentifier &volId,
00173 const TVector3& entry, const TVector3& exit,
00174 McParticle *mc, McParticle *origin,
00175 const TLorentzVector& p4Mom,
00176 Double_t tof, UInt_t flags)
00177 {
00178 m_mcParticleId = particleId;
00179 m_depositedEnergy = edep;
00180 m_volumeId = volId;
00181 m_entry = entry;
00182 m_exit = exit;
00183 m_mcParticle = mc;
00184 m_originMcParticle = origin;
00185 m_particleFourMomentum = p4Mom;
00186 m_timeOfFlight = tof;
00187 m_statusFlags = flags;
00188 }
00189
00190 void McPositionHit::initialize(Int_t mcParticleId, Int_t originParticleId,
00191 Double_t edep, const VolumeIdentifier& volId,
00192 const TVector3& entry, const TVector3& exit,
00193 const TVector3& gEntry, const TVector3& gExit,
00194 McParticle *mc, McParticle *origin, const TLorentzVector& p4Mom,
00195 Double_t tof, UInt_t flags)
00196 {
00197 m_mcParticleId = mcParticleId;
00198 m_originMcParticleId = originParticleId;
00199 m_depositedEnergy = edep;
00200 m_volumeId = volId;
00201 m_entry = entry;
00202 m_exit = exit;
00203 m_globalEntry = gEntry;
00204 m_globalExit = gExit;
00205 m_mcParticle = mc;
00206 m_originMcParticle = origin;
00207 m_particleFourMomentum = p4Mom;
00208 m_timeOfFlight = tof;
00209 m_statusFlags = flags;
00210 }
00211
00212
00213 Bool_t McPositionHit::needDigi() const
00214 {
00215 return m_statusFlags & McParticle::NEED_DIGI;
00216 }