Getting an empty canvas

Hi developers,

I am plotting different variables on a canvas. The half part of my macro works good but when I apply cuts on the loop (starting from line 86) it will not draw pt and eta. Kindly see it
I am attaching my macro and path to root file is /afs/cern.ch/user/n/nmajeed/public/May26_2.root


#include <TFile.h>
#include <TTree.h>
#include <TROOT.h>
#include <TH1.h>
#include <TH2.h>
#include <TSystem.h>
#include <vector>
#include <TLorentzVector.h>
#include <math.h>
#include "TMath.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <map>
#include <TFileMerger.h>

void third_ratio()
{
   TFile *f = new TFile("May26_2.root");
   TTree *t = (TTree*)f->Get("demo/AnaTree");
   TH1F *h1 = new TH1F("h1","Z1_mass",100,0,200);
   TH1F *h2 = new TH1F("h2","Z2_mass",100,0,200);
   TH1F *h3 = new TH1F("h3","Z3_mass",100,0,200);
   TH1F *h4 = new TH1F("h4","third_lep_pt",100,0,300);
   TH1F *h5 = new TH1F("h5","third_lep_eta",100,0,2.5);

using namespace std;

Float_t VetoMu_px[1000], VetoMu_py[1000], VetoMu_pz[1000], VetoMu_en[1000], VetoMu_pt[1000], VetoMu_eta[1000], VetoMu_phi[1000], VetoMu_iso[1000];
Int_t VetoMu, VetoMu_charge[1000], VetoMu_ismuon[1000], VetoMu_idTight[1000];

          t->SetBranchAddress("VetoMu_px",VetoMu_px);
          t->SetBranchAddress("VetoMu_py",VetoMu_py);
          t->SetBranchAddress("VetoMu_pz",VetoMu_pz);
          t->SetBranchAddress("VetoMu_en",VetoMu_en);
          t->SetBranchAddress("VetoMu",&VetoMu);
          t->SetBranchAddress("VetoMu_charge",&VetoMu_charge);
          t->SetBranchAddress("VetoMu_pt",VetoMu_pt);
          t->SetBranchAddress("VetoMu_eta",VetoMu_eta);
          t->SetBranchAddress("VetoMu_phi",VetoMu_phi);
          t->SetBranchAddress("VetoMu_idTight",VetoMu_idTight);
          t->SetBranchAddress("VetoMu_ismuon",VetoMu_ismuon);
          t->SetBranchAddress("VetoMu_iso",VetoMu_iso);

TLorentzVector tmp(0,0,0,0), tmp1(0,0,0,0), tmp2(0,0,0,0), tmp3(0,0,0,0);

 for (int i=0;i<10000;i++)   {
        
 TLorentzVector tmp1, tmp2, tmp3;

         t->GetEntry(i);
    
 for(int m=0; m<VetoMu;m++)   {
           
	  if(VetoMu<2)continue;
  
int m1=0, m2=1, m3=2;

if(m1==0) tmp1.SetPxPyPzE(VetoMu_px[m1], VetoMu_py[m1], VetoMu_pz[m1], VetoMu_en[m1]);
if(m2==1) tmp2.SetPxPyPzE(VetoMu_px[m2], VetoMu_py[m2], VetoMu_pz[m2], VetoMu_en[m2]);
if(m3==2) tmp3.SetPxPyPzE(VetoMu_px[m3], VetoMu_py[m3], VetoMu_pz[m3], VetoMu_en[m3]);

if (VetoMu_charge[m1]*VetoMu_charge[m2] < 0.) {

	double z1_mass = (tmp1 + tmp2).M();
}
if (VetoMu_charge[m2]*VetoMu_charge[m3] < 0.) {

	double z2_mass = (tmp2 + tmp3).M();
}
if (VetoMu_charge[m3]*VetoMu_charge[m1] < 0.) {

	double z3_mass = (tmp1 + tmp3).M();
}
//	cout<<"z1 : "<< z1_mass<<endl;
//	cout<<"z2 :"<< z2_mass<<endl;
//	cout<< "z3 : "<<z3_mass<<endl;

         t->Fill();
         h1->Fill(z1_mass);
//         h2->Fill(z2_mass);
//         h3->Fill(z3_mass);

//      for(int m3=2; m3<VetoMu;m3++) {
//double VetoMu_pt, VetoMu_eta;
{  
        TLorentzVector tmp;
          if(VetoMu_pt[m3] < 20 ) continue;
          if(VetoMu_eta[m3] > 2.5 ) continue;
          if(VetoMu_idTight[m3] == 0) continue;
          if(VetoMu_iso[m3] > 0.12) continue;
          if(VetoMu_ismuon[m3]  == 0) continue;
          tmp.SetPtEtaPhiE(VetoMu_pt[m3], VetoMu_eta[m3], VetoMu_phi[m3], VetoMu_en[m3]);
        cout<<"pt : "<< VetoMu_pt<<endl;
        cout<<"eta : "<< VetoMu_eta<<endl;
          t->Fill();
 //         h4->Fill(VetoMu_pt);
 //         h5->Fill(VetoMu_eta);

}        
}
}       
        TCanvas *c1 = new TCanvas("c1","c1",800,600) ;
        c1->Divide(2,2); 
  	c1->cd(1);
        h1->Draw();
        h1->GetXaxis()->SetTitle("Z_12_mass");
/*        c1->cd(2);
        h2->Draw();
        h2->GetXaxis()->SetTitle("Z_23_mass");
  	c1->cd(3);
        h3->Draw();
        h3->GetXaxis()->SetTitle("Z_31_mass");

c1->SaveAs("Z_mass_VetoMu_LV.png");
*/

//Third Lepton


/*      for(int m3=2; m3<VetoMu;m3++) {
        
          TLorentzVector tmp;
          if(VetoMu_pt[m3] < 20 ) continue;
          if(VetoMu_eta[m3]) > 2.5 ) continue;
          if(VetoMu_idTight[m3] == 0) continue;
          if(VetoMu_iso[m3] > 0.12) continue;
          if(VetooMu_ismuon[m3]  == 0) continue;
          tmp.SetPtEtaPhiE(VetoMu_pt[m3], VetoMu_eta[m3], VetoMu_phi[m3], VetoMu_en[m3]);

          h4->Fill(VetoMu_pt,wgt);
          h5->Fill(VetoMu_eta;wgt);
*/
          c1->cd(2);
	  h4->Draw("VetoMu_pt");
          h4->GetXaxis()->SetTitle("third_lep_pt");
          c1->cd(3);
	  h5->Draw("VetoMu_eta");
          h5->GetXaxis()->SetTitle("third_lep_eta");


}

