12 #include <arich/modules/arichFillHits/ARICHFillHitsModule.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 #include <framework/dataobjects/EventMetaData.h>
19 #include <framework/logging/Logger.h>
22 #include <arich/dataobjects/ARICHDigit.h>
23 #include <arich/dataobjects/ARICHHit.h>
25 #include <framework/geometry/BFieldManager.h>
48 setDescription(
"Fills ARICHHits collection from ARICHDigits");
49 setPropertyFlags(c_ParallelProcessingCertified);
50 addParam(
"bitMask", m_bitMask,
"hit bit mask (8 bits/channel)", (uint8_t)0xFF);
51 addParam(
"maxApdHits" , m_maxApdHits ,
"Remove hits with more than MaxApdHits per APD chip", (uint8_t)18);
52 addParam(
"maxHapdHits", m_maxHapdHits,
"Remove hits with more than MaxHapdHits per HAPD", (uint8_t)100);
53 addParam(
"MagFieldCorrection", m_bcorrect,
"Apply hit position correction due to non-perp. mag. field", 0);
54 addParam(
"fillAll", m_fillall,
"Make hits for all active channels (useful for likelihood PDF studies)", 0);
57 ARICHFillHitsModule::~ARICHFillHitsModule()
61 void ARICHFillHitsModule::initialize()
68 arichHits.registerInDataStore();
70 arichHits.registerRelationTo(digits);
73 void ARICHFillHitsModule::beginRun()
77 void ARICHFillHitsModule::event()
85 std::vector<uint8_t> apdHits(420 * 4, 0);
86 std::vector<uint8_t> hapdHits(420, 0);
87 for (
const auto& digit : digits) {
88 uint8_t bits = digit.getBitmap();
89 if (!(bits & m_bitMask))
continue;
91 int moduleID = digit.getModuleID();
92 if (moduleID > 420 || moduleID < 1)
continue;
94 int channelID = digit.getChannelID();
95 if (channelID > 143 || channelID < 0)
continue;
96 int chipID = moduleID * 4 + channelID / 36;
102 for (
const auto& digit : digits) {
103 int asicCh = digit.getChannelID();
104 int modID = digit.getModuleID();
105 if (modID > 420 || modID < 1)
continue;
106 if (asicCh > 143 || asicCh < 0)
continue;
107 uint8_t hitBitmap = digit.getBitmap();
108 if (!(hitBitmap & m_bitMask))
continue;
111 if (!m_chnMask->isActive(modID, asicCh))
continue;
113 int chipID = (modID - 1) * 4 + asicCh / 36;
115 if (apdHits[chipID] > m_maxApdHits)
continue;
116 if (hapdHits[modID - 1] > m_maxHapdHits)
continue;
120 if (not m_chnMap->getXYFromAsic(asicCh, xCh, yCh)) {
121 B2ERROR(
"Invalid ARICH hit! This hit will be ignored.");
125 TVector2 hitpos2D = m_geoPar->getChannelPosition(modID, xCh, yCh);
126 TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
127 hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
129 if (m_bcorrect) magFieldCorrection(hitpos3D);
130 ARICHHit* hh = arichHits.appendNew(hitpos3D, modID, asicCh);
134 for (
int imod = 1; imod < 421; imod++) {
135 for (
int ichn = 0; ichn < 144; ichn++) {
138 if (!m_chnMask->isActive(imod, ichn))
continue;
139 int chipID = (imod - 1) * 4 + ichn / 36;
141 if (apdHits[chipID] > m_maxApdHits)
continue;
142 if (hapdHits[imod - 1] > m_maxHapdHits)
continue;
145 if (not m_chnMap->getXYFromAsic(ichn, xCh, yCh)) {
146 B2ERROR(
"Invalid ARICH hit! This hit will be ignored.");
150 TVector2 hitpos2D = m_geoPar->getChannelPosition(imod, xCh, yCh);
151 TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
152 hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
153 if (m_bcorrect) magFieldCorrection(hitpos3D);
154 arichHits.appendNew(hitpos3D, imod, ichn);
161 void ARICHFillHitsModule::magFieldCorrection(TVector3& hitpos)
163 TVector3 Bfield = BFieldManager::getField(hitpos);
164 TVector3 shift = m_geoPar->getHAPDGeometry().getPhotocathodeApdDistance() / abs(Bfield.Z()) * Bfield;
165 hitpos.SetX(hitpos.X() - shift.X());
166 hitpos.SetY(hitpos.Y() - shift.Y());
169 void ARICHFillHitsModule::endRun()
173 void ARICHFillHitsModule::terminate()