Belle II Software development
ARICHFillHitsModule.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// Own header.
10#include <arich/modules/arichFillHits/ARICHFillHitsModule.h>
11
12// framework - DataStore
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/dataobjects/EventMetaData.h>
16// framework aux
17#include <framework/logging/Logger.h>
18
19// Dataobject classes
20#include <arich/dataobjects/ARICHDigit.h>
21#include <arich/dataobjects/ARICHHit.h>
22// magnetic field manager
23#include <framework/geometry/BFieldManager.h>
24
25namespace Belle2 {
31 //-----------------------------------------------------------------
33 //-----------------------------------------------------------------
34
35 REG_MODULE(ARICHFillHits);
36
37 //-----------------------------------------------------------------
38 // Implementation
39 //-----------------------------------------------------------------
40
42 {
43 // set module description (e.g. insert text)
44 setDescription("Fills ARICHHits collection from ARICHDigits");
46 addParam("bitMask", m_bitMask, "hit bit mask (8 bits/channel)", (uint8_t)0xFF);
47 addParam("maxApdHits", m_maxApdHits, "Remove hits with more than MaxApdHits per APD chip", (uint8_t)18);
48 addParam("maxHapdHits", m_maxHapdHits, "Remove hits with more than MaxHapdHits per HAPD", (uint8_t)100);
49 addParam("MagFieldCorrection", m_bcorrect, "Apply hit position correction due to non-perp. mag. field", 0);
50 addParam("fillAll", m_fillall, "Make hits for all active channels (useful for likelihood PDF studies)", 0);
51 }
52
54 {
55 }
56
58 {
59
61 digits.isRequired();
62
63 StoreArray<ARICHHit> arichHits;
64 arichHits.registerInDataStore();
65
66 arichHits.registerRelationTo(digits);
67 }
68
70 {
72
74 StoreArray<ARICHHit> arichHits;
75
76 // calculate number of hits on each apd and on each hapd
77 std::vector<uint8_t> apdHits(420 * 4, 0);
78 std::vector<uint8_t> hapdHits(420, 0);
79 for (const auto& digit : digits) {
80 uint8_t bits = digit.getBitmap();
81 if (!(bits & m_bitMask)) continue;
82
83 int moduleID = digit.getModuleID();
84 if (moduleID > 420 || moduleID < 1) continue;
85 moduleID--;
86 int channelID = digit.getChannelID();
87 if (channelID > 143 || channelID < 0) continue;
88 int chipID = moduleID * 4 + channelID / 36;
89 apdHits[chipID]++;
90 hapdHits[moduleID]++;
91 }
92
93 if (!m_fillall) {
94 for (const auto& digit : digits) {
95 int asicCh = digit.getChannelID();
96 int modID = digit.getModuleID();
97 if (modID > 420 || modID < 1) continue;
98 if (asicCh > 143 || asicCh < 0) continue;
99 uint8_t hitBitmap = digit.getBitmap();
100 if (!(hitBitmap & m_bitMask)) continue;
101
102 // remove hot and dead channels
103 if (!m_chnMask->isActive(modID, asicCh)) continue;
104
105 int chipID = (modID - 1) * 4 + asicCh / 36;
106
107 if (apdHits[chipID] > m_maxApdHits) continue;
108 if (hapdHits[modID - 1] > m_maxHapdHits) continue;
109
110
111 int xCh, yCh;
112 if (not m_chnMap->getXYFromAsic(asicCh, xCh, yCh)) {
113 B2ERROR("Invalid ARICH hit! This hit will be ignored.");
114 continue;
115 }
116
117 ROOT::Math::XYVector hitpos2D = m_geoPar->getChannelPosition(modID, xCh, yCh);
118 ROOT::Math::XYZVector hitpos3D(hitpos2D.X(), hitpos2D.Y(),
119 m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
120 hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
121
122 if (m_bcorrect) magFieldCorrection(hitpos3D);
123 ARICHHit* hh = arichHits.appendNew(hitpos3D, modID, asicCh);
124 hh->addRelationTo(&digit);
125 }
126 } else {
127 for (int imod = 1; imod < 421; imod++) {
128 for (int ichn = 0; ichn < 144; ichn++) {
129
130 // remove hot and dead channels
131 if (!m_chnMask->isActive(imod, ichn)) continue;
132 int chipID = (imod - 1) * 4 + ichn / 36;
133
134 if (apdHits[chipID] > m_maxApdHits) continue;
135 if (hapdHits[imod - 1] > m_maxHapdHits) continue;
136
137 int xCh, yCh;
138 if (not m_chnMap->getXYFromAsic(ichn, xCh, yCh)) {
139 B2ERROR("Invalid ARICH hit! This hit will be ignored.");
140 continue;
141 }
142
143 ROOT::Math::XYVector hitpos2D = m_geoPar->getChannelPosition(imod, xCh, yCh);
144 ROOT::Math::XYZVector hitpos3D(hitpos2D.X(), hitpos2D.Y(),
145 m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
146 hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
147 if (m_bcorrect) magFieldCorrection(hitpos3D);
148 arichHits.appendNew(hitpos3D, imod, ichn);
149 }
150 }
151 }
152
153 }
154
155 void ARICHFillHitsModule::magFieldCorrection(ROOT::Math::XYZVector& hitpos)
156 {
157 ROOT::Math::XYZVector Bfield = BFieldManager::getField(hitpos);
158 ROOT::Math::XYZVector shift = m_geoPar->getHAPDGeometry().getPhotocathodeApdDistance() / abs(Bfield.Z()) * Bfield;
159 hitpos.SetX(hitpos.X() - shift.X());
160 hitpos.SetY(hitpos.Y() - shift.Y());
161 }
162
164} // end Belle2 namespace
165
int m_fillall
make hit for all active channels (usefull for likelihood PDF studies)
uint8_t m_maxApdHits
reject hits with more than number of hits in Apd
uint8_t m_bitMask
hit bit mask (only convert digits with hit in bitmask bits)
DBObjPtr< ARICHGeometryConfig > m_geoPar
geometry configuration parameters from the DB
int m_bcorrect
apply hit position correction for the non-perp.
DBObjPtr< ARICHChannelMapping > m_chnMap
(x,y) to asic channel mapping
uint8_t m_maxHapdHits
reject hits with more than number of hits in Hapd
DBObjPtr< ARICHChannelMask > m_chnMask
list of dead channels from the DB
Datastore class that holds photon hits. Input to the reconstruction.
Definition: ARICHHit.h:23
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void magFieldCorrection(ROOT::Math::XYZVector &hitpos)
Corrects hit position for distorsion due to non-perpendicular magnetic field component.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual ~ARICHFillHitsModule()
Destructor.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
Abstract base class for different kinds of events.