CMS 3D CMS Logo

Public Member Functions | Private Attributes

L1TOccupancyClientHistogramService Class Reference

#include <L1TOccupancyClientHistogramService.h>

List of all members.

Public Member Functions

TH2F * getDifferentialHistogram (std::string test)
std::vector< int > getLSCertification (std::string iHistName)
std::vector< std::pair< int,
int > > 
getMaskedBins (std::string test)
unsigned int getNBinsHistogram (std::string test)
unsigned int getNBinsMasked (std::string test)
TH2F * getRebinnedHistogram (std::string iHistName, std::string iHistLocation)
bool isMasked (std::string test, int x, int y)
bool isStripMasked (std::string test, int binStrip, int axis)
 L1TOccupancyClientHistogramService ()
 L1TOccupancyClientHistogramService (edm::ParameterSet iParameters, DQMStore *iDBE, bool iVerbose)
TH2F * loadHisto (std::string test, std::string histo)
int maskBins (std::string test, TH2F *histo, int strip, int axis)
void resetHisto (std::string test)
void setMaskedBins (std::string test, std::vector< edm::ParameterSet > mask)
void updateHistogramEndLS (std::string test, std::string histo, int iLS)
void updateHistogramEndRun (std::string iHistName)

Private Attributes

DQMStoremDBE
std::map< std::string, TH2F * > mHistDiffMinus1
std::map< std::string,
std::pair< TH2F *, TH2F * > > 
mHistograms
std::map< std::string, bool > mHistValid
std::map< std::string,
std::vector< int > > 
mLSListDiff
std::map< std::string,
std::vector< int > > 
mLSListDiffMinus1
std::map< std::string,
std::vector< std::pair< int,
int > > * > 
mMaskedBins
edm::ParameterSet mParameters
bool mVerbose

Detailed Description

Definition at line 23 of file L1TOccupancyClientHistogramService.h.


Constructor & Destructor Documentation

L1TOccupancyClientHistogramService::L1TOccupancyClientHistogramService ( )

Definition at line 20 of file L1TOccupancyClientHistogramService.cc.

{}
L1TOccupancyClientHistogramService::L1TOccupancyClientHistogramService ( edm::ParameterSet  iParameters,
DQMStore iDBE,
bool  iVerbose 
)

Definition at line 30 of file L1TOccupancyClientHistogramService.cc.

                                                                                                                              {
  mDBE        = iDBE;
  mVerbose    = iVerbose;
  mParameters = iParameters;
}

Member Function Documentation

TH2F * L1TOccupancyClientHistogramService::getDifferentialHistogram ( std::string  test)

Definition at line 440 of file L1TOccupancyClientHistogramService.cc.

                                                                                   {  
  if(mHistValid[iHistName]){return mHistograms[iHistName].second;}
  return 0;
}                                            
vector< int > L1TOccupancyClientHistogramService::getLSCertification ( std::string  iHistName)

Definition at line 430 of file L1TOccupancyClientHistogramService.cc.

{return mLSListDiff[iHistName];}
vector< pair< int, int > > L1TOccupancyClientHistogramService::getMaskedBins ( std::string  test)

Definition at line 150 of file L1TOccupancyClientHistogramService.cc.

                                                                                         {
  return (*mMaskedBins[iHistName]);
}
unsigned int L1TOccupancyClientHistogramService::getNBinsHistogram ( std::string  test)

Definition at line 45 of file L1TOccupancyClientHistogramService.cc.

                                                                                   {

  TH2F* pHistogram  = getDifferentialHistogram(iHistName);
  int   nBinsX      = pHistogram->GetNbinsX();
  int   nBinsY      = pHistogram->GetNbinsY();
  int   nMasked     = getNBinsMasked(iHistName);
  unsigned int  nBinsActive = (nBinsX*nBinsY)-nMasked;

  return nBinsActive;

}
unsigned int L1TOccupancyClientHistogramService::getNBinsMasked ( std::string  test)

