CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes

ESTrendTask Class Reference

#include <ESTrendTask.h>

Inheritance diagram for ESTrendTask:
edm::EDAnalyzer

List of all members.

Public Member Functions

 ESTrendTask (const edm::ParameterSet &ps)
virtual ~ESTrendTask ()

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c)
void beginJob (void)
void beginRun (const edm::Run &r, const edm::EventSetup &c)
void cleanup (void)
void endJob (void)
void endRun (const edm::Run &r, const edm::EventSetup &c)
void reset (void)
void setup (void)
void shift2Left (TProfile *p, int bins=1)
void shift2Right (TProfile *p, int bins=1)
void updateTime (const edm::Event &)

Private Attributes

long int current_time_
edm::InputTag dccCollections_
DQMStoredqmStore_
bool enableCleanup_
MonitorElementhESFiberErrTrend_
MonitorElementhESFiberErrTrendHr_
MonitorElementhESRecHitTrend_ [2][2]
MonitorElementhESRecHitTrendHr_ [2][2]
MonitorElementhESSLinkErrTrend_
MonitorElementhESSLinkErrTrendHr_
int ievt_
bool init_
long int last_time_
bool mergeRuns_
std::string prefixME_
edm::InputTag rechitlabel_
long int start_time_

Detailed Description

Definition at line 13 of file ESTrendTask.h.


Constructor & Destructor Documentation

ESTrendTask::ESTrendTask ( const edm::ParameterSet ps)

Definition at line 25 of file ESTrendTask.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, j, and cppFunctionSkipper::operator.

                                               {

  init_ = false;

  dqmStore_ = Service<DQMStore>().operator->();

  prefixME_       = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower"); 
  enableCleanup_  = ps.getUntrackedParameter<bool>("enableCleanup", false);
  mergeRuns_      = ps.getUntrackedParameter<bool>("mergeRuns", false);
  rechitlabel_    = ps.getParameter<InputTag>("RecHitLabel");
  dccCollections_ = ps.getParameter<InputTag>("ESDCCCollections");

  for (int i=0; i<2; ++i)
    for (int j=0; j<2; ++j) {
      hESRecHitTrend_[i][j] = 0;
      hESRecHitTrendHr_[i][j] = 0;
    }

  hESSLinkErrTrend_ = 0;
  hESFiberErrTrend_ = 0;
  hESSLinkErrTrendHr_ = 0;
  hESFiberErrTrendHr_ = 0;

  start_time_ = 0;
  current_time_ = 0;
  last_time_ = 0;

}
ESTrendTask::~ESTrendTask ( ) [virtual]

Definition at line 54 of file ESTrendTask.cc.

                          {
}

Member Function Documentation

void ESTrendTask::analyze ( const edm::Event e,
const edm::EventSetup c 
) [protected, virtual]

Implements edm::EDAnalyzer.

Definition at line 180 of file ESTrendTask.cc.

