Belle II Software  release-08-01-10
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 
25 namespace 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  {
71  StoreObjPtr<EventMetaData> evtMetaData;
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  TVector2 hitpos2D = m_geoPar->getChannelPosition(modID, xCh, yCh);
118  TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
119  hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
120 
121  if (m_bcorrect) magFieldCorrection(hitpos3D);
122  ARICHHit* hh = arichHits.appendNew(hitpos3D, modID, asicCh);
123  hh->addRelationTo(&digit);
124  }
125  } else {
126  for (int imod = 1; imod < 421; imod++) {
127  for (int ichn = 0; ichn < 144; ichn++) {
128 
129  // remove hot and dead channels
130  if (!m_chnMask->isActive(imod, ichn)) continue;
131  int chipID = (imod - 1) * 4 + ichn / 36;
132 
133  if (apdHits[chipID] > m_maxApdHits) continue;
134  if (hapdHits[imod - 1] > m_maxHapdHits) continue;
135 
136  int xCh, yCh;
137  if (not m_chnMap->getXYFromAsic(ichn, xCh, yCh)) {
138  B2ERROR("Invalid ARICH hit! This hit will be ignored.");
139  continue;
140  }
141 
142  TVector2 hitpos2D = m_geoPar->getChannelPosition(imod, xCh, yCh);
143  TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
144  hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
145  if (m_bcorrect) magFieldCorrection(hitpos3D);
146  arichHits.appendNew(hitpos3D, imod, ichn);
147  }
148  }
149  }
150 
151  }
152 
154  {
155  ROOT::Math::XYZVector Bfield = BFieldManager::getField(ROOT::Math::XYZVector(hitpos));
156  ROOT::Math::XYZVector shift = m_geoPar->getHAPDGeometry().getPhotocathodeApdDistance() / abs(Bfield.Z()) * Bfield;
157  hitpos.SetX(hitpos.X() - shift.X());
158  hitpos.SetY(hitpos.Y() - shift.Y());
159  }
160 
162 } // end Belle2 namespace
163 
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
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
void magFieldCorrection(TVector3 &hitpos)
Corrects hit position for distorsion due to non-perpendicular magnetic field component.
virtual ~ARICHFillHitsModule()
Destructor.
REG_MODULE(arichBtest)
Register the Module.
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
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.