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 // disable cut on resolution
45 requiredZResolution = 1000;
47 else if (analysisMode & kTPC)
48 requiredZResolution = 10.;
51 Double_t zRes = vertex->GetZRes();
53 if (zRes > requiredZResolution) {
55 Printf("AliPWG0Helper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
59 if (vertex->IsFromVertexerZ())
61 if (vertex->GetDispersion() > 0.02)
64 Printf("AliPWG0Helper::TestVertex: Delta Phi too large in Vertexer Z: %f (required: %f", vertex->GetDispersion(), 0.02);
72 //____________________________________________________________________
73 const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug)
75 // Get the vertex from the ESD and returns it if the vertex is valid
77 // Second argument decides which vertex is used (this selects
78 // also the quality criteria that are applied)
80 const AliESDVertex* vertex = 0;
81 if (analysisMode & kSPD || analysisMode & kTPCITS)
83 vertex = aEsd->GetPrimaryVertexSPD();
85 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
87 else if (analysisMode & kTPC)
89 vertex = aEsd->GetPrimaryVertexTPC();
91 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
94 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
98 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
102 // check Ncontributors
103 if (vertex->GetNContributors() <= 0) {
105 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors());
106 Printf("AliPWG0Helper::GetVertex: NIndices(): %d",vertex->GetNIndices());
113 Double_t zRes = vertex->GetZRes();
115 Printf("AliPWG0Helper::GetVertex: UNEXPECTED: resolution is 0.");
121 Printf("AliPWG0Helper::GetVertex: Returning valid vertex: %s", vertex->GetTitle());
128 //____________________________________________________________________
129 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
132 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
133 // shall be counted as a primary particle
135 // This function or a equivalent should be available in some common place of AliRoot
137 // WARNING: Call this function only for particles that are among the particles from the event generator!
138 // --> stack->Particle(id) with id < stack->GetNprimary()
140 // if the particle has a daughter primary, we do not want to count it
141 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
144 printf("Dropping particle because it has a daughter among the primaries.\n");
148 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
151 // skip quarks and gluon
152 if (pdgCode <= 10 || pdgCode == 21)
155 printf("Dropping particle because it is a quark or gluon.\n");
159 Int_t status = aParticle->GetStatusCode();
160 // skip non final state particles..
163 printf("Dropping particle because it is not a final state particle.\n");
167 if (strcmp(aParticle->GetName(),"XXX") == 0)
169 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
173 TParticlePDG* pdgPart = aParticle->GetPDG();
175 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
177 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
181 if (pdgPart->Charge() == 0)
184 printf("Dropping particle because it is not charged.\n");
191 //____________________________________________________________________
192 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
194 // create projections of 3d hists to all 2d combinations
195 // the histograms are not returned, just use them from memory or use this to create them in a file
197 TH1* proj = hist->Project3D("yx");
198 proj->SetXTitle(hist->GetXaxis()->GetTitle());
199 proj->SetYTitle(hist->GetYaxis()->GetTitle());
203 proj = hist->Project3D("zx");
204 proj->SetXTitle(hist->GetXaxis()->GetTitle());
205 proj->SetYTitle(hist->GetZaxis()->GetTitle());
209 proj = hist->Project3D("zy");
210 proj->SetXTitle(hist->GetYaxis()->GetTitle());
211 proj->SetYTitle(hist->GetZaxis()->GetTitle());
216 //____________________________________________________________________
217 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
219 // create projections of the 3d hists divides them
220 // axis decides to which plane, if axis is 0 to all planes
221 // the histograms are not returned, just use them from memory or use this to create them in a file
225 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
226 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
227 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
232 TH1* proj = hist->Project3D(axis);
234 if (strlen(axis) == 2)
236 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
237 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
239 else if (strlen(axis) == 1)
240 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
242 TH1* proj2 = hist2->Project3D(axis);
243 if (strlen(axis) == 2)
245 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
246 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
248 else if (strlen(axis) == 1)
249 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
251 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
252 //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()));
253 //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()));
254 division->Divide(proj, proj2, 1, 1, "B");
255 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
260 if (division->GetDimension() == 1)
262 Int_t nBins = division->GetNbinsX();
263 for (Int_t i = 1; i <= nBins; ++i)
264 if (proj2->GetBinContent(i) != 0)
265 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
267 else if (division->GetDimension() == 2)
269 Int_t nBinsX = division->GetNbinsX();
270 Int_t nBinsY = division->GetNbinsY();
271 for (Int_t i = 1; i <= nBinsX; ++i)
272 for (Int_t j = 1; j <= nBinsY; ++j)
273 if (proj2->GetBinContent(i, j) != 0)
274 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
286 //____________________________________________________________________
287 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
289 // returns the title of the axis given in axis (x, y, z)
292 return hist->GetXaxis()->GetTitle();
293 else if (axis == 'y')
294 return hist->GetYaxis()->GetTitle();
295 else if (axis == 'z')
296 return hist->GetZaxis()->GetTitle();
302 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
304 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
306 if (!pythiaGenHeader) {
307 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
308 return kInvalidProcess;
312 Int_t pythiaType = pythiaGenHeader->ProcessType();
313 fgLastProcessType = pythiaType;
314 MCProcessType globalType = kInvalidProcess;
318 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
322 if(pythiaType==92||pythiaType==93){
325 else if(pythiaType==94){
328 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
336 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
338 // get the process type of the event.
341 // can only read pythia headers, either directly or from cocktalil header
342 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
344 if (!dpmJetGenHeader) {
345 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
346 return kInvalidProcess;
349 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
350 fgLastProcessType = dpmJetType;
351 MCProcessType globalType = kInvalidProcess;
355 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
359 if(dpmJetType == 1){ // this is explicitly inelastic
362 else if(dpmJetType==5||dpmJetType==6){
365 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
372 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
374 // get the process type of the event.
378 // Check for simple headers first
380 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
381 if (pythiaGenHeader) {
382 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
385 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
386 if (dpmJetGenHeader) {
387 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
391 // check for cocktail
393 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
394 if (!genCocktailHeader) {
395 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
396 return kInvalidProcess;
399 TList* headerList = genCocktailHeader->GetHeaders();
401 return kInvalidProcess;
404 for (Int_t i=0; i<headerList->GetEntries(); i++) {
406 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
407 if (pythiaGenHeader) {
408 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
411 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
412 if (dpmJetGenHeader) {
413 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
416 return kInvalidProcess;
421 //____________________________________________________________________
422 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
425 // Finds the first mother among the primary particles of the particle identified by <label>,
426 // i.e. the primary that "caused" this particle
429 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
433 return stack->Particle(motherLabel);
436 //____________________________________________________________________
437 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
440 // Finds the first mother among the primary particles of the particle identified by <label>,
441 // i.e. the primary that "caused" this particle
446 Int_t nPrim = stack->GetNprimary();
448 while (label >= nPrim)
450 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
452 TParticle* particle = stack->Particle(label);
455 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
460 if (particle->GetMother(0) < 0)
462 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
466 label = particle->GetMother(0);
472 //____________________________________________________________________
473 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
476 // normalizes a 1-d histogram to its bin width
479 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
481 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
482 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
486 //____________________________________________________________________
487 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
490 // normalizes a 2-d histogram to its bin width (x width * y width)
493 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
494 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
496 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
497 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
498 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
502 //____________________________________________________________________
503 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, AliTriggerAnalysis::Trigger trigger)
506 // Prints the given configuration
509 TString str(">>>> Running with >");
511 if (analysisMode & kSPD)
514 if (analysisMode & kSPDOnlyL0)
515 str += " (only L0 clusters)";
517 if (analysisMode & kTPC)
520 if (analysisMode & kTPCITS)
521 str += "Global tracking";
523 if (analysisMode & kFieldOn)
525 str += " (with field)";
528 str += " (WITHOUT field)";
530 str += "< and trigger >";
531 str += AliTriggerAnalysis::GetTriggerName(trigger);
534 Printf("%s", str.Data());