CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimRomanPot/SimFP420/src/ZeroSuppressFP420.cc

Go to the documentation of this file.
00001 
00002 // File: ZeroSuppressFP420.cc
00003 // Date: 12.2006
00004 // Description: ZeroSuppressFP420 for FP420
00005 // Modifications: 
00007 #include "SimRomanPot/SimFP420/interface/ZeroSuppressFP420.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 ZeroSuppressFP420::ZeroSuppressFP420(const edm::ParameterSet& conf, float noise) : conf_(conf), theNumFEDalgos(4)
00011 {
00012   noiseInAdc=noise;
00013   initParams(conf_);
00014   verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00015   //initParams();
00016   if(verbosity>0) {
00017     std::cout << "ZeroSuppressFP420: constructor: noiseInAdc=  " << noiseInAdc << std::endl;
00018   }
00019 }
00020 
00021 /*
00022  * The zero suppression algorithm, implemented in the trkFEDclusterizer method.
00023  * The class publically inherits from the ZSuppressFP420 class, which requires 
00024  * the use of a method named zeroSuppress.
00025  */
00026 
00027 void ZeroSuppressFP420::initParams(edm::ParameterSet const& conf_)
00028 {
00029   verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00030   algoConf      = conf_.getParameter<int>("FedFP420Algorithm"); //FedFP420Algorithm: =1  (,2,3,4)
00031   lowthreshConf      = conf_.getParameter<double>("FedFP420LowThreshold"); // FedFP420LowThreshold  =3.
00032   highthreshConf      = conf_.getParameter<double>("FedFP420HighThreshold"); // FedFP420HighThreshold  =4.
00033   
00034   /*
00035    * There are four possible algorithms, the default of which (4)
00036    * has different thresholds for isolated channels and ones in clusters.
00037    * It also merges clusters (single or multi channels) that are only separated
00038    * by one hole. This channel is selected as signal even though it is below
00039    * both thresholds.
00040    */
00041   
00042   theFEDalgorithm  = algoConf;
00043   theFEDlowThresh  = lowthreshConf * noiseInAdc;
00044   theFEDhighThresh = highthreshConf * noiseInAdc;
00045   
00046   if(verbosity>0) {
00047     std::cout << "ZeroSuppressFP420: initParams: !!!  theFEDalgorithm=  " << theFEDalgorithm << std::endl;
00048     std::cout << " lowthreshConf=  " << lowthreshConf << " highthreshConf=  " << highthreshConf << " theFEDlowThresh=  " << theFEDlowThresh << " theFEDhighThresh=  " << theFEDhighThresh << std::endl;
00049   }
00050   
00051   //Check zero suppress algorithm
00052   if (theFEDalgorithm < 1 || theFEDalgorithm > theNumFEDalgos) {
00053     edm::LogError("FP420DigiInfo")<<"ZeroSuppressFP420 FATAL ERROR: Unknown zero suppress algorithm "<<theFEDalgorithm;
00054     exit(1);
00055   }
00056   
00057   //Check thresholds
00058   if (theFEDlowThresh > theFEDhighThresh) {
00059     edm::LogError("FP420DigiInfo")<<"ZeroSuppressFP420 FATAL ERROR: Low threshold exceeds high threshold: "<<theFEDlowThresh<<" > "<<theFEDhighThresh;
00060     exit(2);
00061   }
00062 }
00063 
00064 ZSuppressFP420::DigitalMapType ZeroSuppressFP420::zeroSuppress(const DigitalMapType& notZeroSuppressedMap,int vrb)
00065 {
00066   return trkFEDclusterizer(notZeroSuppressedMap, vrb); 
00067   if(vrb>0) {
00068     std::cout << "zeroSuppress: return trkFEDclusterizer(notZeroSuppressedMap)" << std::endl;
00069   }
00070 }
00071 
00072 //This performs the zero suppression
00073 ZSuppressFP420::DigitalMapType ZeroSuppressFP420::trkFEDclusterizer(const DigitalMapType &in, int vrb) 
00074 {
00075   const std::string s2("ZeroSuppressFP420::trkFEDclusterizer1");
00076   
00077   DigitalMapType selectedSignal;
00078   register DigitalMapType::const_iterator i, iPrev, iNext, iPrev2, iNext2;
00079   
00080   if(vrb>0) {
00081     std::cout << "Before For loop" << std::endl;
00082   }
00083   
00084   for (i = in.begin(); i != in.end(); i++) {
00085     
00086     //Find adc values for neighbouring strips
00087     int strip = i->first;
00088     int adc   = i->second;
00089     iPrev  = in.find(strip - 1);
00090     iNext  = in.find(strip + 1);
00091     if(vrb>0) {
00092       std::cout << "Inside For loop trkFEDclusterizer: strip= " << strip << " adc= " << adc << std::endl;
00093     }
00094     //Set values for channels just outside module to infinity.
00095     //This is to avoid losing channels at the edges, 
00096     //which otherwise would pass cuts if strips were next to each other.
00097     int adcPrev = -99999;
00098     int adcNext = -99999;
00099     if ( ((strip)%128) == 127) adcNext = 99999;
00100     if ( ((strip)%128) == 0)   adcPrev = 99999;
00101     //Otherwise if channel was found then find it's ADC count.
00102     if ( iPrev  != in.end() ) adcPrev  = iPrev->second;
00103     if ( iNext  != in.end() ) adcNext  = iNext->second;
00104     int adcMaxNeigh = std::max(adcPrev, adcNext);
00105     if(vrb>0) {
00106       std::cout << "adcPrev= " << adcPrev << " adcNext= " << adcNext << " adcMaxNeigh= " << adcMaxNeigh << std::endl;
00107     }
00108     
00109     //Find adc values for next neighbouring channes
00110     iPrev2 = in.find(strip - 2); 
00111     iNext2 = in.find(strip + 2);
00112     //See above 
00113     int adcPrev2 = -99999;
00114     int adcNext2 = -99999;
00115     if ( ((strip)%128) == 126) adcNext2 = 99999;
00116     if ( ((strip)%128) == 1)   adcPrev2 = 99999; 
00117     if ( iPrev2 != in.end() ) adcPrev2 = iPrev2->second; 
00118     if ( iNext2 != in.end() ) adcNext2 = iNext2->second; 
00119     
00120     if(vrb>0) {
00121       std::cout << "adcPrev2= " << adcPrev2 << " adcNext2= " << adcNext2 << std::endl;
00122       std::cout << "To be accepted or not?  adc= " << adc << " >= theFEDlowThresh=" << theFEDlowThresh << std::endl;
00123     }
00124     // Decide if this channel should be accepted.
00125     bool accept = false;
00126     switch (theFEDalgorithm) {
00127       
00128     case 1: 
00129       accept = (adc >= theFEDlowThresh);
00130       break;
00131       
00132     case 2:
00133       accept = (adc >= theFEDhighThresh || (adc >= theFEDlowThresh && 
00134                                             adcMaxNeigh >= theFEDlowThresh));
00135       break;
00136       
00137     case 3:
00138       accept = (adc >= theFEDhighThresh || (adc >= theFEDlowThresh && 
00139                                             adcMaxNeigh >= theFEDhighThresh));
00140       break;
00141       
00142     case 4:
00143       accept = ((adc >= theFEDhighThresh) ||           //Test for adc>highThresh (same as algorithm 2)
00144                 ((adc >= theFEDlowThresh) &&           //Test for adc>lowThresh, with neighbour adc>lowThresh (same as algorithm 2)
00145                  (adcMaxNeigh >= theFEDlowThresh)) || 
00146                 ((adc < theFEDlowThresh) &&            //Test for adc<lowThresh
00147                  (((adcPrev  >= theFEDhighThresh) &&   //with both neighbours>highThresh
00148                    (adcNext  >= theFEDhighThresh)) ||    
00149                   ((adcPrev  >= theFEDhighThresh) &&   //OR with previous neighbour>highThresh and
00150                    (adcNext  >= theFEDlowThresh)  &&   //both the next neighbours>lowThresh
00151                    (adcNext2 >= theFEDlowThresh))  ||    
00152                   ((adcNext  >= theFEDhighThresh) &&   //OR with next neighbour>highThresh and
00153                    (adcPrev  >= theFEDlowThresh)  &&   //both the previous neighbours>lowThresh
00154                    (adcPrev2 >= theFEDlowThresh))  ||
00155                   ((adcNext  >= theFEDlowThresh)  &&   //OR with both next neighbours>lowThresh and
00156                    (adcNext2 >= theFEDlowThresh)  &&   //both the previous neighbours>lowThresh
00157                    (adcPrev  >= theFEDlowThresh)  && 
00158                    (adcPrev2 >= theFEDlowThresh)))));
00159       break;
00160     }
00161     
00162     /*
00163      * When a channel satisfying only the lower threshold is at the edge of an APV or module, 
00164      * the trkFEDclusterizer method assumes that every channel just outside an APV or module has a hit on it.
00165      * This is to avoid channel inefficiencies at the edges of APVs and modules.   
00166      */
00167     if (accept) {   
00168       selectedSignal[strip] = adc;
00169       
00170       if(vrb>0) {
00171         std::cout << "selected strips = " << strip << " adc= " << adc << std::endl;
00172       }
00173     }  
00174   }
00175   
00176   if(vrb>0) {
00177     std::cout << "last line of trkFEDclusterizer: return selectedSignal" << std::endl;
00178   }
00179   return selectedSignal;
00180 }
00181