46 bufferAlreadySet(
false),
48 thePixelThreshold( conf.
getParameter<
int>(
"ChannelThreshold") ),
49 theSeedThreshold( conf.
getParameter<
int>(
"SeedThreshold") ),
50 theClusterThreshold( conf.
getParameter<
double>(
"ClusterThreshold") ),
51 theConversionFactor( conf.
getParameter<
int>(
"VCaltoElectronGain") ),
52 theOffset( conf.
getParameter<
int>(
"VCaltoElectronOffset") ),
53 theStackADC_( conf.
exists(
"AdcFullScaleStack") ? conf.
getParameter<
int>(
"AdcFullScaleStack") : 255 ),
54 theFirstStack_( conf.
exists(
"FirstStackLayer") ? conf.
getParameter<
int>(
"FirstStackLayer") : 5 ),
55 theElectronPerADCGain_( conf.
exists(
"ElectronPerADCGain") ? conf.
getParameter<
double>(
"ElectronPerADCGain") : 135. ),
56 theNumOfRows(0), theNumOfCols(0), detid_(0),
59 doSplitClusters( conf.
getParameter<
bool>(
"SplitClusters") )
61 theBuffer.setSize( theNumOfRows, theNumOfCols );
76 int nrows = topol.
nrows();
82 if ( nrows > theBuffer.rows() ||
83 ncols > theBuffer.columns() )
91 theBuffer.setSize(nrows,ncols);
92 bufferAlreadySet =
true;
107 const std::vector<short>& badChannels,
110 typename T::const_iterator
begin = input.begin();
111 typename T::const_iterator
end = input.end();
117 if ( !
setup(pixDet) )
120 detid_ = input.detId();
124 copy_to_buffer(begin, end);
126 assert(output.
empty());
129 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
134 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
141 if ( cluster.
charge() >= theClusterThreshold)
157 clear_buffer(begin, end);
174 theBuffer.set_adc( di->row(), di->column(), 0 );
182 for(
int i = 0;
i < ci->size(); ++
i)
186 theBuffer.set_adc( pixel.
x, pixel.
y, 0 );
196 #ifdef PIXELREGRESSION 197 static std::atomic<int> s_ic=0;
204 memset(electron, 0,
sizeof(electron));
205 if ( doMissCalibrate ) {
206 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor, theOffset,electron);
211 auto adc = di->adc();
212 const float gain = theElectronPerADCGain_;
214 electron[
i] =
int(
adc * gain + pedestal);
215 if (layer>=theFirstStack_) {
216 if (theStackADC_==1&&
adc==1) {
217 electron[
i] =
int(255*135);
219 if (theStackADC_>1&&theStackADC_!=255&&
adc>=1){
220 const float gain = theElectronPerADCGain_;
221 electron[
i] =
int((
adc-1) * gain * 255/
float(theStackADC_-1));
226 assert(i==(end-begin));
230 #ifdef PIXELREGRESSION 231 static std::atomic<int> eqD=0;
235 int col = di->column();
236 int adc = electron[i++];
237 #ifdef PIXELREGRESSION 238 int adcOld = calibrate(di->adc(),
col,row);
240 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
242 if ( adc >= thePixelThreshold) {
243 theBuffer.set_adc( row, col, adc);
247 assert(i==(end-begin));
256 for(
int i = 0;
i < ci->size(); ++
i) {
262 if ( adc >= thePixelThreshold) {
263 theBuffer.add_adc( row, col, adc);
279 if ( doMissCalibrate )
283 if ( !theSiPixelGainCalibrationService_->isDead(detid_,col,row) &&
284 !theSiPixelGainCalibrationService_->isNoisy(detid_,col,row) )
295 float DBgain = theSiPixelGainCalibrationService_->getGain(detid_, col, row);
296 float DBpedestal = theSiPixelGainCalibrationService_->getPedestal(detid_, col, row) * DBgain;
303 float vcal = adc * DBgain - DBpedestal;
318 electrons =
int( vcal * theConversionFactor + theOffset);
324 const float gain = theElectronPerADCGain_;
326 electrons =
int(adc * gain + pedestal);
327 if (layer>=theFirstStack_) {
328 if (theStackADC_==1&&adc==1)
330 electrons =
int(255*135);
332 if (theStackADC_>1&&theStackADC_!=255&&adc>=1)
334 const float gain = theElectronPerADCGain_;
335 electrons =
int((adc-1) * gain * 255/
float(theStackADC_-1));
353 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
372 seed_adc = theBuffer(pix.
row(), pix.
col());
373 theBuffer.set_adc( pix, 1);
377 acluster.
add(pix, seed_adc);
380 bool dead_flag =
false;
381 while ( ! acluster.
empty())
384 auto curInd = acluster.
top(); acluster.
pop();
385 for (
auto c =
std::max(0,
int(acluster.
y[curInd])-1);
c <
std::min(
int(acluster.
y[curInd])+2,theBuffer.columns()) ; ++
c) {
386 for (
auto r =
std::max(0,
int(acluster.
x[curInd])-1);
r <
std::min(
int(acluster.
x[curInd])+2,theBuffer.rows()); ++
r) {
387 if ( theBuffer(
r,
c) >= thePixelThreshold) {
389 if (!acluster.
add( newpix, theBuffer(
r,
c)))
goto endClus;
390 theBuffer.set_adc( newpix, 1);
428 if (dead_flag && doSplitClusters)
432 bool have_second_cluster =
false;
433 while ( !dead_pixel_stack.empty() )
437 theBuffer.set_adc(deadpix, 1);
443 if ( second_cluster.
charge() >= theClusterThreshold &&
444 first_cluster.
charge() >= theClusterThreshold )
447 have_second_cluster =
true;
452 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
453 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
455 int temp_x = branch_pixels[
i].x;
456 int temp_y = branch_pixels[
i].y;
457 int temp_adc = branch_pixels[
i].adc;
459 cluster.
add(newpix, temp_adc);}
463 if ( first_cluster.
charge() >= theClusterThreshold && have_second_cluster)
int adc(sample_type sample)
get the ADC sample (12 bits)
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
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)
unsigned int layer() const
layer id
static std::string const input
void clusterizeDetUnitT(const T &input, const PixelGeomDetUnit *pixDet, 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...
~PixelThresholdClusterizer()
edm::DetSet< PixelDigi >::const_iterator DigiIterator
void add(const PixelPos &pix, int adc)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool add(SiPixelCluster::PixelPos const &p, UShort const iadc)
constexpr int col() 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.
Pixel cluster – collection of neighboring pixels above threshold.
virtual int ncolumns() const =0
bool setup(const PixelGeomDetUnit *pixDet)
Private helper methods:
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.