00001
00002 #include "DQM/SiStripCommissioningSources/interface/PedsFullNoiseTask.h"
00003
00004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00006 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00007 #include "DQM/SiStripCommon/src/UpdateTProfile.cc"
00008 #include "DQMServices/Core/interface/DQMStore.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011
00012 #include "boost/lexical_cast.hpp"
00013
00014
00015
00016
00017 PedsFullNoiseTask::PedsFullNoiseTask(DQMStore * dqm, const FedChannelConnection & conn, const edm::ParameterSet & pset) :
00018 CommissioningTask(dqm, conn, "PedsFullNoiseTask"),
00019 nstrips_(256)
00020 {
00021 LogTrace(sistrip::mlDqmSource_)
00022 << "[PedsFullNoiseTask::" << __func__ << "]"
00023 << " Constructing object...";
00024 edm::ParameterSet params = pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters");
00025 nskip_ = params.getParameter<int>("NrEvToSkipAtStart");
00026 skipped_ = false;
00027 nevpeds_ = params.getParameter<int>("NrEvForPeds");
00028 pedsdone_ = false;
00029 nadcnoise_ = params.getParameter<int>("NrPosBinsNoiseHist");
00030 fillnoiseprofile_ = params.getParameter<bool>("FillNoiseProfile");
00031 useavgcm_ = params.getParameter<bool>("UseAverageCommonMode");
00032 usefloatpeds_ = params.getParameter<bool>("UseFloatPedestals");
00033 }
00034
00035
00036
00037 PedsFullNoiseTask::~PedsFullNoiseTask()
00038 {
00039 LogTrace(sistrip::mlDqmSource_)
00040 << "[PedsFullNoiseTask::" << __func__ << "]"
00041 << " Destructing object...";
00042 }
00043
00044
00045
00046 void PedsFullNoiseTask::book()
00047 {
00048
00049 LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]";
00050
00051
00052 pedhist_.isProfile_ = true;
00053 pedhist_.explicitFill_ = false;
00054 if (!pedhist_.explicitFill_) {
00055 pedhist_.vNumOfEntries_.resize(nstrips_,0);
00056 pedhist_.vSumOfContents_.resize(nstrips_,0);
00057 pedhist_.vSumOfSquares_.resize(nstrips_,0);
00058 }
00059 std::string titleped = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00060 sistrip::PEDS_FULL_NOISE,
00061 sistrip::FED_KEY,
00062 fedKey(),
00063 sistrip::LLD_CHAN,
00064 connection().lldChannel(),
00065 sistrip::extrainfo::pedestals_).title();
00066 pedhist_.histo( dqm()->bookProfile( titleped, titleped,
00067 nstrips_, -0.5, nstrips_*1.-0.5,
00068 1025, 0., 1025. ) );
00069
00070
00071 noiseprof_.isProfile_ = true;
00072 noiseprof_.explicitFill_ = false;
00073 if (!noiseprof_.explicitFill_) {
00074 noiseprof_.vNumOfEntries_.resize(nstrips_,0);
00075 noiseprof_.vSumOfContents_.resize(nstrips_,0);
00076 noiseprof_.vSumOfSquares_.resize(nstrips_,0);
00077 }
00078 std::string titlenoise = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00079 sistrip::PEDS_FULL_NOISE,
00080 sistrip::FED_KEY,
00081 fedKey(),
00082 sistrip::LLD_CHAN,
00083 connection().lldChannel(),
00084 sistrip::extrainfo::noiseProfile_ ).title();
00085 noiseprof_.histo( dqm()->bookProfile( titlenoise, titlenoise,
00086 nstrips_, -0.5, nstrips_*1.-0.5,
00087 1025, 0., 1025. ) );
00088
00089
00090 noisehist_.explicitFill_ = false;
00091 if (!noisehist_.explicitFill_) {
00092 noisehist_.vNumOfEntries_.resize((nstrips_+2)*2*(nadcnoise_+2), 0);
00093 }
00094 std::string titlenoise2d = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00095 sistrip::PEDS_FULL_NOISE,
00096 sistrip::FED_KEY,
00097 fedKey(),
00098 sistrip::LLD_CHAN,
00099 connection().lldChannel(),
00100 sistrip::extrainfo::noise2D_ ).title();
00101 noisehist_.histo( dqm()->book2S( titlenoise2d, titlenoise2d,
00102 2*nadcnoise_, -nadcnoise_, nadcnoise_,
00103 nstrips_, -0.5, nstrips_*1.-0.5 ) );
00104 hist2d_ = (TH2S *) noisehist_.histo()->getTH2S();
00105
00106 }
00107
00108
00109
00110 void PedsFullNoiseTask::fill( const SiStripEventSummary & summary,
00111 const edm::DetSet<SiStripRawDigi> & digis )
00112 {
00113
00114
00115 uint16_t nbins = digis.data.size();
00116 if (nbins != nstrips_) {
00117 edm::LogWarning(sistrip::mlDqmSource_)
00118 << "[PedsFullNoiseTask::" << __func__ << "]"
00119 << " " << nstrips_ << " digis expected, but got " << nbins << ". Skipping.";
00120 return;
00121 }
00122
00123
00124 static int32_t firstev = summary.event();
00125
00126
00127 if (!skipped_) {
00128 if (static_cast<int32_t>(summary.event()) - firstev < nskip_) {
00129 return;
00130 } else {
00131 skipped_ = true;
00132 if (nskip_ > 0) LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
00133 << " Done skipping events. Now starting pedestals.";
00134 }
00135 }
00136
00137
00138 if (!pedsdone_) {
00139 if (static_cast<int32_t>(summary.event()) - firstev < nskip_ + nevpeds_) {
00140
00141 for ( uint16_t istrip = 0; istrip < nstrips_; ++istrip ) {
00142 updateHistoSet( pedhist_, istrip, digis.data[istrip].adc() );
00143 }
00144 return;
00145 } else {
00146 pedsdone_ = true;
00147
00148 peds_.clear(); pedsfl_.clear();
00149 for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00150 for ( uint16_t ibin = 0; ibin < 128; ++ibin ) {
00151 uint16_t istrip = (iapv*128)+ibin;
00152 if (usefloatpeds_) {
00153 pedsfl_.push_back(1.*pedhist_.vSumOfContents_.at(istrip)/pedhist_.vNumOfEntries_.at(istrip));
00154 } else {
00155 peds_.push_back(static_cast<int16_t>(1.*pedhist_.vSumOfContents_.at(istrip)/pedhist_.vNumOfEntries_.at(istrip)));
00156 }
00157 }
00158 }
00159 LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
00160 << " Rough pedestals done. Now starting noise measurements.";
00161 }
00162 }
00163
00164
00165 if (fillnoiseprofile_) {
00166
00167 std::vector<int32_t> cm; cm.resize(2, 0);
00168 std::vector<uint16_t> adc;
00169 for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
00170 adc.clear(); adc.reserve(128);
00171 for ( uint16_t ibin = 0; ibin < 128; ibin++ ) {
00172 if ( (iapv*128)+ibin < nbins ) {
00173 adc.push_back( digis.data.at((iapv*128)+ibin).adc() );
00174 }
00175 }
00176 sort( adc.begin(), adc.end() );
00177
00178 uint16_t index = adc.size()%2 ? adc.size()/2 : adc.size()/2-1;
00179 cm[iapv] = static_cast<int16_t>(adc[index]);
00180 }
00181
00182 for ( uint16_t istrip = 0; istrip < nstrips_; ++istrip ) {
00183
00184 int16_t noiseval = static_cast<int16_t>(digis.data.at(istrip).adc()) - cm[istrip/128];
00185 updateHistoSet( noiseprof_, istrip, noiseval );
00186 }
00187 }
00188
00189
00190 std::vector<int16_t> noisevals, noisevalssorted;
00191 std::vector<float> noisevalsfl, noisevalssortedfl;
00192 for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
00193 float totadc = 0;
00194 noisevals.clear(); noisevalsfl.clear();
00195 noisevalssorted.clear(); noisevalssortedfl.clear();
00196 for ( uint16_t ibin = 0; ibin < 128; ++ibin ) {
00197 uint16_t istrip = (iapv*128)+ibin;
00198
00199 if (usefloatpeds_) {
00200 noisevalsfl.push_back( static_cast<float>(digis.data.at(istrip).adc()) - pedsfl_.at(istrip) );
00201
00202 if (useavgcm_) {
00203 totadc += noisevalsfl[ibin];
00204 } else {
00205 noisevalssortedfl.push_back( noisevalsfl[ibin] );
00206 }
00207 } else {
00208 noisevals.push_back( static_cast<int16_t>(digis.data.at(istrip).adc()) - peds_.at(istrip) );
00209
00210 if (useavgcm_) {
00211 totadc += noisevals[ibin];
00212 } else {
00213 noisevalssorted.push_back( noisevals[ibin] );
00214 }
00215 }
00216 }
00217
00218 float cmshift = 0;
00219 if (useavgcm_) {
00220 if (usefloatpeds_) {
00221 cmshift = totadc/128;
00222 } else {
00223 cmshift = static_cast<int16_t>(totadc/128);
00224 }
00225 } else {
00226 if (usefloatpeds_) {
00227
00228 sort( noisevalssortedfl.begin(), noisevalssortedfl.end() );
00229 uint16_t index = noisevalssortedfl.size()%2 ? noisevalssortedfl.size()/2 : noisevalssortedfl.size()/2-1;
00230 cmshift = noisevalssortedfl[index];
00231 } else {
00232
00233 sort( noisevalssorted.begin(), noisevalssorted.end() );
00234 uint16_t index = noisevalssorted.size()%2 ? noisevalssorted.size()/2 : noisevalssorted.size()/2-1;
00235 cmshift = noisevalssorted[index];
00236 }
00237 }
00238
00239 for ( uint16_t ibin = 0; ibin < 128; ++ibin ) {
00240 uint16_t istrip = (iapv*128)+ibin;
00241
00242 float noiseval = (usefloatpeds_ ? noisevalsfl[ibin] : noisevals[ibin]) - cmshift;
00243
00244 uint32_t binnr = hist2d_->GetBin(static_cast<int>(noiseval+nadcnoise_), istrip+1);
00245
00246 updateHistoSet( noisehist_, binnr );
00247 }
00248 }
00249
00250 }
00251
00252
00253
00254 void PedsFullNoiseTask::update()
00255 {
00256
00257
00258 updateHistoSet( pedhist_ );
00259
00260 if (fillnoiseprofile_) {
00261
00262 TProfile* histo = ExtractTObject<TProfile>().extract( noiseprof_.histo() );
00263 for ( uint16_t ii = 0; ii < noiseprof_.vNumOfEntries_.size(); ++ii ) {
00264 float mean = 0.;
00265 float spread = 0.;
00266 float entries = noiseprof_.vNumOfEntries_[ii];
00267 if ( entries > 0. ) {
00268 mean = noiseprof_.vSumOfContents_[ii] / entries;
00269 spread = sqrt( noiseprof_.vSumOfSquares_[ii] / entries - mean * mean );
00270 }
00271 float error = spread / sqrt(entries);
00272 UpdateTProfile::setBinContent( histo, ii+1, entries, spread, error );
00273 }
00274 }
00275
00276
00277 updateHistoSet( noisehist_ );
00278
00279 }
00280