3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
21 #include <AliESDVertex.h>
23 #include <AliGenEventHeader.h>
24 #include <AliGenPythiaEventHeader.h>
25 #include <AliGenCocktailEventHeader.h>
27 //____________________________________________________________________
28 ClassImp(AliPWG0Helper)
30 //____________________________________________________________________
31 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
33 // see function with ULong64_t argument
35 ULong64_t triggerMask = aEsd->GetTriggerMask();
36 return IsEventTriggered(triggerMask, trigger);
39 //____________________________________________________________________
40 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
42 // check if the event was triggered
44 // this function needs the branch fTriggerMask
47 // definitions from p-p.cfg
48 ULong64_t spdFO = (1 << 14);
49 ULong64_t v0left = (1 << 11);
50 ULong64_t v0right = (1 << 12);
56 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
62 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
71 //____________________________________________________________________
72 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESD* aEsd)
74 // see function with AliESDVertex argument
76 const AliESDVertex* vtxESD = aEsd->GetVertex();
77 return IsVertexReconstructed(vtxESD);
80 //____________________________________________________________________
81 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESDVertex* vtxESD)
83 // checks if the vertex is reasonable
85 // this function needs the branches fSPDVertex*
90 // the vertex should be reconstructed
91 if (strcmp(vtxESD->GetName(), "default")==0)
94 // check Ncontributors
95 if (vtxESD->GetNContributors() <= 0)
99 vtx_res[0] = vtxESD->GetXRes();
100 vtx_res[1] = vtxESD->GetYRes();
101 vtx_res[2] = vtxESD->GetZRes();
103 if (vtx_res[2]==0 || vtx_res[2]>0.1)
109 //____________________________________________________________________
110 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
113 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
114 // shall be counted as a primary particle
116 // This function or a equivalent should be available in some common place of AliRoot
118 // WARNING: Call this function only for particles that are among the particles from the event generator!
119 // --> stack->Particle(id) with id < stack->GetNprimary()
121 // if the particle has a daughter primary, we do not want to count it
122 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
125 printf("Dropping particle because it has a daughter among the primaries.\n");
129 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
131 // skip quarks and gluon
132 if (pdgCode <= 10 || pdgCode == 21)
135 printf("Dropping particle because it is a quark or gluon.\n");
139 if (strcmp(aParticle->GetName(),"XXX") == 0)
142 printf("WARNING: There is a particle named XXX.\n");
146 TParticlePDG* pdgPart = aParticle->GetPDG();
148 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
151 printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
155 if (pdgPart->Charge() == 0)
158 printf("Dropping particle because it is not charged.\n");
165 //____________________________________________________________________
166 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
168 // create projections of 3d hists to all 2d combinations
169 // the histograms are not returned, just use them from memory or use this to create them in a file
171 TH1* proj = hist->Project3D("yx");
172 proj->SetXTitle(hist->GetXaxis()->GetTitle());
173 proj->SetYTitle(hist->GetYaxis()->GetTitle());
177 proj = hist->Project3D("zx");
178 proj->SetXTitle(hist->GetXaxis()->GetTitle());
179 proj->SetYTitle(hist->GetZaxis()->GetTitle());
183 proj = hist->Project3D("zy");
184 proj->SetXTitle(hist->GetYaxis()->GetTitle());
185 proj->SetYTitle(hist->GetZaxis()->GetTitle());
190 //____________________________________________________________________
191 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
193 // create projections of the 3d hists divides them
194 // axis decides to which plane, if axis is 0 to all planes
195 // the histograms are not returned, just use them from memory or use this to create them in a file
199 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
200 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
201 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
206 TH1* proj = hist->Project3D(axis);
208 if (strlen(axis) == 2)
210 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
211 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
213 else if (strlen(axis) == 1)
214 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
216 TH1* proj2 = hist2->Project3D(axis);
217 if (strlen(axis) == 2)
219 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
220 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
222 else if (strlen(axis) == 1)
223 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
225 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
226 //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()));
227 //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()));
228 division->Divide(proj, proj2, 1, 1, "B");
229 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
234 if (division->GetDimension() == 1)
236 Int_t nBins = division->GetNbinsX();
237 for (Int_t i = 1; i <= nBins; ++i)
238 if (proj2->GetBinContent(i) != 0)
239 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
241 else if (division->GetDimension() == 2)
243 Int_t nBinsX = division->GetNbinsX();
244 Int_t nBinsY = division->GetNbinsY();
245 for (Int_t i = 1; i <= nBinsX; ++i)
246 for (Int_t j = 1; j <= nBinsY; ++j)
247 if (proj2->GetBinContent(i, j) != 0)
248 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
260 //____________________________________________________________________
261 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
263 // returns the title of the axis given in axis (x, y, z)
266 return hist->GetXaxis()->GetTitle();
267 else if (axis == 'y')
268 return hist->GetYaxis()->GetTitle();
269 else if (axis == 'z')
270 return hist->GetZaxis()->GetTitle();
275 //____________________________________________________________________
276 Int_t AliPWG0Helper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
278 // get the process type of the event.
281 // can only read pythia headers, either directly or from cocktalil header
282 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
284 if (!pythiaGenHeader) {
286 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
287 if (!genCocktailHeader) {
288 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
292 TList* headerList = genCocktailHeader->GetHeaders();
297 for (Int_t i=0; i<headerList->GetEntries(); i++) {
298 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
303 if (!pythiaGenHeader) {
304 printf("AliPWG0Helper::GetProcessType : Could not find Pythia header. \n");
310 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
313 return pythiaGenHeader->ProcessType();
316 //____________________________________________________________________
317 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
320 // Finds the first mother among the primary particles of the particle identified by <label>,
321 // i.e. the primary that "caused" this particle
324 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
328 return stack->Particle(motherLabel);
331 //____________________________________________________________________
332 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
335 // Finds the first mother among the primary particles of the particle identified by <label>,
336 // i.e. the primary that "caused" this particle
341 Int_t nPrim = stack->GetNprimary();
343 while (label >= nPrim)
345 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
347 TParticle* particle = stack->Particle(label);
350 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
355 if (particle->GetMother(0) < 0)
357 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
361 label = particle->GetMother(0);
367 void AliPWG0Helper::SetBranchStatusRecursive(TTree* tree, char *bname, Bool_t status, Bool_t debug)
369 // Function to switch on/off all data members of a top level branch
370 // this is needed for branches without a trailing dot ".", for those
371 // the root functionality with regular expressions does not work.
373 // chain->SetBranchStatus("*", 0);
374 // SetBranchStatusRecursive(chain,"SPDVertex",1);
375 // You need to give the full name of the top level branch zou want to access
376 //==========================================================================
377 // Author Christian.Klein-Boesing@cern.ch
382 TBranch *br = tree->GetBranch(bname);
384 Printf("AliPWG0Helper::SetBranchStatusRecursive: Branch %s not found", bname);
387 TObjArray *leaves = tree->GetListOfLeaves();
388 Int_t nleaves = leaves->GetEntries();
392 for (Int_t i=0;i<nleaves;i++) {
393 // the matched entry e.g. SPDVertex is its own Mother
394 leaf = (TLeaf*)leaves->UncheckedAt(i);
395 branch = (TBranch*)leaf->GetBranch();
396 mother = branch->GetMother();
399 Printf(">>>> AliPWG0Helper::SetBranchStatusRecursive: Setting status %s %s to %d", mother->GetName(), leaf->GetName(), status);
400 if (status) branch->ResetBit(kDoNotProcess);
401 else branch->SetBit(kDoNotProcess);
406 //____________________________________________________________________
407 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
410 // normalizes a 1-d histogram to its bin width
413 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
415 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
416 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
420 //____________________________________________________________________
421 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
424 // normalizes a 2-d histogram to its bin width (x width * y width)
427 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
428 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
430 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
431 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
432 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);