cheers,
Nab

You are not using the right syntax to draw an histogram with cut. You need to enclose the cut name between square brackets.

I want to draw only the lepton left with m3.

you do:

 h4->Draw("VetoMu_pt");

you should do:

 h4->Draw("[VetoMu_pt]");

I am getting again the same results i.e empty canvas.

You macro has a problem:

root [0] 
Processing third_ratio.C...
In file included from input_line_13:1:
/Users/couet/roottest/third_ratio.C:80:19: error: use of undeclared identifier 'z1_mass'
         h1->Fill(z1_mass);
                  ^
/Users/couet/roottest/third_ratio.C:81:19: error: use of undeclared identifier 'z2_mass'
         h2->Fill(z2_mass);
                  ^
/Users/couet/roottest/third_ratio.C:82:19: error: use of undeclared identifier 'z3_mass'
         h3->Fill(z3_mass);

But these variables are plotted and I get a plot

I see …
cut in the Draw method for 2d histogram must be graphical cut … there is not connection between
the histogram and the original tree … only graphical cut can work,

What will be the graphical cut?

What will be the graphical cut?

I have no idea … It is your data set … you should know …

The way to define a graphical cut is shown in the example here:

https://root.cern/doc/master/classTHistPainter.html#HP24

Well, I will try to correct it. Thank you

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