AliPhysics  vAN-20150425 (2dcf1b0)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliReducedHighPtEventCreator.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2015, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <map>
16 #include <vector>
17 
18 #include <TArrayD.h>
19 #include <TArrayI.h>
20 #include <TClonesArray.h>
21 #include <TMath.h>
22 #include <TObjArray.h>
23 #include <TString.h>
24 #include <TTree.h>
25 
26 #include "AliAnalysisUtils.h"
27 #include "AliAODEvent.h"
28 #include "AliAODMCParticle.h"
29 #include "AliAODTrack.h"
30 #include "AliCentrality.h"
31 #include "AliESDEvent.h"
32 #include "AliESDtrack.h"
33 #include "AliInputEventHandler.h"
34 #include "AliLog.h"
35 #include "AliMCEvent.h"
36 #include "AliPicoTrack.h"
37 #include "AliStack.h"
38 #include "AliVCluster.h"
39 #include "AliVEvent.h"
40 #include "AliVTrack.h"
41 #include "AliVVertex.h"
42 #include "AliEmcalTriggerPatchInfo.h"
43 
45 #include "AliReducedEmcalCluster.h"
47 #include "AliReducedHighPtEvent.h"
48 #include "AliReducedMCHeader.h"
50 #include "AliReducedPatchInfo.h"
53 
55 ClassImp(HighPtTracks::AliReducedTrackSelectionContainer)
56 ClassImp(HighPtTracks::AliReducedHighPtEventCreator)
58 
59 namespace HighPtTracks {
60 
64 AliReducedHighPtEventCreator::AliReducedHighPtEventCreator():
65  AliAnalysisTaskEmcal(),
66  fOutputTree(NULL),
67  fOutputEvent(NULL),
68  fTrackSelections(NULL),
69  fSwapTriggerThresholds(kFALSE),
70  fMinClusterE(-1),
71  fMaxClusterE(1000),
72  fMinPt(-1),
73  fMaxPt(1000),
74  fMinEta(-1000),
75  fMaxEta(1000),
76  fCentralityMethod("V0A")
77 {
78 
79 }
80 
85 AliReducedHighPtEventCreator::AliReducedHighPtEventCreator(const char* name):
86  AliAnalysisTaskEmcal(name, kTRUE),
87  fOutputTree(NULL),
88  fOutputEvent(NULL),
89  fTrackSelections(NULL),
90  fSwapTriggerThresholds(kFALSE),
91  fMinClusterE(-1),
92  fMaxClusterE(1000),
93  fMinPt(-1),
94  fMaxPt(1000),
95  fMinEta(-1000),
96  fMaxEta(1000),
97  fCentralityMethod("V0A")
98 {
99  DefineOutput(2, TTree::Class());
100 
101  fTrackSelections = new TObjArray;
102  fTrackSelections->SetOwner(kTRUE);
103 }
104 
108 AliReducedHighPtEventCreator::~AliReducedHighPtEventCreator() {
109  if(fTrackSelections) delete fTrackSelections;
110 }
111 
115 void AliReducedHighPtEventCreator::UserCreateOutputObjects() {
116  AliAnalysisTaskEmcal::UserCreateOutputObjects();
117  OpenFile(2);
118 
119  fOutputTree = new TTree("ReducedEvent", "A simple reduced event");
120  fOutputEvent = new AliReducedHighPtEvent();
121  fOutputTree->Branch("ReducedEvent", "AliReducedHighPtEvent", fOutputEvent, 128000, 0);
122 
123  PostData(1, fOutput);
124  PostData(2, fOutputTree);
125 }
126 
137 Bool_t AliReducedHighPtEventCreator::Run() {
138  if(!fCaloClusters){
139  AliError("Cluster container missing");
140  return kFALSE;
141  }
142  if(!fTracks){
143  AliError("Track container missing");
144  return kFALSE;
145  }
146  if(!SelectEvent(fInputEvent)) return kFALSE;
147  new(fOutputEvent) AliReducedHighPtEvent(kTRUE);
148 
149  // Write event specific information
150  fOutputEvent->SetVertexZ(fInputEvent->GetPrimaryVertex()->GetZ());
151  AliCentrality *centralityHandler = fInputEvent->GetCentrality();
152  if(centralityHandler) fOutputEvent->SetCentralityPercentile(centralityHandler->GetCentralityPercentile(fCentralityMethod.Data()));
153  ConvertTriggerPatches(fTriggerPatchInfo, fOutputEvent->GetPatchContainer());
154  TString triggerString(fInputEvent->GetFiredTriggerClasses());
155  fOutputEvent->SetDecisionFromTriggerString(triggerString.Contains("EG1"), triggerString.Contains("EG2"), triggerString.Contains("EJ1"), triggerString.Contains("EJ2"));
156  fOutputEvent->SetMinBiasEvent(fInputHandler->IsEventSelected() & AliVEvent::kINT7);
157 
158  std::map<int, int> mcindexmap;
159  if(MCEvent()){
160  // Generate Monte-Carlo header
161  AliReducedMCHeader *mcheader = new AliReducedMCHeader();
162  if(fIsPythia){
163  mcheader->SetCrossSection(fXsection);
164  mcheader->SetNumberOfTrials(fNTrials);
165  mcheader->SetPtHard(fPtHard);
166  }
167  fOutputEvent->SetMonteCarloHeader(mcheader);
168 
169  // Convert Monte Carlo particles, fill index map
170  AliMCEvent *mcev = MCEvent();
171  int npart(0);
172  for(Int_t ipart = 0; ipart < mcev->GetNumberOfTracks(); ipart++){
173  AliVParticle *part = mcev->GetTrack(ipart);
174  Double_t pt(TMath::Abs(part->Pt())), eta(part->Eta());
175  if(pt < fMinPt || pt > fMaxPt) continue;
176  if(eta < fMinEta || eta > fMaxEta) continue;
177  if(!part->Charge()) continue;
178  if(part->IsA() == AliAODMCParticle::Class()){
179  AliAODMCParticle *aodpart = static_cast<AliAODMCParticle *>(part);
180  if(!aodpart->IsPhysicalPrimary()) continue;
181  } else {
182  // ESD - get information from stack
183  if(!mcev->Stack()->IsPhysicalPrimary(ipart)) continue;
184  }
185 
186  AliReducedGeneratedParticle *reducedgen = new AliReducedGeneratedParticle(npart, part->PdgCode(), part->Px(), part->Py(), part->Pz(), part->E());
187  fOutputEvent->AddReducedGeneratedParticle(reducedgen);
188  mcindexmap.insert(std::pair<int,int>(ipart, npart));
189  npart++;
190  }
191  }
192 
193  // Filter Clusters
194  std::map<int, int> clusterindexmap;
195  int ncluster(0);
196  Double_t vtxpos[3];fInputEvent->GetPrimaryVertex()->GetXYZ(vtxpos);
197  for(TIter cliter = TIter(fCaloClusters).Begin(); cliter != TIter::End(); ++cliter){
198  AliVCluster *incluster = static_cast<AliVCluster *>(*cliter);
199  if(!SelectCluster(incluster)) continue;
200  TLorentzVector clustervec;
201  incluster->GetMomentum(clustervec, vtxpos);
202  AliReducedEmcalCluster *redcluster = new AliReducedEmcalCluster(ncluster, incluster->E(), clustervec.Eta(), clustervec.Phi(), incluster->GetM02(), incluster->GetM20());
203  // Get leading 3 cell energies
204  TArrayD cellEnergies;
205  GetCellEnergies(incluster, cellEnergies);
206  TArrayI indices(cellEnergies.GetSize());
207  TMath::Sort(cellEnergies.GetSize(), cellEnergies.GetArray(), indices.GetArray(), kTRUE);
208  redcluster->SetLeadingCellEnergies(
209  cellEnergies[indices[0]],
210  cellEnergies.GetSize() > 1 ? cellEnergies[indices[1]] : 0,
211  cellEnergies.GetSize() > 2 ? cellEnergies[indices[2]] : 0
212  );
213  // Assing MC particles
214  if(MCEvent()){
215  for(Int_t ilab = 0; ilab < incluster->GetNLabels(); ilab++){
216  AliVParticle *assigned = MCEvent()->GetTrack(TMath::Abs(incluster->GetLabels()[ilab]));
217  if(!assigned) continue;
218  redcluster->AddTrueContributor(assigned->PdgCode(), assigned->Px(), assigned->Py(), assigned->Pz(), assigned->E());
219  }
220  }
221  fOutputEvent->AddReducedCluster(redcluster);
222  clusterindexmap.insert(std::pair<int,int>(incluster->GetID(), ncluster));
223  ncluster++;
224  }
225 
226  // Filter tracks
227  for(TIter trkiter = TIter(fTracks).Begin(); trkiter != TIter::End(); ++trkiter){
228  AliVTrack *trackRaw = static_cast<AliVTrack *>(*trkiter), *trackToCheck(NULL);
229  // handlinf for pico tracks as input
230  if(trackRaw->IsA() == AliPicoTrack::Class()){
231  AliPicoTrack *picotrack = static_cast<AliPicoTrack *>(trackRaw);
232  trackToCheck = picotrack->GetTrack();
233  } else {
234  trackToCheck = trackRaw;
235  }
236  FixTrackInputEvent(trackToCheck);
237  TArrayI cutIndices;
238  if(!SelectTrack(trackToCheck,cutIndices)) continue;
239  AliReducedReconstructedTrack *rectrack = new AliReducedReconstructedTrack;
240  double pvec[3];
241  trackToCheck->GetPxPyPz(pvec);
242  rectrack->SetMomentumVector(pvec[0], pvec[1], pvec[2]);
243  for(Int_t icut = 0; icut < cutIndices.GetSize(); icut++) rectrack->SetTrackCuts(cutIndices[icut]);
244  if(MCEvent()){
245  // handle label
246  Int_t label = TMath::Abs(trackToCheck->GetLabel());
247  if(label < fMCEvent->GetNumberOfTracks()){
248  std::map<int,int>::iterator found = mcindexmap.find(label);
249  if(found != mcindexmap.end()){
250  rectrack->SetMatchedParticleIndex(found->second);
251  }
252  if(label >= 0) rectrack->SetGoodTrackLabel(kTRUE);
253  rectrack->SetTPCClusters(trackToCheck->GetTPCNcls());
254  rectrack->SetTPCCrossedRows(GetTPCCrossedRows(trackToCheck));
255  rectrack->SetTPCSharedClusters(trackToCheck->GetTPCSharedMapPtr()->CountBits());
256  rectrack->SetTPCFindableClusters(trackToCheck->GetTPCNclsF());
257  }
258  }
259  // handle clusters
260  Int_t clusterIndex = trackToCheck->GetEMCALcluster();
261  if(clusterIndex >= 0 && clusterIndex < fCaloClusters->GetEntries()){
262  std::map<int,int>::iterator found = clusterindexmap.find(clusterIndex);
263  if(found != clusterindexmap.end()){
264  rectrack->SetMatchedClusterIndex(found->second);
265  }
266  }
267  }
268 
269  fOutputTree->Fill();
270  PostData(2, fOutputTree);
271  return kTRUE;
272 }
273 
279 void AliReducedHighPtEventCreator::AddVirtualTrackSelection(
281  fTrackSelections->Add(new AliReducedTrackSelectionContainer(cutindex, sel));
282 }
283 
289 Bool_t AliReducedHighPtEventCreator::SelectEvent(AliVEvent* event) const {
290  const AliVVertex *primvtx = event->GetPrimaryVertex();
291  if(!primvtx || !primvtx->GetNContributors()) return kFALSE;
292  if(TMath::Abs(primvtx->GetZ()) > 10.) return kFALSE;
293  if(event->IsPileupFromSPD(3, 0.8, 3., 2., 5.)) return kFALSE;
294  AliAnalysisUtils eventSelUtil;
295  if(!eventSelUtil.IsVertexSelected2013pA(event)) return kFALSE;
296  return kTRUE;
297 }
298 
304 Bool_t AliReducedHighPtEventCreator::SelectCluster(const AliVCluster* clust) const {
305  if(!clust->IsEMCAL()) return kFALSE;
306  if(clust->E() < fMinClusterE || clust->E() > fMaxClusterE) return kFALSE;
307  return kTRUE;
308 }
309 
316 Int_t AliReducedHighPtEventCreator::SelectTrack(AliVTrack* track, TArrayI& cutindices) const {
317  std::vector<int> selected;
318 
319  double pt = TMath::Abs(track->Pt()), eta = track->Eta();
320  if(pt < fMinPt || pt > fMaxPt) return 0;
321  if(eta < fMinEta || eta > fMaxEta) return 0;
322 
323  for(TIter cutiter = TIter(fTrackSelections).Begin(); cutiter != TIter::End(); ++cutiter){
324  AliReducedTrackSelectionContainer *mycut = static_cast<AliReducedTrackSelectionContainer *>(*cutiter);
325  if(!mycut->GetTrackSelection()->IsTrackAccepted(track)) continue;
326  selected.push_back(mycut->GetIndex());
327  }
328  if(!selected.size()) return 0;
329  cutindices.Set(selected.size());
330  int counter = 0;
331  for(std::vector<int>::iterator inditer = selected.begin(); inditer != selected.end(); ++inditer){
332  cutindices[counter++] = *inditer;
333  }
334  return selected.size();
335 }
336 
342 Int_t AliReducedHighPtEventCreator::GetTPCCrossedRows(const AliVTrack* trk) const {
343  if(trk->IsA() == AliESDtrack::Class()){
344  return (static_cast<const AliESDtrack *>(trk))->GetTPCCrossedRows();
345  } else if(trk->IsA() == AliAODTrack::Class()){
346  return (static_cast<const AliAODTrack *>(trk))->GetTPCNCrossedRows();
347  }
348  return 0;
349 }
350 
356 void AliReducedHighPtEventCreator::GetCellEnergies(AliVCluster* emccluster, TArrayD& energies) const {
357  if(!fInputEvent->GetEMCALCells()) {
358  AliError("No EMCAL cells");
359  return;
360  }
361  AliDebug(2, Form("Number of cells: %d, array: %p", emccluster->GetNCells(), emccluster->GetCellsAbsId()));
362  energies.Set(emccluster->GetNCells());
363  for(int icell = 0; icell < emccluster->GetNCells(); icell++){
364  // printf("Cell ID: %d\n", emccluster->GetCellsAbsId()[icell]);
365  energies[icell] = fInputEvent->GetEMCALCells()->GetCellAmplitude(emccluster->GetCellsAbsId()[icell]);
366  }
367 }
368 
374 void AliReducedHighPtEventCreator::ConvertTriggerPatches(TClonesArray* patches,
375  AliReducedPatchContainer* cont) {
376  if(!patches){
377  AliError("Trigger patch container not found\n");
378  return;
379  }
380  for(TIter patchIter = TIter(patches).Begin(); patchIter != TIter::End(); ++patchIter){
381  AliEmcalTriggerPatchInfo *mypatch = static_cast<AliEmcalTriggerPatchInfo *>(*patchIter);
382  if(!mypatch->IsOfflineSimple() && mypatch->IsLevel0()) continue;
384  Bool_t isDefined(kFALSE);
385  if(mypatch->IsOfflineSimple()){
386  if(mypatch->IsGammaHighSimple()) { triggertype = AliReducedPatchContainer::kEMCGammaHigh; isDefined = kTRUE; }
387  if(mypatch->IsGammaLowSimple()) { triggertype = AliReducedPatchContainer::kEMCGammaLow; isDefined = kTRUE; }
388  if(mypatch->IsJetHighSimple()) { triggertype = AliReducedPatchContainer::kEMCJetHigh; isDefined = kTRUE; }
389  if(mypatch->IsJetLowSimple()) { triggertype = AliReducedPatchContainer::kEMCJetLow; isDefined = kTRUE; }
390  if(!isDefined){
391  AliDebug(2, "Unknown offline patch type");
392  continue;
393  }
394  AliDebug(2, Form("Adding offline patch of type %d", int(triggertype)));
395  cont->AddTriggerPatch(kTRUE, triggertype, mypatch->GetPatchE(), mypatch->GetADCAmp(), mypatch->GetEtaGeo(), mypatch->GetPhiGeo());
396  } else {
397  if(mypatch->IsGammaHigh()) { triggertype = fSwapTriggerThresholds ? AliReducedPatchContainer::kEMCGammaLow : AliReducedPatchContainer::kEMCGammaHigh; isDefined=kTRUE; }
398  if(mypatch->IsGammaLow()) { triggertype = fSwapTriggerThresholds ? AliReducedPatchContainer::kEMCGammaHigh : AliReducedPatchContainer::kEMCGammaLow; isDefined=kTRUE; }
399  if(mypatch->IsJetHigh()) { triggertype = fSwapTriggerThresholds ? AliReducedPatchContainer::kEMCJetLow : AliReducedPatchContainer::kEMCJetHigh; isDefined=kTRUE; }
400  if(mypatch->IsJetLow()) { triggertype = fSwapTriggerThresholds ? AliReducedPatchContainer::kEMCJetHigh : AliReducedPatchContainer::kEMCJetLow; isDefined=kTRUE; }
401  if(!isDefined){
402  AliDebug(2, "Unknown online patch type");
403  continue;
404  }
405  AliDebug(2, Form("Adding online patch of type %d", int(triggertype)));
406  cont->AddTriggerPatch(kFALSE, triggertype, mypatch->GetPatchE(), mypatch->GetADCAmp(), mypatch->GetEtaGeo(), mypatch->GetPhiGeo());
407  }
408  }
409 }
410 
416 void AliReducedHighPtEventCreator::FixTrackInputEvent(AliVTrack* trk) {
417  if(!trk->GetEvent()){
418  if(trk->IsA() == AliESDtrack::Class())
419  (static_cast<AliESDtrack *>(trk))->SetESDEvent(static_cast<AliESDEvent *>(fInputEvent));
420  else if(trk->IsA() == AliAODTrack::Class())
421  (static_cast<AliAODTrack *>(trk))->SetAODEvent(static_cast<AliAODEvent *>(fInputEvent));
422  else if(trk->IsA() == AliPicoTrack::Class()){
423  AliPicoTrack *mytrk = static_cast<AliPicoTrack *>(trk);
424  if(!mytrk->GetEvent()){
425  if(mytrk->GetTrack()->IsA() == AliESDtrack::Class())
426  (static_cast<AliESDtrack *>(mytrk->GetTrack()))->SetESDEvent(static_cast<AliESDEvent *>(fInputEvent));
427  else
428  (static_cast<AliAODTrack *>(mytrk->GetTrack()))->SetAODEvent(static_cast<AliAODEvent *>(fInputEvent));
429  }
430  }
431  }
432 }
433 
437 AliReducedTrackSelectionContainer::AliReducedTrackSelectionContainer():
438  fIndex(-1),
439  fTrackSelection(NULL)
440 {
441 }
442 
448 AliReducedTrackSelectionContainer::AliReducedTrackSelectionContainer(
450  fIndex(index),
451  fTrackSelection(sel)
452 {
453 }
454 
458 AliReducedTrackSelectionContainer::~AliReducedTrackSelectionContainer() {
459  if(fTrackSelection) delete fTrackSelection;
460 }
461 
462 } /* namespace HighPtTracks */
463 
Reduced event structure for high- analysis.
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
Declaration of class AliReducedHighPtEventCreator and AliReducedTrackSelectionContainer.
Declaration of class AlliReducedPatchInfo.
Declaration of class AliReducedPatchContainer, a container for reduced trigger patches.
Declaration of a reduced MC event header.
Declaration of class AliReducedGeneratedParticle.
Reduced information about reconstructed EMCAL clusters.
Declartion of class AliEMCalPtTaskVTrackSelection.