CMS 3D CMS Logo

Functions

ecaldqm Namespace Reference

Functions

void calcBins (int binWidth, int divisor, long int start_time, long int last_time, long int current_time, long int &binDiff, long int &diff)
TObject * cloneIt (MonitorElement *me, std::string histo)
void getAverageFromTProfile (TProfile *p, double &mean, double &rms)
void getMeanRms (TObject *pre, TObject *cur, double &mean, double &rms)
void shift2Left (TProfile *p, int bins)
void shift2Right (TProfile *p, int bins)

Function Documentation

void ecaldqm::calcBins ( int  binWidth,
int  divisor,
long int  start_time,
long int  last_time,
long int  current_time,
long int &  binDiff,
long int &  diff 
)

Definition at line 28 of file UtilFunctions.h.

References evf::utils::start_time.

Referenced by EBTrendTask::analyze(), EETrendClient::analyze(), EETrendTask::analyze(), and EBTrendClient::analyze().

                                                     {

    // changing arguments : binDiff, diff

    // binWidth : time interval
    // divisor : time unit - for minute case divisor is 60 and for hour case 3600
    // start_time : initial time when the job started
    // last_time : the last updated time before calling the current "analyze" function
    // current_time : the current time inside "analyze" fucntion
    // binDiff : the bin difference for the current time compared to the bin location of the last time
    // diff : time difference between the current time and the last time

    long int diff_current_start = current_time - start_time;
    long int diff_last_start = last_time - start_time;

    // --------------------------------------------------
    // Calculate time interval and bin width
    // --------------------------------------------------

    binDiff = diff_current_start/divisor/binWidth - diff_last_start/divisor/binWidth;
    diff = (current_time - last_time)/divisor;

    if(diff >= binWidth) {
      while(diff >= binWidth) diff -= binWidth;
    }

  } // calcBins
TObject* ecaldqm::cloneIt ( MonitorElement me,
std::string  histo 
)

Definition at line 186 of file UtilFunctions.h.

References MonitorElement::getRootObject(), runTheMatrix::ret, and indexGen::title.

Referenced by EETrendClient::analyze(), and EBTrendClient::analyze().

                                                        {

    // The cloned object, ret should be deleted after using it.

    TObject* ret = 0;

    if(!me) return ret;

    std::string title = histo + " Clone";
    ret = (TObject*) (me->getRootObject()->Clone(title.c_str()));

    return ret;
  }
void ecaldqm::getAverageFromTProfile ( TProfile *  p,
double &  mean,
double &  rms 
)

Definition at line 123 of file UtilFunctions.h.

References i, RecoTauCommonJetSelections_cfi::nbins, mathSSE::sqrt(), and detailsBasic3DVector::y.

Referenced by getMeanRms().

                                                                      {

    // changing arguments : mean, rms
    mean = rms = 0.0;

    if(!p) return;

    int nbins = p->GetXaxis()->GetNbins();
    double y = 0.0;
    double y2 = 0.0;
    for(int i=1; i<=nbins; i++){
      y += p->GetBinContent(i);
      y2 += y*y;
    }
    mean = y/nbins;
    rms = std::sqrt(y2/nbins - mean*mean);

  } // getAverageFromTProfile
void ecaldqm::getMeanRms ( TObject *  pre,
TObject *  cur,
double &  mean,
double &  rms 
)

Definition at line 145 of file UtilFunctions.h.

References getAverageFromTProfile(), mergeVDriftHistosByStation::name, and mathSSE::sqrt().

Referenced by EETrendClient::analyze(), and EBTrendClient::analyze().

                                                                         {

    // changing arguments : mean, rms

    mean = rms = 0.0;

    if(!cur) return;

    TString name(cur->IsA()->GetName());

    if(name.Contains("TProfile")) {
      getAverageFromTProfile((TProfile*)cur,mean,rms);
    }
    else if(name.Contains("TH2")) {
      if(pre) {
        mean = ((TH2F*)cur)->GetEntries() - ((TH2F*)pre)->GetEntries();
        rms = std::sqrt(mean);
      }
      else {
        mean = ((TH2F*)cur)->GetEntries();
        rms = std::sqrt(mean);
      }
      float nxybins = ((TH2F*)cur)->GetNbinsX()*((TH2F*)cur)->GetNbinsY();
      mean /= nxybins;
      rms /= nxybins;
    }
    else if(name.Contains("TH1")) {
      if(pre) {
        ((TH1F*)pre)->Sumw2();
        ((TH1F*)pre)->Add((TH1F*)pre,(TH1F*)cur,-1,1);
        mean = ((TH1F*)pre)->GetMean();
        rms = ((TH1F*)pre)->GetRMS();
      }
      else {
        mean = ((TH1F*)cur)->GetMean();
        rms = ((TH1F*)cur)->GetRMS();
      }
    }

  } // getMeanRms
void ecaldqm::shift2Left ( TProfile *  p,
int  bins 
)

Definition at line 93 of file UtilFunctions.h.

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 ecaldqm::shift2Right ( TProfile *  p,
int  bins 
)

Definition at line 61 of file UtilFunctions.h.

References i.

Referenced by EBTrendTask::analyze(), EETrendClient::analyze(), EETrendTask::analyze(), ESTrendTask::analyze(), and EBTrendClient::analyze().

                                         {

    // bins : how many bins need to be shifted

    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(i);
    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);
    }
    
  }