CMS 3D CMS Logo

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