Belle II Software development
PXDClusterPositionCollectorModule.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#include <pxd/modules/pxdClusterPositionCollector/PXDClusterPositionCollectorModule.h>
10#include <pxd/dataobjects/PXDDigit.h>
11#include <pxd/dataobjects/PXDTrueHit.h>
12#include <vxd/geometry/GeoCache.h>
13#include <pxd/reconstruction/PXDClusterPositionEstimator.h>
14#include <pxd/geometry/SensorInfo.h>
15
16#include <TTree.h>
17#include <TMath.h>
18#include <TH2F.h>
19
20#include <boost/format.hpp>
21#include <cmath>
22
23using namespace std;
24using boost::format;
25using namespace Belle2;
26
27//-----------------------------------------------------------------
28// Register the Module
29//-----------------------------------------------------------------
30REG_MODULE(PXDClusterPositionCollector);
31
32//-----------------------------------------------------------------
33// Implementation
34//-----------------------------------------------------------------
35
37 , m_clusterEta(0), m_positionOffsetU(0), m_positionOffsetV(0), m_sizeV(0), m_pitchV(0)
38{
39 // Set module properties
40 setDescription("Calibration collector module for PXD cluster position estimation");
42
43 addParam("clustersName", m_storeClustersName, "Name of the collection to use for PXDClusters", string(""));
44 addParam("clusterKind", m_clusterKind, "Collect data for Clusterkind", int(0));
45 addParam("binsU", m_binsU, "Number of bins for thetaU ", int(18));
46 addParam("binsV", m_binsV, "Number of bins for thetaV ", int(18));
47}
48
49void PXDClusterPositionCollectorModule::prepare() // Do your initialise() stuff here
50{
52
53 // Data object creation --------------------------------------------------
54 string gridname = str(format("GridKind_%1%") % m_clusterKind);
55 auto grid = new TH2F(gridname.c_str(), gridname.c_str(), m_binsU, -90.0, +90.0, m_binsV, -90.0, +90.0);
56 registerObject<TH2F>(gridname, grid);
57
58 string pitchtreename = "pitchtree";
59 auto ptree = new TTree(pitchtreename.c_str(), pitchtreename.c_str());
60 ptree->Branch<int>("ClusterKind", &m_clusterKind);
61 ptree->Branch<float>("PitchV", &m_pitchV);
62 registerObject<TTree>(pitchtreename, ptree);
63
64 for (auto uBin = 1; uBin <= grid->GetXaxis()->GetNbins(); uBin++) {
65 for (auto vBin = 1; vBin <= grid->GetYaxis()->GetNbins(); vBin++) {
66 string treename = str(format("tree_%1%_%2%_%3%") % m_clusterKind % uBin % vBin);
67 auto tree = new TTree(treename.c_str(), treename.c_str());
68 tree->Branch<string>("ShapeName", &m_shapeName);
69 tree->Branch<string>("MirroredShapeName", &m_mirroredShapeName);
70 tree->Branch<float>("ClusterEta", &m_clusterEta);
71 tree->Branch<float>("OffsetU", &m_positionOffsetU);
72 tree->Branch<float>("OffsetV", &m_positionOffsetV);
73 tree->Branch<int>("SizeV", &m_sizeV);
74 registerObject<TTree>(treename, tree);
75 }
76 }
77}
78
79void PXDClusterPositionCollectorModule::collect() // Do your event() stuff here
80{
81 // If no input, nothing to do
82 if (!m_pxdCluster) return;
83
84 string gridname = str(format("GridKind_%1%") % m_clusterKind);
85 auto grid = getObjectPtr<TH2F>(gridname);
86
87 for (auto& cluster : m_pxdCluster) {
88
89 // Ignore clustes with more than one truehit
90 if (cluster.getRelationsTo<PXDTrueHit>().size() > 1) {
91 continue;
92 }
93
94 // Ignore freak clusters with more than 1000 digits
95 if (cluster.getSize() >= 1000) {
96 continue;
97 }
98
99 // Ignore clusters with wrong clusterkind
100 if (m_clusterKind != PXD::PXDClusterPositionEstimator::getInstance().getClusterkind(cluster)) {
101 continue;
102 }
103
104 for (auto& truehit : cluster.getRelationsTo<PXDTrueHit>()) {
105
106 auto mom = truehit.getMomentum();
107
108 if (mom.Z() == 0 || mom.R() < 0.02) continue;
109
110 double thetaU = TMath::ATan2(mom.X() / mom.Z(), 1.0) * TMath::RadToDeg();
111 double thetaV = TMath::ATan2(mom.Y() / mom.Z(), 1.0) * TMath::RadToDeg();
112 int uBin = grid->GetXaxis()->FindBin(thetaU);
113 int vBin = grid->GetYaxis()->FindBin(thetaV);
114
115 if (uBin < 1 || uBin > m_binsU || vBin < 1 || vBin > m_binsV) continue;
116
117 // Add new entry to sources
118 grid->Fill(thetaU, thetaV);
119
120 VxdID sensorID = truehit.getSensorID();
121 const PXD::SensorInfo& Info = dynamic_cast<const PXD::SensorInfo&>(VXD::GeoCache::getInstance().getSensorInfo(sensorID));
122
123 // Sort all pixels related to the cluster
124 set<PXD::Pixel> pixels;
125 for (int i = 0; i < cluster.getSize(); i++) {
126 const PXDDigit* const storeDigit = cluster.getRelationsTo<PXDDigit>("PXDDigits")[i];
127 pixels.insert(PXD::Pixel(storeDigit, i));
128 }
129
130 // Fill tree variables
131 m_shapeName = PXD::PXDClusterPositionEstimator::getInstance().getShortName(pixels, cluster.getUStart(), cluster.getVStart(),
132 cluster.getVSize(), thetaU, thetaV);
134 cluster.getVStart(), cluster.getVSize(), thetaU, thetaV);
135 m_clusterEta = PXD::PXDClusterPositionEstimator::getInstance().computeEta(pixels, cluster.getVStart(), cluster.getVSize(), thetaU,
136 thetaV);
137 m_positionOffsetU = truehit.getU() - Info.getUCellPosition(cluster.getUStart());
138 m_positionOffsetV = truehit.getV() - Info.getVCellPosition(cluster.getVStart());
139 m_pitchV = Info.getVPitch(truehit.getV());
140 m_sizeV = cluster.getVSize();
141
142 // Fill the tree
143 string treename = str(format("tree_%1%_%2%_%3%") % m_clusterKind % uBin % vBin);
144 getObjectPtr<TTree>(treename)->Fill();
145
146 // Fill the pitch tree (this should happen only once per collector)
147 string pitchtreename = "pitchtree";
148 if (getObjectPtr<TTree>(pitchtreename)->GetEntries() == 0) {
149 getObjectPtr<TTree>(pitchtreename)->Fill();
150 }
151 }
152 }
153}
Calibration collector module base class.
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
std::string m_mirroredShapeName
Name of mirrored cluster shape.
StoreArray< PXDCluster > m_pxdCluster
< Required input for PXDCluster
std::string m_storeClustersName
Name of the collection to use for PXDClusters.
PXDClusterPositionCollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
The PXD digit class.
Definition: PXDDigit.h:27
Class PXDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: PXDTrueHit.h:31
static PXDClusterPositionEstimator & getInstance()
Main (and only) way to access the PXDClusterPositionEstimator.
const std::string getMirroredShortName(const std::set< Pixel > &pixels, int uStart, int vStart, int vSize, double thetaU, double thetaV) const
Return the mirrored name for the pixel set.
float computeEta(const std::set< Pixel > &pixels, int vStart, int vSize, double thetaU, double thetaV) const
Return the normed charge ratio between head and tail pixels (size>=2) or the charge of the seed (size...
const std::string getShortName(const std::set< Pixel > &pixels, int uStart, int vStart, int vSize, double thetaU, double thetaV) const
Return the name for the pixel set.
Class to represent one pixel, used in clustering for fast access.
Definition: Pixel.h:36
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
Definition: SensorInfo.h:23
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
double getVCellPosition(int vID) const
Return the position of a specific strip/pixel in v direction.
double getUCellPosition(int uID, int vID=-1) const
Return the position of a specific strip/pixel in u direction.
double getVPitch(double v=0) const
Return the pitch of the sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
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
#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.
STL namespace.