]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliPWG0Helper.cxx
replaced THXF to THX in many function prototypes
[u/mrichter/AliRoot.git] / PWG0 / AliPWG0Helper.cxx
CommitLineData
04a7657f 1/* $Id$ */
2
3#include <AliPWG0Helper.h>
4
5#include <TParticle.h>
6#include <TParticlePDG.h>
847489f7 7#include <TH1.h>
dd367a14 8#include <TH2.h>
25db2d85 9#include <TH3.h>
116083b1 10#include <TList.h>
9cd015f7 11#include <TTree.h>
12#include <TBranch.h>
13#include <TLeaf.h>
116083b1 14
15#include <AliHeader.h>
16#include <AliStack.h>
17#include <AliLog.h>
04a7657f 18
19#include <AliLog.h>
20#include <AliESD.h>
770a1f1d 21#include <AliESDEvent.h>
04a7657f 22#include <AliESDVertex.h>
23
116083b1 24#include <AliGenEventHeader.h>
25#include <AliGenPythiaEventHeader.h>
26#include <AliGenCocktailEventHeader.h>
6b62a9c7 27#include <AliGenDPMjetEventHeader.h>
116083b1 28
04a7657f 29//____________________________________________________________________
30ClassImp(AliPWG0Helper)
31
a67484a6 32Int_t AliPWG0Helper::fgLastProcessType = -1;
33
04a7657f 34//____________________________________________________________________
116083b1 35Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
36{
37 // see function with ULong64_t argument
38
39 ULong64_t triggerMask = aEsd->GetTriggerMask();
40 return IsEventTriggered(triggerMask, trigger);
41}
42
43//____________________________________________________________________
44Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
04a7657f 45{
46 // check if the event was triggered
47 //
5c495d37 48 // this function needs the branch fTriggerMask
dd367a14 49
dd367a14 50 // definitions from p-p.cfg
51 ULong64_t spdFO = (1 << 14);
52 ULong64_t v0left = (1 << 11);
53 ULong64_t v0right = (1 << 12);
04a7657f 54
e9c3977b 55 switch (trigger)
56 {
57 case kMB1:
58 {
dd367a14 59 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
e9c3977b 60 return kTRUE;
61 break;
62 }
63 case kMB2:
64 {
dd367a14 65 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
e9c3977b 66 return kTRUE;
67 break;
68 }
1c15d51a 69 case kSPDFASTOR:
70 {
71 if (triggerMask & spdFO)
72 return kTRUE;
73 break;
74 }
e9c3977b 75 }
04a7657f 76
77 return kFALSE;
78}
79
770a1f1d 80//____________________________________________________________________
ebf31fda 81const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug)
770a1f1d 82{
83 // Get the vertex from the ESD and returns it if the vertex is valid
84 //
85 // Second argument decides which vertex is used (this selects
86 // also the quality criteria that are applied)
87
88 const AliESDVertex* vertex = 0;
89 Float_t requiredZResolution = -1;
90 if (analysisMode == kSPD || analysisMode == kTPCITS)
91 {
d1f50534 92 vertex = aEsd->GetPrimaryVertexSPD();
770a1f1d 93 requiredZResolution = 0.1;
ebf31fda 94 if (debug)
95 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
770a1f1d 96 }
97 else if (analysisMode == kTPC)
98 {
d1f50534 99 vertex = aEsd->GetPrimaryVertexTPC();
770a1f1d 100 requiredZResolution = 0.6;
ebf31fda 101 if (debug)
102 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
770a1f1d 103 }
104 else
105 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
106
ebf31fda 107 if (!vertex) {
108 if (debug)
109 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
770a1f1d 110 return 0;
ebf31fda 111 }
770a1f1d 112
113 // check Ncontributors
ebf31fda 114 if (vertex->GetNContributors() <= 0) {
115 if (debug)
116 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0");
770a1f1d 117 return 0;
ebf31fda 118 }
770a1f1d 119
120 // check resolution
121 Double_t zRes = vertex->GetZRes();
122
ebf31fda 123 if (zRes == 0 || zRes > requiredZResolution) {
124 if (debug)
125 Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
770a1f1d 126 return 0;
ebf31fda 127 }
128
129 if (debug)
130 Printf("AliPWG0Helper::GetVertex: Returning valid vertex");
770a1f1d 131
132 return vertex;
133}
134
04a7657f 135//____________________________________________________________________
7584d357 136Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
04a7657f 137{
138 //
25db2d85 139 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
140 // shall be counted as a primary particle
141 //
04a7657f 142 // This function or a equivalent should be available in some common place of AliRoot
143 //
dd367a14 144 // WARNING: Call this function only for particles that are among the particles from the event generator!
145 // --> stack->Particle(id) with id < stack->GetNprimary()
04a7657f 146
147 // if the particle has a daughter primary, we do not want to count it
148 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
149 {
7584d357 150 if (adebug)
25db2d85 151 printf("Dropping particle because it has a daughter among the primaries.\n");
04a7657f 152 return kFALSE;
153 }
154
155 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
156
157 // skip quarks and gluon
158 if (pdgCode <= 10 || pdgCode == 21)
159 {
7584d357 160 if (adebug)
25db2d85 161 printf("Dropping particle because it is a quark or gluon.\n");
04a7657f 162 return kFALSE;
163 }
164
165 if (strcmp(aParticle->GetName(),"XXX") == 0)
166 {
1c15d51a 167 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
04a7657f 168 return kFALSE;
169 }
170
171 TParticlePDG* pdgPart = aParticle->GetPDG();
172
173 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
174 {
1c15d51a 175 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
04a7657f 176 return kFALSE;
177 }
178
179 if (pdgPart->Charge() == 0)
180 {
7584d357 181 if (adebug)
25db2d85 182 printf("Dropping particle because it is not charged.\n");
04a7657f 183 return kFALSE;
184 }
185
186 return kTRUE;
187}
847489f7 188
189//____________________________________________________________________
29771dc8 190void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
847489f7 191{
192 // create projections of 3d hists to all 2d combinations
193 // the histograms are not returned, just use them from memory or use this to create them in a file
194
195 TH1* proj = hist->Project3D("yx");
196 proj->SetXTitle(hist->GetXaxis()->GetTitle());
197 proj->SetYTitle(hist->GetYaxis()->GetTitle());
29771dc8 198 if (save)
199 proj->Write();
847489f7 200
201 proj = hist->Project3D("zx");
202 proj->SetXTitle(hist->GetXaxis()->GetTitle());
203 proj->SetYTitle(hist->GetZaxis()->GetTitle());
29771dc8 204 if (save)
205 proj->Write();
847489f7 206
207 proj = hist->Project3D("zy");
208 proj->SetXTitle(hist->GetYaxis()->GetTitle());
209 proj->SetYTitle(hist->GetZaxis()->GetTitle());
29771dc8 210 if (save)
211 proj->Write();
847489f7 212}
1afae8ff 213
214//____________________________________________________________________
29771dc8 215void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
1afae8ff 216{
217 // create projections of the 3d hists divides them
218 // axis decides to which plane, if axis is 0 to all planes
219 // the histograms are not returned, just use them from memory or use this to create them in a file
220
221 if (axis == 0)
222 {
29771dc8 223 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
224 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
225 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
1afae8ff 226
227 return;
228 }
229
230 TH1* proj = hist->Project3D(axis);
0ab29cfa 231
232 if (strlen(axis) == 2)
233 {
234 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
235 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
236 }
237 else if (strlen(axis) == 1)
238 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
1afae8ff 239
240 TH1* proj2 = hist2->Project3D(axis);
0ab29cfa 241 if (strlen(axis) == 2)
242 {
243 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
244 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
245 }
246 else if (strlen(axis) == 1)
247 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
1afae8ff 248
249 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
29771dc8 250 //printf("doing axis: %s, x axis has %d %d bins, min %f %f max %f %f\n", axis, division->GetNbinsX(), proj2->GetNbinsX(), division->GetXaxis()->GetBinLowEdge(1), proj2->GetXaxis()->GetBinLowEdge(1), division->GetXaxis()->GetBinUpEdge(division->GetNbinsX()), proj2->GetXaxis()->GetBinUpEdge(proj2->GetNbinsX()));
251 //printf("doing axis: %s, y axis has %d %d bins, min %f %f max %f %f\n", axis, division->GetNbinsY(), proj2->GetNbinsY(), division->GetYaxis()->GetBinLowEdge(1), proj2->GetYaxis()->GetBinLowEdge(1), division->GetYaxis()->GetBinUpEdge(division->GetNbinsY()), proj2->GetYaxis()->GetBinUpEdge(proj2->GetNbinsY()));
9e952c39 252 division->Divide(proj, proj2, 1, 1, "B");
29771dc8 253 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
0ab29cfa 254
255 if (putErrors)
256 {
257 division->Sumw2();
258 if (division->GetDimension() == 1)
259 {
260 Int_t nBins = division->GetNbinsX();
29771dc8 261 for (Int_t i = 1; i <= nBins; ++i)
0ab29cfa 262 if (proj2->GetBinContent(i) != 0)
263 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
264 }
265 else if (division->GetDimension() == 2)
266 {
267 Int_t nBinsX = division->GetNbinsX();
268 Int_t nBinsY = division->GetNbinsY();
29771dc8 269 for (Int_t i = 1; i <= nBinsX; ++i)
270 for (Int_t j = 1; j <= nBinsY; ++j)
0ab29cfa 271 if (proj2->GetBinContent(i, j) != 0)
272 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
273 }
274 }
29771dc8 275
276 if (save)
277 {
278 proj->Write();
279 proj2->Write();
280 division->Write();
281 }
1afae8ff 282}
283
92d2d8ad 284//____________________________________________________________________
25db2d85 285const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
92d2d8ad 286{
287 // returns the title of the axis given in axis (x, y, z)
288
289 if (axis == 'x')
290 return hist->GetXaxis()->GetTitle();
291 else if (axis == 'y')
292 return hist->GetYaxis()->GetTitle();
293 else if (axis == 'z')
294 return hist->GetZaxis()->GetTitle();
295
296 return 0;
297}
116083b1 298
6b62a9c7 299
1c15d51a 300AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
6b62a9c7 301
302 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
303
304 if (!pythiaGenHeader) {
305 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
306 return kInvalidProcess;
307 }
308
309
310 Int_t pythiaType = pythiaGenHeader->ProcessType();
a67484a6 311 fgLastProcessType = pythiaType;
6b62a9c7 312 MCProcessType globalType = kInvalidProcess;
313
314
315 if (adebug) {
316 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
317 }
318
319
320 if(pythiaType==92||pythiaType==93){
321 globalType = kSD;
322 }
323 else if(pythiaType==94){
324 globalType = kDD;
325 }
326 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
327 else {
328 globalType = kND;
329 }
330 return globalType;
331}
332
333
1c15d51a 334AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
116083b1 335 //
336 // get the process type of the event.
337 //
338
339 // can only read pythia headers, either directly or from cocktalil header
6b62a9c7 340 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
341
342 if (!dpmJetGenHeader) {
343 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
344 return kInvalidProcess;
345 }
346
347 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
a67484a6 348 fgLastProcessType = dpmJetType;
6b62a9c7 349 MCProcessType globalType = kInvalidProcess;
350
351
352 if (adebug) {
353 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
354 }
355
356
357 if(dpmJetType == 1){ // this is explicitly inelastic
358 globalType = kND;
359 }
360 else if(dpmJetType==5||dpmJetType==6){
361 globalType = kSD;
362 }
363 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
364 globalType = kDD;
365 }
366 return globalType;
367}
368
369
1c15d51a 370AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
6b62a9c7 371 //
372 // get the process type of the event.
373 //
374
375
376 // Check for simple headers first
377
116083b1 378 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
6b62a9c7 379 if (pythiaGenHeader) {
380 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
381 }
116083b1 382
6b62a9c7 383 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
384 if (dpmJetGenHeader) {
385 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
386 }
387
116083b1 388
6b62a9c7 389 // check for cocktail
116083b1 390
6b62a9c7 391 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
392 if (!genCocktailHeader) {
393 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
394 return kInvalidProcess;
395 }
116083b1 396
6b62a9c7 397 TList* headerList = genCocktailHeader->GetHeaders();
398 if (!headerList) {
399 return kInvalidProcess;
400 }
401
402 for (Int_t i=0; i<headerList->GetEntries(); i++) {
403
404 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
405 if (pythiaGenHeader) {
406 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
116083b1 407 }
408
6b62a9c7 409 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
410 if (dpmJetGenHeader) {
411 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
116083b1 412 }
413 }
6b62a9c7 414 return kInvalidProcess;
415}
116083b1 416
116083b1 417
116083b1 418
419//____________________________________________________________________
420TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
421{
422 //
423 // Finds the first mother among the primary particles of the particle identified by <label>,
424 // i.e. the primary that "caused" this particle
425 //
426
427 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
428 if (motherLabel < 0)
429 return 0;
430
431 return stack->Particle(motherLabel);
432}
433
434//____________________________________________________________________
435Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
436{
437 //
438 // Finds the first mother among the primary particles of the particle identified by <label>,
439 // i.e. the primary that "caused" this particle
440 //
441 // returns its label
442 //
443
444 Int_t nPrim = stack->GetNprimary();
445
446 while (label >= nPrim)
447 {
448 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
449
450 TParticle* particle = stack->Particle(label);
451 if (!particle)
452 {
453 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
454 return -1;
455 }
456
457 // find mother
458 if (particle->GetMother(0) < 0)
459 {
460 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
461 return -1;
462 }
463
464 label = particle->GetMother(0);
465 }
466
467 return label;
468}
9cd015f7 469
dd367a14 470//____________________________________________________________________
471void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
472{
473 //
474 // normalizes a 1-d histogram to its bin width
475 //
476
477 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
478 {
479 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
480 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
481 }
482}
483
484//____________________________________________________________________
485void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
486{
487 //
488 // normalizes a 2-d histogram to its bin width (x width * y width)
489 //
490
491 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
492 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
493 {
494 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
495 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
496 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
497 }
498}
d1f50534 499
500//____________________________________________________________________
501void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
502{
503 //
504 // Prints the given configuration
505 //
506
507 TString str(">>>> Running with ");
508
509 switch (analysisMode)
510 {
773f84dc 511 case kInvalid: str += "invalid setting"; break;
d1f50534 512 case kSPD : str += "SPD-only"; break;
513 case kTPC : str += "TPC-only"; break;
514 case kTPCITS : str += "Global tracking"; break;
515 }
516
517 str += " and trigger ";
518
519 switch (trigger)
520 {
521 case kMB1 : str += "MB1"; break;
522 case kMB2 : str += "MB2"; break;
1c15d51a 523 case kSPDFASTOR : str += "SPD FASTOR"; break;
d1f50534 524 }
525
526 str += " <<<<";
527
528 Printf("%s", str.Data());
529}
530