Skip to content

Commit

Permalink
Implementation of a virtual track selection
Browse files Browse the repository at this point in the history
A virtual track selection, hiding differences in the handling
of ESDs and AODs, is implemented. The core of is the set of
classes AliVTrackSelection, AliAODTrackSelection and AliESDTrackSelection,
ported from the EMCAL framework. The primary goal is to make
the analysis framework transparent to ESD and AOD analysis. Users
need to configure the track selection, either with track cuts
inheriting from AliVCuts, or filter bits. Supported aree AliESDtrackCuts
as well as all cuts coming from the correction framework. Selected
tracks can be accessed by either of the methods IsTrackAccepted or
GetAcceptedTracks.

As the data type is know typically only at run time, a natural
way to handle the track selection is by providing a factory class
implementing the creation of the track cuts objets. A base class
AliTrackSelectionFactory is provided, having an abstract function
CreateTrackSelection. Users have to implement this function in their
own class.

The AliAnalysisTaskSE is adapted for this, providing pointers to
both a track selection factory and a track selection object. Both
pointers are not mandatory. Only in case they are set, a track selection
is created in CreateOutput objects, matching to the data type used in
the analysis. The function GetAcceptedTracks can be used by user analyses.
In case track cuts are provided, this method will call the GetAcceptedTracks
from AliVTrackSelection and return its result.
  • Loading branch information
mfasDa authored and dberzano committed Feb 25, 2016
1 parent a175a67 commit 4004191
Show file tree
Hide file tree
Showing 12 changed files with 676 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ANALYSIS/ANALYSISalice/ANALYSISaliceLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

#pragma link C++ class AliAnalysisTaskBadChunkID+;

#pragma link C++ class AliTrackSelectionFactory+;
#pragma link C++ class AliVTrackSelection+;
#pragma link C++ class AliESDTrackSelection+;
#pragma link C++ class AliAODTrackSelection+;

// If ROOT was built with XML support
#ifdef WITHXML
#pragma link C++ class AliTagAnalysis+;
Expand Down
103 changes: 103 additions & 0 deletions ANALYSIS/ANALYSISalice/AliAODTrackSelection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**************************************************************************
* Copyright(c) 1998-2015, 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 <TClonesArray.h>
#include <TBits.h>
#include <TObjArray.h>

#include <AliAODEvent.h>
#include <AliAODTrack.h>
#include <AliAODTrackSelection.h>
#include <AliESDtrack.h>
#include <AliESDtrackCuts.h>

/// \cond CLASSIMP
ClassImp(AliAODTrackSelection)
/// \endcond

/**
* Main constructor, initialises fields with 0 (or NULL). For ROOT I/O, not intended
* to be used by the users.
*/
AliAODTrackSelection::AliAODTrackSelection() :
AliVTrackSelection(),
fFilterBits(0)
{
}

/**
* Main Constructor, initalising also track cuts and filter bits. In case the initial cuts
* is a nullpointer, only filter bits are used for the track selection. This constructor is
* intended to be used by the users.
*
* \param cuts Inital track cut object (of type AliESDtrackCuts, can be a nullpointer)
* \param filterbits Filter bits required
*/
AliAODTrackSelection::AliAODTrackSelection(AliVCuts* cuts, UInt_t filterbits):
AliVTrackSelection(),
fFilterBits(filterbits)
{
AddTrackCuts(cuts);
}

/**
* Function checks whether track is accepted under the given track selection cuts.
* The function can handle AliAODTrack and AliPicoTrack, while for AliPico track an
* AliAODTrack is expected to be the underlying structure. If it is not possible to
* access an AOD track from the input track, the object will not be selected. Otherwise
* first the status bits are checked (if requested), and if further track cuts (of type
* AliESDtrackCuts) are provided, the track is converted to an ESD track for further checks.
*
* \param trk: Track to check
* \return true if selected, false otherwise
*/
bool AliAODTrackSelection::IsTrackAccepted(AliVTrack * const trk)
{
AliAODTrack *aodt = dynamic_cast<AliAODTrack*>(trk);
if(!aodt){
AliError("Failed getting AOD track");
return kFALSE;
}

fTrackBitmap.ResetAllBits();
Int_t cutcounter(0);
if (fFilterBits) {
if(aodt->TestFilterBit(fFilterBits)) fTrackBitmap.SetBitNumber(cutcounter);
cutcounter++;
}
if (fListOfCuts) {
for (TIter cutIter = TIter(fListOfCuts).Begin(); cutIter != TIter::End(); ++cutIter){
AliVCuts *trackCuts = static_cast<AliVCuts*>(*cutIter);
if (trackCuts->IsA() == AliESDtrackCuts::Class()) {
// If track cuts are AliESDtrackCuts, the track needs to be converted to an AliESDtrack before
AliESDtrack copyTrack(aodt);
if (trackCuts->IsSelected(&copyTrack)) fTrackBitmap.SetBitNumber(cutcounter);
}
else{
if (trackCuts->IsSelected(aodt)) fTrackBitmap.SetBitNumber(cutcounter);
}
cutcounter++;
}
}

if (fSelectionModeAny){
// In case of ANY one of the cuts need to be fulfilled (equivalent to one but set)
return fTrackBitmap.CountBits() > 0 || cutcounter == 0;
}
else {
// In case of ALL all of the cuts need to be fulfilled (equivalent to all bits set)
return fTrackBitmap.CountBits() == cutcounter;
}
}
51 changes: 51 additions & 0 deletions ANALYSIS/ANALYSISalice/AliAODTrackSelection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* \file AliAODTrackSelection.h
* \brief Implement virtual track selection for AOD analysis
*
* \author Markus Fasel <[email protected]>, Lawrence Berkeley National Laboratory
* \date Jul 24, 2015
*/
#ifndef ALIAODTRACKSELECTIONAOD_H_
#define ALIAODTRACKSELECTIONAOD_H_
/* Copyright(c) 1998-2015, ALICE Experiment at CERN, All rights reserved. *
* See cxx source for full Copyright notice */

#include <AliVTrackSelection.h>

class AliVCuts;
class AliVTrack;

/**
* \class AliAODTrackSelection
* \brief Implement virtual track selection for AOD analysis
*
* Implementation of track selection in case the analysis runs on AODs
* For the moment it uses the AliESDtrackCuts and converts AOD tracks to
* ESD tracks, which might change in the future when an AOD track selection
* framework becomes available.
*/
class AliAODTrackSelection: public AliVTrackSelection {
public:
AliAODTrackSelection();
AliAODTrackSelection(AliVCuts *cuts, UInt_t filterbits);
virtual ~AliAODTrackSelection() {}

virtual bool IsTrackAccepted(AliVTrack * const trk);

/**
* Add a new filter bit to the track selection. Multiple filter bits can be set
* at the same time (via the bitwise or operator |).
*
* \param filterbits
*/
void AddFilterBit(UInt_t filterbits) { fFilterBits |= filterbits; }

private:
UInt_t fFilterBits; ///< Track filter bits

/// \cond CLASSIMP
ClassDef(AliAODTrackSelection, 2);
/// \endcond
};

#endif /* ALIAODTRACKSELECTIONAOD_H_ */
33 changes: 30 additions & 3 deletions ANALYSIS/ANALYSISalice/AliAnalysisTaskSE.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "AliESDInputHandler.h"
#include "AliMCEvent.h"
#include "AliStack.h"
#include "AliTrackSelectionFactory.h"
#include "AliVTrackSelection.h"
#include "AliLog.h"
#include "AliAODDimuon.h"

