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);
127 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
133 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
139 if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
145 if (triggerMask & spdFO)
150 Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
157 //____________________________________________________________________
158 Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug)
160 // Checks if a vertex meets the needed quality criteria
162 Float_t requiredZResolution = -1;
163 if (analysisMode == kSPD || analysisMode == kTPCITS)
165 requiredZResolution = 0.1;
167 else if (analysisMode == kTPC)
168 requiredZResolution = 10.;
171 Double_t zRes = vertex->GetZRes();
173 if (zRes > requiredZResolution) {
175 Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
182 //____________________________________________________________________
183 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC)
185 // Get the vertex from the ESD and returns it if the vertex is valid
187 // Second argument decides which vertex is used (this selects
188 // also the quality criteria that are applied)
190 const AliESDVertex* vertex = 0;
191 if (analysisMode == kSPD || analysisMode == kTPCITS)
193 vertex = aEsd->GetPrimaryVertexSPD();
195 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
197 else if (analysisMode == kTPC)
201 Printf("AliPWG0Helper::GetVertex: Redoing vertex");
202 Double_t kBz = aEsd->GetMagneticField();
203 AliVertexerTracks vertexer(kBz);
204 vertexer.SetTPCMode();
205 AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
206 aEsd->SetPrimaryVertexTPC(vTPC);
207 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
208 AliESDtrack *t = aEsd->GetTrack(i);
209 t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
214 vertex = aEsd->GetPrimaryVertexTPC();
216 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
219 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
223 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
227 // check Ncontributors
228 if (vertex->GetNContributors() <= 0) {
230 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
231 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
238 Double_t zRes = vertex->GetZRes();
240 Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
246 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
253 //____________________________________________________________________
254 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
257 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
258 // shall be counted as a primary particle
260 // This function or a equivalent should be available in some common place of AliRoot
262 // WARNING: Call this function only for particles that are among the particles from the event generator!
263 // --> stack->Particle(id) with id < stack->GetNprimary()
265 // if the particle has a daughter primary, we do not want to count it
266 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
269 printf("Dropping particle because it has a daughter among the primaries.\n");
273 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
276 // skip quarks and gluon
277 if (pdgCode <= 10 || pdgCode == 21)
280 printf("Dropping particle because it is a quark or gluon.\n");
284 Int_t status = aParticle->GetStatusCode();
285 // skip non final state particles..
288 printf("Dropping particle because it is not a final state particle.\n");
292 if (strcmp(aParticle->GetName(),"XXX") == 0)
294 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
298 TParticlePDG* pdgPart = aParticle->GetPDG();
300 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
302 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
306 if (pdgPart->Charge() == 0)
309 printf("Dropping particle because it is not charged.\n");
316 //____________________________________________________________________
317 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
319 // create projections of 3d hists to all 2d combinations
320 // the histograms are not returned, just use them from memory or use this to create them in a file
322 TH1* proj = hist->Project3D("yx");
323 proj->SetXTitle(hist->GetXaxis()->GetTitle());
324 proj->SetYTitle(hist->GetYaxis()->GetTitle());
328 proj = hist->Project3D("zx");
329 proj->SetXTitle(hist->GetXaxis()->GetTitle());
330 proj->SetYTitle(hist->GetZaxis()->GetTitle());
334 proj = hist->Project3D("zy");
335 proj->SetXTitle(hist->GetYaxis()->GetTitle());
336 proj->SetYTitle(hist->GetZaxis()->GetTitle());
341 //____________________________________________________________________
342 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
344 // create projections of the 3d hists divides them
345 // axis decides to which plane, if axis is 0 to all planes
346 // the histograms are not returned, just use them from memory or use this to create them in a file
350 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
351 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
352 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
357 TH1* proj = hist->Project3D(axis);
359 if (strlen(axis) == 2)
361 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
362 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
364 else if (strlen(axis) == 1)
365 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
367 TH1* proj2 = hist2->Project3D(axis);
368 if (strlen(axis) == 2)
370 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
371 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
373 else if (strlen(axis) == 1)
374 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
376 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
377 //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()));
378 //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()));
379 division->Divide(proj, proj2, 1, 1, "B");
380 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
385 if (division->GetDimension() == 1)
387 Int_t nBins = division->GetNbinsX();
388 for (Int_t i = 1; i <= nBins; ++i)
389 if (proj2->GetBinContent(i) != 0)
390 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
392 else if (division->GetDimension() == 2)
394 Int_t nBinsX = division->GetNbinsX();
395 Int_t nBinsY = division->GetNbinsY();
396 for (Int_t i = 1; i <= nBinsX; ++i)
397 for (Int_t j = 1; j <= nBinsY; ++j)
398 if (proj2->GetBinContent(i, j) != 0)
399 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
411 //____________________________________________________________________
412 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
414 // returns the title of the axis given in axis (x, y, z)
417 return hist->GetXaxis()->GetTitle();
418 else if (axis == 'y')
419 return hist->GetYaxis()->GetTitle();
420 else if (axis == 'z')
421 return hist->GetZaxis()->GetTitle();
427 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
429 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
431 if (!pythiaGenHeader) {
432 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
433 return kInvalidProcess;
437 Int_t pythiaType = pythiaGenHeader->ProcessType();
438 fgLastProcessType = pythiaType;
439 MCProcessType globalType = kInvalidProcess;
443 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
447 if(pythiaType==92||pythiaType==93){
450 else if(pythiaType==94){
453 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
461 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
463 // get the process type of the event.
466 // can only read pythia headers, either directly or from cocktalil header
467 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
469 if (!dpmJetGenHeader) {
470 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
471 return kInvalidProcess;
474 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
475 fgLastProcessType = dpmJetType;
476 MCProcessType globalType = kInvalidProcess;
480 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
484 if(dpmJetType == 1){ // this is explicitly inelastic
487 else if(dpmJetType==5||dpmJetType==6){
490 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
497 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
499 // get the process type of the event.
503 // Check for simple headers first
505 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
506 if (pythiaGenHeader) {
507 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
510 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
511 if (dpmJetGenHeader) {
512 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
516 // check for cocktail
518 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
519 if (!genCocktailHeader) {
520 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
521 return kInvalidProcess;
524 TList* headerList = genCocktailHeader->GetHeaders();
526 return kInvalidProcess;
529 for (Int_t i=0; i<headerList->GetEntries(); i++) {
531 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
532 if (pythiaGenHeader) {
533 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
536 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
537 if (dpmJetGenHeader) {
538 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
541 return kInvalidProcess;
546 //____________________________________________________________________
547 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
550 // Finds the first mother among the primary particles of the particle identified by <label>,
551 // i.e. the primary that "caused" this particle
554 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
558 return stack->Particle(motherLabel);
561 //____________________________________________________________________
562 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
565 // Finds the first mother among the primary particles of the particle identified by <label>,
566 // i.e. the primary that "caused" this particle
571 Int_t nPrim = stack->GetNprimary();
573 while (label >= nPrim)
575 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
577 TParticle* particle = stack->Particle(label);
580 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
585 if (particle->GetMother(0) < 0)
587 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
591 label = particle->GetMother(0);
597 //____________________________________________________________________
598 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
601 // normalizes a 1-d histogram to its bin width
604 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
606 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
607 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
611 //____________________________________________________________________
612 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
615 // normalizes a 2-d histogram to its bin width (x width * y width)
618 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
619 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
621 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
622 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
623 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
627 //____________________________________________________________________
628 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
631 // Prints the given configuration
634 TString str(">>>> Running with ");
636 switch (analysisMode)
638 case kInvalid: str += "invalid setting"; break;
639 case kSPD : str += "SPD-only"; break;
640 case kTPC : str += "TPC-only"; break;
641 case kTPCITS : str += "Global tracking"; break;
644 str += " and trigger ";
648 case kMB1 : str += "MB1"; break;
649 case kMB2 : str += "MB2"; break;
650 case kMB3 : str += "MB3"; break;
651 case kSPDFASTOR : str += "SPD FASTOR"; break;
652 case kOfflineMB1 : str += "Offline MB1"; break;
653 case kOfflineMB2 : str += "Offline MB2"; break;
654 case kOfflineMB3 : str += "Offline MB3"; break;
655 case kOfflineFASTOR : str += "Offline SPD FASTOR"; break;
660 Printf("%s", str.Data());