CMS Data Analysis School Pre-Exercises - Fourth Set

Introduction

In this set of exercises, we will analyze the MiniAOD file that was made in Third Set of Exercise. You must have this skimmed MiniAOD stored locally (at your Tier-2) in order to access them. We will use different options of analyzing the MiniAOD, namely, EDAnalyzer, FWLite executable, FWLite Macro and FWLite PyROOT. We will basically re-make the Zpeak and few other histograms and store them in an output root file. In the exercise in the end we will try to fit with a Gaussian, Breit-Wigner function etc.

Please run and complete these exercises. Questions for each exercise are in red font. Post the answers in the online response form available from the course web area:

If problems are encountered please e-mail the
  • LPC contact CMSDASATLPC@fnal.gov for CMSDAS@LPC2018
with a detailed description of your problem. The instructors will be delighted to help you.

Exercise 17 - Analyzing MiniAOD with an EDAnalyzer

In this exercise we will analyze the skimmed MiniAODs created in Third Set of Exercise using an EDAnalyzer. In these skimmed MiniAODs , if you recall, we saved only the Muons and Electrons. So do not look for Jets or Photons or other objects as they were simply not saved. We will use a python config file and an EDAnalyzer ( a .cc file) to make a Z mass peak.

First we will add the PhysicsTools/PatExamples package as follows to YOURWORKINGAREA/CMSSW_9_3_2/src. The PatExamples package has lot of examples for a user to try. However, we will add our own code and config file to it and then compile. To add this package, do this:

cd CMSSW_9_3_2/src
git cms-addpkg PhysicsTools/PatExamples

The python config file analyzePatBasics_cfg.py should be in PhysicsTools/PatExamples/test/ directory. The EDAnalyzer named PatBasicAnalyzer.cc should be in your PhysicsTools/PatExamples/plugins/ directory.

First cut, paste and save the following two files. Save MyZPeakAnalyzer.cc as MyZPeakAnalyzer.cc in PhysicsTools/PatExamples/src/ and MyZPeak_cfg.py as MyZPeak_cfg.py in CMSSW_9_3_2/src/.

The we will compile the code that you just saved. To do this, do:

cd CMSSW_9_3_2/src
scram b

When you do the above you should see among the output a line like the one below while compilation is going on, otherwise it is not compiled and you may end up assuming so

>> Compiling  /your_path/YOURWORKINGAREA/CMSSW_9_3_2/src/PhysicsTools/PatExamples/src/MyZPeakAnalyzer.cc 

After successful compilation, you must run the config file as follows:

cmsRun MyZPeak_cfg.py

Successful running of the above config file will produce an output file myZPeakCRAB.root.

Note: In the case above, the file MyZPeak_cfg.py will read from area root://cmseos.fnal.gov//store/user/cmsdas/2018/pre_exercises/fourth_set/. You should have a similar location from where you can read your CRAB output ROOT files. You can edit the MyZPeak _cfg.py file to use the MiniAOD files you made in Exercise 15 by replacing the location of the input files.

'root://cmseos.fnal.gov//store/user/cmsdas/2018/pre_exercises/fourth_set/slimMiniAOD_data_MuEle_1.root', (at USCMS) or
'file:/afs/cern.ch/work/d/dmoon/public/CMSDAS_Files/Exe4/slimMiniAOD_data_MuEle_1.root', (at lxplus or Bari) or
'file:/cmsdas/data/pre_exercises/Exe4/slimMiniAOD_data_MuEle_1.root', (at KNU) or
'file:/pnfs/desy.de/cms/tier2/store/user/your_username/DoubleMuon/crab_CMSDAS_Data_analysis_test0/160718_090558/0000/slimMiniAOD_data_MuEle_1.root' (at nafhh-cms)
to the path of file you generated. Also note the that the output file myZPeakCRAB.root has several histograms, besides the ZPeak called mumuMass, like muonMult, muonEta, muonPhi, muonPt and similarly for electrons.

For CMSDAS@LPC2018 please submit your answers at the Google Form fourth set.

QUESTION 17 - What is the number of entries in the mumuMass plot ?

Exercise 18 - Analyzing MiniAOD with an FWLite executable

In this exercise we will make the same ROOT file myZPeakCRAB.root as in Exercise 17, but we call it myZPeakCRAB_fwlite.root so that you do not end of overwriting the file previously made in Exercise 17.

