Belle II Software development
GeoECLCreator.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include "G4Transform3D.hh"
10#include "G4PVPlacement.hh"
11#include "G4SDManager.hh"
12#include "G4UserLimits.hh"
13#include <G4VisAttributes.hh>
14#include <G4Box.hh>
15
16#include <ecl/geometry/GeoECLCreator.h>
17#include <ecl/geometry/shapes.h>
18#include <ecl/simulation/SensitiveDetector.h>
19#include <geometry/CreatorFactory.h>
20#include <geometry/Materials.h>
21#include <framework/gearbox/GearDir.h>
22#include "ecl/dbobjects/ECLCrystalsShapeAndPosition.h"
23#include <framework/database/IntervalOfValidity.h>
24#include <framework/database/Database.h>
25#include <framework/database/DBObjPtr.h>
26#include <framework/logging/Logger.h>
27
28using namespace Belle2;
29using namespace Belle2::geometry;
30using namespace ECL;
31
32//-----------------------------------------------------------------
33// Register the GeoCreator
34//-----------------------------------------------------------------
35
36CreatorFactory<GeoECLCreator> GeoECLFactory("ECLCreator");
37
38//-----------------------------------------------------------------
39// Implementation
40//-----------------------------------------------------------------
41
42
43GeoECLCreator::GeoECLCreator(): m_sap(0), m_overlap(0)
44{
45 m_sensediode = nullptr;
46 m_sensitive = new SensitiveDetector("ECLSensitiveDetector", (2 * 24)*CLHEP::eV, 10 * CLHEP::MeV);
47 G4SDManager::GetSDMpointer()->AddNewDetector(m_sensitive);
49}
50
51
53{
54 for (auto a : m_atts) delete a.second;
55}
56
57void GeoECLCreator::createFromDB(const std::string&, G4LogicalVolume& topVolume, geometry::GeometryTypes)
58{
59 m_sensediode = new SensitiveDiode("ECLSensitiveDiode");
60 G4SDManager::GetSDMpointer()->AddNewDetector(m_sensediode);
61
63 if (!crystals.isValid()) B2FATAL("No crystal's data in the database.");
64 m_sap = &(*crystals);
65
66 forward(topVolume);
67 barrel(topVolume);
68 backward(topVolume);
69}
70
72{
73 ECLCrystalsShapeAndPosition crystals = loadCrystalsShapeAndPosition();
75}
76
77void GeoECLCreator::create(const GearDir&, G4LogicalVolume& topVolume, geometry::GeometryTypes)
78{
79 m_sensediode = new SensitiveDiode("ECLSensitiveDiode");
80 G4SDManager::GetSDMpointer()->AddNewDetector(m_sensediode);
81
82 ECLCrystalsShapeAndPosition crystals = loadCrystalsShapeAndPosition();
83 m_sap = &crystals;
84
85 forward(topVolume);
86 barrel(topVolume);
87 backward(topVolume);
88}
89
90G4LogicalVolume* GeoECLCreator::wrapped_crystal(const shape_t* s, const std::string& endcap, double wrapthickness)
91{
92 std::string prefix("sv_"); prefix += endcap; prefix += "_wrap";
93 G4Translate3D tw;
94 G4VSolid* wrapped_crystal = s->get_solid(prefix, wrapthickness, tw);
95 std::string name("lv_"); name += endcap + "_wrap_" + std::to_string(s->nshape);
96 G4Material* wrap = nullptr;
97 if (wrapthickness < 0.170)
98 wrap = Materials::get("WRAP170");
99 else if (wrapthickness < 0.200)
100 wrap = Materials::get("WRAP200");
101 else
102 wrap = Materials::get("WRAP250");
103 G4LogicalVolume* wrapped_logical = new G4LogicalVolume(wrapped_crystal, wrap, name.c_str(), 0, 0, 0);
104 wrapped_logical->SetVisAttributes(att("wrap"));
105
106 prefix = "sv_"; prefix += endcap; prefix += "_crystal";
107 G4Translate3D tc;
108 G4VSolid* crystal_solid = s->get_solid(prefix, 0, tc);
109 name = "lv_" + endcap + "_crystal_" + std::to_string(s->nshape);
110 G4LogicalVolume* crystal_logical = new G4LogicalVolume(crystal_solid, Materials::get("G4_CESIUM_IODIDE"), name.c_str(),
111 0, 0, 0);
112 crystal_logical->SetVisAttributes(att("cryst"));
113 crystal_logical->SetSensitiveDetector(m_sensitive);
114
115 new G4PVPlacement(nullptr, G4ThreeVector(), crystal_logical, name.c_str(), wrapped_logical, false, 0, 0);
116 return wrapped_logical;
117}
118
120{
121 m_atts["wrap"] = new G4VisAttributes(G4Colour(0.5, 0.5, 1.0));
122 m_atts["cryst"] = new G4VisAttributes(G4Colour(0.7, 0.7, 1.0));
123
124 m_atts["iron"] = new G4VisAttributes(G4Colour(1., 0.1, 0.1));
125 m_atts["iron2"] = new G4VisAttributes(G4Colour(1., 0.5, 0.5));
126 m_atts["alum"] = new G4VisAttributes(G4Colour(0.25, 0.25, 1.0, 0.5));
127 m_atts["alum2"] = new G4VisAttributes(G4Colour(0.5, 0.5, 1.0));
128 m_atts["silv"] = new G4VisAttributes(G4Colour(0.9, 0., 0.9));
129 m_atts["air"] = new G4VisAttributes(G4Colour(1., 1., 1.));
130 m_atts["air"]->SetVisibility(false);
131 m_atts["preamp"] = new G4VisAttributes(G4Colour(0.1, 0.1, 0.8));
132 m_atts["plate"] = new G4VisAttributes(G4Colour(0.2, 0.8, 0.2));
133 m_atts["connector"] = new G4VisAttributes(G4Colour(0.1, 0.1, 0.1));
134 m_atts["capacitor"] = new G4VisAttributes(G4Colour(0.1, 0.1, 0.8));
135 m_atts["holder"] = new G4VisAttributes(G4Colour(0.4, 0.8, 0.8));
136 m_atts["asolid6"] = new G4VisAttributes(G4Colour(1., 0.3, 0.2));
137 m_atts["asolid7"] = new G4VisAttributes(G4Colour(1., 0.3, 0.2));
138 m_atts["asolid13"] = new G4VisAttributes(G4Colour(1., 0.5, 0.5));
139}
140
141const G4VisAttributes* GeoECLCreator::att(const std::string& n) const
142{
143 auto p = m_atts.find(n);
144 assert(p != m_atts.end());
145 return p->second;
146}
147
148G4LogicalVolume* GeoECLCreator::get_preamp() const
149{
150 static G4LogicalVolume* lv_preamplifier = nullptr;
151 if (lv_preamplifier == nullptr) {
152 G4VSolid* sv_preamplifier = new G4Box("sv_preamplifier", 58. / 2, 51. / 2, get_pa_box_height() / 2);
153 lv_preamplifier = new G4LogicalVolume(sv_preamplifier, Materials::get("A5052"), "lv_preamplifier", 0, 0, 0);
154 G4VSolid* sv_diode = new G4Box("sv_diode", 20. / 2, 20. / 2, 0.3 / 2);
155 G4LogicalVolume* lv_diode = new G4LogicalVolume(sv_diode, Materials::get("G4_Si"), "lv_diode", 0, 0, 0);
156 lv_diode->SetUserLimits(new G4UserLimits(0.01));
157 lv_diode->SetSensitiveDetector(m_sensediode);
158 new G4PVPlacement(G4TranslateZ3D(-get_pa_box_height() / 2 + 0.3 / 2), lv_diode, "pv_diode", lv_preamplifier, false, 0, m_overlap);
159
160 // G4VSolid* sv_diode = new G4Box("sv_diode", 10. / 2, 20. / 2, 0.3 / 2);
161 // G4LogicalVolume* lv_diode = new G4LogicalVolume(sv_diode, Materials::get("G4_Si"), "lv_diode", 0, 0, 0);
162 // lv_diode->SetUserLimits(new G4UserLimits(0.01));
163 // new G4PVPlacement(G4Translate3D(-5, 0, -pa_box_height / 2 + 0.3 / 2), lv_diode, "pv_diode1", lv_preamplifier, false, 1, overlap);
164 // new G4PVPlacement(G4Translate3D(5, 0, -pa_box_height / 2 + 0.3 / 2), lv_diode, "pv_diode2", lv_preamplifier, false, 2, overlap);
165
166 lv_preamplifier->SetVisAttributes(att("preamp"));
167 }
168 return lv_preamplifier;
169}
170
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
void barrel(G4LogicalVolume &)
Make the ECL barrel and then place elements inside it.
Definition: barrel.cc:63
void defineVisAttributes()
Define visual attributes.
Simulation::SensitiveDetectorBase * m_sensediode
Sensitive diode.
Definition: GeoECLCreator.h:96
double get_pa_box_height() const
Getter for preamplifier box height (hard-coded to be 2)
Definition: GeoECLCreator.h:88
const G4VisAttributes * att(const std::string &n) const
Define visual attributes.
virtual void createFromDB(const std::string &name, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
Function to create the geometry from the Database.
virtual void createPayloads(const GearDir &content, const IntervalOfValidity &iov) override
Function to create the geometry database.
void backward(G4LogicalVolume &)
Place elements inside the backward endcap.
Definition: backward.cc:42
~GeoECLCreator()
The destructor of the GeoECLCreator class.
const ECLCrystalsShapeAndPosition * m_sap
pointer to a storage with crystal shapes and positions
Definition: GeoECLCreator.h:91
std::map< std::string, G4VisAttributes * > m_atts
Vector of background-Sensitive detectors.
Definition: GeoECLCreator.h:98
Simulation::SensitiveDetectorBase * m_sensitive
Sensitive detector.
Definition: GeoECLCreator.h:94
G4LogicalVolume * get_preamp() const
Get Logical volume of preamplifier.
G4LogicalVolume * wrapped_crystal(const shape_t *s, const std::string &endcap, double wrapthickness)
Wrapped crystal.
void forward(G4LogicalVolume &)
Place elements inside the forward endcap.
Definition: forward.cc:44
GeoECLCreator()
Constructor of the GeoECLCreator class.
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
Function to actually create the geometry, has to be overridden by derived classes.
Class for ECL Sensitive Detector.
Class for ECL Sensitive Detector.
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
A class that describes the interval of experiments/runs for which an object in the database is valid.
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141
Common code concerning the geometry representation of the detector.
Definition: CreatorBase.h:25
GeometryTypes
Flag indiciating the type of geometry to be used.
Abstract base class for different kinds of events.
Very simple class to provide an easy way to register creators with the CreatorManager.