+/* $Id$ */
+
// The class definition in esdV0.h has been generated automatically
// by the ROOT utility TTree::MakeSelector(). This class is derived
// from the ROOT class TSelector. For more information on the TSelector
//
#include "AliSelector.h"
+
#include <TStyle.h>
#include <TSystem.h>
#include <TCanvas.h>
#include <TRegexp.h>
-
+#include <TTime.h>
+#include <TParticle.h>
+#include <TParticlePDG.h>
#include <TFriendElement.h>
+#include <TTree.h>
+#include <TChain.h>
+#include <TFile.h>
-#include <iostream>
-using namespace std;
+#include <AliLog.h>
+#include <AliESD.h>
ClassImp(AliSelector)
-AliSelector::AliSelector(TTree *) :
+AliSelector::AliSelector() :
TSelector(),
- fChain(0),
+ fTree(0),
fESD(0),
- fHeader(0),
- fRunLoader(0),
+ fCountFiles(0),
fKineFile(0)
{
+ //
// Constructor. Initialization of pointers
+ //
+
+ AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
}
AliSelector::~AliSelector()
{
- // Remove all pointers
+ //
+ // Destructor
+ //
// histograms are in the output list and deleted when the output
// list is deleted by the TSelector dtor
}
-void AliSelector::Begin(TTree *)
+void AliSelector::Begin(TTree*)
{
// The Begin() function is called at the start of the query.
// When running with PROOF Begin() is only called on the client.
// The tree argument is deprecated (on PROOF 0 is passed).
-
- //TString option = GetOption();
}
-void AliSelector::SlaveBegin(TTree * tree)
+void AliSelector::SlaveBegin(TTree* tree)
{
// The SlaveBegin() function is called after the Begin() function.
// When running with PROOF SlaveBegin() is called on each slave server.
// The tree argument is deprecated (on PROOF 0 is passed).
- Init(tree);
-
- printf("=======SLAVEBEGIN========\n");
- gSystem->Exec("hostname");
- gSystem->Exec("date");
- TFile *f = fChain->GetCurrentFile();
- printf("%s\n",f->GetName());
+ AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
+ AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+ AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
- TString option = GetOption();
+ if (tree != 0)
+ Init(tree);
}
void AliSelector::Init(TTree *tree)
// generated code, but the routine can be extended by the user if needed.
// Init() will be called many times when running with PROOF.
- printf("=========Init==========\n");
+ AliDebug(AliLog::kDebug, "=========Init==========");
- // Set branch addresses
- if (tree == 0)
- {
- printf("ERROR: tree argument is 0.\n");
- return;
- }
+ fTree = tree;
- fChain = dynamic_cast<TChain*> (tree);
- if (fChain == 0)
+ if (fTree == 0)
{
- printf("ERROR: tree argument could not be casted to TChain.\n");
+ AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
return;
}
- fChain->SetBranchAddress("ESD", &fESD);
+ // Set branch address
+ fTree->SetBranchAddress("ESD", &fESD);
if (fESD != 0)
- printf("INFO: Found ESD branch in chain.\n");
-
- fChain->SetBranchAddress("Header", &fHeader);
- if (fHeader != 0)
- printf("INFO: Found event header branch in chain.\n");
-
+ AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
}
Bool_t AliSelector::Notify()
// to the generated code, but the routine can be extended by the
// user if needed.
- printf("=========NOTIFY==========\n");
- gSystem->Exec("hostname");
- gSystem->Exec("date");
- TFile *f = fChain->GetCurrentFile();
- TString fileName(f->GetName());
- printf("%s\n",fileName.Data());
+ AliDebug(AliLog::kDebug, "=========NOTIFY==========");
+ AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+ AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
+
+ ++fCountFiles;
+ if (fTree)
+ {
+ TFile *f = fTree->GetCurrentFile();
+ AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
+ }
+ else
+ {
+ AliDebug(AliLog::kError, "fTree not available");
+ }
DeleteKinematicsFile();
- DeleteRunLoader();
return kTRUE;
}
// WARNING when a selector is used with a TChain, you must use
// the pointer to the current TTree to call GetEntry(entry).
// The entry is always the local entry number in the current tree.
- // Assuming that fChain is the pointer to the TChain being processed,
- // use fChain->GetTree()->GetEntry(entry).
+ // Assuming that fTree is the pointer to the TChain being processed,
+ // use fTree->GetTree()->GetEntry(entry).
- printf("=========PROCESS========== Entry %lld\n", entry);
+ AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
- if (!fChain)
+ if (!fTree)
{
- printf("ERROR: fChain is 0.\n");
+ AliDebug(AliLog::kError, "ERROR: fTree is 0.");
return kFALSE;
}
- fChain->GetTree()->GetEntry(entry);
+ fTree->GetTree()->GetEntry(entry);
+ /*
+ // debugging
if (fESD)
- printf("ESD: We have %d tracks.\n", fESD->GetNumberOfTracks());
+ AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
if (fHeader)
- printf("Header: We have %d primaries.\n", fHeader->GetNprimary());
+ AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
TTree* kinematics = GetKinematics();
if (kinematics)
- printf("Kinematics from folder: We have %lld particles.\n", kinematics->GetEntries());
-
- printf("\n");
+ AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
+ */
return kTRUE;
}
// on each slave server.
DeleteKinematicsFile();
- DeleteRunLoader();
}
void AliSelector::Terminate()
// a query. It always runs on the client, it can be used to present
// the results graphically or save the results to file.
- printf("=========TERMINATE==========\n");
+ AliDebug(AliLog::kDebug, "=========TERMINATE==========");
}
TTree* AliSelector::GetKinematics()
{
+ // Returns kinematics tree corresponding to current ESD active in fTree
+ // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
+ // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
+
if (!fKineFile)
{
- if (!fChain->GetCurrentFile())
+ if (!fTree->GetCurrentFile())
return 0;
- TString fileName(fChain->GetCurrentFile()->GetName());
+ TString fileName(fTree->GetCurrentFile()->GetName());
fileName.ReplaceAll("AliESDs", "Kinematics");
+ AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
+
fKineFile = TFile::Open(fileName);
if (!fKineFile)
return 0;
}
- return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
-
- /* this is if we want to get it from a TChain
-
- define it in the header:
-
- TChain* fKineChain;
-
- this creates the chain:
-
- TChain* chainKine = new TChain("TreeK");
- for (Int_t i=0; i<20; ++i)
- chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
- for (Int_t i=0; i<20; ++i)
- chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
-
- <mainChain>->GetUserInfo()->Add(chainKine);
-
- we retrieve it in init:
-
- fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
-
- and use it in process:
-
- if (fKineChain)
- {
- Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
- cout << "Entry in fKineChain: " << entryK << endl;
- fKineChain->LoadTree(entryK);
- TTree* kineTree = fKineChain->GetTree();
-
- printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
- }
- */
+ return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
}
void AliSelector::DeleteKinematicsFile()
{
+ //
+ // Closes the kinematics file and deletes the pointer.
+ //
+
if (fKineFile)
{
fKineFile->Close();
}
}
-AliRun* AliSelector::GetAliRun()
+Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
{
- if (!fRunLoader)
+ //
+ // Returns if the given particle is a primary particle
+ // This function or a equivalent should be available in some common place of AliRoot
+ //
+
+ // if the particle has a daughter primary, we do not want to count it
+ if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
{
- if (!fChain->GetCurrentFile())
- return 0;
+ AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
+ return kFALSE;
+ }
- TString fileName(fChain->GetCurrentFile()->GetName());
- fileName.ReplaceAll("AliESDs", "galice");
+ Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
- fRunLoader = AliRunLoader::Open(fileName);
- if (!fRunLoader)
- return 0;
+ // skip quarks and gluon
+ if (pdgCode <= 10 || pdgCode == 21)
+ {
+ AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
+ return kFALSE;
+ }
- fRunLoader->LoadgAlice();
+ if (strcmp(aParticle->GetName(),"XXX") == 0)
+ {
+ AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
+ return kFALSE;
}
- return fRunLoader->GetAliRun();
-}
+ TParticlePDG* pdgPart = aParticle->GetPDG();
-void AliSelector::DeleteRunLoader()
-{
- if (fRunLoader)
+ if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
{
- fRunLoader->Delete();
- fRunLoader = 0;
+ AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
+ return kFALSE;
}
+
+ if (pdgPart->Charge() == 0)
+ {
+ return kFALSE;
+ AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged.");
+ }
+
+ return kTRUE;
}