CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripCommissioningSummary/src/CalibrationSummaryFactory.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSummary/interface/CalibrationSummaryFactory.h"
00002 #include "CondFormats/SiStripObjects/interface/CalibrationAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include <iostream>
00006 #include <sstream>
00007 
00008 using namespace sistrip;
00009 
00010 // -----------------------------------------------------------------------------
00011 //
00012 void CalibrationSummaryFactory::extract( Iterator iter ) {
00013 
00014   CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>( iter->second );
00015   if ( !anal ) { return; }
00016 
00017   std::vector<float> temp(128, 1. * sistrip::invalid_ );
00018   std::vector< std::vector<float> > value( 2, temp );
00019   std::vector< std::vector<float> > error( 2, temp );
00020   std::vector< std::vector<float> > amplitude( 2, temp );
00021   std::vector< std::vector<float> > tail( 2, temp );
00022   std::vector< std::vector<float> > riseTime( 2, temp );
00023   std::vector< std::vector<float> > timeConstant( 2, temp );
00024   std::vector< std::vector<float> > smearing( 2, temp );
00025   std::vector< std::vector<float> > chi2( 2, temp );
00026   amplitude[0] = anal->amplitude()[0];
00027   amplitude[1] = anal->amplitude()[1];
00028   tail[0] = anal->tail()[0];
00029   tail[1] = anal->tail()[1];
00030   riseTime[0] = anal->riseTime()[0];
00031   riseTime[1] = anal->riseTime()[1];
00032   timeConstant[0] = anal->timeConstant()[0];
00033   timeConstant[1] = anal->timeConstant()[1];
00034   smearing[0] = anal->smearing()[0];
00035   smearing[1] = anal->smearing()[1];
00036   chi2[0] = anal->chi2()[0];
00037   chi2[1] = anal->chi2()[1];
00038   
00039   SiStripFecKey lldKey = SiStripFecKey(iter->first);
00040   uint32_t key1 = SiStripFecKey(lldKey.fecCrate(),
00041                                 lldKey.fecSlot(),
00042                                 lldKey.fecRing(),
00043                                 lldKey.ccuAddr(),
00044                                 lldKey.ccuChan(),
00045                                 lldKey.lldChan(),
00046                                 lldKey.i2cAddr(lldKey.lldChan(),true)).key();
00047   uint32_t key2 = SiStripFecKey(lldKey.fecCrate(),
00048                                 lldKey.fecSlot(),
00049                                 lldKey.fecRing(),
00050                                 lldKey.ccuAddr(),
00051                                 lldKey.ccuChan(),
00052                                 lldKey.lldChan(),
00053                                 lldKey.i2cAddr(lldKey.lldChan(),false)).key();
00054   
00055   bool all_strips = false;
00056   bool with_error = false;
00057   if ( mon_ == sistrip::CALIBRATION_AMPLITUDE_ALLSTRIPS) {
00058     all_strips = true;
00059     uint16_t bins = amplitude[amplitude[0].size() < amplitude[1].size() ? 1 : 0].size();
00060     for ( uint16_t i = 0; i < bins; i++ ) {
00061       value[0][i] = amplitude[0][i]/10.;
00062       value[1][i] = amplitude[1][i]/10.;
00063     }
00064   } else if ( mon_ == sistrip::CALIBRATION_AMPLITUDE) {
00065     with_error = true;
00066     value[0][0] = anal->amplitudeMean()[0]/10.;
00067     value[1][0] = anal->amplitudeMean()[1]/10.;
00068     error[0][0] = anal->amplitudeSpread()[0]/10.;
00069     error[1][0] = anal->amplitudeSpread()[1]/10.;
00070   } else if ( mon_ == sistrip::CALIBRATION_AMPLITUDE_MIN) {
00071     value[0][0] = anal->amplitudeMin()[0]/10.;
00072     value[1][0] = anal->amplitudeMin()[1]/10.;
00073   } else if ( mon_ == sistrip::CALIBRATION_AMPLITUDE_MAX) {
00074     value[0][0] = anal->amplitudeMax()[0]/10.;
00075     value[1][0] = anal->amplitudeMax()[1]/10.;
00076   } else if ( mon_ == sistrip::CALIBRATION_TAIL_ALLSTRIPS) {
00077     all_strips = true;
00078     uint16_t bins = tail[tail[0].size() < tail[1].size() ? 1 : 0].size();
00079     for ( uint16_t i = 0; i < bins; i++ ) {
00080       value[0][i] = tail[0][i];
00081       value[1][i] = tail[1][i];
00082     }
00083   } else if ( mon_ == sistrip::CALIBRATION_TAIL) {
00084     with_error = true;
00085     value[0][0] = anal->tailMean()[0];
00086     value[1][0] = anal->tailMean()[1];
00087     error[0][0] = anal->tailSpread()[0];
00088     error[1][0] = anal->tailSpread()[1];
00089   } else if ( mon_ == sistrip::CALIBRATION_TAIL_MIN) {
00090     value[0][0] = anal->tailMin()[0];
00091     value[1][0] = anal->tailMin()[1];
00092   } else if ( mon_ == sistrip::CALIBRATION_TAIL_MAX) {
00093     value[0][0] = anal->tailMax()[0];
00094     value[1][0] = anal->tailMax()[1];
00095   } else if ( mon_ == sistrip::CALIBRATION_RISETIME_ALLSTRIPS) {
00096     all_strips = true;
00097     uint16_t bins = riseTime[riseTime[0].size() < riseTime[1].size() ? 1 : 0].size();
00098     for ( uint16_t i = 0; i < bins; i++ ) {
00099       value[0][i] = riseTime[0][i];
00100       value[1][i] = riseTime[1][i];
00101     }
00102   } else if ( mon_ == sistrip::CALIBRATION_RISETIME) {
00103     with_error = true;
00104     value[0][0] = anal->riseTimeMean()[0];
00105     value[1][0] = anal->riseTimeMean()[1];
00106     error[0][0] = anal->riseTimeSpread()[0];
00107     error[1][0] = anal->riseTimeSpread()[1];
00108   } else if ( mon_ == sistrip::CALIBRATION_RISETIME_MIN) {
00109     value[0][0] = anal->riseTimeMin()[0];
00110     value[1][0] = anal->riseTimeMin()[1];
00111   } else if ( mon_ == sistrip::CALIBRATION_RISETIME_MAX) {
00112     value[0][0] = anal->riseTimeMax()[0];
00113     value[1][0] = anal->riseTimeMax()[1];
00114   } else if ( mon_ == sistrip::CALIBRATION_TIMECONSTANT_ALLSTRIPS) {
00115     all_strips = true;
00116     uint16_t bins = timeConstant[timeConstant[0].size() < timeConstant[1].size() ? 1 : 0].size();
00117     for ( uint16_t i = 0; i < bins; i++ ) {
00118       value[0][i] = timeConstant[0][i];
00119       value[1][i] = timeConstant[1][i];
00120     }
00121   } else if ( mon_ == sistrip::CALIBRATION_TIMECONSTANT) {
00122     with_error = true;
00123     value[0][0] = anal->timeConstantMean()[0];
00124     value[1][0] = anal->timeConstantMean()[1];
00125     error[0][0] = anal->timeConstantSpread()[0];
00126     error[1][0] = anal->timeConstantSpread()[1];
00127   } else if ( mon_ == sistrip::CALIBRATION_TIMECONSTANT_MIN) {
00128     value[0][0] = anal->timeConstantMin()[0];
00129     value[1][0] = anal->timeConstantMin()[1];
00130   } else if ( mon_ == sistrip::CALIBRATION_TIMECONSTANT_MAX) {
00131     value[0][0] = anal->timeConstantMax()[0];
00132     value[1][0] = anal->timeConstantMax()[1];
00133   } else if ( mon_ == sistrip::CALIBRATION_SMEARING_ALLSTRIPS) {
00134     all_strips = true;
00135     uint16_t bins = smearing[smearing[0].size() < smearing[1].size() ? 1 : 0].size();
00136     for ( uint16_t i = 0; i < bins; i++ ) {
00137       value[0][i] = smearing[0][i];
00138       value[1][i] = smearing[1][i];
00139     }
00140   } else if ( mon_ == sistrip::CALIBRATION_SMEARING) {
00141     with_error = true;
00142     value[0][0] = anal->smearingMean()[0];
00143     value[1][0] = anal->smearingMean()[1];
00144     error[0][0] = anal->smearingSpread()[0];
00145     error[1][0] = anal->smearingSpread()[1];
00146   } else if ( mon_ == sistrip::CALIBRATION_SMEARING_MIN) {
00147     value[0][0] = anal->smearingMin()[0];
00148     value[1][0] = anal->smearingMin()[1];
00149   } else if ( mon_ == sistrip::CALIBRATION_SMEARING_MAX) {
00150     value[0][0] = anal->smearingMax()[0];
00151     value[1][0] = anal->smearingMax()[1];
00152   } else if ( mon_ == sistrip::CALIBRATION_CHI2_ALLSTRIPS) {
00153     all_strips = true;
00154     uint16_t bins = chi2[chi2[0].size() < chi2[1].size() ? 1 : 0].size();
00155     for ( uint16_t i = 0; i < bins; i++ ) {
00156       value[0][i] = chi2[0][i];
00157       value[1][i] = chi2[1][i];
00158     }
00159   } else if ( mon_ == sistrip::CALIBRATION_CHI2) {
00160     with_error = true;
00161     value[0][0] = anal->chi2Mean()[0]/100.;
00162     value[1][0] = anal->chi2Mean()[1]/100.;
00163     error[0][0] = anal->chi2Spread()[0]/100.;
00164     error[1][0] = anal->chi2Spread()[1]/100.;
00165   } else if ( mon_ == sistrip::CALIBRATION_CHI2_MIN) {
00166     value[0][0] = anal->chi2Min()[0]/100.;
00167     value[1][0] = anal->chi2Min()[1]/100.;
00168   } else if ( mon_ == sistrip::CALIBRATION_CHI2_MAX) {
00169     value[0][0] = anal->chi2Max()[0]/100.;
00170     value[1][0] = anal->chi2Max()[1]/100.;
00171   } else { 
00172     edm::LogWarning(mlSummaryPlots_)
00173         << "[SummaryPlotFactory::" << __func__ << "]"
00174         << " Unexpected monitorable: "
00175         << SiStripEnumsAndStrings::monitorable( SummaryPlotFactoryBase::mon_ );
00176     return; 
00177   }
00178 
00179   if ( !all_strips ) {
00180     if( !with_error) {
00181       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00182                                                    SummaryPlotFactoryBase::gran_,
00183                                                    key1,
00184                                                    value[0][0] );
00185                                                  
00186       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00187                                                    SummaryPlotFactoryBase::gran_,
00188                                                    key2,
00189                                                    value[1][0] );
00190     } else {
00191       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00192                                                    SummaryPlotFactoryBase::gran_,
00193                                                    key1,
00194                                                    value[0][0],
00195                                                    error[0][0]);
00196                                                  
00197       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00198                                                    SummaryPlotFactoryBase::gran_,
00199                                                    key2,
00200                                                    value[1][0],
00201                                                    error[1][0]);
00202     }
00203   } else {
00204     
00205     for ( uint16_t istr = 0; istr < value[0].size(); istr++ ) {
00206       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00207                                                    SummaryPlotFactoryBase::gran_,
00208                                                    key1,
00209                                                    value[0][istr] );
00210     }
00211     
00212     for ( uint16_t istr = 0; istr < value[1].size(); istr++ ) {
00213       SummaryPlotFactoryBase::generator_->fillMap( SummaryPlotFactoryBase::level_,
00214                                                    SummaryPlotFactoryBase::gran_,
00215                                                    key2,
00216                                                    value[1][istr] );
00217     }
00218   }
00219 }
00220 
00221 //------------------------------------------------------------------------------
00222 //
00223 void CalibrationSummaryFactory::format() {
00224 
00225   // Histogram formatting
00226   if ( mon_ == sistrip::CALIBRATION_AMPLITUDE ) {
00227     generator_->axisLabel( "Amplitude (ADC*Nevt/10.)" );
00228   } else if ( mon_ == sistrip::CALIBRATION_TAIL ) { 
00229     generator_->axisLabel( "Tail (%)" );
00230   } else if ( mon_ == sistrip::CALIBRATION_RISETIME ) { 
00231     generator_->axisLabel( "Rise time (ns)" );
00232   } else if ( mon_ == sistrip::CALIBRATION_TIMECONSTANT ) { 
00233     generator_->axisLabel( "Time constant (ns)" );
00234   } else if ( mon_ == sistrip::CALIBRATION_SMEARING ) { 
00235     generator_->axisLabel( "Smearing (ns)" );
00236   } else if ( mon_ == sistrip::CALIBRATION_CHI2 ) { 
00237     generator_->axisLabel( "Chi2/100." );
00238   } else { 
00239     edm::LogWarning(mlSummaryPlots_) 
00240          << "[SummaryPlotFactory::" << __func__ << "]"
00241          <<  " Unexpected SummaryHisto value:"
00242          << SiStripEnumsAndStrings::monitorable( SummaryPlotFactoryBase::mon_ ) ;
00243   } 
00244   
00245 }
00246