CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripCommissioningAnalysis/src/FedCablingAlgorithm.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningAnalysis/interface/FedCablingAlgorithm.h"
00002 #include "CondFormats/SiStripObjects/interface/FedCablingAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "TProfile.h"
00007 #include "TH1.h"
00008 #include <iostream>
00009 #include <sstream>
00010 #include <iomanip>
00011 #include <cmath>
00012 
00013 using namespace sistrip;
00014 
00015 // ----------------------------------------------------------------------------
00016 // 
00017 FedCablingAlgorithm::FedCablingAlgorithm( const edm::ParameterSet & pset, FedCablingAnalysis* const anal ) 
00018   : CommissioningAlgorithm(anal),
00019     hFedId_(0,""),
00020     hFedCh_(0,"")
00021 {;}
00022 
00023 // ----------------------------------------------------------------------------
00024 // 
00025 void FedCablingAlgorithm::extract( const std::vector<TH1*>& histos ) { 
00026 
00027   if ( !anal() ) {
00028     edm::LogWarning(mlCommissioning_)
00029       << "[FedCablingAlgorithm::" << __func__ << "]"
00030       << " NULL pointer to Analysis object!";
00031     return; 
00032   }
00033 
00034   // Check number of histograms
00035   if ( histos.size() != 2 ) {
00036     anal()->addErrorCode(sistrip::numberOfHistos_);
00037   }
00038 
00039   // Extract FED key from histo title
00040   if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
00041 
00042   // Extract histograms
00043   std::vector<TH1*>::const_iterator ihis = histos.begin();
00044   for ( ; ihis != histos.end(); ihis++ ) {
00045     
00046     // Check for NULL pointer
00047     if ( !(*ihis) ) { continue; }
00048 
00049     // Check name
00050     SiStripHistoTitle title( (*ihis)->GetName() );
00051     if ( title.runType() != sistrip::FED_CABLING ) {
00052       anal()->addErrorCode(sistrip::unexpectedTask_);
00053       continue;
00054     }
00055     
00056     // Extract FED id and channel histos
00057     if ( title.extraInfo().find(sistrip::feDriver_) != std::string::npos ) {
00058       hFedId_.first = *ihis;
00059       hFedId_.second = (*ihis)->GetName();
00060     } else if ( title.extraInfo().find(sistrip::fedChannel_) != std::string::npos ) {
00061       hFedCh_.first = *ihis;
00062       hFedCh_.second = (*ihis)->GetName();
00063     } else { 
00064       anal()->addErrorCode(sistrip::unexpectedExtraInfo_);
00065     }
00066     
00067   }
00068   
00069 }
00070 
00071 // -----------------------------------------------------------------------------
00072 // 
00073 void FedCablingAlgorithm::analyse() { 
00074 
00075   if ( !anal() ) {
00076     edm::LogWarning(mlCommissioning_)
00077       << "[FedCablingAlgorithm::" << __func__ << "]"
00078       << " NULL pointer to base Analysis object!";
00079     return; 
00080   }
00081 
00082   CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>( anal() );
00083   FedCablingAnalysis* anal = dynamic_cast<FedCablingAnalysis*>( tmp );
00084   if ( !anal ) {
00085     edm::LogWarning(mlCommissioning_)
00086       << "[FedCablingAlgorithm::" << __func__ << "]"
00087       << " NULL pointer to derived Analysis object!";
00088     return; 
00089   }
00090 
00091   if ( !hFedId_.first ) {
00092     anal->addErrorCode(sistrip::nullPtr_);
00093     return;
00094   }
00095 
00096   if ( !hFedCh_.first ) {
00097     anal->addErrorCode(sistrip::nullPtr_);
00098     return;
00099   }
00100 
00101   TProfile* fedid_histo = dynamic_cast<TProfile*>(hFedId_.first);
00102   if ( !fedid_histo ) {
00103     anal->addErrorCode(sistrip::nullPtr_);
00104     return;
00105   }
00106 
00107   TProfile* fedch_histo = dynamic_cast<TProfile*>(hFedCh_.first);
00108   if ( !fedch_histo ) {
00109     anal->addErrorCode(sistrip::nullPtr_);
00110     return;
00111   }
00112 
00113   // Some initialization
00114   anal->candidates_.clear();
00115   float max       = -1.;
00116   float weight    = -1.;
00117   uint16_t id_val = sistrip::invalid_;
00118   uint16_t ch_val = sistrip::invalid_;
00119   
00120   // FED id
00121   max = 0.;
00122   for ( uint16_t ifed = 0; ifed < fedid_histo->GetNbinsX(); ifed++ ) {
00123     if ( fedid_histo->GetBinEntries(ifed+1) ) {
00124       if ( fedid_histo->GetBinContent(ifed+1) > max &&
00125            fedid_histo->GetBinContent(ifed+1) > FedCablingAnalysis::threshold_ ) { 
00126         id_val = ifed; 
00127         max = fedid_histo->GetBinContent(ifed+1);
00128       }
00129     }
00130   }
00131   weight = max;
00132 
00133   // FED ch
00134   max = 0.;
00135   for ( uint16_t ichan = 0; ichan < fedch_histo->GetNbinsX(); ichan++ ) {
00136     if ( fedch_histo->GetBinEntries(ichan+1) ) {
00137       if ( fedch_histo->GetBinContent(ichan+1) > max &&
00138            fedch_histo->GetBinContent(ichan+1) > FedCablingAnalysis::threshold_ ) { 
00139         ch_val = ichan; 
00140         max = fedch_histo->GetBinContent(ichan+1);
00141       }
00142     }
00143   }
00144   if ( max > weight ) { weight = max; }
00145 
00146   // Set "best" candidate and ADC level
00147   if  ( id_val != sistrip::invalid_ &&
00148         ch_val != sistrip::invalid_ ) {
00149     uint32_t key = SiStripFedKey( id_val, 
00150                                   SiStripFedKey::feUnit(ch_val),
00151                                   SiStripFedKey::feChan(ch_val) ).key();
00152     anal->candidates_[key] = static_cast<uint16_t>(weight);
00153     anal->fedId_ = id_val;
00154     anal->fedCh_ = ch_val;
00155     anal->adcLevel_ = weight;
00156   } else {
00157     anal->addErrorCode(sistrip::noCandidates_);
00158   }
00159 
00160 }