Hi,
I am having the following problem which I didn’t manage to solve:
I have generated p p > t t~ events width madgraph (which are in the unweighted_events.root file in attach) and I am writing a Macro to analyze it.
I manage to reconstruct a variable, top PT, and to plot it but the resulting plot contains in y axis the number of events/bin instead than a cs/bin.
I read the manuals and I found that I should fill the istograms in the following way
myhistogram->Fill(PT,weight);
where weight should be in
*............................................................................*
*Br 6 :Event.Weight : Double_t Weight[Event_] *
*Entries : 100 : Total Size= 1869 bytes File Size = 284 *
*Baskets : 1 : Basket Size= 64000 bytes Compression= 4.53 *
*............................................................................*
.
This part looks very similar to
*............................................................................*
*Br 22 :Particle.Pz : Double_t Pz[Particle_] *
*Entries : 100 : Total Size= 4270 bytes File Size = 3422 *
*Baskets : 1 : Basket Size= 64000 bytes Compression= 1.08 *
*............................................................................*
so I have tried to access it in the same way (see code below), but If I uncomment line 94
eventweightBranch_1->GetEntry(i_1);
I get an error " *** Break *** segmentation violation".
Does anybody know what I am doing wrong?
Thanks in advance
Daniele
[code]#include “TFile.h”
#include “TTree.h”
#include “TBranch.h”
#include “TH1F.h”
const Int_t kMaxfParticles = 500000;
// select file to analyze
const char* file1name=“unweighted_events.root”;
void Analysis_example_twofiles()
{
// List of branches (1file)
TBranch *nParticlesBranch_1;
TBranch *particlesPIDBranch_1;
TBranch *particlesStatusBranch_1;
TBranch *particlesMassBranch_1;
TBranch *particlesPXBranch_1;
TBranch *particlesPYBranch_1;
TBranch *particlesPZBranch_1;
TBranch *eventweightBranch_1;
// // // // // // // Declaration of leaf types 1 file
Int_t nParticles_1;
Int_t particlesPID_1[kMaxfParticles];
Int_t particlesStatus_1[kMaxfParticles];
Double_t particlesMass_1[kMaxfParticles];
Double_t particlesPX_1[kMaxfParticles];
Double_t particlesPY_1[kMaxfParticles];
Double_t particlesPZ_1[kMaxfParticles];
Double_t eventweight_1[kMaxfParticles];
// define canvas
TCanvas *c1 = new TCanvas(“c1”,“Histogram”,500,400);
//Defining Custom variables
Double_t PT;
// open the 1 file
TFile *f_1 = TFile::Open(file1name);
if (f_1 == 0) {
// if we cannot open the file, print an error message and return immediatly
printf(“Error: cannot open 1th file\n”);
return;
}
// get a pointer to the tree for the 1 file
TTree *tree_1 = (TTree *)f_1->Get(“LHEF”);
// To use SetBranchAddress() with simple types (e.g. double, int)
// instead of objects (e.g. std::vector).
tree_1->SetMakeClass(1);
// // // // // //
// Connect the branches with their member variables, 1 file
tree_1->SetBranchAddress(“Particle”, &nParticles_1, &nParticlesBranch_1);
tree_1->SetBranchAddress(“Particle.PID”, particlesPID_1, &particlesPIDBranch_1);
tree_1->SetBranchAddress(“Particle.Status”, particlesStatus_1, &particlesStatusBranch_1);
tree_1->SetBranchAddress(“Particle.M”, particlesMass_1, &particlesMassBranch_1);
tree_1->SetBranchAddress(“Particle.Px”, particlesPX_1, &particlesPXBranch_1);
tree_1->SetBranchAddress(“Particle.Py”, particlesPY_1, &particlesPYBranch_1);
tree_1->SetBranchAddress(“Particle.Pz”, particlesPZ_1, &particlesPZBranch_1);
tree_1->SetBranchAddress(“Event.Weight”, eventweight_1, &eventweightBranch_1);
// // // // // //
// Defining Histograms
hPT = new TH1F(“hPTtop”, “”, 50, -500, 500);
// // // // // //
// Get the number of entries
Long64_t nentries_1 = tree_1->GetEntries();
//---------------------------------------------------//
//------ ANALYSIS PART --------//
//---------------------------------------------------//
// 1 FILE
Double_t cs;
printf("#----------------------------#\n");
for (Long64_t i_1=0;i_1<nentries_1;i_1++) {
printf(“Event n. %d\n”,i_1+1);
//event weight
eventweightBranch_1->GetEntry(i_1);
//number of particles in each event
nParticlesBranch_1->GetEntry(i_1);
//particle PID
particlesPIDBranch_1->GetEntry(i_1);
//status
particlesStatusBranch_1->GetEntry(i_1);
//mass
particlesMassBranch_1->GetEntry(i_1);
//pz
particlesPZBranch_1->GetEntry(i_1);
//px
particlesPXBranch_1->GetEntry(i_1);
//py
particlesPYBranch_1->GetEntry(i_1);
for(int iParticle_1 = 0; iParticle_1 < nParticles_1; ++iParticle_1){
PT=sqrt(particlesPX_1[iParticle_1]*2+particlesPY_1[iParticle_1]**2);
if(particlesStatus_1[iParticle_1]==1){
printf("Particles number %d, PID=%d, mass=%d and status=%d and Px=%d and Py=%d and Pz=%d and PT=%d\n",iParticle_1+1,particlesPID_1[iParticle_1],particlesMass_1[iParticle_1],particlesStatus_1[iParticle_1],particlesPX_1[iParticle_1],particlesPY_1[iParticle_1],particlesPZ_1[iParticle_1],PT);
if(particlesPID_1[iParticle_1]==6){
hPT->Fill(PT);
}
}
}
printf("#----------------------------#\n");
}
hPT->Draw();
c1->Update();
c1->SaveAs(“example.eps”);
}
[/code]
unweighted_events.root (34.4 KB)