Belle II Software  release-05-02-19
ARICHFillHitsModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Luka Santelj *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <arich/modules/arichFillHits/ARICHFillHitsModule.h>
13 
14 // framework - DataStore
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 #include <framework/dataobjects/EventMetaData.h>
18 // framework aux
19 #include <framework/logging/Logger.h>
20 
21 // Dataobject classes
22 #include <arich/dataobjects/ARICHDigit.h>
23 #include <arich/dataobjects/ARICHHit.h>
24 // magnetic field manager
25 #include <framework/geometry/BFieldManager.h>
26 
27 using namespace std;
28 
29 namespace Belle2 {
35  //-----------------------------------------------------------------
36  // Register module
37  //-----------------------------------------------------------------
38 
39  REG_MODULE(ARICHFillHits)
40 
41  //-----------------------------------------------------------------
42  // Implementation
43  //-----------------------------------------------------------------
44 
46  {
47  // set module description (e.g. insert text)
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);
55  }
56 
57  ARICHFillHitsModule::~ARICHFillHitsModule()
58  {
59  }
60 
61  void ARICHFillHitsModule::initialize()
62  {
63 
65  digits.isRequired();
66 
67  StoreArray<ARICHHit> arichHits;
68  arichHits.registerInDataStore();
69 
70  arichHits.registerRelationTo(digits);
71  }
72 
73  void ARICHFillHitsModule::beginRun()
74  {
75  }
76 
77  void ARICHFillHitsModule::event()
78  {
79  StoreObjPtr<EventMetaData> evtMetaData;
80 
82  StoreArray<ARICHHit> arichHits;
83 
84  // calculate number of hits on each apd and on each hapd
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;
90 
91  int moduleID = digit.getModuleID();
92  if (moduleID > 420 || moduleID < 1) continue;
93  moduleID--;
94  int channelID = digit.getChannelID();
95  if (channelID > 143 || channelID < 0) continue;
96  int chipID = moduleID * 4 + channelID / 36;
97  apdHits[chipID]++;
98  hapdHits[moduleID]++;
99  }
100 
101  if (!m_fillall) {
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;
109 
110  // remove hot and dead channels
111  if (!m_chnMask->isActive(modID, asicCh)) continue;
112 
113  int chipID = (modID - 1) * 4 + asicCh / 36;
114 
115  if (apdHits[chipID] > m_maxApdHits) continue;
116  if (hapdHits[modID - 1] > m_maxHapdHits) continue;
117 
118 
119  int xCh, yCh;
120  if (not m_chnMap->getXYFromAsic(asicCh, xCh, yCh)) {
121  B2ERROR("Invalid ARICH hit! This hit will be ignored.");
122  continue;
123  }
124 
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);
128 
129  if (m_bcorrect) magFieldCorrection(hitpos3D);
130  ARICHHit* hh = arichHits.appendNew(hitpos3D, modID, asicCh);
131  hh->addRelationTo(&digit);
132  }
133  } else {
134  for (int imod = 1; imod < 421; imod++) {
135  for (int ichn = 0; ichn < 144; ichn++) {
136 
137  // remove hot and dead channels
138  if (!m_chnMask->isActive(imod, ichn)) continue;
139  int chipID = (imod - 1) * 4 + ichn / 36;
140 
141  if (apdHits[chipID] > m_maxApdHits) continue;
142  if (hapdHits[imod - 1] > m_maxHapdHits) continue;
143 
144  int xCh, yCh;
145  if (not m_chnMap->getXYFromAsic(ichn, xCh, yCh)) {
146  B2ERROR("Invalid ARICH hit! This hit will be ignored.");
147  continue;
148  }
149 
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);
155  }
156  }
157  }
158 
159  }
160 
161  void ARICHFillHitsModule::magFieldCorrection(TVector3& hitpos)
162  {
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());
167  }
168 
169  void ARICHFillHitsModule::endRun()
170  {
171  }
172 
173  void ARICHFillHitsModule::terminate()
174  {
175  }
176 
177 
179 } // end Belle2 namespace
180 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RelationsInterface::addRelationTo
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).
Definition: RelationsObject.h:144
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::ARICHHit
Datastore class that holds photon hits. Input to the reconstruction.
Definition: ARICHHit.h:33
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::ARICHFillHitsModule
Fill ARICHHit collection from ARICHDigits.
Definition: ARICHFillHitsModule.h:44
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33