AliPhysics  e469bb5 (e469bb5)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEmcalJetExtractor.cxx
Go to the documentation of this file.
1 // $Id$
2 //
3 // Jet extractor task
4 // Stores jets (e.g. as AliEmcalJet objects) in trees
5 
6 // Author: R. Haake
7 
8 #include "AliParticleContainer.h"
9 #include "AliEmcalJet.h"
10 #include "AliAODTrack.h"
11 #include "TRandom3.h"
13 
14 
16 
17 
18 //________________________________________________________________________
21  fJetsCont(0),
22  fTracksCont(0),
23  fJetBuffer(0),
24  fJetsOutput(0),
25  fCounter(0),
26  fRandom(0),
27  fIsExtractionDefined(0),
28  fExtractionType(0),
29  fExtractionCriterium(0),
30  fExtractionMinPt(0),
31  fExtractionMaxPt(0),
32  fExtractionPercentage(1.0)
33 {
34  // Default constructor.
35  SetMakeGeneralHistograms(kTRUE);
36 }
37 
38 //________________________________________________________________________
40  AliAnalysisTaskEmcalJet(name, kTRUE),
41  fJetsCont(0),
42  fTracksCont(0),
43  fJetBuffer(0),
44  fJetsOutput(0),
45  fCounter(0),
46  fRandom(0),
47  fIsExtractionDefined(0),
48  fExtractionType(0),
49  fExtractionCriterium(0),
50  fExtractionMinPt(0),
51  fExtractionMaxPt(0),
52  fExtractionPercentage(1.0)
53 {
55 }
56 
57 //________________________________________________________________________
59 {
60  if(fRandom) delete fRandom;
61  if(fJetsOutput) delete fJetsOutput;
62 }
63 
64 //________________________________________________________________________
65 void AliAnalysisTaskEmcalJetExtractor::DefineExtraction(Int_t type, Int_t criterium, Double_t minPt, Double_t maxPt, Double_t percentage)
66 {
68  {
69  fIsExtractionDefined = kTRUE;
70  fExtractionType = type;
71  fExtractionCriterium = criterium;
72  fExtractionMinPt = minPt;
73  fExtractionMaxPt = maxPt;
74  fExtractionPercentage = percentage;
75  }
76  else
77  AliFatal("Tried to define extraction twice -- aborting.");
78 }
79 
80 //________________________________________________________________________
82 {
84  fRandom = new TRandom3(0);
85  // ### Basic container settings
87  if(fJetsCont) { //get particles connected to jets
89  } else { //no jets, just analysis tracks
90  fTracksCont = dynamic_cast<AliTrackContainer*>(GetTrackContainer(0));
91  }
92  if(fTracksCont) fTracksCont->SetClassName("AliAODTrack");
93 
94  // Histograms
95  AddHistogram2D<TH2D>("hTrackPhiEta", "Track angular distribution #phi/#eta", "COLZ", 180, 0., 2*TMath::Pi(), 100, -2.5, 2.5, "#phi", "#eta", "dN^{Tracks}/d#phi d#eta");
96  AddHistogram2D<TH2D>("hJetPhiEta", "Jet angular distribution #phi/#eta", "COLZ", 180, 0., 2*TMath::Pi(), 100, -2.5, 2.5, "#phi", "#eta", "dN^{Jets}/d#phi d#eta");
97 
98  PrintSettings();
99 
100  PostData(1, fOutput); // Post data for ALL output slots > 0 here.
101 }
102 
103 //________________________________________________________________________
105 {
106  std::cout << std::endl << Form("########### Printing settings for task %s", GetName()) << std::endl;
107  std::cout << "Jet container cuts:\n";
108  fJetsCont->PrintCuts();
109  std::cout << "---------------------------------------\n";
110  std::cout << "Particle container: " << fTracksCont->GetName() << std::endl;
111  std::cout << "Track filter: " << fTracksCont->GetTrackFilterType() << " (0 - no filter, 1 - custom, 2 - hybrid, 3 - TPC only)\n";
112  std::cout << "---------------------------------------\n";
113  std::cout << "Extraction type: " << fExtractionType << " (0 - AliEmcalJet, 1 - AliBasicJet, 2 - AliBasicJet w/constituents)\n";
114  std::cout << "Extraction criterium: " << fExtractionCriterium << " (0 - MinBias, 1 - Signal jets, 2 - Background jets)\n";
115  std::cout << "Extraction min pT (after background correction if rho given): " << fExtractionMinPt << "\n";
116  std::cout << "Extraction max pT (after background correction if rho given): " << fExtractionMaxPt << "\n";
117  std::cout << "Extraction percentage (rest is thrown away): " << fExtractionPercentage << "\n";
118  std::cout << "###########" << std::endl << std::endl;
119 }
120 
121 //________________________________________________________________________
123 {
124  return kTRUE;
125 }
126 
127 //________________________________________________________________________
130  if (fJetsCont && fJetsCont->GetArray() == 0)
131  {
132  fJetsCont = 0;
133  AliFatal("No jet container found.");
134  }
135  if (fTracksCont && fTracksCont->GetArray() == 0)
136  {
137  fTracksCont = 0;
138  AliFatal("No track container found.");
139  }
141  {
142  AliFatal("Extraction conditions not defined. Use DefineExtraction().");
143  }
144 
145 
146  fJetsOutput = new TTree("ExtractedJets", "ExtractedJets");
147  if(fExtractionType==0) // AliEmcalJet
148  fJetsOutput->Branch("Jets", "AliEmcalJet", &fJetBuffer, 1000);
149  else if(fExtractionType==1) // AliBasicJet w/o constituents
150  fJetsOutput->Branch("Jets", "AliBasicJet", &fJetBuffer, 1000);
151  else if(fExtractionType==2) // AliBasicJet w/ constituents
152  fJetsOutput->Branch("Jets", "AliBasicJet", &fJetBuffer, 1000);
153 
154  TList* list = dynamic_cast<TList*> (GetOutputData(1));
155  list->Add(fJetsOutput);
156 
157 }
158 
159 //________________________________________________________________________
161 {
162  Long64_t eventID = InputEvent()->GetHeader()->GetEventIdAsLong();
163 
165  AliAODTrack *track = static_cast<AliAODTrack*>(fTracksCont->GetNextAcceptParticle());
166  // All tracks plots
167  while(track) {
168  FillHistogram("hTrackPhiEta", track->Phi(), track->Eta());
169  track = static_cast<AliAODTrack*>(fTracksCont->GetNextAcceptParticle());
170  }
171 
174  while(jet) {
175  // Select jets according to extraction criterium
176  if( ((jet->Pt()-jet->Area()*fJetsCont->GetRhoVal()) < fExtractionMinPt) || ((jet->Pt()-jet->Area()*fJetsCont->GetRhoVal()) >= fExtractionMaxPt) )
177  {
178  jet = fJetsCont->GetNextAcceptJet();
179  continue;
180  }
181 
182  // "Minimum bias" criterium
183  if(fExtractionCriterium==0)
184  {
185  // do nothing
186  }
187 
188  // Discard jets statistically
189  if(fRandom->Rndm() >= fExtractionPercentage)
190  {
191  jet = fJetsCont->GetNextAcceptJet();
192  continue;
193  }
194 
195  FillHistogram("hJetPhiEta", jet->Phi(), jet->Eta());
196 
197  // Create the jet object that will be saved to the tree
198  if(fExtractionType==0) // AliEmcalJet
199  {
200  fJetBuffer = jet;
201  fJetsOutput->Fill();
202  }
203  else if( (fExtractionType==1) || (fExtractionType==2) )// AliBasicJet
204  {
205  AliBasicJet basicJet(jet->Eta(), jet->Phi(), jet->Pt(), jet->Charge(), fJetsCont->GetJetRadius(), jet->Area(), fJetsCont->GetRhoVal(), eventID, fCent);
206  if(fExtractionType==1)
207  fJetBuffer = &basicJet;
208  else if(fExtractionType==2) // AliBasicJet w/ constituents
209  {
210  for(Int_t i = 0; i < jet->GetNumberOfTracks(); i++)
211  {
212  AliVParticle* particle = static_cast<AliVParticle*>(jet->TrackAt(i, fTracksCont->GetArray()));
213  basicJet.AddJetConstituent(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge());
214  fJetBuffer = &basicJet;
215  }
216  }
217  fJetsOutput->Fill();
218  }
219  jet = fJetsCont->GetNextAcceptJet();
220  }
221 
222  return kTRUE;
223 
224 }
225 
226 //########################################################################
227 // HISTOGRAM HELPER FUNCTIONS
228 //########################################################################
229 
230 //________________________________________________________________________
231 inline void AliAnalysisTaskEmcalJetExtractor::FillHistogram(const char * key, Double_t x)
232 {
233  TH1* tmpHist = static_cast<TH1*>(fOutput->FindObject(key));
234  if(!tmpHist)
235  {
236  AliError(Form("Cannot find histogram <%s> ",key)) ;
237  return;
238  }
239 
240  tmpHist->Fill(x);
241 }
242 
243 //________________________________________________________________________
244 inline void AliAnalysisTaskEmcalJetExtractor::FillHistogram(const char * key, Double_t x, Double_t y)
245 {
246  TH1* tmpHist = static_cast<TH1*>(fOutput->FindObject(key));
247  if(!tmpHist)
248  {
249  AliError(Form("Cannot find histogram <%s> ",key));
250  return;
251  }
252 
253  if (tmpHist->IsA()->GetBaseClass("TH1"))
254  static_cast<TH1*>(tmpHist)->Fill(x,y); // Fill x with y
255  else if (tmpHist->IsA()->GetBaseClass("TH2"))
256  static_cast<TH2*>(tmpHist)->Fill(x,y); // Fill x,y with 1
257 }
258 
259 //________________________________________________________________________
260 inline void AliAnalysisTaskEmcalJetExtractor::FillHistogram(const char * key, Double_t x, Double_t y, Double_t add)
261 {
262  TH2* tmpHist = static_cast<TH2*>(fOutput->FindObject(key));
263  if(!tmpHist)
264  {
265  AliError(Form("Cannot find histogram <%s> ",key));
266  return;
267  }
268 
269  tmpHist->Fill(x,y,add);
270 }
271 
272 //________________________________________________________________________
273 template <class T> T* AliAnalysisTaskEmcalJetExtractor::AddHistogram1D(const char* name, const char* title, const char* options, Int_t xBins, Double_t xMin, Double_t xMax, const char* xTitle, const char* yTitle)
274 {
275  T* tmpHist = new T(name, title, xBins, xMin, xMax);
276 
277  tmpHist->GetXaxis()->SetTitle(xTitle);
278  tmpHist->GetYaxis()->SetTitle(yTitle);
279  tmpHist->SetOption(options);
280  tmpHist->SetMarkerStyle(kFullCircle);
281  tmpHist->Sumw2();
282 
283  fOutput->Add(tmpHist);
284 
285  return tmpHist;
286 }
287 
288 //________________________________________________________________________
289 template <class T> T* AliAnalysisTaskEmcalJetExtractor::AddHistogram2D(const char* name, const char* title, const char* options, Int_t xBins, Double_t xMin, Double_t xMax, Int_t yBins, Double_t yMin, Double_t yMax, const char* xTitle, const char* yTitle, const char* zTitle)
290 {
291  T* tmpHist = new T(name, title, xBins, xMin, xMax, yBins, yMin, yMax);
292  tmpHist->GetXaxis()->SetTitle(xTitle);
293  tmpHist->GetYaxis()->SetTitle(yTitle);
294  tmpHist->GetZaxis()->SetTitle(zTitle);
295  tmpHist->SetOption(options);
296  tmpHist->SetMarkerStyle(kFullCircle);
297  tmpHist->Sumw2();
298 
299  fOutput->Add(tmpHist);
300 
301  return tmpHist;
302 }
Short_t Charge() const
Definition: AliEmcalJet.h:62
Double_t Area() const
Definition: AliEmcalJet.h:69
Double_t GetRhoVal() const
const char * title
Definition: MakeQAPdf.C:26
AliJetContainer * GetJetContainer(Int_t i=0) const
Double_t Eta() const
Definition: AliEmcalJet.h:60
Double_t Phi() const
Definition: AliEmcalJet.h:55
Container with name, TClonesArray and cuts for particles.
TList * list
TTree * fJetsOutput
buffer for one jet (that will be saved to the tree)
TList * fOutput
!output list
UShort_t GetNumberOfTracks() const
Definition: AliEmcalJet.h:83
AliParticleContainer * GetParticleContainer() const
Double_t fCent
!event centrality
TClonesArray * GetArray() const
ETrackFilterType_t GetTrackFilterType() const
void SetClassName(const char *clname)
AliEmcalJet * GetNextAcceptJet()
Double_t Pt() const
Definition: AliEmcalJet.h:47
const char * GetName() const
Float_t GetJetRadius() const
Short_t TrackAt(Int_t idx) const
Definition: AliEmcalJet.h:107
T * AddHistogram1D(const char *name="CustomHistogram", const char *title="NO_TITLE", const char *options="", Int_t xBins=100, Double_t xMin=0.0, Double_t xMax=20.0, const char *xTitle="x axis", const char *yTitle="y axis")
AliTrackContainer * GetTrackContainer(Int_t i=0) const
void SetMakeGeneralHistograms(Bool_t g)
void DefineExtraction(Int_t type, Int_t criterium, Double_t minPt, Double_t maxPt, Double_t percentage)
ClassImp(AliAnalysisTaskEmcalJetExtractor) AliAnalysisTaskEmcalJetExtractor
virtual AliVParticle * GetNextAcceptParticle()
T * AddHistogram2D(const char *name="CustomHistogram", const char *title="NO_TITLE", const char *options="", Int_t xBins=100, Double_t xMin=0.0, Double_t xMax=20.0, Int_t yBins=100, Double_t yMin=0.0, Double_t yMax=20.0, const char *xTitle="x axis", const char *yTitle="y axis", const char *zTitle="z axis")
void ResetCurrentID(Int_t i=-1)
void FillHistogram(const char *key, Double_t x)