45 bufferAlreadySet(
false),
47 thePixelThreshold( conf.
getParameter<
int>(
"ChannelThreshold") ),
48 theSeedThreshold( conf.
getParameter<
int>(
"SeedThreshold") ),
49 theClusterThreshold( conf.
getParameter<
int>(
"ClusterThreshold") ),
50 theClusterThreshold_L1( conf.
getParameter<
int>(
"ClusterThreshold_L1") ),
51 theConversionFactor( conf.
getParameter<
int>(
"VCaltoElectronGain") ),
52 theConversionFactor_L1( conf.
getParameter<
int>(
"VCaltoElectronGain_L1") ),
53 theOffset( conf.
getParameter<
int>(
"VCaltoElectronOffset") ),
54 theOffset_L1( conf.
getParameter<
int>(
"VCaltoElectronOffset_L1") ),
55 theStackADC_( conf.
exists(
"AdcFullScaleStack") ? conf.
getParameter<
int>(
"AdcFullScaleStack") : 255 ),
56 theFirstStack_( conf.
exists(
"FirstStackLayer") ? conf.
getParameter<
int>(
"FirstStackLayer") : 5 ),
57 theElectronPerADCGain_( conf.
exists(
"ElectronPerADCGain") ? conf.
getParameter<
double>(
"ElectronPerADCGain") : 135. ),
58 theNumOfRows(0), theNumOfCols(0), detid_(0),
61 doSplitClusters( conf.
getParameter<
bool>(
"SplitClusters") )
63 theBuffer.setSize( theNumOfRows, theNumOfCols );
75 desc.
add<
int>(
"ChannelThreshold", 1000);
77 desc.
add<
bool>(
"SplitClusters",
false);
78 desc.
add<
int>(
"VCaltoElectronGain", 65);
79 desc.
add<
int>(
"VCaltoElectronGain_L1", 65);
80 desc.
add<
int>(
"VCaltoElectronOffset", -414);
81 desc.
add<
int>(
"VCaltoElectronOffset_L1", -414);
83 desc.
add<
int>(
"SeedThreshold", 1000);
84 desc.
add<
int>(
"ClusterThreshold_L1", 4000);
85 desc.
add<
int>(
"ClusterThreshold", 4000);
86 desc.
add<
int>(
"maxNumberOfClusters", -1);
87 descriptions.
add(
"siPixelClusters", desc);
100 int nrows = topol.
nrows();
103 theNumOfRows = nrows;
104 theNumOfCols =
ncols;
106 if ( nrows > theBuffer.rows() ||
107 ncols > theBuffer.columns() )
115 theBuffer.setSize(nrows,ncols);
116 bufferAlreadySet =
true;
132 const std::vector<short>& badChannels,
135 typename T::const_iterator
begin = input.begin();
136 typename T::const_iterator
end = input.end();
142 if ( !
setup(pixDet) )
145 detid_ = input.detId();
148 auto clusterThreshold = theClusterThreshold;
150 if (
layer_==1) clusterThreshold = theClusterThreshold_L1;
154 copy_to_buffer(begin, end);
156 assert(output.
empty());
159 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
164 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
171 if ( cluster.
charge() >= clusterThreshold)
187 clear_buffer(begin, end);
204 theBuffer.set_adc( di->row(), di->column(), 0 );
212 for(
int i = 0;
i < ci->size(); ++
i)
216 theBuffer.set_adc( pixel.
x, pixel.
y, 0 );
226 #ifdef PIXELREGRESSION 227 static std::atomic<int> s_ic=0;
234 memset(electron, 0,
sizeof(electron));
235 if ( doMissCalibrate ) {
237 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor_L1, theOffset_L1,electron);
239 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor, theOffset, electron);
244 auto adc = di->adc();
245 const float gain = theElectronPerADCGain_;
247 electron[
i] =
int(
adc * gain + pedestal);
248 if (
layer_>=theFirstStack_) {
249 if (theStackADC_==1&&
adc==1) {
250 electron[
i] =
int(255*135);
252 if (theStackADC_>1&&theStackADC_!=255&&
adc>=1){
253 const float gain = theElectronPerADCGain_;
254 electron[
i] =
int((
adc-1) * gain * 255/
float(theStackADC_-1));
259 assert(i==(end-begin));
263 #ifdef PIXELREGRESSION 264 static std::atomic<int> eqD=0;
268 int col = di->column();
269 int adc = electron[i++];
271 #ifdef PIXELREGRESSION 272 int adcOld = calibrate(di->adc(),
col,row);
274 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
282 if ( adc >= thePixelThreshold) {
283 theBuffer.set_adc( row, col, adc);
287 assert(i==(end-begin));
296 for(
int i = 0;
i < ci->size(); ++
i) {
302 if ( adc >= thePixelThreshold) {
303 theBuffer.add_adc( row, col, adc);
317 if ( doMissCalibrate )
321 if ( !theSiPixelGainCalibrationService_->isDead(detid_,col,row) &&
322 !theSiPixelGainCalibrationService_->isNoisy(detid_,col,row) )
333 float DBgain = theSiPixelGainCalibrationService_->getGain(detid_, col, row);
334 float pedestal = theSiPixelGainCalibrationService_->getPedestal(detid_, col, row);
335 float DBpedestal = pedestal * DBgain;
341 float vcal = adc * DBgain - DBpedestal;
357 electrons =
int( vcal * theConversionFactor_L1 + theOffset_L1);
359 electrons =
int( vcal * theConversionFactor + theOffset);
367 const float gain = theElectronPerADCGain_;
369 electrons =
int(adc * gain + pedestal);
370 if (
layer_>=theFirstStack_) {
371 if (theStackADC_==1&&adc==1)
373 electrons =
int(255*135);
375 if (theStackADC_>1&&theStackADC_!=255&&adc>=1)
377 const float gain = theElectronPerADCGain_;
378 electrons =
int((adc-1) * gain * 255/
float(theStackADC_-1));
396 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
415 seed_adc = theBuffer(pix.
row(), pix.
col());
416 theBuffer.set_adc( pix, 1);
420 acluster.
add(pix, seed_adc);
423 bool dead_flag =
false;
424 while ( ! acluster.
empty())
427 auto curInd = acluster.
top(); acluster.
pop();
428 for (
auto c =
std::max(0,
int(acluster.
y[curInd])-1);
c <
std::min(
int(acluster.
y[curInd])+2,theBuffer.columns()) ; ++
c) {
429 for (
auto r =
std::max(0,
int(acluster.
x[curInd])-1);
r <
std::min(
int(acluster.
x[curInd])+2,theBuffer.rows()); ++
r) {
430 if ( theBuffer(
r,
c) >= thePixelThreshold) {
432 if (!acluster.
add( newpix, theBuffer(
r,
c)))
goto endClus;
433 theBuffer.set_adc( newpix, 1);
471 if (dead_flag && doSplitClusters)
474 auto clusterThreshold = theClusterThreshold;
475 if (
layer_==1) clusterThreshold = theClusterThreshold_L1;
479 bool have_second_cluster =
false;
480 while ( !dead_pixel_stack.empty() )
484 theBuffer.set_adc(deadpix, 1);
490 if ( second_cluster.
charge() >= clusterThreshold &&
491 first_cluster.
charge() >= clusterThreshold )
494 have_second_cluster =
true;
499 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
500 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
502 int temp_x = branch_pixels[
i].x;
503 int temp_y = branch_pixels[
i].y;
504 int temp_adc = branch_pixels[
i].adc;
506 cluster.
add(newpix, temp_adc);}
510 if ( first_cluster.
charge() >= clusterThreshold && have_second_cluster)
int adc(sample_type sample)
get the ADC sample (12 bits)
void clusterizeDetUnitT(const T &input, const PixelGeomDetUnit *pixDet, const TrackerTopology *tTopo, const std::vector< short > &badChannels, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)
Cluster pixels. This method operates on a matrix of pixels and finds the largest contiguous cluster a...
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void push_back(data_type const &d)
virtual int nrows() const =0
static const char layer_[]
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
PixelThresholdClusterizer(edm::ParameterSet const &conf)
SiPixelCluster make_cluster(const SiPixelCluster::PixelPos &pix, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)
The actual clustering algorithm: group the neighboring pixels around the seed.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static std::string const input
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
edm::DetSet< PixelDigi >::const_iterator DigiIterator
void add(const PixelPos &pix, int adc)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool add(SiPixelCluster::PixelPos const &p, UShort const iadc)
constexpr int col() const
unsigned int pxbLayer(const DetId &id) const
edmNew::DetSet< SiPixelCluster >::const_iterator ClusterIterator
void clear_buffer(DigiIterator begin, DigiIterator end)
Clear the internal buffer array.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Pixel cluster – collection of neighboring pixels above threshold.
virtual int ncolumns() const =0
bool setup(const PixelGeomDetUnit *pixDet)
Private helper methods:
~PixelThresholdClusterizer() override
int calibrate(int adc, int col, int row)
constexpr int row() const
const std::vector< Pixel > pixels() const
void copy_to_buffer(DigiIterator begin, DigiIterator end)
Copy adc counts from PixelDigis into the buffer, identify seeds.