]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/UNICOR/AliDAnalysisTask.cxx
Added seperate methods to write histograms to a file when not using the task framework
[u/mrichter/AliRoot.git] / PWG2 / UNICOR / AliDAnalysisTask.cxx
1 //Author: Dariusz Miskowiec 2007
2
3 //=============================================================================
4 // my analysis task
5 //=============================================================================
6 #include "TChain.h"
7 #include "AliESDInputHandler.h"
8 #include "AliAnalysisManager.h"
9 #include "AliDAnalysisTask.h"
10 #include "AliDAnalGlobal.h"
11 #include "AliDAnalSingle.h"
12 #include "AliDAnalCorrel.h"
13 #include "AliDAnalPtfluc.h"
14 #include "AliDEventAliceESD.h"
15
16 ClassImp(AliDAnalysisTask)
17
18 /*****************************************************************************/
19 AliDAnalysisTask::AliDAnalysisTask() : 
20   AliAnalysisTask("dali", ""), 
21   fESD(0), fEv0(0), fEv1(0), 
22   fDag(0), fAll(0), fPim(0), fPip(0), 
23   fCnn(0), fCpp(0), fPtf(0),
24   fOutputList(0)
25 {
26   // constructor
27
28   fEv0 = new AliDEventAliceESD();
29   DefineInput(0, TChain::Class());
30   DefineOutput(0, TList::Class());
31 }
32 /*****************************************************************************/
33 void AliDAnalysisTask::CreateOutputObjects() 
34 {
35   // executed once on each worker 
36
37   fDag = new AliDAnalGlobal("dag");
38   fAll = new AliDAnalSingle("all",fEv0->Etamin(),fEv0->Etamax(),0);
39   fPim = new AliDAnalSingle("pim",fEv0->Etamin(),fEv0->Etamax(),-211);
40   fPip = new AliDAnalSingle("pip",fEv0->Etamin(),fEv0->Etamax(), 211);
41   fCnn = new AliDAnalCorrel("cnn",fEv0->Etamin(),fEv0->Etamax(),-211,-211);
42   fCpp = new AliDAnalCorrel("cpp",fEv0->Etamin(),fEv0->Etamax(), 211, 211);
43   fPtf = new AliDAnalPtfluc("ptf",0,0);
44   fOutputList = new TList();
45   fOutputList->Add(fDag);
46   fOutputList->Add(fAll);
47   fOutputList->Add(fPim);
48   fOutputList->Add(fPip);
49   fOutputList->Add(fCnn);
50   fOutputList->Add(fCpp);
51   fOutputList->Add(fPtf);
52 }
53 /*****************************************************************************/
54 void AliDAnalysisTask::ConnectInputData(Option_t *)
55 {
56 // connect ESD or AOD here
57 // called on each input data change.
58
59   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
60   if (!tree) {
61     Printf("ERROR: Could not read chain from input slot 0");
62   } else {
63     fEv0->AttachTree(tree);
64   } 
65   AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*>
66         (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
67
68   if (!esdH) Printf("ERROR: Could not get ESDInputHandler");
69   else fESD = esdH->GetEvent();
70
71 /*****************************************************************************/
72 void AliDAnalysisTask::Exec(Option_t */*option*/)
73 {
74   // process one event
75
76
77   if (!fESD) {
78     Printf("ERROR: fESD not available");
79     return;
80   }
81   // If AttachTree aka ReadFromTree above cannot be done then this is 
82   // the alternative: shallow copy of the current alice esd event to fEv0
83   // memcpy((AliESDEvent*)fEv0, fESD, sizeof(AliESDEvent)); 
84
85   if (!fEv0->Good()) return;
86   fDag->Process(fEv0);
87   fPim->Process(fEv0);
88   fAll->Process(fEv0);
89   fPip->Process(fEv0);
90   fCnn->Process(0,fEv0,fEv0,0);
91   fCnn->Process(2,fEv0,fEv0,TMath::DegToRad()*180);       
92   fCpp->Process(0,fEv0,fEv0,0);
93   fCpp->Process(2,fEv0,fEv0,TMath::DegToRad()*180);       
94   fPtf->Process(0,fEv0,fEv0);     
95   PostData(0, fOutputList);
96
97 /*****************************************************************************/
98 void AliDAnalysisTask::Terminate(Option_t *)
99 {
100   // terminate
101   printf("terminate\n");
102   fDag->Save("unicor-result.root","recreate");
103   fAll->Save("unicor-result.root");
104   fPim->Save("unicor-result.root");
105   fPip->Save("unicor-result.root");
106   fCnn->Save("unicor-result.root");
107   fCpp->Save("unicor-result.root");
108   fPtf->Save("unicor-result.root");
109 }
110 /*****************************************************************************/