First make sure you have checked the following two packages:

cd CMSSW_9_3_2/src
git cms-addpkg PhysicsTools/FWLite
git cms-addpkg PhysicsTools/UtilAlgos

Then cut, paste and save the following two files:

* Replace the CMSSW_9_3_2/src/PhysicsTools/FWLite/bin/FWLiteWithPythonConfig.cc with this FWLiteWithPythonConfig.cc and save.

* Cut, paste and save parameters.py as parameters.py in CMSSW_9_3_2/src/.

NOTE: Cut and paste parameters.py only if you have not successfully finished SET 3. In case Exercise SET 3 has been done successfully, put the names and path of the root files that you made yourself via submitting CRAB job.

Note: parameters.py will read from area root://cmseos.fnal.gov//store/user/cmsdas/2018/pre_exercises/fourth_set/. You should have a similar location from where you can read your CRAB output ROOT files. You can edit the MyZPeak _cfg.py file to use the MiniAOD files you made in Exercise 15 by replacing the location of the input files.

'root://cmseos.fnal.gov//store/user/benwu/CMSDAS/DoubleMu/crab_CMSDAS_Data_analysis_test0/141126_235113/0000/slimMiniAOD_data_MuEle_1.root', (at USCMS)
'file:/afs/cern.ch/work/d/dmoon/public/CMSDAS_Files/Exe4/slimMiniAOD_data_MuEle_1.root', (at lxplus or Bari) or
'file:/cmsdas/data/pre_exercises/Exe4/slimMiniAOD_data_MuEle_1.root', (at KNU) or
'file:/pnfs/desy.de/cms/tier2/store/user/your_username/DoubleMuon/crab_CMSDAS_Data_analysis_test0/160718_090558/0000/slimMiniAOD_data_MuEle_1.root' (at nafhh-cms)

to the path of file you generated.

Then we will compile the code that you just saved. To do this, do:

scram b

When you do the above you should see among the output a line like the one below while compilation is going on, otherwise it is not compiled and you may end up assuming so

>> Compiling  /your_path/YOURWORKINGAREA/CMSSW_9_3_2/src/PhysicsTools/FWLite/bin/FWLiteWithPythonConfig.cc

After successful compilation, you must run the config file as follows:

cd CMSSW_9_3_2/src
cmsenv
FWLiteWithPythonConfig parameters.py

Note: How the parameters defined in parameters.py get input to the executable code FWLiteWithPythonConfig.cc. Note that the extra cmsenv is to ensure the changes to files in the bin subdirectory are picked up in your path.

Note: You might get a segfault when running this exercise. Just ignore it, the output root file will still be created and be readable.

A successful running of the FWLite executable FWLiteWithPythonConfig results in an output file called myZPeakCRAB_fwlite.root.

The output ROOT file myZPeakCRAB_fwlite.root is a bit different from myZPeakCRAB.root made in Exercise 17 since we did not make any of the electron histograms. The histograms do have the mumuMass, besides, muonEta, muonPhi and muonPt.

QUESTION 18 - What is the number in entries in the mumuMass obtained in Exercise 17 and 18 ?

Exercise 19 - Fitting the Z mass peak

Before you move further, make sure you have the above ROOT file called myZPeakCRAB.root in your CMSSW_9_3_2/src. If you have not managed to do so, you can get this ROOT file from root://cmseos.fnal.gov//store/user/cmsdas/2018/pre_exercises/fourth_set/myZPeakCRAB.root (LPC) or /afs/cern.ch/cms/Tutorials/TWIKI_DATA/CMSDataAnaSch/myZPeakCRAB.root and move ahead. The below session will use /afs/cern.ch/cms/Tutorials/TWIKI_DATA/CMSDataAnaSch/myZPeakCRAB.root (lxplus or Bari) for illustration purpose.

The main intention of fitting the Z mass peak is to show how to fit a distribution. To do this exercise will need the root file that you made in Exercises 17 and 18. Let us take the root file myZPeakCRAB.root for this exercise. Yo can use myZPeakCRAB_fwlite.root also, but just make sure to have the right name of the ROOT file. Both of these have the histogram mumuMass and that is what is important. The different distribution that we would fit to the Z mass peak are:

  • Gaussian

