CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQM/SiStripCommissioningSources/src/PedestalsTask.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSources/interface/PedestalsTask.h"
00002 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00004 #include "DQMServices/Core/interface/DQMStore.h"
00005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00006 #include "DQM/SiStripCommon/interface/UpdateTProfile.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <algorithm>
00009 #include <math.h>
00010 
00011 using namespace sistrip;
00012 
00013 // -----------------------------------------------------------------------------
00014 //
00015 PedestalsTask::PedestalsTask( DQMStore* dqm,
00016                                     const FedChannelConnection& conn ) :
00017   CommissioningTask( dqm, conn, "PedestalsTask" ),
00018   peds_(),
00019   cm_()
00020 {
00021   LogTrace(mlDqmSource_)
00022     << "[PedestalsTask::" << __func__ << "]"
00023     << " Constructing object...";
00024 }
00025 
00026 // -----------------------------------------------------------------------------
00027 //
00028 PedestalsTask::~PedestalsTask() {
00029   LogTrace(mlDqmSource_)
00030     << "[PedestalsTask::" << __func__ << "]"
00031     << " Destructing object...";
00032 }
00033 
00034 // -----------------------------------------------------------------------------
00035 //
00036 void PedestalsTask::book() {
00037   LogTrace(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]";
00038   
00039   uint16_t nbins;
00040   std::string title;
00041   std::string extra_info;
00042   peds_.resize(2);
00043   nbins = 256;
00044   
00045   // Pedestals histogram
00046   extra_info = sistrip::extrainfo::pedestals_; 
00047   peds_[0].isProfile_ = true;
00048   
00049   title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00050                              sistrip::PEDESTALS, 
00051                              sistrip::FED_KEY, 
00052                              fedKey(),
00053                              sistrip::LLD_CHAN, 
00054                              connection().lldChannel(),
00055                              extra_info ).title();
00056   
00057   peds_[0].histo( dqm()->bookProfile( title, title, 
00058                                       nbins, -0.5, nbins*1.-0.5,
00059                                       1025, 0., 1025. ) );
00060   
00061   peds_[0].vNumOfEntries_.resize(nbins,0);
00062   peds_[0].vSumOfContents_.resize(nbins,0);
00063   peds_[0].vSumOfSquares_.resize(nbins,0);
00064 
00065   // Noise histogram
00066   extra_info = sistrip::extrainfo::noise_; 
00067   peds_[1].isProfile_ = true;
00068   
00069   title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00070                              sistrip::PEDESTALS, 
00071                              sistrip::FED_KEY, 
00072                              fedKey(),
00073                              sistrip::LLD_CHAN, 
00074                              connection().lldChannel(),
00075                              extra_info ).title();
00076   
00077   peds_[1].histo( dqm()->bookProfile( title, title, 
00078                                       nbins, -0.5, nbins*1.-0.5,
00079                                       1025, 0., 1025. ) );
00080   
00081   peds_[1].vNumOfEntries_.resize(nbins,0);
00082   peds_[1].vSumOfContents_.resize(nbins,0);
00083   peds_[1].vSumOfSquares_.resize(nbins,0);
00084 
00085   // Common mode histograms
00086   cm_.resize(2);
00087   nbins = 1024;
00088   for ( uint16_t iapv = 0; iapv < 2; iapv++ ) { 
00089     
00090     title = SiStripHistoTitle( sistrip::EXPERT_HISTO, 
00091                                sistrip::PEDESTALS, 
00092                                sistrip::FED_KEY, 
00093                                fedKey(),
00094                                sistrip::APV, 
00095                                connection().i2cAddr(iapv),
00096                                sistrip::extrainfo::commonMode_ ).title();
00097     
00098     cm_[iapv].histo( dqm()->book1D( title, title, nbins, -0.5, nbins*1.-0.5 ) );
00099     cm_[iapv].isProfile_ = false;
00100     
00101     cm_[iapv].vNumOfEntries_.resize(nbins,0);
00102     cm_[iapv].vNumOfEntries_.resize(nbins,0);
00103     
00104   }
00105   
00106 }
00107 
00108 // -----------------------------------------------------------------------------
00109 //
00110 void PedestalsTask::fill( const SiStripEventSummary& summary,
00111                           const edm::DetSet<SiStripRawDigi>& digis ) {
00112   
00113   if ( digis.data.size() != peds_[0].vNumOfEntries_.size() ) {
00114     edm::LogWarning(mlDqmSource_)
00115       << "[PedestalsTask::" << __func__ << "]"
00116       << " Unexpected number of digis: " 
00117       << digis.data.size(); 
00118     return;
00119   }
00120   
00121   // Check number of digis
00122   uint16_t nbins = peds_[0].vNumOfEntries_.size();
00123   if ( digis.data.size() < nbins ) { nbins = digis.data.size(); }
00124 
00125   //@@ Inefficient!!!
00126   uint16_t napvs = nbins / 128;
00127   std::vector<uint32_t> cm; cm.resize(napvs,0);
00128   
00129   // Calc common mode for both APVs
00130   std::vector<uint16_t> adc;
00131   for ( uint16_t iapv = 0; iapv < napvs; iapv++ ) { 
00132     adc.clear(); adc.reserve(128);
00133     for ( uint16_t ibin = 0; ibin < 128; ibin++ ) { 
00134       if ( (iapv*128)+ibin < nbins ) { 
00135         adc.push_back( digis.data[(iapv*128)+ibin].adc() );  //@@ VIRGIN RAW DATA (MUX, APV READOUT)
00136       }
00137     }
00138     sort( adc.begin(), adc.end() ); 
00139     uint16_t index = adc.size()%2 ? adc.size()/2 : adc.size()/2-1;
00140     if ( !adc.empty() ) { cm[iapv] = static_cast<uint32_t>( adc[index] ); }
00141   }
00142   
00143   for ( uint16_t ibin = 0; ibin < nbins; ibin++ ) {
00144     updateHistoSet( peds_[0], ibin, digis.data[ibin].adc() ); // peds and raw noise
00145     float diff = static_cast<float>( digis.data[ibin].adc() ) - static_cast<float>( cm[ibin/128] );
00146     updateHistoSet( peds_[1], ibin, diff ); // residuals and real noise
00147   }
00148   
00149   if ( cm.size() < cm_.size() ) {
00150     edm::LogWarning(mlDqmSource_)
00151       << "[PedestalsTask::" << __func__ << "]"
00152       << " Fewer CM values than expected: " << cm.size();
00153   }
00154   
00155   updateHistoSet( cm_[0], cm[0] );
00156   updateHistoSet( cm_[1], cm[1] );
00157   
00158 }
00159 
00160 // -----------------------------------------------------------------------------
00161 //
00162 void PedestalsTask::update() {
00163   
00164   // Pedestals 
00165   updateHistoSet( peds_[0] );
00166   
00167   // Noise (cannot use HistoSet directly, as want to plot noise as "contents", not "error")
00168   TProfile* histo = ExtractTObject<TProfile>().extract( peds_[1].histo() );
00169   for ( uint16_t ii = 0; ii < peds_[1].vNumOfEntries_.size(); ++ii ) {
00170     
00171     float mean    = 0.;
00172     float spread  = 0.;
00173     float entries = peds_[1].vNumOfEntries_[ii];
00174     if ( entries > 0. ) {
00175       mean = peds_[1].vSumOfContents_[ii] / entries;
00176       spread = sqrt( peds_[1].vSumOfSquares_[ii] / entries - mean * mean ); 
00177     }
00178     
00179     float noise = spread;
00180     float error = 0; // sqrt(entries) / entries;
00181     
00182     UpdateTProfile::setBinContent( histo, ii+1, entries, noise, error );
00183     
00184   }
00185   
00186   // Common mode
00187   updateHistoSet( cm_[0] );
00188   updateHistoSet( cm_[1] );
00189   
00190 }
00191