Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: GammaRayTelTrackerSD.cc,v 1.8 2003/11/14 15:00:00 flongo Exp $ >> 25 // GEANT4 tag $Name: geant4-07-00-patch-01 $ 27 // ------------------------------------------- 26 // ------------------------------------------------------------ 28 // GEANT 4 class implementation file 27 // GEANT 4 class implementation file 29 // CERN Geneva Switzerland 28 // CERN Geneva Switzerland 30 // 29 // 31 // 30 // 32 // ------------ GammaRayTelTrackerSD --- 31 // ------------ GammaRayTelTrackerSD ------ 33 // by R.Giannitrapani, F.Longo & G. 32 // by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000) 34 // 33 // 35 // ******************************************* 34 // ************************************************************ 36 << 35 #include "G4RunManager.hh" 37 #include "GammaRayTelTrackerSD.hh" 36 #include "GammaRayTelTrackerSD.hh" >> 37 38 #include "GammaRayTelTrackerHit.hh" 38 #include "GammaRayTelTrackerHit.hh" 39 #include "GammaRayTelDetectorConstruction.hh" 39 #include "GammaRayTelDetectorConstruction.hh" 40 40 41 #include "G4RunManager.hh" << 42 #include "G4SystemOfUnits.hh" << 43 #include "G4VPhysicalVolume.hh" 41 #include "G4VPhysicalVolume.hh" >> 42 44 #include "G4Step.hh" 43 #include "G4Step.hh" 45 #include "G4VTouchable.hh" 44 #include "G4VTouchable.hh" 46 #include "G4TouchableHistory.hh" 45 #include "G4TouchableHistory.hh" 47 #include "G4SDManager.hh" 46 #include "G4SDManager.hh" >> 47 48 #include "G4ios.hh" 48 #include "G4ios.hh" 49 49 50 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 51 51 52 GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4S << 52 GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4String name):G4VSensitiveDetector(name) 53 auto *runManager = G4RunManager::GetRunMan << 53 { 54 << 54 G4RunManager* runManager = G4RunManager::GetRunManager(); 55 detector = (GammaRayTelDetectorConstructio << 55 Detector = 56 << 56 (GammaRayTelDetectorConstruction*)(runManager->GetUserDetectorConstruction()); 57 auto numberOfTKRTiles = detector->GetNbOfT << 57 58 numberOfTKRStrips = detector->GetNbOfTKRSt << 58 G4int NbOfTKRTiles = Detector->GetNbOfTKRTiles(); 59 numberOfTKRLayers = detector->GetNbOfTKRLa << 59 NbOfTKRStrips = Detector->GetNbOfTKRStrips(); 60 numberOfTKRStrips = numberOfTKRStrips * nu << 60 NbOfTKRLayers = Detector->GetNbOfTKRLayers(); 61 numberOfTKRChannels = numberOfTKRStrips * << 61 NbOfTKRStrips = NbOfTKRStrips*NbOfTKRTiles; 62 << 62 63 tkrHitXID = new G4int[numberOfTKRChannels] << 63 NbOfTKRChannels = NbOfTKRStrips* NbOfTKRTiles * NbOfTKRLayers; 64 tkrHitYID = new G4int[numberOfTKRChannels] << 64 65 << 65 ThitXID = new G4int[NbOfTKRChannels]; 66 constexpr auto TRACKER_COLLECTION_NAME = " << 66 ThitYID = new G4int[NbOfTKRChannels]; 67 collectionName.insert(TRACKER_COLLECTION_N << 67 collectionName.insert("TrackerCollection"); >> 68 } >> 69 >> 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 71 >> 72 GammaRayTelTrackerSD::~GammaRayTelTrackerSD() >> 73 { >> 74 delete [] ThitXID; >> 75 delete [] ThitYID; >> 76 } >> 77 >> 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 79 >> 80 void GammaRayTelTrackerSD::Initialize(G4HCofThisEvent*) >> 81 { >> 82 TrackerCollection = new GammaRayTelTrackerHitsCollection >> 83 (SensitiveDetectorName,collectionName[0]); >> 84 >> 85 for (G4int i=0;i<NbOfTKRChannels;i++) >> 86 { >> 87 ThitXID[i] = -1; >> 88 ThitYID[i] = -1; >> 89 }; >> 90 } >> 91 >> 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 93 >> 94 G4bool GammaRayTelTrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist) >> 95 { >> 96 >> 97 G4double edep = aStep->GetTotalEnergyDeposit(); >> 98 if ((edep/keV == 0.)) return false; >> 99 >> 100 G4int StripTotal = Detector->GetNbOfTKRStrips(); >> 101 G4int TileTotal = Detector->GetNbOfTKRTiles(); >> 102 >> 103 // This TouchableHistory is used to obtain the physical volume >> 104 // of the hit >> 105 G4TouchableHistory* theTouchable >> 106 = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()); >> 107 >> 108 //G4VPhysicalVolume* phys_tile = theTouchable->GetVolume(); >> 109 >> 110 G4VPhysicalVolume* plane = theTouchable->GetVolume(1); >> 111 >> 112 G4int PlaneNumber = 0; >> 113 PlaneNumber=plane->GetCopyNo(); >> 114 G4String PlaneName = plane->GetName(); >> 115 >> 116 // The RO History is used to obtain the real strip >> 117 // of the hit >> 118 >> 119 G4int StripNumber = 0; >> 120 G4VPhysicalVolume* strip = 0; >> 121 strip = ROhist->GetVolume(); >> 122 G4String StripName = strip->GetName(); >> 123 StripNumber= strip->GetCopyNo(); >> 124 >> 125 ROhist->MoveUpHistory(); >> 126 G4VPhysicalVolume* tile = ROhist->GetVolume(); >> 127 G4int TileNumber = tile->GetCopyNo(); >> 128 G4String TileName = tile->GetName(); >> 129 >> 130 G4int NTile = (TileNumber%TileTotal); >> 131 G4int j=0; >> 132 >> 133 G4int NChannel = 0; >> 134 >> 135 for (j=0;j<TileTotal;j++) >> 136 { >> 137 if(NTile==j) StripNumber += StripTotal*NTile; >> 138 } >> 139 >> 140 NChannel = PlaneNumber*TileTotal*StripTotal + StripNumber; >> 141 >> 142 /* G4cout << NChannel << " Channel Number" << G4endl; >> 143 G4cout << " Plane Number = " << PlaneNumber << " " << PlaneName >> 144 << G4endl; >> 145 G4cout << StripName << " " << StripNumber << G4endl; */ >> 146 >> 147 if (PlaneName == "TKRDetectorX" ) >> 148 // The hit is on an X silicon plane >> 149 { >> 150 // This is a new hit >> 151 if (ThitXID[NChannel]==-1) >> 152 { >> 153 GammaRayTelTrackerHit* TrackerHit = new GammaRayTelTrackerHit; >> 154 TrackerHit->SetPlaneType(1); >> 155 TrackerHit->AddSil(edep); >> 156 TrackerHit->SetPos(aStep->GetPreStepPoint()->GetPosition()); >> 157 TrackerHit->SetNSilPlane(PlaneNumber); >> 158 TrackerHit->SetNStrip(StripNumber); >> 159 ThitXID[NChannel] = >> 160 TrackerCollection->insert(TrackerHit) -1; >> 161 } >> 162 else // This is not new >> 163 { >> 164 (*TrackerCollection)[ThitXID[NChannel]]->AddSil(edep); >> 165 // G4cout << "X" << PlaneNumber << " " << StripNumber << G4endl; >> 166 } >> 167 } >> 168 >> 169 if (PlaneName == "TKRDetectorY") >> 170 // The hit is on an Y silicon plane >> 171 { >> 172 // This is a new hit >> 173 if (ThitYID[NChannel]==-1) >> 174 { >> 175 GammaRayTelTrackerHit* TrackerHit = new GammaRayTelTrackerHit; >> 176 TrackerHit->SetPlaneType(0); >> 177 TrackerHit->AddSil(edep); >> 178 TrackerHit->SetPos(aStep->GetPreStepPoint()->GetPosition()); >> 179 TrackerHit->SetNSilPlane(PlaneNumber); >> 180 TrackerHit->SetNStrip(StripNumber); >> 181 ThitYID[NChannel] = >> 182 TrackerCollection->insert(TrackerHit)-1; >> 183 } >> 184 else // This is not new >> 185 { >> 186 (*TrackerCollection)[ThitYID[NChannel]]->AddSil(edep); >> 187 // G4cout << "Y" << PlaneNumber << " " << StripNumber << G4endl; >> 188 } >> 189 } >> 190 >> 191 return true; 68 } 192 } 69 193 70 //....oooOO0OOooo........oooOO0OOooo........oo 194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 71 195 72 GammaRayTelTrackerSD::~GammaRayTelTrackerSD() << 196 void GammaRayTelTrackerSD::EndOfEvent(G4HCofThisEvent* HCE) 73 delete[] tkrHitXID; << 197 { 74 delete[] tkrHitYID; << 198 static G4int HCID = -1; >> 199 if(HCID<0) >> 200 { >> 201 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); >> 202 } >> 203 HCE->AddHitsCollection(HCID,TrackerCollection); >> 204 >> 205 >> 206 for (G4int i=0;i<NbOfTKRChannels;i++) >> 207 { >> 208 ThitXID[i] = -1; >> 209 ThitYID[i] = -1; >> 210 }; 75 } 211 } 76 212 77 //....oooOO0OOooo........oooOO0OOooo........oo 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 78 214 79 void GammaRayTelTrackerSD::Initialize(G4HCofTh << 215 void GammaRayTelTrackerSD::clear() 80 trackerCollection = new GammaRayTelTracker << 216 {} 81 << 82 for (auto i = 0; i < numberOfTKRChannels; << 83 tkrHitXID[i] = -1; << 84 tkrHitYID[i] = -1; << 85 }; << 86 } << 87 217 88 //....oooOO0OOooo........oooOO0OOooo........oo 218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 89 219 90 auto GammaRayTelTrackerSD::ProcessHits(G4Step << 220 void GammaRayTelTrackerSD::DrawAll() 91 G4double depositedEnergy = 0.; << 221 {} 92 depositedEnergy = step->GetTotalEnergyDepo << 93 if (depositedEnergy == 0.) { << 94 return false; << 95 } << 96 222 97 auto totalNumberOfStrips = detector->GetNb << 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 98 auto totalnumberOfTiles = detector->GetNbO << 99 224 100 // This TouchableHistory is used to obtain << 225 void GammaRayTelTrackerSD::PrintAll() 101 auto *touchable = (G4TouchableHistory*) (s << 226 {} 102 auto *plane = touchable->GetVolume(2); << 103 << 104 G4int planeNumber = 0; << 105 planeNumber = plane->GetCopyNo(); << 106 auto planeName = plane->GetName(); << 107 << 108 // The hits sees now the real strip << 109 << 110 G4int stripNumber = 0; << 111 G4VPhysicalVolume *strip{nullptr}; << 112 strip = touchable->GetVolume(); << 113 << 114 G4String stripName = strip->GetName(); << 115 stripNumber = strip->GetCopyNo(); << 116 << 117 auto *tile = touchable->GetVolume(1); << 118 auto tileNumber = tile->GetCopyNo(); << 119 auto tileName = tile->GetName(); << 120 auto NTile = (tileNumber % totalnumberOfTi << 121 << 122 G4int channelNumber = 0; << 123 << 124 for (auto j = 0; j < totalnumberOfTiles; j << 125 if (NTile == j) { << 126 stripNumber += totalNumberOfStrips << 127 } << 128 } << 129 227 130 channelNumber = planeNumber * totalnumberO << 228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 131 229 132 /* << 133 G4cout << " Channel: " << channelNumber << << 134 G4cout << " Plane: " << planeNumber << " " << 135 G4cout << " Strip: " << stripNumber << " " << 136 */ << 137 230 138 // The hit is on an X silicon plane << 139 if (planeName == "TKRDetectorX") { << 140 if (tkrHitXID[channelNumber] == -1) { << 141 auto *trackerHit = new GammaRayTel << 142 trackerHit->SetPlaneType(1); << 143 trackerHit->AddDepositedEnergy(dep << 144 trackerHit->SetPosition(step->GetP << 145 trackerHit->SetSiliconPlaneNumber( << 146 trackerHit->SetStripNumber(stripNu << 147 tkrHitXID[channelNumber] = tracker << 148 } else { // This is not new << 149 (*trackerCollection)[tkrHitXID[cha << 150 // G4cout << "X" << planeNumber << << 151 } << 152 } << 153 231 154 // The hit is on an Y silicon plane << 155 if (planeName == "TKRDetectorY") { << 156 if (tkrHitYID[channelNumber] == -1) { << 157 auto *trackerHit = new GammaRayTel << 158 trackerHit->SetPlaneType(0); << 159 trackerHit->AddDepositedEnergy(dep << 160 trackerHit->SetPosition(step->GetP << 161 trackerHit->SetSiliconPlaneNumber( << 162 trackerHit->SetStripNumber(stripNu << 163 tkrHitYID[channelNumber] = tracker << 164 } else { // This is not new << 165 (*trackerCollection)[tkrHitYID[cha << 166 // G4cout << "Y" << planeNumber << << 167 } << 168 } << 169 232 170 return true; << 171 } << 172 233 173 //....oooOO0OOooo........oooOO0OOooo........oo << 174 234 175 void GammaRayTelTrackerSD::EndOfEvent(G4HCofTh << 176 static G4int collectionIdentifier = -1; << 177 if (collectionIdentifier < 0) { << 178 collectionIdentifier = G4SDManager::Ge << 179 } << 180 collection->AddHitsCollection(collectionId << 181 235 182 for (auto i = 0; i < numberOfTKRChannels; << 183 tkrHitXID[i] = -1; << 184 tkrHitYID[i] = -1; << 185 } << 186 } << 187 236 188 //....oooOO0OOooo........oooOO0OOooo........oo << 189 237 190 void GammaRayTelTrackerSD::clear() { << 191 } << 192 238 193 //....oooOO0OOooo........oooOO0OOooo........oo << 194 239 195 void GammaRayTelTrackerSD::DrawAll() { << 196 } << 197 240 198 //....oooOO0OOooo........oooOO0OOooo........oo << 199 241 200 void GammaRayTelTrackerSD::PrintAll() { << 201 } << 202 242