Expand Down Expand Up @@ -88,7 +90,9 @@ AliAnalysisTaskSE::AliAnalysisTaskSE():
fHistosQA(0x0),
fOfflineTriggerMask(0),
fMultiInputHandler(0),
fMCEventHandler(0)
fMCEventHandler(0),
fTrackSelectionFactory(0),
fTrackSelection(0)
{
// Default constructor
}
Expand All @@ -107,7 +111,9 @@ AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
fHistosQA(0x0),
fOfflineTriggerMask(0),
fMultiInputHandler(0),
fMCEventHandler(0)
fMCEventHandler(0),
fTrackSelectionFactory(0),
fTrackSelection(0)
{
// Default constructor
DefineInput (0, TChain::Class());
Expand All @@ -128,7 +134,9 @@ AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
fHistosQA(0x0),
fOfflineTriggerMask(0),
fMultiInputHandler(obj.fMultiInputHandler),
fMCEventHandler(obj.fMCEventHandler)
fMCEventHandler(obj.fMCEventHandler),
fTrackSelectionFactory(obj.fTrackSelectionFactory),
fTrackSelection(obj.fTrackSelection)
{
// Copy constructor
fDebug = obj.fDebug;
Expand Down Expand Up @@ -165,6 +173,8 @@ AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
fOfflineTriggerMask = other.fOfflineTriggerMask;
fMultiInputHandler = other.fMultiInputHandler;
fMCEventHandler = other.fMCEventHandler;
fTrackSelectionFactory = other.fTrackSelectionFactory;
fTrackSelection = other.fTrackSelection;
return *this;
}

Expand Down Expand Up @@ -332,6 +342,13 @@ void AliAnalysisTaskSE::CreateOutputObjects()
fOutputAOD->GetStdContent();
}
}

if(fTrackSelectionFactory && !fTrackSelection)
fTrackSelection = fTrackSelectionFactory->CreateTrackCuts(
AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()->IsA() == AliAODInputHandler::Class() ?
AliTrackSelectionFactory::kAOD :
AliTrackSelectionFactory::kESD
);
ConnectMultiHandler();
UserCreateOutputObjects();
DisconnectMultiHandler();
Expand Down Expand Up @@ -866,3 +883,13 @@ void AliAnalysisTaskSE::DisconnectMultiHandler()
//
if (fMultiInputHandler) fInputHandler = fMultiInputHandler;
}

/**
* Perform track selection in case a virtual track selection is provided.
* @return List of accepted tracks in case a track selection is provided, null otherwise
*/
TObjArray *AliAnalysisTaskSE::GetAcceptedTracks(){
TObjArray *result = NULL;
if(fTrackSelection) result = fTrackSelection->GetAcceptedTracks(InputEvent());
return result;
}
10 changes: 10 additions & 0 deletions ANALYSIS/ANALYSISalice/AliAnalysisTaskSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AliMultiInputEventHandler;
class AliAnalysisCuts;
class AliESDfriend;
class AliEventTag;
class AliTrackSelectionFactory;
class AliVTrackSelection;

class TTree;
class TList;
Expand Down Expand Up @@ -70,10 +72,16 @@ class AliAnalysisTaskSE : public AliAnalysisTask
virtual TList* GetQAHistos() const {return fHistosQA;}
virtual Bool_t IsEventInBinZero() { return kFALSE;}
virtual UInt_t GetCollisionCandidates() const { return fOfflineTriggerMask;}

void SetTrackSelectionFactory(AliTrackSelectionFactory *factory) { fTrackSelectionFactory = factory; }
void SetTrackSelection(AliVTrackSelection *sel) { fTrackSelection = sel; }

protected:
void ConnectMultiHandler();
void DisconnectMultiHandler();

TObjArray *GetAcceptedTracks();

protected:
Int_t fDebug; // Debug flag
// IO
Expand Down Expand Up @@ -111,6 +119,8 @@ class AliAnalysisTaskSE : public AliAnalysisTask
// Event Mixing
AliMultiInputEventHandler *fMultiInputHandler; //! pointer to multihandler
AliInputEventHandler *fMCEventHandler; //! pointer to MCEventHandler
AliTrackSelectionFactory *fTrackSelectionFactory; /// track selection factory
AliVTrackSelection *fTrackSelection; /// track selection
ClassDef(AliAnalysisTaskSE, 4); // Analysis task for standard jet analysis
};

Expand Down
73 changes: 73 additions & 0 deletions ANALYSIS/ANALYSISalice/AliESDTrackSelection.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**************************************************************************
* Copyright(c) 1998-2015, 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 <AliESDTrackSelection.h>
#include <TBits.h>
#include <TClonesArray.h>
#include <TObjArray.h>
#include <memory>

#include "AliESDEvent.h"
#include "AliESDtrack.h"
#include "AliESDtrackCuts.h"
#include "AliLog.h"
#include "AliVCuts.h"

/// \cond CLASSIMP
ClassImp(AliESDTrackSelection)
/// \endcond

/**
* Default constructor
*/
AliESDTrackSelection::AliESDTrackSelection():
AliVTrackSelection()
{
}

/**
* Constructor with cuts
*/
AliESDTrackSelection::AliESDTrackSelection(AliVCuts* cuts):
AliVTrackSelection()
{
this->AddTrackCuts(cuts);
}

/**
* Check whether track is accepted. Iterates over all cuts assigned to the track selection.
*
* \param trk: Track to check
* \return: true if selected, false otherwise
*/
bool AliESDTrackSelection::IsTrackAccepted(AliVTrack* const trk) {
if (!fListOfCuts) return kTRUE;
AliESDtrack *esdt = dynamic_cast<AliESDtrack *>(trk);
if(!esdt){
AliError("Failed getting ESD track");
return kFALSE;
}
fTrackBitmap.ResetAllBits();
Int_t cutcounter = 0;
for (TIter cutIter = TIter(fListOfCuts).Begin(); cutIter != TIter::End(); ++cutIter){
if((static_cast<AliVCuts *>(*cutIter))->IsSelected(esdt)) fTrackBitmap.SetBitNumber(cutcounter);
cutcounter++;
}
// In case of ANY at least one bit has to be set, while in case of ALL all bits have to be set
if (fSelectionModeAny){
return fTrackBitmap.CountBits() > 0 || cutcounter == 0;
} else {
return fTrackBitmap.CountBits() == cutcounter;
}
}
41 changes: 41 additions & 0 deletions ANALYSIS/ANALYSISalice/AliESDTrackSelection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* \file AliESDTrackSelection.h
* \brief Declaration of class AliESDTrackSelection
*
* In this header file the class AliESDTrackSelection, which implements
* the virtual track selection for ESD tracks, is declared
*
* \author Markus Fasel <[email protected]>, Lawrence Berkeley National Laboratory
* \date Jul 24, 2015
*/
#ifndef ALIESDTASKTRACKSELECTION_H_
#define ALIESDTASKTRACKSELECTION_H_
/* Copyright(c) 1998-2015, ALICE Experiment at CERN, All rights reserved. *
* See cxx source for full Copyright notice */

#include <AliVTrackSelection.h>

class AliVCuts;
class AliVTrack;

/**
* \class AliESDTrackSelection
* \brief Implementation of virtual track selection for ESDs
*
* Implementation of the track selection for the analysis on ESDs using
* AliESDtrackCuts as underlying structure
*/
class AliESDTrackSelection: public AliVTrackSelection {
public:
AliESDTrackSelection();
AliESDTrackSelection(AliVCuts *cuts);
virtual ~AliESDTrackSelection() {}

virtual bool IsTrackAccepted(AliVTrack * const trk);

/// \cond CLASSIMP
ClassDef(AliESDTrackSelection,1);
/// \endcond
};

#endif /* ALIESDTRACKSELECTION_H_ */
Loading

0 comments on commit 4004191

Please sign in to comment.