00001 #include <memory>
00002 #include <ostream>
00003
00004 #include "CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h"
00005 #include "CalibTracker/SiStripAPVAnalysis/interface/ApvFactoryService.h"
00006 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00007 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
00008 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00009 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00010 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00011 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00012 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
00013 #include "DQM/SiStripCommon/interface/UpdateTProfile.h"
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017
00018 #include "DQM/SiStripCommissioningSources/interface/NoiseTask.h"
00019
00020 using namespace sistrip;
00021
00022 std::ostream &operator <<( std::ostream &rOut,
00023 ApvAnalysis::PedestalType &rPEDS)
00024 {
00025 for( ApvAnalysis::PedestalType::const_iterator pedsIter = rPEDS.begin();
00026 pedsIter != rPEDS.end();
00027 ++pedsIter)
00028 {
00029 rOut << ' ' << *pedsIter;
00030 }
00031
00032 return rOut;
00033 }
00034
00035
00036
00037 NoiseTask::NoiseTask( DQMStore *dqm,
00038 const FedChannelConnection &conn)
00039 : CommissioningTask( dqm, conn, "NoiseTask")
00040 {
00041
00042 pApvFactory_ = edm::Service<ApvFactoryService>().operator->()->getApvFactory();
00043
00044 LogTrace( mlDqmSource_)
00045 << "[NoiseTask::" << __func__ << "]"
00046 << " Constructing object...";
00047 }
00048
00049
00050
00051 NoiseTask::~NoiseTask()
00052 {
00053 LogTrace(mlDqmSource_)
00054 << "[NoiseTask::" << __func__ << "]"
00055 << " Destructing object...";
00056
00057
00058
00059 if( pApvFactory_) { delete pApvFactory_; }
00060 }
00061
00062
00063
00064 void NoiseTask::book()
00065 {
00066 LogTrace( mlDqmSource_) << "[NoiseTask::" << __func__ << "]";
00067
00068
00069 static std::auto_ptr<SiStripPedestals> pDBPedestals;
00070 static std::auto_ptr<SiStripNoises> pDBNoises;
00071
00072 const uint16_t nBINS = 256;
00073
00074 {
00075
00076 std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00077 sistrip::NOISE,
00078 sistrip::FED_KEY,
00079 fedKey(),
00080 sistrip::LLD_CHAN,
00081 connection().lldChannel(),
00082 sistrip::extrainfo::pedestals_).title();
00083
00084 HistoSet oHSet;
00085 oHSet.isProfile_ = true;
00086
00087 oHSet.vNumOfEntries_.resize( nBINS, 0);
00088 oHSet.vSumOfContents_.resize( nBINS, 0);
00089 oHSet.vSumOfSquares_.resize( nBINS, 0);
00090
00091 oHSet.histo( dqm()->bookProfile( title, title,
00092 nBINS, -0.5, nBINS * 1. - 0.5,
00093 1025, 0., 1025.) );
00094
00095 peds_.push_back( oHSet);
00096 }
00097
00098 {
00099
00100 std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00101 sistrip::NOISE,
00102 sistrip::FED_KEY,
00103 fedKey(),
00104 sistrip::LLD_CHAN,
00105 connection().lldChannel(),
00106 sistrip::extrainfo::noise_).title();
00107
00108 HistoSet oHSet;
00109 oHSet.isProfile_ = true;
00110
00111 oHSet.vNumOfEntries_.resize( nBINS, 0);
00112 oHSet.vSumOfContents_.resize( nBINS, 0);
00113 oHSet.vSumOfSquares_.resize( nBINS, 0);
00114
00115 oHSet.histo( dqm()->bookProfile( title, title,
00116 nBINS, -0.5, nBINS * 1. - 0.5,
00117 1025, 0., 1025.) );
00118
00119 peds_.push_back( oHSet);
00120 }
00121
00122 const uint16_t nCM_BINS = 1024;
00123 for( uint16_t nApv = 0; 2 > nApv; ++nApv)
00124 {
00125 std::string title = SiStripHistoTitle( sistrip::EXPERT_HISTO,
00126 sistrip::PEDESTALS,
00127 sistrip::FED_KEY,
00128 fedKey(),
00129 sistrip::APV,
00130 connection().i2cAddr( nApv),
00131 sistrip::extrainfo::commonMode_).title();
00132
00133 HistoSet oHSet;
00134
00135 oHSet.isProfile_ = false;
00136
00137 oHSet.vNumOfEntries_.resize( nCM_BINS, 0);
00138
00139 oHSet.histo( dqm()->book1D( title, title,
00140 nCM_BINS,
00141 nCM_BINS/2 * -1. - 0.5,
00142 nCM_BINS/2 * 1. - 0.5 ) );
00143
00144 cm_.push_back( oHSet);
00145 }
00146
00147
00148 pApvFactory_->instantiateApvs( connection().detId(), connection().nApvs() );
00149
00150
00151
00152 if( !pDBPedestals.get()) {
00153 LogTrace( mlDqmSource_)
00154 << "[NoiseTask::" << __func__ << "] "
00155 << "Retrieving Pedestals from DB";
00156
00157
00158 edm::ESHandle<SiStripPedestals> pedestals;
00159 eventSetup()->get<SiStripPedestalsRcd>().get( pedestals);
00160
00161
00162 pDBPedestals.reset( new SiStripPedestals( *pedestals) );
00163
00164 LogTrace( mlDqmSource_)
00165 << "[NoiseTask::" << __func__ << "] "
00166 << "Done Retrieving Pedestals from DB";
00167 }
00168
00169
00170
00171 if( !pDBNoises.get()) {
00172 LogTrace( mlDqmSource_)
00173 << "[NoiseTask::" << __func__ << "] "
00174 << "Retrieving Noises from DB";
00175
00176
00177 edm::ESHandle<SiStripNoises> noises;
00178 eventSetup()->get<SiStripNoisesRcd>().get( noises);
00179
00180
00181 pDBNoises.reset( new SiStripNoises( *noises) );
00182
00183 LogTrace( mlDqmSource_)
00184 << "[NoiseTask::" << __func__ << "] "
00185 << "Done Retrieving Noises from DB";
00186 }
00187
00188
00189
00190 ApvAnalysisFactory::ApvAnalysisVector
00191 apvAnalysisVector( pApvFactory_->getApvAnalysis( connection().detId()));
00192
00193 SiStripPedestals::Range pedestalsRange(
00194 pDBPedestals->getRange( connection().detId() ) );
00195 SiStripNoises::Range noisesRange(
00196 pDBNoises->getRange( connection().detId() ) );
00197
00198
00199 const uint16_t nAPV_PAIR = connection().apvPairNumber();
00200
00201 for( uint16_t nLclApv = 0; 2 > nLclApv; ++nLclApv) {
00202
00203 ApvAnalysis::PedestalType pedestals;
00204 ApvAnalysis::PedestalType noises;
00205 for( uint16_t nStrip = nAPV_PAIR * 256 + nLclApv * 128,
00206 nMaxStrip = nStrip + 128;
00207 nMaxStrip > nStrip;
00208 ++nStrip)
00209 {
00210 pedestals.push_back( pDBPedestals->getPed( nStrip, pedestalsRange));
00211 noises.push_back( pDBNoises->getNoise( nStrip, noisesRange));
00212 }
00213
00214 try {
00215
00216 ApvAnalysisFactory::ApvAnalysisVector::reference rApvAnalysis =
00217 apvAnalysisVector.at( nAPV_PAIR * 2 + nLclApv);
00218
00219 rApvAnalysis->pedestalCalculator().setPedestals( pedestals);
00220 rApvAnalysis->pedestalCalculator().setNoise( noises);
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 } catch( std::out_of_range) {
00233
00234 LogTrace( mlDqmSource_)
00235 << "[NoiseTask::" << __func__ << "] "
00236 << "Could not set Pedestals/Noises for DetId|Apv# -> "
00237 << connection().detId() << '|' << ( nAPV_PAIR * 2 + nLclApv)
00238 << ". !!! POSSIBLE BUG !!!";
00239 }
00240 }
00241 }
00242
00243
00244
00245 void NoiseTask::fill( const SiStripEventSummary &rSummary,
00246 const edm::DetSet<SiStripRawDigi> &rDigis)
00247 {
00248 pApvFactory_->updatePair( connection().detId(),
00249 connection().apvPairNumber(),
00250 rDigis);
00251 }
00252
00253
00254
00255 void NoiseTask::update()
00256 {
00257 static UpdateTProfile updateTProfile;
00258
00259 TProfile *pedsProf = ExtractTObject<TProfile>().extract( peds_[0].histo() );
00260 TProfile *noiseProf = ExtractTObject<TProfile>().extract( peds_[1].histo() );
00261
00262 for( uint16_t nLclApv = 2 * connection().apvPairNumber(),
00263 nMaxLclApv = nLclApv + 2,
00264 nApv = 0;
00265 nMaxLclApv > nLclApv;
00266 ++nLclApv, ++nApv)
00267 {
00268 ApvAnalysis::PedestalType lclPedestals;
00269 ApvAnalysis::PedestalType lclNoises;
00270 ApvAnalysis::PedestalType lclCommonMode(
00271 pApvFactory_->getCommonMode( connection().detId(), nLclApv) );
00272
00273 pApvFactory_->getPedestal ( connection().detId(), nLclApv, lclPedestals);
00274 pApvFactory_->getNoise ( connection().detId(), nLclApv, lclNoises );
00275
00276 const uint16_t nSTART_BIN = 128 * ( nLclApv % 2);
00277
00278 for( uint16_t nBin = 0,
00279 nAbsBin = nSTART_BIN + nBin + 1;
00280 128 > nBin;
00281 ++nBin, ++nAbsBin)
00282 {
00283 updateTProfile.setBinContent( pedsProf, nAbsBin, 5,
00284 lclPedestals[nBin], lclNoises[nBin]);
00285 updateTProfile.setBinContent( noiseProf, nAbsBin, 5,
00286 lclNoises[nBin], 0);
00287 }
00288
00289
00290
00291
00292 for( ApvAnalysis::PedestalType::const_iterator cmIterator
00293 = lclCommonMode.begin();
00294 cmIterator != lclCommonMode.end();
00295 ++cmIterator)
00296 {
00297
00298
00299
00300 float nCM = static_cast<float>( *cmIterator );
00301 updateHistoSet( cm_[nApv], nCM );
00302 }
00303
00304 std::stringstream out;
00305 LogTrace( mlDqmSource_)
00306 << "[NoiseTask::" << __func__ << "] "
00307 << "DET ID [" << connection().detId()
00308 << "] has Common Mode size " << lclCommonMode.size() << " : "
00309 << ( out << lclCommonMode, out.str());
00310 }
00311
00312 updateHistoSet( cm_[0]);
00313 updateHistoSet( cm_[1]);
00314 }