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