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