Triple for loop, 1 loop over strings, other two over integers

Hi all, I would like to have a triple for loop, where I want my first for loop to select a trigger cut (vector of strings), my second for loop to select a pT1 cut and my third for loop to select a pT2 cut (both are vectors of integers).

However, I’m only interested in certain combinations of these cuts, if i=0 for my first for loop, I want my second for loop to only select j=0 (but still have all the k combinations), similarly if i = 1, I want j to be 1 as well, but I’m not sure how to implement that in my code and I also get a few errors that I don’t know how to solve…

So in the end I would like to have 3 plots on my canvas, the first one with L1_J20 and pT cut = 80 (and then different graphs for the pT2 cuts on that plot as before, where my selected pT2 cut has to be smaller or equal to my pT1 cut), second plot with L1_J40 and pT cut =135 (and again different pT2 cuts), and so on. I hope this is a bit clear! Thanks!

#include "TFile.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TMultiGraph.h"
#include "TGraphAsymmErrors.h"
#include "TString.h"
#include <vector>
#include <iostream>

void mjj_eff(const char *fname = "HaddOutput.root") {
  if (!(fname && fname[0])) return; // just a precaution
  TFile *f = TFile::Open(fname);
  if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
  std::vector<std::string> TriggerCut = {"L1_J20", "L1_J40", "L1_J50"};  
  std::vector<int> pT1Cut = {80, 130, 145};
  std::vector<int> pT2Cut = {50, 60, 70, 80, 90, 100, 110, 120, 130, 145};
  int n = TriggerCut.size();
  int n1 = pT1Cut.size();
  int n2 = pT2Cut.size();
  TCanvas *c = new TCanvas("c", "", (n1 * 350), 1000);
  c->Divide(3, 1);
  TH1D *h[n];
  TH1D *s[n][n1];
  TH1D *m[n][n1][n2];
  TMultiGraph *mg[n];
  TGraphAsymmErrors *eff[n][n1][n2];
  TH1D *histo = (TH1D*)f->Get("AfterCuts/yCut_0.6/pT1Cut_0/pT2Cut_0/Mjj");  

  for (int i = 0; i < n; i++) {
    c->cd(i + 1);
    f->GetObject(TString::Format("%s/yCut_0.6/pT1Cut_0/pT2Cut_0/Mjj", TriggerCut[i].c_str()), h[i]);

    if (!h[i]) continue; // just a precaution
    mg[i] = new TMultiGraph();
    for (int j = i; j < n1; j++) {
	f->GetObject("%s/yCut_0.6/pT1Cut_%d/pT2Cut_0/Mjj", TriggerCut[i].c_str()), pT1Cut[j], s[i][j]);

      for (int k = 0; k < n2; k++) {
	  f->GetObject("%s/yCut_0.6/pT1Cut_%d/pT2Cut_%d/Mjj", TriggerCut[i].c_str()), pT1Cut[j], pT2Cut[k], m[i][j][k]);
      eff[i][j][k] = new TGraphAsymmErrors();
      mg[i]->Add(eff[i][j][k], "p");	


  for (int i = 0; i < n; i++) {
    // ...
    for (int j = 0; j < n1; j++) {
      if (j != i) continue; // skip unwanted
      // ...
      for (int k = 0; k < n2; k++) {
        if (pT2Cut[k] > pT1Cut[j]) continue; // skip unwanted
        // ...
1 Like

That is exactly what I wanted to do, however I still get errors saying that “error: no matching member function for call to ‘GetObject’”.

Thoroughly compare the lines with “GetObject” for which you do not get these errors with lines for which you get them and fix your source code.

I found my error! Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.