00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "BDSGlobalConstants.hh"
00011 #include "BDSExecOptions.hh"
00012 #include "BDSSamplerSD.hh"
00013 #include "BDSSamplerHit.hh"
00014 #include "G4VPhysicalVolume.hh"
00015 #include "G4LogicalVolume.hh"
00016 #include "G4Track.hh"
00017 #include "G4Step.hh"
00018 #include "G4StepPoint.hh"
00019 #include "G4ParticleDefinition.hh"
00020 #include "G4VTouchable.hh"
00021 #include "G4TouchableHistory.hh"
00022 #include "G4ios.hh"
00023 #include "G4RotationMatrix.hh"
00024 #include "G4ThreeVector.hh"
00025
00026 #include "G4AffineTransform.hh"
00027
00028 #include "G4RunManager.hh"
00029 #include <vector>
00030
00031 #include "G4SDManager.hh"
00032
00033
00034
00035
00036 extern G4double
00037 initial_x, initial_xp,
00038 initial_y, initial_yp,
00039 initial_z, initial_zp,
00040 initial_E, initial_t;
00041
00042
00043 BDSSamplerSD::BDSSamplerSD(G4String name, G4String type)
00044 :G4VSensitiveDetector(name),SamplerCollection(NULL),
00045 itsType(type)
00046 {
00047 itsCollectionName="Sampler_"+type;
00048 collectionName.insert(itsCollectionName);
00049 }
00050
00051 BDSSamplerSD::~BDSSamplerSD()
00052 {;}
00053
00054 void BDSSamplerSD::Initialize(G4HCofThisEvent*)
00055 {
00056
00057 SamplerCollection = new BDSSamplerHitsCollection(SensitiveDetectorName,itsCollectionName);
00058
00059
00060
00061
00062
00063 }
00064
00065 G4bool BDSSamplerSD::ProcessHits(G4Step*aStep,G4TouchableHistory*)
00066 {
00067 G4Track* theTrack = aStep->GetTrack();
00068 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00069
00070
00071
00072
00073
00074
00075 if(BDSGlobalConstants::Instance()->DoTwiss() || BDSGlobalConstants::Instance()->isReference) return false;
00076
00077 if(preStepPoint->GetStepStatus()!=fGeomBoundary) return false;
00078
00079
00080 G4int TrackID = theTrack->GetTrackID();
00081
00082 G4int ParentID = theTrack->GetParentID();
00083
00084 G4double t = theTrack->GetGlobalTime();
00085
00086
00087
00088 G4double energy = theTrack->GetKineticEnergy()+
00089 theTrack->GetDefinition()->GetPDGMass();
00090
00091
00092
00093 G4ThreeVector pos = theTrack->GetPosition();
00094
00095 G4double s = theTrack->GetTrackLength();
00096 if(ParentID != 0) s = pos.z();
00097
00098
00099 G4ThreeVector momDir = theTrack->GetMomentumDirection();
00100
00101
00102
00103
00104 G4AffineTransform tf(preStepPoint->GetTouchableHandle()->GetHistory()->GetTopTransform());
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 G4ThreeVector LocalPosition = tf.TransformPoint(pos);
00116 G4ThreeVector LocalDirection = tf.TransformAxis(momDir);
00117
00118 G4double x=LocalPosition.x();
00119 G4double y=LocalPosition.y();
00120 G4double z=LocalPosition.z();
00121 G4double xPrime=LocalDirection.x();
00122 G4double yPrime=LocalDirection.y();
00123 G4double zPrime=LocalDirection.z();
00124
00125
00126
00127
00128
00129 if(zPrime<0) energy*=-1;
00130
00131
00132 G4int nEvent=
00133 G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
00134
00135 nEvent+=BDSGlobalConstants::Instance()->GetEventNumberOffset();
00136
00137 G4int nSampler=theTrack->GetVolume()->GetCopyNo()+1;
00138 G4String SampName = theTrack->GetVolume()->GetName()+"_"+BDSGlobalConstants::Instance()->StringFromInt(nSampler);
00139 G4int PDGtype=theTrack->GetDefinition()->GetPDGEncoding();
00140
00141 G4String pName=theTrack->GetDefinition()->GetParticleName();
00142
00143 #ifdef DEBUG
00144 G4cout << __METHOD_NAME__ << "BDSSamplerSD> Particle name: " << pName << G4endl;
00145 G4cout << __METHOD_NAME__ << "BDSSamplerSD> PDG encoding: " << PDGtype << G4endl;
00146 G4cout << __METHOD_NAME__ << "BDSSamplerSD> TrackID: " << TrackID << G4endl;
00147 #endif
00148
00149 G4ThreeVector vtx=theTrack->GetVertexPosition();
00150 G4ThreeVector dir=theTrack->GetVertexMomentumDirection();
00151
00152 G4double
00153 start_x, start_xp,
00154 start_y, start_yp,
00155 start_z, start_zp,
00156 start_E, start_t;
00157
00158 if(pName!="e+" && pName!="e-")
00159 {
00160
00161 start_x = vtx.x();
00162 start_xp = dir.x();
00163 start_y = vtx.y();
00164 start_yp = dir.y();
00165 start_z = vtx.z();
00166 start_zp = dir.z();
00167
00168 start_E = theTrack->GetVertexKineticEnergy()+
00169 theTrack->GetDefinition()->GetPDGMass();
00170
00171 start_t = t - theTrack->GetLocalTime();
00172 }
00173 else
00174 {
00175 start_x = initial_x;
00176 start_xp = initial_xp;
00177 start_y = initial_y;
00178 start_yp = initial_yp;
00179 start_z = initial_z;
00180 start_zp = initial_zp;
00181 start_E = initial_E;
00182 start_t = initial_t;
00183 }
00184 G4double weight=theTrack->GetWeight();
00185
00186
00187
00188
00189
00190
00191
00192 BDSSamplerHit* smpHit
00193 = new BDSSamplerHit(
00194 SampName,
00195 start_E,
00196 start_x, start_xp,
00197 start_y, start_yp,
00198 start_z, start_zp,
00199 start_t,
00200 energy,
00201 x, xPrime,
00202 y, yPrime,
00203 z, zPrime,
00204 t,
00205 s,
00206 weight,
00207 PDGtype,nEvent, ParentID, TrackID);
00208 smpHit->SetGlobalX(pos.x());
00209 smpHit->SetGlobalY(pos.y());
00210 smpHit->SetGlobalZ(pos.z());
00211 smpHit->SetGlobalXPrime(momDir.x());
00212 smpHit->SetGlobalYPrime(momDir.y());
00213 smpHit->SetGlobalZPrime(momDir.z());
00214 smpHit->SetType(itsType);
00215
00216 #ifdef DEBUG
00217 G4cout << __METHOD_NAME__ << " Sampler : " << SampName << G4endl;
00218 G4cout << __METHOD_NAME__ << " Storing hit: E, x, y, z, xPrime, yPrime" << G4endl;
00219 G4cout << __METHOD_NAME__ << " " << energy <<" " << x << " " << y << " " << z << " " << xPrime << " " << yPrime << G4endl;
00220 G4cout << __METHOD_NAME__ << " Storing hit: E, x, y, z, xPrime, yPrime" << G4endl;
00221 G4cout << __METHOD_NAME__ << " " << energy <<" " << pos.x() << " " << pos.y() << " " << pos.z() << " " << xPrime << " " << yPrime << G4endl;
00222 G4cout << __METHOD_NAME__ << " entries in hits collection before inserting hit: " << SamplerCollection->entries() << G4endl;
00223 #endif
00224 SamplerCollection->insert(smpHit);
00225 #ifdef DEBUG
00226 G4cout << __METHOD_NAME__ << " entries in hits collection after inserting hit: " << SamplerCollection->entries() << G4endl;
00227 #endif
00228
00229
00230 return true;
00231 }
00232
00233 void BDSSamplerSD::EndOfEvent(G4HCofThisEvent*HCE)
00234 {
00235 G4SDManager * SDman = G4SDManager::GetSDMpointer();
00236 G4int HCID = SDman->GetCollectionID(itsCollectionName);
00237 HCE->AddHitsCollection(HCID, SamplerCollection );
00238
00239
00240
00241
00242 }
00243
00244 void BDSSamplerSD::clear(){}
00245
00246 void BDSSamplerSD::DrawAll(){}
00247
00248 void BDSSamplerSD::PrintAll(){}