Belle II Software  release-06-01-15
EKLMAlignmentAlongStripsCollectorModule.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 <klm/eklm/modules/EKLMAlignmentAlongStrips/EKLMAlignmentAlongStripsCollectorModule.h>
11 
12 /* Belle 2 headers. */
13 #include <framework/gearbox/Unit.h>
14 #include <tracking/dataobjects/ExtHit.h>
15 
16 /* ROOT headers. */
17 #include <TTree.h>
18 
19 using namespace Belle2;
20 
21 REG_MODULE(EKLMAlignmentAlongStripsCollector)
22 
26  m_ElementNumbers(&(EKLMElementNumbers::Instance())),
27  m_GeoDat(nullptr),
28  m_TransformData(nullptr),
29  m_Event(new EKLMAlignmentAlongStripsAlgorithm::Event)
30 {
31  setDescription("Module for EKLM alignment along strip (data collection).");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 }
34 
37 {
38  delete m_Event;
39 }
40 
42 {
43  TTree* t;
47  m_KLMDigits.isRequired();
48  m_Tracks.isRequired();
49  StoreArray<ExtHit> extHits;
50  m_Tracks.requireRelationTo(extHits);
51  t = new TTree("calibration_data", "");
52  t->Branch("event", &m_Event);
53  registerObject<TTree>("calibration_data", t);
54 }
55 
57 {
58  /* cppcheck-suppress variableScope */
59  int i, j, n, n2, vol;
60  double l;
61  const HepGeom::Transform3D* tr;
62  TVector3 hitPosition;
63  HepGeom::Point3D<double> hitGlobal, hitLocal;
64  std::multimap<int, ExtHit*> mapExtHit;
65  std::multimap<int, ExtHit*>::iterator it, it2, itLower, itUpper;
66  std::set<int> digitVolumes;
67  ExtHit* extHit;
68  TTree* calibrationData = getObjectPtr<TTree>("calibration_data");
69  /* Create volume - extHit map. */
70  n = m_Tracks.getEntries();
71  for (i = 0; i < n; i++) {
72  RelationVector<ExtHit> extHits = m_Tracks[i]->getRelationsTo<ExtHit>();
73  n2 = extHits.size();
74  for (j = 0; j < n2; j++) {
75  if (extHits[j]->getDetectorID() != Const::EDetector::EKLM)
76  continue;
77  if (!m_GeoDat->hitInEKLM(extHits[j]->getPosition().Z()))
78  continue;
79  mapExtHit.insert(std::pair<int, ExtHit*>(extHits[j]->getCopyID(),
80  extHits[j]));
81  }
82  }
83  /* Create set of strips with signal. */
84  n = m_KLMDigits.getEntries();
85  for (i = 0; i < n; i++) {
86  if (m_KLMDigits[i]->getSubdetector() != KLMElementNumbers::c_EKLM)
87  continue;
89  m_KLMDigits[i]->getSection(), m_KLMDigits[i]->getLayer(),
90  m_KLMDigits[i]->getSector(), m_KLMDigits[i]->getPlane(),
91  m_KLMDigits[i]->getStrip());
92  digitVolumes.insert(vol);
93  }
94  /* Search for strips with extHits, but without signal. */
95  for (it = mapExtHit.begin(); it != mapExtHit.end();) {
96  itLower = it;
97  do {
98  ++it;
99  } while ((it != mapExtHit.end()) && (it->first == itLower->first));
100  itUpper = it;
101  if (digitVolumes.find(itLower->first) != digitVolumes.end())
102  continue;
103  /* Found: write all extHits to the data tree. */
104  for (it2 = itLower; it2 != itUpper; ++it2) {
105  extHit = it2->second;
106  hitPosition = extHit->getPosition();
107  m_Event->x = hitPosition.X();
108  m_Event->y = hitPosition.Y();
109  m_Event->z = hitPosition.Z();
110  hitGlobal.setX(hitPosition.X() / Unit::mm * CLHEP::mm);
111  hitGlobal.setY(hitPosition.Y() / Unit::mm * CLHEP::mm);
112  hitGlobal.setZ(hitPosition.Z() / Unit::mm * CLHEP::mm);
113  m_Event->stripGlobal = it2->first;
119  m_Event->strip);
120  hitLocal = (*tr) * hitGlobal;
121  l = m_GeoDat->getStripLength(m_Event->strip) / CLHEP::mm * Unit::mm;
122  m_Event->distSiPM = 0.5 * l - hitLocal.x() / CLHEP::mm * Unit::mm;
123  m_Event->distFarEnd = 0.5 * l + hitLocal.x() / CLHEP::mm * Unit::mm;
128  calibrationData->Fill();
129  }
130  }
131 }
132 
134 {
135  delete m_TransformData;
136 }
137 
Calibration collector module base class.
void collect() override
This method is called for each event.
void finish() override
This method is called at the end of the event processing.
struct EKLMAlignmentAlongStripsAlgorithm::Event * m_Event
Event.
EKLM element numbers.
int stripNumber(int section, int layer, int sector, int plane, int strip) const
Get strip number.
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
static constexpr int getNStripsSegment()
Get number of strips in a segment.
int segmentNumber(int section, int layer, int sector, int plane, int segment) const
Get segment number.
bool hitInEKLM(double z) const
Check if z coordinate may be in EKLM.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Definition: GeometryData.cc:33
double getStripLength(int strip) const
Get strip length.
Definition: GeometryData.h:71
Transformation data.
Definition: TransformData.h:35
@ c_Alignment
Use alignment data (for everything else).
Definition: TransformData.h:45
const HepGeom::Transform3D * getStripGlobalToLocal(KLMDigit *hit) const
Get strip global to local transformation by hit.
Store one Ext hit as a ROOT object.
Definition: ExtHit.h:30
TVector3 getPosition() const
Get position of this extrapolation hit.
Definition: ExtHit.h:143
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
static const double mm
[millimeters]
Definition: Unit.h:70
#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.
float distFarEnd
Distance from hit to the far end of the strip.