Definition at line 162 of file L1TOccupancyClientHistogramService.cc.

                                                                                {
  return mMaskedBins[iHistName]->size();
}
TH2F * L1TOccupancyClientHistogramService::getRebinnedHistogram ( std::string  iHistName,
std::string  iHistLocation 
)

Definition at line 317 of file L1TOccupancyClientHistogramService.cc.

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

                                                                                                     {
  
  MonitorElement* me = mDBE->get(iHistLocation);

  TH2F* histMonitor;
  
  if(!me){
    histMonitor           = 0;
    mHistValid[iHistName] = false;
  }
  else{
    mHistValid[iHistName] = true;
    histMonitor = new TH2F(*(mDBE->get(iHistLocation)->getTH2F()));

    // Default rebin factors
    int rebinFactorX=1;
    int rebinFactorY=1;

    vector<ParameterSet> testParameters = mParameters.getParameter< vector<ParameterSet> >("testParams");
    for(unsigned int i=0 ; i<testParameters.size() ; i++){
      if(testParameters[i].getParameter<string>("testName")==iHistName){
        ParameterSet algoParameters = testParameters[i].getParameter<ParameterSet>("algoParams");
        rebinFactorX = algoParameters.getUntrackedParameter<int>("rebinFactorX",1);
        rebinFactorY = algoParameters.getUntrackedParameter<int>("rebinFactorY",1);
        break;
      }
    }

    // Rebinning
    if(rebinFactorX!=1){histMonitor->RebinY(rebinFactorX);}
    if(rebinFactorY!=1){histMonitor->RebinY(rebinFactorY);}

  }

  return histMonitor;
  
}
bool L1TOccupancyClientHistogramService::isMasked ( std::string  test,
int  x,
int  y 
)
bool L1TOccupancyClientHistogramService::isStripMasked ( std::string  test,
int  binStrip,
int  axis 
)

Definition at line 247 of file L1TOccupancyClientHistogramService.cc.

References prof2calltree::count, and i.

                                                                                                 {

  bool stripIsMasked = true;
  vector<pair<int,int> > *thisHistMaskedBins = mMaskedBins[iHistName];

  // If the histogram to be tested had strips defined along Y
  if(iAxis==1) {
    int count=0;
    for(unsigned int i=0; i<thisHistMaskedBins->size(); i++) {
      if((*thisHistMaskedBins)[i].first==iBinStrip){count++;}
    }
    stripIsMasked = getDifferentialHistogram(iHistName)->GetYaxis()->GetNbins()==count;
  }
  // If the histogram to be tested had strips defined along X
  else {
    int count=0;
    for(unsigned int i=0; i<thisHistMaskedBins->size(); i++) {
      if((*thisHistMaskedBins)[i].second==iBinStrip){count++;}
    }
    stripIsMasked = getDifferentialHistogram(iHistName)->GetXaxis()->GetNbins()==count;
  }

  return stripIsMasked;
}
TH2F * L1TOccupancyClientHistogramService::loadHisto ( std::string  test,
std::string  histo 
)

Definition at line 282 of file L1TOccupancyClientHistogramService.cc.

                                                                                          {

  pair<TH2F*,TH2F*> histPair; 

  // Histogram to be monitored should be loaded  in the begining of the run
  TH2F* pHist = getRebinnedHistogram(iHistName,iHistLocation);
  
  if(mHistValid[iHistName]){
  
    histPair.first = pHist; 
  
    TH2F* histDiff = new TH2F(*histPair.first); // Clone the rebinned histogram to be monitored
    histDiff->Reset();                          // We reset histDiff so we are sure it is empty
    histPair.second=histDiff;
  
    mHistograms[iHistName]=histPair;
  
    // Stating the previous closed LS Block Histogram Diff 
    mHistDiffMinus1[iHistName]=new TH2F(*histDiff);
    
  }
    
  return pHist;  //return pointer to the differential histogram
  
}
int L1TOccupancyClientHistogramService::maskBins ( std::string  test,
TH2F *  histo,
int  strip,
int  axis 
)

