00001 #include "DQM/SiStripCommissioningAnalysis/interface/SamplingAlgorithm.h"
00002 #include "CondFormats/SiStripObjects/interface/SamplingAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "DQM/SiStripCommissioningAnalysis/interface/SiStripPulseShape.h"
00007 #include "TProfile.h"
00008 #include "TF1.h"
00009 #include <iostream>
00010 #include <sstream>
00011 #include <iomanip>
00012 #include <cmath>
00013
00014 using namespace sistrip;
00015
00016
00017
00018 SamplingAlgorithm::SamplingAlgorithm( SamplingAnalysis* const anal )
00019 : CommissioningAlgorithm(anal),
00020 histo_(0,""),
00021 deconv_fitter_(0),
00022 peak_fitter_(0),
00023 samp_(0)
00024 {
00025 peak_fitter_ = new TF1("peak_fitter",fpeak_convoluted,-4800,0,5);
00026 peak_fitter_->SetNpx(2000);
00027 peak_fitter_->FixParameter(0,0);
00028 peak_fitter_->SetParLimits(1,0,4800);
00029 peak_fitter_->SetParLimits(2,0,20);
00030 peak_fitter_->FixParameter(3,50);
00031 peak_fitter_->SetParLimits(4,0,100);
00032 peak_fitter_->SetParameters(0.,1250,10,50,10);
00033 deconv_fitter_ = new TF1("deconv_fitter",fdeconv_convoluted,-50,50,5);
00034 deconv_fitter_->SetNpx(1000);
00035 deconv_fitter_->FixParameter(0,0);
00036 deconv_fitter_->SetParLimits(1,-10,10);
00037 deconv_fitter_->SetParLimits(2,0,200);
00038 deconv_fitter_->SetParLimits(3,5,100);
00039 deconv_fitter_->FixParameter(3,50);
00040 deconv_fitter_->SetParLimits(4,0,100);
00041 deconv_fitter_->SetParameters(0.,-2.82,0.96,50,20);
00042 }
00043
00044
00045
00046 void SamplingAlgorithm::extract( const std::vector<TH1*>& histos) {
00047
00048 if ( !anal() ) {
00049 edm::LogWarning(mlCommissioning_)
00050 << "[SamplingAlgorithm::" << __func__ << "]"
00051 << " NULL pointer to Analysis object!";
00052 return;
00053 }
00054
00055 CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>( anal() );
00056 samp_ = dynamic_cast<SamplingAnalysis*>( tmp );
00057 if ( !samp_ ) {
00058 edm::LogWarning(mlCommissioning_)
00059 << "[SamplingAlgorithm::" << __func__ << "]"
00060 << " NULL pointer to derived Analysis object!";
00061 return;
00062 }
00063
00064
00065 if ( histos.size() != 1 && histos.size() != 2 ) {
00066 samp_->addErrorCode(sistrip::numberOfHistos_);
00067 }
00068
00069
00070 if ( !histos.empty() ) { samp_->fedKey( extractFedKey( histos.front() ) ); }
00071
00072
00073 std::vector<TH1*>::const_iterator ihis = histos.begin();
00074 for ( ; ihis != histos.end(); ihis++ ) {
00075
00076
00077 if ( !(*ihis) ) {
00078 edm::LogWarning(mlCommissioning_) << " NULL pointer to histogram!";
00079 continue;
00080 }
00081
00082
00083 SiStripHistoTitle title( (*ihis)->GetName() );
00084 if ( title.runType() != sistrip::APV_LATENCY && title.runType() != sistrip::FINE_DELAY) {
00085 samp_->addErrorCode(sistrip::unexpectedTask_);
00086 continue;
00087 }
00088
00089 samp_->runType_ = title.runType();
00090
00091
00092 samp_->granularity_ = title.granularity();
00093
00094
00095 if ( title.extraInfo().find(sistrip::extrainfo::clusterCharge_) != std::string::npos ) {
00096 histo_.first = *ihis;
00097 histo_.second = (*ihis)->GetName();
00098 }
00099
00100 }
00101
00102 }
00103
00104
00105
00106 void SamplingAlgorithm::analyse() {
00107
00108 if ( !samp_ ) {
00109 edm::LogWarning(mlCommissioning_)
00110 << "[SamplingAlgorithm::" << __func__ << "]"
00111 << " NULL pointer to derived Analysis object!";
00112 return;
00113 }
00114
00115 TProfile* prof = (TProfile*)(histo_.first);
00116 if ( !prof ) {
00117 edm::LogWarning(mlCommissioning_)
00118 << " NULL pointer to histogram!" ;
00119 return;
00120 }
00121
00122
00123 prof->SetErrorOption(" ");
00124
00125
00126 pruneProfile(prof);
00127
00128
00129 correctBinning(prof);
00130
00131
00132 correctProfile(prof,samp_->sOnCut_);
00133
00134
00135 if(samp_->runType_==sistrip::APV_LATENCY) {
00136
00137
00138 float max = prof->GetBinCenter(prof->GetMaximumBin());
00139 float ampl = prof->GetMaximum();
00140 peak_fitter_->SetParameters(0.,50-max,ampl/20.,50,10);
00141
00142
00143 if(prof->Fit(peak_fitter_,"Q")==0)
00144 prof->Fit(peak_fitter_,"QEM");
00145
00146
00147 samp_->max_ = peak_fitter_->GetMaximumX();
00148 samp_->error_ = peak_fitter_->GetParError(1);
00149
00150 } else {
00151
00152
00153 if(prof->Fit(deconv_fitter_,"Q")==0)
00154 prof->Fit(deconv_fitter_,"QEM");
00155
00156
00157 samp_->max_ = deconv_fitter_->GetMaximumX();
00158 samp_->error_ = deconv_fitter_->GetParError(1);
00159
00160 }
00161
00162 }
00163
00164
00165
00166 void SamplingAlgorithm::pruneProfile(TProfile* profile) const
00167 {
00168
00169 uint32_t nbins=profile->GetNbinsX();
00170 uint32_t max = 0;
00171 for(uint32_t bin=1;bin<=nbins;++bin) max = max < profile->GetBinEntries(bin) ? uint32_t(profile->GetBinEntries(bin)) : max;
00172
00173 uint32_t min = max/10;
00174 for(uint32_t bin=1;bin<=nbins;++bin)
00175 if(profile->GetBinEntries(bin)<min) {
00176 profile->SetBinContent(bin,0.);
00177 profile->SetBinError(bin,0.);
00178 }
00179 }
00180
00181
00182
00183 void SamplingAlgorithm::correctBinning(TProfile* prof) const
00184 {
00185 prof->GetXaxis()->SetLimits(prof->GetXaxis()->GetXmin()-prof->GetBinWidth(1)/2.,
00186 prof->GetXaxis()->GetXmax()-prof->GetBinWidth(1)/2.);
00187 }
00188
00189
00190
00191 void SamplingAlgorithm::correctProfile(TProfile* profile, float SoNcut) const
00192 {
00193 if ( !samp_ ) { return; }
00194 uint32_t nbins=profile->GetNbinsX();
00195 float min = samp_->limit(SoNcut);
00196 for(uint32_t bin=1;bin<=nbins;++bin)
00197 if(profile->GetBinContent(bin)<min) {
00198 profile->SetBinContent(bin,0.);
00199 profile->SetBinError(bin,0.);
00200 profile->SetBinEntries(bin,0);
00201 }
00202 else {
00203 profile->SetBinContent(bin,
00204 profile->GetBinEntries(bin)*
00205 samp_->correctMeasurement(profile->GetBinContent(bin),SoNcut));
00206 }
00207 }