3 #include "AliTestESDtrackCutsSelector.h"
9 #include <TParticlePDG.h>
15 #include <TSelector.h>
20 #include <AliRunLoader.h>
23 #include "esdTrackCuts/AliESDtrackCuts.h"
24 #include "AliPWG0Helper.h"
27 ClassImp(AliTestESDtrackCutsSelector)
29 AliTestESDtrackCutsSelector::AliTestESDtrackCutsSelector() :
36 // Constructor. Initialization of pointers
40 AliTestESDtrackCutsSelector::~AliTestESDtrackCutsSelector()
46 // histograms are in the output list and deleted when the output
47 // list is deleted by the TSelector dtor
50 void AliTestESDtrackCutsSelector::Begin(TTree* tree)
54 AliSelectorRL::Begin(tree);
56 ReadUserObjects(tree);
59 void AliTestESDtrackCutsSelector::ReadUserObjects(TTree* tree)
61 // read the user objects, called from slavebegin and begin
63 if (!fEsdTrackCutsAll && fInput)
64 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsAll")->Clone());
65 if (!fEsdTrackCutsPri && fInput)
66 fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsPri")->Clone());
67 if (!fEsdTrackCutsSec && fInput)
68 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsSec")->Clone());
70 if (!fEsdTrackCutsAll && tree)
71 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsAll"));
72 if (!fEsdTrackCutsPri && tree)
73 fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsPri"));
74 if (!fEsdTrackCutsSec && tree)
75 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsSec"));
77 if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec)
78 AliDebug(AliLog::kError, "ERROR: Could not read esdTrackCutsXXX from input list.");
81 void AliTestESDtrackCutsSelector::SlaveBegin(TTree* tree)
83 // The SlaveBegin() function is called after the Begin() function.
84 // When running with PROOF SlaveBegin() is called on each slave server.
85 // The tree argument is deprecated (on PROOF 0 is passed).
87 AliSelectorRL::SlaveBegin(tree);
89 ReadUserObjects(tree);
92 Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
94 // The Process() function is called for each entry in the tree (or possibly
95 // keyed object in the case of PROOF) to be processed. The entry argument
96 // specifies which entry in the currently loaded tree is to be processed.
97 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
98 // to read either all or the required parts of the data. When processing
99 // keyed objects with PROOF, the object is already loaded and is available
100 // via the fObject pointer.
102 // This function should contain the "body" of the analysis. It can contain
103 // simple or elaborate selection criteria, run algorithms on the data
104 // of the event and typically fill histograms.
106 // WARNING when a selector is used with a TChain, you must use
107 // the pointer to the current TTree to call GetEntry(entry).
108 // The entry is always the local entry number in the current tree.
109 // Assuming that fTree is the pointer to the TChain being processed,
110 // use fTree->GetTree()->GetEntry(entry).
112 if (AliSelectorRL::Process(entry) == kFALSE)
115 // Check prerequisites
117 AliDebug(AliLog::kError, "ESD branch not available");
121 if (!AliPWG0Helper::IsVertexReconstructed(fESD)) {
122 AliDebug(AliLog::kDebug+5, "Vertex is not reconstructed");
126 // check if the esd track cut objects are there
127 if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec) {
128 AliDebug(AliLog::kError, "fEsdTrackCutsXXX not available");
132 // get particle stack
133 AliStack* stack = GetStack();
135 AliDebug(AliLog::kError, "Stack not available");
138 Int_t nPrim = stack->GetNprimary();
140 // ########################################################
141 // loop over esd tracks
142 Int_t nTracks = fESD->GetNumberOfTracks();
144 // count the number of "good" tracks as parameter for vertex reconstruction efficiency
145 for (Int_t t=0; t<nTracks; t++) {
146 AliDebug(AliLog::kDebug+1, Form("ESD Loop: Processing track %d.", t));
148 AliESDtrack* esdTrack = fESD->GetTrack(t);
150 fEsdTrackCutsAll->AcceptTrack(esdTrack);
152 // using the properties of the mc particle
153 Int_t label = TMath::Abs(esdTrack->GetLabel());
155 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
158 TParticle* particle = stack->Particle(label);
160 AliDebug(AliLog::kError, Form("UNEXPECTED: part with label %d not found in stack (track loop).", label));
165 fEsdTrackCutsPri->AcceptTrack(esdTrack);
167 fEsdTrackCutsSec->AcceptTrack(esdTrack);
173 void AliTestESDtrackCutsSelector::SlaveTerminate()
175 // The SlaveTerminate() function is called after all entries or objects
176 // have been processed. When running with PROOF SlaveTerminate() is called
177 // on each slave server.
179 AliSelectorRL::SlaveTerminate();
181 // Add the histograms to the output on each slave server
184 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
188 fOutput->Add(fEsdTrackCutsAll);
189 fOutput->Add(fEsdTrackCutsPri);
190 fOutput->Add(fEsdTrackCutsSec);
193 void AliTestESDtrackCutsSelector::Terminate()
195 // The Terminate() function is the last function to be called during
196 // a query. It always runs on the client, it can be used to present
197 // the results graphically or save the results to file.
199 AliSelectorRL::Terminate();
204 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsAll"));
205 fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsPri"));
206 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsSec"));
208 // check if the esd track cut objects are there
209 if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec) {
210 AliDebug(AliLog::kError, Form("fEsdTrackCutsXXX not available %p %p %p", fEsdTrackCutsAll, fEsdTrackCutsPri, fEsdTrackCutsSec));
214 TFile* file = TFile::Open("trackCuts.root", "RECREATE");
215 fEsdTrackCutsAll->SaveHistograms("esdTrackCutsAll");
216 fEsdTrackCutsPri->SaveHistograms("esdTrackCutsPri");
217 fEsdTrackCutsSec->SaveHistograms("esdTrackCutsSec");