3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
21 #include <AliESDEvent.h>
22 #include <AliESDVertex.h>
23 #include <AliVertexerTracks.h>
24 #include <AliMultiplicity.h>
26 #include <AliGenEventHeader.h>
27 #include <AliGenPythiaEventHeader.h>
28 #include <AliGenCocktailEventHeader.h>
29 #include <AliGenDPMjetEventHeader.h>
30 #include <AliESDVZERO.h>
32 //____________________________________________________________________
33 ClassImp(AliPWG0Helper)
35 Int_t AliPWG0Helper::fgLastProcessType = -1;
37 //____________________________________________________________________
38 Bool_t AliPWG0Helper::IsEventTriggered(const AliESDEvent* aEsd, Trigger trigger)
40 // checks if an event has been triggered
41 // this function implements the "offline" methods that use the ESD, other trigger requests are passed to the function prototype with ULong_t
47 // offline triggers have to be dealt with here, because we need the esd pointer
48 if (trigger == kOfflineFASTOR || trigger == kOfflineMB1 || trigger == kOfflineMB2 || trigger == kOfflineMB3)
50 const AliMultiplicity* mult = aEsd->GetMultiplicity();
53 Printf("AliPWG0Helper::IsEventTriggered: ERROR: AliMultiplicity not available");
56 firedChips = mult->GetNumberOfFiredChips(0) + mult->GetNumberOfFiredChips(1);
58 if (trigger == kOfflineMB1 || trigger == kOfflineMB2 || trigger == kOfflineMB3)
60 AliESDVZERO* v0Data = aEsd->GetVZEROData();
63 Printf("AliPWG0Helper::IsEventTriggered: ERROR: AliESDVZERO not available");
66 for (Int_t i=0; i<32; i++)
68 if (v0Data->BBTriggerV0A(i))
70 if (v0Data->BBTriggerV0C(i))
85 if ((firedChips > 0) || v0A || v0C)
91 if ((firedChips > 0) && (v0A || v0C))
97 if ((firedChips > 0) && v0A && v0C)
103 return IsEventTriggered(aEsd->GetTriggerMask(), trigger);
111 //____________________________________________________________________
112 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
114 // check if the event was triggered
116 // this function needs the branch fTriggerMask
118 // definitions from p-p.cfg
119 ULong64_t spdFO = (1 << 14);
120 ULong64_t v0left = (1 << 10);
121 ULong64_t v0right = (1 << 11);
132 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
138 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
144 if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
150 if (triggerMask & spdFO)
155 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
162 //____________________________________________________________________
163 Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug)
165 // Checks if a vertex meets the needed quality criteria
167 Float_t requiredZResolution = -1;
168 if (analysisMode & kSPD || analysisMode & kTPCITS)
170 requiredZResolution = 0.1;
172 else if (analysisMode & kTPC)
173 requiredZResolution = 10.;
176 Double_t zRes = vertex->GetZRes();
178 if (zRes > requiredZResolution) {
180 Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
187 //____________________________________________________________________
188 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC)
190 // Get the vertex from the ESD and returns it if the vertex is valid
192 // Second argument decides which vertex is used (this selects
193 // also the quality criteria that are applied)
195 const AliESDVertex* vertex = 0;
196 if (analysisMode & kSPD || analysisMode & kTPCITS)
198 vertex = aEsd->GetPrimaryVertexSPD();
200 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
202 else if (analysisMode & kTPC)
206 Printf("AliPWG0Helper::GetVertex: Redoing vertex");
207 Double_t kBz = aEsd->GetMagneticField();
208 AliVertexerTracks vertexer(kBz);
209 vertexer.SetTPCMode();
210 AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
211 aEsd->SetPrimaryVertexTPC(vTPC);
212 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
213 AliESDtrack *t = aEsd->GetTrack(i);
214 t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
219 vertex = aEsd->GetPrimaryVertexTPC();
221 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
224 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
228 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
232 // check Ncontributors
233 if (vertex->GetNContributors() <= 0) {
235 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
236 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
243 Double_t zRes = vertex->GetZRes();
245 Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
251 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
258 //____________________________________________________________________
259 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
262 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
263 // shall be counted as a primary particle
265 // This function or a equivalent should be available in some common place of AliRoot
267 // WARNING: Call this function only for particles that are among the particles from the event generator!
268 // --> stack->Particle(id) with id < stack->GetNprimary()
270 // if the particle has a daughter primary, we do not want to count it
271 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
274 printf("Dropping particle because it has a daughter among the primaries.\n");
278 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
281 // skip quarks and gluon
282 if (pdgCode <= 10 || pdgCode == 21)
285 printf("Dropping particle because it is a quark or gluon.\n");
289 Int_t status = aParticle->GetStatusCode();
290 // skip non final state particles..
293 printf("Dropping particle because it is not a final state particle.\n");
297 if (strcmp(aParticle->GetName(),"XXX") == 0)
299 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
303 TParticlePDG* pdgPart = aParticle->GetPDG();
305 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
307 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
311 if (pdgPart->Charge() == 0)
314 printf("Dropping particle because it is not charged.\n");
321 //____________________________________________________________________
322 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
324 // create projections of 3d hists to all 2d combinations
325 // the histograms are not returned, just use them from memory or use this to create them in a file
327 TH1* proj = hist->Project3D("yx");
328 proj->SetXTitle(hist->GetXaxis()->GetTitle());
329 proj->SetYTitle(hist->GetYaxis()->GetTitle());
333 proj = hist->Project3D("zx");
334 proj->SetXTitle(hist->GetXaxis()->GetTitle());
335 proj->SetYTitle(hist->GetZaxis()->GetTitle());
339 proj = hist->Project3D("zy");
340 proj->SetXTitle(hist->GetYaxis()->GetTitle());
341 proj->SetYTitle(hist->GetZaxis()->GetTitle());
346 //____________________________________________________________________
347 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
349 // create projections of the 3d hists divides them
350 // axis decides to which plane, if axis is 0 to all planes
351 // the histograms are not returned, just use them from memory or use this to create them in a file
355 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
356 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
357 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
362 TH1* proj = hist->Project3D(axis);
364 if (strlen(axis) == 2)
366 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
367 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
369 else if (strlen(axis) == 1)
370 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
372 TH1* proj2 = hist2->Project3D(axis);
373 if (strlen(axis) == 2)
375 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
376 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
378 else if (strlen(axis) == 1)
379 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
381 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
382 //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()));
383 //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()));
384 division->Divide(proj, proj2, 1, 1, "B");
385 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
390 if (division->GetDimension() == 1)
392 Int_t nBins = division->GetNbinsX();
393 for (Int_t i = 1; i <= nBins; ++i)
394 if (proj2->GetBinContent(i) != 0)
395 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
397 else if (division->GetDimension() == 2)
399 Int_t nBinsX = division->GetNbinsX();
400 Int_t nBinsY = division->GetNbinsY();
401 for (Int_t i = 1; i <= nBinsX; ++i)
402 for (Int_t j = 1; j <= nBinsY; ++j)
403 if (proj2->GetBinContent(i, j) != 0)
404 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
416 //____________________________________________________________________
417 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
419 // returns the title of the axis given in axis (x, y, z)
422 return hist->GetXaxis()->GetTitle();
423 else if (axis == 'y')
424 return hist->GetYaxis()->GetTitle();
425 else if (axis == 'z')
426 return hist->GetZaxis()->GetTitle();
432 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
434 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
436 if (!pythiaGenHeader) {
437 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
438 return kInvalidProcess;
442 Int_t pythiaType = pythiaGenHeader->ProcessType();
443 fgLastProcessType = pythiaType;
444 MCProcessType globalType = kInvalidProcess;
448 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
452 if(pythiaType==92||pythiaType==93){
455 else if(pythiaType==94){
458 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
466 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
468 // get the process type of the event.
471 // can only read pythia headers, either directly or from cocktalil header
472 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
474 if (!dpmJetGenHeader) {
475 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
476 return kInvalidProcess;
479 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
480 fgLastProcessType = dpmJetType;
481 MCProcessType globalType = kInvalidProcess;
485 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
489 if(dpmJetType == 1){ // this is explicitly inelastic
492 else if(dpmJetType==5||dpmJetType==6){
495 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
502 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
504 // get the process type of the event.
508 // Check for simple headers first
510 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
511 if (pythiaGenHeader) {
512 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
515 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
516 if (dpmJetGenHeader) {
517 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
521 // check for cocktail
523 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
524 if (!genCocktailHeader) {
525 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
526 return kInvalidProcess;
529 TList* headerList = genCocktailHeader->GetHeaders();
531 return kInvalidProcess;
534 for (Int_t i=0; i<headerList->GetEntries(); i++) {
536 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
537 if (pythiaGenHeader) {
538 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
541 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
542 if (dpmJetGenHeader) {
543 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
546 return kInvalidProcess;
551 //____________________________________________________________________
552 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
555 // Finds the first mother among the primary particles of the particle identified by <label>,
556 // i.e. the primary that "caused" this particle
559 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
563 return stack->Particle(motherLabel);
566 //____________________________________________________________________
567 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
570 // Finds the first mother among the primary particles of the particle identified by <label>,
571 // i.e. the primary that "caused" this particle
576 Int_t nPrim = stack->GetNprimary();
578 while (label >= nPrim)
580 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
582 TParticle* particle = stack->Particle(label);
585 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
590 if (particle->GetMother(0) < 0)
592 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
596 label = particle->GetMother(0);
602 //____________________________________________________________________
603 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
606 // normalizes a 1-d histogram to its bin width
609 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
611 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
612 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
616 //____________________________________________________________________
617 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
620 // normalizes a 2-d histogram to its bin width (x width * y width)
623 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
624 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
626 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
627 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
628 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
632 //____________________________________________________________________
633 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
636 // Prints the given configuration
639 TString str(">>>> Running with >");
641 if (analysisMode & kSPD)
644 if (analysisMode & kTPC)
647 if (analysisMode & kTPCITS)
648 str += "Global tracking";
650 if (analysisMode & kFieldOn)
652 str += " (with field)";
655 str += " (WITHOUT field)";
657 str += "< and trigger >";
661 case kAcceptAll : str += "ACCEPT ALL (bypass!)"; break;
662 case kMB1 : str += "MB1"; break;
663 case kMB2 : str += "MB2"; break;
664 case kMB3 : str += "MB3"; break;
665 case kSPDFASTOR : str += "SPD FASTOR"; break;
666 case kOfflineMB1 : str += "Offline MB1"; break;
667 case kOfflineMB2 : str += "Offline MB2"; break;
668 case kOfflineMB3 : str += "Offline MB3"; break;
669 case kOfflineFASTOR : str += "Offline SPD FASTOR"; break;
674 Printf("%s", str.Data());