Definition at line 178 of file L1TOccupancyClientHistogramService.cc.

References prof2calltree::count, gather_cfg::cout, i, m, and AlCaHLTBitMon_ParallelJobs::p.

                                                                                                     {

  vector<pair<int,int> > m = (*mMaskedBins[iHistName]);
  int count=0;
  
  // iAxis==1 : Means symmetry axis is vertical
  if(iAxis==1) {
    for(unsigned int i=0;i<m.size();i++) {
      pair<int,int> &p = m[i];
      if(p.first==iStrip) {
        oHist->SetBinContent(p.first,p.second,0.0);
        count++;
      }
    }
  }
  // iAxis==2 : Means symmetry axis is horizontal
  else if(iAxis==2) {
    for(unsigned int i=0;i<m.size();i++) {
      pair<int,int> &p = m[i];
      if(p.second==iStrip) {
        oHist->SetBinContent(p.first,p.second,0.0);
        count++;
      }
    }
  }
  else {
    if(mVerbose) {cout << "invalid axis" << endl;}
  }
  
  return count;
}
void L1TOccupancyClientHistogramService::resetHisto ( std::string  test)

Definition at line 403 of file L1TOccupancyClientHistogramService.cc.

References edm::second().

                                                                   {
  
  if(mHistValid[iHistName]){
  
    // Replacing mHistDiffMinus1
    delete mHistDiffMinus1[iHistName];
    mHistDiffMinus1[iHistName] = new TH2F(*mHistograms[iHistName].second);  

    // Resetting
    mHistograms[iHistName].second->Reset();

    // LS Accounting  
    mLSListDiffMinus1[iHistName] = mLSListDiff[iHistName]; // Replacing
    mLSListDiff      [iHistName].clear();                 // Resetting
    
  }
}
void L1TOccupancyClientHistogramService::setMaskedBins ( std::string  test,
std::vector< edm::ParameterSet mask 
)

Definition at line 65 of file L1TOccupancyClientHistogramService.cc.

References edm::ParameterSet::getParameter(), timingPdfMaker::histo, i, m, AlCaHLTBitMon_ParallelJobs::p, x, xlast, detailsBasic3DVector::y, and z.

                                                                                                          {

  TH2F* histo = mHistograms[iHistName].first;
  vector<pair<int,int> >* m = new vector<pair<int,int> >();
  
  if(mVerbose){printf("Masked areas for: %s\n",iHistName.c_str());}

  for(unsigned int i=0;i<iMaskedAreas.size();i++) {

    ParameterSet iMA        = iMaskedAreas[i];
    int          iTypeUnits = iMA.getParameter<int>("kind");

    //get boundaries from python
    double xmin = iMA.getParameter<double>("xmin");
    double xmax = iMA.getParameter<double>("xmax");
    double ymin = iMA.getParameter<double>("ymin");
    double ymax = iMA.getParameter<double>("ymax");

    if(mVerbose){
      string sTypeUnits;
      if     (iTypeUnits == 0){sTypeUnits = "Histogram Units";}
      else if(iTypeUnits == 1){sTypeUnits = "Bin Units";}
      else                    {sTypeUnits = "Unknown Units";}
      printf("Area %3i: xmin=%6.2f xmax=%6.2f ymin=%6.2f ymax=%6.2f %s\n",i,xmin,xmax,ymin,ymax,sTypeUnits.c_str());
    }

    int xfirst,yfirst,xlast,ylast;

    //if min < max: change
    if(!(xmin<=xmax)){int z=xmax; xmax=xmin; xmin=z;}
    if(!(ymin<=ymax)){int z=ymax; ymax=ymin; ymin=z;}

    // If masked area are defined in terms of units of the histogram get bin coordinates
    if(iTypeUnits==0) {

      // We get the global bin number for this coordinates
      int globalMaxBin = histo->FindBin(xmax,ymax);
      int globalMinBin = histo->FindBin(xmax,ymax);

      // Dummy value for this variable since is a 2D histogram
      int binZ = 0; 

      // We convert global bins in axis bin numbers
      histo->GetBinXYZ(globalMinBin,xfirst,yfirst,binZ);
      histo->GetBinXYZ(globalMaxBin,xlast ,ylast ,binZ);

      // If the max edge (on X or Y) coincide with the lower edge of the current bin
      // pass one bin bellow (since bins are defined from [a,b[)
      if(histo->GetXaxis()->GetBinLowEdge(globalMaxBin)==xmax){xlast--;}
      if(histo->GetYaxis()->GetBinLowEdge(globalMaxBin)==ymax){ylast--;}

    }
    // Else units are bin coordinates just convert from double to int
    else {
      xfirst = (int) xmin;
      xlast  = (int) xmax;
      yfirst = (int) ymin;
      ylast  = (int) ymax;
    }
    
    // Now we generate coordinate pairs for each bin in the masked area
    // and we store them for future use
    for(int x=xfirst; x<=xlast; x++) {
      for(int y=yfirst; y<=ylast; y++) {
        pair<int,int> p;
        p.first  = x;
        p.second = y;
        m->push_back(p);
      }
    }
  }
  
  delete[] mMaskedBins[iHistName];
  mMaskedBins[iHistName]=m;

}
void L1TOccupancyClientHistogramService::updateHistogramEndLS ( std::string  test,
std::string  histo,
int  iLS 
)

