QwGeant4
QweakSimGEM_WirePlaneSD.cc
Go to the documentation of this file.
1 //=============================================================================
2 //
3 // ---------------------------
4 // | Doxygen File Information |
5 // ---------------------------
6 //
7 /**
8 
9  \file QweakSimGEM_WirePlaneSD.cc
10 
11  $Revision: 1.3 $
12  $Date: 2006/05/05 21:39:28 $
13 
14  \author Klaus Hans Grimm
15 
16 */
17 //=============================================================================
18 
19 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
20 
22 
23 // user includes
27 
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 
31 :G4VSensitiveDetector(name)
32 {
33 // G4cout << G4endl << "###### Calling QweakSimGEM_WirePlaneSD::QweakSimGEM_WirePlaneSD() " << G4endl << G4endl;
34 
35  collectionName.insert("GEMWirePlaneCollection"); //collectionName[0]
36  HCID = -1;
37 
38 // G4cout << G4endl << "###### Leaving QweakSimGEM_WirePlaneSD::QweakSimGEM_WirePlaneSD() " << G4endl << G4endl;
39 }
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 {
44  //G4cout << G4endl << "###### Calling QweakSimGEM_WirePlaneSD::~QweakSimGEM_WirePlaneSD() " << G4endl << G4endl;
45  //delete hitsCollection;
46  //G4cout << G4endl << "###### Leaving QweakSimGEM_WirePlaneSD::~QweakSimGEM_WirePlaneSD() " << G4endl << G4endl;
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 void QweakSimGEM_WirePlaneSD::Initialize(G4HCofThisEvent* HCE)
51 {
52  //G4cout << G4endl << "###### Calling QweakSimGEM_WirePlaneSD::Initialize() " << G4endl << G4endl;
53 
54  hitsCollection = new QweakSimGEM_WirePlane_HitsCollection(SensitiveDetectorName,collectionName[0]);
55 
56  HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
57 
58  HCE->AddHitsCollection( HCID, hitsCollection );
59 
60  //G4cout << G4endl << "###### Leaving QweakSimGEM_WirePlaneSD::Initialize() " << G4endl << G4endl;
61 
62 }
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 G4bool QweakSimGEM_WirePlaneSD::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROhist*/)
65 {
66  //G4cout << G4endl << "###### Calling QweakSimGEM_WirePlaneSD::ProcessHits() " << G4endl << G4endl;
67 
68 
69  G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
70 
71 // G4cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Charge =" << charge << G4endl;
72 
73  // dismiss photons
74  if(charge==0.) return false;
75 
76 
77  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
78  G4StepPoint* postStepPoint = aStep->GetPreStepPoint();
79  G4TouchableHistory* theTouchable = (G4TouchableHistory*)(preStepPoint->GetTouchable());
80  G4VPhysicalVolume* physVol = theTouchable->GetVolume();
81 
82  // we are only interested if the particle is crossing a boundary (glass->vaccuum)
83  if (postStepPoint->GetStepStatus() != fGeomBoundary) {
84 // G4cout << "=======================================================================" << G4endl;
85 // G4cout << ">>>> QweakSimGEM_WirePlaneSD: We are NOT crossing a boundary <<<<<<" << G4endl;
86 // G4cout << ">>>> Aborting QweakSimGEM_WirePlaneSD::ProcessHits <<<<<<" << G4endl;
87 // G4cout << "=======================================================================" << G4endl;
88 
89  return false;
90  }
91 
92 // G4cout << "================== We are in volume :" << physVol->GetName() << G4endl << G4endl;
93 
94 
95  if(strcmp(physVol->GetName(),"GEM_AnodeCopperLayer_Physical") == 0 ) {
96 
97 // G4cout << "=============================================================" << G4endl;
98 // G4cout << ">>>>>>> Particle crossing : GEM_AnodeCopperLayer_Physical <<<<<<<<<" << G4endl;
99 // G4cout << "=============================================================" << G4endl;
100 
101 // G4int trackID = aStep->GetTrack()->GetTrackID();
102 // G4cout << "====> Track ID : " << trackID << G4endl;
103 
104 // G4int parentID = aStep->GetTrack()->GetParentID();
105 // G4cout << "====> Parent ID : " << parentID << G4endl;
106 
107 
108 
109 // G4int MotherCopyNo = theTouchable->GetVolume(1)->GetCopyNo(); // Several MotherVolumes
110  G4int WirePlaneCopyNo = theTouchable->GetVolume()->GetCopyNo(); // but only one WirePlane per MV
111 // G4int MotherReplicaNo = theTouchable->GetReplicaNumber(1); // Several MotherVolumes
112 
113 //pqwang@jlab.org
114 //there are 3 fold MotherVolume, the GEMID must be taken from the outer container
115 // for decoding correct GEMID in the EventAction
116 // G4int MotherCopyNo2 = theTouchable->GetVolume(2)->GetCopyNo(); // Several MotherVolumes
117 // G4int MotherReplicaNo2 = theTouchable->GetReplicaNumber(2); // Several MotherVolumes
118 
119  G4int MotherCopyNo3 = theTouchable->GetVolume(3)->GetCopyNo(); // Several MotherVolumes
120 // G4int MotherReplicaNo3 = theTouchable->GetReplicaNumber(3); // Several MotherVolumes
121 
122 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane MV CopyNumber :" << MotherCopyNo << G4endl;
123 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane CopyNumber :" << WirePlaneCopyNo << G4endl;
124 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane ReplicaNumber :" << MotherReplicaNo << G4endl;
125 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane MV CopyNumber2 :" << MotherCopyNo2 << G4endl;
126 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane ReplicaNumber2 :" << MotherReplicaNo2 << G4endl;
127 
128 
129  G4ThreeVector worldPos = preStepPoint->GetPosition();
130 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldPos.X [cm]:" << worldPos.x()/cm << G4endl;
131 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldPos.Y [cm]:" << worldPos.y()/cm << G4endl;
132 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldPos.Z [cm]:" << worldPos.z()/cm << G4endl;
133 
134  G4ThreeVector localPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(worldPos);
135 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalPos.X [cm]:" << localPos.x()/cm << G4endl;
136 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalPos.Y [cm]:" << localPos.y()/cm << G4endl;
137 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalPos.Z [cm]:" << localPos.z()/cm << G4endl;
138 
139  G4ThreeVector worldMomentum = preStepPoint->GetMomentum();
140 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldMomentum.X [GeV]:" << worldMomentum.x()/GeV << G4endl;
141 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldMomentum.Y [GeV]:" << worldMomentum.y()/GeV << G4endl;
142 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane WorldMomentum.Z [GeV]:" << worldMomentum.z()/GeV << G4endl;
143 
144  G4ThreeVector localMomentum = theTouchable->GetHistory()->GetTopTransform().TransformPoint(worldMomentum);
145 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalMomentum.X [GeV]:" << localMomentum.x()/GeV << G4endl;
146 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalMomentum.Y [GeV]:" << localMomentum.y()/GeV << G4endl;
147 // G4cout << "%%%%%%%%%%%%%%%%%%% WirePlane LocalMomentum.Z [GeV]:" << localMomentum.z()/GeV << G4endl;
148 
149  G4double currentKineticEnergy = preStepPoint->GetKineticEnergy();
150  G4double currentTotalEnergy = preStepPoint->GetTotalEnergy();
151 
152  // Vertex: where this track was generated
153  G4ThreeVector originVertexPosition = aStep->GetTrack()->GetVertexPosition();
154  G4ThreeVector originVertexMomentumDirection = aStep->GetTrack()->GetVertexMomentumDirection();
155  G4double originVertexKineticEnergy = aStep->GetTrack()->GetVertexKineticEnergy();
156 
157 // G4cout << "====> originVertexPosition_X [cm] : " << originVertexPosition.x()/cm << G4endl;
158 // G4cout << "====> originVertexPosition_Y [cm] : " << originVertexPosition.y()/cm << G4endl;
159 // G4cout << "====> originVertexPosition_Z [cm] : " << originVertexPosition.z()/cm << G4endl;
160 
161 // G4cout << "====> originVertexMomentumDirection_X : " << originVertexMomentumDirection.x() << G4endl;
162 // G4cout << "====> originVertexMomentumDirection_Y : " << originVertexMomentumDirection.y() << G4endl;
163 // G4cout << "====> originVertexMomentumDirection_Z : " << originVertexMomentumDirection.z() << G4endl;
164 
165 // G4cout << "====> originVertexKineticEnergy [Mev] : " << originVertexKineticEnergy/MeV << G4endl;
166 
167 
168 
169 // G4double target_zcut = -630*cm;
170 
171 // if (originVertexPosition.z()/cm > target_zcut/cm)
172 // {
173 // G4cout << "################################################################" << G4endl;
174 // G4cout << ">>>>>>>>>>>> originVertexPosition.z > 630cm !!! <<<<<<<<<<<" << G4endl;
175 // G4cout << ">>>>>>>>>>>> Track does not origin from target <<<<<<<<<<<" << G4endl;
176 // G4cout << ">>>>>>>>>>>> Aborting QweakSimGEM_WirePlaneSD::ProcessHits() <<<<<<<<<<<" << G4endl;
177 // G4cout << "################################################################" << G4endl;
178 //
179 // return false;
180 //
181 // }
182 
183 // // get User Track Info
184 // QweakSimTrackInformation* info = (QweakSimTrackInformation*) (aStep->GetTrack()->GetUserInformation());
185 // info->Print();
186 
187 // G4double primaryQ2 = info->GetPrimaryQ2();
188 // G4double crossSection = info->GetCrossSection();
189 // G4double crossSectionWeight = info->GetCrossSectionWeight();
190 // G4int primaryEventNumber = info->GetPrimaryEventNumber();
191 
192 // G4cout << " @@@@@@@@@@@@@@@@@@@@@@@ Original Track Q2 : " << primaryQ2 << G4endl;
193 // G4cout << " @@@@@@@@@@@@@@@@@@@@@@@ Original Track Event Number : " << primaryEventNumber << G4endl;
194 // G4cout << " @@@@@@@@@@@@@@@@@@@@@@@ Original CrossSection Weight (ub) : " << crossSectionWeight << G4endl << G4endl;
195 
196 
197 
198 // G4cout << " =====> Storing GEM hit information into aHit" << G4endl;
199 
200  // QweakSimGEMHit* aHit = new QweakSimGEMHit(MotherCopyNo); // there is only one plane per motherVolume
201  QweakSimGEM_WirePlaneHit* aHit = new QweakSimGEM_WirePlaneHit(); // there is only one plane per motherVolume
202 
203 //pqwang@jlab.org
204 //there are 3 fold MotherVolume, the GEMID must be taken from the outer container
205 // for decoding correct GEMID in the EventAction
206  aHit->StoreGEMID(MotherCopyNo3); // 0: Front GEM , 1: Back GEM
207  aHit->StoreWirePlaneID(WirePlaneCopyNo); // [0,5] : WirePlane #0 to #5 (6 wire plane in total per GEM)
208 
209  aHit->StoreWorldPosition(worldPos);
210  aHit->StoreLocalPosition(localPos);
211 
212  aHit->StoreWorldMomentum(worldMomentum);
213  aHit->StoreLocalMomentum(localMomentum);
214 
215  aHit->StoreGlobalTime(preStepPoint->GetGlobalTime());
216 
217  aHit->StoreOriginVertexPosition(originVertexPosition);
218  aHit->StoreOriginVertexMomentumDirection(originVertexMomentumDirection);
219  aHit->StoreOriginVertexKineticEnergy(originVertexKineticEnergy);
220 
221 // aHit->StorePrimaryQ2(primaryQ2);
222 // aHit->StoreCrossSection(crossSection);
223 // aHit->StoreCrossSectionWeight(crossSectionWeight);
224 // aHit->StorePrimaryEventNumber(primaryEventNumber);
225 
226  aHit->StoreKineticEnergy(currentKineticEnergy);
227  aHit->StoreTotalEnergy(currentTotalEnergy);
228 
229 
230  // now store all the hit information into the hit collection
231  hitsCollection->insert(aHit);
232 
233  //delete aHit; // NOT ALLOWED, Geant4 crashes
234 
235  } // end of if(strcmp(physVol->GetName(),"GEM_WirePlane_Physical")==0)
236 
237 
238  //G4cout << G4endl << "###### Leaving QweakSimGEM_WirePlaneSD::ProcessHits() " << G4endl << G4endl;
239 
240  return true;
241 }
242 
243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
244 //void QweakSimGEM_WirePlaneSD::EndOfEvent(G4HCofThisEvent* HCE)
245 void QweakSimGEM_WirePlaneSD::EndOfEvent(G4HCofThisEvent* )
246 {
247  //G4cout << G4endl << "###### Calling QweakSimGEM_WirePlaneSD::EndOfEvent() " << G4endl << G4endl;
248 
249 // G4int NbHits = hitsCollection->entries();
250 // G4cout << "\n-------->Hits Collection: in this event they are " << NbHits
251 // << " hits in the Wire Planes: " << G4endl;
252 // for (G4int i=0;i<NbHits;i++) (*hitsCollection)[i]->Print();
253 
254  //G4cout << G4endl << "###### Leaving QweakSimGEM_WirePlaneSD::EndOfEvent() " << G4endl << G4endl;
255 
256 }
257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
void StoreOriginVertexKineticEnergy(G4double ekin)
QweakSimGEM_WirePlane_HitsCollection * hitsCollection
G4THitsCollection< QweakSimGEM_WirePlaneHit > QweakSimGEM_WirePlane_HitsCollection
void EndOfEvent(G4HCofThisEvent *HCE)
void StoreWorldPosition(G4ThreeVector gxyz)
void StoreWirePlaneID(G4int wireplane_ID)
void StoreLocalPosition(G4ThreeVector lxyz)
void Initialize(G4HCofThisEvent *HCE)
void StoreLocalMomentum(G4ThreeVector lpxyz)
void StoreOriginVertexMomentumDirection(G4ThreeVector pxyz)
Handling of a Readoutplane Hit of the GEM detector (I know there is no wire plane ...
void StoreWorldMomentum(G4ThreeVector gpxyz)
void StoreOriginVertexPosition(G4ThreeVector xyz)
void StoreKineticEnergy(G4double ekin)