CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoRomanPot/RecoFP420/src/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 
00010 // sense of xytype here is X or Y type planes. Now we are working with X only, i.e. xytype=2
00011 
00012 bool ClusterProducerFP420::badChannel( int channel, 
00013                                        const std::vector<short>& badChannels) const
00014 {
00015   const std::vector<short>::size_type linearCutoff = 20;// number of possible bad channels
00016   // check: is it bad cnannel or not
00017     /*
00018   std::cout  
00019     << "badChannel:  badChannels.size()= " << badChannels.size() <<  " \t"
00020     << "badChannel:  hardcoded linearCutoff= " << linearCutoff  << " \t"
00021     << "badChannel:  channel= " << channel <<  " \t"
00022     << std::endl; 
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 //FIXME
00034 //In the future, with blobs, perhaps we will come back at this version
00035 // std::vector<ClusterFP420>
00036 // ClusterProducerFP420::clusterizeDetUnit( DigiIterator begin, DigiIterator end,
00037 //                                                 unsigned int detid,
00038 //                                                 const std::vector<float>& noiseVec,
00039 //                                                 const std::vector<short>& badChannels)
00040 // {
00041 
00042 //                                                                              digiRangeIteratorBegin,digiRangeIteratorEnd
00043 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnit( HDigiFP420Iter begin, HDigiFP420Iter end,
00044                                                                    unsigned int detid, const ElectrodNoiseVector& vnoise){
00045 //                                                 const std::vector<short>& badChannels)
00046 
00047   //reminder:     int zScale=2;  unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+xytype;
00048   // const int maxBadChannels_ = 1;
00049   HDigiFP420Iter ibeg, iend, ihigh, itest, i;  
00050   ibeg = iend = begin;
00051   std::vector<HDigiFP420> cluster_digis;  
00052   // reserve 15 possible channels for one cluster
00053   cluster_digis.reserve(15);
00054   // reserve one third of digiRange for number of clusters
00055   std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00056   //  predicate(declare): take noise above seed_thr
00057   AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00058   //Check if channel is lower than vnoise.size()
00059   itest = end - 1;
00060   int vnoisesize = vnoise.size();
00061   //  if (vnoise.size()<=itest->channel()) // old
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   //                                   loop in elements above seed_thr
00069   //                                find seed with seed noise above seed_thr
00070   while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00071     // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
00072     // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
00073     // to iend, and itest is the electrode under study, not yet accepted.
00074     
00075     // go to right side:
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     //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
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     // go to left side:
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     //if the next digi after ibeg is an adiacent bad digi then insert into candidate cluster
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       //just check for consecutive digis
00117       if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
00118         //digits: *(i-1) and *i   are not consecutive(we asked !=1-> it means 2...),so  create an equivalent number of Digis with zero amp
00119         for (int j=(i-1)->channel()+1;j<i->channel();++j){
00120           cluster_digis.push_back(HDigiFP420(j,0)); //if electrode bad or under threshold set HDigiFP420.adc_=0  
00121         }
00122       }
00123       //
00124 
00125 // FIXME: should the digi be tested for badChannel before using the adc?
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);// put into cluster_digis good i info
00131       } else {
00132         cluster_digis.push_back(HDigiFP420(i->channel(),0)); //if electrode bad or under threshold set HDigiFP420.adc_=0
00133       }
00134       //
00135     }//for i++
00136     float sigmaNoise = sqrt(sigmaNoise2);
00137     // define here cog,err,xytype not used
00138     float cog;
00139     float err;
00140     unsigned int xytype=2;// it can be even =1,although we are working with =2(Xtypes of planes)
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       //      std::cout << "Looking at cog and err  : cog " << cog << " err " << err  << std::endl;
00146     }
00147     ibeg = iend+1;
00148   } // while ( ibeg
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 //                                                                              digiRangeIteratorBegin,digiRangeIteratorEnd
00185 std::vector<ClusterFP420> ClusterProducerFP420::clusterizeDetUnitPixels( HDigiFP420Iter begin, HDigiFP420Iter end,
00186                                                                          unsigned int detid, const ElectrodNoiseVector& vnoise, unsigned int xytype, int verb){
00187 //                                                 const std::vector<short>& badChannels)
00188 
00189   //reminder:     int zScale=2;  unsigned int detID = sScale*(sector - 1)+zScale*(zmodule - 1)+xytype;
00190 
00191   // const int maxBadChannels_ = 1;
00192   
00193   HDigiFP420Iter ibeg, iend, ihigh, itest, i;  
00194   ibeg = iend = begin;
00195   std::vector<HDigiFP420> cluster_digis;  
00196   
00197   // reserve 25 possible channels for one cluster
00198   cluster_digis.reserve(25);
00199   
00200   // reserve one third of digiRange for number of clusters
00201   std::vector<ClusterFP420> rhits; rhits.reserve( (end - begin)/3 + 1);
00202   
00203   //  predicate(declare): take noise above seed_thr
00204   AboveSeed predicate(seedThresholdInNoiseSigma(),vnoise);
00205   
00206   //Check if no channels with digis at all
00207   /*
00208   HDigiFP420Iter abeg, aend;  
00209   abeg = begin; aend = end;
00210   std::vector<HDigiFP420> a_digis;  
00211   for ( ;abeg != aend; ++abeg ) {
00212     a_digis.push_back(*abeg);
00213   } // for
00214   if (a_digis.size()<1) return rhits;;
00215 */  
00216   //Check if channel is lower than vnoise.size()
00217   itest = end - 1;
00218   int vnoisesize = vnoise.size();
00219   if (vnoisesize<=itest->channel()) 
00220     {
00221 //      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;
00222       return rhits;
00223     }
00224   //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
00225   
00226   //  std::cout << "before while loop..." << std::endl;
00227   
00228   //                                   loop in elements above seed_thr
00229   //                                find seed with seed noise above seed_thr
00230   while ( ibeg != end && (ihigh = find_if( ibeg, end, predicate)) != end) {
00231     
00232     
00233     // The seed electrode is ihigh. Scan up and down from it, finding nearby(sosednie) electrodes above
00234     // threshold, allowing for some voids. The accepted cluster runs from electrode ibeg
00235     // to iend, and itest is the electrode under study, not yet accepted.
00236     
00237     // go to right side:
00238     iend = ihigh;
00239     itest = iend + 1;
00240     //    while ( itest != end && (itest->channel() - iend->channel() <= max_voids_ + 1 )) {
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     //if the next digi after iend is an adjacent bad(!) digi then insert into candidate cluster
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     // go to left side:
00266     ibeg = ihigh;
00267     itest = ibeg - 1;
00268     //  while ( itest >= begin && (ibeg->channel() - itest->channel() <= max_voids_ + 1 )) {
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     //if the next digi after ibeg is an adjacent bad digi then insert into candidate cluster
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     //    HDigiFP420Iter ilast=ibeg; // AZ
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       //just check for consecutive digis
00314       // if (i!=ibeg && i->channel()-(i-1)->channel()!=1){
00315       //if (i!=ibeg && difNarr(xytype,i,i-1) !=1 && difWide(xytype,i,i-1) !=1){
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       // in fact, no sense in this check, but still keep if something wrong is going:
00321       //      if (i!=ibeg && (difNarr(xytype,i,i-1) > 1 || difWide(xytype,i,i-1) > 1)   ){
00322       if (i!=ibeg && (difNarr(xytype,i,i-1) > 1 && difWide(xytype,i,i-1) > 1)   ){
00323         //digits: *(i-1) and *i   are not consecutive(we asked !=1-> it means 2...),so  create an equivalent number of Digis with zero amp
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)); //if not consecutive digis set HDigiFP420.adc_=0  
00329         }//for
00330       }//if
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);// put into cluster_digis good i info
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)); //if electrode bad or under threshold set HDigiFP420.adc_=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       }//if else
00346       
00347     }//for i++
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   } // while ( ibeg
00368   
00369   
00370   return rhits;
00371   
00372 }
00373 
00374 
00375