]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliPWG0depHelper.cxx
Keep only the forward mapping array persistent, the inverse one is created on demand...
[u/mrichter/AliRoot.git] / PWG0 / AliPWG0depHelper.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 #include <TList.h>
19 #include <TParticle.h>
20
21 #include <AliPWG0depHelper.h>
22
23 #include <AliHeader.h>
24 #include <AliStack.h>
25 #include <AliLog.h>
26
27 #include <AliGenEventHeader.h>
28 #include <AliGenPythiaEventHeader.h>
29 #include <AliGenCocktailEventHeader.h>
30
31 //____________________________________________________________________
32 ClassImp(AliPWG0depHelper)
33
34 //____________________________________________________________________
35 Int_t AliPWG0depHelper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
36   //
37   // get the process type of the event.
38   //
39
40   // can only read pythia headers, either directly or from cocktalil header
41   AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
42
43   if (!pythiaGenHeader) {
44
45     AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
46     if (!genCocktailHeader) {
47       printf("AliPWG0depHelper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
48       return -1;
49     }
50
51     TList* headerList = genCocktailHeader->GetHeaders();
52     if (!headerList) {
53       return -1;
54     }
55
56     for (Int_t i=0; i<headerList->GetEntries(); i++) {
57       pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
58       if (pythiaGenHeader)
59         break;
60     }
61
62     if (!pythiaGenHeader) {
63       printf("AliPWG0depHelper::GetProcessType : Could not find Pythia header. \n");
64       return -1;
65     }
66   }
67
68   if (adebug) {
69     printf("AliPWG0depHelper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
70   }
71
72   return pythiaGenHeader->ProcessType();
73 }
74
75 //____________________________________________________________________
76 TParticle* AliPWG0depHelper::FindPrimaryMother(AliStack* stack, Int_t label)
77 {
78   //
79   // Finds the first mother among the primary particles of the particle identified by <label>,
80   // i.e. the primary that "caused" this particle
81   //
82
83   Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
84   if (motherLabel < 0)
85     return 0;
86
87   return stack->Particle(motherLabel);
88 }
89
90 //____________________________________________________________________
91 Int_t AliPWG0depHelper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
92 {
93   //
94   // Finds the first mother among the primary particles of the particle identified by <label>,
95   // i.e. the primary that "caused" this particle
96   //
97   // returns its label
98   //
99
100   Int_t nPrim  = stack->GetNprimary();
101
102   while (label >= nPrim)
103   {
104     //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
105
106     TParticle* particle = stack->Particle(label);
107     if (!particle)
108     {
109       AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
110       return -1;
111     }
112  
113     // find mother
114     if (particle->GetMother(0) < 0)
115     {
116       AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
117       return -1;
118     }
119
120     label = particle->GetMother(0);
121   }
122
123   return label;
124 }
125
126