CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterProducerFP420.cc
Go to the documentation of this file.
1 // File: ClusterProducerFP420.cc
3 // Date: 12.2006
4 // Description: ClusterProducerFP420 for FP420
5 // Modifications:
8 using namespace std;
9 
10 // sense of xytype here is X or Y type planes. Now we are working with X only, i.e. xytype=2
11 
13  const std::vector<short>& badChannels) const
14 {
15  const std::vector<short>::size_type linearCutoff = 20;// number of possible bad channels
16  // check: is it bad cnannel or not
17  /*
18  std::cout
19  << "badChannel: badChannels.size()= " << badChannels.size() << " \t"
20  << "badChannel: hardcoded linearCutoff= " << linearCutoff << " \t"
21  << "badChannel: channel= " << channel << " \t"
22  << std::endl;
23 */
24  if (badChannels.size() < linearCutoff) {
25  return (std::find( badChannels.begin(), badChannels.end(), channel) != badChannels.end());
26  }
27  else return std::binary_search( badChannels.begin(), badChannels.end(), channel);
28 
29 
30 }
31 
32 
33 //FIXME
34 //In the future, with blobs, perhaps we will come back at this version
35 // std::vector<ClusterFP420>
36 // ClusterProducerFP420::clusterizeDetUnit( DigiIterator begin, DigiIterator end,
37 // unsigned int detid,
38 // const std::vector<float>& noiseVec,
39 // const std::vector<short>& badChannels)
40 // {
41 
42 // digiRangeIteratorBegin,digiRangeIteratorEnd
44  unsigned int detid, const ElectrodNoiseVector& vnoise){
45 // const std::vector<short>& badChannels)
46 
47  //reminder: int zScale=2; unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+xytype;
48  // const int maxBadChannels_ = 1;
49  HDigiFP420Iter ibeg, iend, ihigh, itest, i;
50  ibeg = iend = begin;
51  std::vector<HDigiFP420> cluster_digis;
52  // reserve 15 possible channels for one cluster
53  cluster_digis.reserve(15);
54  // reserve one third of digiRange for number of clusters
55  std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
56  // predicate(declare): take noise above seed_thr
57  AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
58  //Check if channel is lower than vnoise.size()
59  itest = end - 1;
60  int vnoisesize = vnoise.size();
61  // if (vnoise.size()<=itest->channel()) // old
62  if (vnoisesize<=itest->channel())
63  {
64  std::cout << "WARNING for detid " << detid << " there will be a request for noise for channel seed" << itest->channel() << " but this detid has vnoise.size= " << vnoise.size() << "\nskip"<< std::endl;
65  return rhits;
66  }
67  //
68  // loop in elements above seed_thr
69  // find seed with seed noise above seed_thr
70  while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
71  // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
72  // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
73  // to iend, and itest is the electrode under study, not yet accepted.
74 
75  // go to right side:
76  iend = ihigh;
77  itest = iend + 1;
78  while ( itest != end && (itest->channel() - iend->channel() <= max_voids_ + 1 )) {
79  float channelNoise = vnoise[itest->channel()].getNoise();
80  bool IsBadChannel = vnoise[itest->channel()].getDisable();
81  if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
82  iend = itest;
83  }
84  ++itest;
85  }
86  //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
87  itest=iend+1;
88  if ( itest != end && (itest->channel() - iend->channel() == 1) && vnoise[itest->channel()].getDisable() ) {
89  std::cout << "Inserted bad electrode at the end edge iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
90  iend++;
91  }
92  // go to left side:
93  ibeg = ihigh;
94  itest = ibeg - 1;
95  while ( itest >= begin && (ibeg->channel() - itest->channel() <= max_voids_ + 1 )) {
96  float channelNoise = vnoise[itest->channel()].getNoise();
97  bool IsBadChannel = vnoise[itest->channel()].getDisable();
98  if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
99  ibeg = itest;
100  }
101  --itest;
102  }
103  //if the next digi after ibeg is an adiacent bad digi then insert into candidate cluster
104  itest=ibeg-1;
105  if ( itest >= begin && (ibeg->channel() - itest->channel() == 1) && vnoise[itest->channel()].getDisable() ) {
106  std::cout << "Inserted bad electrode at the begin edge ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
107  ibeg--;
108  }
109  //============================================================================================================
110  int charge = 0;
111  float sigmaNoise2=0;
112  cluster_digis.clear();
113  for (i=ibeg; i<=iend; ++i) {
114  float channelNoise = vnoise[i->channel()].getNoise();
115  bool IsBadChannel = vnoise[i->channel()].getDisable();
116  //just check for consecutive digis
117  if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
118  //digits: *(i-1) and *i are not consecutive(we asked !=1-> it means 2...),so create an equivalent number of Digis with zero amp
119  for (int j=(i-1)->channel()+1;j<i->channel();++j){
120  cluster_digis.push_back(HDigiFP420(j,0)); //if electrode bad or under threshold set HDigiFP420.adc_=0
121  }
122  }
123  //
124 
125 // FIXME: should the digi be tested for badChannel before using the adc?
126 
127  if (!IsBadChannel && i->adc() >= static_cast<int>( channelThresholdInNoiseSigma()*channelNoise)) {
128  charge += i->adc();
129  sigmaNoise2 += channelNoise*channelNoise; //
130  cluster_digis.push_back(*i);// put into cluster_digis good i info
131  } else {
132  cluster_digis.push_back(HDigiFP420(i->channel(),0)); //if electrode bad or under threshold set HDigiFP420.adc_=0
133  }
134  //
135  }//for i++
136  float sigmaNoise = sqrt(sigmaNoise2);
137  // define here cog,err,xytype not used
138  float cog;
139  float err;
140  unsigned int xytype=2;// it can be even =1,although we are working with =2(Xtypes of planes)
141  if (charge >= static_cast<int>( clusterThresholdInNoiseSigma()*sigmaNoise)) {
142  rhits.push_back( ClusterFP420( detid, xytype, ClusterFP420::HDigiFP420Range( cluster_digis.begin(),
143  cluster_digis.end()),
144  cog, err));
145  // std::cout << "Looking at cog and err : cog " << cog << " err " << err << std::endl;
146  }
147  ibeg = iend+1;
148  } // while ( ibeg
149  return rhits;
150 }
151 
152 int ClusterProducerFP420::difNarr(unsigned int xytype, HDigiFP420Iter ichannel,
153  HDigiFP420Iter jchannel) {
154  int d = 9999;
155  if(xytype == 2) {
156  d = ichannel->stripV() - jchannel->stripV();
157  d=std::abs(d);
158  }
159  else if(xytype == 1) {
160  d = ichannel->stripH() - jchannel->stripH();
161  d=std::abs(d);
162  }
163  else{
164  std::cout << "difNarr: wrong xytype = " << xytype << std::endl;
165  }
166  return d;
167 }
168 int ClusterProducerFP420::difWide(unsigned int xytype, HDigiFP420Iter ichannel,
169  HDigiFP420Iter jchannel) {
170  int d = 9999;
171  if(xytype == 2) {
172  d = ichannel->stripVW() - jchannel->stripVW();
173  d=std::abs(d);
174  }
175  else if(xytype == 1) {
176  d = ichannel->stripHW() - jchannel->stripHW();
177  d=std::abs(d);
178  }
179  else{
180  std::cout << "difWide: wrong xytype = " << xytype << std::endl;
181  }
182  return d;
183 }
184 // digiRangeIteratorBegin,digiRangeIteratorEnd
186  unsigned int detid, const ElectrodNoiseVector& vnoise, unsigned int xytype, int verb){
187 // const std::vector<short>& badChannels)
188 
189  //reminder: int zScale=2; unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+xytype;
190 
191  // const int maxBadChannels_ = 1;
192 
193  HDigiFP420Iter ibeg, iend, ihigh, itest, i;
194  ibeg = iend = begin;
195  std::vector<HDigiFP420> cluster_digis;
196 
197  // reserve 25 possible channels for one cluster
198  cluster_digis.reserve(25);
199 
200  // reserve one third of digiRange for number of clusters
201  std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
202 
203  // predicate(declare): take noise above seed_thr
204  AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
205 
206  //Check if no channels with digis at all
207  /*
208  HDigiFP420Iter abeg, aend;
209  abeg = begin; aend = end;
210  std::vector<HDigiFP420> a_digis;
211  for ( ;abeg != aend; ++abeg ) {
212  a_digis.push_back(*abeg);
213  } // for
214  if (a_digis.size()<1) return rhits;;
215 */
216  //Check if channel is lower than vnoise.size()
217  itest = end - 1;
218  int vnoisesize = vnoise.size();
219  if (vnoisesize<=itest->channel())
220  {
221 // std::cout << "WARNING for detid " << detid << " there will be a request for noise for channel seed" << itest->channel() << " but this detid has vnoise.size= " << vnoise.size() << "\nskip"<< std::endl;
222  return rhits;
223  }
224  //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
225 
226  // std::cout << "before while loop..." << std::endl;
227 
228  // loop in elements above seed_thr
229  // find seed with seed noise above seed_thr
230  while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
231 
232 
233  // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
234  // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
235  // to iend, and itest is the electrode under study, not yet accepted.
236 
237  // go to right side:
238  iend = ihigh;
239  itest = iend + 1;
240  // while ( itest != end && (itest->channel() - iend->channel() <= max_voids_ + 1 )) {
241  while ( itest != end && (difNarr(xytype,itest,iend)<= max_voids_ + 1 ) && (difWide(xytype,itest,iend)<= 1) ) {
242  float channelNoise = vnoise[itest->channel()].getNoise();
243  bool IsBadChannel = vnoise[itest->channel()].getDisable();
244  if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
245  iend = itest;
246  if(verb>2){
247  std::cout << "=========================================================================== " << std::endl;
248  std::cout << "Right side: itest->adc()= " << itest->adc() << " channel_noise = " << static_cast<int>( channelThresholdInNoiseSigma() * channelNoise) << std::endl;
249  }
250  }
251  ++itest;
252  }
253  //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
254  itest=iend+1;
255  if ( itest != end && (difNarr(xytype,itest,iend) == 1) && (difWide(xytype,itest,iend)< 1) && vnoise[itest->channel()].getDisable() ) {
256  if(verb>2){
257  std::cout << "Inserted bad electrode at the end edge iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
258  }
259  iend++;
260  }
261  if(verb>2){
262  std::cout << "Result of going to right side iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
263  }
264 
265  // go to left side:
266  ibeg = ihigh;
267  itest = ibeg - 1;
268  // while ( itest >= begin && (ibeg->channel() - itest->channel() <= max_voids_ + 1 )) {
269  while ( itest >= begin && (difNarr(xytype,ibeg,itest) <= max_voids_ + 1 ) && (difWide(xytype,ibeg,itest) <= 1) ) {
270  float channelNoise = vnoise[itest->channel()].getNoise();
271  bool IsBadChannel = vnoise[itest->channel()].getDisable();
272  if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
273  ibeg = itest;
274  if(verb>2){
275  std::cout << "Left side: itest->adc()= " << itest->adc() << " channel_noise = " << static_cast<int>( channelThresholdInNoiseSigma() * channelNoise) << std::endl;
276  }
277  }
278  --itest;
279  }
280  //if the next digi after ibeg is an adjacent bad digi then insert into candidate cluster
281  itest=ibeg-1;
282  if ( itest >= begin && (difNarr(xytype,ibeg,itest) == 1) && (difWide(xytype,ibeg,itest) < 1) && vnoise[itest->channel()].getDisable() ) {
283  if(verb>2){
284  std::cout << "Inserted bad electrode at the begin edge ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
285  }
286  ibeg--;
287  }
288  if(verb>2){
289  std::cout << "Result of going to left side ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
290  }
291  //============================================================================================================
292 
293 
294 
295 
296 
297  //============================================================================================================
298  int charge = 0;
299  float sigmaNoise2=0;
300  cluster_digis.clear();
301  // HDigiFP420Iter ilast=ibeg; // AZ
302  if(verb>2){
303  std::cout << "check for consecutive digis ibeg->channel()= " << ibeg->channel() << " iend->channel() = " << iend->channel() << std::endl;
304  }
305  for (i=ibeg; i<=iend; ++i) {
306  float channelNoise = vnoise[i->channel()].getNoise();
307  bool IsBadChannel = vnoise[i->channel()].getDisable();
308  if(verb>2){
309  std::cout << "Looking at cluster digis: detid " << detid << " digis " << i->channel()
310  << " adc " << i->adc() << " channelNoise " << channelNoise << " IsBadChannel " << IsBadChannel << std::endl;
311  }
312 
313  //just check for consecutive digis
314  // if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
315  //if (i!=ibeg && difNarr(xytype,i,i-1) !=1 && difWide(xytype,i,i-1) !=1){
316  if(verb>2){
317  std::cout << "difNarr(xytype,i,i-1) = " << difNarr(xytype,i,i-1) << std::endl;
318  std::cout << "difWide(xytype,i,i-1) = " << difWide(xytype,i,i-1) << std::endl;
319  }
320  // in fact, no sense in this check, but still keep if something wrong is going:
321  // if (i!=ibeg && (difNarr(xytype,i,i-1) > 1 || difWide(xytype,i,i-1) > 1) ){
322  if (i!=ibeg && (difNarr(xytype,i,i-1) > 1 && difWide(xytype,i,i-1) > 1) ){
323  //digits: *(i-1) and *i are not consecutive(we asked !=1-> it means 2...),so create an equivalent number of Digis with zero amp
324  for (int j=(i-1)->channel()+1;j<i->channel();++j){
325  if(verb>2){
326  std::cout << "not consecutive digis: set HDigiFP420.adc_=0 : j = " << j << std::endl;
327  }
328  cluster_digis.push_back(HDigiFP420(j,0)); //if not consecutive digis set HDigiFP420.adc_=0
329  }//for
330  }//if
331 
332 
333  if (!IsBadChannel && i->adc() >= static_cast<int>( channelThresholdInNoiseSigma()*channelNoise)) {
334  charge += i->adc();
335  sigmaNoise2 += channelNoise*channelNoise; //
336  cluster_digis.push_back(*i);// put into cluster_digis good i info
337  if(verb>2){
338  std::cout << "put into cluster_digis good i info: i->channel() = " << i->channel() << std::endl;
339  }
340  } else {
341  cluster_digis.push_back(HDigiFP420(i->channel(),0)); //if electrode bad or under threshold set HDigiFP420.adc_=0
342  if(verb>2){
343  std::cout << "else if electrode bad or under threshold set HDigiFP420.adc_=0: i->channel() = " << i->channel() << std::endl;
344  }
345  }//if else
346 
347  }//for i++
348 
349 
350 
351 
352  float sigmaNoise = sqrt(sigmaNoise2);
353  float cog;
354  float err;
355  if (charge >= static_cast<int>( clusterThresholdInNoiseSigma()*sigmaNoise)) {
356  rhits.push_back( ClusterFP420( detid, xytype, ClusterFP420::HDigiFP420Range( cluster_digis.begin(),
357  cluster_digis.end()),
358  cog, err));
359  if(verb>2){
360  std::cout << "Looking at cog and err : cog " << cog << " err " << err << std::endl;
361  std::cout << "=========================================================================== " << std::endl;
362  }
363  }
364 
365 
366  ibeg = iend+1;
367  } // while ( ibeg
368 
369 
370  return rhits;
371 
372 }
373 
374 
375 
int i
Definition: DBlmapReader.cc:9
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< ClusterNoiseFP420::ElectrodData > ElectrodNoiseVector
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint16_t size_type
double charge(const std::vector< uint8_t > &Ampls)
std::pair< HDigiFP420Iter, HDigiFP420Iter > HDigiFP420Range
Definition: ClusterFP420.h:11
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
std::vector< HDigiFP420 >::const_iterator HDigiFP420Iter
#define end
Definition: vmac.h:38
std::vector< ClusterFP420 > clusterizeDetUnit(HDigiFP420Iter begin, HDigiFP420Iter end, unsigned int detid, const ElectrodNoiseVector &vnoise)
bool badChannel(int channel, const std::vector< short > &badChannels) const
int difNarr(unsigned int xytype, HDigiFP420Iter ichannel, HDigiFP420Iter jchannel)
#define begin
Definition: vmac.h:31
std::vector< ClusterFP420 > clusterizeDetUnitPixels(HDigiFP420Iter begin, HDigiFP420Iter end, unsigned int detid, const ElectrodNoiseVector &vnoise, unsigned int xytype, int verb)
int difWide(unsigned int xytype, HDigiFP420Iter ichannel, HDigiFP420Iter jchannel)
tuple cout
Definition: gather_cfg.py:121