Belle II Software development
GeoARICHBtestCreator.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#include <sstream>
9#include <string.h>
10
11//#include <geant4/G4LogicalVolume.hh>
12
13// Geant4
14#include <G4LogicalVolume.hh>
15#include <G4PVPlacement.hh>
16#include <G4LogicalSkinSurface.hh>
17#include <G4OpticalSurface.hh>
18// Geant4 Shapes
19#include <G4Box.hh>
20#include <G4SubtractionSolid.hh>
21#include <G4Material.hh>
22
23#include <Python.h>
24
25#include <arich/geometry/GeoARICHBtestCreator.h>
26#include <arich/geometry/ARICHGeometryPar.h>
27#include <arich/geometry/ARICHBtestGeometryPar.h>
28
29#include <geometry/Materials.h>
30#include <geometry/CreatorFactory.h>
31#include <geometry/utilities.h>
32#include <framework/gearbox/GearDir.h>
33#include <framework/gearbox/Unit.h>
34#include <framework/logging/Logger.h>
35// Framework - DataStore
36#include <framework/datastore/StoreObjPtr.h>
37#include <framework/dataobjects/EventMetaData.h>
38
39#include <arich/simulation/SensitiveDetector.h>
40#include <arich/simulation/SensitiveAero.h>
41
42using namespace std;
43
44namespace Belle2 {
50 using namespace geometry;
51
52 namespace arich {
53
54 //-----------------------------------------------------------------
55 // Register the Creator
56 //-----------------------------------------------------------------
57
58 geometry::CreatorFactory<GeoARICHBtestCreator> GeoARICHBtestFactory("ARICHBtestCreator");
59
60 //-----------------------------------------------------------------
61 // Implementation
62 //-----------------------------------------------------------------
63
65 m_sensitive(new SensitiveDetector),
66 m_sensitiveAero(new SensitiveAero),
67 m_runno(0),
68 m_neve(0),
69 m_rotation(0),
70 m_rx(0),
71 m_ry(0),
72 m_aerosupport(0),
73 m_aerogeldx(0),
74 m_framedx(0),
75 m_rotation1(0),
76 m_configuration(0)
77 {};
78
80 {
81
82 }
83
84
85 void GeoARICHBtestCreator::create(const GearDir& content, G4LogicalVolume& topVolume, GeometryTypes)
86 {
87
88 B2INFO("GeoARICHBtestCreator::create");
89 StoreObjPtr<EventMetaData> eventMetaDataPtr;
90
91 int run = 68;
92 PyObject* m = PyImport_AddModule(strdup("__main__"));
93 if (m) {
94 PyObject* v = PyObject_GetAttrString(m, strdup("runno"));
95 if (v) {
96 run = PyLong_AsLong(v);
97 Py_DECREF(v);
98 }
99 B2INFO("GeoARICHBtestCreator::create runno = " << run);
100 }
101
102 B2INFO("eventMetaDataPtr run:" << run);
103 // eventMetaDataPtr->setEndOfData();
104
105
106
107
108 string Type = content.getString("@type", "");
109
110 char nodestr[100];
111 sprintf(nodestr, "run[runno=%d]", run);
112 if (Type == "beamtest") {
113 for (const GearDir& runparam : content.getNodes(nodestr)) {
114 m_runno = runparam.getInt("runno", -1);
115 m_author = runparam.getString("author", "");
116 m_neve = runparam.getInt("neve", -1);
117 m_runtype = runparam.getString("calibration", "pion");
118 m_hapdID = runparam.getString("setup1", "unknown");
119 m_aerogelID = runparam.getString("aerogel1", "unknown");
120 m_mirrorID = runparam.getString("mirror", "unknown");
121 m_rotation = runparam.getDouble("rotation", 0);
122 m_rx = runparam.getDouble("positionx", 0);
123 m_ry = runparam.getDouble("positiony", 0);
124 m_mytype = runparam.getString("type1", "unknown");
125 m_daqqa = runparam.getString("daqqa1", "unknown");
126 m_comment = runparam.getString("comment1", "unknown");
127 m_datum = runparam.getString("datum", "unknown");
128
129
130 B2INFO("runno : " << m_runno);
131 B2INFO("author : " << m_author);
132 B2INFO("neve : " << m_neve);
133 B2INFO("runtype : " << m_runtype);
134 B2INFO("hapdID : " << m_hapdID);
135 B2INFO("aerogelID: " << m_aerogelID);
136 B2INFO("mirrorID : " << m_mirrorID);
137 B2INFO("rotation : " << m_rotation);
138 B2INFO("rx : " << m_rx);
139 B2INFO("ry : " << m_ry);
140 B2INFO("runtype : " << m_mytype);
141 B2INFO("daqqa : " << m_daqqa);
142 B2INFO("comment : " << m_comment);
143 B2INFO("datum : " << m_datum);
144
145
146 }
147 string aerogelname;
148 sprintf(nodestr, "setup/aerogel/row[@id=\"%s\"]", m_aerogelID.c_str());
149
150 GearDir runparam(content, nodestr);
151 B2INFO("id : " << runparam.getString("@id", ""));
152 for (const GearDir& aeroparam : runparam.getNodes("aerogel")) {
153 aerogelname = aeroparam.getString(".", "");
154 string stype = aeroparam.getString("@type", "");
155 B2INFO(stype << " aerogelname : " << aerogelname);
156 sprintf(nodestr, "setup/aerogelinfo/row[@id=\"%s\"]", aerogelname.c_str());
157 GearDir infoparam(content, nodestr);
158
159 double agelrefind = infoparam.getDouble("refind", 1);
160 double ageltrlen = infoparam.getLength("trlen", 0);
161 double agelthickness = infoparam.getLength("thickness", 0);
162 if (stype != string("left")) {
163 m_ageltrlen.push_back(ageltrlen);
164 m_agelrefind.push_back(agelrefind);
165 m_agelthickness.push_back(agelthickness);
166 }
167 B2INFO("refind : " << agelrefind);
168 B2INFO("trlen : " << ageltrlen / Unit::mm);
169 B2INFO("thickness : " << agelthickness / Unit::mm);
170
171 }
172 int size = m_hapdID.size();
173
174 m_aerosupport = 0;
175 if (size > 0) {
176 char agelsupport = m_hapdID.at(size - 1);
177 if (agelsupport == 'a') m_aerosupport = 1;
178 if (agelsupport == 'b') m_aerosupport = 2;
179 }
180
181 if (m_aerosupport) size--;
182 sprintf(nodestr, "setup/hapd/row[@id=\"%s\"]", m_hapdID.substr(0, size).c_str());
183 B2INFO("nodestr : " << nodestr);
184 B2INFO("aerogelsupport : " << m_aerosupport);
185 GearDir hapdparam(content, nodestr);
186 //for (const GearDir& runparam : content.getNodes(nodestr)) {
187 m_aerogeldx = hapdparam.getLength("aerogeldx", 0);
188 m_framedx = hapdparam.getLength("framedx", 0) * CLHEP::mm / Unit::mm ;
189 m_rotation1 = hapdparam.getDouble("rotation", 0);
190 m_configuration = hapdparam.getInt("setup", 0);
191 m_comment1 = hapdparam.getString("comment", "");
192
193
194 B2INFO("aerogeldx : " << m_aerogeldx);
195 B2INFO("framedx : " << m_framedx);
196 B2INFO("rotation : " << m_rotation1);
197 B2INFO("configuration : " << m_configuration);
198 B2INFO("comment : " << m_comment);
199 //}
200
201 GearDir setup(content, "setup");
202
203 createBtestGeometry(setup, topVolume);
204 }
205 }
206
207 double GeoARICHBtestCreator::getAvgRINDEX(G4Material* material)
208 {
209 G4MaterialPropertiesTable* mTable = material->GetMaterialPropertiesTable();
210 if (!mTable) return 0;
211 G4MaterialPropertyVector* mVector = mTable->GetProperty("RINDEX");
212 if (!mVector) return 0;
213 G4bool b;
214 return mVector->GetValue(2 * Unit::eV / Unit::MeV, b);
215 }
216
218 {
219
220 // get detector module parameters
221
222 // get module materials
223 string wallMat = Module.getString("wallMaterial");
224 string winMat = Module.getString("windowMaterial");
225 string botMat = Module.getString("Bottom/material");
226 G4Material* wallMaterial = Materials::get(wallMat);
227 G4Material* windowMaterial = Materials::get(winMat);
228 G4Material* bottomMaterial = Materials::get(botMat);
229 G4Material* boxFill = Materials::get("ARICH_Vacuum");
230
231 // check that module window material has specified refractive index
232 double wref = getAvgRINDEX(windowMaterial);
233 if (!wref) B2WARNING("Material '" << winMat <<
234 "', required for ARICH photon detector window as no specified refractive index. Continuing, but no photons in ARICH will be detected.");
236 m_arichgp->setWindowRefIndex(wref);
237 // get module dimensions
238 double modXsize = Module.getLength("moduleXSize") / Unit::mm;
239 double modZsize = Module.getLength("moduleZSize") / Unit::mm;
240 double wallThick = Module.getLength("moduleWallThickness") / Unit::mm;
241 double winThick = Module.getLength("windowThickness") / Unit::mm ;
242 double sensXsize = m_arichgp->getSensitiveSurfaceSize() / Unit::mm;
243 double botThick = Module.getLength("Bottom/thickness") / Unit::mm;
244
245 // some trivial checks of overlaps
246 if (sensXsize > modXsize - 2 * wallThick)
247 B2FATAL("ARICH photon detector module: Sensitive surface is too big. Doesn't fit into module box.");
248 if (winThick + botThick > modZsize)
249 B2FATAL("ARICH photon detector module: window + bottom thickness larger than module thickness.");
250
251 // module master volume
252 G4Box* moduleBox = new G4Box("Box", modXsize / 2., modXsize / 2., modZsize / 2.);
253 G4LogicalVolume* lmoduleBox = new G4LogicalVolume(moduleBox, boxFill, "moduleBox");
254
255 // build and place module wall
256 G4Box* tempBox = new G4Box("tempBox", modXsize / 2. - wallThick, modXsize / 2. - wallThick,
257 modZsize / 2. + 0.1); // Don't care about "+0.1", needs to be there.
258 G4SubtractionSolid* moduleWall = new G4SubtractionSolid("Box-tempBox", moduleBox, tempBox);
259 G4LogicalVolume* lmoduleWall = new G4LogicalVolume(moduleWall, wallMaterial, "moduleWall");
260 setColor(*lmoduleWall, "rgb(1.0,0.0,0.0,1.0)");
261 new G4PVPlacement(G4Transform3D(), lmoduleWall, "moduleWall", lmoduleBox, false, 1);
262
263 // build module window
264 G4Box* winBox = new G4Box("winBox", modXsize / 2. - wallThick, modXsize / 2. - wallThick, winThick / 2.);
265 G4LogicalVolume* lmoduleWin = new G4LogicalVolume(winBox, windowMaterial, "moduleWindow");
266 setColor(*lmoduleWin, "rgb(0.7,0.7,0.7,1.0)");
267 G4Transform3D transform = G4Translate3D(0., 0., (-modZsize + winThick) / 2.);
268 new G4PVPlacement(transform, lmoduleWin, "moduleWindow", lmoduleBox, false, 1);
269
270 // build module bottom
271 G4Box* botBox = new G4Box("botBox", modXsize / 2. - wallThick, modXsize / 2. - wallThick, botThick / 2.);
272 G4LogicalVolume* lmoduleBot = new G4LogicalVolume(botBox, bottomMaterial, "moduleBottom");
273 // if (isBeamBkgStudy) lmoduleBot->SetSensitiveDetector(new BkgSensitiveDetector("ARICH", 1));
274 setColor(*lmoduleBot, "rgb(0.0,1.0,0.0,1.0)");
275 G4Transform3D transform1 = G4Translate3D(0., 0., (modZsize - botThick) / 2.);
276 // add surface optical properties if specified
277 Materials& materials = Materials::getInstance();
278 GearDir bottomParam(Module, "Bottom/Surface");
279 if (bottomParam) {
280 G4OpticalSurface* optSurf = materials.createOpticalSurface(bottomParam);
281 new G4LogicalSkinSurface("bottomSurface", lmoduleBot, optSurf);
282 } else B2INFO("ARICH: No optical properties are specified for detector module bottom surface.");
283 new G4PVPlacement(transform1, lmoduleBot, "moduleBottom", lmoduleBox, false, 1);
284
285 // build sensitive surface
286 G4Box* sensBox = new G4Box("sensBox", sensXsize / 2., sensXsize / 2., 0.1 * Unit::mm);
287 G4LogicalVolume* lmoduleSens = new G4LogicalVolume(sensBox, boxFill, "moduleSensitive");
288 lmoduleSens->SetSensitiveDetector(m_sensitive);
289 setColor(*lmoduleSens, "rgb(0.5,0.5,0.5,1.0)");
290 G4Transform3D transform2 = G4Translate3D(0., 0., (-modZsize + 0.1) / 2. + winThick);
291 new G4PVPlacement(transform2, lmoduleSens, "moduleSensitive", lmoduleBox, false, 1);
292
293 // module is build, return module logical volume
294 return lmoduleBox;
295 }
296
297
298 G4Material* GeoARICHBtestCreator::createAerogel(const char* aeroname, double RefractiveIndex, double AerogelTransmissionLength)
299 {
300
301
302 G4double density = (RefractiveIndex - 1) / 0.21 * CLHEP::g / CLHEP::cm3;
303 B2INFO("Creating ARICH " << aeroname << " n=" << RefractiveIndex << " density=" << density / CLHEP::g * CLHEP::cm3 << " g/cm3");
304 Materials& materials = Materials::getInstance();
305 G4Material* _aerogel = new G4Material(aeroname, density, 4);
306 _aerogel->AddElement(materials.getElement("O"), 0.665);
307 _aerogel->AddElement(materials.getElement("H"), 0.042);
308 _aerogel->AddElement(materials.getElement("Si"), 0.292);
309 _aerogel->AddElement(materials.getElement("C"), 0.001);
310
311
312 const G4double AerogelAbsorbtionLength = 1000 * Unit::mm;
313
314 const G4int NBins = 40;
315 G4double MomentumBins[NBins];
316
317 G4double AerogelRindex[NBins];
318 G4double AerogelAbsorption[NBins];
319 G4double AerogelRayleigh[NBins];
320
321 G4double MaxPhotonEnergy = 5 * CLHEP::eV;
322 G4double MinPhotonEnergy = 1.5 * CLHEP::eV;
323
324 for (G4int i = 0; i < NBins; i++) {
325
326 const G4double energy = float(i) / NBins * (MaxPhotonEnergy - MinPhotonEnergy) + MinPhotonEnergy;
327
328 MomentumBins[i] = energy;
329 AerogelRindex[i] = RefractiveIndex;
330 AerogelAbsorption[i] = AerogelAbsorbtionLength;
331
332 const G4double Lambda0 = 400 * 1e-6 * CLHEP::mm;
333 const G4double Lambda = 1240 * CLHEP::eV / energy * 1e-6 * CLHEP::mm;
334 G4double x = Lambda / Lambda0;
335 AerogelRayleigh[i] = AerogelTransmissionLength * x * x * x * x;
336 }
337
338
339 G4MaterialPropertiesTable* AeroProperty = new G4MaterialPropertiesTable();
340 AeroProperty->AddProperty("RINDEX", MomentumBins, AerogelRindex, NBins);
341 AeroProperty->AddProperty("ABSLENGTH", MomentumBins, AerogelAbsorption, NBins);
342 AeroProperty->AddProperty("RAYLEIGH", MomentumBins, AerogelRayleigh, NBins);
343
344
345 _aerogel->SetMaterialPropertiesTable(AeroProperty);
346
347
348 return _aerogel;
349 }
350
351
352 void GeoARICHBtestCreator::createBtestGeometry(const GearDir& content, G4LogicalVolume& topWorld)
353 {
354
355 B2INFO("ARICH Btest geometry will be built.");
357
359
360 // experimental box
361
362 GearDir boxParams(content, "ExperimentalBox");
363 double xBox = boxParams.getLength("xSize") * CLHEP::mm / Unit::mm;
364 double yBox = boxParams.getLength("ySize") * CLHEP::mm / Unit::mm;
365 double zBox = boxParams.getLength("zSize") * CLHEP::mm / Unit::mm;
366
367 double xoffset = boxParams.getLength("beamcenter/x") * CLHEP::mm / Unit::mm;
368 double yoffset = boxParams.getLength("beamcenter/y") * CLHEP::mm / Unit::mm;
369 double zoffset = boxParams.getLength("beamcenter/z") * CLHEP::mm / Unit::mm - zBox / 2.;
370 G4ThreeVector roffset(xoffset, yoffset, zoffset);
371
372 ROOT::Math::XYZVector sh(boxParams.getLength("beamcenter/x"), boxParams.getLength("beamcenter/y"),
373 boxParams.getLength("beamcenter/z") - boxParams.getLength("zSize") / 2.);
374 m_arichbtgp->setOffset(sh);
375
376 string boxMat = boxParams.getString("material");
377 G4Material* boxMaterial = Materials::get(boxMat);
378 G4Box* expBox = new G4Box("ExperimentalBox", xBox / 2., yBox / 2., zBox / 2.);
379 G4LogicalVolume* topVolume = new G4LogicalVolume(expBox, boxMaterial, "ARICH.experimentalbox");
380 new G4PVPlacement(G4Transform3D(), topVolume, "ARICH.experimentalbox", &topWorld, false, 1);
381 setVisibility(*topVolume, false);
382
383 ROOT::Math::XYZVector trackingshift(content.getLength("tracking/shift/x"),
384 content.getLength("tracking/shift/y"),
385 content.getLength("tracking/shift/z"));
386
387 char mnodestr[256];
388 sprintf(mnodestr, "tracking/shift/run[@id=\"%d\"]", m_runno);
389 if (content.exists(mnodestr)) {
390 GearDir runtrackingshift(content, mnodestr);
391 trackingshift.SetXYZ(runtrackingshift.getLength("x"),
392 runtrackingshift.getLength("y"),
393 runtrackingshift.getLength("z"));
394 }
395 m_arichbtgp->setTrackingShift(trackingshift);
396 ARICHTracking* m_mwpc = new ARICHTracking[4];
397 m_arichbtgp->setMwpc(m_mwpc);
398 for (const GearDir& mwpc : content.getNodes("tracking/mwpc")) {
399 double x = mwpc.getLength("size/x") * CLHEP::mm / Unit::mm;
400 double y = mwpc.getLength("size/y") * CLHEP::mm / Unit::mm;
401 double z = mwpc.getLength("size/z") * CLHEP::mm / Unit::mm;
402
403 double px = mwpc.getLength("position/x") * CLHEP::mm / Unit::mm;
404 double py = mwpc.getLength("position/y") * CLHEP::mm / Unit::mm;
405 double pz = mwpc.getLength("position/z") * CLHEP::mm / Unit::mm;
406
407 G4Box* mwpcBox = new G4Box("MwpcBox", x / 2., y / 2., z / 2.);
408 G4LogicalVolume* mwpcVol = new G4LogicalVolume(mwpcBox, Materials::get(mwpc.getString("material")), "ARICH.mwpc");
409 new G4PVPlacement(G4Transform3D(G4RotationMatrix(), G4ThreeVector(px, py, pz) + roffset), mwpcVol, "ARICH.mwpc", topVolume, false,
410 1);
411 //setVisibility(*mwpc, true);
412
413 int id = mwpc.getInt("@id", -1);
414 B2INFO("GeoARICHBtestCreator::" << LogVar("MWPC ID", id));
415 if (id < 4 && id >= 0) {
416 m_mwpc[id].tdc[0] = mwpc.getInt("tdc/y/up");
417 m_mwpc[id].tdc[1] = mwpc.getInt("tdc/y/down");
418 m_mwpc[id].tdc[2] = mwpc.getInt("tdc/x/left");
419 m_mwpc[id].tdc[3] = mwpc.getInt("tdc/x/right");
420 m_mwpc[id].atdc = mwpc.getInt("tdc/anode", 0);
421 m_mwpc[id].slp[0] = mwpc.getDouble("slope/x");
422 m_mwpc[id].slp[1] = mwpc.getDouble("slope/y");
423 m_mwpc[id].offset[0] = mwpc.getDouble("offset/x");
424 m_mwpc[id].offset[1] = mwpc.getDouble("offset/y");
425 m_mwpc[id].cutll[0] = mwpc.getInt("tdccut/y/min");
426 m_mwpc[id].cutll[1] = mwpc.getInt("tdccut/x/min");
427 m_mwpc[id].cutul[0] = mwpc.getInt("tdccut/y/max");
428 m_mwpc[id].cutul[1] = mwpc.getInt("tdccut/x/max");
429 m_mwpc[id].pos[0] = mwpc.getDouble("position/x");
430 m_mwpc[id].pos[1] = mwpc.getDouble("position/y");
431 m_mwpc[id].pos[2] = mwpc.getDouble("position/z");
432 // m_mwpc[id].Print();
433 }
434
435 }
436 // physical position of the hapd channels
437
438 istringstream mapstream;
439 double mx, my;
440 mapstream.str(content.getString("hapdmap"));
441 while (mapstream >> mx >> my) {
442 m_arichbtgp->AddHapdChannelPositionPair(mx, my);
443 }
444 mapstream.clear();
445
446 // mapping of the electronic channels
447 int ipx, ipy;
448 mapstream.str(content.getString("hapdchmap"));
449 while (mapstream >> ipx >> ipy) {
450 m_arichbtgp->AddHapdElectronicMapPair(ipx, ipy);
451 }
452 // experimental frame consisting of detector plane, aerogel and mirrors
453
454 GearDir frameParams(content, "Frame");
455 double xFrame = frameParams.getLength("xSize") * CLHEP::mm / Unit::mm;
456 double yFrame = frameParams.getLength("ySize") * CLHEP::mm / Unit::mm;
457 double zFrame = frameParams.getLength("zSize") * CLHEP::mm / Unit::mm;
458 string envMat = frameParams.getString("material");
459
460 double px = frameParams.getLength("position/x") * CLHEP::mm / Unit::mm;
461 double py = frameParams.getLength("position/y") * CLHEP::mm / Unit::mm;
462 double pz = frameParams.getLength("position/z") * CLHEP::mm / Unit::mm;
463
464 G4Material* envMaterial = Materials::get(envMat);
465
466
467 G4Box* envBox = new G4Box("FrameBox", xFrame / 2., yFrame / 2., zFrame / 2.);
468 G4LogicalVolume* lenvBox = new G4LogicalVolume(envBox, envMaterial, "ARICH.frame");
469 G4ThreeVector frameOrigin0(m_framedx + px, py, pz); // rotation point of the detector frame wrt beamcenter
470 G4ThreeVector frameOrigin = frameOrigin0 + roffset;
471 G4RotationMatrix frameRotation;
472 frameRotation.rotateY(-m_rotation1 * CLHEP::degree);
473 G4Transform3D frameTransformation = G4Transform3D(frameRotation, frameOrigin);
474
475 new G4PVPlacement(frameTransformation, lenvBox, "ARICH.frame", topVolume, false, 1);
476 //setVisibility(*lenvBox, false);
477
478 ROOT::Math::XYZVector rotationCenter(frameOrigin0.x() * Unit::mm / CLHEP::mm,
479 frameOrigin0.y() * Unit::mm / CLHEP::mm,
480 frameOrigin0.z() * Unit::mm / CLHEP::mm);
481 m_arichbtgp->setFrameRotation(m_rotation1 * CLHEP::degree);
482 m_arichbtgp->setRotationCenter(rotationCenter);
483
484
485 char nodestr[256];
486 B2INFO(content.getPath());
487 sprintf(nodestr, "PhotonDetector/setup[@id=\"%d\"]", m_configuration);
488 GearDir hapdcontent(content, nodestr);
489 B2INFO(hapdcontent.getPath());
490
491
492
493 char mirrornodestr[256];
494 sprintf(mirrornodestr, "Mirrors/setup[@id=\"%s\"]", m_mirrorID.c_str());
495
496 GearDir mirrorcontent(content, mirrornodestr);
497 B2INFO(mirrorcontent.getPath());
498
499 // detectors
500 m_arichgp->Initialize(hapdcontent, mirrorcontent);
501
502
503 GearDir moduleParam(hapdcontent, "Detector/Module");
504 G4LogicalVolume* detModule = buildModule(moduleParam);
505
506 double detZpos = hapdcontent.getLength("Detector/Plane/zPosition") * CLHEP::mm / Unit::mm;
507 double detThick = hapdcontent.getLength("Detector/Module/moduleZSize") * CLHEP::mm / Unit::mm;
508 int nModules = m_arichgp->getNMCopies();
509
510 for (int i = 1; i <= nModules; i++) {
511 G4ThreeVector origin = m_arichgp->getOriginG4(i);
512 origin.setZ(detZpos + detThick / 2.);
513 double angle = m_arichgp->getModAngle(i);
514 G4RotationMatrix Ra;
515 Ra.rotateZ(angle);
516 G4Transform3D trans = G4Transform3D(Ra, origin);
517 new G4PVPlacement(G4Transform3D(Ra, origin), detModule, "detModule", lenvBox, false, i);
518 B2INFO(nodestr << "Module " << i << " is build ");
519 }
520 // mask hot channels
521 int npx = m_arichgp->getDetectorXPadNumber();
522 for (const double& ch : hapdcontent.getArray("HotChannels")) {
523 int channelID = (int) ch;
524 int moduleID = (npx) ? channelID / (npx * npx) : 0;
525 channelID %= (npx * npx);
526 m_arichgp->setActive(moduleID, channelID, false);
527 B2INFO("HotChannel " << ch << " : Module " << moduleID << "channelID " << channelID << " disabled");
528 }
529 // mask dead channels
530 for (const double& ch : hapdcontent.getArray("DeadChannels")) {
531 int channelID = (int) ch;
532 int moduleID = (npx) ? channelID / (npx * npx) : 0;
533 channelID %= (npx * npx);
534 m_arichgp->setActive(moduleID, channelID, false);
535 B2INFO("DeadChannel " << ch << " : Module " << moduleID << "channelID " << channelID << " disabled");
536 }
537 // place aerogel tiles
538 GearDir aerogelParam(content, "Aerogel");
539 double sizeX = aerogelParam.getLength("tileXSize") * CLHEP::mm / Unit::mm;
540 double sizeY = aerogelParam.getLength("tileYSize") * CLHEP::mm / Unit::mm;
541 double posX = aerogelParam.getLength("tileXPos") * CLHEP::mm / Unit::mm;
542 double posY = aerogelParam.getLength("tileYPos") * CLHEP::mm / Unit::mm;
543 double posZ = aerogelParam.getLength("tileZPos") * CLHEP::mm / Unit::mm;
544 double posZ0 = posZ;
545 double meanrefind = 0;
546 double meantrlen = 0;
547
548 // get parameter from python script
549 PyObject* m = PyImport_AddModule(strdup("__main__"));
550 if (m) {
551 int averageagel = 0;
552 PyObject* v = PyObject_GetAttrString(m, strdup("averageagel"));
553 if (v) {
554 averageagel = PyLong_AsLong(v);
555 Py_DECREF(v);
556 }
557 B2INFO("Python averageagel = " << averageagel);
558 m_arichbtgp->setAverageAgel(averageagel > 0);
559 }
560
561 for (unsigned int ilayer = 0; ilayer < m_agelthickness.size(); ilayer++) {
562 char aeroname[100];
563 sprintf(aeroname, "Aerogel%u", ilayer + 1);
564 G4Material* tileMaterial = createAerogel(aeroname, m_agelrefind[ilayer], m_ageltrlen[ilayer]);
565 double sizeZ = m_agelthickness[ilayer] * CLHEP::mm / Unit::mm;
566
567 if (!m_arichbtgp->getAverageAgel()) {
568 m_arichgp->setAeroRefIndex(ilayer, m_agelrefind[ilayer]);
569 m_arichgp->setAerogelZPosition(ilayer, (posZ - zFrame / 2.) * Unit::mm / CLHEP::mm);
570 m_arichgp->setAerogelThickness(ilayer, sizeZ * Unit::mm / CLHEP::mm);
571 m_arichgp->setAeroTransLength(ilayer, m_ageltrlen[ilayer]);
572 }
573
574 meantrlen += sizeZ / m_ageltrlen[ilayer];
575 meanrefind += m_agelrefind[ilayer];
576 G4Box* tileBox = new G4Box("tileBox", sizeX / 2., sizeY / 2., sizeZ / 2.);
577 G4LogicalVolume* lTile = new G4LogicalVolume(tileBox, tileMaterial, "Tile", 0, ilayer == 0 ? m_sensitiveAero : 0);
578 setColor(*lTile, "rgb(0.0, 1.0, 1.0,1.0)");
579 G4Transform3D trans = G4Translate3D(posX, posY, posZ + sizeZ / 2. - zFrame / 2.);
580 new G4PVPlacement(trans, lTile, "ARICH.tile", lenvBox, false, ilayer + 1);
581 posZ += sizeZ;
582 }
583 if (m_arichbtgp->getAverageAgel() && m_agelthickness.size()) {
584 B2INFO("Average aerogel will be used in the reconstruction ");
585 m_arichgp->setAeroRefIndex(0, meanrefind / m_agelthickness.size());
586 m_arichgp->setAerogelZPosition(0, (posZ0 - zFrame)* Unit::mm / CLHEP::mm);
587 m_arichgp->setAerogelThickness(0, posZ * Unit::mm / CLHEP::mm);
588 if (meantrlen > 0 && posZ > 0) meantrlen = 1 / meantrlen / posZ;
589 m_arichgp->setAeroTransLength(0, meantrlen);
590 }
591
592
593 // place mirrors
594 GearDir mirrorsParam(mirrorcontent, "Mirrors");
595 double height = mirrorsParam.getLength("height") * CLHEP::mm / Unit::mm;
596 double width = mirrorsParam.getLength("width") * CLHEP::mm / Unit::mm;
597 double thickness = mirrorsParam.getLength("thickness") * CLHEP::mm / Unit::mm;
598 string mirrMat = mirrorsParam.getString("material");
599 G4Material* mirrMaterial = Materials::get(mirrMat);
600 G4Box* mirrBox = new G4Box("mirrBox", thickness / 2., height / 2., width / 2.);
601 G4LogicalVolume* lmirror = new G4LogicalVolume(mirrBox, mirrMaterial, "mirror");
602
603 Materials& materials = Materials::getInstance();
604 GearDir surface(mirrorsParam, "Surface");
605 G4OpticalSurface* optSurf = materials.createOpticalSurface(surface);
606 new G4LogicalSkinSurface("mirrorsSurface", lmirror, optSurf);
607 int iMirror = 0;
608 for (const GearDir& mirror : mirrorsParam.getNodes("Mirror")) {
609 double xpos = mirror.getLength("xPos") * CLHEP::mm / Unit::mm;
610 double ypos = mirror.getLength("yPos") * CLHEP::mm / Unit::mm;
611 double zpos = mirror.getLength("zPos") * CLHEP::mm / Unit::mm;
612 double angle = mirror.getAngle("angle") / Unit::rad;
613 G4ThreeVector origin(xpos, ypos, zpos + width / 2. - zFrame / 2.);
614 G4RotationMatrix Ra;
615 Ra.rotateZ(angle);
616 G4Transform3D trans = G4Transform3D(Ra, origin);
617 new G4PVPlacement(G4Transform3D(Ra, origin), lmirror, "ARICH.mirror", lenvBox, false, iMirror);
618 iMirror++;
619 }
620 m_arichgp->Print();
621 m_arichbtgp->Print();
622 }
623
624
625 }
627}
The Class for ARICH Beamtest Geometry Parameters.
The Class for ARICH Geometry Parameters.
Beamtest ARICH Geometry Tracking Class.
float slp[2]
Calibration constants of the MWPC ( ) - slopes for x an y direction.
int cutll[2]
Cuts on the tdc sums - lower levels.
float pos[3]
MWPC chamber position.
int tdc[4]
TDC of the 4 cathode signals.
int atdc
TDC of the anode signal.
float offset[2]
Calibration constants of the MWPC - offsets for x an y direction.
int cutul[2]
Cuts on the tdc sums - upper levels.
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
Definition: GearDir.h:69
Base class for Modules.
Definition: Module.h:72
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
static const double mm
[millimeters]
Definition: Unit.h:70
static const double rad
Standard of [angle].
Definition: Unit.h:50
static const double eV
[electronvolt]
Definition: Unit.h:112
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
std::string m_comment
comment in the runlog
int m_aerosupport
Type of aerogel support - not used at the moment.
std::string m_aerogelID
ID of the aerogel configuration setup.
double m_rotation1
rotation angle of the frame
std::string m_runtype
Type of the beamtest run.
std::vector< double > m_agelrefind
vector of aerogel refractive indices
void createBtestGeometry(const GearDir &content, G4LogicalVolume &topVolume)
Creation of the beamtest geometry.
std::string m_mytype
type of the run
G4Material * createAerogel(const char *aeroname, double rind, double trl)
create aerogel material
double m_ry
y shift of the prototype ARICH frame
std::vector< double > m_ageltrlen
vector of aerogel transmission lengths
virtual ~GeoARICHBtestCreator()
The destructor of the GeoPXDCreator class.
G4LogicalVolume * buildModule(GearDir Module)
Build the module.
double getAvgRINDEX(G4Material *material)
Get the average refractive index if the material.
std::string m_mirrorID
ID of the mirror configuration setup.
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Creates the ROOT Objects for the ARICH Beamtest 2011 geometry.
double m_aerogeldx
shift of the aerogel center
std::string m_datum
datum of the runlog
SensitiveAero * m_sensitiveAero
pointer to the sesnitive aerogel
std::string m_author
Beamtest runlog record author.
GeoARICHBtestCreator()
Constructor of the GeoPXDCreator class.
std::string m_daqqa
classification of the run
std::string m_hapdID
ID of the HAPD configuration setup.
std::vector< double > m_agelthickness
vector of aerogel thicknesses
double m_rotation
rotation angle of the setup
SensitiveDetector * m_sensitive
pointer to the sensitive detector
double m_rx
x shift of the prototype ARICH frame
int m_neve
Number of event in the beamtest run.
int m_configuration
configuration number of the HAPD
This is optional (temporary) class that provides information on track parameters on aerogel plane,...
Definition: SensitiveAero.h:22
The Class for ARICH Sensitive Detector.
std::vector< double > getArray(const std::string &path) const noexcept(false)
Get the parameter path as a list of double values converted to the standard unit.
Definition: Interface.cc:123
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Definition: Interface.cc:41
std::string getPath() const
Return path of the current interface.
Definition: Interface.h:70
double getLength(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
Definition: Interface.h:259
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Definition: Interface.cc:21
int getInt(const std::string &path="") const noexcept(false)
Get the parameter path as a int.
Definition: Interface.cc:60
Thin wrapper around the Geant4 Material system.
Definition: Materials.h:48
static G4Material * get(const std::string &name)
Find given material.
Definition: Materials.h:63
static Materials & getInstance()
Get a reference to the singleton instance.
Definition: Materials.cc:85
G4OpticalSurface * createOpticalSurface(const gearbox::Interface &parameters)
Create an optical surface from parameters, will abort on error.
Definition: Materials.cc:295
G4Element * getElement(const std::string &name)
Find given chemical element.
Definition: Materials.cc:150
Class to store variables with their name which were sent to the logging service.
void setOffset(const ROOT::Math::XYZVector &)
Set of the setup global offset.
int getDetectorXPadNumber()
get number of pads of detector module (in one direction)
void setAeroTransLength(int ilayer, double trlen)
set transmission length of "ilayer" aerogel layer
int AddHapdElectronicMapPair(int, int)
Set the mapping of the electronic channel to the HAPD module nr and the channel number.
void setRotationCenter(const ROOT::Math::XYZVector &)
Set the rotation center of the Aerogel RICH frame.
void setAerogelThickness(int ilayer, double thick)
set thickness of "ilayer" aerogel layer
void setTrackingShift(const ROOT::Math::XYZVector &)
Set the tracking shift.
double getSensitiveSurfaceSize() const
get size of detector sensitive surface (size of two chips + gap between)
bool getAverageAgel()
Get the flag for the reconstruction by using the average aerogel refractive index.
void setFrameRotation(double)
Set the rotation angle of the Aerogel RICH frame.
void setMwpc(ARICHTracking *m_mwpc)
Set the pointer of the tracking MWPCs.
void Initialize(const GearDir &content)
calculates detector parameters needed for geometry build and reconstruction.
void setAerogelZPosition(int ilayer, double zPos)
set z position of "ilayer" aerogel layer
static ARICHBtestGeometryPar * Instance()
Static method to get a reference to the ARICHBtestGeometryPar instance.
void Print(void) const
Print some debug information.
static ARICHGeometryPar * Instance()
Static method to get a reference to the ARICHGeometryPar instance.
void setAeroRefIndex(int ilayer, double n)
set refractive index of "ilayer" aerogel layer
double getModAngle(int copyno)
get the angle of copyno-th HAPD rotation
G4ThreeVector getOriginG4(int copyNo)
get the position of copyNo-th HAPD module origin (returns G4ThreeVector)
void setAverageAgel(bool)
Set the flag for the reconstruction by using the average aerogel refractive index.
int getNMCopies() const
get the total number of HAPD modules
void setActive(int module, int channel, bool val)
set the channel on/off
int AddHapdChannelPositionPair(double, double)
Set the position of the HAPD channel.
void setWindowRefIndex(double refInd)
set detector module window refractive index
void setVisibility(G4LogicalVolume &volume, bool visible)
Helper function to quickly set the visibility of a given volume.
Definition: utilities.cc:108
void setColor(G4LogicalVolume &volume, const std::string &color)
Set the color of a logical volume.
Definition: utilities.cc:100
GeometryTypes
Flag indicating the type of geometry to be used.
Abstract base class for different kinds of events.
STL namespace.