]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/correlationHF/AliAnalysisTaskDxHFECorrelation.cxx
New task for D0-hadron correlation + macros (Fabio)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliAnalysisTaskDxHFECorrelation.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE Project            * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  Sedat Altinpinar <Sedat.Altinpinar@cern.ch>           *
9 //*                  Hege Erdal       <hege.erdal@gmail.com>               *
10 //*                                                                        *
11 //* Permission to use, copy, modify and distribute this software and its   *
12 //* documentation strictly for non-commercial purposes is hereby granted   *
13 //* without fee, provided that the above copyright notice appears in all   *
14 //* copies and that both the copyright notice and this permission notice   *
15 //* appear in the supporting documentation. The authors make no claims     *
16 //* about the suitability of this software for any purpose. It is          *
17 //* provided "as is" without express or implied warranty.                  *
18 //**************************************************************************
19
20 /// @file   AliAnalysisTaskDxHFECorrelation.cxx
21 /// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22 /// @date   2012-03-19
23 /// @brief  AnalysisTask D0 - HFE correlation
24 ///
25
26 #include "AliAnalysisTaskDxHFECorrelation.h"
27 #include "AliDxHFECorrelation.h"
28 #include "AliDxHFEParticleSelectionD0.h"
29 #include "AliDxHFEParticleSelectionEl.h"
30 #include "AliAnalysisManager.h"
31 #include "AliLog.h"
32 #include "AliESDInputHandler.h"
33 #include "TChain.h"
34 #include "TSystem.h"
35 #include "TFile.h"
36 #include <memory>
37
38 /// ROOT macro for the implementation of ROOT specific class methods
39 ClassImp(AliAnalysisTaskDxHFECorrelation)
40
41 AliAnalysisTaskDxHFECorrelation::AliAnalysisTaskDxHFECorrelation(const char* opt)
42   : AliAnalysisTaskSE("AliAnalysisTaskDxHFECorrelation")
43   , fOutput(0)
44   , fOption(opt)
45   , fCorrelation(NULL)
46   , fD0s(NULL)
47   , fElectrons(NULL)
48 {
49   // constructor
50   //
51   //
52
53   DefineSlots();
54 }
55
56 int AliAnalysisTaskDxHFECorrelation::DefineSlots()
57 {
58   // define the data slots
59   DefineInput(0, TChain::Class());
60   DefineOutput(1, TList::Class());
61   return 0;
62 }
63
64 AliAnalysisTaskDxHFECorrelation::~AliAnalysisTaskDxHFECorrelation()
65 {
66   // destructor
67   //
68   //
69
70   // histograms are in the output list and deleted when the output
71   // list is deleted by the TSelector dtor
72
73   if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
74     delete fOutput;
75     fOutput = 0;
76   }
77   if (fD0s) delete fD0s;
78   fD0s=NULL;
79   if (fElectrons) delete fElectrons;
80   fElectrons=NULL;
81   if (fCorrelation) delete fCorrelation;
82   fCorrelation=NULL;
83 }
84
85 void AliAnalysisTaskDxHFECorrelation::UserCreateOutputObjects()
86 {
87   // create result objects and add to output list
88
89   std::auto_ptr<TList> Output(new TList);
90   std::auto_ptr<AliDxHFEParticleSelection> D0s(new AliDxHFEParticleSelectionD0);
91   std::auto_ptr<AliDxHFEParticleSelection> Electrons(new AliDxHFEParticleSelectionEl);
92   std::auto_ptr<AliDxHFECorrelation> Correlation(new AliDxHFECorrelation);
93
94   if (!Output     .get() ||
95       !D0s        .get() ||
96       !Electrons  .get() ||
97       !Correlation.get()) {
98     AliFatal("allocation of worker classes failed");
99     return;
100   }
101
102   fOutput      = Output     .release();
103   fD0s         = D0s        .release();
104   fElectrons   = Electrons  .release();
105   fCorrelation = Correlation.release();
106
107   fOutput->SetOwner();
108
109   // all tasks must post data once for all outputs
110   PostData(1, fOutput);
111 }
112
113 void AliAnalysisTaskDxHFECorrelation::UserExec(Option_t* /*option*/)
114 {
115   // process the event
116
117   // TODO: implement correct input, this is likely not to be the
118   // ESD
119   TObject* pInput=InputEvent();
120   if (!pInput) {
121     AliError("failed to get input");
122     return;
123   }
124   AliVEvent *pEvent = dynamic_cast<AliVEvent*>(pInput);
125   if(!pEvent){
126     AliError(Form("input of wrong class type %s, expecting AliVEvent", pInput->ClassName()));
127     return;
128   }
129
130   std::auto_ptr<TObjArray> pSelectedD0s(fD0s->Select(pEvent));
131   std::auto_ptr<TObjArray> pSelectedElectrons(fElectrons->Select(pEvent));
132   int iResult=fCorrelation->Fill(pSelectedD0s.get(), pSelectedElectrons.get());
133   if (iResult<0) {
134     AliError(Form("%s processing failed with error %d", fCorrelation->GetName(), iResult));
135   }
136
137   PostData(1, fOutput);
138 }
139
140 void AliAnalysisTaskDxHFECorrelation::FinishTaskOutput()
141 {
142   // end of the processing
143 }
144
145 void AliAnalysisTaskDxHFECorrelation::Terminate(Option_t *)
146 {
147   // last action on the client
148   fOutput = dynamic_cast<TList*> (GetOutputData(1));
149   if (!fOutput) {
150     AliFatal("failed to get output container");
151     return;
152   }
153
154 }