3 #include <AliPWG0Helper.h>
6 #include <TParticlePDG.h>
15 #include <AliHeader.h>
21 #include <AliESDEvent.h>
22 #include <AliESDVertex.h>
24 #include <AliGenEventHeader.h>
25 #include <AliGenPythiaEventHeader.h>
26 #include <AliGenCocktailEventHeader.h>
27 #include <AliGenDPMjetEventHeader.h>
29 //____________________________________________________________________
30 ClassImp(AliPWG0Helper)
32 Int_t AliPWG0Helper::fgLastProcessType = -1;
34 //____________________________________________________________________
35 Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
37 // see function with ULong64_t argument
39 ULong64_t triggerMask = aEsd->GetTriggerMask();
40 return IsEventTriggered(triggerMask, trigger);
43 //____________________________________________________________________
44 Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
46 // check if the event was triggered
48 // this function needs the branch fTriggerMask
50 // definitions from p-p.cfg
51 ULong64_t spdFO = (1 << 14);
52 ULong64_t v0left = (1 << 11);
53 ULong64_t v0right = (1 << 12);
59 if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right)))
65 if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right)))
71 if (triggerMask & spdFO)
80 //____________________________________________________________________
81 const AliESDVertex* AliPWG0Helper::GetVertex(const AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug)
83 // Get the vertex from the ESD and returns it if the vertex is valid
85 // Second argument decides which vertex is used (this selects
86 // also the quality criteria that are applied)
88 const AliESDVertex* vertex = 0;
89 Float_t requiredZResolution = -1;
90 if (analysisMode == kSPD || analysisMode == kTPCITS)
92 vertex = aEsd->GetPrimaryVertexSPD();
93 requiredZResolution = 0.1;
95 Printf("AliPWG0Helper::GetVertex: Returning SPD vertex");
97 else if (analysisMode == kTPC)
99 vertex = aEsd->GetPrimaryVertexTPC();
100 requiredZResolution = 0.6;
102 Printf("AliPWG0Helper::GetVertex: Returning vertex from tracks");
105 Printf("AliPWG0Helper::GetVertex: ERROR: Invalid second argument %d", analysisMode);
109 Printf("AliPWG0Helper::GetVertex: No vertex found in ESD");
113 // check Ncontributors
114 if (vertex->GetNContributors() <= 0) {
116 Printf("AliPWG0Helper::GetVertex: NContributors() <= 0");
121 Double_t zRes = vertex->GetZRes();
123 if (zRes == 0 || zRes > requiredZResolution) {
125 Printf("AliPWG0Helper::GetVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution);
130 Printf("AliPWG0Helper::GetVertex: Returning valid vertex");
135 //____________________________________________________________________
136 Bool_t AliPWG0Helper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug)
139 // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack)
140 // shall be counted as a primary particle
142 // This function or a equivalent should be available in some common place of AliRoot
144 // WARNING: Call this function only for particles that are among the particles from the event generator!
145 // --> stack->Particle(id) with id < stack->GetNprimary()
147 // if the particle has a daughter primary, we do not want to count it
148 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
151 printf("Dropping particle because it has a daughter among the primaries.\n");
155 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
157 // skip quarks and gluon
158 if (pdgCode <= 10 || pdgCode == 21)
161 printf("Dropping particle because it is a quark or gluon.\n");
165 if (strcmp(aParticle->GetName(),"XXX") == 0)
167 Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode);
171 TParticlePDG* pdgPart = aParticle->GetPDG();
173 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
175 Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode);
179 if (pdgPart->Charge() == 0)
182 printf("Dropping particle because it is not charged.\n");
189 //____________________________________________________________________
190 void AliPWG0Helper::CreateProjections(TH3* hist, Bool_t save)
192 // create projections of 3d hists to all 2d combinations
193 // the histograms are not returned, just use them from memory or use this to create them in a file
195 TH1* proj = hist->Project3D("yx");
196 proj->SetXTitle(hist->GetXaxis()->GetTitle());
197 proj->SetYTitle(hist->GetYaxis()->GetTitle());
201 proj = hist->Project3D("zx");
202 proj->SetXTitle(hist->GetXaxis()->GetTitle());
203 proj->SetYTitle(hist->GetZaxis()->GetTitle());
207 proj = hist->Project3D("zy");
208 proj->SetXTitle(hist->GetYaxis()->GetTitle());
209 proj->SetYTitle(hist->GetZaxis()->GetTitle());
214 //____________________________________________________________________
215 void AliPWG0Helper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save)
217 // create projections of the 3d hists divides them
218 // axis decides to which plane, if axis is 0 to all planes
219 // the histograms are not returned, just use them from memory or use this to create them in a file
223 CreateDividedProjections(hist, hist2, "yx", putErrors, save);
224 CreateDividedProjections(hist, hist2, "zx", putErrors, save);
225 CreateDividedProjections(hist, hist2, "zy", putErrors, save);
230 TH1* proj = hist->Project3D(axis);
232 if (strlen(axis) == 2)
234 proj->SetYTitle(GetAxisTitle(hist, axis[0]));
235 proj->SetXTitle(GetAxisTitle(hist, axis[1]));
237 else if (strlen(axis) == 1)
238 proj->SetXTitle(GetAxisTitle(hist, axis[0]));
240 TH1* proj2 = hist2->Project3D(axis);
241 if (strlen(axis) == 2)
243 proj2->SetYTitle(GetAxisTitle(hist2, axis[0]));
244 proj2->SetXTitle(GetAxisTitle(hist2, axis[1]));
246 else if (strlen(axis) == 1)
247 proj2->SetXTitle(GetAxisTitle(hist2, axis[0]));
249 TH1* division = dynamic_cast<TH1*> (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName())));
250 //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()));
251 //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()));
252 division->Divide(proj, proj2, 1, 1, "B");
253 division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle()));
258 if (division->GetDimension() == 1)
260 Int_t nBins = division->GetNbinsX();
261 for (Int_t i = 1; i <= nBins; ++i)
262 if (proj2->GetBinContent(i) != 0)
263 division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i));
265 else if (division->GetDimension() == 2)
267 Int_t nBinsX = division->GetNbinsX();
268 Int_t nBinsY = division->GetNbinsY();
269 for (Int_t i = 1; i <= nBinsX; ++i)
270 for (Int_t j = 1; j <= nBinsY; ++j)
271 if (proj2->GetBinContent(i, j) != 0)
272 division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j));
284 //____________________________________________________________________
285 const char* AliPWG0Helper::GetAxisTitle(TH3* hist, const char axis)
287 // returns the title of the axis given in axis (x, y, z)
290 return hist->GetXaxis()->GetTitle();
291 else if (axis == 'y')
292 return hist->GetYaxis()->GetTitle();
293 else if (axis == 'z')
294 return hist->GetZaxis()->GetTitle();
300 AliPWG0Helper::MCProcessType AliPWG0Helper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
302 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader);
304 if (!pythiaGenHeader) {
305 printf("AliPWG0Helper::GetProcessType : Unknown gen Header type). \n");
306 return kInvalidProcess;
310 Int_t pythiaType = pythiaGenHeader->ProcessType();
311 fgLastProcessType = pythiaType;
312 MCProcessType globalType = kInvalidProcess;
316 printf("AliPWG0Helper::GetProcessType : Pythia process type found: %d \n",pythiaType);
320 if(pythiaType==92||pythiaType==93){
323 else if(pythiaType==94){
326 //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB??
334 AliPWG0Helper::MCProcessType AliPWG0Helper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) {
336 // get the process type of the event.
339 // can only read pythia headers, either directly or from cocktalil header
340 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader);
342 if (!dpmJetGenHeader) {
343 printf("AliPWG0Helper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n");
344 return kInvalidProcess;
347 Int_t dpmJetType = dpmJetGenHeader->ProcessType();
348 fgLastProcessType = dpmJetType;
349 MCProcessType globalType = kInvalidProcess;
353 printf("AliPWG0Helper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType);
357 if(dpmJetType == 1){ // this is explicitly inelastic
360 else if(dpmJetType==5||dpmJetType==6){
363 else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron
370 AliPWG0Helper::MCProcessType AliPWG0Helper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) {
372 // get the process type of the event.
376 // Check for simple headers first
378 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(aHeader->GenEventHeader());
379 if (pythiaGenHeader) {
380 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
383 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(aHeader->GenEventHeader());
384 if (dpmJetGenHeader) {
385 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
389 // check for cocktail
391 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(aHeader->GenEventHeader());
392 if (!genCocktailHeader) {
393 printf("AliPWG0Helper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n");
394 return kInvalidProcess;
397 TList* headerList = genCocktailHeader->GetHeaders();
399 return kInvalidProcess;
402 for (Int_t i=0; i<headerList->GetEntries(); i++) {
404 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
405 if (pythiaGenHeader) {
406 return GetPythiaEventProcessType(pythiaGenHeader,adebug);
409 dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(headerList->At(i));
410 if (dpmJetGenHeader) {
411 return GetDPMjetEventProcessType(dpmJetGenHeader,adebug);
414 return kInvalidProcess;
419 //____________________________________________________________________
420 TParticle* AliPWG0Helper::FindPrimaryMother(AliStack* stack, Int_t label)
423 // Finds the first mother among the primary particles of the particle identified by <label>,
424 // i.e. the primary that "caused" this particle
427 Int_t motherLabel = FindPrimaryMotherLabel(stack, label);
431 return stack->Particle(motherLabel);
434 //____________________________________________________________________
435 Int_t AliPWG0Helper::FindPrimaryMotherLabel(AliStack* stack, Int_t label)
438 // Finds the first mother among the primary particles of the particle identified by <label>,
439 // i.e. the primary that "caused" this particle
444 Int_t nPrim = stack->GetNprimary();
446 while (label >= nPrim)
448 //printf("Particle %d (pdg %d) is not a primary. Let's check its mother %d\n", label, mother->GetPdgCode(), mother->GetMother(0));
450 TParticle* particle = stack->Particle(label);
453 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack.", label));
458 if (particle->GetMother(0) < 0)
460 AliDebugGeneral("FindPrimaryMother", AliLog::kError, Form("UNEXPECTED: Could not find mother of secondary particle %d.", label));
464 label = particle->GetMother(0);
470 //____________________________________________________________________
471 void AliPWG0Helper::NormalizeToBinWidth(TH1* hist)
474 // normalizes a 1-d histogram to its bin width
477 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
479 hist->SetBinContent(i, hist->GetBinContent(i) / hist->GetBinWidth(i));
480 hist->SetBinError(i, hist->GetBinError(i) / hist->GetBinWidth(i));
484 //____________________________________________________________________
485 void AliPWG0Helper::NormalizeToBinWidth(TH2* hist)
488 // normalizes a 2-d histogram to its bin width (x width * y width)
491 for (Int_t i=1; i<=hist->GetNbinsX(); ++i)
492 for (Int_t j=1; j<=hist->GetNbinsY(); ++j)
494 Double_t factor = hist->GetXaxis()->GetBinWidth(i) * hist->GetYaxis()->GetBinWidth(j);
495 hist->SetBinContent(i, j, hist->GetBinContent(i, j) / factor);
496 hist->SetBinError(i, j, hist->GetBinError(i, j) / factor);
500 //____________________________________________________________________
501 void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
504 // Prints the given configuration
507 TString str(">>>> Running with ");
509 switch (analysisMode)
511 case kInvalid: str += "invalid setting"; break;
512 case kSPD : str += "SPD-only"; break;
513 case kTPC : str += "TPC-only"; break;
514 case kTPCITS : str += "Global tracking"; break;
517 str += " and trigger ";
521 case kMB1 : str += "MB1"; break;
522 case kMB2 : str += "MB2"; break;
523 case kSPDFASTOR : str += "SPD FASTOR"; break;
528 Printf("%s", str.Data());