CMS Plot Styles

Instructions for CMS plot styles:

To use the ROOT .C macros in pyROOT, the simplest way is:

from ROOT import gROOT

# Set TDR styles
gROOT.LoadMacro("tdrstyle.C")
gROOT.ProcessLine("setTDRStyle();")

# Add CMS text
gROOT.LoadMacro("CMS_lumi.C")
gROOT.ProcessLine("CMS_lumi(c1);")

EOS Utilities

Useful links on EOS utilities at FNAL LPC:

Monitoring service for all things LPC:


Fixed-point two's complement in C++

Two’s complement is the most common way to represent signed numbers in fixed-point integer operations. Here is a simple implementation in C++ to convert from C++ signed integer to N-bit two’s complement value.

#include <iostream>
 
template<int N>
int to_twos_complement(int x) {
    return (x < 0) ? ((~abs(x) + 1) & ((1<<N)-1)) : x;
}
 
template<int N>
int from_twos_complement(int x) {
    return (x & (1<<(N-1))) ? (~(x-1) & ((1<<N)-1)) : x;
}
 
int main()
{
    int x = -1;
    int y = to_twos_complement<8>(x);
    int z = from_twos_complement<8>(y);
     
    std::cout << x << std::endl;  // = -1
    std::cout << y << std::endl;  // = 255
    std::cout << z << std::endl;  // = 1
}

Branchless delta-phi in C++

I recently found that CMSSW has a very nice implementation of delta-phi calculation with a very clever use of std::round(). See https://github.com/cms-sw/cmssw/blob/CMSSW_8_1_X/DataFormats/Math/interface/deltaPhi.h

But I realized it can be made even better by removing the branching condition. Hence this is my modified deltaPhi() function:

#include <cmath>

template <typename T>
inline T deltaPhiInRadians(T phi1, T phi2) {
  T result = phi1 - phi2;  // same convention as reco::deltaPhi()
  constexpr T _twopi = M_PI*2.;
  result /= _twopi;
  result -= std::round(result);
  result *= _twopi;  // result in [-pi,pi]
  return result;
}

template <typename T>
inline T deltaPhiInDegrees(T phi1, T phi2) {
  T result = phi1 - phi2;  // same convention as reco::deltaPhi()
  constexpr T _twopi = 360.;
  result /= _twopi;
  result -= std::round(result);
  result *= _twopi;  // result in [-180,180]
  return result;
}

Open files with Xrootd

Xrootd is a service implemented in ROOT that allows the user to remotely read data located at various CMS sites. The protocol details can be found at the following TWiki page:

Once you have a valid grid proxy (obtained by doing voms-proxy-init --voms cms), you can read a file on a remote site by using a ROOT command like.

TFile *f = TFile::Open("root://cmsxrootd.fnal.gov//store/mc/path/to/file");

The prefix root://cmsxrootd.fnal.gov/ is known as the redirector. In this case, it is the Fermilab redirector. There are also root://xrootd-cms.infn.it/ for Europe regional redirector, and root://cms-xrd-global.cern.ch/ for global redirector. The path /store/mc/... or /store/data/... is known as the Logical File Name (LFN), which is the global identifier of an official CMS dataset. You can also access non-official files stored under /store/user/username/... at any CMS storage element that provides Xrootd service. To download the file, you can use xrdcp:

xrdcp root://cmsxrootd.fnal.gov//store/mc/path/to/file /some/local/path

In case your grid proxy is not recognized, check if the environment variable $X509_USER_PROXY is set. If not, set it by doing:

export X509_USER_PROXY=/tmp/x509up_u`id -u`

or:

export X509_USER_PROXY=`voms-proxy-info -path`

To debug what’s wrong with Xrootd, do

export XRD_LOGLEVEL=Debug