#include "SampleAnalyzer/User/Analyzer/user_1.h"
#include <iostream>
usingnamespace MA5;
usingnamespace std;
// -----------------------------------------------------------------------------
// Initialize
// function called one time at the beginning of the analysis
// -----------------------------------------------------------------------------
bool user_1::Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters)
{
cout << "BEGIN Initialization" << endl;
// initialize variables, histos
// Initializing PhysicsService for MC
PHYSICS->mcConfig().Reset();
// definition of the multiparticle "hadronic"
PHYSICS->mcConfig().AddHadronicId(-5);
PHYSICS->mcConfig().AddHadronicId(-4);
PHYSICS->mcConfig().AddHadronicId(-3);
PHYSICS->mcConfig().AddHadronicId(-2);
PHYSICS->mcConfig().AddHadronicId(-1);
PHYSICS->mcConfig().AddHadronicId(1);
PHYSICS->mcConfig().AddHadronicId(2);
PHYSICS->mcConfig().AddHadronicId(3);
PHYSICS->mcConfig().AddHadronicId(4);
PHYSICS->mcConfig().AddHadronicId(5);
PHYSICS->mcConfig().AddHadronicId(21);
// definition of the multiparticle "invisible"
PHYSICS->mcConfig().AddInvisibleId(-16);
PHYSICS->mcConfig().AddInvisibleId(-14);
PHYSICS->mcConfig().AddInvisibleId(-12);
PHYSICS->mcConfig().AddInvisibleId(12);
PHYSICS->mcConfig().AddInvisibleId(14);
PHYSICS->mcConfig().AddInvisibleId(16);
PHYSICS->mcConfig().AddInvisibleId(1000022);
// Initializing each selection item
myHisto = new TH1F("mTTbar", "mTTbar", 100, 0.0, 1000.0);
cout << "END Initialization" << endl;
returntrue;
}
void user_1::Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files)
{
cout << "BEGIN Finalization" << endl;
// Saving histogram
TFile *myOutput = new TFile ("output.root","RECREATE");
myOutput->cd();
myHisto->Write();
cout << "END Finalization" << endl;
}
// -----------------------------------------------------------------------------
// Execute
// function called each time one event is read
// -----------------------------------------------------------------------------
bool user_1::Execute(SampleFormat& sample, const EventFormat& event)
{
// ***************************************************************************
// Example of analysis with generated particles
// Concerned samples : LHE/STDHEP/HEPMC
// ***************************************************************************
cout << "---------------NEW EVENT-------------------" << endl;
unsignedint n = event.mc()->particles().size();
for (unsignedint i=0;i<n;i++)
{
const MCParticleFormat* prt = &event.mc()->particles()[i]; //prt é um objecto da classe MCParticleFormat
if (const MCParticleFormat.pdgid() = 6000006) //corre se o pdgid for 6000006
{
myHisto->Fill(prt->m());
}
}
returntrue
}
When I try "make" in Build directory it gives the following error:
1 2 3 4 5 6 7 8 9
SampleAnalyzer/User/Analyzer/user_1.cpp: In member function ‘virtualbool MA5::user_1::Execute(MA5::SampleFormat&, const MA5::EventFormat&)’:
SampleAnalyzer/User/Analyzer/user_1.cpp:108:12: error: expected primary-expression before ‘const’
if (const MCParticleFormat.pdgid() = 6000006) //corre se o pdgid for 6000006
^
SampleAnalyzer/User/Analyzer/user_1.cpp:108:12: error: expected ‘)’ before ‘const’
SampleAnalyzer/User/Analyzer/user_1.cpp:115:1: error: expected ‘;’ before ‘}’ token
}
^
make: *** [SampleAnalyzer/User/Analyzer/user_1.o] Error 1
¿why did you write const there?
= is assignment, == is comparison.
if (MCParticleFormat.pdgid() == 6000006)
Edit: just notice that `MCParticleFormat' is the name of a class
however `pdgid()' is a message that you would send to an object (¿what object do you want to operate on?)
bool user_1::Execute(SampleFormat& sample, const EventFormat& event)
{
unsignedint n = event.mc()->particles().size();
for (unsignedint i=0;i<n;i++)
{
const MCParticleFormat* prt = &event.mc()->particles()[i];
if ( prt==0 or prt->pdgid() not_eq 6000006)
continue; //would stop this iteration and continue with the next one
myHisto->Fill(prt->m());
}
returntrue;
}