3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
20 #include <AliESDEvent.h>
21 #include <AliESDVertex.h>
22 #include <AliVertexerTracks.h>
23 #include <AliMultiplicity.h>
25 #include <AliGenEventHeader.h>
26 #include <AliGenPythiaEventHeader.h>
27 #include <AliGenCocktailEventHeader.h>
28 #include <AliGenDPMjetEventHeader.h>
29 #include <AliESDVZERO.h>
31 #include <AliOfflineTrigger.h>
33 //____________________________________________________________________
34 ClassImp(AliPWG0Helper)
36 Int_t AliPWG0Helper::fgLastProcessType = -1;
37 AliOfflineTrigger* AliPWG0Helper::fgOfflineTrigger = 0;
39 //____________________________________________________________________
40 AliOfflineTrigger* AliPWG0Helper::GetOfflineTrigger()
42 // returns the current AliOfflineTrigger object
43 // creates one if needed
45 if (!fgOfflineTrigger)
46 fgOfflineTrigger = new AliOfflineTrigger;
48 return fgOfflineTrigger;
51 //____________________________________________________________________
52 Bool_t AliPWG0Helper::IsEventTriggered(const AliESDEvent* aEsd, Trigger trigger)
54 // checks if an event has been triggered
56 if (trigger & kOfflineFlag)
57 return GetOfflineTrigger()->IsEventTriggered(aEsd, trigger);
59 return IsEventTriggered(aEsd->GetTriggerMask(), trigger);
62 //____________________________________________________________________
63 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
65 // check if the event was triggered
67 // this function needs the branch fTriggerMask
69 // definitions from p-p.cfg
70 ULong64_t spdFO = (1 << 14);
71 ULong64_t v0left = (1 << 10);
72 ULong64_t v0right = (1 << 11);
83 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
89 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
95 if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
101 if (triggerMask & spdFO)
106 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
113 //____________________________________________________________________
114 Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug)
116 // Checks if a vertex meets the needed quality criteria
118 Float_t requiredZResolution = -1;
119 if (analysisMode & kSPD || analysisMode & kTPCITS)
121 requiredZResolution = 0.1;
123 else if (analysisMode & kTPC)
124 requiredZResolution = 10.;
127 Double_t zRes = vertex->GetZRes();
129 if (zRes > requiredZResolution) {
131 Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
138 //____________________________________________________________________
139 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC)
141 // Get the vertex from the ESD and returns it if the vertex is valid
143 // Second argument decides which vertex is used (this selects
144 // also the quality criteria that are applied)
146 const AliESDVertex* vertex = 0;
147 if (analysisMode & kSPD || analysisMode & kTPCITS)
149 vertex = aEsd->GetPrimaryVertexSPD();
151 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
153 else if (analysisMode & kTPC)
157 Printf("AliPWG0Helper::GetVertex: Redoing vertex");
158 Double_t kBz = aEsd->GetMagneticField();
159 AliVertexerTracks vertexer(kBz);
160 vertexer.SetTPCMode();
161 AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
162 aEsd->SetPrimaryVertexTPC(vTPC);
163 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
164 AliESDtrack *t = aEsd->GetTrack(i);
165 t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
170 vertex = aEsd->GetPrimaryVertexTPC();
172 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
175 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
179 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
183 // check Ncontributors
184 if (vertex->GetNContributors() <= 0) {
186 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
187 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
194 Double_t zRes = vertex->GetZRes();
196 Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
202 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
209 //____________________________________________________________________
210 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
213 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
214 // shall be counted as a primary particle
216 // This function or a equivalent should be available in some common place of AliRoot
218 // WARNING: Call this function only for particles that are among the particles from the event generator!
219 // --> stack->Particle(id) with id < stack->GetNprimary()
221 // if the particle has a daughter primary, we do not want to count it
222 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
225 printf("Dropping particle because it has a daughter among the primaries.\n");
229 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
232 // skip quarks and gluon
233 if (pdgCode <= 10 || pdgCode == 21)
236 printf("Dropping particle because it is a quark or gluon.\n");
240 Int_t status = aParticle->GetStatusCode();
241 // skip non final state particles..
244 printf("Dropping particle because it is not a final state particle.\n");
248 if (strcmp(aParticle->GetName(),"XXX") == 0)
250 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
254 TParticlePDG* pdgPart = aParticle->GetPDG();
256 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
258 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
262 if (pdgPart->Charge() == 0)
265 printf("Dropping particle because it is not charged.\n");
272 //____________________________________________________________________
273 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
275 // create projections of 3d hists to all 2d combinations
276 // the histograms are not returned, just use them from memory or use this to create them in a file
278 TH1* proj = hist->Project3D("yx");
279 proj->SetXTitle(hist->GetXaxis()->GetTitle());
280 proj->SetYTitle(hist->GetYaxis()->GetTitle());
284 proj = hist->Project3D("zx");
285 proj->SetXTitle(hist->GetXaxis()->GetTitle());
286 proj->SetYTitle(hist->GetZaxis()->GetTitle());
290 proj = hist->Project3D("zy");
291 proj->SetXTitle(hist->GetYaxis()->GetTitle());
292 proj->SetYTitle(hist->GetZaxis()->GetTitle());
297 //____________________________________________________________________
298 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
300 // create projections of the 3d hists divides them
301 // axis decides to which plane, if axis is 0 to all planes
302 // the histograms are not returned, just use them from memory or use this to create them in a file
306 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
307 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
308 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
313 TH1* proj = hist->Project3D(axis);
315 if (strlen(axis) == 2)
317 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
318 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
320 else if (strlen(axis) == 1)
321 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
323 TH1* proj2 = hist2->Project3D(axis);
324 if (strlen(axis) == 2)
326 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
327 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
329 else if (strlen(axis) == 1)
330 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
332 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
333 //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()));
334 //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()));
335 division->Divide(proj, proj2, 1, 1, "B");
336 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
341 if (division->GetDimension() == 1)
343 Int_t nBins = division->GetNbinsX();
344 for (Int_t i = 1; i <= nBins; ++i)
345 if (proj2->GetBinContent(i) != 0)
346 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
348 else if (division->GetDimension() == 2)
350 Int_t nBinsX = division->GetNbinsX();
351 Int_t nBinsY = division->GetNbinsY();
352 for (Int_t i = 1; i <= nBinsX; ++i)
353 for (Int_t j = 1; j <= nBinsY; ++j)
354 if (proj2->GetBinContent(i, j) != 0)
355 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
367 //____________________________________________________________________
368 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
370 // returns the title of the axis given in axis (x, y, z)
373 return hist->GetXaxis()->GetTitle();
374 else if (axis == 'y')
375 return hist->GetYaxis()->GetTitle();
376 else if (axis == 'z')
377 return hist->GetZaxis()->GetTitle();
383 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
385 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
387 if (!pythiaGenHeader) {
388 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
389 return kInvalidProcess;
393 Int_t pythiaType = pythiaGenHeader->ProcessType();
394 fgLastProcessType = pythiaType;
395 MCProcessType globalType = kInvalidProcess;
399 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
403 if(pythiaType==92||pythiaType==93){
406 else if(pythiaType==94){
409 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
417 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
419 // get the process type of the event.
422 // can only read pythia headers, either directly or from cocktalil header
423 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
425 if (!dpmJetGenHeader) {
426 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
427 return kInvalidProcess;
430 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
431 fgLastProcessType = dpmJetType;
432 MCProcessType globalType = kInvalidProcess;
436 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
440 if(dpmJetType == 1){ // this is explicitly inelastic
443 else if(dpmJetType==5||dpmJetType==6){
446 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
453 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
455 // get the process type of the event.
459 // Check for simple headers first
461 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
462 if (pythiaGenHeader) {
463 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
466 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
467 if (dpmJetGenHeader) {
468 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
472 // check for cocktail
474 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
475 if (!genCocktailHeader) {
476 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
477 return kInvalidProcess;
480 TList* headerList = genCocktailHeader->GetHeaders();
482 return kInvalidProcess;
485 for (Int_t i=0; i<headerList->GetEntries(); i++) {
487 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
488 if (pythiaGenHeader) {
489 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
492 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
493 if (dpmJetGenHeader) {
494 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
497 return kInvalidProcess;
502 //____________________________________________________________________
503 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
506 // Finds the first mother among the primary particles of the particle identified by <label>,
507 // i.e. the primary that "caused" this particle
510 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
514 return stack->Particle(motherLabel);
517 //____________________________________________________________________
518 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
521 // Finds the first mother among the primary particles of the particle identified by <label>,
522 // i.e. the primary that "caused" this particle
527 Int_t nPrim = stack->GetNprimary();
529 while (label >= nPrim)
531 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
533 TParticle* particle = stack->Particle(label);
536 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
541 if (particle->GetMother(0) < 0)
543 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
547 label = particle->GetMother(0);
553 //____________________________________________________________________
554 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
557 // normalizes a 1-d histogram to its bin width
560 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
562 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
563 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
567 //____________________________________________________________________
568 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
571 // normalizes a 2-d histogram to its bin width (x width * y width)
574 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
575 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
577 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
578 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
579 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
583 //____________________________________________________________________
584 const char* AliPWG0Helper::GetTriggerName(Trigger trigger)
586 // returns the name of the requested trigger
587 // the returned string will only be valid until the next call to this function [not thread-safe]
591 UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) kStartOfFlags;
593 switch (triggerNoFlags)
595 case kAcceptAll : str = "ACCEPT ALL (bypass!)"; break;
596 case kMB1 : str = "MB1"; break;
597 case kMB2 : str = "MB2"; break;
598 case kMB3 : str = "MB3"; break;
599 case kSPDGFO : str = "SPD GFO"; break;
600 case kV0A : str = "V0 A"; break;
601 case kV0C : str = "V0 C"; break;
602 case kZDCA : str = "ZDC A"; break;
603 case kZDCC : str = "ZDC C"; break;
604 case kFMD : str = "FMD"; break;
605 default: str = ""; break;
608 if (trigger & kOfflineFlag)
614 //____________________________________________________________________
615 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
618 // Prints the given configuration
621 TString str(">>>> Running with >");
623 if (analysisMode & kSPD)
626 if (analysisMode & kTPC)
629 if (analysisMode & kTPCITS)
630 str += "Global tracking";
632 if (analysisMode & kFieldOn)
634 str += " (with field)";
637 str += " (WITHOUT field)";
639 str += "< and trigger >";
640 str += GetTriggerName(trigger);
643 Printf("%s", str.Data());