/************************************************************************** * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "dNdPt/AlidNdPtEventCuts.h" #include "dNdPt/AlidNdPtAcceptanceCuts.h" #include "dNdPt/AlidNdPtHelper.h" //____________________________________________________________________ ClassImp(AlidNdPtHelper) Int_t AlidNdPtHelper::fgLastProcessType = -1; //____________________________________________________________________ Bool_t AlidNdPtHelper::IsEventTriggered(const AliESD* aEsd, Trigger trigger) { // see function with ULong64_t argument ULong64_t triggerMask = aEsd->GetTriggerMask(); return IsEventTriggered(triggerMask, trigger); } //____________________________________________________________________ Bool_t AlidNdPtHelper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger) { // check if the event was triggered // // this function needs the branch fTriggerMask // definitions from p-p.cfg ULong64_t spdFO = (1 << 14); ULong64_t v0left = (1 << 11); ULong64_t v0right = (1 << 12); switch (trigger) { case kMB1: { if (triggerMask & spdFO || ((triggerMask & v0left) || (triggerMask & v0right))) return kTRUE; break; } case kMB2: { if (triggerMask & spdFO && ((triggerMask & v0left) || (triggerMask & v0right))) return kTRUE; break; } case kSPDFASTOR: { if (triggerMask & spdFO) return kTRUE; break; } } return kFALSE; } //____________________________________________________________________ const Bool_t AlidNdPtHelper::TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug) { // Checks if a vertex meets the needed quality criteria if(!vertex) return kFALSE; Float_t requiredZResolution = -1; if (analysisMode == kSPD || analysisMode == kTPCITS || analysisMode == kTPCSPDvtx) { requiredZResolution = 0.1; } else if (analysisMode == kTPC || analysisMode == kMCRec || analysisMode == kMCPion || analysisMode == kMCKaon || analysisMode == kMCProton || analysisMode ==kPlus || analysisMode ==kMinus) requiredZResolution = 10.; // check Ncontributors if (vertex->GetNContributors() <= 0) { if (debug){ Printf("AlidNdPtHelper::GetVertex: NContributors() <= 0: %d",vertex->GetNContributors()); Printf("AlidNdPtHelper::GetVertex: NIndices(): %d",vertex->GetNIndices()); vertex->Print(); } return kFALSE; } // check resolution Double_t zRes = vertex->GetZRes(); if (zRes == 0) { Printf("AlidNdPtHelper::GetVertex: UNEXPECTED: resolution is 0."); return kFALSE; } if (zRes > requiredZResolution) { if (debug) Printf("AlidNdPtHelper::TestVertex: Resolution too poor %f (required: %f", zRes, requiredZResolution); return kFALSE; } return kTRUE; } //____________________________________________________________________ const AliESDVertex* AlidNdPtHelper::GetVertex(AliESDEvent* aEsd, AlidNdPtEventCuts *evtCuts, AlidNdPtAcceptanceCuts *accCuts, AliESDtrackCuts *trackCuts, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC, Bool_t bUseMeanVertex) { // Get the vertex from the ESD and returns it if the vertex is valid // // Second argument decides which vertex is used (this selects // also the quality criteria that are applied) if(!aEsd) { ::Error("AlidNdPtHelper::GetVertex()","esd event is NULL"); return NULL; } if(!evtCuts || !accCuts || !trackCuts) { ::Error("AlidNdPtHelper::GetVertex()","cuts not available"); return NULL; } const AliESDVertex* vertex = 0; AliESDVertex *initVertex = 0; if (analysisMode == kSPD || analysisMode == kTPCITS || analysisMode == kTPCSPDvtx || analysisMode == kMCRec || analysisMode == kMCPion || analysisMode == kMCKaon || analysisMode == kMCProton || analysisMode ==kPlus || analysisMode ==kMinus ) { vertex = aEsd->GetPrimaryVertexSPD(); if (debug) Printf("AlidNdPtHelper::GetVertex: Returning SPD vertex"); } else if (analysisMode == kTPC || analysisMode == kMCRec || analysisMode == kMCPion || analysisMode == kMCKaon || analysisMode == kMCProton || analysisMode == kPlus || analysisMode == kMinus) { if(bRedoTPC) { Double_t kBz = aEsd->GetMagneticField(); AliVertexerTracks vertexer(kBz); if(bUseMeanVertex) { Double_t pos[3]={evtCuts->GetMeanXv(),evtCuts->GetMeanYv(),evtCuts->GetMeanZv()}; Double_t err[3]={evtCuts->GetSigmaMeanXv(),evtCuts->GetSigmaMeanYv(),evtCuts->GetSigmaMeanZv()}; //printf("pos[0] %f, pos[1] %f, pos[2] %f \n", pos[0], pos[1], pos[2]); initVertex = new AliESDVertex(pos,err); vertexer.SetVtxStart(initVertex); vertexer.SetConstraintOn(); } //vertexer.SetTPCMode(Double_t dcacut=0.1, Double_t dcacutIter0=1.0, Double_t maxd0z0=5.0, Int_t minCls=10, Int_t mintrks=1, Double_t nsigma=3., Double_t mindetfitter=0.1, Double_t maxtgl=1.5, Double_t fidR=3., Double_t fidZ=30., Int_t finderAlgo=1, Int_t finderAlgoIter0=4); Double_t maxDCAr = accCuts->GetMaxDCAr(); Double_t maxDCAz = accCuts->GetMaxDCAz(); Int_t minTPCClust = trackCuts->GetMinNClusterTPC(); vertexer.SetTPCMode(0.1,1.0,5.0,minTPCClust,1,3.,0.1,2.0,maxDCAr,maxDCAz,1,4); // TPC track preselection Int_t ntracks = aEsd->GetNumberOfTracks(); TObjArray array(ntracks); UShort_t *id = new UShort_t[ntracks]; Int_t count=0; for (Int_t i=0;i GetTrack(i); if (!t) continue; if (t->Charge() == 0) continue; if (!t->GetTPCInnerParam()) continue; if (t->GetTPCNcls()GetTPCInnerParam())); if(tpcTrack) { array.AddLast(tpcTrack); id[count] = (UShort_t)t->GetID(); count++; } } AliESDVertex *vTPC = vertexer.VertexForSelectedTracks(&array,id, kTRUE, kTRUE, bUseMeanVertex); aEsd->SetPrimaryVertexTPC(vTPC); for (Int_t i=0; iGetNumberOfTracks(); i++) { AliESDtrack *t = aEsd->GetTrack(i); t->RelateToVertexTPC(vTPC, kBz, kVeryBig); } delete vTPC; array.Delete(); delete [] id; id=NULL; } vertex = aEsd->GetPrimaryVertexTPC(); if (debug) Printf("AlidNdPtHelper::GetVertex: Returning vertex from tracks"); } else Printf("AlidNdPtHelper::GetVertex: ERROR: Invalid second argument %d", analysisMode); if (!vertex) { if (debug) Printf("AlidNdPtHelper::GetVertex: No vertex found in ESD"); return 0; } if (debug) { Printf("AlidNdPtHelper::GetVertex: Returning valid vertex: %s", vertex->GetTitle()); vertex->Print(); } if(initVertex) delete initVertex; initVertex=NULL; return vertex; } //____________________________________________________________________ Bool_t AlidNdPtHelper::IsPrimaryParticle(AliStack* stack, Int_t idx, AnalysisMode analysisMode) { // check primary particles // depending on the analysis mode // if(!stack) return kFALSE; TParticle* particle = stack->Particle(idx); if (!particle) return kFALSE; // only charged particles Double_t charge = particle->GetPDG()->Charge()/3.; if (charge == 0.0) return kFALSE; Int_t pdg = TMath::Abs(particle->GetPdgCode()); // physical primary Bool_t prim = stack->IsPhysicalPrimary(idx); if(analysisMode==kMCPion) { if(prim && pdg==kPiPlus) return kTRUE; else return kFALSE; } if (analysisMode==kMCKaon) { if(prim && pdg==kKPlus) return kTRUE; else return kFALSE; } if (analysisMode==kMCProton) { if(prim && pdg==kProton) return kTRUE; else return kFALSE; } return prim; } //____________________________________________________________________ Bool_t AlidNdPtHelper::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug) { // // this function checks if a particle from the event generator (i.e. among the nPrim particles in the stack) // shall be counted as a primary particle // // This function or a equivalent should be available in some common place of AliRoot // // WARNING: Call this function only for particles that are among the particles from the event generator! // --> stack->Particle(id) with id < stack->GetNprimary() // if the particle has a daughter primary, we do not want to count it if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries) { if (adebug) printf("Dropping particle because it has a daughter among the primaries.\n"); return kFALSE; } Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode()); // skip quarks and gluon if (pdgCode <= 10 || pdgCode == 21) { if (adebug) printf("Dropping particle because it is a quark or gluon.\n"); return kFALSE; } Int_t status = aParticle->GetStatusCode(); // skip non final state particles.. if(status!=1){ if (adebug) printf("Dropping particle because it is not a final state particle.\n"); return kFALSE; } if (strcmp(aParticle->GetName(),"XXX") == 0) { Printf("WARNING: There is a particle named XXX (pdg code %d).", pdgCode); return kFALSE; } TParticlePDG* pdgPart = aParticle->GetPDG(); if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0) { Printf("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode); return kFALSE; } if (pdgPart->Charge() == 0) { if (adebug) printf("Dropping particle because it is not charged.\n"); return kFALSE; } return kTRUE; } //____________________________________________________________________ void AlidNdPtHelper::CreateProjections(TH3* hist, Bool_t save) { // create projections of 3d hists to all 2d combinations // the histograms are not returned, just use them from memory or use this to create them in a file TH1* proj = hist->Project3D("yx"); proj->SetXTitle(hist->GetXaxis()->GetTitle()); proj->SetYTitle(hist->GetYaxis()->GetTitle()); if (save) proj->Write(); proj = hist->Project3D("zx"); proj->SetXTitle(hist->GetXaxis()->GetTitle()); proj->SetYTitle(hist->GetZaxis()->GetTitle()); if (save) proj->Write(); proj = hist->Project3D("zy"); proj->SetXTitle(hist->GetYaxis()->GetTitle()); proj->SetYTitle(hist->GetZaxis()->GetTitle()); if (save) proj->Write(); } //____________________________________________________________________ void AlidNdPtHelper::CreateDividedProjections(TH3* hist, TH3* hist2, const char* axis, Bool_t putErrors, Bool_t save) { // create projections of the 3d hists divides them // axis decides to which plane, if axis is 0 to all planes // the histograms are not returned, just use them from memory or use this to create them in a file if (axis == 0) { CreateDividedProjections(hist, hist2, "yx", putErrors, save); CreateDividedProjections(hist, hist2, "zx", putErrors, save); CreateDividedProjections(hist, hist2, "zy", putErrors, save); return; } TH1* proj = hist->Project3D(axis); if (strlen(axis) == 2) { proj->SetYTitle(GetAxisTitle(hist, axis[0])); proj->SetXTitle(GetAxisTitle(hist, axis[1])); } else if (strlen(axis) == 1) proj->SetXTitle(GetAxisTitle(hist, axis[0])); TH1* proj2 = hist2->Project3D(axis); if (strlen(axis) == 2) { proj2->SetYTitle(GetAxisTitle(hist2, axis[0])); proj2->SetXTitle(GetAxisTitle(hist2, axis[1])); } else if (strlen(axis) == 1) proj2->SetXTitle(GetAxisTitle(hist2, axis[0])); TH1* division = dynamic_cast (proj->Clone(Form("%s_div_%s", proj->GetName(), proj2->GetName()))); //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())); //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())); division->Divide(proj, proj2, 1, 1, "B"); division->SetTitle(Form("%s divided %s", proj->GetTitle(), proj2->GetTitle())); if (putErrors) { division->Sumw2(); if (division->GetDimension() == 1) { Int_t nBins = division->GetNbinsX(); for (Int_t i = 1; i <= nBins; ++i) if (proj2->GetBinContent(i) != 0) division->SetBinError(i, TMath::Sqrt(proj->GetBinContent(i)) / proj2->GetBinContent(i)); } else if (division->GetDimension() == 2) { Int_t nBinsX = division->GetNbinsX(); Int_t nBinsY = division->GetNbinsY(); for (Int_t i = 1; i <= nBinsX; ++i) for (Int_t j = 1; j <= nBinsY; ++j) if (proj2->GetBinContent(i, j) != 0) division->SetBinError(i, j, TMath::Sqrt(proj->GetBinContent(i, j)) / proj2->GetBinContent(i, j)); } } if (save) { proj->Write(); proj2->Write(); division->Write(); } } //____________________________________________________________________ const char* AlidNdPtHelper::GetAxisTitle(TH3* hist, const char axis) { // returns the title of the axis given in axis (x, y, z) if (axis == 'x') return hist->GetXaxis()->GetTitle(); else if (axis == 'y') return hist->GetYaxis()->GetTitle(); else if (axis == 'z') return hist->GetZaxis()->GetTitle(); return 0; } AlidNdPtHelper::MCProcessType AlidNdPtHelper::GetPythiaEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) { AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast(aHeader); if (!pythiaGenHeader) { printf("AlidNdPtHelper::GetProcessType : Unknown gen Header type). \n"); return kInvalidProcess; } Int_t pythiaType = pythiaGenHeader->ProcessType(); fgLastProcessType = pythiaType; MCProcessType globalType = kInvalidProcess; if (adebug) { printf("AlidNdPtHelper::GetProcessType : Pythia process type found: %d \n",pythiaType); } if(pythiaType==92||pythiaType==93){ globalType = kSD; } else if(pythiaType==94){ globalType = kDD; } //else if(pythiaType != 91){ // also exclude elastic to be sure... CKB?? else { globalType = kND; } return globalType; } AlidNdPtHelper::MCProcessType AlidNdPtHelper::GetDPMjetEventProcessType(AliGenEventHeader* aHeader, Bool_t adebug) { // // get the process type of the event. // // can only read pythia headers, either directly or from cocktalil header AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast(aHeader); if (!dpmJetGenHeader) { printf("AlidNdPtHelper::GetDPMjetProcessType : Unknown header type (not DPMjet or). \n"); return kInvalidProcess; } Int_t dpmJetType = dpmJetGenHeader->ProcessType(); fgLastProcessType = dpmJetType; MCProcessType globalType = kInvalidProcess; if (adebug) { printf("AlidNdPtHelper::GetDPMJetProcessType : DPMJet process type found: %d \n",dpmJetType); } if(dpmJetType == 1){ // this is explicitly inelastic globalType = kND; } else if(dpmJetType==5||dpmJetType==6){ globalType = kSD; } else if(dpmJetType==7||dpmJetType==4){// DD and double pomeron globalType = kDD; } return globalType; } AlidNdPtHelper::MCProcessType AlidNdPtHelper::GetEventProcessType(AliHeader* aHeader, Bool_t adebug) { // // get the process type of the event. // // Check for simple headers first AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast(aHeader->GenEventHeader()); if (pythiaGenHeader) { return GetPythiaEventProcessType(pythiaGenHeader,adebug); } AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast(aHeader->GenEventHeader()); if (dpmJetGenHeader) { return GetDPMjetEventProcessType(dpmJetGenHeader,adebug); } // check for cocktail AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast(aHeader->GenEventHeader()); if (!genCocktailHeader) { printf("AlidNdPtHelper::GetProcessType : Unknown header type (not Pythia or Cocktail). \n"); return kInvalidProcess; } TList* headerList = genCocktailHeader->GetHeaders(); if (!headerList) { return kInvalidProcess; } for (Int_t i=0; iGetEntries(); i++) { pythiaGenHeader = dynamic_cast(headerList->At(i)); if (pythiaGenHeader) { return GetPythiaEventProcessType(pythiaGenHeader,adebug); } dpmJetGenHeader = dynamic_cast(headerList->At(i)); if (dpmJetGenHeader) { return GetDPMjetEventProcessType(dpmJetGenHeader,adebug); } } return kInvalidProcess; } //____________________________________________________________________ TParticle* AlidNdPtHelper::FindPrimaryMother(AliStack* stack, Int_t label) { // // Finds the first mother among the primary particles of the particle identified by