9 #include <pxd/modules/pxdClusterChargeCollector/PXDClusterChargeCollectorModule.h>
11 #include <framework/datastore/RelationArray.h>
13 #include <vxd/geometry/GeoCache.h>
14 #include <pxd/geometry/SensorInfo.h>
15 #include <pxd/reconstruction/PXDGainCalibrator.h>
20 #include <boost/format.hpp>
36 , m_signal(0), m_run(0), m_exp(0)
39 setDescription(
"Calibration collector module for cluster charge related calibrations.");
40 setPropertyFlags(c_ParallelProcessingCertified);
42 addParam(
"clustersName", m_storeClustersName,
"Name of the collection to use for PXDClusters",
string(
""));
43 addParam(
"mcParticlesName", m_storeMCParticlesName,
"Name of the collection to use for MCParticles",
string(
"MCParticles"));
44 addParam(
"minClusterCharge", m_minClusterCharge,
"Minimum cluster charge cut",
int(0));
45 addParam(
"minClusterSize", m_minClusterSize,
"Minimum cluster size cut ",
int(2));
46 addParam(
"maxClusterSize", m_maxClusterSize,
"Maximum cluster size cut ",
int(6));
47 addParam(
"nBinsU", m_nBinsU,
"Number of gain corrections per sensor along u side",
int(4));
48 addParam(
"nBinsV", m_nBinsV,
"Number of gain corrections per sensor along v side",
int(6));
49 addParam(
"chargePayloadName", m_chargeName,
"Payload name for Cluster Charge to be read from DB",
string(
""));
50 addParam(
"gainPayloadName", m_gainName,
"Payload name for Gain to be read from DB",
string(
""));
51 addParam(
"fillChargeHistogram", m_fillChargeHistogram,
"Flag to fill Charge histograms",
bool(
false));
52 addParam(
"matchTrack", m_matchTrack,
53 "Flag to use track matched clusters (=1) and apply theta angle projection to cluster charge (=2)",
int(0));
54 addParam(
"mcSamples", m_mcSamples,
"Flag to deal with MC samples",
bool(
false));
55 addParam(
"relationCheck", m_relationCheck,
"Flag to check relations between PXDClusters and PXDClustersFromTracks",
bool(
false));
59 void PXDClusterChargeCollectorModule::prepare()
61 m_pxdClusters.isRequired(m_storeClustersName);
62 if (m_relationCheck) {
63 std::string storeClustersName2;
64 storeClustersName2 = (m_storeClustersName ==
"PXDClusters") ?
65 "PXDClustersFromTracks" :
"PXDClusters";
69 m_tracks.isOptional();
70 m_recoTracks.isOptional();
72 if (m_mcSamples && m_matchTrack > 0) {
73 m_mcParticles.isRequired(m_storeMCParticlesName);
75 m_mcParticles.isOptional();
79 B2WARNING(
"Number of bins along u side incremented from 0->1");
84 B2WARNING(
"Number of bins along v side incremented from 0->1");
88 auto gTools = VXD::GeoCache::getInstance().getGeoTools();
89 int nPXDSensors = gTools->getNumberOfPXDSensors();
95 auto hPXDClusterCounter =
new TH1I(
"hPXDClusterCounter",
"Number of clusters found in data sample",
96 m_nBinsU * m_nBinsV * nPXDSensors, 0,
97 m_nBinsU * m_nBinsV * nPXDSensors);
98 hPXDClusterCounter->GetXaxis()->SetTitle(
"bin id");
99 hPXDClusterCounter->GetYaxis()->SetTitle(
"Number of clusters");
100 for (
int iSensor = 0; iSensor < nPXDSensors; iSensor++) {
101 for (
int uBin = 0; uBin < m_nBinsU; uBin++) {
102 for (
int vBin = 0; vBin < m_nBinsV; vBin++) {
103 VxdID id = gTools->getSensorIDFromPXDIndex(iSensor);
104 string sensorDescr = id;
105 hPXDClusterCounter->GetXaxis()->SetBinLabel(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin + 1,
106 str(format(
"%1%_%2%_%3%") % sensorDescr % uBin % vBin).c_str());
110 registerObject<TH1I>(
"PXDClusterCounter", hPXDClusterCounter);
111 if (m_fillChargeHistogram) {
112 auto hPXDClusterCharge =
new TH2I(
"hPXDClusterCharge",
"Charge of clusters found in data sample",
113 m_nBinsU * m_nBinsV * nPXDSensors, 0,
114 m_nBinsU * m_nBinsV * nPXDSensors,
116 hPXDClusterCharge->GetXaxis()->SetTitle(
"bin id");
117 hPXDClusterCharge->GetYaxis()->SetTitle(
"Cluster charge [ADU]");
118 registerObject<TH2I>(
"PXDClusterCharge", hPXDClusterCharge);
125 for (
int iSensor = 0; iSensor < nPXDSensors; iSensor++) {
126 for (
int uBin = 0; uBin < m_nBinsU; uBin++) {
127 for (
int vBin = 0; vBin < m_nBinsV; vBin++) {
128 VxdID id = gTools->getSensorIDFromPXDIndex(iSensor);
130 auto ladderNumber =
id.getLadderNumber();
131 auto sensorNumber =
id.getSensorNumber();
132 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
133 auto tree =
new TTree(treename.c_str(), treename.c_str());
134 tree->Branch<
int>(
"signal", &m_signal);
135 registerObject<TTree>(treename, tree);
140 auto dbtree =
new TTree(
"dbtree",
"dbtree");
141 dbtree->Branch<
int>(
"run", &m_run);
142 dbtree->Branch<
int>(
"exp", &m_exp);
145 registerObject<TTree>(
"dbtree", dbtree);
148 void PXDClusterChargeCollectorModule::startRun()
150 m_run = m_evtMetaData->getRun();
151 m_exp = m_evtMetaData->getExperiment();
152 if (m_chargeName.length()) {
154 m_chargeMap = *chargeMap;
158 if (m_gainName.length()) {
160 m_gainMap = *gainMap;
164 getObjectPtr<TTree>(
"dbtree")->Fill();
167 void PXDClusterChargeCollectorModule::collect()
170 if (!m_pxdClusters)
return;
172 auto gTools = VXD::GeoCache::getInstance().getGeoTools();
174 if (!m_matchTrack || m_mcSamples) {
176 for (
auto& cluster : m_pxdClusters) {
177 if (m_relationCheck) {
178 if (m_storeClustersName ==
"PXDClusters") {
180 if (!relPXDClusters.
size())
continue;
181 }
else if (m_storeClustersName ==
"PXDClustersFromTracks") {
183 if (!relPXDClusters.
size())
continue;
186 double correction = 1.0;
187 if (m_matchTrack > 0) {
189 if (!mcParticlesPXD.
size())
continue;
190 if (m_matchTrack == 2) {
191 correction = sin(mcParticlesPXD[0]->getMomentum().Theta());
195 if (cluster.getCharge() >= m_minClusterCharge && cluster.getSize() >= m_minClusterSize && cluster.getSize() <= m_maxClusterSize) {
197 VxdID sensorID = cluster.getSensorID();
201 auto iSensor = gTools->getPXDSensorIndex(sensorID);
205 auto uBin = PXD::PXDGainCalibrator::getInstance().getBinU(sensorID, uID, vID, m_nBinsU);
206 auto vBin = PXD::PXDGainCalibrator::getInstance().getBinV(sensorID, vID, m_nBinsV);
207 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
210 m_signal = cluster.getCharge();
212 getObjectPtr<TTree>(treename)->Fill();
214 getObjectPtr<TH1I>(
"PXDClusterCounter")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin);
215 if (m_fillChargeHistogram)
216 getObjectPtr<TH2I>(
"PXDClusterCharge")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin,
217 cluster.getCharge()*correction);
225 if (!m_tracks)
return;
227 for (
const Track& track : m_tracks) {
230 if (!recoTrack.
size())
continue;
233 const TrackFitResult* tfr = track.getTrackFitResultWithClosestMass(Const::pion);
234 double correction = 1.0;
235 if (tfr && m_matchTrack == 2) correction = sin(tfr->
getMomentum().Theta());
237 for (
auto& cluster : pxdClustersTrack) {
238 if (m_relationCheck) {
239 if (m_storeClustersName ==
"PXDClustersFromTracks") {
241 if (!relPXDClusters.
size())
continue;
243 B2WARNING(
"Relation check for data only works when clustersName is set to PXDClustersFromTracks");
248 if (cluster.getCharge() >= m_minClusterCharge && cluster.getSize() >= m_minClusterSize && cluster.getSize() <= m_maxClusterSize) {
250 VxdID sensorID = cluster.getSensorID();
254 auto iSensor = gTools->getPXDSensorIndex(sensorID);
258 auto uBin = PXD::PXDGainCalibrator::getInstance().getBinU(sensorID, uID, vID, m_nBinsU);
259 auto vBin = PXD::PXDGainCalibrator::getInstance().getBinV(sensorID, vID, m_nBinsV);
260 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
263 m_signal = cluster.getCharge();
265 getObjectPtr<TTree>(treename)->Fill();
267 getObjectPtr<TH1I>(
"PXDClusterCounter")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin);
268 if (m_fillChargeHistogram)
269 getObjectPtr<TH2I>(
"PXDClusterCharge")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin,
270 cluster.getCharge()*correction);
Calibration collector module base class.
Class for accessing objects in the database.
Collector module for PXD gain calibration.
The payload class for PXD cluster charge calibrations.
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
The payload class for PXD gain corrections.
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
This is the Reconstruction Event-Data Model Track.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Values of the result of a track fit with a given particle hypothesis.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Class that bundles various TrackFitResults.
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.