How to compare histograms from two different ROOT files in which histograms are saved

  • Example macro: displayTwofiles.C
  • To use this macro, within ROOT do the following
        .L displayTwofiles.C
        displayTwofiles( .....) // depending on your file names, histogram names, etc.
      

How to compare histograms from two different ROOT files in which trees are saved

How to use ROOT and plot distributions saved in the ROOT file

  • Log on to grid03 either via ssh in Linux or putty + xming in Windows
        ssh 140.115.32.53 -l "your_user_id"
      
  • If ROOT is not yet setup in your directory, follow the instruction below
    • Check which shell you are running
              echo $SHELL
             
    • If it is tcsh or csh, follow the instruction below.
       
               source /opt/exp_soft/cms/cmsset_default.csh
               cd
               cmsrel CMSSW_3_9_7
               cd CMSSW_3_9_7/src
               cmsenv
              
      * If it is bash, follow the instruction below.
               source /opt/exp_soft/cms/cmsset_default.sh
               cd
               cmsrel CMSSW_3_9_7
               cd CMSSW_3_9_7/src
               cmsenv
              
  • Create a directory in your home area
         cd
         mkdir rootExercise
         cd rootExercise
       
  • Copy the following files to this directory
       cp -p /data/syu/Plot_jiechen.* .
      
  • Check if the files are there
       ls
      
  • Enter ROOT and run the macro
        root -l
        .L Plot_jiechen.C++
        Plot_jiechen a;
        a.Loop();
       
  • The test root file is big. Therefore, it will take about 5 mins to finish.
  • Then, exit ROOT
        .q
       
  • An output file "output_histo.root" will be created in the same directory. You could open the root file to see the content.
         root -l output_histo.root
         .ls
         h_phoet->Draw();
         h_phophi->Draw();
         
  • Please modify Plot_jiechen.C to make histograms for other photon variables (pho*...).

How to write a macro for any ROOT file format

  • Here is the macro:
  • To use the example macro:
       .L loopEntries.C++
       loopEntries()
      
  • Caveat!!! You need to declare the variables you want to use with the correct data type.
    For example, if I want to take the variable "phoEt" and the variable is saved as a Double_t. When assigning a local variable to phoEt, I can't use Float_t

How to create macro for any ROOT file format with MakeClass

  • Supposedly if your ROOT file is /data/syu/31x_7TeV_PhotonJet_Pt15_pythia.root
         root -l /data/syu/31x_7TeV_PhotonJet_Pt15_pythia.root
      
  • You need to know the name of the tree saved in this ROOT file, use TBrowser to find the name. In this example, the name of TTree is EventTree.
       EventTree->MakeClass("myMacro");
      
    You could change myMacro to any name you prefer.
  • Now two files are created, myMacro.h and myMacro.C.
  • You could modify these two files to do your analysis.

-- ShinShanYu - 24-Apr-2011

Topic attachments
I Attachment History Action Size Date Who Comment
C source code filec displayTwoTrees.C r1 manage 1.8 K 2011-06-01 - 07:50 ShinShanYu  
C source code filec displayTwofiles.C r1 manage 3.1 K 2011-05-19 - 06:58 ShinShanYu  
C source code filec loopEntries.C r1 manage 2.0 K 2011-06-22 - 15:42 ShinShanYu  
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2011-06-22 - ShinShanYu
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback