//------------------------------------------------------
void DefineCutsTagger(AliHFJetsTaggingVertex *tg){
   
    // define cuts for tagger:
    // 1) AliRDHFJetsCuts: event selections, basic jet cuts (pT jet, accpetance, emcal, pT leading-track)
    // 2) AliRDHFJetsCutsVertex: cuts to reconstruct vertices
    // (nprong, pT jet, eta, R, pTmin tracks, electron ID, displacement and other cut variables)
    AliRDHFJetsCutsVertex *cuts2=new AliRDHFJetsCutsVertex("jetCuts");
    // jets
    cuts2->SetJetRadius(0.4);
    cuts2->SetMaxEtaJet(0.5);//0.9-R
    cuts2->SetMinPtJet(10);
    cuts2->SetMaxPtJet(200);
    // tracks
    AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
    esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
    esdTrackCuts->SetMinNClustersTPC(70);
    esdTrackCuts->SetMaxChi2PerClusterTPC(4);
    esdTrackCuts->SetRequireTPCRefit(kTRUE);
    esdTrackCuts->SetRequireITSRefit(kTRUE);
    //esdTrackCuts->SetMinNClustersITS(4);
    esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
    esdTrackCuts->SetMinDCAToVertexXY(0.);
    esdTrackCuts->SetEtaRange(-0.8,0.8);
    esdTrackCuts->SetPtRange(0.3,1.e10);
  
    cuts2->AddTrackCuts(esdTrackCuts);
    
    // vertexing
    cuts2->SetNprongs(3);
    cuts2->SetIsElec(kFALSE); // kTRUE to select e in jet vertex  

    cuts2->SetMinPtHardestTrack(1.0);//default 0.3
    cuts2->SetSecVtxWithKF(kFALSE);//default with StrLinMinDist
    cuts2->SetImpParCut(0.);//default 0
    cuts2->SetDistPrimSec(0.);//default 0
    cuts2->SetCospCut(-1);//default -1
    tg->SetCuts(cuts2);

    delete esdTrackCuts;
    delete cuts2;
}
AliAnalysisTaskJetExtractorHF* AddTaskJetExtractorHF(
  const char *trackArray         = "tracks",
  const char *jetArray           = "jets",
  const char *rhoObject          = "Rho",
  Double_t    jetRadius          = 0.3,
  Double_t    minJetEta          = 0.6,
  Double_t    minJetPt           = 0.15,
  Double_t    minTrackPt         = 0.15,
  Double_t    minJetAreaPerc     = 0.557,
  const char *suffix             = ""
)
{  
  cout << " ############ MACRO EXECUTION STARTED: AddTaskJetExtractorHF.C ############\n";
  //==============================================================================
  // Prepare analysis manager, containers, etc.
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();

  if (!mgr)
  {
    ::Error("AddTaskJetExtractorHF", "No analysis manager to connect to.");
    return NULL;
  }  
  if (!mgr->GetInputEventHandler())
  {
    ::Error("AddTaskJetExtractorHF", "This task requires an input event handler");
    return NULL;
  }
  
  TString name("AliAnalysisTaskJetExtractorHF");
  if (strcmp(jetArray,"")) {
    name += "_";
    name += jetArray;
  }
  if (strcmp(rhoObject,"")) {
    name += "_";
    name += rhoObject;
  }
  if (strcmp(suffix,"")) {
    name += "_";
    name += suffix;
  }

  AliAnalysisDataContainer* contHistos = mgr->CreateContainer(Form("%s_histos", name.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, Form("%s:ChargedJetsHadronCF", AliAnalysisManager::GetCommonFileName()));

  //==============================================================================
  // Adding and configuring tasks

  AliAnalysisTaskJetExtractorHF* jetTask = new AliAnalysisTaskJetExtractorHF(name);
  jetTask->SetNeedEmcalGeom(kFALSE);
  jetTask->SetVzRange(-10.,10.);

  AliRDHFJetsCutsVertex* cuts = new AliRDHFJetsCutsVertex("jetCuts");

  // vertexing
  AliESDtrackCuts* esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts", "default");
  esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
  esdTrackCuts->SetMinNClustersTPC(90);
  esdTrackCuts->SetMaxChi2PerClusterTPC(4);
  esdTrackCuts->SetRequireTPCRefit(kTRUE);
  esdTrackCuts->SetRequireITSRefit(kTRUE);
  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
  esdTrackCuts->SetMinDCAToVertexXY(0.);
  esdTrackCuts->SetEtaRange(-0.8, 0.8);
  esdTrackCuts->SetPtRange(1.0, 1.e10);

  cuts->AddTrackCuts(esdTrackCuts);
  cuts->SetNprongs(3);
  cuts->SetMinPtHardestTrack(1.0);//default 0.3
  cuts->SetSecVtxWithKF(kFALSE);//default with StrLinMinDist
  cuts->SetImpParCut(0.);//default 0
  cuts->SetDistPrimSec(0.);//default 0
  cuts->SetCospCut(-1);//default -1

  jetTask->SetVertexerCuts(cuts);

  AliParticleContainer *trackCont = 0;
  if(!strcmp(trackArray,"mctracks") || !strcmp(trackArray, "mcparticles"))
    trackCont = jetTask->AddMCParticleContainer(trackArray);
  else
    trackCont = jetTask->AddTrackContainer(trackArray);

  trackCont->SetParticlePtCut(minTrackPt);

  AliJetContainer *jetCont = jetTask->AddJetContainer(jetArray,6,jetRadius);
  if (jetCont) {
    jetCont->SetRhoName(rhoObject);
    jetCont->SetPercAreaCut(minJetAreaPerc);
    jetCont->SetJetPtCut(minJetPt);
    jetCont->SetLeadingHadronType(0);
    jetCont->SetPtBiasJetTrack(minTrackPt);
    jetCont->SetJetEtaLimits(-minJetEta, +minJetEta);
    jetCont->ConnectParticleContainer(trackCont);
    jetCont->SetMaxTrackPt(1000);
  }

  mgr->AddTask(jetTask);

  //==============================================================================
  // Finalization

  mgr->ConnectInput  (jetTask, 0,  mgr->GetCommonInputContainer() );
  mgr->ConnectOutput (jetTask, 1, contHistos );
 
  cout << " ############ MACRO EXECUTION DONE: AddTaskJetExtractorHF.C ############\n";
 
  return jetTask;
}
Exemple #3
0
AliAnalysisTaskEmcalHFCJQA* AddTaskEmcalHFCJQA(
  const char *ntracks            = "Tracks",
  const char *nclusters          = "CaloClusters",
  const char *njets              = "Jets",
  const char *nrho               = "Rho",
  Int_t       nCentBins          = 1,
  Double_t    jetradius          = 0.4,
  Double_t    jetptcut           = 0,
  Double_t    jetareacut         = 0.6,
  const char *type               = "TPC",
  Int_t       leadhadtype        = 0,
  const char *taskname           = "AliAnalysisTaskEmcalHFCJQA",
  TString cutfile				 ="HFCJCuts.root",
  UInt_t triggerMask			 =-1,//AliVEvent::kEMC1 | AliVEvent::kEMC7 | AliVEvent::kEMC8,/*kMB kEMC7 (kEMC8) kEMCEJE kEMCEGA*/
  Bool_t isMC					 = kFALSE,
  Float_t minC					 = 0.,
  Float_t maxC					 = 7.5
)
{  
  // Get the pointer to the existing analysis manager via the static access method.
  //==============================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr)
  {
    ::Error("AddTaskEmcalHFCJQA", "No analysis manager to connect to.");
    return NULL;
  }  
  
  // Check the analysis type using the event handlers connected to the analysis manager.
  //==============================================================================
  if (!mgr->GetInputEventHandler())
  {
    ::Error("AddTaskEmcalHFCJQA", "This task requires an input event handler");
    return NULL;
  }
  
  //-------------------------------------------------------
  // Init the task and do settings
  //-------------------------------------------------------

  TString name(taskname);
  if (strcmp(njets,"")) {
    name += "_";
    name += njets;
  }
  if (strcmp(nrho,"")) {
    name += "_";
    name += nrho;
  }
  if (strcmp(type,"")) {
    name += "_";
    name += type;
  }

  Printf("name: %s",name.Data());

  AliAnalysisTaskEmcalHFCJQA* jetTask = new AliAnalysisTaskEmcalHFCJQA(name);
  jetTask->SetReadMC(isMC);
  jetTask->SetDebug(-1);
  jetTask->SetFilterBit(AliAODTrack::kTrkGlobalNoDCA);
  //Defaut parameters
  
  AliParticleContainer *trackCont  = jetTask->AddParticleContainer(ntracks);
  trackCont->SetClassName("AliVTrack");
  AliClusterContainer *clusterCont = jetTask->AddClusterContainer(nclusters);

  TString strType(type);
  AliJetContainer *jetCont = jetTask->AddJetContainer(njets,strType,jetradius);
  if(jetCont) {
    jetCont->SetRhoName(nrho);
    jetCont->ConnectParticleContainer(trackCont);
    jetCont->ConnectClusterContainer(clusterCont);
    jetCont->SetZLeadingCut(0.98,0.98);
    jetCont->SetPercAreaCut(0.6);
    jetCont->SetJetPtCut(jetptcut);    
    jetCont->SetLeadingHadronType(leadhadtype);
  }

//=========================CUTS=========================
AliRDHFJetsCuts *cuts;

bool kFileExists=kFALSE;
//if(!gSystem->AccessPathName(cutfile.Data(),kFileExists)){
  
if(gSystem->AccessPathName(cutfile.Data(),kFileExists))
{
	Printf("\n==CutObject not Defined in .root File. Using Standard Cuts==\n");

// possible (!not standard!) selection for pp2012 data triggered with EMCAL
    cuts=new AliRDHFJetsCuts();
    hfTask = new AliAnalysisTaskEmcalHFCJQA("AliAnalysisTaskEmcalHFCJQA");
   
    // AliRDHFJetsCutsVertex *cuts2=new AliRDHFJetsCutsVertex("jetCuts");

    //cuts for jets
    //    cuts->SetJetRadius(0.4);
    //    cuts->SetMaxEtaJet(0.5);//0.9-R
    //    cuts->SetMinPtJet(0);
    //    cuts->SetMaxPtJet(200);
    //    cuts->ResetMaskAndEnableMBTrigger();
    //cuts->SetUseAnyTrigger();
    //cuts->SetTriggerMask(0);
    cuts->SetTriggerMask(AliVEvent::kEMC1 | AliVEvent::kEMC7 | AliVEvent::kEMC8);
    cuts->SetTriggerClass("");

    AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
    esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
    esdTrackCuts->SetMinNClustersTPC(70);
    esdTrackCuts->SetMaxChi2PerClusterTPC(4);
    esdTrackCuts->SetRequireTPCRefit(kTRUE);
    esdTrackCuts->SetRequireITSRefit(kTRUE);
    esdTrackCuts->SetMinNClustersITS(2);
    esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
    esdTrackCuts->SetMinDCAToVertexXY(0.);
    esdTrackCuts->SetEtaRange(-0.8,0.8);
    esdTrackCuts->SetPtRange(1,1.e10);

    if(minC>0&&minC<maxC)
    {
      // Pb-Pb
      cuts->SetTriggerClass("");
      cuts->ResetMaskAndEnableMBTrigger();
      cuts->EnableCentralTrigger();
      cuts->EnableSemiCentralTrigger();
      cuts->SetUseCentrality(AliRDHFCuts::kCentV0M);
      cuts->SetMinCentrality(minC);
      cuts->SetMaxCentrality(maxC);  
    }

    cuts->AddTrackCuts(esdTrackCuts);
    //cuts for vertexing
    //    ::Error("AddTaskSEHFJets","No Cut Object");
}
else
{
	TFile *f=TFile::Open(cutfile.Data());
	//cuts= (AliRDHFCutsD0toKpi*)f->Get("EventTrackCuts");
	cuts= (AliRDHFJetsCuts*)f->Get("HFCJCuts");

	cout<<"\n==========================================\n Cutfile used:\n"<<cutfile.Data()<<endl;
	//cuts->PrintAll();
	//jetTask->SetJetCuts(cuts);
}
if(triggerMask>0) cuts->SetTriggerMask(triggerMask);

jetTask->SetJetCuts(cuts);
delete cuts;
//========================================================== 
  
//-------------------------------------------------------
// Final settings, pass to manager and set the containers
//-------------------------------------------------------
  
  mgr->AddTask(jetTask);

  // Create containers for input/output
  AliAnalysisDataContainer *cinput1  = mgr->GetCommonInputContainer()  ;
  TString contname(name);
  contname += "_histos";
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(contname.Data(), 
							    TList::Class(),AliAnalysisManager::kOutputContainer,
							    Form("%s", AliAnalysisManager::GetCommonFileName()));
  mgr->ConnectInput  (jetTask, 0,  cinput1 );
  mgr->ConnectOutput (jetTask, 1, coutput1 );
  
  return jetTask;
}
//
// *** Configuration script for K*+-->K0Short-Pi analysis ***
// 
// A configuration script for RSN package needs to define the followings:
//
// (1) decay tree of each resonance to be studied, which is needed to select
//     true pairs and to assign the right mass to all candidate daughters
// (2) cuts at all levels: single daughters, tracks, events
// (3) output objects: histograms or trees
//
Bool_t ConfigKStarPlusMinus
(  
   AliRsnMiniAnalysisTask *task,
   Int_t		   collSyst, 
   Bool_t                  isMC,
   Float_t                 piPIDCut,
   Float_t                 pPIDCut,
   Int_t                   aodFilterBit,
   Float_t                 trackDCAcut,
   Float_t                 massTol,
   Float_t                 lambdaDCA,
   Float_t                 lambdaCosPoinAn,
   Float_t                 lambdaDaughDCA,
   Int_t                   NTPCcluster,
   const char             *suffix,
   AliRsnCutSet           *cutsPair
)
{
   // manage suffix
   if (strlen(suffix) > 0) suffix = Form("_%s", suffix);
 
   /////////////////////////////////////////////////////
   // selections for the pion from the decay of KStarPlusMinus*
   /////////////////////////////////////////////////////
   //
   AliRsnCutDaughterSigmaStar2010PP *cutPi = new AliRsnCutDaughterSigmaStar2010PP("cutPionForKStarPlusMinus", AliPID::kPion);
   cutPi->SetPIDCut(piPIDCut);    // fPIDCut used in IsSelected() after the call to cutQuality
   AliRsnCutTrackQuality *cutQuality = (AliRsnCutTrackQuality*) cutPi->CutQuality();
   //cutQuality->SetDefaults2011();
   cutQuality->SetDefaults2010(0,1);  // 1st par. not default (0 -> use TPC clusters). 2nd par. default (-> standard Pt and eta range)
   // SetDefaults2010 contains the following selections:
   //     SetPtRange(0.15, 1E+20);
   //     SetEtaRange(-0.8, 0.8);
   //     and from aliroot/master/src/ANALYSIS/ANALYSISalice/AliESDtrackCuts.cxx
   //     AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(1,0)
   //         esdTrackCuts->SetMinNClustersTPC(70);
   //         esdTrackCuts->SetMaxChi2PerClusterTPC(4);
   //         esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
   //         esdTrackCuts->SetRequireTPCRefit(kTRUE);
   //         esdTrackCuts->SetRequireITSRefit(kTRUE);
   //         esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
   //         esdTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");    // NB. With pt_min=0.15 (see above) -> DCAxy_max = 0.2560
   //         esdTrackCuts->SetMaxChi2TPCConstrainedGlobal(36);
   //         esdTrackCuts->SetMaxDCAToVertexZ(2);
   //         esdTrackCuts->SetDCAToVertex2D(kFALSE);
   //         esdTrackCuts->SetRequireSigmaToVertex(kFALSE);  
   //         esdTrackCuts->SetMaxChi2PerClusterITS(36);
   //  
   AliRsnCutSet *cutSetPi = new AliRsnCutSet("setPionForKStarPlusMinus", AliRsnTarget::kDaughter);
   cutSetPi->AddCut(cutPi);
   cutSetPi->SetCutScheme(cutPi->GetName());
   Int_t iCutPi = task->AddTrackCuts(cutSetPi);
   //
   /////////////////////////////////////////////////////////////
   // selections for Lambda and for the daughters of Lambda 
   /////////////////////////////////////////////////////////////
   // 
   // selections for the proton and pion daugthers of Lambda and AntiLambda
   AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("qualityDaughterLambda");   
   esdTrackCuts->SetPtRange(0.15,1.E10);
   esdTrackCuts->SetEtaRange(-0.8,0.8);
   esdTrackCuts->SetRequireTPCRefit();
   esdTrackCuts->SetAcceptKinkDaughters(0); //
   esdTrackCuts->SetMinNClustersTPC(NTPCcluster);
   esdTrackCuts->SetMaxChi2PerClusterTPC(4);
   esdTrackCuts->SetMinDCAToVertexXY(0.15);   
   //
   /////////////////////////////////////////////////
   // selections for Lambda
   AliRsnCutV0 *cutLambda = new AliRsnCutV0("cutLambda", kK0Short, AliPID::kPion, AliPID::kPion);
   cutLambda->SetPIDCutProton(pPIDCut);       // PID for the proton daughter of Lambda
   cutLambda->SetPIDCutPion(piPIDCut);        // PID for the pion daughter of Lambda 
   cutLambda->SetESDtrackCuts(esdTrackCuts);  // all the other selections (defined above) for proton and pion daughters of Lambda
   cutLambda->SetMaxDaughtersDCA(lambdaDaughDCA);
   cutLambda->SetMaxDCAVertex(lambdaDCA);
   cutLambda->SetMinCosPointingAngle(lambdaCosPoinAn);
   cutLambda->SetTolerance(massTol);
   cutLambda->SetMaxRapidity(0.5);
   //
   AliRsnCutSet *cutSetLambda = new AliRsnCutSet("setLambda", AliRsnTarget::kDaughter);
   cutSetLambda->AddCut(cutLambda);
   cutSetLambda->SetCutScheme(cutLambda->GetName());
   Int_t iCutLambda = task->AddTrackCuts(cutSetLambda);
   //
   
   
   //######################################################################################################  
    
   //
   // -- Values ------------------------------------------------------------------------------------
   //
   
   /* invariant mass   */ Int_t imID   = task->CreateValue(AliRsnMiniValue::kInvMass, kFALSE);
   /* transv. momentum */ Int_t ptID   = task->CreateValue(AliRsnMiniValue::kPt, kFALSE);
   /* centrality       */ Int_t centID = task->CreateValue(AliRsnMiniValue::kMult, kFALSE);
   
   //
   // -- Create all needed outputs -----------------------------------------------------------------
   //
   
   // use an array for more compact writing, which are different on mixing and charges
   // [0] = unlike
   // [1] = mixing
   // [2] = like ++
   // [3] = like --
   Bool_t   use     [6] = {1               ,1                ,1                  ,1                   ,1                ,1                 };
   Bool_t   useIM   [6] = {1               ,1                ,1                  ,1                   ,1                ,1                 };
   TString  name    [6] = {"KStarPlusMinus","AKStarPlusMinus","KStarPlusMinusmix","AKStarPlusMinusmix","KStarPlusMinust","AKStarPlusMinust"};
   TString  comp    [6] = {"PAIR"          ,"PAIR"           ,"MIX"              ,"MIX"               ,"TRUE"           ,"TRUE"            };
   TString  output  [6] = {"HIST"          ,"HIST"           ,"HIST"             ,"HIST"              ,"HIST"           ,"HIST"            };
   Char_t   charge1 [6] = {'0'             ,'0'              ,'0'                ,'0'                 ,'0'              ,'0'               };
   Char_t   charge2 [6] = {'+'             ,'-'              ,'+'                ,'-'                 ,'+'              ,'-'               };
   Int_t    cutID1  [6] = { iCutLambda     ,iCutLambda   ,iCutLambda         ,iCutLambda      ,iCutLambda       ,iCutLambda    };
   Int_t    cutID2  [6] = { iCutPi         ,iCutPi           ,iCutPi             ,iCutPi              ,iCutPi           ,iCutPi            };
   Int_t    ipdg    [6] = {323             ,-323             ,323                ,-323                ,323              ,-323              };
   Double_t mass    [6] = { 0.89166        ,0.89166          ,0.89166            ,0.89166             ,0.89166          ,0.89166           };
   
   for (Int_t i = 0; i < 6; i++) {
      if (!use[i]) continue;
      if (collSyst) output[i] = "SPARSE";
      // create output
      AliRsnMiniOutput *out = task->CreateOutput(Form("sigmastar_%s%s", name[i].Data(), suffix), output[i].Data(), comp[i].Data());
      // selection settings
      out->SetCutID(0, cutID1[i]);
      out->SetCutID(1, cutID2[i]);
      out->SetDaughter(0, AliRsnDaughter::kKaon0);
      out->SetDaughter(1, AliRsnDaughter::kPion);
      out->SetCharge(0, charge1[i]);
      out->SetCharge(1, charge2[i]);
      out->SetMotherPDG(ipdg[i]);
      out->SetMotherMass(mass[i]);
      // pair cuts
      out->SetPairCuts(cutsPair);
      // axis X: invmass
      if (useIM[i]) 
             out->AddAxis(imID, 2000, 0, 2.0);
      //  out->AddAxis(imID, 700, 1.2, 4.0);
      // axis Y: transverse momentum
	  out->AddAxis(ptID, 100, 0.0, 10.0);
	 //out->AddAxis(lambdaDCA, 10, 0.0, 1.0);
	 
      if (collSyst) out->AddAxis(centID, 10, 0.0, 100.0);
      
    } 
    
   AddMonitorOutput_PionPt(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionEta(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionDCAxy(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionDCAz(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionPIDCut(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionNTPC(cutSetPi->GetMonitorOutput());
   AddMonitorOutput_PionTPCchi2(cutSetPi->GetMonitorOutput());
   
   // AddMonitorOutput_LambdaP(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaPt(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaNegDaughPt(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaPosDaughPt(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaMass(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaDCA(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaRadius(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaDaughterDCA(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaCosPointAngle(cutSetLambda->GetMonitorOutput());
   //   AddMonitorOutput_LambdaProtonPID(cutSetLambda->GetMonitorOutput());
   AddMonitorOutput_LambdaPionPID(cutSetLambda->GetMonitorOutput());
   
   if (isMC) {
     
     TString mode = "HIST";
     if (collSyst) mode = "SPARSE";
     
     // create output
     AliRsnMiniOutput *out = task->CreateOutput(Form("KStarPlusMinus_TrueMC%s", suffix), mode.Data(), "MOTHER");
     // selection settings
     out->SetDaughter(0, AliRsnDaughter::kKaon0);
     out->SetDaughter(1, AliRsnDaughter::kPion);
     out->SetMotherPDG(323);
     out->SetMotherMass(0.89166);
     // pair cuts
     out->SetPairCuts(cutsPair);
     // binnings
     out->AddAxis(imID, 2000, 0.0, 2.0);
     out->AddAxis(ptID, 100, 0.0, 10.0);
     //out->AddAxis(lambdaDCA, 10, 0.0, 1.0);
     
     if (collSyst) out->AddAxis(centID, 10, 0.0, 100.0);
     
     // create output
     AliRsnMiniOutput *out = task->CreateOutput(Form("AKStarPlusMinus_TrueMC%s", suffix), mode.Data(), "MOTHER");
     // selection settings
     out->SetDaughter(0, AliRsnDaughter::kKaon0);
     out->SetDaughter(1, AliRsnDaughter::kPion);
     out->SetMotherPDG(-323);
     out->SetMotherMass(0.89166);
     // pair cuts
     out->SetPairCuts(cutsPair);
     // binnings
     out->AddAxis(imID, 2000, 0.0, 2.0);
     out->AddAxis(ptID, 100, 0.0, 10.0);
     //out->AddAxis(lambdaDCA, 10, 0.0, 1.0);
     
     if (collSyst) out->AddAxis(centID, 10, 0.0, 100.0);
     
   }
   
   return kTRUE;
}
AliCFSingleTrackEfficiencyTask *AddSingleTrackEfficiencyTaskAnalysisQA(TString collSyst="pp",
								       const Bool_t readAOD = 0, // Flag to read AOD:1 or ESD:0
								       TString suffix="default", // suffix for the output directory
								       AliPID::EParticleType specie=AliPID::kPion, 
								       Int_t pdgcode=0, //particle specie
								       Bool_t useMCtruthForKine=kFALSE,
								       Double_t maxRadiusForPrimaries=999.,
								       ULong64_t triggerMask=AliVEvent::kAnyINT,
								       TString centralityEstimator = "V0M",
								       Int_t fBit=0,
								       Bool_t TPCRefit = kTRUE,
								       Int_t minclustersTPC = 0,
								       Bool_t ITSRefit = kTRUE,
								       Int_t spdHits=AliESDtrackCuts::kAny,
								       Int_t minclustersITS = 0,
								       Bool_t useRecoEvSelCutsForKine=kFALSE,
								       Int_t configuration=AliCFSingleTrackEfficiencyTask::kFast,
								       Int_t usageOfBayesianPID=AliSingleTrackEffCuts::kNoBayesianPID)
{

  Info("AliCFSingleTrackEfficiencyTask","SETUP CONTAINER");

  //
  // Setting up the container
  // 
  // Variables
  const Int_t nvar = 7; // number of variables on the grid: pt, y, phi, theta, zvtx, multiplicity, centrality
  UInt_t nstep = 8;     // number of container steps
  const UInt_t ipt = 0;
  const UInt_t ieta  = 1;
  const UInt_t iphi = 2;
  const UInt_t itheta = 3;
  const UInt_t izvtx = 4;
  const UInt_t imult = 5;
  const UInt_t icent = 6;
  //
  // Containter bining

  const Int_t nbinpt=30;
  //   A2. Bins variation by hand for other variables
  const Int_t nbin2 = configuration==AliCFSingleTrackEfficiencyTask::kSlow ? 8 : 8; //bins in eta
  const Int_t nbin3 = configuration==AliCFSingleTrackEfficiencyTask::kSlow ? 9 : 18; //bins in phi
  const Int_t nbin4 = configuration==AliCFSingleTrackEfficiencyTask::kSlow ? 9 : 1; //bins in theta
  const Int_t nbin5 = configuration==AliCFSingleTrackEfficiencyTask::kSlow ? 10 : 4; //bins in zvtx

  const Int_t nbinmult=8;
  const Int_t nbincent=12;

  //arrays for the number of bins in each dimension
  Int_t iBin[nvar];
  iBin[0]=nbinpt;
  iBin[1]=nbin2;
  iBin[2]=nbin3;
  iBin[3]=nbin4;
  iBin[4]=nbin5;
  iBin[5]=nbinmult;
  iBin[6]=nbincent;

  //arrays for lower bounds :
  Double_t binLimpT[nbinpt+1] = {0.00,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.50,0.60,
				 0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50,3.00,
				 3.50,4.00,5.00,6.00,7.00,8.00,10.0,12.0,16.0,20.0,30.0};

  Double_t *binLim2 = new Double_t[iBin[1]+1];
  Double_t *binLim3 = new Double_t[iBin[2]+1];
  Double_t *binLim4 = new Double_t[iBin[3]+1];
  Double_t *binLim5 = new Double_t[iBin[4]+1];
  Double_t binLimmult[nbinmult+1] = {0.,5.,10.,20.,30.,40.,50.,80.,200.};
  Double_t binLimcent[nbincent+1] = {0.,2.5,5.0,7.5,10.,15.,20.,30.,40.,50.,60.,80.,100.};
  if(collSyst=="Pb-Pb" || collSyst=="PbPb" || collSyst=="Xe-Xe" || collSyst=="XeXe"){
    binLimmult[1]=100.;
    binLimmult[2]=500.;
    binLimmult[3]=1000.;
    binLimmult[4]=2000.;
    binLimmult[5]=3000.;
    binLimmult[6]=4000.;
    binLimmult[7]=5000.;
    binLimmult[8]=10000.;
  }

  // Other Variables
  for(Int_t i=0; i<=nbin2; i++) binLim2[i]=(Double_t)etamin + (etamax-etamin)/nbin2*(Double_t)i ;
  for(Int_t i=0; i<=nbin3; i++) binLim3[i]=(Double_t)phimin + (phimax-phimin)/nbin3*(Double_t)i ;
  for(Int_t i=0; i<=nbin4; i++) binLim4[i]=(Double_t)thetamin + (thetamax-thetamin)/nbin4*(Double_t)i ;
  for(Int_t i=0; i<=nbin5; i++) binLim5[i]=(Double_t)zvtxmin + (zvtxmax-zvtxmin)/nbin5*(Double_t)i ;

  // Container  
  AliCFContainer* container = new AliCFContainer(Form("container%s",suffix.Data()),"container for tracks",nstep,nvar,iBin);
  container -> SetBinLimits(ipt,binLimpT);    // pt
  container -> SetBinLimits(ieta,binLim2);      // eta
  container -> SetBinLimits(iphi,binLim3);    // phi
  container -> SetBinLimits(itheta,binLim4);  // theta
  container -> SetBinLimits(izvtx,binLim5);   // Zvtx
  container -> SetBinLimits(imult,binLimmult);// multiplicity
  container -> SetBinLimits(icent,binLimcent);// centrality

  // Variable Titles
  container -> SetVarTitle(ipt,"pt");
  container -> SetVarTitle(ieta, "eta");
  container -> SetVarTitle(iphi,"phi");
  container -> SetVarTitle(itheta, "theta");
  container -> SetVarTitle(izvtx, "Zvtx");
  container -> SetVarTitle(imult, "Multiplicity");
  container -> SetVarTitle(icent, "Centrality");

  // Step Titles
  container -> SetStepTitle(0, " MC Particle with Generated Cuts");
  container -> SetStepTitle(1, " MC Particle with Kine Acceptance Cuts");
  container -> SetStepTitle(2, " MC Particle with Track Ref Acceptance Cuts");
  container -> SetStepTitle(3, " Total Reconstructed  Particle ");
  container -> SetStepTitle(4, " Reco Particle With Kine Acceptance Cuts");
  container -> SetStepTitle(5, " Reco Particle to MC True pt particles ");
  container -> SetStepTitle(6, " Reco Particle With Quality Cuts");
  container -> SetStepTitle(7, " Reco PID With Quality Cuts");


  // SET TLIST FOR QA HISTOS
  TList* qaList = new TList();
  TObjArray* emptyList = new TObjArray(0);

  //CREATE THE INTERFACE TO CORRECTION FRAMEWORK USED IN THE TASK
  printf("CREATE INTERFACE AND CUTS\n");
  AliCFManager* man = new AliCFManager();

  man->SetNStepEvent(2);
  man->SetEventContainer(container);
  man->SetEventCutsList(0,emptyList);//evtmcList);
  man->SetEventCutsList(1,emptyList);//evtrecoList);
  
  man->SetParticleContainer(container);
  man->SetParticleCutsList(0,emptyList);//mcGenList);
  man->SetParticleCutsList(1,emptyList);//mcKineList);
  man->SetParticleCutsList(2,emptyList);//mcaccList);
  man->SetParticleCutsList(3,emptyList);//evtrecoPureList);
  man->SetParticleCutsList(4,emptyList);//recKineList);
  man->SetParticleCutsList(5,emptyList);
  man->SetParticleCutsList(6,emptyList);
  man->SetParticleCutsList(7,emptyList);
  
  // Simulated particle & event cuts
  AliSingleTrackEffCuts* cuts = new AliSingleTrackEffCuts();
  cuts->SetPtRange(ptmin,ptmax);
  cuts->SetEtaRange(etamin,etamax);
  cuts->SetIsCharged(ischarged);
  cuts->SetMinVtxContr(1);
  cuts->SetMaxVtxZ(zvtxmax);
  cuts->SetNumberOfClusters(mintrackrefsITS,mintrackrefsTPC,mintrackrefsTOF,mintrackrefsMUON);
  cuts->SetTriggerMask(triggerMask);
  cuts->SetIsAOD(readAOD);
  cuts->SetMaxRadiusOfParticleOrigin(maxRadiusForPrimaries);
  //
  // Pid selection here
  //
  if(pdgcode>0){
    cuts->SetUsePid(true);
    cuts->SetParticleSpecie(specie);
    cuts->SetPdgCode(pdgcode);
    // 
    const Int_t nlims=1;
    Float_t plims[nlims+1]={0.,999.}; //TPC limits in momentum [GeV/c]
    Float_t sigmas[nlims]={3.};
    cuts->SetUseTPCPid();
    cuts->SetTPCSigmaPtBins(nlims,plims,sigmas);
    cuts->SetMaximumPTPC(4.);
    // 
    const Int_t nlims2=1;
    Float_t plims2[nlims2+1]={0.,999.}; //TPC limits in momentum [GeV/c]
    Float_t sigmas2[nlims2]={3.};
    cuts->SetUseTOFPid();
    cuts->SetTOFSigmaPtBins(nlims2,plims2,sigmas2);
    cuts->SetMaximumPTOF(4.);

    if(usageOfBayesianPID>0) {
      cuts->SetUseCombinPID(usageOfBayesianPID);
      if(usageOfBayesianPID==AliSingleTrackEffCuts::kThresholdBayesianProb)
	cuts->SetPIDThreshold(thresholdPID);
    }

  }

  //
  //  Track Quality cuts via ESD track cuts
  //
  AliESDtrackCuts* QualityCuts = new AliESDtrackCuts();
  QualityCuts->SetRequireSigmaToVertex(kFALSE);
  QualityCuts->SetMinNClustersTPC(minclustersTPC);
  QualityCuts->SetMinNClustersITS(minclustersITS);
  QualityCuts->SetRequireTPCRefit(TPCRefit);
  QualityCuts->SetRequireITSRefit(ITSRefit);
  QualityCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,spdHits);
  QualityCuts->SetMinDCAToVertexXY(0.);
  QualityCuts->SetEtaRange(etamin,etamax);
  QualityCuts->SetPtRange(ptmin,ptmax);


  //CREATE THE TASK
  printf("CREATE CF Single track task\n");

  AliCFSingleTrackEfficiencyTask *task = new AliCFSingleTrackEfficiencyTask("AliCFSingleTrackEfficiencyTask",QualityCuts,cuts);
  if(readAOD && fBit>=0){
    task->SetFilterBit(kTRUE);
    task->SetFilterType(fBit);
  }else{
    task->SetFilterBit(kFALSE);
  }

  //  task->SelectCollisionCandidates(triggerMask);//AliVEvent::kMB);
  if(centralityEstimator != "") task->SetUseCentrality(kTRUE,centralityEstimator);
  task->SetConfiguration(configuration);
  task->SetUseGeneratedKine(useMCtruthForKine);
  if(useRecoEvSelCutsForKine) task->ApplyRecoEventSelectionsToFillMCKine();
  task->SetCFManager(man); //here is set the CF manager

  //
  // Get the pointer to the existing analysis manager via the static access method.
  //==============================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTask", "No analysis manager to connect to.");
    return NULL;
  }

  // This task requires an ESD or AOD input handler and an AOD output handler.
  // Check this using the analysis manager.
  //===============================================================================
  TString type = mgr->GetInputEventHandler()->GetDataType();
  if (!type.Contains("ESD") && !type.Contains("AOD")) {
    ::Error("AddSingleTrackEfficiencyTaskPbPb", "AliCFSingleTrackEfficiency task needs the manager to have an ESD or AOD input handler.");
    return NULL;
  }
  
  mgr->AddTask(task);
  printf(" Create the output container\n");

  //
  // Create and connect containers for input/output
  //
  // ----- output data -----
  TString outputfile = AliAnalysisManager::GetCommonFileName();
  TString input1name="cchain0";
  TString output2name="HistEventsProcessed", output3name="container",output4name="list",output5name="ESDtrackCuts",output6name="MCtrackCuts";
  outputfile += ":PWGPP_CFSingleTrack";
//  outputfile += suffix;
  output2name += suffix;
  output3name += suffix;
  output4name += suffix;
  output5name += suffix;
  output6name += suffix;


  // ------ input data ------
  AliAnalysisDataContainer *cinput0  = mgr->GetCommonInputContainer();
  // ----- output data -----
  // output TH1I for event counting
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(output2name, TH1I::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
  // output Correction Framework Container (for acceptance & efficiency calculations)
  AliAnalysisDataContainer *coutput2 = mgr->CreateContainer(output3name, AliCFContainer::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
  // output QA histograms
  AliAnalysisDataContainer *coutput3 = mgr->CreateContainer(output4name, TList::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
  // output ESD track cuts for book keeping
  AliAnalysisDataContainer *coutput4 = mgr->CreateContainer(output5name, AliESDtrackCuts::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());
  // output event and particle selection cuts for book keeping
  AliAnalysisDataContainer *coutput5 = mgr->CreateContainer(output6name, AliSingleTrackEffCuts::Class(),AliAnalysisManager::kOutputContainer,outputfile.Data());

  mgr->ConnectInput(task,0,mgr->GetCommonInputContainer());
  mgr->ConnectOutput(task,1,coutput1);
  mgr->ConnectOutput(task,2,coutput2);
  mgr->ConnectOutput(task,3,coutput3);
  mgr->ConnectOutput(task,4,coutput4);
  mgr->ConnectOutput(task,5,coutput5);

  return task;
}
AliAnalysisTaskSEHFJetsOrig* AddTaskSEHFJetsOrig(TString fileout="standard",Bool_t readmc=kTRUE,TString cutfile="HFJetVertexCuts.root",TString containerprefix="c", Float_t minC=0., Float_t maxC=7.5)
{  
  //
  // Configuration macro for the task to analyze the fraction of prompt charm
  // using the D0 impact parameter
  // [email protected]
  //
  //==========================================================================

  Int_t last=0;

  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskSEHFJetsOrig", "No analysis manager to connect to.");
    return NULL;
  }   
  
  TString str,containername;
  if(fileout=="standard"){
    fileout=AliAnalysisManager::GetCommonFileName();
    fileout+=":PWG3_HFCJ_";
    fileout+="HFjetVertex";
    if(containerprefix!="c")fileout+=containerprefix;
    str="HFjetVertex";
  }
  else {
    str=fileout;
    str.ReplaceAll(".root","");
  }
  str.Prepend("_");

  AliAnalysisTaskSEHFJetsOrig *hfTask;
  
  
  if(!gSystem->AccessPathName(cutfile.Data(),kFileExists)){
    TFile *f=TFile::Open(cutfile.Data());
    AliRDHFJetsCuts.cxx *cuts= (AliRDHFCutsD0toKpi*)f->Get("HFJetsCutsVertex");
    cuts->PrintAll();
    hfTask = new AliAnalysisTaskSEHFJetsOrig("AliAnalysisTaskSEHFJetsOrig");
    AliHFJetVertexTagging *tagger=new AliHFJetVertexTagging();
    hfTask->SetTagger(tagger);
    hfTask->SetCuts(cuts);
  }
  else {
    
    AliRDHFJetsCuts *cuts=new AliRDHFJetsCuts();
    hfTask = new AliAnalysisTaskSEHFJetsOrig("AliAnalysisTaskSEHFJetsOrig");
    hfTask->SetCuts(cuts);
    AliHFJetVertexTagging *tagger=new AliHFJetVertexTagging();

    AliRDHFJetsCutsVertex *cuts2=new AliRDHFJetsCutsVertex("jetCuts");

    //cuts for jets
    cuts->SetJetRadius(0.4);
    cuts->SetMaxEtaJet(0.5);//0.9-R
    cuts->SetMinPtJet(5);
    cuts->SetMaxPtJet(200);
    cuts2->SetJetRadius(0.4);
    cuts2->SetMaxEtaJet(0.5);//0.9-R
    cuts2->SetMinPtJet(5);
    cuts2->SetMaxPtJet(200);

    AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
    esdTrackCuts->SetRequireSigmaToVertex(kFALSE);
    esdTrackCuts->SetMinNClustersTPC(70);
    esdTrackCuts->SetMaxChi2PerClusterTPC(4);
    esdTrackCuts->SetRequireTPCRefit(kTRUE);
    esdTrackCuts->SetRequireITSRefit(kTRUE);
    //esdTrackCuts->SetMinNClustersITS(4);
    esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
    esdTrackCuts->SetMinDCAToVertexXY(0.);
    esdTrackCuts->SetEtaRange(-0.8,0.8);
    esdTrackCuts->SetPtRange(0.3,1.e10);
  
    cuts2->AddTrackCuts(esdTrackCuts);
    //cuts for vertexing
    cuts2->SetNprongs(3);
    cuts2->SetIsElec(kFALSE); // kTRUE to select e in jet vertex  

 //    cuts2->SetMinPtHardestTrack(1.5);//default 0.3
//     cuts2->SetSecVtxWithKF(kFALSE);//default with StrLinMinDist
//     cuts2->SetImpParCut(0.01);//default 0
//     cuts2->SetDistPrimSec(0.1);//default 0
//     cuts2->SetCospCut(0.7);//default -1

//   cuts2->SetMinPtHardestTrack(1.3);//default 0.3
//     cuts2->SetSecVtxWithKF(kFALSE);//default with StrLinMinDist
//     cuts2->SetImpParCut(0.01);//default 0
//     cuts2->SetDistPrimSec(0.05);//default 0
//     cuts2->SetCospCut(0.7);//default -1

    cuts2->SetMinPtHardestTrack(1.0);//default 0.3
    cuts2->SetSecVtxWithKF(kFALSE);//default with StrLinMinDist
    cuts2->SetImpParCut(0.);//default 0
    cuts2->SetDistPrimSec(0.);//default 0
    cuts2->SetCospCut(-1);//default -1
 

    tagger->SetCuts(cuts2);
    hfTask->SetCuts(cuts);
    hfTask->SetTagger(tagger);
    //    ::Error("AddTaskSEHFJets","No Cut Object");
  }

  cuts->SetMinCentrality(minC);
  cuts->SetMaxCentrality(maxC);
  hfTask->SetReadMC(readmc);
  
  
  mgr->AddTask(hfTask);
 
 
  
 // Create containers for input/output
  AliAnalysisDataContainer *cinput =   mgr->GetCommonInputContainer();
  //mgr->CreateContainer("cinput",TChain::Class(),AliAnalysisManager::kInputContainer);
  mgr->ConnectInput(hfTask,0,cinput);
  

  //Now container for general properties histograms
  containername="outputNentries";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputNentries = mgr->CreateContainer(containername.Data(),TH1F::Class(), AliAnalysisManager::kOutputContainer, fileout.Data());
  mgr->ConnectOutput(hfTask,1,coutputNentries);

  containername="RecoJetsProp";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cSparseVtxProp = mgr->CreateContainer(containername.Data(),THnSparse::Class(), AliAnalysisManager::kOutputContainer, fileout.Data());
  mgr->ConnectOutput(hfTask,2,cSparseVtxProp);

  containername="SparseVerticesProp";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cSparseVtxProp = mgr->CreateContainer(containername.Data(),THnSparse::Class(), AliAnalysisManager::kOutputContainer, fileout.Data());
  mgr->ConnectOutput(hfTask,3,cSparseVtxProp);

  containername="SparseJetVerticesProp";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cSparseVtxProp = mgr->CreateContainer(containername.Data(),THnSparse::Class(), AliAnalysisManager::kOutputContainer, fileout.Data());
  mgr->ConnectOutput(hfTask,4,cSparseVtxProp);


  containername="SparsebTaggedJets";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cSparsebJets = mgr->CreateContainer(containername.Data(),THnSparse::Class(), AliAnalysisManager::kOutputContainer, fileout.Data());
  mgr->ConnectOutput(hfTask,5,cSparsebJets);




  return hfTask;
}