Belle II Software  release-06-02-00
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 include
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 using namespace std;
26 
27 namespace Belle2 {
33  //-----------------------------------------------------------------
34  // Register module
35  //-----------------------------------------------------------------
36 
37  REG_MODULE(ARICHFillHits)
38 
39  //-----------------------------------------------------------------
40  // Implementation
41  //-----------------------------------------------------------------
42 
44  {
45  // set module description (e.g. insert text)
46  setDescription("Fills ARICHHits collection from ARICHDigits");
47  setPropertyFlags(c_ParallelProcessingCertified);
48  addParam("bitMask", m_bitMask, "hit bit mask (8 bits/channel)", (uint8_t)0xFF);
49  addParam("maxApdHits" , m_maxApdHits , "Remove hits with more than MaxApdHits per APD chip", (uint8_t)18);
50  addParam("maxHapdHits", m_maxHapdHits, "Remove hits with more than MaxHapdHits per HAPD", (uint8_t)100);
51  addParam("MagFieldCorrection", m_bcorrect, "Apply hit position correction due to non-perp. mag. field", 0);
52  addParam("fillAll", m_fillall, "Make hits for all active channels (useful for likelihood PDF studies)", 0);
53  }
54 
55  ARICHFillHitsModule::~ARICHFillHitsModule()
56  {
57  }
58 
59  void ARICHFillHitsModule::initialize()
60  {
61 
63  digits.isRequired();
64 
65  StoreArray<ARICHHit> arichHits;
66  arichHits.registerInDataStore();
67 
68  arichHits.registerRelationTo(digits);
69  }
70 
71  void ARICHFillHitsModule::beginRun()
72  {
73  }
74 
75  void ARICHFillHitsModule::event()
76  {
77  StoreObjPtr<EventMetaData> evtMetaData;
78 
80  StoreArray<ARICHHit> arichHits;
81 
82  // calculate number of hits on each apd and on each hapd
83  std::vector<uint8_t> apdHits(420 * 4, 0);
84  std::vector<uint8_t> hapdHits(420, 0);
85  for (const auto& digit : digits) {
86  uint8_t bits = digit.getBitmap();
87  if (!(bits & m_bitMask)) continue;
88 
89  int moduleID = digit.getModuleID();
90  if (moduleID > 420 || moduleID < 1) continue;
91  moduleID--;
92  int channelID = digit.getChannelID();
93  if (channelID > 143 || channelID < 0) continue;
94  int chipID = moduleID * 4 + channelID / 36;
95  apdHits[chipID]++;
96  hapdHits[moduleID]++;
97  }
98 
99  if (!m_fillall) {
100  for (const auto& digit : digits) {
101  int asicCh = digit.getChannelID();
102  int modID = digit.getModuleID();
103  if (modID > 420 || modID < 1) continue;
104  if (asicCh > 143 || asicCh < 0) continue;
105  uint8_t hitBitmap = digit.getBitmap();
106  if (!(hitBitmap & m_bitMask)) continue;
107 
108  // remove hot and dead channels
109  if (!m_chnMask->isActive(modID, asicCh)) continue;
110 
111  int chipID = (modID - 1) * 4 + asicCh / 36;
112 
113  if (apdHits[chipID] > m_maxApdHits) continue;
114  if (hapdHits[modID - 1] > m_maxHapdHits) continue;
115 
116 
117  int xCh, yCh;
118  if (not m_chnMap->getXYFromAsic(asicCh, xCh, yCh)) {
119  B2ERROR("Invalid ARICH hit! This hit will be ignored.");
120  continue;
121  }
122 
123  TVector2 hitpos2D = m_geoPar->getChannelPosition(modID, xCh, yCh);
124  TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
125  hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
126 
127  if (m_bcorrect) magFieldCorrection(hitpos3D);
128  ARICHHit* hh = arichHits.appendNew(hitpos3D, modID, asicCh);
129  hh->addRelationTo(&digit);
130  }
131  } else {
132  for (int imod = 1; imod < 421; imod++) {
133  for (int ichn = 0; ichn < 144; ichn++) {
134 
135  // remove hot and dead channels
136  if (!m_chnMask->isActive(imod, ichn)) continue;
137  int chipID = (imod - 1) * 4 + ichn / 36;
138 
139  if (apdHits[chipID] > m_maxApdHits) continue;
140  if (hapdHits[imod - 1] > m_maxHapdHits) continue;
141 
142  int xCh, yCh;
143  if (not m_chnMap->getXYFromAsic(ichn, xCh, yCh)) {
144  B2ERROR("Invalid ARICH hit! This hit will be ignored.");
145  continue;
146  }
147 
148  TVector2 hitpos2D = m_geoPar->getChannelPosition(imod, xCh, yCh);
149  TVector3 hitpos3D(hitpos2D.X(), hitpos2D.Y(), m_geoPar->getDetectorZPosition() + m_geoPar->getHAPDGeometry().getWinThickness());
150  hitpos3D = m_geoPar->getMasterVolume().pointToGlobal(hitpos3D);
151  if (m_bcorrect) magFieldCorrection(hitpos3D);
152  arichHits.appendNew(hitpos3D, imod, ichn);
153  }
154  }
155  }
156 
157  }
158 
159  void ARICHFillHitsModule::magFieldCorrection(TVector3& hitpos)
160  {
161  TVector3 Bfield = BFieldManager::getField(hitpos);
162  TVector3 shift = m_geoPar->getHAPDGeometry().getPhotocathodeApdDistance() / abs(Bfield.Z()) * Bfield;
163  hitpos.SetX(hitpos.X() - shift.X());
164  hitpos.SetY(hitpos.Y() - shift.Y());
165  }
166 
167  void ARICHFillHitsModule::endRun()
168  {
169  }
170 
171  void ARICHFillHitsModule::terminate()
172  {
173  }
174 
175 
177 } // end Belle2 namespace
178 
Fill ARICHHit collection from ARICHDigits.
Datastore class that holds photon hits. Input to the reconstruction.
Definition: ARICHHit.h:23
Base class for Modules.
Definition: Module.h:72
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:95
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.