CMS 3D CMS Logo

ClusterProducerFP420.cc

Go to the documentation of this file.
00001 
00002 // File: ClusterProducerFP420.cc
00003 // Date: 12.2006
00004 // Description: ClusterProducerFP420 for FP420
00005 // Modifications: 
00007 #include "RecoRomanPot/RecoFP420/interface/ClusterProducerFP420.h"
00008 using namespace std;
00009 //#define mycldebug0
00010 //#define mycldebug1
00011 
00012 // sense of zside here is X or Y type planes. Now we are working with X only, i.e. zside=2
00013 
00014 bool ClusterProducerFP420::badChannel( int channel, 
00015                                        const std::vector<short>& badChannels) const
00016 {
00017   const std::vector<short>::size_type linearCutoff = 20;// number of possible bad channels
00018   // check: is it bad cnannel or not
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 //FIXME
00036 //In the future, with blobs, perhaps we will come back at this version
00037 // std::vector<ClusterFP420>
00038 // ClusterProducerFP420::clusterizeDetUnit( DigiIterator begin, DigiIterator end,
00039 //                                                 unsigned int detid,
00040 //                                                 const std::vector<float>& noiseVec,
00041 //                                                 const std::vector<short>& badChannels)
00042 // {
00043 
00044 //                                                                              digiRangeIteratorBegin,digiRangeIteratorEnd
00045 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnit( HDigiFP420Iter begin, HDigiFP420Iter end,
00046                                                                    unsigned int detid, const ElectrodNoiseVector& vnoise){
00047 //                                                 const std::vector<short>& badChannels)
00048 
00049   //reminder:     int zScale=2;  unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00050   // const int maxBadChannels_ = 1;
00051   HDigiFP420Iter ibeg, iend, ihigh, itest, i;  
00052   ibeg = iend = begin;
00053   std::vector<HDigiFP420> cluster_digis;  
00054   // reserve 15 possible channels for one cluster
00055   cluster_digis.reserve(15);
00056   // reserve one third of digiRange for number of clusters
00057   std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00058   //  predicate(declare): take noise above seed_thr
00059   AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00060   //Check if channel is lower than vnoise.size()
00061   itest = end - 1;
00062   int vnoisesize = vnoise.size();
00063   //  if (vnoise.size()<=itest->channel()) // old
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   //                                   loop in elements above seed_thr
00071   //                                find seed with seed noise above seed_thr
00072   while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00073     // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
00074     // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
00075     // to iend, and itest is the electrode under study, not yet accepted.
00076     
00077     // go to right side:
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     //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
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     // go to left side:
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     //if the next digi after ibeg is an adiacent bad digi then insert into candidate cluster
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       //just check for consecutive digis
00119       if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
00120         //digits: *(i-1) and *i   are not consecutive(we asked !=1-> it means 2...),so  create an equivalent number of Digis with zero amp
00121         for (int j=(i-1)->channel()+1;j<i->channel();++j){
00122           cluster_digis.push_back(HDigiFP420(j,0)); //if electrode bad or under threshold set HDigiFP420.adc_=0  
00123         }
00124       }
00125       //
00126 
00127 // FIXME: should the digi be tested for badChannel before using the adc?
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);// put into cluster_digis good i info
00133       } else {
00134         cluster_digis.push_back(HDigiFP420(i->channel(),0)); //if electrode bad or under threshold set HDigiFP420.adc_=0
00135       }
00136       //
00137     }//for i++
00138     float sigmaNoise = sqrt(sigmaNoise2);
00139     // define here cog,err,zside not used
00140     float cog;
00141     float err;
00142     unsigned int zside=2;// it can be even =1,although we are working with =2(Xtypes of planes)
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   } // while ( ibeg
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 //                                                                              digiRangeIteratorBegin,digiRangeIteratorEnd
00189 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnitPixels( HDigiFP420Iter begin, HDigiFP420Iter end,
00190                                                                          unsigned int detid, const ElectrodNoiseVector& vnoise, unsigned int zside){
00191 //                                                 const std::vector<short>& badChannels)
00192 
00193   //reminder:     int zScale=2;  unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
00194 
00195   // const int maxBadChannels_ = 1;
00196   
00197   HDigiFP420Iter ibeg, iend, ihigh, itest, i;  
00198   ibeg = iend = begin;
00199   std::vector<HDigiFP420> cluster_digis;  
00200   
00201   // reserve 25 possible channels for one cluster
00202   cluster_digis.reserve(25);
00203   
00204   // reserve one third of digiRange for number of clusters
00205   std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00206   
00207   //  predicate(declare): take noise above seed_thr
00208   AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00209   
00210   //Check if no channels with digis at all
00211   /*
00212   HDigiFP420Iter abeg, aend;  
00213   abeg = begin; aend = end;
00214   std::vector<HDigiFP420> a_digis;  
00215   for ( ;abeg != aend; ++abeg ) {
00216     a_digis.push_back(*abeg);
00217   } // for
00218   if (a_digis.size()<1) return rhits;;
00219 */  
00220   //Check if channel is lower than vnoise.size()
00221   itest = end - 1;
00222   int vnoisesize = vnoise.size();
00223   if (vnoisesize<=itest->channel()) 
00224     {
00225 //      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;
00226       return rhits;
00227     }
00228   //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00229   
00230   //  std::cout << "before while loop..." << std::endl;
00231   
00232   //                                   loop in elements above seed_thr
00233   //                                find seed with seed noise above seed_thr
00234   while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00235     
00236     
00237     // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
00238     // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
00239     // to iend, and itest is the electrode under study, not yet accepted.
00240     
00241     // go to right side:
00242     iend = ihigh;
00243     itest = iend + 1;
00244     //    while ( itest != end && (itest->channel() - iend->channel() <= max_voids_ + 1 )) {
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     //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
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     // go to left side:
00270     ibeg = ihigh;
00271     itest = ibeg - 1;
00272     //  while ( itest >= begin && (ibeg->channel() - itest->channel() <= max_voids_ + 1 )) {
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     //if the next digi after ibeg is an adjacent bad digi then insert into candidate cluster
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     //    HDigiFP420Iter ilast=ibeg; // AZ
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       //just check for consecutive digis
00318       // if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
00319       //if (i!=ibeg && difNarr(zside,i,i-1) !=1 && difWide(zside,i,i-1) !=1){
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       // in fact, no sense in this check, but still keep if something wrong is going:
00327       //      if (i!=ibeg && (difNarr(zside,i,i-1) > 1 || difWide(zside,i,i-1) > 1)   ){
00328       if (i!=ibeg && (difNarr(zside,i,i-1) > 1 && difWide(zside,i,i-1) > 1)   ){
00329         //digits: *(i-1) and *i   are not consecutive(we asked !=1-> it means 2...),so  create an equivalent number of Digis with zero amp
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)); //if not consecutive digis set HDigiFP420.adc_=0  
00335         }//for
00336       }//if
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);// put into cluster_digis good i info
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)); //if electrode bad or under threshold set HDigiFP420.adc_=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       }//if else
00353 
00354     }//for i++
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   } // while ( ibeg
00375   
00376   
00377   return rhits;
00378   
00379 }
00380 
00381 
00382 

Generated on Tue Jun 9 17:44:55 2009 for CMSSW by  doxygen 1.5.4