CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DQM/SiStripCommissioningClients/src/ApvTimingHistograms.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningClients/interface/ApvTimingHistograms.h"
00002 #include "CondFormats/SiStripObjects/interface/ApvTimingAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00004 #include "DQM/SiStripCommissioningAnalysis/interface/ApvTimingAlgorithm.h"
00005 #include "DQM/SiStripCommissioningSummary/interface/ApvTimingSummaryFactory.h"
00006 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "TProfile.h"
00009 #include <iostream>
00010 #include <sstream>
00011 #include <iomanip>
00012  
00013 using namespace std;
00014 using namespace sistrip;
00015 
00016 // -----------------------------------------------------------------------------
00018 ApvTimingHistograms::ApvTimingHistograms( const edm::ParameterSet& pset,
00019                                           DQMStore* bei ) 
00020   : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("ApvTimingParameters"),
00021                              bei,
00022                              sistrip::APV_TIMING )
00023 {
00024   factory_ = auto_ptr<ApvTimingSummaryFactory>( new ApvTimingSummaryFactory );
00025   LogTrace(mlDqmClient_) 
00026     << "[ApvTimingHistograms::" << __func__ << "]"
00027     << " Constructing object...";
00028 }
00029 
00030 // -----------------------------------------------------------------------------
00032 ApvTimingHistograms::~ApvTimingHistograms() {
00033   LogTrace(mlDqmClient_) 
00034     << "[ApvTimingHistograms::" << __func__ << "]"
00035     << " Destructing object...";
00036 }
00037 
00038 // -----------------------------------------------------------------------------         
00040 void ApvTimingHistograms::histoAnalysis( bool debug ) {
00041   LogTrace(mlDqmClient_)
00042     << "[ApvTimingHistograms::" << __func__ << "]";
00043 
00044   // Some initialisation
00045   uint16_t valid = 0;
00046   HistosMap::const_iterator iter;
00047   Analyses::iterator ianal;
00048   std::map<std::string,uint16_t> errors;
00049   
00050   // Clear map holding analysis objects
00051   for ( ianal = data().begin(); ianal != data().end(); ianal++ ) { 
00052     if ( ianal->second ) { delete ianal->second; }
00053   } 
00054   data().clear();
00055   
00056   // Reset minimum / maximum delays
00057   float time_min =  1. * sistrip::invalid_;
00058   float time_max = -1. * sistrip::invalid_;
00059   uint32_t device_min = sistrip::invalid_;
00060   uint32_t device_max = sistrip::invalid_;
00061   
00062   // Iterate through map containing histograms
00063   for ( iter = histos().begin();
00064         iter != histos().end(); iter++ ) {
00065     
00066     // Check vector of histos is not empty
00067     if ( iter->second.empty() ) {
00068       edm::LogWarning(mlDqmClient_) 
00069         << "[ApvTimingHistograms::" << __func__ << "]"
00070         << " Zero histograms found!";
00071       continue;
00072     }
00073     
00074     // Retrieve pointers to histos
00075     std::vector<TH1*> profs;
00076     Histos::const_iterator ihis = iter->second.begin(); 
00077     for ( ; ihis != iter->second.end(); ihis++ ) {
00078       TProfile* prof = ExtractTObject<TProfile>().extract( (*ihis)->me_ );
00079       if ( prof ) { profs.push_back(prof); }
00080     } 
00081     
00082     // Perform histo analysis
00083     ApvTimingAnalysis* anal = new ApvTimingAnalysis( iter->first );
00084     ApvTimingAlgorithm algo( this->pset(), anal );
00085     algo.analysis( profs );
00086     data()[iter->first] = anal; 
00087 
00088     // Check if tick mark found
00089     if ( !anal->foundTickMark() ) { continue; }
00090     
00091     // Find maximum time
00092     if ( anal->time() > time_max ) { 
00093       time_max = anal->time(); 
00094       device_max = iter->first;
00095     }
00096     
00097     // Find minimum time
00098     if ( anal->time() < time_min ) { 
00099       time_min = anal->time(); 
00100       device_min = iter->first;
00101     }
00102     
00103   }
00104   
00105   // Adjust maximum (and minimum) delay(s) to find optimum sampling point(s)
00106   if ( time_max > sistrip::valid_ ||
00107        time_max < -1.*sistrip::valid_ ) { 
00108 
00109     edm::LogWarning(mlDqmClient_)
00110       << "[ApvTimingHistograms::" << __func__ << "]"
00111       << " Unable to set maximum time! Found unexpected value: "
00112       << time_max;
00113     
00114   } else {
00115     
00116     SiStripFecKey min( device_min );
00117     edm::LogVerbatim(mlDqmClient_)
00118       << "[ApvTimingHistograms::" << __func__ << "]"
00119       << " Crate/FEC/Ring/CCU/module/channel: " 
00120       << min.fecCrate() << "/" 
00121       << min.fecSlot() << "/" 
00122       << min.fecRing() << "/" 
00123       << min.ccuAddr() << "/"
00124       << min.ccuChan() << "/"
00125       << min.lldChan() 
00126       << " has minimum time for tick mark rising edge [ns]: " << time_min;
00127     
00128     SiStripFecKey max( device_max );
00129     edm::LogVerbatim(mlDqmClient_)
00130       << "[ApvTimingHistograms::" << __func__ << "]"
00131       << " Crate/FEC/Ring/CCU/module/channel: " 
00132       << max.fecCrate() << "/" 
00133       << max.fecSlot() << "/" 
00134       << max.fecRing() << "/" 
00135       << max.ccuAddr() << "/"
00136       << max.ccuChan() << "/"
00137       << max.lldChan() 
00138       << " has maximum time for tick mark rising edge [ns]: " << time_max;
00139 
00140     edm::LogVerbatim(mlDqmClient_)
00141       << "[ApvTimingHistograms::" << __func__ << "]"
00142       << " Difference b/w minimum and maximum times"
00143       << " for tick mark rising edges [ns] is: " << ( time_max - time_min );
00144 
00145   }
00146   
00147   // Set reference time for all analysis objects
00148   for ( ianal = data().begin(); ianal != data().end(); ianal++ ) { 
00149     ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(ianal->second);
00150     if ( !anal ) { continue; }
00151     anal->refTime( time_max, this->pset().getParameter<int>("TargetDelay") );
00152     if ( anal->isValid() ) { valid++; }
00153     if ( !anal->getErrorCodes().empty() ) { 
00154       errors[anal->getErrorCodes()[0]]++;
00155     }
00156   }
00157 
00158   if ( !histos().empty() ) {
00159     edm::LogVerbatim(mlDqmClient_) 
00160       << "[ApvTimingHistograms::" << __func__ << "]"
00161       << " Analyzed histograms for " << histos().size() 
00162       << " FED channels, of which " << valid 
00163       << " (" << 100 * valid / histos().size()
00164       << "%) are valid.";
00165   } else {
00166     edm::LogWarning(mlDqmClient_) 
00167       << "[ApvTimingHistograms::" << __func__ << "]"
00168       << " No histograms to analyze!";
00169   }
00170 
00171   if ( !histos().empty() ) {
00172     edm::LogVerbatim(mlDqmClient_) 
00173       << "[ApvTimingHistograms::" << __func__ << "]"
00174       << " Analyzed histograms for " << histos().size() 
00175       << " FED channels, of which " << valid 
00176       << " (" << 100 * valid / histos().size()
00177       << "%) are valid.";
00178     if ( !errors.empty() ) {
00179       uint16_t count = 0;
00180       std::stringstream ss;
00181       ss << std::endl;
00182       std::map<std::string,uint16_t>::const_iterator ii;
00183       for ( ii = errors.begin(); ii != errors.end(); ++ii ) { 
00184         ss << " " << ii->first << ": " << ii->second << std::endl;
00185         count += ii->second;
00186       }
00187       edm::LogWarning(mlDqmClient_) 
00188         << "[ApvTimingHistograms::" << __func__ << "]"
00189         << " Found " << count << " errors ("
00190         << 100 * count / histos().size() << "%): " 
00191         << ss.str();
00192     }
00193   } else {
00194     edm::LogWarning(mlDqmClient_) 
00195       << "[ApvTimingHistograms::" << __func__ << "]"
00196       << " No histograms to analyze!";
00197   }
00198   
00199 }