3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
11 #include <AliHeader.h>
17 #include <AliESDVertex.h>
19 #include <AliGenEventHeader.h>
20 #include <AliGenPythiaEventHeader.h>
21 #include <AliGenCocktailEventHeader.h>
23 //____________________________________________________________________
24 ClassImp(AliPWG0Helper)
26 //____________________________________________________________________
27 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
29 // see function with ULong64_t argument
31 ULong64_t triggerMask = aEsd->GetTriggerMask();
32 return IsEventTriggered(triggerMask, trigger);
35 //____________________________________________________________________
36 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
38 // check if the event was triggered
40 // this function needs the branch fTriggerMask
43 // ITS_SPD_GFO_L0 : 32
51 if (triggerMask&32 || ((triggerMask&1) || (triggerMask&2)))
57 if (triggerMask&32 && ((triggerMask&1) || (triggerMask&2)))
66 //____________________________________________________________________
67 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESD* aEsd)
69 // see function with AliESDVertex argument
71 const AliESDVertex* vtxESD = aEsd->GetVertex();
72 return IsVertexReconstructed(vtxESD);
75 //____________________________________________________________________
76 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESDVertex* vtxESD)
78 // checks if the vertex is reasonable
80 // this function needs the branches fSPDVertex*
85 // the vertex should be reconstructed
86 if (strcmp(vtxESD->GetName(), "default")==0)
90 vtx_res[0] = vtxESD->GetXRes();
91 vtx_res[1] = vtxESD->GetYRes();
92 vtx_res[2] = vtxESD->GetZRes();
94 if (vtx_res[2]==0 || vtx_res[2]>0.1)
97 // check Ncontributors, if <0 it means error *gna*
102 //____________________________________________________________________
103 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
106 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
107 // shall be counted as a primary particle
109 // This function or a equivalent should be available in some common place of AliRoot
112 // if the particle has a daughter primary, we do not want to count it
113 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
116 printf("Dropping particle because it has a daughter among the primaries.\n");
120 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
122 // skip quarks and gluon
123 if (pdgCode <= 10 || pdgCode == 21)
126 printf("Dropping particle because it is a quark or gluon.\n");
130 if (strcmp(aParticle->GetName(),"XXX") == 0)
133 printf("WARNING: There is a particle named XXX.\n");
137 TParticlePDG* pdgPart = aParticle->GetPDG();
139 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
142 printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
146 if (pdgPart->Charge() == 0)
149 printf("Dropping particle because it is not charged.\n");
156 //____________________________________________________________________
157 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
159 // create projections of 3d hists to all 2d combinations
160 // the histograms are not returned, just use them from memory or use this to create them in a file
162 TH1* proj = hist->Project3D("yx");
163 proj->SetXTitle(hist->GetXaxis()->GetTitle());
164 proj->SetYTitle(hist->GetYaxis()->GetTitle());
168 proj = hist->Project3D("zx");
169 proj->SetXTitle(hist->GetXaxis()->GetTitle());
170 proj->SetYTitle(hist->GetZaxis()->GetTitle());
174 proj = hist->Project3D("zy");
175 proj->SetXTitle(hist->GetYaxis()->GetTitle());
176 proj->SetYTitle(hist->GetZaxis()->GetTitle());
181 //____________________________________________________________________
182 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
184 // create projections of the 3d hists divides them
185 // axis decides to which plane, if axis is 0 to all planes
186 // the histograms are not returned, just use them from memory or use this to create them in a file
190 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
191 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
192 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
197 TH1* proj = hist->Project3D(axis);
199 if (strlen(axis) == 2)
201 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
202 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
204 else if (strlen(axis) == 1)
205 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
207 TH1* proj2 = hist2->Project3D(axis);
208 if (strlen(axis) == 2)
210 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
211 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
213 else if (strlen(axis) == 1)
214 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
216 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
217 //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()));
218 //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()));
219 division->Divide(proj, proj2, 1, 1, "B");
220 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
225 if (division->GetDimension() == 1)
227 Int_t nBins = division->GetNbinsX();
228 for (Int_t i = 1; i <= nBins; ++i)
229 if (proj2->GetBinContent(i) != 0)
230 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
232 else if (division->GetDimension() == 2)
234 Int_t nBinsX = division->GetNbinsX();
235 Int_t nBinsY = division->GetNbinsY();
236 for (Int_t i = 1; i <= nBinsX; ++i)
237 for (Int_t j = 1; j <= nBinsY; ++j)
238 if (proj2->GetBinContent(i, j) != 0)
239 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
251 //____________________________________________________________________
252 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
254 // returns the title of the axis given in axis (x, y, z)
257 return hist->GetXaxis()->GetTitle();
258 else if (axis == 'y')
259 return hist->GetYaxis()->GetTitle();
260 else if (axis == 'z')
261 return hist->GetZaxis()->GetTitle();
266 //____________________________________________________________________
267 Int_t AliPWG0Helper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
269 // get the process type of the event.
272 // can only read pythia headers, either directly or from cocktalil header
273 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
275 if (!pythiaGenHeader) {
277 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
278 if (!genCocktailHeader) {
279 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
283 TList* headerList = genCocktailHeader->GetHeaders();
288 for (Int_t i=0; i<headerList->GetEntries(); i++) {
289 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
294 if (!pythiaGenHeader) {
295 printf("AliPWG0Helper::GetProcessType : Could not find Pythia header. \n");
301 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
304 return pythiaGenHeader->ProcessType();
307 //____________________________________________________________________
308 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
311 // Finds the first mother among the primary particles of the particle identified by <label>,
312 // i.e. the primary that "caused" this particle
315 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
319 return stack->Particle(motherLabel);
322 //____________________________________________________________________
323 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
326 // Finds the first mother among the primary particles of the particle identified by <label>,
327 // i.e. the primary that "caused" this particle
332 Int_t nPrim = stack->GetNprimary();
334 while (label >= nPrim)
336 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
338 TParticle* particle = stack->Particle(label);
341 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
346 if (particle->GetMother(0) < 0)
348 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
352 label = particle->GetMother(0);