I did something in one code that worked and I can’t get it to work in another.
Where it worked:
I have a file with many branches with information of many events, recently I was tasked with graphing the momentum of only the electrons, I did this and it worked:
tree->Draw("lepP4.Px()","lepPdgId>abs(11)");
For what I understand lepP4 has data of all leptons, and the branch Px has the momentum in the x direction of all leptons, and when I say “lepPdgId>abs(11)” it specifies that I only want electrons or antielectrons, since their identifiers are 11 and -11.
Where it doesn’t work yet:
I have to put that same data of momentum in a vector, and that is almost done:
// All libraries you could wish for
#include <iostream> // class for inputoutput streams
#include <stdio.h> // printf, scanf, puts, NULL
#include <stdlib.h> // srand, rand, atof
#include <time.h> // time
#include <fstream> // class for inputoutput file streams
#include <dirent.h>
#include <string.h> // class to manipulate strings
#include <sstream> // class for parsing strings
#include <vector>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TH1F.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TPaveStats.h>
#include <TPad.h>
#include <TMath.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TLegend.h>
#include <TString.h>
#include <TGraph.h>
#include <TLatex.h>
#include <unistd.h>
#define GetCurrentDir getcwd
#include <TTree.h>
#include "Math/SMatrix.h"
using namespace std;
// using namespace TMath;
int main(int argc, char* argv[])
{
TFile* file = TFile::Open("/Users/Fer/Documents/traajo/samples/NeroNtuples_9.root"); // TFile::Open() instead of a constructor since it works over xrootd etc.
TTree *tree=(TTree*)file->Get("nero/events");
int nentries = tree->GetEntries(); // Get the number of entries
ROOT::Math::SVector<double, 418886> px;
double ievento;
tree->SetBranchAddress("lepP4.Px()","lepPdgId>abs(11)",&ievento); // Tell the tree which branch you want to be read into which variable
for(int ientry = 0; ientry < nentries; ientry++) // Now you can loop over each entry in the TTree
{
tree->GetEntry(ientry); // Fetch the entry... this will change the value of variable1 and variable2
// Do whatever you want with each event in here
px[ientry]=ievento;
}
cout<<px;
return 0;
}
That’s the whole code, and the problem lies on the SetBranchAddress method, because I wanted to specify that I wanted the electrons and antielectrons data in the same way but it doesn’t work, and I don’t know what to do, I’ve tried to read about the method but I can’t find what I need.
Thanks a lot