Go to the documentation of this file.00001 #include "DQM/SiStripCommissioningAnalysis/interface/ApvLatencyAlgorithm.h"
00002 #include "CondFormats/SiStripObjects/interface/ApvLatencyAnalysis.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 <iostream>
00008 #include <cmath>
00009
00010 using namespace sistrip;
00011
00012
00013
00014 ApvLatencyAlgorithm::ApvLatencyAlgorithm( const edm::ParameterSet & pset, ApvLatencyAnalysis* const anal )
00015 : CommissioningAlgorithm(anal),
00016 histo_(0,"")
00017 {;}
00018
00019
00020
00021 void ApvLatencyAlgorithm::extract( const std::vector<TH1*>& histos ) {
00022
00023 if ( !anal() ) {
00024 edm::LogWarning(mlCommissioning_)
00025 << "[ApvLatencyAlgorithm::" << __func__ << "]"
00026 << " NULL pointer to Analysis object!";
00027 return;
00028 }
00029
00030
00031 if ( histos.size() != 1 ) {
00032 anal()->addErrorCode(sistrip::numberOfHistos_);
00033 }
00034
00035
00036 if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
00037
00038
00039 std::vector<TH1*>::const_iterator ihis = histos.begin();
00040 for ( ; ihis != histos.end(); ihis++ ) {
00041
00042
00043 if ( !(*ihis) ) { continue; }
00044
00045
00046 SiStripHistoTitle title( (*ihis)->GetName() );
00047 if ( title.runType() != sistrip::APV_LATENCY ) {
00048 anal()->addErrorCode(sistrip::unexpectedTask_);
00049 continue;
00050 }
00051
00052
00053 histo_.first = *ihis;
00054 histo_.second = (*ihis)->GetName();
00055
00056 }
00057
00058 }
00059
00060
00061
00062 void ApvLatencyAlgorithm::analyse() {
00063
00064 if ( !anal() ) {
00065 edm::LogWarning(mlCommissioning_)
00066 << "[ApvLatencyAlgorithm::" << __func__ << "]"
00067 << " NULL pointer to base Analysis object!";
00068 return;
00069 }
00070
00071 CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>( anal() );
00072 ApvLatencyAnalysis* anal = dynamic_cast<ApvLatencyAnalysis*>( tmp );
00073 if ( !anal ) {
00074 edm::LogWarning(mlCommissioning_)
00075 << "[ApvLatencyAlgorithm::" << __func__ << "]"
00076 << " NULL pointer to derived Analysis object!";
00077 return;
00078 }
00079
00080
00081
00082 std::vector<const TProfile*> histos;
00083 std::vector<unsigned short> monitorables;
00084
00085
00086
00087 histos.clear();
00088 histos.push_back( const_cast<const TProfile*>( dynamic_cast<TProfile*>(histo_.first) ) );
00089 if ( !histos[0] ) {
00090 anal->addErrorCode(sistrip::nullPtr_);
00091 return;
00092 }
00093
00094 monitorables.clear();
00095
00096
00097
00098
00099
00100 if (histos.size() != 1) {
00101
00102 monitorables.push_back(0);
00103 return;
00104 }
00105 const TProfile* histo = histos[0];
00106
00107
00108 unsigned short latency;
00109
00110 std::vector<unsigned short> binContent; binContent.reserve((unsigned short)histo->GetNbinsX()); binContent.resize((unsigned short)histo->GetNbinsX(), 0);
00111
00112 for (unsigned short k = 0; k < (unsigned short)histo->GetNbinsX(); k++) {
00113
00114
00115 binContent.push_back((unsigned int)(histo->GetBinContent(k)));}
00116
00117
00118
00119 sort(binContent.begin(), binContent.end());
00120
00121
00122
00123 float meanNoise = 0.;
00124 float mean2Noise = 0.;
00125
00126 for (unsigned short k = (unsigned short)(binContent.size()*.1); k < (unsigned short)(binContent.size()*.9); k++) {
00127 meanNoise += binContent[k];
00128 mean2Noise += binContent[k]*binContent[k];;
00129 }
00130
00131 meanNoise = meanNoise * binContent.size() * 0.8;
00132 mean2Noise = mean2Noise * binContent.size() * 0.8;
00133 float sigmaNoise = sqrt(fabs(meanNoise*meanNoise - mean2Noise));
00134
00135
00136 unsigned short count = 0;
00137 unsigned short maxlatency = 0;
00138 unsigned int maxhits = 0;
00139
00140 for (unsigned short k = 1; k < ((unsigned short)histo->GetNbinsX() + 1); k++) {
00141 if (histo->GetBinContent((Int_t)k) > maxhits) maxlatency = k - 1;
00142 if ((float)histo->GetBinContent((Int_t)k) > (meanNoise + 5 * sigmaNoise)) {
00143 latency = k - 1; count++;
00144 }
00145 }
00146
00147 if (!count) {
00148
00149 latency = maxlatency;
00150 }
00151
00152 if (count > 1) {
00153
00154 latency = maxlatency;
00155 }
00156
00157
00158 monitorables.clear();
00159 monitorables.push_back(latency);
00160
00161 anal->latency_ = monitorables[0];
00162
00163 }