00001
00002
00003
00004
00005
00007 #include "RecoRomanPot/RecoFP420/interface/ClusterProducerFP420.h"
00008 using namespace std;
00009
00010
00011
00012
00013
00014 bool ClusterProducerFP420::badChannel( int channel,
00015 const std::vector<short>& badChannels) const
00016 {
00017 const std::vector<short>::size_type linearCutoff = 20;
00018
00019 #ifdef mycldebug0
00020 std::cout
00021 << "badChannel: badChannels.size()= " << badChannels.size() << " \t"
00022 << "badChannel: hardcoded linearCutoff= " << linearCutoff << " \t"
00023 << "badChannel: channel= " << channel << " \t"
00024 << std::endl;
00025 #endif
00026 if (badChannels.size() < linearCutoff) {
00027 return (std::find( badChannels.begin(), badChannels.end(), channel) != badChannels.end());
00028 }
00029 else return std::binary_search( badChannels.begin(), badChannels.end(), channel);
00030
00031
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnit( HDigiFP420Iter begin, HDigiFP420Iter end,
00046 unsigned int detid, const ElectrodNoiseVector& vnoise){
00047
00048
00049
00050
00051 HDigiFP420Iter ibeg, iend, ihigh, itest, i;
00052 ibeg = iend = begin;
00053 std::vector<HDigiFP420> cluster_digis;
00054
00055 cluster_digis.reserve(15);
00056
00057 std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00058
00059 AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00060
00061 itest = end - 1;
00062 int vnoisesize = vnoise.size();
00063
00064 if (vnoisesize<=itest->channel())
00065 {
00066 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;
00067 return rhits;
00068 }
00069
00070
00071
00072 while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00073
00074
00075
00076
00077
00078 iend = ihigh;
00079 itest = iend + 1;
00080 while ( itest != end && (itest->channel() - iend->channel() <= max_voids_ + 1 )) {
00081 float channelNoise = vnoise[itest->channel()].getNoise();
00082 bool IsBadChannel = vnoise[itest->channel()].getDisable();
00083 if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
00084 iend = itest;
00085 }
00086 ++itest;
00087 }
00088
00089 itest=iend+1;
00090 if ( itest != end && (itest->channel() - iend->channel() == 1) && vnoise[itest->channel()].getDisable() ) {
00091 std::cout << "Inserted bad electrode at the end edge iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
00092 iend++;
00093 }
00094
00095 ibeg = ihigh;
00096 itest = ibeg - 1;
00097 while ( itest >= begin && (ibeg->channel() - itest->channel() <= max_voids_ + 1 )) {
00098 float channelNoise = vnoise[itest->channel()].getNoise();
00099 bool IsBadChannel = vnoise[itest->channel()].getDisable();
00100 if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
00101 ibeg = itest;
00102 }
00103 --itest;
00104 }
00105
00106 itest=ibeg-1;
00107 if ( itest >= begin && (ibeg->channel() - itest->channel() == 1) && vnoise[itest->channel()].getDisable() ) {
00108 std::cout << "Inserted bad electrode at the begin edge ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
00109 ibeg--;
00110 }
00111
00112 int charge = 0;
00113 float sigmaNoise2=0;
00114 cluster_digis.clear();
00115 for (i=ibeg; i<=iend; ++i) {
00116 float channelNoise = vnoise[i->channel()].getNoise();
00117 bool IsBadChannel = vnoise[i->channel()].getDisable();
00118
00119 if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
00120
00121 for (int j=(i-1)->channel()+1;j<i->channel();++j){
00122 cluster_digis.push_back(HDigiFP420(j,0));
00123 }
00124 }
00125
00126
00127
00128
00129 if (!IsBadChannel && i->adc() >= static_cast<int>( channelThresholdInNoiseSigma()*channelNoise)) {
00130 charge += i->adc();
00131 sigmaNoise2 += channelNoise*channelNoise;
00132 cluster_digis.push_back(*i);
00133 } else {
00134 cluster_digis.push_back(HDigiFP420(i->channel(),0));
00135 }
00136
00137 }
00138 float sigmaNoise = sqrt(sigmaNoise2);
00139
00140 float cog;
00141 float err;
00142 unsigned int zside=2;
00143 if (charge >= static_cast<int>( clusterThresholdInNoiseSigma()*sigmaNoise)) {
00144 rhits.push_back( ClusterFP420( detid, zside, ClusterFP420::HDigiFP420Range( cluster_digis.begin(),
00145 cluster_digis.end()),
00146 cog, err));
00147 #ifdef mycldebug0
00148 std::cout << "Looking at cog and err : cog " << cog << " err " << err << std::endl;
00149 #endif
00150 }
00151 ibeg = iend+1;
00152 }
00153 return rhits;
00154 }
00155
00156 int ClusterProducerFP420::difNarr(unsigned int zside, HDigiFP420Iter ichannel,
00157 HDigiFP420Iter jchannel) {
00158 int d = 9999;
00159 if(zside == 2) {
00160 d = ichannel->stripV() - jchannel->stripV();
00161 d=abs(d);
00162 }
00163 else if(zside == 1) {
00164 d = ichannel->stripH() - jchannel->stripH();
00165 d=abs(d);
00166 }
00167 else{
00168 std::cout << "difNarr: wrong zside = " << zside << std::endl;
00169 }
00170 return d;
00171 }
00172 int ClusterProducerFP420::difWide(unsigned int zside, HDigiFP420Iter ichannel,
00173 HDigiFP420Iter jchannel) {
00174 int d = 9999;
00175 if(zside == 2) {
00176 d = ichannel->stripVW() - jchannel->stripVW();
00177 d=abs(d);
00178 }
00179 else if(zside == 1) {
00180 d = ichannel->stripHW() - jchannel->stripHW();
00181 d=abs(d);
00182 }
00183 else{
00184 std::cout << "difWide: wrong zside = " << zside << std::endl;
00185 }
00186 return d;
00187 }
00188
00189 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnitPixels( HDigiFP420Iter begin, HDigiFP420Iter end,
00190 unsigned int detid, const ElectrodNoiseVector& vnoise, unsigned int zside){
00191
00192
00193
00194
00195
00196
00197 HDigiFP420Iter ibeg, iend, ihigh, itest, i;
00198 ibeg = iend = begin;
00199 std::vector<HDigiFP420> cluster_digis;
00200
00201
00202 cluster_digis.reserve(25);
00203
00204
00205 std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00206
00207
00208 AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 itest = end - 1;
00222 int vnoisesize = vnoise.size();
00223 if (vnoisesize<=itest->channel())
00224 {
00225
00226 return rhits;
00227 }
00228
00229
00230
00231
00232
00233
00234 while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00235
00236
00237
00238
00239
00240
00241
00242 iend = ihigh;
00243 itest = iend + 1;
00244
00245 while ( itest != end && (difNarr(zside,itest,iend)<= max_voids_ + 1 ) && (difWide(zside,itest,iend)<= 1) ) {
00246 float channelNoise = vnoise[itest->channel()].getNoise();
00247 bool IsBadChannel = vnoise[itest->channel()].getDisable();
00248 if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
00249 iend = itest;
00250 #ifdef mycldebug1
00251 std::cout << "=========================================================================== " << std::endl;
00252 std::cout << "Right side: itest->adc()= " << itest->adc() << " channel_noise = " << static_cast<int>( channelThresholdInNoiseSigma() * channelNoise) << std::endl;
00253 #endif
00254 }
00255 ++itest;
00256 }
00257
00258 itest=iend+1;
00259 if ( itest != end && (difNarr(zside,itest,iend) == 1) && (difWide(zside,itest,iend)< 1) && vnoise[itest->channel()].getDisable() ) {
00260 #ifdef mycldebug1
00261 std::cout << "Inserted bad electrode at the end edge iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
00262 #endif
00263 iend++;
00264 }
00265 #ifdef mycldebug1
00266 std::cout << "Result of going to right side iend->channel()= " << iend->channel() << " itest->channel() = " << itest->channel() << std::endl;
00267 #endif
00268
00269
00270 ibeg = ihigh;
00271 itest = ibeg - 1;
00272
00273 while ( itest >= begin && (difNarr(zside,ibeg,itest) <= max_voids_ + 1 ) && (difWide(zside,ibeg,itest) <= 1) ) {
00274 float channelNoise = vnoise[itest->channel()].getNoise();
00275 bool IsBadChannel = vnoise[itest->channel()].getDisable();
00276 if (!IsBadChannel && itest->adc() >= static_cast<int>( channelThresholdInNoiseSigma() * channelNoise)) {
00277 ibeg = itest;
00278 #ifdef mycldebug1
00279 std::cout << "Left side: itest->adc()= " << itest->adc() << " channel_noise = " << static_cast<int>( channelThresholdInNoiseSigma() * channelNoise) << std::endl;
00280 #endif
00281 }
00282 --itest;
00283 }
00284
00285 itest=ibeg-1;
00286 if ( itest >= begin && (difNarr(zside,ibeg,itest) == 1) && (difWide(zside,ibeg,itest) < 1) && vnoise[itest->channel()].getDisable() ) {
00287 #ifdef mycldebug1
00288 std::cout << "Inserted bad electrode at the begin edge ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
00289 #endif
00290 ibeg--;
00291 }
00292 #ifdef mycldebug1
00293 std::cout << "Result of going to left side ibeg->channel()= " << ibeg->channel() << " itest->channel() = " << itest->channel() << std::endl;
00294 #endif
00295
00296
00297
00298
00299
00300
00301
00302 int charge = 0;
00303 float sigmaNoise2=0;
00304 cluster_digis.clear();
00305
00306 #ifdef mycldebug1
00307 std::cout << "check for consecutive digis ibeg->channel()= " << ibeg->channel() << " iend->channel() = " << iend->channel() << std::endl;
00308 #endif
00309 for (i=ibeg; i<=iend; ++i) {
00310 float channelNoise = vnoise[i->channel()].getNoise();
00311 bool IsBadChannel = vnoise[i->channel()].getDisable();
00312 #ifdef mycldebug1
00313 std::cout << "Looking at cluster digis: detid " << detid << " digis " << i->channel()
00314 << " adc " << i->adc() << " channelNoise " << channelNoise << " IsBadChannel " << IsBadChannel << std::endl;
00315 #endif
00316
00317
00318
00319
00320
00321 #ifdef mycldebug1
00322 std::cout << "difNarr(zside,i,i-1) = " << difNarr(zside,i,i-1) << std::endl;
00323 std::cout << "difWide(zside,i,i-1) = " << difWide(zside,i,i-1) << std::endl;
00324 #endif
00325
00326
00327
00328 if (i!=ibeg && (difNarr(zside,i,i-1) > 1 && difWide(zside,i,i-1) > 1) ){
00329
00330 for (int j=(i-1)->channel()+1;j<i->channel();++j){
00331 #ifdef mycldebug1
00332 std::cout << "not consecutive digis: set HDigiFP420.adc_=0 : j = " << j << std::endl;
00333 #endif
00334 cluster_digis.push_back(HDigiFP420(j,0));
00335 }
00336 }
00337
00338
00339
00340 if (!IsBadChannel && i->adc() >= static_cast<int>( channelThresholdInNoiseSigma()*channelNoise)) {
00341 charge += i->adc();
00342 sigmaNoise2 += channelNoise*channelNoise;
00343 cluster_digis.push_back(*i);
00344 #ifdef mycldebug1
00345 std::cout << "put into cluster_digis good i info: i->channel() = " << i->channel() << std::endl;
00346 #endif
00347 } else {
00348 cluster_digis.push_back(HDigiFP420(i->channel(),0));
00349 #ifdef mycldebug1
00350 std::cout << "else if electrode bad or under threshold set HDigiFP420.adc_=0: i->channel() = " << i->channel() << std::endl;
00351 #endif
00352 }
00353
00354 }
00355
00356
00357
00358
00359 float sigmaNoise = sqrt(sigmaNoise2);
00360 float cog;
00361 float err;
00362 if (charge >= static_cast<int>( clusterThresholdInNoiseSigma()*sigmaNoise)) {
00363 rhits.push_back( ClusterFP420( detid, zside, ClusterFP420::HDigiFP420Range( cluster_digis.begin(),
00364 cluster_digis.end()),
00365 cog, err));
00366 #ifdef mycldebug1
00367 std::cout << "Looking at cog and err : cog " << cog << " err " << err << std::endl;
00368 std::cout << "=========================================================================== " << std::endl;
00369 #endif
00370 }
00371
00372
00373 ibeg = iend+1;
00374 }
00375
00376
00377 return rhits;
00378
00379 }
00380
00381
00382