References edm::Event::getByLabel(), ESDCCHeaderBlock::getDCCErrors(), ESDCCHeaderBlock::getFEChannelStatus(), getTProfile(), i, j, HcalObjRepresent::setup(), ecaldqm::shift2Right(), and ESDetId::zside().

                                                             {

  if ( ! init_ ) this->setup();

  ievt_++;

  // Collect time information
  updateTime(e);

  long int diff_current_start = current_time_ - start_time_;
  long int diff_last_start    = last_time_ - start_time_;
  //LogInfo("ESTrendTask") << "time difference is negative in " << ievt_ << " events\n"
  //<< "\tcurrent - start time = " << diff_current_start
  //<< ", \tlast - start time = " << diff_last_start << endl;

  //  std::cout << "current_time : " << current_time_ << ", diff : " << diff_current_start << std::endl;

  // Calculate time interval and bin width
  //  int minuteBinWidth = int(nBasicClusterMinutely_->getTProfile()->GetXaxis()->GetBinWidth(1));
  int minuteBinWidth = 5;
  long int minuteBinDiff = diff_current_start/60/minuteBinWidth - diff_last_start/60/minuteBinWidth;
  long int minuteDiff = (current_time_ - last_time_)/60;

  //  int hourBinWidth = int(nBasicClusterHourly_->getTProfile()->GetXaxis()->GetBinWidth(1));
  int hourBinWidth = 1;
  long int hourBinDiff = diff_current_start/3600/hourBinWidth - diff_last_start/3600/hourBinWidth;
  long int hourDiff = (current_time_ - last_time_)/3600;

  if (minuteDiff >= minuteBinWidth) {
    while (minuteDiff >= minuteBinWidth) minuteDiff -= minuteBinWidth;
  }
  if (hourDiff >= hourBinWidth) {
    while (hourDiff >= hourBinWidth) hourDiff -= hourBinWidth;
  }

  // ES DCC
  Int_t slinkCRCErr = 0;
  Int_t fiberErr = 0;
  vector<int> fiberStatus;
  Handle<ESRawDataCollection> dccs;
  if ( e.getByLabel(dccCollections_, dccs) ) {
    for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
      ESDCCHeaderBlock dcc = (*dccItr);

      if (dcc.getDCCErrors() == 101) slinkCRCErr++;

      fiberStatus = dcc.getFEChannelStatus();
      for (unsigned int i=0; i<fiberStatus.size(); ++i) {
        if (fiberStatus[i]==4 || fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12)
          fiberErr++;
      }
      
    }
  }

  shift2Right(hESSLinkErrTrend_->getTProfile(), minuteBinDiff);
  hESSLinkErrTrend_->Fill(minuteDiff, slinkCRCErr);

  shift2Right(hESFiberErrTrend_->getTProfile(), minuteBinDiff);
  hESFiberErrTrend_->Fill(minuteDiff, fiberErr);

  shift2Right(hESSLinkErrTrendHr_->getTProfile(), hourBinDiff);
  hESSLinkErrTrendHr_->Fill(hourDiff, slinkCRCErr);

  shift2Right(hESFiberErrTrendHr_->getTProfile(), hourBinDiff);
  hESFiberErrTrendHr_->Fill(hourDiff, fiberErr);

  // ES RecHits
  int zside, plane;
  int nrh[2][2];
  for (int i = 0; i < 2; i++ ) 
    for( int j = 0; j < 2; j++) {
      nrh[i][j] = 0;
    }

  Handle<EcalRecHitCollection> ESRecHit;
  if ( e.getByLabel(rechitlabel_, ESRecHit) ) {
    
    for (ESRecHitCollection::const_iterator hitItr = ESRecHit->begin(); hitItr != ESRecHit->end(); ++hitItr) {
      
      ESDetId id = ESDetId(hitItr->id());
      
      zside = id.zside();
      plane = id.plane();
      
      int i = (zside==1)? 0:1;
      int j = plane-1;
      
      nrh[i][j]++;
    }
  } else {
    LogWarning("ESTrendTask") << rechitlabel_ << " not available";
  }
  
  for (int i=0; i<2; ++i) 
    for (int j=0; j<2; ++j) {
      shift2Right(hESRecHitTrend_[i][j]->getTProfile(), minuteBinDiff);
      hESRecHitTrend_[i][j]->Fill(minuteDiff, nrh[i][j]/(1072*32.));

      shift2Right(hESRecHitTrendHr_[i][j]->getTProfile(), hourBinDiff);
      hESRecHitTrendHr_[i][j]->Fill(hourDiff, nrh[i][j]/(1072*32.));
    }

}
void ESTrendTask::beginJob ( void  ) [protected, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 57 of file ESTrendTask.cc.

                               {

  ievt_ = 0;

  if ( dqmStore_ ) {
    dqmStore_->setCurrentFolder(prefixME_ + "/ESTrendTask");
    dqmStore_->rmdir(prefixME_ + "/ESTrendTask");
  }

}
void ESTrendTask::beginRun ( const edm::Run r,
const edm::EventSetup c 
) [protected, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 68 of file ESTrendTask.cc.

References edm::RunBase::beginTime(), and reset().

                                                            {

  if ( ! mergeRuns_ ) this->reset();

  start_time_ = (r.beginTime()).unixTime();

  //std::cout << "start time : " << start_time_ << std::endl;

}
void ESTrendTask::cleanup ( void  ) [protected]
void ESTrendTask::endJob ( void  ) [protected, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 172 of file ESTrendTask.cc.

References edm::cleanup().

                             {

  LogInfo("ESTrendTask") << "analyzed " << ievt_ << " events";

  if ( enableCleanup_ ) this->cleanup();

}
void ESTrendTask::endRun ( const edm::Run r,
const edm::EventSetup c 
) [protected, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 78 of file ESTrendTask.cc.

                                                          {

}
void ESTrendTask::reset ( void  ) [protected]

Definition at line 82 of file ESTrendTask.cc.

References i, and j.

void ESTrendTask::setup ( void  ) [protected]

Definition at line 97 of file ESTrendTask.cc.

References timingPdfMaker::histo, i, and j.

                            {

  init_ = true;

  char histo[200];

  if ( dqmStore_ ) {
    dqmStore_->setCurrentFolder(prefixME_ + "/ESTrendTask");

    for (int i=0 ; i<2; ++i)  
      for (int j=0 ; j<2; ++j) {
        int iz = (i==0)? 1:-1;
        sprintf(histo, "ES Trending RH Occ per 5 mins Z %d P %d", iz, j+1);
        hESRecHitTrend_[i][j] = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
        hESRecHitTrend_[i][j]->setAxisTitle("Elapse time (Minutes)", 1);
        hESRecHitTrend_[i][j]->setAxisTitle("ES RecHit Occupancy / 5 minutes", 2);

        sprintf(histo, "ES Trending RH Occ per hour Z %d P %d", iz, j+1);
        hESRecHitTrendHr_[i][j] = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
        hESRecHitTrendHr_[i][j]->setAxisTitle("Elapse time (Hours)", 1);
        hESRecHitTrendHr_[i][j]->setAxisTitle("ES RecHit Occupancy / hour", 2);
      }

    sprintf(histo, "ES Trending SLink CRC Error per 5 mins");
    hESSLinkErrTrend_ = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
    hESSLinkErrTrend_->setAxisTitle("Elapse time (Minutes)", 1);
    hESSLinkErrTrend_->setAxisTitle("ES SLink CRC Err / 5 minutes", 2);

    sprintf(histo, "ES Trending Fiber Error per 5 mins");
    hESFiberErrTrend_ = dqmStore_->bookProfile(histo, histo, 36, 0.0, 180.0, 100, 0.0, 1.0e6, "s");
    hESFiberErrTrend_->setAxisTitle("Elapse time (Minutes)", 1);
    hESFiberErrTrend_->setAxisTitle("ES Fiber Err / 5 minutes", 2);

    sprintf(histo, "ES Trending SLink CRC Error per hour");
    hESSLinkErrTrendHr_ = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
    hESSLinkErrTrendHr_->setAxisTitle("Elapse time (Hours)", 1);
    hESSLinkErrTrendHr_->setAxisTitle("ES SLink CRC Err / hour", 2);

    sprintf(histo, "ES Trending Fiber Error per hour");
    hESFiberErrTrendHr_ = dqmStore_->bookProfile(histo, histo, 24, 0.0, 24.0, 100, 0.0, 1.0e6, "s");
    hESFiberErrTrendHr_->setAxisTitle("Elapse time (Hours)", 1);
    hESFiberErrTrendHr_->setAxisTitle("ES Fiber Err / hour", 2);
  }

}
void ESTrendTask::shift2Left ( TProfile *  p,
int  bins = 1 
) [protected]

Definition at line 319 of file ESTrendTask.cc.

References i.

                                                  {

  if(bins <= 0) return;

  if(!p->GetSumw2()) p->Sumw2();
  int nBins = p->GetXaxis()->GetNbins();

  // by shifting n bin to the left, the number of entries are
  // reduced by the number in n bins including the underflow bin.
  double nentries = p->GetEntries();
  for(int i=0; i<bins; i++) nentries -= p->GetBinEntries(i);
  p->SetEntries(nentries);
  
  // the first bin goes to underflow
  // each bin moves to the right

  TArrayD* sumw2 = p->GetSumw2();

  for(int i=0; i<=nBins+1-bins; i++) {
    // GetBinContent return binContent/binEntries
    p->SetBinContent(i, p->GetBinContent(i+bins)*p->GetBinEntries(i+bins));
    p->SetBinEntries(i,p->GetBinEntries(i+bins));
    sumw2->SetAt(sumw2->GetAt(i+bins),i);
  }

}
void ESTrendTask::shift2Right ( TProfile *  p,
int  bins = 1 
) [protected]

Definition at line 292 of file ESTrendTask.cc.

References i.

                                                   {

  if(bins <= 0) return;

  if(!p->GetSumw2()) p->Sumw2();
  int nBins = p->GetXaxis()->GetNbins();

  // by shifting n bin to the right, the number of entries are
  // reduced by the number in n bins including the overflow bin.
  double nentries = p->GetEntries();
  for(int i=0; i<bins; i++) nentries -= p->GetBinEntries(nBins+1-bins);
  p->SetEntries(nentries);
  
  // the last bin goes to overflow
  // each bin moves to the right

  TArrayD* sumw2 = p->GetSumw2();

  for(int i=nBins+1; i>bins; i--) {
    // GetBinContent return binContent/binEntries
    p->SetBinContent(i, p->GetBinContent(i-bins)*p->GetBinEntries(i-bins));
    p->SetBinEntries(i,p->GetBinEntries(i-bins));
    sumw2->SetAt(sumw2->GetAt(i-bins),i);
  }

}
void ESTrendTask::updateTime ( const edm::Event e) [protected]

Member Data Documentation

long int ESTrendTask::current_time_ [private]

Definition at line 84 of file ESTrendTask.h.

Definition at line 71 of file ESTrendTask.h.

Definition at line 62 of file ESTrendTask.h.

Definition at line 66 of file ESTrendTask.h.

Definition at line 75 of file ESTrendTask.h.

Definition at line 79 of file ESTrendTask.h.

Definition at line 73 of file ESTrendTask.h.

Definition at line 77 of file ESTrendTask.h.

Definition at line 74 of file ESTrendTask.h.

Definition at line 78 of file ESTrendTask.h.

int ESTrendTask::ievt_ [private]

Definition at line 60 of file ESTrendTask.h.

bool ESTrendTask::init_ [private]

Definition at line 81 of file ESTrendTask.h.

long int ESTrendTask::last_time_ [private]

Definition at line 85 of file ESTrendTask.h.

bool ESTrendTask::mergeRuns_ [private]

Definition at line 68 of file ESTrendTask.h.

std::string ESTrendTask::prefixME_ [private]

Definition at line 64 of file ESTrendTask.h.

Definition at line 70 of file ESTrendTask.h.

long int ESTrendTask::start_time_ [private]

Definition at line 83 of file ESTrendTask.h.