11 #include <top/reconstruction/TOPconfigure.h>
12 #include <top/geometry/TOPGeometryPar.h>
13 #include <top/reconstruction/TOPf77fun.h>
16 #include <framework/gearbox/Unit.h>
17 #include <framework/logging/Logger.h>
18 #include <framework/geometry/BFieldManager.h>
22 void set_mirror_refl_(
int*,
float*);
23 void set_surface_refl_(
int*,
float*);
24 void set_alignment_(
int*,
float*,
float*,
float*,
float*,
float*,
float*);
25 int set_tts_type_(
int*,
int*,
float*,
float*,
float*);
26 int set_pmt_type_(
int*,
int*,
int*);
38 bool TOPconfigure::m_configured(
false);
39 DBObjPtr<TOPCalModuleAlignment> TOPconfigure::m_alignment;
40 OptionalDBArray<TOPPmtInstallation> TOPconfigure::m_pmtInstalled;
42 TOPconfigure::TOPconfigure()
44 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
47 m_R1 = geo->getInnerRadius();
48 m_R2 = geo->getOuterRadius();
49 m_Z1 = geo->getBackwardZ();
50 m_Z2 = geo->getForwardZ();
53 const auto& tdc = geo->getNominalTDC();
54 m_timeRange = tdc.getOverflowValue() * tdc.getBinWidth();
56 if (m_configured)
return;
59 setTOPvolume(m_R1, m_R2, m_Z1, m_Z2);
62 TVector3 Bfield = BFieldManager::getField(0, geo->getRadius(), 0) / Unit::T;
63 setBfield(-Bfield.Z());
66 const auto& pmt = geo->getModule(1).getPMTArray().getPMT();
67 setPMT(pmt.getSizeX(), pmt.getSizeY(),
68 pmt.getSensSizeX(), pmt.getSensSizeY(),
69 pmt.getNumColumns(), pmt.getNumRows());
72 const auto& tts = geo->getNominalTTS().getTTS();
73 std::vector<float> frac, mean, sigma;
74 for (
const auto& gauss : tts) {
75 frac.push_back(gauss.fraction);
76 mean.push_back(gauss.position);
77 sigma.push_back(gauss.sigma);
79 setTTS(tts.size(), frac.data(), mean.data(), sigma.data());
82 setPMTDependentTTSes();
86 m_pmtInstalled.addCallback(&setPMTTypes);
89 const auto& nominalQE = geo->getNominalQE();
90 std::vector<float> wavelength;
91 for (
unsigned i = 0; i < nominalQE.getQE().size(); i++) {
92 float wl = nominalQE.getLambdaFirst() + nominalQE.getLambdaStep() * i;
93 wavelength.push_back(wl);
95 auto QE = nominalQE.getQE();
97 const auto& wavelengthFilter = geo->getWavelengthFilter();
98 for (
unsigned i = 0; i < QE.size(); i++) {
99 QE[i] *= wavelengthFilter.getBulkTransmittance(wavelength[i]);
101 setQE(wavelength.data(), QE.data(), QE.size(),
102 nominalQE.getCE() * tdc.getEfficiency());
105 setTDC(tdc.getNumBits(), tdc.getBinWidth(), tdc.getOffset());
106 setCFD(tdc.getPileupTime(), tdc.getDoubleHitResolution());
111 for (
unsigned i = 0; i < geo->getNumModules(); i++) {
112 const auto& module = geo->getModule(i + 1);
113 double A = module.getBarWidth();
114 double B = module.getBarThickness();
115 double z1 = module.getBackwardZ();
116 double z2 = module.getForwardZ();
117 double R = module.getInnerRadius();
118 double phi = module.getPhi() - M_PI / 2;
119 int id = setQbar(A, B, z1, z2, R, 0, phi, c_PMT, c_SphericM);
120 setSurfaceReflectivity(
id, module.getSurfaceReflectivity(3.0));
122 const auto& mirror = module.getMirrorSegment();
123 setMirrorRadius(
id, mirror.getRadius());
124 setMirrorCenter(
id, mirror.getXc(), mirror.getYc());
125 setMirrorReflectivity(
id, mirror.getMirrorReflectivity(3.0));
127 const auto& prism = module.getPrism();
128 double prismLength = prism.getLength();
129 double prismFlat = prism.getFlatLength();
130 double prismExit = prism.getExitThickness();
131 double prismWidth = prism.getWidth();
132 addExpansionVolume(
id, c_Left, c_Prism, prismLength - prismFlat,
133 B / 2, B / 2 - prismExit, 0, 0, prismWidth);
135 const auto& pmtArray = module.getPMTArray();
136 double pmtWindow = pmtArray.getPMT().getWinThickness();
138 double filterThickness = pmtArray.getFilterThickness() + prism.getFilterThickness();
139 double cookieThickness = pmtArray.getCookieThickness();
140 setBBoxWindow(
id, prismFlat + cookieThickness + filterThickness + pmtWindow);
142 double x0 = module.getPMTArrayDisplacement().getX();
143 double y0 = module.getPMTArrayDisplacement().getY();
144 arrangePMT(
id, c_Left, pmtArray.getSizeX(), pmtArray.getSizeY(), x0, y0);
148 setAlignmentConstants();
149 m_alignment.addCallback(&setAlignmentConstants);
151 m_configured = TOPfinalize(0);
152 if (!m_configured) B2ERROR(
"TOPconfigure: configuration failed");
156 void TOPconfigure::setAlignmentConstants()
158 if (!m_alignment.isValid()) {
159 B2ERROR(
"TOPconfigure: No valid alignment for TOP found in database");
163 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
164 for (
unsigned i = 0; i < geo->getNumModules(); i++) {
165 int moduleID = i + 1;
166 if (m_alignment->isCalibrated(moduleID)) {
168 float dx = m_alignment->getX(moduleID);
169 float dy = m_alignment->getY(moduleID);
170 float dz = m_alignment->getZ(moduleID);
171 float alfa = m_alignment->getAlpha(moduleID);
172 float beta = m_alignment->getBeta(moduleID);
173 float gama = m_alignment->getGamma(moduleID);
174 set_alignment_(&
id, &dx, &dy, &dz, &alfa, &beta, &gama);
178 B2INFO(
"TOPconfigure: Alignment constants are set in reconstruction");
182 void TOPconfigure::setPMTDependentTTSes()
184 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
185 const auto& ttses = geo->getTTSes();
186 for (
const auto& tts : ttses) {
187 int type = tts.second.getPMTType();
188 std::vector<float> frac, mean, sigma;
189 for (
const auto& gauss : tts.second.getTTS()) {
190 frac.push_back(gauss.fraction);
191 mean.push_back(gauss.position);
192 sigma.push_back(gauss.sigma);
194 int size = frac.size();
195 int err = set_tts_type_(&type, &size, frac.data(), mean.data(), sigma.data());
197 B2ERROR(
"TOPconfigure: sum of TTS fractions is zero."
198 <<
LogVar(
"TTS type", type));
199 }
else if (err == 2) {
200 B2ERROR(
"TOPconfigure: TTS type is out of range."
201 <<
LogVar(
"TTS type", type));
207 void TOPconfigure::setPMTTypes()
209 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
211 for (
const auto& module : geo->getModules()) {
212 auto moduleID = module.getModuleID();
213 const auto& pmtArray = module.getPMTArray();
214 const auto& pmt = pmtArray.getPMT();
215 for (
unsigned pmtID = 1; pmtID <= pmtArray.getSize(); pmtID++) {
216 int pmtType = TOPGeometryPar::Instance()->getPMTType(moduleID, pmtID);
217 for (
unsigned pmtPixel = 1; pmtPixel <= pmt.getNumPixels(); pmtPixel++) {
218 auto pixelID = pmtArray.getPixelID(pmtID, pmtPixel);
219 int ich = pixelID - 1;
220 int mdn = moduleID - 1;
221 int err = set_pmt_type_(&mdn, &ich, &pmtType);
223 B2ERROR(
"TOPconfigure: PMT type is out of range."
224 <<
LogVar(
"PMT type", pmtType));
225 }
else if (err == 2) {
226 B2ERROR(
"TOPconfigure: invalid slot ID or pixel ID."
227 <<
LogVar(
"slot ID", moduleID)
228 <<
LogVar(
"pixel ID", pixelID));
234 B2INFO(
"TOPconfigure: new map of PMT types has been passed to reconstruction");
238 void TOPconfigure::setTOPvolume(
double R1,
double R2,
double Z1,
double Z2)
240 float r1 = (float) R1;
float r2 = (float) R2;
241 float z1 = (float) Z1;
float z2 = (float) Z2;
242 set_topvol_(&r1, &r2, &z1, &z2);
245 void TOPconfigure::setBfield(
double B)
251 void TOPconfigure::setEdgeRoughness(
double R)
257 void TOPconfigure::setPMT(
double A,
double B,
double Asens,
double Bsens,
258 int Nx,
int Ny,
double TTS)
260 float a = (float) A;
float b = (float) B;
261 float aa = (float) Asens;
float bb = (float) Bsens;
262 float tts = (float) TTS;
263 set_pmt_(&a, &b, &aa, &bb, &Nx, &Ny, &tts);
266 void TOPconfigure::setTTS(
int ng,
float Frac[],
float Mean[],
float Sigma[])
268 set_tts_(&ng, Frac, Mean, Sigma);
271 void TOPconfigure::setQE(
float Wavelength[],
float QE[],
int Size,
double CE)
273 float ce = (float) CE;
274 set_qeffi_(Wavelength, QE, &Size, &ce);
277 int TOPconfigure::setQbar(
double A,
double B,
double Z1,
double Z2,
double R,
278 double Dx,
double Phi,
int Lside,
int Rside)
280 float a = (float) A;
float b = (float) B;
281 float z1 = (float) Z1;
float z2 = (float) Z2;
float r = (float) R;
282 float dx = (float) Dx;
float phi = (float) Phi;
283 int id = set_qbar_(&a, &b, &z1, &z2, &r, &dx, &phi, &Lside, &Rside);
287 void TOPconfigure::setBBoxWindow(
int moduleID,
double thickness)
290 set_bbwin_(&moduleID, &d);
293 void TOPconfigure::addExpansionVolume(
int moduleID,
int LR,
int Shape,
double Dz,
294 double Yup,
double Ydown,
295 double YupIn,
double YdownIn,
296 double Width,
double DzRefl,
double Refl)
298 float dz = Dz;
float yup = Yup;
float ydn = Ydown;
float a = Width;
299 float yupi = YupIn;
float ydni = YdownIn;
300 float dzrefl = DzRefl;
float refl = Refl;
301 set_extvol_(&moduleID, &LR, &Shape, &dz, &yup, &ydn, &a, &yupi, &ydni,
305 void TOPconfigure::arrangePMT(
int moduleID,
double sizX,
double sizY,
306 double Dx,
double Dy)
308 float sizx = (float) sizX;
float sizy = (float) sizY;
309 float dx = (float) Dx;
float dy = (float) Dy;
311 arrange_pmt_(&moduleID, &LR, &sizx, &sizy, &dx, &dy);
313 arrange_pmt_(&moduleID, &LR, &sizx, &sizy, &dx, &dy);
316 void TOPconfigure::arrangePMT(
int moduleID,
int LR,
double sizX,
double sizY,
317 double Dx,
double Dy)
319 float sizx = (float) sizX;
float sizy = (float) sizY;
320 float dx = (float) Dx;
float dy = (float) Dy;
321 arrange_pmt_(&moduleID, &LR, &sizx, &sizy, &dx, &dy);
324 void TOPconfigure::setMirrorRadius(
int moduleID,
double R)
327 set_rmi_(&moduleID, &r);
330 void TOPconfigure::setMirrorCenter(
int moduleID,
double Xc,
double Yc)
332 float xc = (float) Xc;
float yc = (float) Yc;
333 set_xyc_(&moduleID, &xc, &yc);
336 void TOPconfigure::setMirrorReflectivity(
int moduleID,
double reflectivity)
338 float refl = (float) reflectivity;
341 B2WARNING(
"TOPconfigure: mirror reflectivity greater than 1 -> set to 1 in reconstruction");
343 set_mirror_refl_(&moduleID, &refl);
346 void TOPconfigure::setSurfaceReflectivity(
int moduleID,
double reflectivity)
348 float refl = (float) reflectivity;
351 B2WARNING(
"TOPconfigure: surface reflectivity greater than 1 -> set to 1 in reconstruction");
353 set_surface_refl_(&moduleID, &refl);
356 void TOPconfigure::setTDC(
int NBIT,
double ChWid,
double Offset)
358 float chwid = (float) ChWid;
float offset = (float) Offset;
359 set_tdc_(&NBIT, &chwid, &offset);
362 void TOPconfigure::setCFD(
double delTpileup,
double delTdoubleHit)
364 float dt = delTpileup;
float delt = delTdoubleHit;
365 set_cfd_(&dt, &delt);
368 bool TOPconfigure::TOPfinalize(
int Dump)
370 return top_geo_finalize_(&Dump);
373 void TOPconfigure::print()
const
378 void TOPconfigure::getQbar(
int moduleID,
double& A,
double& B,
double& C,
379 int& Lside,
int& Rside,
int& LexpvID,
int& RexpvID)
383 get_qbar_(&moduleID, &a, &b, &c, &Lside, &Rside, &LexpvID, &RexpvID);
387 void TOPconfigure::getExpansionVolume(
int expvID,
double& Dz,
double& Yup,
double& Ydown,
388 double& YupIn,
double& YdownIn,
389 double& Width,
int& Shape,
int& LR)
391 float dz, yup, ydn, a, yupi, ydni;
392 get_expvol_(&expvID, &dz, &yup, &ydn, &yupi, &ydni, &a, &Shape, &LR);
393 Dz = dz; Yup = yup; Ydown = ydn; YupIn = yupi; YdownIn = ydni; Width = a;
396 void TOPconfigure::getMirror(
int moduleID,
double& R,
double& Xc,
double& Yc,
double& Zc,
400 float r, xc, yc, zc, f;
401 get_mirror_(&moduleID, &r, &xc, &yc, &zc, &f);
402 R = r; Xc = xc; Yc = yc; Zc = zc; F = f;
405 double TOPconfigure::getBBoxWindow(
int moduleID)
408 return get_bbwin_(&moduleID);