Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:35

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 #include "Par04Hit.hh"
0027 
0028 #include "G4AttDef.hh"  // for G4AttDef
0029 #include "G4AttDefStore.hh"  // for GetInstance
0030 #include "G4AttValue.hh"  // for G4AttValue
0031 #include "G4Colour.hh"  // for G4Colour
0032 #include "G4SystemOfUnits.hh"  // for mm, MeV, cm, rad
0033 #include "G4Tubs.hh"  // for G4Tubs
0034 #include "G4UnitsTable.hh"  // for G4BestUnit
0035 #include "G4VVisManager.hh"  // for G4VVisManager
0036 #include "G4VisAttributes.hh"  // for G4VisAttributes
0037 
0038 #include <CLHEP/Units/SystemOfUnits.h>  // for mm, pi, MeV, cm, rad
0039 #include <CLHEP/Vector/ThreeVector.h>  // for operator/, operator<<, Hep...
0040 #include <G4RotationMatrix.hh>  // for G4RotationMatrix
0041 #include <G4String.hh>  // for G4String
0042 #include <G4ThreeVector.hh>  // for G4ThreeVector
0043 #include <G4Transform3D.hh>  // for G4Transform3D
0044 #include <G4VHit.hh>  // for G4VHit
0045 #include <algorithm>  // for max
0046 #include <cmath>  // for log10
0047 #include <iostream>  // for operator<<, basic_ostream:...
0048 #include <string>  // for operator<
0049 template<class Type>
0050 class G4Allocator;
0051 
0052 G4ThreadLocal G4Allocator<Par04Hit>* Par04HitAllocator;
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 Par04Hit::Par04Hit() : G4VHit() {}
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 Par04Hit::~Par04Hit() = default;
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 Par04Hit::Par04Hit(const Par04Hit& aRight) : G4VHit()
0065 {
0066   fEdep = aRight.fEdep;
0067   fNdep = aRight.fNdep;
0068   fZId = aRight.fZId;
0069   fRhoId = aRight.fRhoId;
0070   fPhiId = aRight.fPhiId;
0071   fTime = aRight.fTime;
0072   fPos = aRight.fPos;
0073   fRot = aRight.fRot;
0074   fType = aRight.fType;
0075   fLogVol = aRight.fLogVol;
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 const Par04Hit& Par04Hit::operator=(const Par04Hit& aRight)
0081 {
0082   fEdep = aRight.fEdep;
0083   fNdep = aRight.fNdep;
0084   fZId = aRight.fZId;
0085   fRhoId = aRight.fRhoId;
0086   fPhiId = aRight.fPhiId;
0087   fTime = aRight.fTime;
0088   fPos = aRight.fPos;
0089   fRot = aRight.fRot;
0090   fType = aRight.fType;
0091   fLogVol = aRight.fLogVol;
0092   return *this;
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 int Par04Hit::operator==(const Par04Hit& aRight) const
0098 {
0099   return (fRhoId == aRight.fRhoId && fPhiId == aRight.fPhiId && fZId == aRight.fZId);
0100 }
0101 
0102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0103 
0104 void Par04Hit::Draw()
0105 {
0106   /// Arbitrary size corresponds to the example macros
0107   G4ThreeVector meshSize(2.325 * mm, 2 * CLHEP::pi / 50. * CLHEP::rad, 3.4 * mm);
0108   G4int numPhiCells = CLHEP::pi * 2. / meshSize.y();
0109   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
0110   // Hits can be filtered out in visualisation
0111   if (!pVVisManager->FilterHit(*this)) return;
0112   // Do not plot hits from parallel world
0113   if (fType >= 2) return;
0114   // Do not draw empty hits
0115   if (fEdep <= 0) return;
0116   // Do not plot if default values were not changed
0117   if (fRhoId == -1 && fZId == -1 && fPhiId == -1) return;
0118   if (pVVisManager) {
0119     G4Transform3D trans(fRot, fPos);
0120     G4VisAttributes attribs;
0121     G4Tubs solid("draw", fRhoId * meshSize.x(), (fRhoId + 1) * meshSize.x(), meshSize.z() / 2.,
0122                  (-numPhiCells / 2. + fPhiId) * meshSize.y(), meshSize.y());
0123     // Set colours depending on type of hit (full/fast sim)
0124     G4double colR = fType == 0 ? 0 : 1;
0125     G4double colG = fType == 0 ? 1 : 0;
0126     G4double colB = 0;
0127     // Set transparency depending on the energy
0128     // Arbitrary formula
0129     G4double alpha = 2 * std::log10(fEdep + 1);
0130     G4Colour colour(colR, colG, colB, alpha);
0131     attribs.SetColour(colour);
0132     attribs.SetForceSolid(true);
0133     pVVisManager->Draw(solid, attribs, trans);
0134   }
0135 }
0136 
0137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0138 
0139 const std::map<G4String, G4AttDef>* Par04Hit::GetAttDefs() const
0140 {
0141   G4bool isNew;
0142   std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Par04Hit", isNew);
0143   if (isNew) {
0144     (*store)["HitType"] = G4AttDef("HitType", "Hit Type", "Physics", "", "G4String");
0145     (*store)["Energy"] =
0146       G4AttDef("Energy", "Energy Deposited", "Physics", "G4BestUnit", "G4double");
0147     (*store)["Time"] = G4AttDef("Time", "Time", "Physics", "G4BestUnit", "G4double");
0148     (*store)["Pos"] = G4AttDef("Pos", "Position", "Physics", "G4BestUnit", "G4ThreeVector");
0149   }
0150   return store;
0151 }
0152 
0153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0154 
0155 std::vector<G4AttValue>* Par04Hit::CreateAttValues() const
0156 {
0157   std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
0158   values->push_back(G4AttValue("HitType", "HadPar04Hit", ""));
0159   values->push_back(G4AttValue("Energy", G4BestUnit(fEdep, "Energy"), ""));
0160   values->push_back(G4AttValue("Time", G4BestUnit(fTime, "Time"), ""));
0161   values->push_back(G4AttValue("Pos", G4BestUnit(fPos, "Length"), ""));
0162   return values;
0163 }
0164 
0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0166 
0167 void Par04Hit::Print()
0168 {
0169   std::cout << "\tHit " << fEdep / MeV << " MeV from " << fNdep << " deposits at " << fPos / cm
0170             << " cm rotation " << fRot << " (R,phi,z)= (" << fRhoId << ", " << fPhiId << ", "
0171             << fZId << "), " << fTime << " ns" << std::endl;
0172 }