Definition at line 362 of file L1TOccupancyClientHistogramService.cc.

References edm::first().

                                                                                                           {
    
  if(mHistValid[iHistName]){
  
    TH2F* histo_curr = getRebinnedHistogram(iHistLocation,iHistLocation); // Get the rebinned histogram current cumulative iHistLocation

    TH2F* histo_old = new TH2F(*histo_curr);            // Clonecout <<"WP01"<<end; 
    histo_curr->Add(mHistograms[iHistName].first,-1.0); //calculate the difference to previous cumulative histo

    mLSListDiff[iHistName].push_back(iLS);

    delete mHistograms[iHistName].first;            //delete old cumulateive histo 
    mHistograms[iHistName].first=histo_old;         //save old as new
    mHistograms[iHistName].second->Add(histo_curr); //save new as current
  }  
}
void L1TOccupancyClientHistogramService::updateHistogramEndRun ( std::string  iHistName)

Definition at line 386 of file L1TOccupancyClientHistogramService.cc.

References begin, and end.

                                                                              {
  
  if(mHistValid[iHistName]){
  
    mHistograms[iHistName].second->Add(mHistDiffMinus1[iHistName]);
    mLSListDiff[iHistName].insert(mLSListDiff      [iHistName].end(), 
                                  mLSListDiffMinus1[iHistName].begin(),
                                  mLSListDiffMinus1[iHistName].end());
  }
}

Member Data Documentation

Definition at line 58 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,TH2F*> L1TOccupancyClientHistogramService::mHistDiffMinus1 [private]

Definition at line 66 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,std::pair<TH2F*,TH2F*> > L1TOccupancyClientHistogramService::mHistograms [private]

Definition at line 64 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,bool> L1TOccupancyClientHistogramService::mHistValid [private]

Definition at line 63 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,std::vector<int> > L1TOccupancyClientHistogramService::mLSListDiff [private]

Definition at line 67 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,std::vector<int> > L1TOccupancyClientHistogramService::mLSListDiffMinus1 [private]

Definition at line 68 of file L1TOccupancyClientHistogramService.h.

std::map<std::string,std::vector<std::pair<int,int> >* > L1TOccupancyClientHistogramService::mMaskedBins [private]

Definition at line 65 of file L1TOccupancyClientHistogramService.h.

Definition at line 60 of file L1TOccupancyClientHistogramService.h.

Definition at line 59 of file L1TOccupancyClientHistogramService.h.