3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
21 #include <AliESDEvent.h>
22 #include <AliESDVertex.h>
24 #include <AliGenEventHeader.h>
25 #include <AliGenPythiaEventHeader.h>
26 #include <AliGenCocktailEventHeader.h>
28 //____________________________________________________________________
29 ClassImp(AliPWG0Helper)
31 //____________________________________________________________________
32 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
34 // see function with ULong64_t argument
36 ULong64_t triggerMask = aEsd->GetTriggerMask();
37 return IsEventTriggered(triggerMask, trigger);
40 //____________________________________________________________________
41 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
43 // check if the event was triggered
45 // this function needs the branch fTriggerMask
48 // definitions from p-p.cfg
49 ULong64_t spdFO = (1 << 14);
50 ULong64_t v0left = (1 << 11);
51 ULong64_t v0right = (1 << 12);
57 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
63 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
72 //____________________________________________________________________
73 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESD* aEsd)
75 // see function with AliESDVertex argument
77 const AliESDVertex* vtxESD = aEsd->GetVertex();
78 return IsVertexReconstructed(vtxESD);
81 //____________________________________________________________________
82 Bool_t AliPWG0Helper::IsVertexReconstructed(const AliESDVertex* vtxESD)
84 // checks if the vertex is reasonable
86 // this function needs the branches fSPDVertex*
91 // the vertex should be reconstructed
92 if (strcmp(vtxESD->GetName(), "default")==0)
95 // check Ncontributors
96 if (vtxESD->GetNContributors() <= 0)
100 vtx_res[0] = vtxESD->GetXRes();
101 vtx_res[1] = vtxESD->GetYRes();
102 vtx_res[2] = vtxESD->GetZRes();
104 if (vtx_res[2]==0 || vtx_res[2]>0.1)
110 //____________________________________________________________________
111 const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMode analysisMode)
113 // Get the vertex from the ESD and returns it if the vertex is valid
115 // Second argument decides which vertex is used (this selects
116 // also the quality criteria that are applied)
118 const AliESDVertex* vertex = 0;
119 Float_t requiredZResolution = -1;
120 if (analysisMode == kSPD || analysisMode == kTPCITS)
122 vertex = aEsd->GetVertex();
123 requiredZResolution = 0.1;
125 else if (analysisMode == kTPC)
127 vertex = aEsd->GetPrimaryVertex();
128 requiredZResolution = 0.6;
131 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
136 // check Ncontributors
137 if (vertex->GetNContributors() <= 0)
141 Double_t zRes = vertex->GetZRes();
143 if (zRes == 0 || zRes > requiredZResolution)
149 //____________________________________________________________________
150 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
153 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
154 // shall be counted as a primary particle
156 // This function or a equivalent should be available in some common place of AliRoot
158 // WARNING: Call this function only for particles that are among the particles from the event generator!
159 // --> stack->Particle(id) with id < stack->GetNprimary()
161 // if the particle has a daughter primary, we do not want to count it
162 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
165 printf("Dropping particle because it has a daughter among the primaries.\n");
169 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
171 // skip quarks and gluon
172 if (pdgCode <= 10 || pdgCode == 21)
175 printf("Dropping particle because it is a quark or gluon.\n");
179 if (strcmp(aParticle->GetName(),"XXX") == 0)
182 printf("WARNING: There is a particle named XXX.\n");
186 TParticlePDG* pdgPart = aParticle->GetPDG();
188 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
191 printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
195 if (pdgPart->Charge() == 0)
198 printf("Dropping particle because it is not charged.\n");
205 //____________________________________________________________________
206 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
208 // create projections of 3d hists to all 2d combinations
209 // the histograms are not returned, just use them from memory or use this to create them in a file
211 TH1* proj = hist->Project3D("yx");
212 proj->SetXTitle(hist->GetXaxis()->GetTitle());
213 proj->SetYTitle(hist->GetYaxis()->GetTitle());
217 proj = hist->Project3D("zx");
218 proj->SetXTitle(hist->GetXaxis()->GetTitle());
219 proj->SetYTitle(hist->GetZaxis()->GetTitle());
223 proj = hist->Project3D("zy");
224 proj->SetXTitle(hist->GetYaxis()->GetTitle());
225 proj->SetYTitle(hist->GetZaxis()->GetTitle());
230 //____________________________________________________________________
231 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
233 // create projections of the 3d hists divides them
234 // axis decides to which plane, if axis is 0 to all planes
235 // the histograms are not returned, just use them from memory or use this to create them in a file
239 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
240 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
241 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
246 TH1* proj = hist->Project3D(axis);
248 if (strlen(axis) == 2)
250 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
251 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
253 else if (strlen(axis) == 1)
254 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
256 TH1* proj2 = hist2->Project3D(axis);
257 if (strlen(axis) == 2)
259 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
260 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
262 else if (strlen(axis) == 1)
263 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
265 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
266 //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()));
267 //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()));
268 division->Divide(proj, proj2, 1, 1, "B");
269 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
274 if (division->GetDimension() == 1)
276 Int_t nBins = division->GetNbinsX();
277 for (Int_t i = 1; i <= nBins; ++i)
278 if (proj2->GetBinContent(i) != 0)
279 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
281 else if (division->GetDimension() == 2)
283 Int_t nBinsX = division->GetNbinsX();
284 Int_t nBinsY = division->GetNbinsY();
285 for (Int_t i = 1; i <= nBinsX; ++i)
286 for (Int_t j = 1; j <= nBinsY; ++j)
287 if (proj2->GetBinContent(i, j) != 0)
288 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
300 //____________________________________________________________________
301 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
303 // returns the title of the axis given in axis (x, y, z)
306 return hist->GetXaxis()->GetTitle();
307 else if (axis == 'y')
308 return hist->GetYaxis()->GetTitle();
309 else if (axis == 'z')
310 return hist->GetZaxis()->GetTitle();
315 //____________________________________________________________________
316 Int_t AliPWG0Helper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
318 // get the process type of the event.
321 // can only read pythia headers, either directly or from cocktalil header
322 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
324 if (!pythiaGenHeader) {
326 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
327 if (!genCocktailHeader) {
328 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
332 TList* headerList = genCocktailHeader->GetHeaders();
337 for (Int_t i=0; i<headerList->GetEntries(); i++) {
338 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
343 if (!pythiaGenHeader) {
344 printf("AliPWG0Helper::GetProcessType : Could not find Pythia header. \n");
350 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
353 return pythiaGenHeader->ProcessType();
356 //____________________________________________________________________
357 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
360 // Finds the first mother among the primary particles of the particle identified by <label>,
361 // i.e. the primary that "caused" this particle
364 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
368 return stack->Particle(motherLabel);
371 //____________________________________________________________________
372 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
375 // Finds the first mother among the primary particles of the particle identified by <label>,
376 // i.e. the primary that "caused" this particle
381 Int_t nPrim = stack->GetNprimary();
383 while (label >= nPrim)
385 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
387 TParticle* particle = stack->Particle(label);
390 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
395 if (particle->GetMother(0) < 0)
397 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
401 label = particle->GetMother(0);
407 void AliPWG0Helper::SetBranchStatusRecursive(TTree* tree, char *bname, Bool_t status, Bool_t debug)
409 // Function to switch on/off all data members of a top level branch
410 // this is needed for branches without a trailing dot ".", for those
411 // the root functionality with regular expressions does not work.
413 // chain->SetBranchStatus("*", 0);
414 // SetBranchStatusRecursive(chain,"SPDVertex",1);
415 // You need to give the full name of the top level branch zou want to access
416 //==========================================================================
417 // Author Christian.Klein-Boesing@cern.ch
422 TBranch *br = tree->GetBranch(bname);
424 Printf("AliPWG0Helper::SetBranchStatusRecursive: Branch %s not found", bname);
427 TObjArray *leaves = tree->GetListOfLeaves();
428 Int_t nleaves = leaves->GetEntries();
432 for (Int_t i=0;i<nleaves;i++) {
433 // the matched entry e.g. SPDVertex is its own Mother
434 leaf = (TLeaf*)leaves->UncheckedAt(i);
435 branch = (TBranch*)leaf->GetBranch();
436 mother = branch->GetMother();
439 Printf(">>>> AliPWG0Helper::SetBranchStatusRecursive: Setting status %s %s to %d", mother->GetName(), leaf->GetName(), status);
440 if (status) branch->ResetBit(kDoNotProcess);
441 else branch->SetBit(kDoNotProcess);
446 //____________________________________________________________________
447 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
450 // normalizes a 1-d histogram to its bin width
453 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
455 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
456 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
460 //____________________________________________________________________
461 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
464 // normalizes a 2-d histogram to its bin width (x width * y width)
467 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
468 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
470 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
471 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
472 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);