11 #include <pxd/modules/pxdClusterChargeCollector/PXDClusterChargeCollectorModule.h>
13 #include <framework/datastore/RelationArray.h>
15 #include <vxd/geometry/GeoCache.h>
16 #include <pxd/geometry/SensorInfo.h>
17 #include <pxd/reconstruction/PXDGainCalibrator.h>
22 #include <boost/format.hpp>
38 , m_signal(0), m_run(0), m_exp(0)
41 setDescription(
"Calibration collector module for cluster charge related calibrations.");
42 setPropertyFlags(c_ParallelProcessingCertified);
44 addParam(
"clustersName", m_storeClustersName,
"Name of the collection to use for PXDClusters",
string(
""));
45 addParam(
"mcParticlesName", m_storeMCParticlesName,
"Name of the collection to use for MCParticles",
string(
"MCParticles"));
46 addParam(
"minClusterCharge", m_minClusterCharge,
"Minimum cluster charge cut",
int(0));
47 addParam(
"minClusterSize", m_minClusterSize,
"Minimum cluster size cut ",
int(2));
48 addParam(
"maxClusterSize", m_maxClusterSize,
"Maximum cluster size cut ",
int(6));
49 addParam(
"nBinsU", m_nBinsU,
"Number of gain corrections per sensor along u side",
int(4));
50 addParam(
"nBinsV", m_nBinsV,
"Number of gain corrections per sensor along v side",
int(6));
51 addParam(
"chargePayloadName", m_chargeName,
"Payload name for Cluster Charge to be read from DB",
string(
""));
52 addParam(
"gainPayloadName", m_gainName,
"Payload name for Gain to be read from DB",
string(
""));
53 addParam(
"fillChargeHistogram", m_fillChargeHistogram,
"Flag to fill Charge histograms",
bool(
false));
54 addParam(
"matchTrack", m_matchTrack,
55 "Flag to use track matched clusters (=1) and apply theta angle projection to cluster charge (=2)",
int(0));
56 addParam(
"mcSamples", m_mcSamples,
"Flag to deal with MC samples",
bool(
false));
57 addParam(
"relationCheck", m_relationCheck,
"Flag to check relations between PXDClusters and PXDClustersFromTracks",
bool(
false));
61 void PXDClusterChargeCollectorModule::prepare()
63 m_pxdClusters.isRequired(m_storeClustersName);
64 if (m_relationCheck) {
65 std::string storeClustersName2;
66 storeClustersName2 = (m_storeClustersName ==
"PXDClusters") ?
67 "PXDClustersFromTracks" :
"PXDClusters";
69 pxdClusters2.isRequired(storeClustersName2);
71 m_tracks.isOptional();
72 m_recoTracks.isOptional();
74 if (m_mcSamples && m_matchTrack > 0) {
75 m_mcParticles.isRequired(m_storeMCParticlesName);
77 m_mcParticles.isOptional();
81 B2WARNING(
"Number of bins along u side incremented from 0->1");
86 B2WARNING(
"Number of bins along v side incremented from 0->1");
90 auto gTools = VXD::GeoCache::getInstance().getGeoTools();
91 int nPXDSensors = gTools->getNumberOfPXDSensors();
97 auto hPXDClusterCounter =
new TH1I(
"hPXDClusterCounter",
"Number of clusters found in data sample",
98 m_nBinsU * m_nBinsV * nPXDSensors, 0,
99 m_nBinsU * m_nBinsV * nPXDSensors);
100 hPXDClusterCounter->GetXaxis()->SetTitle(
"bin id");
101 hPXDClusterCounter->GetYaxis()->SetTitle(
"Number of clusters");
102 for (
int iSensor = 0; iSensor < nPXDSensors; iSensor++) {
103 for (
int uBin = 0; uBin < m_nBinsU; uBin++) {
104 for (
int vBin = 0; vBin < m_nBinsV; vBin++) {
105 VxdID id = gTools->getSensorIDFromPXDIndex(iSensor);
106 string sensorDescr = id;
107 hPXDClusterCounter->GetXaxis()->SetBinLabel(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin + 1,
108 str(format(
"%1%_%2%_%3%") % sensorDescr % uBin % vBin).c_str());
112 registerObject<TH1I>(
"PXDClusterCounter", hPXDClusterCounter);
113 if (m_fillChargeHistogram) {
114 auto hPXDClusterCharge =
new TH2I(
"hPXDClusterCharge",
"Charge of clusters found in data sample",
115 m_nBinsU * m_nBinsV * nPXDSensors, 0,
116 m_nBinsU * m_nBinsV * nPXDSensors,
118 hPXDClusterCharge->GetXaxis()->SetTitle(
"bin id");
119 hPXDClusterCharge->GetYaxis()->SetTitle(
"Cluster charge [ADU]");
120 registerObject<TH2I>(
"PXDClusterCharge", hPXDClusterCharge);
127 for (
int iSensor = 0; iSensor < nPXDSensors; iSensor++) {
128 for (
int uBin = 0; uBin < m_nBinsU; uBin++) {
129 for (
int vBin = 0; vBin < m_nBinsV; vBin++) {
130 VxdID id = gTools->getSensorIDFromPXDIndex(iSensor);
132 auto ladderNumber =
id.getLadderNumber();
133 auto sensorNumber =
id.getSensorNumber();
134 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
135 auto tree =
new TTree(treename.c_str(), treename.c_str());
136 tree->Branch<
int>(
"signal", &m_signal);
137 registerObject<TTree>(treename, tree);
142 auto dbtree =
new TTree(
"dbtree",
"dbtree");
143 dbtree->Branch<
int>(
"run", &m_run);
144 dbtree->Branch<
int>(
"exp", &m_exp);
147 registerObject<TTree>(
"dbtree", dbtree);
150 void PXDClusterChargeCollectorModule::startRun()
152 m_run = m_evtMetaData->getRun();
153 m_exp = m_evtMetaData->getExperiment();
154 if (m_chargeName.length()) {
156 m_chargeMap = *chargeMap;
160 if (m_gainName.length()) {
162 m_gainMap = *gainMap;
166 getObjectPtr<TTree>(
"dbtree")->Fill();
169 void PXDClusterChargeCollectorModule::collect()
172 if (!m_pxdClusters)
return;
174 auto gTools = VXD::GeoCache::getInstance().getGeoTools();
176 if (!m_matchTrack || m_mcSamples) {
178 for (
auto& cluster : m_pxdClusters) {
179 if (m_relationCheck) {
180 if (m_storeClustersName ==
"PXDClusters") {
182 if (!relPXDClusters.
size())
continue;
183 }
else if (m_storeClustersName ==
"PXDClustersFromTracks") {
185 if (!relPXDClusters.
size())
continue;
188 double correction = 1.0;
189 if (m_matchTrack > 0) {
191 if (!mcParticlesPXD.
size())
continue;
192 if (m_matchTrack == 2) {
193 correction = sin(mcParticlesPXD[0]->getMomentum().Theta());
197 if (cluster.getCharge() >= m_minClusterCharge && cluster.getSize() >= m_minClusterSize && cluster.getSize() <= m_maxClusterSize) {
199 VxdID sensorID = cluster.getSensorID();
203 auto iSensor = gTools->getPXDSensorIndex(sensorID);
207 auto uBin = PXD::PXDGainCalibrator::getInstance().getBinU(sensorID, uID, vID, m_nBinsU);
208 auto vBin = PXD::PXDGainCalibrator::getInstance().getBinV(sensorID, vID, m_nBinsV);
209 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
212 m_signal = cluster.getCharge();
214 getObjectPtr<TTree>(treename)->Fill();
216 getObjectPtr<TH1I>(
"PXDClusterCounter")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin);
217 if (m_fillChargeHistogram)
218 getObjectPtr<TH2I>(
"PXDClusterCharge")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin,
219 cluster.getCharge()*correction);
227 if (!m_tracks)
return;
229 for (
const Track& track : m_tracks) {
232 if (!recoTrack.
size())
continue;
235 const TrackFitResult* tfr = track.getTrackFitResultWithClosestMass(Const::pion);
236 double correction = 1.0;
237 if (tfr && m_matchTrack == 2) correction = sin(tfr->
getMomentum().Theta());
239 for (
auto& cluster : pxdClustersTrack) {
240 if (m_relationCheck) {
241 if (m_storeClustersName ==
"PXDClustersFromTracks") {
243 if (!relPXDClusters.
size())
continue;
245 B2WARNING(
"Relation check for data only works when clustersName is set to PXDClustersFromTracks");
250 if (cluster.getCharge() >= m_minClusterCharge && cluster.getSize() >= m_minClusterSize && cluster.getSize() <= m_maxClusterSize) {
252 VxdID sensorID = cluster.getSensorID();
256 auto iSensor = gTools->getPXDSensorIndex(sensorID);
260 auto uBin = PXD::PXDGainCalibrator::getInstance().getBinU(sensorID, uID, vID, m_nBinsU);
261 auto vBin = PXD::PXDGainCalibrator::getInstance().getBinV(sensorID, vID, m_nBinsV);
262 string treename = str(format(
"tree_%1%_%2%_%3%_%4%_%5%") % layerNumber % ladderNumber % sensorNumber % uBin % vBin);
265 m_signal = cluster.getCharge();
267 getObjectPtr<TTree>(treename)->Fill();
269 getObjectPtr<TH1I>(
"PXDClusterCounter")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin);
270 if (m_fillChargeHistogram)
271 getObjectPtr<TH2I>(
"PXDClusterCharge")->Fill(iSensor * m_nBinsU * m_nBinsV + uBin * m_nBinsV + vBin,
272 cluster.getCharge()*correction);