Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 ////////////////////////////////////////////// 27 // File: CCalG4Ecal.cc 28 // Description: CCalG4Ecal Factory class to co 29 // electromagnetic calorimeter 30 ////////////////////////////////////////////// 31 32 #include <cmath> 33 34 #include "CCalG4Ecal.hh" 35 36 #include "CCalMaterialFactory.hh" 37 #include "CCalRotationMatrixFactory.hh" 38 #include "CCalSensitiveDetectors.hh" 39 40 #include "CCalutils.hh" 41 42 #include "G4SystemOfUnits.hh" 43 #include "G4ThreeVector.hh" 44 #include "G4Box.hh" 45 #include "G4Trd.hh" 46 47 #include "G4LogicalVolume.hh" 48 #include "G4PVPlacement.hh" 49 50 //#define debug 51 //#define ddebug 52 //#define pdebug 53 //#define sdebug 54 55 //Initialize static logical volumes 56 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog 57 58 //Initialize static prefix name 59 G4String CCalG4Ecal::idName = "CrystalMatrix"; 60 61 62 CCalG4Ecal::CCalG4Ecal(const G4String &name) : 63 64 65 CCalG4Ecal::~CCalG4Ecal() {} 66 67 68 G4VPhysicalVolume* CCalG4Ecal::constructIn( G4 69 G4cout << "==>> Constructing CCalG4Ecal..." 70 71 // Construction of global volume as a Box 72 73 if (!crystalmatrixLog) { 74 crystalmatrixLog = constructGlobal(); 75 } 76 CCalRotationMatrixFactory* rotfact = CCalRot 77 78 G4double x, y, z; 79 if (mother != 0) { 80 x = getXpos()*mm; 81 y = getYpos()*mm; 82 z = getZpos()*mm; 83 } else { 84 x = y = z = 0; 85 } 86 87 int num; 88 if (type == module2) { 89 num = 2; 90 } else { 91 num = 1; 92 } 93 #ifdef pdebug 94 G4String name("Null"); 95 if (mother != 0) name = mother->GetName(); 96 G4cout << crystalmatrixLog->GetName() << " N 97 << name << " at (" << x << ", " << y << 98 #endif 99 100 G4RotationMatrix* cmrot = 0; 101 if (mother != 0) { 102 G4String rotstr = idName + num; 103 cmrot = rotfact->findMatrix(rotstr); 104 if (!cmrot) { 105 #ifdef ddebug 106 G4cout << "Creating a new rotation: " << 107 << getThetaX()*deg << "," << getPhi 108 << getThetaY()*deg << "," << getPhi 109 << getThetaZ()*deg << "," << getPhi 110 #endif 111 cmrot = rotfact->AddMatrix(rotstr, getTh 112 getThetaY()*d 113 getThetaZ()*d 114 } // if !cmrot 115 #ifdef pdebug 116 G4cout << " rotation by (" << getThetaX() 117 << getThetaY() << "," << getPhiY() << 118 << getPhiZ() << ")" << G4endl; 119 #endif 120 } else { 121 #ifdef pdebug 122 G4cout << " without rotation..." << G4endl 123 #endif 124 } 125 126 G4PVPlacement* crystalmatrix; 127 if (mother != 0) { 128 crystalmatrix = new G4PVPlacement(cmrot, G 129 crystalm 130 mother-> 131 } else { 132 crystalmatrix = new G4PVPlacement(cmrot, G 133 idName, 134 mother, 135 } 136 G4cout << "<<== End of CCalG4Ecal constructi 137 138 return crystalmatrix; 139 } 140 141 142 G4LogicalVolume* CCalG4Ecal::constructGlobal() 143 144 //Pointers to the Materials and Rotation Mat 145 CCalMaterialFactory* matfact = CCalMat 146 CCalRotationMatrixFactory* rotfact = CCalRot 147 148 G4Material* matter = matfact->findMaterial(g 149 G4VSolid* solid = new G4Box (idName, 0.5*get 150 0.5*getLengBox( 151 #ifdef debug 152 G4cout << tab << idName << " Box made of " < 153 << 0.5*getWidBox()*mm << ", " << 0.5*ge 154 << 0.5*getLengBox()*mm << G4endl; 155 #endif 156 G4LogicalVolume* glog = new G4LogicalVolume 157 setVisType(CCalVisualisable::PseudoVolumes,g 158 159 //Now the layers 160 G4String name = idName + "Layer"; 161 matter = matfact->findMaterial(getLayMat()); 162 solid = new G4Trd(name, getLayPar(0)*mm, ge 163 getLayPar(3)*mm, getLayPa 164 #ifdef debug 165 G4cout << tab << name << " Trd made of " << 166 << getLayPar(0)*mm << ", " << getLayPar 167 << ", " << getLayPar(3)*mm << ", " << g 168 #endif 169 G4LogicalVolume* laylog = new G4LogicalVolum 170 setVisType(CCalVisualisable::OtherServices,l 171 172 G4int i = 0; 173 G4String rotstr; 174 G4double xp, yp, zp, angle; 175 G4double zshift = -0.5 * (getLengBox() - get 176 G4RotationMatrix* rot = 0; 177 for (i = 0; i < getLayNum(); i++) { 178 angle = 0.5 * getLayAngle() * (2*i + 1 - 179 xp = angle * (getLayPar(4) + getLayRad 180 zp = (zshift + getLayPar(0)*std::abs(s 181 rotstr = idName + "Layer" + i; 182 rot = rotfact->findMatrix(rotstr); 183 if (!rot) { 184 #ifdef ddebug 185 G4cout << "Creating a new rotation: " << 186 << (90.0*deg+angle) << "," << 0.0*d 187 << 90.0*deg << "," << angle << "," 188 #endif 189 rot = rotfact->AddMatrix(rotstr, (90.0*d 190 90.0*deg, angle 191 } 192 new G4PVPlacement(rot, G4ThreeVector(xp,0. 193 false, i+1); 194 #ifdef pdebug 195 G4cout << laylog->GetName() << " number " 196 << glog->GetName() << " at (" << xp 197 << ") with rotation angle " << angle/ 198 #endif 199 } 200 201 //Now the crystals 202 name = idName + "Crystal"; 203 matter = matfact->findMaterial(getCrystMat() 204 solid = new G4Trd(name, getCrystPar(0)*mm, 205 getCrystPar(2)*mm, getCry 206 #ifdef debug 207 G4cout << tab << name << " Trd made of " << 208 << getCrystPar(0)*mm << ", " << getCrys 209 << getCrystPar(2)*mm << ", " << getCrys 210 << getCrystPar(4)*mm << G4endl; 211 #endif 212 213 G4LogicalVolume* detLog = new G4LogicalVolum 214 setVisType(CCalVisualisable::Sensitive,detLo 215 sensitiveLogs.push_back(detLog); 216 for (i = 0; i < getCrystNum(); i++) { 217 angle = 0.5 * getLayAngle() * (2*i + 1 - 218 yp = angle * (getCrystPar(4) + getLayR 219 zp = (getCrystPar(0)*std::abs(std::sin 220 rotstr = idName + "Crystal" + i; 221 rot = rotfact->findMatrix(rotstr); 222 if (!rot) { 223 #ifdef ddebug 224 G4cout << "Creating a new rotation: " << 225 << 0.0*deg << "," << (90.0*deg+angl 226 << angle << "," << 90.0*deg << G4en 227 #endif 228 rot = rotfact->AddMatrix(rotstr, 90.0*de 229 90.0*deg, angle 230 } 231 new G4PVPlacement(rot, G4ThreeVector(0,yp, 232 false, i+1); 233 #ifdef pdebug 234 G4cout << detLog->GetName() << " number " 235 << laylog->GetName() << " at (0," << 236 << ") with rotation angle " << angle/ 237 #endif 238 } 239 240 //Support boxes 241 name = idName + "Support"; 242 matter = matfact->findMaterial(getSuppMat()) 243 solid = new G4Box (name, 0.5*getDxSupp()*mm 244 0.5*getDzSupp()*mm); 245 #ifdef debug 246 G4cout << tab << name << " Box made of " << 247 << 0.5*getDxSupp()*mm << ", " << 0.5*ge 248 << 0.5*getDzSupp()*mm << G4endl; 249 #endif 250 G4LogicalVolume* slog = new G4LogicalVolume 251 setVisType(CCalVisualisable::Support,slog); 252 253 zp = (-0.5 * getLengBox() + getCrystLength 254 0.5 * getDzSupp() + getDistSupp()) * 255 for (i = 0; i < getCrystNum(); i++) { 256 yp = getLayPar(1) * (2*i + 1 - getCrystN 257 new G4PVPlacement(0, G4ThreeVector(0,yp,zp 258 false, i+1); 259 #ifdef pdebug 260 G4cout << slog->GetName() << " number " << 261 << glog->GetName() << " at (0," << y 262 << ") with no rotation" << G4endl; 263 #endif 264 } 265 266 return glog; 267 } 268 269 270 void CCalG4Ecal::constructSensitive() { 271 #ifdef debug 272 G4cout << "Now registering CrystalMatrix Log 273 #endif 274 if (sensitiveLogs.size()>0) { 275 CCalSensitiveDetectors* sensDets = CCalSen 276 G4String SDname = idName; 277 for(std::vector<ptrG4Log>::iterator iter=s 278 iter<sensit 279 sensDets->registerVolume(SDname, (*iter) 280 #ifdef sdebug 281 G4cout << "Register volume " << (*iter)- 282 << G4endl; 283 #endif 284 } 285 } 286 } 287