Belle II Software development
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/* Basf2 headers. */
13#include <framework/gearbox/Unit.h>
14#include <tracking/dataobjects/ExtHit.h>
15
16/* ROOT headers. */
17#include <TTree.h>
18
19using namespace Belle2;
20
21REG_MODULE(EKLMAlignmentAlongStripsCollector);
22
34
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 ROOT::Math::XYZVector 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;
88 vol = m_ElementNumbers->stripNumber(
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;
114 m_ElementNumbers->stripNumberToElementNumbers(
115 m_Event->stripGlobal, &m_Event->section, &m_Event->layer,
116 &m_Event->sector, &m_Event->plane, &m_Event->strip);
117 tr = m_TransformData->getStripGlobalToLocal(
118 m_Event->section, m_Event->layer, m_Event->sector, m_Event->plane,
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;
124 m_Event->segmentGlobal =
125 m_ElementNumbers->segmentNumber(
126 m_Event->section, m_Event->layer, m_Event->sector, m_Event->plane,
127 (m_Event->strip - 1) / m_ElementNumbers->getNStripsSegment() + 1);
128 calibrationData->Fill();
129 }
130 }
131}
132
137
void registerObject(std::string name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
T * getObjectPtr(std::string name)
Calls the CalibObjManager to get the requested stored collector data.
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.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Transformation data.
@ c_Alignment
Use alignment data (for everything else).
Store one Ext hit as a ROOT object.
Definition ExtHit.h:31
ROOT::Math::XYZVector getPosition() const
Get position of this extrapolation hit.
Definition ExtHit.h:144
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
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:649
Abstract base class for different kinds of events.