3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
12 #include <AliESDVertex.h>
14 //____________________________________________________________________
15 ClassImp(AliPWG0Helper)
17 //____________________________________________________________________
18 Bool_t AliPWG0Helper::IsEventTriggered(AliESD* aEsd)
20 // check if the event was triggered
22 // this function needs the branch fTriggerMask
25 // ITS_SPD_GFO_L0 : 32
29 ULong64_t triggerMask = aEsd->GetTriggerMask();
31 if (triggerMask&32 && ((triggerMask&1) || (triggerMask&2)))
37 //____________________________________________________________________
38 Bool_t AliPWG0Helper::IsVertexReconstructed(AliESD* aEsd)
40 // checks if the vertex is reasonable
42 // this function needs the branches fSPDVertex*
45 const AliESDVertex* vtxESD = aEsd->GetVertex();
47 // the vertex should be reconstructed
48 if (strcmp(vtxESD->GetName(), "default")==0)
52 vtx_res[0] = vtxESD->GetXRes();
53 vtx_res[1] = vtxESD->GetYRes();
54 vtx_res[2] = vtxESD->GetZRes();
56 if (vtx_res[2]==0 || vtx_res[2]>0.1)
62 //____________________________________________________________________
63 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
66 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
67 // shall be counted as a primary particle
69 // This function or a equivalent should be available in some common place of AliRoot
72 // if the particle has a daughter primary, we do not want to count it
73 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
76 printf("Dropping particle because it has a daughter among the primaries.\n");
80 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
82 // skip quarks and gluon
83 if (pdgCode <= 10 || pdgCode == 21)
86 printf("Dropping particle because it is a quark or gluon.\n");
90 if (strcmp(aParticle->GetName(),"XXX") == 0)
93 printf("WARNING: There is a particle named XXX.\n");
97 TParticlePDG* pdgPart = aParticle->GetPDG();
99 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
102 printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
106 if (pdgPart->Charge() == 0)
109 printf("Dropping particle because it is not charged.\n");
116 //____________________________________________________________________
117 void AliPWG0Helper::CreateProjections(TH3* hist)
119 // create projections of 3d hists to all 2d combinations
120 // the histograms are not returned, just use them from memory or use this to create them in a file
122 TH1* proj = hist->Project3D("yx");
123 proj->SetXTitle(hist->GetXaxis()->GetTitle());
124 proj->SetYTitle(hist->GetYaxis()->GetTitle());
126 proj = hist->Project3D("zx");
127 proj->SetXTitle(hist->GetXaxis()->GetTitle());
128 proj->SetYTitle(hist->GetZaxis()->GetTitle());
130 proj = hist->Project3D("zy");
131 proj->SetXTitle(hist->GetYaxis()->GetTitle());
132 proj->SetYTitle(hist->GetZaxis()->GetTitle());
135 //____________________________________________________________________
136 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors)
138 // create projections of the 3d hists divides them
139 // axis decides to which plane, if axis is 0 to all planes
140 // the histograms are not returned, just use them from memory or use this to create them in a file
144 CreateDividedProjections(hist, hist2, "yx", putErrors);
145 CreateDividedProjections(hist, hist2, "zx", putErrors);
146 CreateDividedProjections(hist, hist2, "zy", putErrors);
151 TH1* proj = hist->Project3D(axis);
153 if (strlen(axis) == 2)
155 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
156 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
158 else if (strlen(axis) == 1)
159 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
161 TH1* proj2 = hist2->Project3D(axis);
162 if (strlen(axis) == 2)
164 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
165 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
167 else if (strlen(axis) == 1)
168 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
170 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
171 division->Divide(proj2);
176 if (division->GetDimension() == 1)
178 Int_t nBins = division->GetNbinsX();
179 for (Int_t i = 0; i <= nBins; ++i)
180 if (proj2->GetBinContent(i) != 0)
181 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
183 else if (division->GetDimension() == 2)
185 Int_t nBinsX = division->GetNbinsX();
186 Int_t nBinsY = division->GetNbinsY();
187 for (Int_t i = 0; i <= nBinsX; ++i)
188 for (Int_t j = 0; j <= nBinsY; ++j)
189 if (proj2->GetBinContent(i, j) != 0)
190 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
195 //____________________________________________________________________
196 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
198 // returns the title of the axis given in axis (x, y, z)
201 return hist->GetXaxis()->GetTitle();
202 else if (axis == 'y')
203 return hist->GetYaxis()->GetTitle();
204 else if (axis == 'z')
205 return hist->GetZaxis()->GetTitle();