3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
21 #include <AliESDEvent.h>
22 #include <AliESDVertex.h>
23 #include <AliVertexerTracks.h>
25 #include <AliGenEventHeader.h>
26 #include <AliGenPythiaEventHeader.h>
27 #include <AliGenCocktailEventHeader.h>
28 #include <AliGenDPMjetEventHeader.h>
30 //____________________________________________________________________
31 ClassImp(AliPWG0Helper)
33 Int_t AliPWG0Helper::fgLastProcessType = -1;
35 //____________________________________________________________________
36 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
38 // see function with ULong64_t argument
40 ULong64_t triggerMask = aEsd->GetTriggerMask();
41 return IsEventTriggered(triggerMask, trigger);
44 //____________________________________________________________________
45 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
47 // check if the event was triggered
49 // this function needs the branch fTriggerMask
51 // definitions from p-p.cfg
52 ULong64_t spdFO = (1 << 14);
53 ULong64_t v0left = (1 << 11);
54 ULong64_t v0right = (1 << 12);
60 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
66 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
72 if (triggerMask & spdFO)
81 //____________________________________________________________________
82 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug,Bool_t bRedoTPC)
84 // Get the vertex from the ESD and returns it if the vertex is valid
86 // Second argument decides which vertex is used (this selects
87 // also the quality criteria that are applied)
89 const AliESDVertex* vertex = 0;
90 Float_t requiredZResolution = -1;
91 if (analysisMode == kSPD || analysisMode == kTPCITS)
93 vertex = aEsd->GetPrimaryVertexSPD();
94 requiredZResolution = 0.1;
96 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
98 else if (analysisMode == kTPC)
101 Double_t kBz = aEsd->GetMagneticField();
102 AliVertexerTracks vertexer(kBz);
103 vertexer.SetTPCMode();
104 AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
105 aEsd->SetPrimaryVertexTPC(vTPC);
106 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
107 AliESDtrack *t = aEsd->GetTrack(i);
108 t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
113 vertex = aEsd->GetPrimaryVertexTPC();
114 requiredZResolution = 10.;
116 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
119 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
123 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
127 // check Ncontributors
128 if (vertex->GetNContributors() <= 0) {
130 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
131 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
138 Double_t zRes = vertex->GetZRes();
140 if (zRes == 0 || zRes > requiredZResolution) {
142 Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
148 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
155 //____________________________________________________________________
156 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
159 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
160 // shall be counted as a primary particle
162 // This function or a equivalent should be available in some common place of AliRoot
164 // WARNING: Call this function only for particles that are among the particles from the event generator!
165 // --> stack->Particle(id) with id < stack->GetNprimary()
167 // if the particle has a daughter primary, we do not want to count it
168 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
171 printf("Dropping particle because it has a daughter among the primaries.\n");
175 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
178 // skip quarks and gluon
179 if (pdgCode <= 10 || pdgCode == 21)
182 printf("Dropping particle because it is a quark or gluon.\n");
186 Int_t status = aParticle->GetStatusCode();
187 // skip non final state particles..
190 printf("Dropping particle because it is not a final state particle.\n");
194 if (strcmp(aParticle->GetName(),"XXX") == 0)
196 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
200 TParticlePDG* pdgPart = aParticle->GetPDG();
202 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
204 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
208 if (pdgPart->Charge() == 0)
211 printf("Dropping particle because it is not charged.\n");
218 //____________________________________________________________________
219 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
221 // create projections of 3d hists to all 2d combinations
222 // the histograms are not returned, just use them from memory or use this to create them in a file
224 TH1* proj = hist->Project3D("yx");
225 proj->SetXTitle(hist->GetXaxis()->GetTitle());
226 proj->SetYTitle(hist->GetYaxis()->GetTitle());
230 proj = hist->Project3D("zx");
231 proj->SetXTitle(hist->GetXaxis()->GetTitle());
232 proj->SetYTitle(hist->GetZaxis()->GetTitle());
236 proj = hist->Project3D("zy");
237 proj->SetXTitle(hist->GetYaxis()->GetTitle());
238 proj->SetYTitle(hist->GetZaxis()->GetTitle());
243 //____________________________________________________________________
244 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
246 // create projections of the 3d hists divides them
247 // axis decides to which plane, if axis is 0 to all planes
248 // the histograms are not returned, just use them from memory or use this to create them in a file
252 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
253 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
254 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
259 TH1* proj = hist->Project3D(axis);
261 if (strlen(axis) == 2)
263 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
264 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
266 else if (strlen(axis) == 1)
267 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
269 TH1* proj2 = hist2->Project3D(axis);
270 if (strlen(axis) == 2)
272 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
273 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
275 else if (strlen(axis) == 1)
276 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
278 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
279 //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()));
280 //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()));
281 division->Divide(proj, proj2, 1, 1, "B");
282 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
287 if (division->GetDimension() == 1)
289 Int_t nBins = division->GetNbinsX();
290 for (Int_t i = 1; i <= nBins; ++i)
291 if (proj2->GetBinContent(i) != 0)
292 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
294 else if (division->GetDimension() == 2)
296 Int_t nBinsX = division->GetNbinsX();
297 Int_t nBinsY = division->GetNbinsY();
298 for (Int_t i = 1; i <= nBinsX; ++i)
299 for (Int_t j = 1; j <= nBinsY; ++j)
300 if (proj2->GetBinContent(i, j) != 0)
301 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
313 //____________________________________________________________________
314 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
316 // returns the title of the axis given in axis (x, y, z)
319 return hist->GetXaxis()->GetTitle();
320 else if (axis == 'y')
321 return hist->GetYaxis()->GetTitle();
322 else if (axis == 'z')
323 return hist->GetZaxis()->GetTitle();
329 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
331 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
333 if (!pythiaGenHeader) {
334 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
335 return kInvalidProcess;
339 Int_t pythiaType = pythiaGenHeader->ProcessType();
340 fgLastProcessType = pythiaType;
341 MCProcessType globalType = kInvalidProcess;
345 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
349 if(pythiaType==92||pythiaType==93){
352 else if(pythiaType==94){
355 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
363 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
365 // get the process type of the event.
368 // can only read pythia headers, either directly or from cocktalil header
369 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
371 if (!dpmJetGenHeader) {
372 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
373 return kInvalidProcess;
376 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
377 fgLastProcessType = dpmJetType;
378 MCProcessType globalType = kInvalidProcess;
382 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
386 if(dpmJetType == 1){ // this is explicitly inelastic
389 else if(dpmJetType==5||dpmJetType==6){
392 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
399 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
401 // get the process type of the event.
405 // Check for simple headers first
407 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
408 if (pythiaGenHeader) {
409 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
412 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
413 if (dpmJetGenHeader) {
414 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
418 // check for cocktail
420 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
421 if (!genCocktailHeader) {
422 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
423 return kInvalidProcess;
426 TList* headerList = genCocktailHeader->GetHeaders();
428 return kInvalidProcess;
431 for (Int_t i=0; i<headerList->GetEntries(); i++) {
433 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
434 if (pythiaGenHeader) {
435 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
438 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
439 if (dpmJetGenHeader) {
440 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
443 return kInvalidProcess;
448 //____________________________________________________________________
449 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
452 // Finds the first mother among the primary particles of the particle identified by <label>,
453 // i.e. the primary that "caused" this particle
456 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
460 return stack->Particle(motherLabel);
463 //____________________________________________________________________
464 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
467 // Finds the first mother among the primary particles of the particle identified by <label>,
468 // i.e. the primary that "caused" this particle
473 Int_t nPrim = stack->GetNprimary();
475 while (label >= nPrim)
477 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
479 TParticle* particle = stack->Particle(label);
482 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
487 if (particle->GetMother(0) < 0)
489 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
493 label = particle->GetMother(0);
499 //____________________________________________________________________
500 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
503 // normalizes a 1-d histogram to its bin width
506 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
508 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
509 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
513 //____________________________________________________________________
514 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
517 // normalizes a 2-d histogram to its bin width (x width * y width)
520 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
521 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
523 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
524 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
525 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
529 //____________________________________________________________________
530 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
533 // Prints the given configuration
536 TString str(">>>> Running with ");
538 switch (analysisMode)
540 case kInvalid: str += "invalid setting"; break;
541 case kSPD : str += "SPD-only"; break;
542 case kTPC : str += "TPC-only"; break;
543 case kTPCITS : str += "Global tracking"; break;
546 str += " and trigger ";
550 case kMB1 : str += "MB1"; break;
551 case kMB2 : str += "MB2"; break;
552 case kSPDFASTOR : str += "SPD FASTOR"; break;
557 Printf("%s", str.Data());