]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALTasks/AliEmcalPhysicsSelectionTask.cxx
comment
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalPhysicsSelectionTask.cxx
1 // $Id$
2 //
3 // Physics selection task.
4 //
5 //
6
7
8 #include <TFile.h>
9 #include <TH1F.h>
10 #include <TH2F.h>
11 #include <TROOT.h>
12 #include "AliAnalysisDataContainer.h"
13 #include "AliAnalysisDataSlot.h"
14 #include "AliAnalysisManager.h"
15 #include "AliEmcalPhysicsSelection.h"
16 #include "AliEmcalPhysicsSelectionTask.h"
17 #include "AliESDEvent.h"
18 #include "AliInputEventHandler.h"
19 #include "AliLog.h"
20
21 ClassImp(AliEmcalPhysicsSelectionTask)
22
23 //__________________________________________________________________________________________________
24 AliEmcalPhysicsSelectionTask::AliEmcalPhysicsSelectionTask() :
25   AliPhysicsSelectionTask(),
26   fDoWriteHistos(1),
27   fNCalled(0),
28   fNAccepted(0),
29   fHAcc(0),
30   fHEvtTypes(0)
31 {
32   // Default constructor.
33 }
34
35 //__________________________________________________________________________________________________
36 AliEmcalPhysicsSelectionTask::AliEmcalPhysicsSelectionTask(const char* opt) : 
37   AliPhysicsSelectionTask(),
38   fDoWriteHistos(1),
39   fNCalled(0),
40   fNAccepted(0),
41   fHAcc(0),
42   fHEvtTypes(0)
43 {
44   // Constructor.
45
46   fOption = opt;
47   fPhysicsSelection = new AliEmcalPhysicsSelection;
48
49   AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
50   if (handler) {
51     handler->SetEventSelection(fPhysicsSelection);
52     AliInfo("Physics Event Selection enabled.");
53   } else {
54     AliError("No input event handler connected to analysis manager. No Physics Event Selection.");
55   }
56   // Define input and output slots here
57   DefineOutput(1, TList::Class());
58   fBranchNames = "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,AliESDVZERO.,"
59                  "AliESDZDC.,SPDVertex.,PrimaryVertex.,TPCVertex.,Tracks,SPDPileupVertices";
60   
61   AliLog::SetClassDebugLevel("AliEmcalPhysicsSelectionTask", AliLog::kWarning);
62 }
63
64 //__________________________________________________________________________________________________
65 void AliEmcalPhysicsSelectionTask::UserCreateOutputObjects()
66 {
67   // User create outputs.
68
69   AliPhysicsSelectionTask::UserCreateOutputObjects();
70   fHAcc = new TH1D("hEvCount",";0=rej/1=acc;#",2,-0.5,1.5);
71   fOutput->Add(fHAcc);
72   fHEvtTypes = new TH1D("hEvtTypes",";#",10,-0.5,9.5);
73   fHEvtTypes->GetXaxis()->SetBinLabel(1,"All");
74   fHEvtTypes->GetXaxis()->SetBinLabel(2,"MB");
75   fHEvtTypes->GetXaxis()->SetBinLabel(3,"FO");
76   fHEvtTypes->GetXaxis()->SetBinLabel(4,"EMC");
77   fHEvtTypes->GetXaxis()->SetBinLabel(5,"EJE");
78   fHEvtTypes->GetXaxis()->SetBinLabel(6,"EGA");
79   fHEvtTypes->GetXaxis()->SetBinLabel(7,"Good");
80   fHEvtTypes->GetXaxis()->SetBinLabel(8,"HC");
81   fHEvtTypes->GetXaxis()->SetBinLabel(9,"HT");
82   fHEvtTypes->GetXaxis()->SetBinLabel(10,"LED");
83   fOutput->Add(fHEvtTypes);
84   if (!fDoWriteHistos) {
85     fOutput->Remove(fPhysicsSelection);
86   }
87 }
88
89 //__________________________________________________________________________________________________
90 void AliEmcalPhysicsSelectionTask::UserExec(const Option_t *opt)
91 {
92   // User exec.
93
94   AliPhysicsSelectionTask::UserExec(opt);
95
96   ++fNCalled;
97
98   UInt_t res = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
99   if (res>0) {
100     ++fNAccepted;
101     fHAcc->Fill(1);
102   } else {
103     fHAcc->Fill(0);
104   }
105
106   AliEmcalPhysicsSelection *ps=static_cast<AliEmcalPhysicsSelection *>(fPhysicsSelection);
107   fHEvtTypes->Fill(0);
108   if (res&AliVEvent::kAnyINT)
109     fHEvtTypes->Fill(1);
110   if (ps->IsFastOnly())
111     fHEvtTypes->Fill(2);
112   if ((res&AliVEvent::kEMC1) || (res&AliVEvent::kEMC7))
113     fHEvtTypes->Fill(3);
114   if (res&AliVEvent::kEMCEJE)
115     fHEvtTypes->Fill(4);
116   if (res&AliVEvent::kEMCEGA)
117     fHEvtTypes->Fill(5);
118   if (ps->IsGoodEvent())
119     fHEvtTypes->Fill(6);
120   if (res&AliEmcalPhysicsSelection::kEmcalHC)
121     fHEvtTypes->Fill(7);
122   if (res&AliEmcalPhysicsSelection::kEmcalHT)
123     fHEvtTypes->Fill(8);
124   if (ps->IsLedEvent())
125     fHEvtTypes->Fill(9);
126 }
127
128 //__________________________________________________________________________________________________
129 void AliEmcalPhysicsSelectionTask::Terminate(Option_t *)
130 {
131   // The Terminate() function is the last function to be called during
132   // a query. It always runs on the client, it can be used to present
133   // the results graphically or save the results to file.
134
135   AliInfo(Form("Called %d times, accepted %d events", fNCalled, fNAccepted));
136
137   if (!fDoWriteHistos)
138     return;
139
140   fOutput = dynamic_cast<TList*> (GetOutputData(1));
141   if (!fOutput) {
142     AliError("fOutput not available");
143     return;
144   }
145
146   AliAnalysisDataSlot *oslot = GetOutputSlot(1);
147   if (!oslot)
148     return;
149
150   AliAnalysisDataContainer *ocont = oslot->GetContainer();
151   if (!ocont)
152     return;
153
154   TFile *file = OpenFile(1);
155   if (!file)
156     return;
157
158   TDirectory::TContext context(file); 
159   if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
160     fPhysicsSelection = dynamic_cast<AliPhysicsSelection*> (fOutput->FindObject("AliPhysicsSelection"));
161   }
162   if (fPhysicsSelection) {
163     //fPhysicsSelection->Print();
164     fPhysicsSelection->SaveHistograms(Form("%sHists",ocont->GetName()));
165     AliInfo(Form("Writing result to %s",file->GetName()));
166   }
167   fOutput->Remove(fPhysicsSelection);
168 }