Skip to content

Special Analyzer

Brenda Fabela edited this page Apr 28, 2020 · 2 revisions

In this page we explain how to set up, compile and use the Special Analyzer included in the main Analyzer framework.

Description

The Special Analyzer is a separate code that runs on top of the main Analyzer framework. This means that you can create a completely customized analyzer that does not require the usual configuration files but you can still access the particle information and functions you have in the main Analyzer. The special analyzer will run in parallel with the main Analyzer.

Setting up the Special Analyzer

There is a template that you can use as a starting point to create your own special analyzer, which is located at NanoAOD_Analyzer/SpecialAna. From there you need to:

  • Create a copy of this folder in NanoAOD_Analyzer with the name of your preference. In this example we use VBFSusyAna:
cp -r SpecialAna VBFSusyAna
  • Modify the code in VBFSusyAna/SpechialAnalysis.h and VBFSusyAna/SpechialAnalysis.cc. The structure of these files is explained below. These files will not be tracked by git, which means you can set up your own repository.

  • In order to activate the Special Analyzer, you need to add or uncomment the lines that end with the comment // Special analyzer below in your src/main.cc file:

  //setup the main analyzer
  Analyzer testing(inputnames, outputname, setCR, configFolder, year);

  SpechialAnalysis spechialAna = SpechialAnalysis(&testing);    // Special analyzer
  spechialAna.init();                                           // Special analyzer

  //catch ctrl+c and just exit the loop
  //this way we still have the output
  signal(SIGINT,KeyboardInterrupt_endJob);
  size_t Nentries=testing.nentries;
  if(testRun){
    Nentries=100;
    testing.nentries=100;
  }
   
  //main event loop
  for(size_t i=0; i < Nentries; i++) {
    
    if(i == 0) spechialAna.begin_run();   // Special analyzer
    
    testing.clear_values();

    testing.preprocess(i, year);

    testing.fill_efficiency();

    testing.fill_histogram();
    
    spechialAna.analyze();                // Special analyzer
    
    //this will be set if ctrl+c is pressed
    if(do_break){
      testing.nentries=i+1;
      break;
    }
  }
  testing.printCuts();
  
  spechialAna.end_run();                // Special analyzer
  • Once you finish modifying the code, set the environment variable MYANA to the name of your recently created folder:
export MYANA=VBFSusyAna
  • Clean up your object/executable files and recompile:
make clean
make -j8
  • Test if you get the output you want running over 100 events:
./Analyzer -in inputFile.root -out outputFile.root -C <ConfigFolder> -t

In principle, you should see the output you normally get with the main Analyzer plus the new directories, trees, or histograms you created in your special analyzer.

Modifying the Special Analyzer

Here you can find some quick examples on how to modify the code. Use them as a starting point.

Special analyzer methods

First, we discuss the structure of the code. The methods of the special analyzer are declared in SpechialAnalysis.h:

class SpechialAnalysis {
public:
  SpechialAnalysis(Analyzer* _a);
  void init();

  void begin_run();
  void analyze();
  void end_run();

private:
  Analyzer* a;
};

In SpechialAnalysis::init() you can define all the histograms and trees you want to store in your output file. SpechialAnalysis::analyze() is where you need to write your customized analysis. You can use all the functions that exist in the main Analyzer and fill the histograms here. In SpechialAnalysis::end_run(), you can write all the histograms/trees you defined at the beginning.

Examples

  • Booking a histogram: In SpechialAnalysis::analyze():
HistClass::CreateHisto("num", "Tau", 10, 0, 9, TString::Format("N_{%s}", "#tau"));
  • Accessing information: In SpechialAnalysis::analyze():
if(a->active_part->at(a->cut_num.at("NRecoTriggers1"))->size() == 0) return;
HistClass::Fill("Tau_num", a->active_part->at(CUTS::eRTau1)->size(), a->wgt);
  • Writing your histograms: In SpechialAnalysis::end_run():
TFile* outfile = a->routfile;
outfile->cd();
outfile->mkdir("Special");
outfile->cd("Special/");
HistClass::WriteAll("Tau_");

For more examples, you can check this repository.