1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //-----------------------------------------------------------------------
17 // Efficiency between different steps of the procedure.
18 // The ouptut of the task is a AliCFContainer from which the efficiencies
20 //-----------------------------------------------------------------------
21 // Author : Marta Verweij - UU
22 //-----------------------------------------------------------------------
25 #ifndef ALIPWG4HIGHPTSPECTRA_CXX
26 #define ALIPWG4HIGHPTSPECTRA_CXX
28 #include "AliPWG4HighPtSpectra.h"
42 #include "AliAnalysisManager.h"
43 #include "AliESDInputHandler.h"
44 #include "AliESDtrack.h"
45 #include "AliESDtrackCuts.h"
46 #include "AliExternalTrackParam.h"
47 #include "AliCentrality.h"
52 #include "TParticle.h"
53 #include "AliMCEvent.h"
54 #include "AliMCEventHandler.h"
55 #include "AliCFContainer.h"
56 #include "AliGenPythiaEventHeader.h"
57 #include "AliGenCocktailEventHeader.h"
58 //#include "$ALICE_ROOT/PWG4/JetTasks/AliAnalysisHelperJetTasks.h"
61 using namespace std; //required for resolving the 'cout' symbol
63 ClassImp(AliPWG4HighPtSpectra)
65 //__________________________________________________________________________
66 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra() : AliAnalysisTask("AliPWG4HighPtSpectra", ""),
78 fTrackCutsReject(0x0),
79 fSigmaConstrainedMax(5.),
95 //___________________________________________________________________________
96 AliPWG4HighPtSpectra::AliPWG4HighPtSpectra(const Char_t* name) :
97 AliAnalysisTask(name,""),
109 fTrackCutsReject(0x0),
110 fSigmaConstrainedMax(5.),
123 // Constructor. Initialization of Inputs and Outputs
125 AliDebug(2,Form("AliPWG4HighPtSpectra Calling Constructor"));
126 // Input slot #0 works with a TChain ESD
127 DefineInput(0, TChain::Class());
128 // Output slot #0 writes into a TList
129 DefineOutput(0,TList::Class());
130 // Output slot #1, #2 writes into a AliCFContainer
131 DefineOutput(1,AliCFContainer::Class());
132 DefineOutput(2,AliCFContainer::Class());
133 // Output slot #3 writes into a AliESDtrackCuts
134 DefineOutput(3, AliESDtrackCuts::Class());
135 DefineOutput(4, AliESDtrackCuts::Class());
138 //________________________________________________________________________
139 void AliPWG4HighPtSpectra::LocalInit()
142 // Only called once at beginning
144 PostData(3,fTrackCuts);
147 //________________________________________________________________________
148 void AliPWG4HighPtSpectra::ConnectInputData(Option_t *)
152 AliDebug(2,Form(">> AliPWG4HighPtSpectra::ConnectInputData \n"));
154 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
156 AliDebug(2,Form( "ERROR: Could not read chain from input slot 0 \n"));
160 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
163 AliDebug(2,Form("ERROR: Could not get ESDInputHandler"));
166 fESD = esdH->GetEvent();
168 AliMCEventHandler *eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
170 AliDebug(2,Form( "ERROR: Could not retrieve MC event handler \n"));
173 fMC = eventHandler->MCEvent();
177 //________________________________________________________________________
178 Bool_t AliPWG4HighPtSpectra::SelectEvent() {
180 // Decide if event should be selected for analysis
183 // Checks following requirements:
185 // - trigger info from AliPhysicsSelection
186 // - number of reconstructed tracks > 1
187 // - primary vertex reconstructed
188 // - z-vertex < 10 cm
190 Bool_t selectEvent = kTRUE;
192 //fESD object available?
194 AliDebug(2,Form("ERROR: fInputEvent not available\n"));
195 fNEventReject->Fill("noESD",1);
196 selectEvent = kFALSE;
201 UInt_t isSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
202 if(!(isSelected&AliVEvent::kMB)) { //Select collison candidates
203 AliDebug(2,Form(" Trigger Selection: event REJECTED ... "));
204 fNEventReject->Fill("Trigger",1);
205 selectEvent = kFALSE;
209 //Check if number of reconstructed tracks is larger than 1
210 if(!fESD->GetNumberOfTracks() || fESD->GetNumberOfTracks()<2) {
211 fNEventReject->Fill("NTracks<2",1);
212 selectEvent = kFALSE;
216 //Check if vertex is reconstructed
217 fVtx = fESD->GetPrimaryVertexSPD();
220 fNEventReject->Fill("noVTX",1);
221 selectEvent = kFALSE;
225 if(!fVtx->GetStatus()) {
226 fNEventReject->Fill("VtxStatus",1);
227 selectEvent = kFALSE;
232 // TString vtxName(fVtx->GetName());
233 if(fVtx->GetNContributors()<2) {
234 fNEventReject->Fill("NCont<2",1);
235 selectEvent = kFALSE;
239 //Check if z-vertex < 10 cm
241 fVtx->GetXYZ(primVtx);
242 if(TMath::Sqrt(primVtx[0]*primVtx[0] + primVtx[1]*primVtx[1])>1. || TMath::Abs(primVtx[2]>10.)){
243 fNEventReject->Fill("ZVTX>10",1);
244 selectEvent = kFALSE;
248 //Centrality selection should only be done in case of PbPb
251 if(fCentClass!=CalculateCentrality(fESD) && fCentClass!=10) {
252 fNEventReject->Fill("cent",1);
253 selectEvent = kFALSE;
257 if(dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()) {
258 cent = dynamic_cast<AliESDEvent*>(fESD)->GetCentrality()->GetCentralityPercentile("V0M");
261 fNEventReject->Fill("cent>90",1);
262 selectEvent = kFALSE;
265 fh1Centrality->Fill(cent);
273 //________________________________________________________________________
274 Int_t AliPWG4HighPtSpectra::CalculateCentrality(AliESDEvent *esd){
280 if(esd->GetCentrality()){
281 cent = esd->GetCentrality()->GetCentralityPercentile("V0M");
294 //_________________________________________________
295 void AliPWG4HighPtSpectra::Exec(Option_t *)
298 // Main loop function
300 AliDebug(2,Form(">> AliPWG4HighPtSpectra::Exec \n"));
302 // All events without selection
303 fNEventAll->Fill(0.);
306 fNEventReject->Fill("NTracks<2",1);
308 PostData(0,fHistList);
309 PostData(1,fCFManagerPos->GetParticleContainer());
310 PostData(2,fCFManagerNeg->GetParticleContainer());
317 AliDebug(2,Form("MC particles: %d", fMC->GetNumberOfTracks()));
318 fStack = fMC->Stack(); //Particles Stack
319 AliDebug(2,Form("MC particles stack: %d", fStack->GetNtrack()));
322 // ---- Get MC Header information (for MC productions in pThard bins) ----
323 Double_t ptHard = 0.;
324 Double_t nTrials = 1; // trials for MC trigger weight for real data
327 AliGenPythiaEventHeader* pythiaGenHeader = GetPythiaEventHeader(fMC);
329 nTrials = pythiaGenHeader->Trials();
330 ptHard = pythiaGenHeader->GetPtHard();
332 fh1PtHard->Fill(ptHard);
333 fh1PtHardTrials->Fill(ptHard,nTrials);
335 fh1Trials->Fill("#sum{ntrials}",fAvgTrials);
339 Int_t nTracks = fESD->GetNumberOfTracks();
340 AliDebug(2,Form("nTracks %d", nTracks));
343 fNEventReject->Fill("noTrackCuts",1);
345 PostData(0,fHistList);
346 PostData(1,fCFManagerPos->GetParticleContainer());
347 PostData(2,fCFManagerNeg->GetParticleContainer());
351 // Selected events for analysis
352 fNEventSel->Fill(0.);
355 Double_t containerInputRec[3] = {0.,0.,0.};
356 Double_t containerInputMC[3] = {0.,0.,0.};
357 Double_t containerInputRecMC[3] = {0.,0.,0.}; //reconstructed yield as function of MC variable
359 //Now go to rec level
360 for (Int_t iTrack = 0; iTrack<nTracks; iTrack++)
362 //Get track for analysis
363 AliESDtrack *track = 0x0;
364 AliESDtrack *esdtrack = fESD->GetTrack(iTrack);
365 if(!esdtrack) continue;
368 track = AliESDtrackCuts::GetTPCOnlyTrack(fESD,esdtrack->GetID());
371 else if(fTrackType==2) {
372 track = AliESDtrackCuts::GetTPCOnlyTrack(fESD,esdtrack->GetID());
375 AliExternalTrackParam exParam;
376 Bool_t relate = track->RelateToVertexTPC(fVtx,fESD->GetMagneticField(),kVeryBig,&exParam);
381 track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
383 else if(fTrackType==7) {
384 //use global constrained track
386 // track->Set(esdtrack->GetConstrainedParam()->GetX(),esdtrack->GetConstrainedParam()->GetAlpha(),esdtrack->GetConstrainedParam()->GetParameter(),esdtrack->GetConstrainedParam()->GetCovariance());
394 //Cut on chi2 of constrained fit
395 if(track->GetConstrainedChi2TPC() > fSigmaConstrainedMax*fSigmaConstrainedMax) {
401 if (fTrackCuts->AcceptTrack(track)) {
404 if(fTrackCutsReject ) {
405 if(fTrackCutsReject->AcceptTrack(track) )
409 if(esdtrack->GetConstrainedParam())
410 track->Set(esdtrack->GetConstrainedParam()->GetX(),esdtrack->GetConstrainedParam()->GetAlpha(),esdtrack->GetConstrainedParam()->GetParameter(),esdtrack->GetConstrainedParam()->GetCovariance());
414 containerInputRec[0] = track->Pt();
415 containerInputRec[1] = track->Phi();
416 containerInputRec[2] = track->Eta();
418 if(track->GetSign()>0.) fCFManagerPos->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
419 if(track->GetSign()<0.) fCFManagerNeg->GetParticleContainer()->Fill(containerInputRec,kStepReconstructed);
422 //Only fill the MC containers if MC information is available
424 Int_t label = TMath::Abs(track->GetLabel());
425 TParticle *particle = fStack->Particle(label) ;
427 if(fTrackType==1 || fTrackType==2)
431 containerInputRecMC[0] = particle->Pt();
432 containerInputRecMC[1] = particle->Phi();
433 containerInputRecMC[2] = particle->Eta();
435 //Container with primaries
436 if(fStack->IsPhysicalPrimary(label)) {
437 if(particle->GetPDG()->Charge()>0.) {
438 fCFManagerPos->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
440 if(particle->GetPDG()->Charge()<0.) {
441 fCFManagerNeg->GetParticleContainer()->Fill(containerInputRecMC,kStepReconstructedMC);
445 //Container with secondaries
446 if (!fStack->IsPhysicalPrimary(label) ) {
447 if(particle->GetPDG()->Charge()>0.) {
448 fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
450 if(particle->GetPDG()->Charge()<0.) {
451 fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepSecondaries);
456 }//trackCuts global tracks
458 if(fTrackType==1 || fTrackType==2)
463 //Fill MC containters if particles are findable
465 for(int iPart = 1; iPart<(fMC->GetNumberOfPrimaries()); iPart++) {
466 AliMCParticle *mcPart = (AliMCParticle*)fMC->GetTrack(iPart);
467 if(!mcPart) continue;
469 containerInputMC[0] = mcPart->Pt();
470 containerInputMC[1] = mcPart->Phi();
471 containerInputMC[2] = mcPart->Eta();
473 if(fStack->IsPhysicalPrimary(iPart)) {
474 if(mcPart->Charge()>0. && fCFManagerPos->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerPos->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
475 if(mcPart->Charge()<0. && fCFManagerNeg->CheckParticleCuts(kStepMCAcceptance,mcPart)) fCFManagerNeg->GetParticleContainer()->Fill(containerInputMC,kStepMCAcceptance);
480 PostData(0,fHistList);
481 PostData(1,fCFManagerPos->GetParticleContainer());
482 PostData(2,fCFManagerNeg->GetParticleContainer());
485 //________________________________________________________________________
486 Bool_t AliPWG4HighPtSpectra::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
488 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
489 // This is to called in Notify and should provide the path to the AOD/ESD file
490 // Copied from AliAnalysisTaskJetSpectrum2
493 TString file(currFile);
497 if(file.Contains("root_archive.zip#")){
498 Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
499 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
500 file.Replace(pos+1,20,"");
503 // not an archive take the basename....
504 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
506 // Printf("%s",file.Data());
508 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
510 // next trial fetch the histgram file
511 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
513 // not a severe condition but inciate that we have no information
517 // find the tlist we want to be independtent of the name so use the Tkey
518 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
523 TList *list = dynamic_cast<TList*>(key->ReadObj());
528 fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
529 fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
532 } // no tree pyxsec.root
534 TTree *xtree = (TTree*)fxsec->Get("Xsection");
540 Double_t xsection = 0;
541 xtree->SetBranchAddress("xsection",&xsection);
542 xtree->SetBranchAddress("ntrials",&ntrials);
550 //________________________________________________________________________
551 Bool_t AliPWG4HighPtSpectra::Notify()
554 // Implemented Notify() to read the cross sections
555 // and number of trials from pyxsec.root
556 // Copied from AliAnalysisTaskJetSpectrum2
559 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
560 Float_t xsection = 0;
565 TFile *curfile = tree->GetCurrentFile();
567 Error("Notify","No current file");
570 if(!fh1Xsec||!fh1Trials){
571 // Printf("%s%d No Histogram fh1Xsec",(char*)__FILE__,__LINE__);
574 PythiaInfoFromFile(curfile->GetName(),xsection,ftrials);
575 fh1Xsec->Fill("<#sigma>",xsection);
576 // construct a poor man average trials
577 Float_t nEntries = (Float_t)tree->GetTree()->GetEntries();
578 if(ftrials>=nEntries && nEntries>0.)fAvgTrials = ftrials/nEntries;
583 //________________________________________________________________________
584 AliGenPythiaEventHeader* AliPWG4HighPtSpectra::GetPythiaEventHeader(AliMCEvent *mcEvent){
586 if(!mcEvent)return 0;
587 AliGenEventHeader* genHeader = mcEvent->GenEventHeader();
588 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
589 if(!pythiaGenHeader){
591 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
593 if (!genCocktailHeader) {
594 // AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Unknown header type (not Pythia or Cocktail)");
595 // AliWarning(Form("%s %d: Unknown header type (not Pythia or Cocktail)",(char*)__FILE__,__LINE__));
598 TList* headerList = genCocktailHeader->GetHeaders();
599 for (Int_t i=0; i<headerList->GetEntries(); i++) {
600 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(i));
604 if(!pythiaGenHeader){
605 AliWarningGeneral(Form(" %s:%d",(char*)__FILE__,__LINE__),"Pythia event header not found");
609 return pythiaGenHeader;
614 //___________________________________________________________________________
615 void AliPWG4HighPtSpectra::Terminate(Option_t*)
617 // The Terminate() function is the last function to be called during
618 // a query. It always runs on the client, it can be used to present
619 // the results graphically or save the results to file.
623 //___________________________________________________________________________
624 void AliPWG4HighPtSpectra::CreateOutputObjects() {
625 //HERE ONE CAN CREATE OUTPUT OBJECTS, IN PARTICULAR IF THE OBJECT PARAMETERS DON'T NEED
626 //TO BE SET BEFORE THE EXECUTION OF THE TASK
628 AliDebug(2,Form("CreateOutputObjects CreateOutputObjects of task %s", GetName()));
630 Bool_t oldStatus = TH1::AddDirectoryStatus();
631 TH1::AddDirectory(kFALSE);
635 fHistList = new TList();
636 fHistList->SetOwner(kTRUE);
637 fNEventAll = new TH1F("fNEventAll","NEventAll",1,-0.5,0.5);
638 fHistList->Add(fNEventAll);
639 fNEventSel = new TH1F("fNEventSel","NEvent Selected for analysis",1,-0.5,0.5);
640 fHistList->Add(fNEventSel);
642 fNEventReject = new TH1F("fNEventReject","Reason events are rejectected for analysis",20,0,20);
644 fNEventReject->Fill("noESD",0);
645 fNEventReject->Fill("Trigger",0);
646 fNEventReject->Fill("NTracks<2",0);
647 fNEventReject->Fill("noVTX",0);
648 fNEventReject->Fill("VtxStatus",0);
649 fNEventReject->Fill("NCont<2",0);
650 fNEventReject->Fill("ZVTX>10",0);
651 fNEventReject->Fill("cent",0);
652 fNEventReject->Fill("cent>90",0);
653 fHistList->Add(fNEventReject);
655 fh1Centrality = new TH1F("fh1Centrality","fh1Centrality; Centrality %",100,0,100);
656 fHistList->Add(fh1Centrality);
658 fh1Xsec = new TProfile("fh1Xsec","xsec from pyxsec.root",1,0,1);
659 fh1Xsec->GetXaxis()->SetBinLabel(1,"<#sigma>");
660 fHistList->Add(fh1Xsec);
662 fh1Trials = new TH1F("fh1Trials","trials root file",1,0,1);
663 fh1Trials->GetXaxis()->SetBinLabel(1,"#sum{ntrials}");
664 fHistList->Add(fh1Trials);
666 fh1PtHard = new TH1F("fh1PtHard","PYTHIA Pt hard;p_{T,hard}",350,-.5,349.5);
667 fHistList->Add(fh1PtHard);
668 fh1PtHardTrials = new TH1F("fh1PtHardTrials","PYTHIA Pt hard weight with trials;p_{T,hard}",350,-.5,349.5);
669 fHistList->Add(fh1PtHardTrials);
671 TH1::AddDirectory(oldStatus);
673 PostData(0,fHistList);
674 PostData(1,fCFManagerPos->GetParticleContainer());
675 PostData(2,fCFManagerNeg->GetParticleContainer());