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 /////////////////////////////////////////////////////////////////////////////// 27 // File: CCalG4Ecal.cc 24 // File: CCalG4Ecal.cc 28 // Description: CCalG4Ecal Factory class to co 25 // Description: CCalG4Ecal Factory class to construct the G4 geometry of the 29 // electromagnetic calorimeter 26 // electromagnetic calorimeter 30 ////////////////////////////////////////////// 27 /////////////////////////////////////////////////////////////////////////////// 31 28 32 #include <cmath> << 33 << 34 #include "CCalG4Ecal.hh" 29 #include "CCalG4Ecal.hh" 35 30 36 #include "CCalMaterialFactory.hh" 31 #include "CCalMaterialFactory.hh" 37 #include "CCalRotationMatrixFactory.hh" 32 #include "CCalRotationMatrixFactory.hh" 38 #include "CCalSensitiveDetectors.hh" 33 #include "CCalSensitiveDetectors.hh" 39 34 40 #include "CCalutils.hh" 35 #include "CCalutils.hh" >> 36 #include <cmath> 41 37 42 #include "G4SystemOfUnits.hh" << 43 #include "G4ThreeVector.hh" 38 #include "G4ThreeVector.hh" 44 #include "G4Box.hh" 39 #include "G4Box.hh" 45 #include "G4Trd.hh" 40 #include "G4Trd.hh" 46 41 47 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolume.hh" 48 #include "G4PVPlacement.hh" 43 #include "G4PVPlacement.hh" 49 44 50 //#define debug 45 //#define debug 51 //#define ddebug 46 //#define ddebug 52 //#define pdebug 47 //#define pdebug 53 //#define sdebug 48 //#define sdebug 54 49 55 //Initialize static logical volumes 50 //Initialize static logical volumes 56 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog 51 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog = 0; 57 52 58 //Initialize static prefix name 53 //Initialize static prefix name 59 G4String CCalG4Ecal::idName = "CrystalMatrix"; 54 G4String CCalG4Ecal::idName = "CrystalMatrix"; 60 55 >> 56 //////////////////////////////////////////////////////////////////// >> 57 // CCalG4Ecal constructor & destructor... >> 58 //////////////////////////////////////////////////////////////////// 61 59 62 CCalG4Ecal::CCalG4Ecal(const G4String &name) : << 60 CCalG4Ecal::CCalG4Ecal(const G4String &name): 63 << 61 CCalEcal(name), CCalG4Able(name), type(module1) {} 64 62 65 CCalG4Ecal::~CCalG4Ecal() {} 63 CCalG4Ecal::~CCalG4Ecal() {} 66 64 >> 65 //////////////////////////////////////////////////////////////////// >> 66 // CCalG4Ecal methods... >> 67 //////////////////////////////////////////////////////////////////// 67 68 68 G4VPhysicalVolume* CCalG4Ecal::constructIn( G4 << 69 G4VPhysicalVolume* CCalG4Ecal::constructIn(G4VPhysicalVolume* mother) { 69 G4cout << "==>> Constructing CCalG4Ecal..." 70 G4cout << "==>> Constructing CCalG4Ecal..." << G4endl; 70 71 >> 72 /////////////////////////////////////////////////////////////// 71 // Construction of global volume as a Box 73 // Construction of global volume as a Box 72 74 73 if (!crystalmatrixLog) { 75 if (!crystalmatrixLog) { 74 crystalmatrixLog = constructGlobal(); 76 crystalmatrixLog = constructGlobal(); 75 } 77 } 76 CCalRotationMatrixFactory* rotfact = CCalRot 78 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 77 79 78 G4double x, y, z; 80 G4double x, y, z; 79 if (mother != 0) { 81 if (mother != 0) { 80 x = getXpos()*mm; 82 x = getXpos()*mm; 81 y = getYpos()*mm; 83 y = getYpos()*mm; 82 z = getZpos()*mm; 84 z = getZpos()*mm; 83 } else { 85 } else { 84 x = y = z = 0; 86 x = y = z = 0; 85 } 87 } 86 88 87 int num; 89 int num; 88 if (type == module2) { 90 if (type == module2) { 89 num = 2; 91 num = 2; 90 } else { 92 } else { 91 num = 1; 93 num = 1; 92 } 94 } 93 #ifdef pdebug 95 #ifdef pdebug 94 G4String name("Null"); 96 G4String name("Null"); 95 if (mother != 0) name = mother->GetName(); 97 if (mother != 0) name = mother->GetName(); 96 G4cout << crystalmatrixLog->GetName() << " N 98 G4cout << crystalmatrixLog->GetName() << " Number " << num << " positioned in " 97 << name << " at (" << x << ", " << y << 99 << name << " at (" << x << ", " << y << ", " << z << ")"; 98 #endif 100 #endif 99 101 100 G4RotationMatrix* cmrot = 0; 102 G4RotationMatrix* cmrot = 0; 101 if (mother != 0) { 103 if (mother != 0) { 102 G4String rotstr = idName + num; 104 G4String rotstr = idName + num; 103 cmrot = rotfact->findMatrix(rotstr); 105 cmrot = rotfact->findMatrix(rotstr); 104 if (!cmrot) { 106 if (!cmrot) { 105 #ifdef ddebug 107 #ifdef ddebug 106 G4cout << "Creating a new rotation: " << 108 G4cout << "Creating a new rotation: " << rotstr << tab 107 << getThetaX()*deg << "," << getPhi << 109 << getThetaX()*deg << "," << getPhiX()*deg << "," 108 << getThetaY()*deg << "," << getPhi << 110 << getThetaY()*deg << "," << getPhiY()*deg << "," 109 << getThetaZ()*deg << "," << getPhi << 111 << getThetaZ()*deg << "," << getPhiZ()*deg << G4endl; 110 #endif 112 #endif 111 cmrot = rotfact->AddMatrix(rotstr, getTh 113 cmrot = rotfact->AddMatrix(rotstr, getThetaX()*deg, getPhiX()*deg, 112 getThetaY()*d << 114 getThetaY()*deg, getPhiY()*deg, 113 getThetaZ()*d << 115 getThetaZ()*deg, getPhiZ()*deg); 114 } // if !cmrot 116 } // if !cmrot 115 #ifdef pdebug 117 #ifdef pdebug 116 G4cout << " rotation by (" << getThetaX() 118 G4cout << " rotation by (" << getThetaX() << ", " << getPhiX() << ", " 117 << getThetaY() << "," << getPhiY() << << 119 << getThetaY() << "," << getPhiY() << ", " << getThetaZ() << ", " 118 << getPhiZ() << ")" << G4endl; << 120 << getPhiZ() << ")" << G4endl; 119 #endif 121 #endif 120 } else { 122 } else { 121 #ifdef pdebug 123 #ifdef pdebug 122 G4cout << " without rotation..." << G4endl 124 G4cout << " without rotation..." << G4endl; 123 #endif 125 #endif 124 } 126 } 125 127 126 G4PVPlacement* crystalmatrix; 128 G4PVPlacement* crystalmatrix; 127 if (mother != 0) { 129 if (mother != 0) { 128 crystalmatrix = new G4PVPlacement(cmrot, G 130 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 129 crystalm << 131 crystalmatrixLog, idName, 130 mother-> << 132 mother->GetLogicalVolume(), false, num); 131 } else { 133 } else { 132 crystalmatrix = new G4PVPlacement(cmrot, G 134 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 133 idName, << 135 idName, crystalmatrixLog, 134 mother, << 136 mother, false, num); 135 } 137 } 136 G4cout << "<<== End of CCalG4Ecal constructi 138 G4cout << "<<== End of CCalG4Ecal construction ..." << G4endl; 137 139 138 return crystalmatrix; 140 return crystalmatrix; 139 } 141 } 140 142 141 143 142 G4LogicalVolume* CCalG4Ecal::constructGlobal() 144 G4LogicalVolume* CCalG4Ecal::constructGlobal() { 143 145 144 //Pointers to the Materials and Rotation Mat 146 //Pointers to the Materials and Rotation Matrix factory 145 CCalMaterialFactory* matfact = CCalMat 147 CCalMaterialFactory* matfact = CCalMaterialFactory::getInstance(); 146 CCalRotationMatrixFactory* rotfact = CCalRot 148 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 147 149 148 G4Material* matter = matfact->findMaterial(g 150 G4Material* matter = matfact->findMaterial(getGenMat()); 149 G4VSolid* solid = new G4Box (idName, 0.5*get 151 G4VSolid* solid = new G4Box (idName, 0.5*getWidBox()*mm, 0.5*getWidBox()*mm, 150 0.5*getLengBox( << 152 0.5*getLengBox()*mm); 151 #ifdef debug 153 #ifdef debug 152 G4cout << tab << idName << " Box made of " < 154 G4cout << tab << idName << " Box made of " << getGenMat() << " of dimension " 153 << 0.5*getWidBox()*mm << ", " << 0.5*ge 155 << 0.5*getWidBox()*mm << ", " << 0.5*getWidBox()*mm << ", " 154 << 0.5*getLengBox()*mm << G4endl; 156 << 0.5*getLengBox()*mm << G4endl; 155 #endif 157 #endif 156 G4LogicalVolume* glog = new G4LogicalVolume 158 G4LogicalVolume* glog = new G4LogicalVolume (solid, matter, idName); 157 setVisType(CCalVisualisable::PseudoVolumes,g 159 setVisType(CCalVisualisable::PseudoVolumes,glog); 158 160 159 //Now the layers 161 //Now the layers 160 G4String name = idName + "Layer"; 162 G4String name = idName + "Layer"; 161 matter = matfact->findMaterial(getLayMat()); 163 matter = matfact->findMaterial(getLayMat()); 162 solid = new G4Trd(name, getLayPar(0)*mm, ge 164 solid = new G4Trd(name, getLayPar(0)*mm, getLayPar(1)*mm, getLayPar(2)*mm, 163 getLayPar(3)*mm, getLayPa << 165 getLayPar(3)*mm, getLayPar(4)*mm); 164 #ifdef debug 166 #ifdef debug 165 G4cout << tab << name << " Trd made of " << 167 G4cout << tab << name << " Trd made of " << getLayMat() << " of dimension " 166 << getLayPar(0)*mm << ", " << getLayPar 168 << getLayPar(0)*mm << ", " << getLayPar(1)*mm << ", " << getLayPar(2)*mm 167 << ", " << getLayPar(3)*mm << ", " << g 169 << ", " << getLayPar(3)*mm << ", " << getLayPar(4)*mm << G4endl; 168 #endif 170 #endif 169 G4LogicalVolume* laylog = new G4LogicalVolum 171 G4LogicalVolume* laylog = new G4LogicalVolume (solid, matter, name); 170 setVisType(CCalVisualisable::OtherServices,l 172 setVisType(CCalVisualisable::OtherServices,laylog); 171 173 172 G4int i = 0; 174 G4int i = 0; 173 G4String rotstr; 175 G4String rotstr; 174 G4double xp, yp, zp, angle; 176 G4double xp, yp, zp, angle; 175 G4double zshift = -0.5 * (getLengBox() - get 177 G4double zshift = -0.5 * (getLengBox() - getCrystLength()) + getLengFront(); 176 G4RotationMatrix* rot = 0; 178 G4RotationMatrix* rot = 0; 177 for (i = 0; i < getLayNum(); i++) { 179 for (i = 0; i < getLayNum(); i++) { 178 angle = 0.5 * getLayAngle() * (2*i + 1 - 180 angle = 0.5 * getLayAngle() * (2*i + 1 - getLayNum()); 179 xp = angle * (getLayPar(4) + getLayRad 181 xp = angle * (getLayPar(4) + getLayRadius()) * mm; 180 zp = (zshift + getLayPar(0)*std::abs(s 182 zp = (zshift + getLayPar(0)*std::abs(std::sin(angle))) * mm; 181 rotstr = idName + "Layer" + i; 183 rotstr = idName + "Layer" + i; 182 rot = rotfact->findMatrix(rotstr); 184 rot = rotfact->findMatrix(rotstr); 183 if (!rot) { 185 if (!rot) { 184 #ifdef ddebug 186 #ifdef ddebug 185 G4cout << "Creating a new rotation: " << 187 G4cout << "Creating a new rotation: " << rotstr << tab 186 << (90.0*deg+angle) << "," << 0.0*d << 188 << (90.0*deg+angle) << "," << 0.0*deg << "," << 90.0*deg << "," 187 << 90.0*deg << "," << angle << "," << 189 << 90.0*deg << "," << angle << "," << 0.0*deg << G4endl; 188 #endif 190 #endif 189 rot = rotfact->AddMatrix(rotstr, (90.0*d 191 rot = rotfact->AddMatrix(rotstr, (90.0*deg+angle), 0.0*deg, 90.0*deg, 190 90.0*deg, angle << 192 90.0*deg, angle, 0.0*deg); 191 } 193 } 192 new G4PVPlacement(rot, G4ThreeVector(xp,0. 194 new G4PVPlacement(rot, G4ThreeVector(xp,0.,zp), laylog, name, glog, 193 false, i+1); << 195 false, i+1); 194 #ifdef pdebug 196 #ifdef pdebug 195 G4cout << laylog->GetName() << " number " 197 G4cout << laylog->GetName() << " number " << i+1 << " positioned in " 196 << glog->GetName() << " at (" << xp 198 << glog->GetName() << " at (" << xp << ", 0," << zp 197 << ") with rotation angle " << angle/ << 199 << ") with rotation angle " << angle/deg << G4endl; 198 #endif 200 #endif 199 } 201 } 200 202 201 //Now the crystals 203 //Now the crystals 202 name = idName + "Crystal"; 204 name = idName + "Crystal"; 203 matter = matfact->findMaterial(getCrystMat() 205 matter = matfact->findMaterial(getCrystMat()); 204 solid = new G4Trd(name, getCrystPar(0)*mm, 206 solid = new G4Trd(name, getCrystPar(0)*mm, getCrystPar(1)*mm, 205 getCrystPar(2)*mm, getCry << 207 getCrystPar(2)*mm, getCrystPar(3)*mm, getCrystPar(4)*mm); 206 #ifdef debug 208 #ifdef debug 207 G4cout << tab << name << " Trd made of " << 209 G4cout << tab << name << " Trd made of " << getCrystMat() << " of dimension " 208 << getCrystPar(0)*mm << ", " << getCrys 210 << getCrystPar(0)*mm << ", " << getCrystPar(1)*mm << ", " 209 << getCrystPar(2)*mm << ", " << getCrys 211 << getCrystPar(2)*mm << ", " << getCrystPar(3)*mm << ", " 210 << getCrystPar(4)*mm << G4endl; 212 << getCrystPar(4)*mm << G4endl; 211 #endif 213 #endif 212 214 213 G4LogicalVolume* detLog = new G4LogicalVolum 215 G4LogicalVolume* detLog = new G4LogicalVolume (solid, matter, name); 214 setVisType(CCalVisualisable::Sensitive,detLo 216 setVisType(CCalVisualisable::Sensitive,detLog); 215 sensitiveLogs.push_back(detLog); 217 sensitiveLogs.push_back(detLog); 216 for (i = 0; i < getCrystNum(); i++) { 218 for (i = 0; i < getCrystNum(); i++) { 217 angle = 0.5 * getLayAngle() * (2*i + 1 - 219 angle = 0.5 * getLayAngle() * (2*i + 1 - getCrystNum()); 218 yp = angle * (getCrystPar(4) + getLayR 220 yp = angle * (getCrystPar(4) + getLayRadius()) * mm; 219 zp = (getCrystPar(0)*std::abs(std::sin 221 zp = (getCrystPar(0)*std::abs(std::sin(angle)) - getCrystTol()) * mm; 220 rotstr = idName + "Crystal" + i; 222 rotstr = idName + "Crystal" + i; 221 rot = rotfact->findMatrix(rotstr); 223 rot = rotfact->findMatrix(rotstr); 222 if (!rot) { 224 if (!rot) { 223 #ifdef ddebug 225 #ifdef ddebug 224 G4cout << "Creating a new rotation: " << 226 G4cout << "Creating a new rotation: " << rotstr << tab << 90.0*deg << "," 225 << 0.0*deg << "," << (90.0*deg+angl << 227 << 0.0*deg << "," << (90.0*deg+angle) << "," << 0.0*deg << "," 226 << angle << "," << 90.0*deg << G4en << 228 << angle << "," << 90.0*deg << G4endl; 227 #endif 229 #endif 228 rot = rotfact->AddMatrix(rotstr, 90.0*de 230 rot = rotfact->AddMatrix(rotstr, 90.0*deg, 0.0*deg, (90.0*deg+angle), 229 90.0*deg, angle << 231 90.0*deg, angle, 90.0*deg); 230 } 232 } 231 new G4PVPlacement(rot, G4ThreeVector(0,yp, 233 new G4PVPlacement(rot, G4ThreeVector(0,yp,zp), detLog, name, laylog, 232 false, i+1); << 234 false, i+1); 233 #ifdef pdebug 235 #ifdef pdebug 234 G4cout << detLog->GetName() << " number " 236 G4cout << detLog->GetName() << " number " << i+1 << " positioned in " 235 << laylog->GetName() << " at (0," << 237 << laylog->GetName() << " at (0," << yp << "," << zp 236 << ") with rotation angle " << angle/ << 238 << ") with rotation angle " << angle/deg << G4endl; 237 #endif 239 #endif 238 } 240 } 239 241 240 //Support boxes 242 //Support boxes 241 name = idName + "Support"; 243 name = idName + "Support"; 242 matter = matfact->findMaterial(getSuppMat()) 244 matter = matfact->findMaterial(getSuppMat()); 243 solid = new G4Box (name, 0.5*getDxSupp()*mm 245 solid = new G4Box (name, 0.5*getDxSupp()*mm, 0.5*getDySupp()*mm, 244 0.5*getDzSupp()*mm); << 246 0.5*getDzSupp()*mm); 245 #ifdef debug 247 #ifdef debug 246 G4cout << tab << name << " Box made of " << 248 G4cout << tab << name << " Box made of " << getSuppMat() << " of dimension " 247 << 0.5*getDxSupp()*mm << ", " << 0.5*ge 249 << 0.5*getDxSupp()*mm << ", " << 0.5*getDySupp()*mm << ", " 248 << 0.5*getDzSupp()*mm << G4endl; 250 << 0.5*getDzSupp()*mm << G4endl; 249 #endif 251 #endif 250 G4LogicalVolume* slog = new G4LogicalVolume 252 G4LogicalVolume* slog = new G4LogicalVolume (solid, matter, name); 251 setVisType(CCalVisualisable::Support,slog); 253 setVisType(CCalVisualisable::Support,slog); 252 254 253 zp = (-0.5 * getLengBox() + getCrystLength 255 zp = (-0.5 * getLengBox() + getCrystLength() + getLengFront() + 254 0.5 * getDzSupp() + getDistSupp()) * << 256 0.5 * getDzSupp() + getDistSupp()) * mm; 255 for (i = 0; i < getCrystNum(); i++) { 257 for (i = 0; i < getCrystNum(); i++) { 256 yp = getLayPar(1) * (2*i + 1 - getCrystN 258 yp = getLayPar(1) * (2*i + 1 - getCrystNum()) * mm; 257 new G4PVPlacement(0, G4ThreeVector(0,yp,zp 259 new G4PVPlacement(0, G4ThreeVector(0,yp,zp), slog, name, glog, 258 false, i+1); << 260 false, i+1); 259 #ifdef pdebug 261 #ifdef pdebug 260 G4cout << slog->GetName() << " number " << 262 G4cout << slog->GetName() << " number " << i+1 << " positioned in " 261 << glog->GetName() << " at (0," << y 263 << glog->GetName() << " at (0," << yp << "," << zp 262 << ") with no rotation" << G4endl; << 264 << ") with no rotation" << G4endl; 263 #endif 265 #endif 264 } 266 } 265 267 266 return glog; 268 return glog; 267 } 269 } 268 270 269 << 270 void CCalG4Ecal::constructSensitive() { 271 void CCalG4Ecal::constructSensitive() { >> 272 271 #ifdef debug 273 #ifdef debug 272 G4cout << "Now registering CrystalMatrix Log 274 G4cout << "Now registering CrystalMatrix LogicalVolume's to SD's:" << G4endl; 273 #endif 275 #endif 274 if (sensitiveLogs.size()>0) { 276 if (sensitiveLogs.size()>0) { 275 CCalSensitiveDetectors* sensDets = CCalSen 277 CCalSensitiveDetectors* sensDets = CCalSensitiveDetectors::getInstance(); 276 G4String SDname = idName; 278 G4String SDname = idName; 277 for(std::vector<ptrG4Log>::iterator iter=s 279 for(std::vector<ptrG4Log>::iterator iter=sensitiveLogs.begin(); 278 iter<sensit << 280 iter<sensitiveLogs.end(); iter++) { 279 sensDets->registerVolume(SDname, (*iter) 281 sensDets->registerVolume(SDname, (*iter)); 280 #ifdef sdebug 282 #ifdef sdebug 281 G4cout << "Register volume " << (*iter)- 283 G4cout << "Register volume " << (*iter)->GetName() << " for" << SDname 282 << G4endl; << 284 << G4endl; 283 #endif 285 #endif 284 } 286 } 285 } 287 } >> 288 286 } 289 } >> 290 >> 291 287 292