%BEGINLATEX% \begin{displaymath} G(x; \mu, \sigma) = \frac{1}{\sqrt{2\pi}\sigma}\exp\left[-\frac{(x-\mu)^2}{2\sigma^2}\right] \end{displaymath} %ENDLATEX%

  • Relativistic Breit-Wigner

%BEGINLATEX% \begin{displaymath} B(m; M, \Gamma) = N \cdot \frac{2}{\pi} \cdot \frac{\Gamma^{2}M^{2}}{(m^{2}-M^{2})^{2}+m^{4}(\Gamma^{2}/M^{2})} \end{displaymath} %ENDLATEX%

  • Convolution of relativistic Breit-Wigner plus interference term with a Gaussian

%BEGINLATEX% \begin{displaymath} P(m) = \int B(m'; M, \Gamma)\cdot G(m-m'; \mu, \sigma) dm' \end{displaymath} %ENDLATEX%

Some general remarks about fitting a Z peak:

To fit a generator-level Z peak a Breit-Wigner fit makes sense. However, reconstructed-level Z peaks have many detector resolutions that smear the Z mass peak. If the detector resolution is relatively poor, then it is usually good enough to fit a gaussian (since the gaussian detector resolution will overwhelm the inherent Briet-Wigner shape of the peak). If the detector resolution is fairly good, then another option is to fit a Breit-Wigner (for the inherent shape) convoluted with a gaussian (to describe the detector effects).This is in the "no-background" case. If you have backgrounds in your sample (Drell-Yan, cosmics, etc...), and you want to do the fit over a large mass range, then another function needs to be included to take care of this - an exponential is commonly used.

Fitting a Gaussian

Before going further, create a rootlogon.C= in your home area (for example /uscms/home/malik/ on = cmslpc) Paste the lines HERE in the rootlogon.C file. If you already have a rootlogon.C file, then make sure that these lines are included in it.

There are several options to fit a Gaussian

Using the inbuilt Gaussian in ROOT

Login to ROOT as follows

root -l
and execute the following commands
TFile f("myZPeakCRAB.root");
f.cd("analyzeBasicPat");
gStyle->SetOptFit(111111);   
mumuMass->Fit("gaus");

This will pop up the following histogram. Save this histogram as pdf or postscript or eps file using the menu of the histogram window. As you can see we should fit a sub-range as this fit is not a good fit. In the next part of this exercise, we will fit a sub-range of the mumuMass distribution, but for this we will use a ROOT macro as using inbuilt ROOT functions have very minimal usage. For more complex or useful fitting functions, one has to use a macro.

Fit description of the Z resonance improves when:

TFile f("myZPeakCRAB.root");
f.cd("analyzeBasicPat");
gStyle->SetOptFit(111111);   
g1 = new TF1("m1","gaus",85,95);
mumuMass->Fit(g1,"R");

One should obtain a similar histogram as:

GaussFitZmm_5311.png

Quit ROOT as follows

.q

The line gStyle->SetOptFit(111111); enables all the histogram statistics to be displayed. For more options and other information please refer to ROOT documentation.

QUESTION 19.1a - What is the value of the mean Z Mass that you get?

QUESTION 19.1b - What is the value of the chisquare/ndf that you get?

Using a macro of your own in ROOT

As you have seen above that we should fit a sub-range of the Z mass distribution as the fit in the full range is not all that great. In this exercise, we will fit a sub-range of the mumuMass distribution but for this we will use a ROOT macro as using inbuilt ROOT functions have very minimal usage. For more complex or useful fitting functions, one has to use a macro. The macro to run is FitZPeak.C. This macro calls another macro called BW.C. So please copy, paste and save them with the corresponding names in CMSSW_9_3_2/src. Note that now the myZPeakCRAB.root file is opened by executing the macro itself, in addition to fitting the Z mass peak.

First step is to change the line in FitZPeak.C:

void FitZPeak3(){
to
void FitZPeak(){

To run this macro execute the following command from the area CMSSW_9_3_2/src.

root -l FitZPeak.C

This should pop up a histogram (shown below) and you will find yourself in a ROOT session.

FitZPeak_C_5311.png

You can save this plot from the menu on top of the histogram and quit ROOT session by doing the following:

.q

In order to run the rootlogon.C from CMSSW_9_3_2/src the following line would have to be modified:

gROOT->Macro("~/rootlogon.C");
to
gROOT->Macro("rootlogon.C");

Here is some explanation of the macro. We have defined the Gaussian distribution that we want to fit in the macro BW.C as the following. Note that in the same macro we have also is defined Breit-Wigner that you can try yourself to fit by using it. However, we fit Breit-Wigner in the later part of the exercise by using RooFit in the next part of this exercise.


Double_t mygauss(Double_t * x, Double_t * par)
{
  Double_t arg = 0;
  if (par[2]<0) par[2]=-par[2];  // par[2]: sigma
  if (par[2] != 0) arg = (x[0] - par[1])/par[2];  // par[1]: mean
 
 //return par[0]*BIN_SIZE*TMath::Exp(-0.5*arg*arg)/
  //   (TMath::Sqrt(2*TMath::Pi())*par[2]); 
   return par[0]*TMath::Exp(-0.5*arg*arg)/
     (TMath::Sqrt(2*TMath::Pi())*par[2]); // par[0] is constant
 
}
 

par[0], par[1] and par[2] respectively are the constant, mean and the sigma parameters. Also x[0] mean the x-axis variable. BW.C is called by FitZPeak.C in the code line gROOT->LoadMacro("BW.C"); . The initial values of the three fitted are defined as follows in the FitZPeak.C

func->SetParameter(0,1.0);   func->SetParName(0,"const");  
func->SetParameter(2,5.0);   func->SetParName(2,"sigma");  
func->SetParameter(1,95.0);     func->SetParName(1,"mean");

Also note that in the macro FitZPeak.C, we have commented the following lines and used the two lines below it. The reason being that we want to fit a sub-range. If you would want to fit the entire range of the histogram, get the minimum and maximum value of the range by instead using the lines that have been commented.

//float massMIN = mumuMass->GetBinLowEdge(1);
//float massMAX = mumuMass->GetBinLowEdge(division+1);

float massMIN = 85.0;
float massMAX = 96.0;

You can also save the plot to an postscript file by un-commenting the following line FitZPeak.C

 //c1->Print ("myZmass_Gausfitted.eps");

QUESTION 19.2 - What mean value of Z Mass in the fitted sub-range do you get?

Using a macro in RooFit

Before we start, have a look at the twiki RooFit to get a feeling for it. The macro to fit Z mass peak in RooFit is RooFitMacro.C. So please copy and paste the lines from RooFitMacro.C and save them with the name RooFitMacro.C in CMSSW_9_3_2/src.

First step is to change the line in RooFitMacro.C

void RooFit2(){
to
void RooFitMacro(){

and

 //RooGaussian gauss("gauss","gauss",x,mean,sigma);
 //RooBreitWigner gauss("gauss","gauss",x,mean,sigma);
 RooVoigtian gauss("gauss","gauss",x,mean,width,sigma);

to

 RooGaussian gauss("gauss","gauss",x,mean,sigma);
 //RooBreitWigner gauss("gauss","gauss",x,mean,sigma);
 //RooVoigtian gauss("gauss","gauss",x,mean,width,sigma);

Then execute the following:

root -l RooFitMacro.C

You may need to add the following line to your roologon.C file to get this interpreted code to work:

 gROOT->ProcessLine(".include /cvmfs/cms.cern.ch/slc6_amd64_gcc491/lcg/roofit/5.34.18-cms3/include/");

This should pop a histogram (shown below) and you will find yourself in a ROOT session. You can save this plot from the menu on top of the histogram and quit ROOT session by doing the following:

.q

To do a Gaussian, we simply commented out the Breit-Wigner and Voigtian (convolution of Breit-Wigner and Gaussian).

myZmmGaussROOTFit_5311.png

QUESTION 19.3a - What is the mean for the gaussian fit in RooFit?

QUESTION 19.3b - What is the sigma for the gaussian fit in RooFit?

Fitting a Breit-Wigner

Using a macro in ROOT

To make fit Breit-Wigner we first uncomment the Breit-Wigner and comment out the Gaussian part in FitZPeak.C as follows (using /* and */) :

////////////////
//For Gaussian//
///////////////
/*
TF1 *func = new TF1("mygauss",mygauss,massMIN, massMAX,3); 
func->SetParameter(0,1.0);   func->SetParName(0,"const");  
func->SetParameter(2,5.0);   func->SetParName(2,"sigma");  
func->SetParameter(1,95.0);     func->SetParName(1,"mean");

Z_mass->Fit("mygauss","QR");
TF1 *fit = Z_mass->GetFunction("mygauss");
*/
/////////////////////
// For Breit-Wigner//
////////////////////
TF1 *func = new TF1("mybw",mybw,massMIN, massMAX,3);
func->SetParameter(0,1.0);   func->SetParName(0,"const");
func->SetParameter(2,5.0);     func->SetParName(1,"sigma");
func->SetParameter(1,95.0);    func->SetParName(2,"mean");

Z_mass->Fit("mybw","QR");
TF1 *fit = Z_mass->GetFunction("mybw");

Then execute the following:

root -l FitZPeak.C

This should pop a histogram (shown below) and you will find yourself in ROOT seession.

BWFitZmm_5311.png

You can save this plot from the menu on top of the histogram and quit ROOT session by doing the following:

.q

QUESTION 19.4a - What is the mean for Breit-Wigner fit using the macro?

QUESTION 19.4b - What is the sigma for Breit-Wigner fit using the macro?

Using a macro in RooFit

Before we proceed we need to uncomment and comment out few lines in RooFitMacro.C to have them look as follows:

 //RooGaussian gauss("gauss","gauss",x,mean,sigma);
 RooBreitWigner gauss("gauss","gauss",x,mean,sigma);
 // RooVoigtian gauss("gauss","gauss",x,mean,width,sigma);

Then execute

root -l RooFitMacro.C

This should pop a histogram (shown below) as follows and you will find yourself in ROOT session.

myZmmBWROOTFit_5311.png

You can save this plot from the menu on top of the histogram and quit ROOT session by doing the following:

.q

QUESTION 19.5a - What is the mean for Breit-Wigner fit using RooFit tool ?

QUESTION 19.5b - What is the sigma for Breit-Wigner fit using RooFit tool ?

Fitting a Convolution of Gaussian and Breit-Wigner

Using a macro in RooFit

Before we proceed we need to uncomment and comment out few lines in RooFitMacro.C to have them look as follows:

 //RooGaussian gauss("gauss","gauss",x,mean,sigma);
 // RooBreitWigner gauss("gauss","gauss",x,mean,sigma);
  RooVoigtian gauss("gauss","gauss",x,mean,width,sigma);

Then execute

root -l RooFitMacro.C

This should pop a histogram (shown below) as follows and you will find yourself in ROOT seession.

myZmmVoigtianROOTFit_5311.png

You can save this plot from the menu on top of the histogram and quit ROOT session by doing the following:

.q

QUESTION 19.6a - What is the mean for the convoluted fit using - RooFit tool?

QUESTION 19.6b - What is the sigma for the convoluted fit using - RooFit tool?

For CMSDAS@LPC2018 please submit your answers at the Google Form fourth set.

Link to SWGuideCMSDataAnalysisSchoolPreExerciseFirstSet

Link to SWGuideCMSDataAnalysisSchoolPreExerciseSecondSet

Link to SWGuideCMSDataAnalysisSchoolPreExerciseThirdSet

Link to SWGuideCMSDataAnalysisSchoolPreExerciseFifthSet

Link to SWGuideCMSDataAnalysisSchoolPreExerciseSixthSet

Reviewer/Editor and Date (copy from screen) Comments
AshleyMarieParker - 2017-10-18 Updated to CMSSW_9_3_2for CMSDAS@LPC 2018
AdrianPerieanu - 19 July 2016 Updated to CMSSW_8_0_6 for CMSDAS@HH
NitishDhingra - 06 October 2013 Updated to CMSSW_7_3_0_pre1 for CMSDAS@Kolkata
NitishDhingra - 23 July 2012 Updated to CMSSW_5_2_5 for CMSDASia

%REVIEW% AdrianPerieanu - 19 July 2016
%REVIEW% NitishDhingra - 06 October 2013
%REVIEW% NitishDhingra - 23 July 2012

-- Sudhir Malik - 2017-12-15

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng FitZPeak_C_5311.png r1 manage 15.9 K 2017-12-15 - 19:02 SudhirMalik  
Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2017-12-15 - SudhirMalik
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback