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