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, Bool_t debug)
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->GetPrimaryVertexSPD();
123 requiredZResolution = 0.1;
125 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
127 else if (analysisMode == kTPC)
129 vertex = aEsd->GetPrimaryVertexTPC();
130 requiredZResolution = 0.6;
132 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
135 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
139 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
143 // check Ncontributors
144 if (vertex->GetNContributors() <= 0) {
146 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0");
151 Double_t zRes = vertex->GetZRes();
153 if (zRes == 0 || zRes > requiredZResolution) {
155 Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
160 Printf("AliPWG0Helper::GetVertex: Returning valid vertex");
165 //____________________________________________________________________
166 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
169 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
170 // shall be counted as a primary particle
172 // This function or a equivalent should be available in some common place of AliRoot
174 // WARNING: Call this function only for particles that are among the particles from the event generator!
175 // --> stack->Particle(id) with id < stack->GetNprimary()
177 // if the particle has a daughter primary, we do not want to count it
178 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
181 printf("Dropping particle because it has a daughter among the primaries.\n");
185 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
187 // skip quarks and gluon
188 if (pdgCode <= 10 || pdgCode == 21)
191 printf("Dropping particle because it is a quark or gluon.\n");
195 if (strcmp(aParticle->GetName(),"XXX") == 0)
198 printf("WARNING: There is a particle named XXX.\n");
202 TParticlePDG* pdgPart = aParticle->GetPDG();
204 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
207 printf("WARNING: There is a particle with an unknown particle class (pdg code %d).\n", pdgCode);
211 if (pdgPart->Charge() == 0)
214 printf("Dropping particle because it is not charged.\n");
221 //____________________________________________________________________
222 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
224 // create projections of 3d hists to all 2d combinations
225 // the histograms are not returned, just use them from memory or use this to create them in a file
227 TH1* proj = hist->Project3D("yx");
228 proj->SetXTitle(hist->GetXaxis()->GetTitle());
229 proj->SetYTitle(hist->GetYaxis()->GetTitle());
233 proj = hist->Project3D("zx");
234 proj->SetXTitle(hist->GetXaxis()->GetTitle());
235 proj->SetYTitle(hist->GetZaxis()->GetTitle());
239 proj = hist->Project3D("zy");
240 proj->SetXTitle(hist->GetYaxis()->GetTitle());
241 proj->SetYTitle(hist->GetZaxis()->GetTitle());
246 //____________________________________________________________________
247 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
249 // create projections of the 3d hists divides them
250 // axis decides to which plane, if axis is 0 to all planes
251 // the histograms are not returned, just use them from memory or use this to create them in a file
255 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
256 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
257 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
262 TH1* proj = hist->Project3D(axis);
264 if (strlen(axis) == 2)
266 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
267 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
269 else if (strlen(axis) == 1)
270 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
272 TH1* proj2 = hist2->Project3D(axis);
273 if (strlen(axis) == 2)
275 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
276 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
278 else if (strlen(axis) == 1)
279 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
281 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
282 //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()));
283 //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()));
284 division->Divide(proj, proj2, 1, 1, "B");
285 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
290 if (division->GetDimension() == 1)
292 Int_t nBins = division->GetNbinsX();
293 for (Int_t i = 1; i <= nBins; ++i)
294 if (proj2->GetBinContent(i) != 0)
295 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
297 else if (division->GetDimension() == 2)
299 Int_t nBinsX = division->GetNbinsX();
300 Int_t nBinsY = division->GetNbinsY();
301 for (Int_t i = 1; i <= nBinsX; ++i)
302 for (Int_t j = 1; j <= nBinsY; ++j)
303 if (proj2->GetBinContent(i, j) != 0)
304 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
316 //____________________________________________________________________
317 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
319 // returns the title of the axis given in axis (x, y, z)
322 return hist->GetXaxis()->GetTitle();
323 else if (axis == 'y')
324 return hist->GetYaxis()->GetTitle();
325 else if (axis == 'z')
326 return hist->GetZaxis()->GetTitle();
331 //____________________________________________________________________
332 Int_t AliPWG0Helper::GetPythiaEventProcessType(AliHeader* aHeader, Bool_t adebug) {
334 // get the process type of the event.
337 // can only read pythia headers, either directly or from cocktalil header
338 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
340 if (!pythiaGenHeader) {
342 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
343 if (!genCocktailHeader) {
344 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
348 TList* headerList = genCocktailHeader->GetHeaders();
353 for (Int_t i=0; i<headerList->GetEntries(); i++) {
354 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
359 if (!pythiaGenHeader) {
360 printf("AliPWG0Helper::GetProcessType : Could not find Pythia header. \n");
366 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaGenHeader->ProcessType());
369 return pythiaGenHeader->ProcessType();
372 //____________________________________________________________________
373 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
376 // Finds the first mother among the primary particles of the particle identified by <label>,
377 // i.e. the primary that "caused" this particle
380 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
384 return stack->Particle(motherLabel);
387 //____________________________________________________________________
388 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
391 // Finds the first mother among the primary particles of the particle identified by <label>,
392 // i.e. the primary that "caused" this particle
397 Int_t nPrim = stack->GetNprimary();
399 while (label >= nPrim)
401 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
403 TParticle* particle = stack->Particle(label);
406 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
411 if (particle->GetMother(0) < 0)
413 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
417 label = particle->GetMother(0);
423 void AliPWG0Helper::SetBranchStatusRecursive(TTree* tree, char *bname, Bool_t status, Bool_t debug)
425 // Function to switch on/off all data members of a top level branch
426 // this is needed for branches without a trailing dot ".", for those
427 // the root functionality with regular expressions does not work.
429 // chain->SetBranchStatus("*", 0);
430 // SetBranchStatusRecursive(chain,"SPDVertex",1);
431 // You need to give the full name of the top level branch zou want to access
432 //==========================================================================
433 // Author Christian.Klein-Boesing@cern.ch
438 TBranch *br = tree->GetBranch(bname);
440 Printf("AliPWG0Helper::SetBranchStatusRecursive: Branch %s not found", bname);
443 TObjArray *leaves = tree->GetListOfLeaves();
444 Int_t nleaves = leaves->GetEntries();
448 for (Int_t i=0;i<nleaves;i++) {
449 // the matched entry e.g. SPDVertex is its own Mother
450 leaf = (TLeaf*)leaves->UncheckedAt(i);
451 branch = (TBranch*)leaf->GetBranch();
452 mother = branch->GetMother();
455 Printf(">>>> AliPWG0Helper::SetBranchStatusRecursive: Setting status %s %s to %d", mother->GetName(), leaf->GetName(), status);
456 if (status) branch->ResetBit(kDoNotProcess);
457 else branch->SetBit(kDoNotProcess);
462 //____________________________________________________________________
463 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
466 // normalizes a 1-d histogram to its bin width
469 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
471 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
472 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
476 //____________________________________________________________________
477 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
480 // normalizes a 2-d histogram to its bin width (x width * y width)
483 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
484 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
486 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
487 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
488 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
492 //____________________________________________________________________
493 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
496 // Prints the given configuration
499 TString str(">>>> Running with ");
501 switch (analysisMode)
503 case kSPD : str += "SPD-only"; break;
504 case kTPC : str += "TPC-only"; break;
505 case kTPCITS : str += "Global tracking"; break;
508 str += " and trigger ";
512 case kMB1 : str += "MB1"; break;
513 case kMB2 : str += "MB2"; break;
518 Printf("%s", str.Data());