CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQM/EcalCommon/src/MESetTrend.cc

Go to the documentation of this file.
00001 #include "DQM/EcalCommon/interface/MESetTrend.h"
00002 
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 namespace ecaldqm {
00006 
00007   MESetTrend::MESetTrend(std::string const& _fullpath, MEData const& _data, bool _readOnly/* = false*/) :
00008     MESetEcal(_fullpath, _data, 1, _readOnly),
00009     t0_(0),
00010     minutely_(false),
00011     tLow_(0)
00012   {
00013     if(!_data.xaxis || _data.xaxis->edges)
00014       throw cms::Exception("InvalidConfiguration") << "MESetTrend";
00015   }
00016 
00017   MESetTrend::~MESetTrend()
00018   {
00019   }
00020 
00021   void
00022   MESetTrend::book()
00023   {
00024     int conversion(minutely_ ? 60 : 3600);
00025     time_t width((data_->xaxis->high - data_->xaxis->low) * conversion);
00026 
00027     tLow_ = t0_;
00028 
00029     MEData const* temp(data_);
00030     BinService::AxisSpecs xaxis(*temp->xaxis);
00031     xaxis.low = tLow_;
00032     xaxis.high = tLow_ + width;
00033 
00034     data_ = new MEData(temp->pathName, temp->otype, temp->btype, temp->kind, &xaxis, temp->yaxis, temp->zaxis);
00035 
00036     MESetEcal::book();
00037 
00038     delete data_;
00039     data_ = temp;
00040 
00041     // if yaxis was variable bin size, xaxis will be booked as variable too
00042 
00043     for(unsigned iME(0); iME < mes_.size(); iME++){
00044       TAxis* axis(mes_[iME]->getTH1()->GetXaxis());
00045       if(axis->IsVariableBinSize())
00046         axis->Set(data_->xaxis->nbins, data_->xaxis->low, data_->xaxis->high);
00047     }
00048   }
00049 
00050   void
00051   MESetTrend::fill(DetId const& _id, double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
00052   {
00053     if(!active_) return;
00054 
00055     unsigned offset(binService_->findOffset(data_->otype, _id));
00056 
00057     if(shift_(time_t(_t)))
00058       MESet::fill_(offset, _t, _wy, _w);
00059   }
00060 
00061   void
00062   MESetTrend::fill(unsigned _dcctccid, double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
00063   {
00064     if(!active_) return;
00065 
00066     unsigned offset(binService_->findOffset(data_->otype, data_->btype, _dcctccid));
00067 
00068     if(shift_(time_t(_t)))
00069       MESet::fill_(offset, _t, _wy, _w);
00070   }
00071 
00072   void
00073   MESetTrend::fill(double _t, double _wy/* = 1.*/, double _w/* = 1.*/)
00074   {
00075     if(!active_) return;
00076     if(mes_.size() != 1)
00077       throw cms::Exception("InvalidCall") << "MESet type incompatible" << std::endl;
00078 
00079     if(shift_(time_t(_t)))
00080       MESet::fill_(0, _t, _wy, _w);
00081   }
00082 
00083   bool
00084   MESetTrend::shift_(time_t _t)
00085   {
00086     int conversion(minutely_ ? 60 : 3600);
00087     time_t width((data_->xaxis->high - data_->xaxis->low) * conversion);
00088 
00089     time_t tHigh(tLow_ + width);
00090     int nbinsX(data_->xaxis->nbins);
00091     MonitorElement::Kind kind(data_->kind);
00092 
00093     int dtPerBin(width / nbinsX);
00094     int dBin(0);
00095 
00096     if(_t >= tLow_ && _t < tHigh)
00097       return true;
00098     else if(_t >= tHigh)
00099       dBin = (_t - tHigh) / dtPerBin + 1;
00100     else if(_t < tLow_){
00101       int maxBin(0);
00102 
00103       for(unsigned iME(0); iME < mes_.size(); iME++){
00104         MonitorElement* me(mes_[iME]);
00105 
00106         bool filled(false);
00107         int iMax(nbinsX + 1);
00108         while(--iMax > 0 && !filled){
00109           switch(kind){
00110           case  MonitorElement::DQM_KIND_TH1F:
00111             if(me->getBinContent(iMax) != 0) filled = true;
00112             break;
00113           case MonitorElement::DQM_KIND_TPROFILE:
00114             if(me->getBinEntries(iMax) != 0) filled = true;
00115             break;
00116           case MonitorElement::DQM_KIND_TH2F:
00117             for(int iy(1); iy <= me->getNbinsY(); iy++)
00118               if(me->getBinContent(iMax, iy) != 0) filled = true;
00119             break;
00120           default:
00121             return false;
00122           }
00123         }
00124 
00125         if(iMax > maxBin) maxBin = iMax;
00126       }
00127 
00128       if(_t < tLow_ - (nbinsX - maxBin) * dtPerBin) return false;
00129 
00130       dBin = (_t - dtPerBin - tLow_) / dtPerBin;
00131     }
00132 
00133     int start(dBin > 0 ? dBin + 1 : nbinsX + dBin);
00134     int end(dBin > 0 ? nbinsX + 1 : 0);
00135     int step(dBin > 0 ? 1 : -1);
00136 
00137     tLow_ += dBin * dtPerBin;
00138     tHigh += dBin * dtPerBin;
00139 
00140     for(unsigned iME(0); iME < mes_.size(); iME++){
00141       MonitorElement* me(mes_[iME]);
00142 
00143       me->setEntries(0.);
00144 
00145       double entries(0.);
00146 
00147       for(int ix(start); (dBin > 0 ? (ix < end) : (ix > end)); ix += step){
00148         switch(kind){
00149         case  MonitorElement::DQM_KIND_TH1F:
00150           entries += me->getBinContent(ix);
00151           me->setBinContent(ix - dBin, me->getBinContent(ix));
00152           me->setBinError(ix - dBin, me->getBinError(ix));
00153           me->setBinContent(ix, 0.);
00154           me->setBinError(ix, 0.);
00155           break;
00156         case MonitorElement::DQM_KIND_TPROFILE:
00157           entries += me->getBinEntries(ix);
00158           me->setBinEntries(ix - dBin, me->getBinEntries(ix));
00159           me->setBinContent(ix - dBin, me->getBinContent(ix) * me->getBinEntries(ix));
00160           if(me->getBinEntries(ix) > 0){
00161             double rms(me->getBinError(ix) * std::sqrt(me->getBinEntries(ix)));
00162             double sumw2((rms * rms + me->getBinContent(ix) * me->getBinContent(ix)) * me->getBinEntries(ix));
00163             me->setBinError(ix - dBin, std::sqrt(sumw2));
00164           }
00165           me->setBinEntries(ix, 0.);
00166           me->setBinContent(ix, 0.);
00167           me->setBinError(ix, 0.);
00168           break;
00169         case MonitorElement::DQM_KIND_TH2F:
00170           for(int iy(1); iy <= me->getNbinsY(); iy++){
00171             int orig(me->getTH1()->GetBin(ix, iy));
00172             int dest(me->getTH1()->GetBin(ix - dBin, iy));
00173             entries += me->getBinContent(orig);
00174             me->setBinContent(dest, me->getBinContent(orig));
00175             me->setBinError(dest, me->getBinError(orig));
00176             me->setBinContent(orig, 0.);
00177             me->setBinError(orig, 0.);
00178           }
00179           break;
00180         default:
00181           break;
00182         }
00183       }
00184 
00185       me->setEntries(entries);
00186       me->getTH1()->GetXaxis()->SetLimits(tLow_, tHigh);
00187     }
00188 
00189     return true;
00190   }
00191 
00192 }