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