#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 <AliLog.h>
+#include <AliESD.h>
ClassImp(AliSelector)
AliSelector::AliSelector() :
TSelector(),
- fChain(0),
+ fTree(0),
fESD(0),
fCountFiles(0),
- fKineFile(0),
- fHeaderFile(0),
- fHeaderTree(0),
- fHeader(0)
+ fKineFile(0)
{
//
// Constructor. Initialization of pointers
//
+
+ AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
}
AliSelector::~AliSelector()
// 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).
}
-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);
-
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)
AliDebug(AliLog::kDebug, "=========Init==========");
- // Set branch addresses
- if (tree == 0)
- {
- AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
- return;
- }
+ fTree = tree;
- fChain = dynamic_cast<TChain*> (tree);
- if (fChain == 0)
+ if (fTree == 0)
{
- AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
+ AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
return;
}
- fChain->SetBranchAddress("ESD", &fESD);
+ // Set branch address
+ fTree->SetBranchAddress("ESD", &fESD);
if (fESD != 0)
AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
-
- /*fChain->SetBranchAddress("Header", &fHeader);
- if (fHeader != 0)
- AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");*/
}
Bool_t AliSelector::Notify()
AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
++fCountFiles;
- TFile *f = fChain->GetCurrentFile();
- AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
+ 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();
- DeleteHeaderFile();
-
- /*TChain* headerChain = dynamic_cast<TChain*> (((TFriendElement*) fChain->GetListOfFriends()->First())->GetTree());
- AliDebug(AliLog::kInfo, Form("Header File: %s", headerChain->GetCurrentFile()->GetName()));*/
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).
AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
- if (!fChain)
+ if (!fTree)
{
- AliDebug(AliLog::kError, "ERROR: fChain is 0.");
+ AliDebug(AliLog::kError, "ERROR: fTree is 0.");
return kFALSE;
}
- fChain->GetTree()->GetEntry(entry);
+ fTree->GetTree()->GetEntry(entry);
/*
// debugging
// on each slave server.
DeleteKinematicsFile();
- DeleteHeaderFile();
}
void AliSelector::Terminate()
TTree* AliSelector::GetKinematics()
{
- // Returns kinematics tree corresponding to current ESD active in fChain
+ // 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()));
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()
fKineFile = 0;
}
}
-
-AliHeader* AliSelector::GetHeader()
-{
- // Returns header corresponding to current ESD active in fChain
- // Loads the header from galice.root, the file is identified by replacing "AliESDs" to
- // "galice" in the file path of the ESD file. This is a hack, to be changed!
-
- if (!fHeaderFile || !fHeaderTree)
- {
- if (!fChain->GetCurrentFile())
- return 0;
-
- TString fileName(fChain->GetCurrentFile()->GetName());
- fileName.ReplaceAll("AliESDs", "galice");
-
- AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
-
- fHeaderFile = TFile::Open(fileName);
- if (!fHeaderFile)
- return 0;
-
- fHeaderTree = dynamic_cast<TTree*> (fHeaderFile->Get("TE"));
- if (!fHeaderTree)
- return 0;
-
- fHeaderTree->SetBranchAddress("Header", &fHeader);
- }
-
- fHeaderTree->GetEntry(fChain->GetTree()->GetReadEntry());
-
- return fHeader;
-}
-
-void AliSelector::DeleteHeaderFile()
-{
- //
- // Closes the kinematics file and deletes the pointer.
- //
-
- if (fHeaderFile)
- {
- fHeaderFile->Close();
- delete fHeaderFile;
- fHeaderTree = 0;
- fHeader = 0;
- }
-}
-
-Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
-{
- //
- // 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)
- {
- AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
- return kFALSE;
- }
-
- Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
-
- // skip quarks and gluon
- if (pdgCode <= 10 || pdgCode == 21)
- {
- AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
- return kFALSE;
- }
-
- if (strcmp(aParticle->GetName(),"XXX") == 0)
- {
- AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
- return kFALSE;
- }
-
- TParticlePDG* pdgPart = aParticle->GetPDG();
-
- if (strcmp(pdgPart->ParticleClass(),"Unknown") == 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;
-}