CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondFormats/SiStripObjects/src/NoiseAnalysis.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiStripObjects/interface/NoiseAnalysis.h"
00002 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <cmath>
00008 
00009 using namespace sistrip;
00010 
00011 // ----------------------------------------------------------------------------
00012 // 
00013 NoiseAnalysis::NoiseAnalysis( const uint32_t& key ) 
00014   : CommissioningAnalysis(key,"NoiseAnalysis"),
00015     peds_(2,VFloat(128,sistrip::invalid_)), 
00016     noise_(2,VFloat(128,sistrip::invalid_)), 
00017     raw_(2,VFloat(128,sistrip::invalid_)), 
00018     dead_(2,VInt(0,sistrip::invalid_)), 
00019     noisy_(2,VInt(0,sistrip::invalid_)),
00020     pedsMean_(2,sistrip::invalid_), 
00021     pedsSpread_(2,sistrip::invalid_), 
00022     noiseMean_(2,sistrip::invalid_), 
00023     noiseSpread_(2,sistrip::invalid_), 
00024     rawMean_(2,sistrip::invalid_), 
00025     rawSpread_(2,sistrip::invalid_), 
00026     pedsMax_(2,sistrip::invalid_), 
00027     pedsMin_(2,sistrip::invalid_), 
00028     noiseMax_(2,sistrip::invalid_), 
00029     noiseMin_(2,sistrip::invalid_),
00030     rawMax_(2,sistrip::invalid_), 
00031     rawMin_(2,sistrip::invalid_),
00032     legacy_(false)
00033 {
00034   dead_[0].reserve(256); dead_[1].reserve(256); 
00035   noisy_[0].reserve(256); noisy_[1].reserve(256);
00036 }
00037 
00038 // ----------------------------------------------------------------------------
00039 // 
00040 NoiseAnalysis::NoiseAnalysis() 
00041   : CommissioningAnalysis("NoiseAnalysis"),
00042     peds_(2,VFloat(128,sistrip::invalid_)), 
00043     noise_(2,VFloat(128,sistrip::invalid_)), 
00044     raw_(2,VFloat(128,sistrip::invalid_)), 
00045     dead_(2,VInt(0,sistrip::invalid_)), 
00046     noisy_(2,VInt(0,sistrip::invalid_)),
00047     pedsMean_(2,sistrip::invalid_), 
00048     pedsSpread_(2,sistrip::invalid_), 
00049     noiseMean_(2,sistrip::invalid_), 
00050     noiseSpread_(2,sistrip::invalid_), 
00051     rawMean_(2,sistrip::invalid_), 
00052     rawSpread_(2,sistrip::invalid_), 
00053     pedsMax_(2,sistrip::invalid_), 
00054     pedsMin_(2,sistrip::invalid_), 
00055     noiseMax_(2,sistrip::invalid_), 
00056     noiseMin_(2,sistrip::invalid_),
00057     rawMax_(2,sistrip::invalid_), 
00058     rawMin_(2,sistrip::invalid_),
00059     legacy_(false)
00060 {
00061   dead_[0].reserve(256); dead_[1].reserve(256); 
00062   noisy_[0].reserve(256); noisy_[1].reserve(256);
00063 }
00064 
00065 // ----------------------------------------------------------------------------
00066 // 
00067 void NoiseAnalysis::reset() {
00068   peds_        = VVFloat(2,VFloat(128,sistrip::invalid_)); 
00069   noise_       = VVFloat(2,VFloat(128,sistrip::invalid_)); 
00070   raw_         = VVFloat(2,VFloat(128,sistrip::invalid_));
00071   dead_        = VVInt(2,VInt(0,sistrip::invalid_)); 
00072   noisy_       = VVInt(2,VInt(0,sistrip::invalid_));
00073   pedsMean_    = VFloat(2,sistrip::invalid_); 
00074   pedsSpread_  = VFloat(2,sistrip::invalid_); 
00075   noiseMean_   = VFloat(2,sistrip::invalid_); 
00076   noiseSpread_ = VFloat(2,sistrip::invalid_); 
00077   rawMean_     = VFloat(2,sistrip::invalid_);
00078   rawSpread_   = VFloat(2,sistrip::invalid_);
00079   pedsMax_     = VFloat(2,sistrip::invalid_); 
00080   pedsMin_     = VFloat(2,sistrip::invalid_); 
00081   noiseMax_    = VFloat(2,sistrip::invalid_); 
00082   noiseMin_    = VFloat(2,sistrip::invalid_);
00083   rawMax_      = VFloat(2,sistrip::invalid_);
00084   rawMin_      = VFloat(2,sistrip::invalid_);
00085   dead_[0].reserve(256); 
00086   dead_[1].reserve(256); 
00087   noisy_[0].reserve(256); 
00088   noisy_[1].reserve(256);
00089   legacy_ = false;
00090 }
00091 
00092 // ----------------------------------------------------------------------------
00093 // 
00094 bool NoiseAnalysis::isValid() const {
00095   return ( pedsMean_[0] < sistrip::maximum_ &&
00096            pedsMean_[1] < sistrip::maximum_ &&
00097            pedsSpread_[0] < sistrip::maximum_ &&
00098            pedsSpread_[1] < sistrip::maximum_ &&
00099            noiseMean_[0] < sistrip::maximum_ &&
00100            noiseMean_[1] < sistrip::maximum_ &&
00101            noiseSpread_[0] < sistrip::maximum_ &&
00102            noiseSpread_[1] < sistrip::maximum_ &&
00103            rawMean_[0] < sistrip::maximum_ &&
00104            rawMean_[1] < sistrip::maximum_ &&
00105            rawSpread_[0] < sistrip::maximum_ &&
00106            rawSpread_[1] < sistrip::maximum_ &&
00107            pedsMax_[0] < sistrip::maximum_ &&
00108            pedsMax_[1] < sistrip::maximum_ &&
00109            pedsMin_[0] < sistrip::maximum_ &&
00110            pedsMin_[1] < sistrip::maximum_ &&
00111            noiseMax_[0] < sistrip::maximum_ &&
00112            noiseMax_[1] < sistrip::maximum_ &&
00113            noiseMin_[0] < sistrip::maximum_ &&
00114            noiseMin_[1] < sistrip::maximum_ &&
00115            rawMax_[0] < sistrip::maximum_ &&
00116            rawMax_[1] < sistrip::maximum_ &&
00117            rawMin_[0] < sistrip::maximum_ &&
00118            rawMin_[1] < sistrip::maximum_ &&
00119            getErrorCodes().empty() );
00120   //noiseMean_[0] <= rawMean_[0] && //@@ temp
00121   //noiseMean_[1] <= rawMean_[1] ); //@@ temp
00122 } 
00123 
00124 // ----------------------------------------------------------------------------
00125 // 
00126 void NoiseAnalysis::summary( std::stringstream& ss ) const { 
00127 
00128   SiStripFecKey fec_key( fecKey() );
00129   SiStripFedKey fed_key( fedKey() );
00130   
00131   sistrip::RunType type = SiStripEnumsAndStrings::runType( myName() );
00132   
00133   std::stringstream extra1,extra2,extra3;
00134   if ( legacy_ ) {
00135     extra1 << sistrip::extrainfo::pedsAndRawNoise_; 
00136     extra2 << sistrip::extrainfo::pedsAndCmSubNoise_; 
00137     extra3 << sistrip::extrainfo::commonMode_;
00138   } else {
00139     extra1 << sistrip::extrainfo::pedestals_; 
00140     extra2 << sistrip::extrainfo::rawNoise_; 
00141     extra3 << sistrip::extrainfo::commonMode_;
00142   }
00143   
00144   std::string title1 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00145                                           type,
00146                                           sistrip::FED_KEY, 
00147                                           fed_key.key(),
00148                                           sistrip::LLD_CHAN, 
00149                                           fec_key.lldChan(),
00150                                           extra1.str() ).title();
00151   std::string title2 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00152                                           type,
00153                                           sistrip::FED_KEY, 
00154                                           fed_key.key(),
00155                                           sistrip::LLD_CHAN, 
00156                                           fec_key.lldChan(),
00157                                           extra2.str() ).title();
00158   std::string title3 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00159                                           type,
00160                                           sistrip::FED_KEY, 
00161                                           fed_key.key(),
00162                                           sistrip::APV, 
00163                                           SiStripFecKey::i2cAddr( fec_key.lldChan(), true ),
00164                                           extra3.str() ).title();
00165   std::string title4 = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00166                                           type,
00167                                           sistrip::FED_KEY, 
00168                                           fed_key.key(),
00169                                           sistrip::APV, 
00170                                           SiStripFecKey::i2cAddr( fec_key.lldChan(), false ),
00171                                           extra3.str() ).title();
00172   
00173   
00174   ss << " Summary"
00175      << ":"
00176      << ( isValid() ? "Valid" : "Invalid" )
00177      << ":"
00178      << sistrip::controlView_ << ":"
00179      << fec_key.fecCrate() << "/" 
00180      << fec_key.fecSlot() << "/" 
00181      << fec_key.fecRing() << "/" 
00182      << fec_key.ccuAddr() << "/" 
00183      << fec_key.ccuChan() 
00184      << ":"
00185      << sistrip::dqmRoot_ << sistrip::dir_ 
00186      << "Collate" << sistrip::dir_ 
00187      << SiStripFecKey( fec_key.fecCrate(),
00188                        fec_key.fecSlot(), 
00189                        fec_key.fecRing(), 
00190                        fec_key.ccuAddr(), 
00191                        fec_key.ccuChan() ).path()
00192      << ":"
00193      << title1 << ";" << title2 << ";" << title3 << ";" << title4
00194      << std::endl;
00195   
00196 }
00197 
00198 // ----------------------------------------------------------------------------
00199 // 
00200 void NoiseAnalysis::print( std::stringstream& ss, uint32_t iapv ) { 
00201 
00202   if ( iapv == 1 || iapv == 2 ) { iapv--; }
00203   else { iapv = 0; }
00204   
00205   if ( peds_[iapv].size() < 128 ||
00206        noise_[iapv].size() < 128 ||
00207        raw_[iapv].size() < 128 ) { 
00208     edm::LogWarning(mlCommissioning_)
00209       << "[" << myName() << "::" << __func__ << "]"
00210       << " Unexpected number of pedestal/noise values: " 
00211       << peds_[iapv].size() << ", " 
00212       << noise_[iapv].size() << ", " 
00213       << raw_[iapv].size();
00214     return;
00215   }
00216   
00217   header( ss );
00218   ss << " Monitorables for APV number     : " << iapv;
00219   if ( iapv == 0 ) { ss << " (first of pair)"; }
00220   else if ( iapv == 1 ) { ss << " (second of pair)"; } 
00221   ss << std::endl;
00222   ss << std::fixed << std::setprecision(2);
00223   ss << " Example peds/noise for strips   : "
00224      << "     0,     31,     63,    127" << std::endl
00225      << "  Peds                     [ADC] : " 
00226      << std::setw(6) << peds_[iapv][0] << ", " 
00227      << std::setw(6) << peds_[iapv][31] << ", " 
00228      << std::setw(6) << peds_[iapv][63] << ", " 
00229      << std::setw(6) << peds_[iapv][127] << std::endl
00230      << "  Noise                    [ADC] : " 
00231      << std::setw(6) << noise_[iapv][0] << ", " 
00232      << std::setw(6) << noise_[iapv][31] << ", " 
00233      << std::setw(6) << noise_[iapv][63] << ", " 
00234      << std::setw(6) << noise_[iapv][127] << std::endl
00235      << "  Raw noise                [ADC] : " 
00236      << std::setw(6) << raw_[iapv][0] << ", " 
00237      << std::setw(6) << raw_[iapv][31] << ", " 
00238      << std::setw(6) << raw_[iapv][63] << ", " 
00239      << std::setw(6) << raw_[iapv][127] << std::endl
00240      << " Dead strips (<5s)       [strip] : (" << dead_[iapv].size() << " in total) ";
00241   for ( uint16_t ii = 0; ii < dead_[iapv].size(); ii++ ) { 
00242     ss << dead_[iapv][ii] << " "; }
00243   
00244   ss << std::endl;
00245   ss << " Noisy strips (>5s)      [strip] : (" << noisy_[iapv].size() << " in total) ";
00246   for ( uint16_t ii = 0; ii < noisy_[iapv].size(); ii++ ) { 
00247     ss << noisy_[iapv][ii] << " "; 
00248   } 
00249   ss << std::endl;
00250   ss << " Mean peds +/- spread      [ADC] : " << pedsMean_[iapv] << " +/- " << pedsSpread_[iapv] << std::endl 
00251      << " Min/Max pedestal          [ADC] : " << pedsMin_[iapv] << " <-> " << pedsMax_[iapv] << std::endl
00252      << " Mean noise +/- spread     [ADC] : " << noiseMean_[iapv] << " +/- " << noiseSpread_[iapv] << std::endl 
00253      << " Min/Max noise             [ADC] : " << noiseMin_[iapv] << " <-> " << noiseMax_[iapv] << std::endl
00254      << " Mean raw noise +/- spread [ADC] : " << rawMean_[iapv] << " +/- " << rawSpread_[iapv] << std::endl 
00255      << " Min/Max raw noise         [ADC] : " << rawMin_[iapv] << " <-> " << rawMax_[iapv] << std::endl
00256      << " Normalised noise                : " << "(yet to be implemented...)" << std::endl
00257      << std::boolalpha 
00258      << " isValid                         : " << isValid()  << std::endl
00259      << std::noboolalpha
00260      << " Error codes (found "
00261      << std::setw(2) << std::setfill(' ') << getErrorCodes().size() 
00262      << ")          : ";
00263   if ( getErrorCodes().empty() ) { ss << "(none)"; }
00264   else { 
00265     VString::const_iterator istr = getErrorCodes().begin();
00266     VString::const_iterator jstr = getErrorCodes().end();
00267     for ( ; istr != jstr; ++istr ) { ss << *istr << " "; }
00268   }
00269   ss << std::endl;
00270 }
00271