51 #include "StPxlClusterMaker.h"
52 #include "StMessMgr.h"
53 #include "StPxlCluster.h"
54 #include "StPxlClusterCollection.h"
55 #include "StPxlRawHitMaker/StPxlRawHit.h"
56 #include "StPxlRawHitMaker/StPxlRawHitCollection.h"
57 #include "StPxlUtil/StPxlConstants.h"
62 StPxlClusterMaker::StPxlClusterMaker(
const Char_t *name) :
StMaker(name),
63 mPxlClusterCollection(0),
68 void StPxlClusterMaker::Clear(
const Option_t *)
81 if (! pxlRawHitDataSet) {
82 LOG_WARN <<
"Make() - there is no pxlRawHitDataSet " << endm;
87 if (!pxlRawHitCollection) {
88 LOG_WARN <<
"Make() - no pxlRawHitCollection." << endm;
92 LOG_INFO <<
" Before clustering. Number of PxlRawHits = " << pxlRawHitCollection->
numberOfRawHits() << endm;
99 fill_n(*mRawHitMap, kNumberOfPxlRowsOnSensor * kNumberOfPxlColumnsOnSensor, static_cast<StPxlRawHit*>(0) );
102 int embeddingShortCut = IAttr(
"EmbeddingShortCut");
104 for (
int i = 0; i < kNumberOfPxlSectors; i++)
105 for (
int j = 0; j < kNumberOfPxlLaddersPerSector; j++)
106 for (
int k = 0; k < kNumberOfPxlSensorsPerLadder; k++) {
108 std::map<int, std::vector<int>> firedPixelsMap;
109 for (
int iHit=0; iHit < pxlRawHitCollection->
numberOfRawHits(i+1, j+1, k+1); ++iHit)
111 StPxlRawHit const* rawHit = pxlRawHitCollection->
rawHit(i + 1, j + 1, k + 1, iHit);
112 int const id = rawHit->
row() * 1000 + rawHit->
column();
113 firedPixelsMap[id].push_back(iHit);
116 for(
auto& pixel: firedPixelsMap)
118 std::vector<int> mcHits;
119 for(
auto const& rawHitIdx: pixel.second)
121 StPxlRawHit const* rawHit = pxlRawHitCollection->
rawHit(i + 1, j + 1, k + 1, rawHitIdx);
122 if(rawHit->
idTruth() > 0) mcHits.push_back(rawHitIdx);
127 int const rnd_idx = std::rand() %
static_cast<int>(mcHits.size());
128 StPxlRawHit const* rawHit = pxlRawHitCollection->
rawHit(i + 1, j + 1, k + 1, mcHits[rnd_idx]);
129 mRawHitMap[rawHit->
row()][rawHit->
column()] = rawHit;
133 int const rnd_idx = std::rand() %
static_cast<int>(pixel.second.size());
134 StPxlRawHit const* rawHit = pxlRawHitCollection->
rawHit(i + 1, j + 1, k + 1, pixel.second[rnd_idx]);
135 mRawHitMap[rawHit->
row()][rawHit->
column()] = rawHit;
138 if(Debug() && pixel.second.size()>1)
140 LOG_INFO <<
" ++ Two or more rawHits found in this pixel row/column = " << pixel.first/1000 <<
"/" << pixel.first%1000 << endm;
141 for(
size_t ih = 0; ih<pixel.second.size(); ++ih)
143 StPxlRawHit const* rawHit = pxlRawHitCollection->
rawHit(i + 1, j + 1, k + 1, pixel.second[ih]);
144 LOG_INFO <<
" rawHit #" << ih <<
"\t idTruth=" << rawHit->
idTruth() << endm;
146 LOG_INFO <<
" => Selected rawHit idTruth = " << mRawHitMap[pixel.first/1000][pixel.first%1000]->
idTruth() << endm;
151 for (
int l = 0; l < pxlRawHitCollection->
numberOfRawHits(i+1, j+1, k+1); l++) {
159 LOG_DEBUG <<
" ==> A new cluster added sector/ladder/sensor/row/column = " << i+1 <<
"/" << j+1 <<
"/" << k+1 <<
"/" << cluster.
rowCenter() <<
"/" << cluster.
columnCenter() <<
"\t nRawHits=" << cluster.
nRawHits() <<
"\t idTruth=" << cluster.
idTruth() << endm;
180 const StPxlRawHit *rawHit = mRawHitMap[row][column];
181 if ( !rawHit )
return;
183 mRawHitMap[row][column] = 0;
186 if ((column - 1) >= 0)
189 if ((column + 1) < kNumberOfPxlColumnsOnSensor)
195 if ((row + 1) < kNumberOfPxlRowsOnSensor)
198 if (((column - 1) >= 0) && ((row - 1) >= 0))
201 if (((column - 1) >= 0) && ((row + 1) < kNumberOfPxlRowsOnSensor))
204 if (((column + 1) < kNumberOfPxlColumnsOnSensor) && ((row - 1) >= 0))
207 if (((column + 1) < kNumberOfPxlColumnsOnSensor) && ((row + 1) < kNumberOfPxlRowsOnSensor))
const StPxlRawHit * rawHit(Int_t sector, Int_t ladder, Int_t sensor, Int_t rawHitIndex) const
pionter to a rawHit in the collection
void findCluster(StPxlCluster *cluster, Int_t column, Int_t row)
Int_t numberOfClusters(Int_t sector, Int_t ladder, Int_t sensor) const
number of clusters in a sensor
void summarize(int embeddingShortCut=0)
calculate column center, row center, and most frequent idTruth among raw hits
StPxlClusterCollection * mPxlClusterCollection
pointer to the pxl cluster collection
void addRawHit(const StPxlRawHit *rawHit)
add a raw hit to the cluster
Float_t rowCenter() const
average raw hit row
Int_t row() const
row 0-927
virtual void Clear(Option_t *option="")
User defined functions.
Int_t idTruth() const
for embedding, 0 as background, most frequent raw hit idTruth as idTruth of the cluster ...
Int_t column() const
column 0-959
Int_t nRawHits() const
number of raw hits
Int_t idTruth() const
for embedding, 0 as background
void addCluster(Int_t sector, Int_t ladder, Int_t sensor, const StPxlCluster &cluster)
add a cluster to the collection
Float_t columnCenter() const
average raw hit column
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Int_t numberOfRawHits(Int_t sector, Int_t ladder, Int_t sensor)
number of raw hits in a sensor