3 #include "AliMultiplicityMCSelector.h"
13 #include <TParticle.h>
18 #include <AliHeader.h>
19 #include <AliGenEventHeader.h>
20 #include <AliMultiplicity.h>
22 #include "esdTrackCuts/AliESDtrackCuts.h"
23 #include "AliPWG0Helper.h"
24 #include "dNdEta/AliMultiplicityCorrection.h"
26 ClassImp(AliMultiplicityMCSelector)
28 AliMultiplicityMCSelector::AliMultiplicityMCSelector() :
34 // Constructor. Initialization of pointers
38 AliMultiplicityMCSelector::~AliMultiplicityMCSelector()
44 // histograms are in the output list and deleted when the output
45 // list is deleted by the TSelector dtor
48 void AliMultiplicityMCSelector::Begin(TTree* tree)
52 AliSelectorRL::Begin(tree);
54 ReadUserObjects(tree);
57 void AliMultiplicityMCSelector::ReadUserObjects(TTree* tree)
59 // read the user objects, called from slavebegin and begin
61 if (!fEsdTrackCuts && fInput)
62 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
64 if (!fEsdTrackCuts && tree)
65 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
68 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
71 void AliMultiplicityMCSelector::SlaveBegin(TTree* tree)
73 // The SlaveBegin() function is called after the Begin() function.
74 // When running with PROOF SlaveBegin() is called on each slave server.
75 // The tree argument is deprecated (on PROOF 0 is passed).
77 AliSelector::SlaveBegin(tree);
79 ReadUserObjects(tree);
81 fMultiplicity = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
84 void AliMultiplicityMCSelector::Init(TTree* tree)
86 // read the user objects
88 AliSelectorRL::Init(tree);
90 // enable only the needed branches
93 tree->SetBranchStatus("*", 0);
94 tree->SetBranchStatus("fTriggerMask", 1);
95 tree->SetBranchStatus("fSPDVertex*", 1);
96 tree->SetBranchStatus("fSPDMult*", 1);
98 //AliESDtrackCuts::EnableNeededBranches(tree);
102 Bool_t AliMultiplicityMCSelector::Process(Long64_t entry)
104 // The Process() function is called for each entry in the tree (or possibly
105 // keyed object in the case of PROOF) to be processed. The entry argument
106 // specifies which entry in the currently loaded tree is to be processed.
107 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
108 // to read either all or the required parts of the data. When processing
109 // keyed objects with PROOF, the object is already loaded and is available
110 // via the fObject pointer.
112 // This function should contain the "body" of the analysis. It can contain
113 // simple or elaborate selection criteria, run algorithms on the data
114 // of the event and typically fill histograms.
116 // WARNING when a selector is used with a TChain, you must use
117 // the pointer to the current TTree to call GetEntry(entry).
118 // The entry is always the local entry number in the current tree.
119 // Assuming that fTree is the pointer to the TChain being processed,
120 // use fTree->GetTree()->GetEntry(entry).
122 if (AliSelectorRL::Process(entry) == kFALSE)
125 // Check prerequisites
128 AliDebug(AliLog::kError, "ESD branch not available");
134 AliDebug(AliLog::kError, "fESDTrackCuts not available");
138 AliHeader* header = GetHeader();
141 AliDebug(AliLog::kError, "Header not available");
145 AliStack* stack = GetStack();
148 AliDebug(AliLog::kError, "Stack not available");
152 if (AliPWG0Helper::IsEventTriggered(fESD) == kFALSE)
155 if (AliPWG0Helper::IsVertexReconstructed(fESD) == kFALSE)
158 // get the ESD vertex
159 const AliESDVertex* vtxESD = fESD->GetVertex();
164 AliGenEventHeader* genHeader = header->GenEventHeader();
166 genHeader->PrimaryVertex(vtxMC);
169 const AliMultiplicity* mult = fESD->GetMultiplicity();
172 AliDebug(AliLog::kError, "AliMultiplicity not available");
176 //const Float_t kPtCut = 0.3;
178 // get number of tracks from MC
179 // loop over mc particles
180 Int_t nPrim = stack->GetNprimary();
182 // tracks in different eta ranges
183 Int_t nMCTracks05 = 0;
184 Int_t nMCTracks10 = 0;
185 Int_t nMCTracks15 = 0;
186 Int_t nMCTracks20 = 0;
187 Int_t nMCTracksAll = 0;
189 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
191 AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
193 TParticle* particle = stack->Particle(iMc);
197 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
201 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
204 //if (particle->Pt() < kPtCut)
207 if (TMath::Abs(particle->Eta()) < 0.5)
210 if (TMath::Abs(particle->Eta()) < 1.0)
213 if (TMath::Abs(particle->Eta()) < 1.5)
216 if (TMath::Abs(particle->Eta()) < 2.0)
220 }// end of mc particle
222 // FAKE: put back vtxMC[2]
223 fMultiplicity->FillGenerated(vtxMC[2], nMCTracks05, nMCTracks10, nMCTracks15, nMCTracks20, nMCTracksAll);
225 Int_t nESDTracks05 = 0;
226 Int_t nESDTracks10 = 0;
227 Int_t nESDTracks15 = 0;
228 Int_t nESDTracks20 = 0;
230 // get multiplicity from ITS tracklets
231 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
233 //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
235 // this removes non-tracklets. Very bad solution. SPD guys are working on better solution...
236 if (mult->GetDeltaPhi(i) < -1000)
239 Float_t theta = mult->GetTheta(i);
240 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
242 if (TMath::Abs(eta) < 0.5)
245 if (TMath::Abs(eta) < 1.0)
248 if (TMath::Abs(eta) < 1.5)
251 if (TMath::Abs(eta) < 2.0)
255 // get multiplicity from ESD tracks
256 /*TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD);
257 Int_t nGoodTracks = list->GetEntries();
258 // loop over esd tracks
259 for (Int_t i=0; i<nGoodTracks; i++)
261 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
264 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
269 esdTrack->GetConstrainedPxPyPz(p); // ### TODO should be okay because we have a vertex, however GetInnerPxPyPy / GetOuterPxPyPy also exist
272 Float_t theta = vector.Theta();
273 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
274 Float_t pt = vector.Pt();
279 if (TMath::Abs(eta) < 0.5)
282 if (TMath::Abs(eta) < 1.0)
285 if (TMath::Abs(eta) < 1.5)
288 if (TMath::Abs(eta) < 2.0)
292 fMultiplicity->FillMeasured(vtxMC[2], nESDTracks05, nESDTracks10, nESDTracks15, nESDTracks20);
294 // TODO should this be vtx[2] or vtxMC[2] ?
295 fMultiplicity->FillCorrection(vtxMC[2], nMCTracks05, nMCTracks10, nMCTracks15, nMCTracks20, nMCTracksAll, nESDTracks05, nESDTracks10, nESDTracks15, nESDTracks20);
300 void AliMultiplicityMCSelector::SlaveTerminate()
302 // The SlaveTerminate() function is called after all entries or objects
303 // have been processed. When running with PROOF SlaveTerminate() is called
304 // on each slave server.
306 AliSelector::SlaveTerminate();
308 // Add the histograms to the output on each slave server
311 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
315 fOutput->Add(fMultiplicity);
318 void AliMultiplicityMCSelector::Terminate()
320 // The Terminate() function is the last function to be called during
321 // a query. It always runs on the client, it can be used to present
322 // the results graphically or save the results to file.
324 AliSelector::Terminate();
326 fMultiplicity = dynamic_cast<AliMultiplicityCorrection*> (fOutput->FindObject("Multiplicity"));
330 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p", (void*) fMultiplicity));
334 TFile* file = TFile::Open("multiplicityMC.root", "RECREATE");
336 fMultiplicity->SaveHistograms();
340 fMultiplicity->DrawHistograms();