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 //____________________________________________________________________
32 ClassImp(AliPWG0Helper)
34 Int_t AliPWG0Helper::fgLastProcessType = -1;
36 //____________________________________________________________________
37 Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug)
39 // Checks if a vertex meets the needed quality criteria
41 Float_t requiredZResolution = -1;
42 if (analysisMode & kSPD || analysisMode & kTPCITS)
44 requiredZResolution = 0.1;
46 else if (analysisMode & kTPC)
47 requiredZResolution = 10.;
50 Double_t zRes = vertex->GetZRes();
52 if (zRes > requiredZResolution) {
54 Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
61 //____________________________________________________________________
62 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC)
64 // Get the vertex from the ESD and returns it if the vertex is valid
66 // Second argument decides which vertex is used (this selects
67 // also the quality criteria that are applied)
69 const AliESDVertex* vertex = 0;
70 if (analysisMode & kSPD || analysisMode & kTPCITS)
72 vertex = aEsd->GetPrimaryVertexSPD();
74 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
76 else if (analysisMode & kTPC)
80 Printf("AliPWG0Helper::GetVertex: Redoing vertex");
81 Double_t kBz = aEsd->GetMagneticField();
82 AliVertexerTracks vertexer(kBz);
83 vertexer.SetTPCMode();
84 AliESDVertex *vTPC = vertexer.FindPrimaryVertex(aEsd);
85 aEsd->SetPrimaryVertexTPC(vTPC);
86 for (Int_t i=0; i<aEsd->GetNumberOfTracks(); i++) {
87 AliESDtrack *t = aEsd->GetTrack(i);
88 t->RelateToVertexTPC(vTPC, kBz, kVeryBig);
93 vertex = aEsd->GetPrimaryVertexTPC();
95 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
98 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
102 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
106 // check Ncontributors
107 if (vertex->GetNContributors() <= 0) {
109 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
110 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
117 Double_t zRes = vertex->GetZRes();
119 Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
125 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
132 //____________________________________________________________________
133 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
136 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
137 // shall be counted as a primary particle
139 // This function or a equivalent should be available in some common place of AliRoot
141 // WARNING: Call this function only for particles that are among the particles from the event generator!
142 // --> stack->Particle(id) with id < stack->GetNprimary()
144 // if the particle has a daughter primary, we do not want to count it
145 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
148 printf("Dropping particle because it has a daughter among the primaries.\n");
152 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
155 // skip quarks and gluon
156 if (pdgCode <= 10 || pdgCode == 21)
159 printf("Dropping particle because it is a quark or gluon.\n");
163 Int_t status = aParticle->GetStatusCode();
164 // skip non final state particles..
167 printf("Dropping particle because it is not a final state particle.\n");
171 if (strcmp(aParticle->GetName(),"XXX") == 0)
173 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
177 TParticlePDG* pdgPart = aParticle->GetPDG();
179 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
181 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
185 if (pdgPart->Charge() == 0)
188 printf("Dropping particle because it is not charged.\n");
195 //____________________________________________________________________
196 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
198 // create projections of 3d hists to all 2d combinations
199 // the histograms are not returned, just use them from memory or use this to create them in a file
201 TH1* proj = hist->Project3D("yx");
202 proj->SetXTitle(hist->GetXaxis()->GetTitle());
203 proj->SetYTitle(hist->GetYaxis()->GetTitle());
207 proj = hist->Project3D("zx");
208 proj->SetXTitle(hist->GetXaxis()->GetTitle());
209 proj->SetYTitle(hist->GetZaxis()->GetTitle());
213 proj = hist->Project3D("zy");
214 proj->SetXTitle(hist->GetYaxis()->GetTitle());
215 proj->SetYTitle(hist->GetZaxis()->GetTitle());
220 //____________________________________________________________________
221 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
223 // create projections of the 3d hists divides them
224 // axis decides to which plane, if axis is 0 to all planes
225 // the histograms are not returned, just use them from memory or use this to create them in a file
229 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
230 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
231 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
236 TH1* proj = hist->Project3D(axis);
238 if (strlen(axis) == 2)
240 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
241 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
243 else if (strlen(axis) == 1)
244 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
246 TH1* proj2 = hist2->Project3D(axis);
247 if (strlen(axis) == 2)
249 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
250 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
252 else if (strlen(axis) == 1)
253 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
255 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
256 //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()));
257 //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()));
258 division->Divide(proj, proj2, 1, 1, "B");
259 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
264 if (division->GetDimension() == 1)
266 Int_t nBins = division->GetNbinsX();
267 for (Int_t i = 1; i <= nBins; ++i)
268 if (proj2->GetBinContent(i) != 0)
269 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
271 else if (division->GetDimension() == 2)
273 Int_t nBinsX = division->GetNbinsX();
274 Int_t nBinsY = division->GetNbinsY();
275 for (Int_t i = 1; i <= nBinsX; ++i)
276 for (Int_t j = 1; j <= nBinsY; ++j)
277 if (proj2->GetBinContent(i, j) != 0)
278 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
290 //____________________________________________________________________
291 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
293 // returns the title of the axis given in axis (x, y, z)
296 return hist->GetXaxis()->GetTitle();
297 else if (axis == 'y')
298 return hist->GetYaxis()->GetTitle();
299 else if (axis == 'z')
300 return hist->GetZaxis()->GetTitle();
306 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
308 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
310 if (!pythiaGenHeader) {
311 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
312 return kInvalidProcess;
316 Int_t pythiaType = pythiaGenHeader->ProcessType();
317 fgLastProcessType = pythiaType;
318 MCProcessType globalType = kInvalidProcess;
322 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
326 if(pythiaType==92||pythiaType==93){
329 else if(pythiaType==94){
332 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
340 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
342 // get the process type of the event.
345 // can only read pythia headers, either directly or from cocktalil header
346 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
348 if (!dpmJetGenHeader) {
349 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
350 return kInvalidProcess;
353 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
354 fgLastProcessType = dpmJetType;
355 MCProcessType globalType = kInvalidProcess;
359 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
363 if(dpmJetType == 1){ // this is explicitly inelastic
366 else if(dpmJetType==5||dpmJetType==6){
369 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
376 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
378 // get the process type of the event.
382 // Check for simple headers first
384 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
385 if (pythiaGenHeader) {
386 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
389 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
390 if (dpmJetGenHeader) {
391 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
395 // check for cocktail
397 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
398 if (!genCocktailHeader) {
399 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
400 return kInvalidProcess;
403 TList* headerList = genCocktailHeader->GetHeaders();
405 return kInvalidProcess;
408 for (Int_t i=0; i<headerList->GetEntries(); i++) {
410 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
411 if (pythiaGenHeader) {
412 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
415 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
416 if (dpmJetGenHeader) {
417 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
420 return kInvalidProcess;
425 //____________________________________________________________________
426 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
429 // Finds the first mother among the primary particles of the particle identified by <label>,
430 // i.e. the primary that "caused" this particle
433 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
437 return stack->Particle(motherLabel);
440 //____________________________________________________________________
441 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
444 // Finds the first mother among the primary particles of the particle identified by <label>,
445 // i.e. the primary that "caused" this particle
450 Int_t nPrim = stack->GetNprimary();
452 while (label >= nPrim)
454 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
456 TParticle* particle = stack->Particle(label);
459 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
464 if (particle->GetMother(0) < 0)
466 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
470 label = particle->GetMother(0);
476 //____________________________________________________________________
477 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
480 // normalizes a 1-d histogram to its bin width
483 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
485 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
486 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
490 //____________________________________________________________________
491 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
494 // normalizes a 2-d histogram to its bin width (x width * y width)
497 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
498 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
500 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
501 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
502 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
506 //____________________________________________________________________
507 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, AliTriggerAnalysis::Trigger trigger)
510 // Prints the given configuration
513 TString str(">>>> Running with >");
515 if (analysisMode & kSPD)
518 if (analysisMode & kTPC)
521 if (analysisMode & kTPCITS)
522 str += "Global tracking";
524 if (analysisMode & kFieldOn)
526 str += " (with field)";
529 str += " (WITHOUT field)";
531 str += "< and trigger >";
532 str += AliTriggerAnalysis::GetTriggerName(trigger);
535 Printf("%s", str.Data());