Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-2015, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
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 : **************************************************************************/
15 : #include <TObjArray.h>
16 : #include <TClonesArray.h>
17 : #include <AliVTrack.h>
18 : #include <AliVEvent.h>
19 : #include <AliVTrackSelection.h>
20 : #include "AliVCuts.h"
21 :
22 : /// \cond CLASSIMP
23 170 : ClassImp(AliVTrackSelection)
24 : /// \endcond
25 :
26 : /**
27 : * Default consturctor, initialising objects with NULL,
28 : * sets acception mode to ALL
29 : */
30 : AliVTrackSelection::AliVTrackSelection() :
31 0 : TObject(),
32 0 : fListOfTracks(NULL),
33 0 : fListOfTrackBitmaps(NULL),
34 0 : fTrackBitmap(64),
35 0 : fListOfCuts(NULL),
36 0 : fSelectionModeAny(kFALSE)
37 0 : {
38 0 : }
39 :
40 : /**
41 : * Copy constructor, performing a flat copy
42 : * \param ref
43 : */
44 : AliVTrackSelection::AliVTrackSelection(const AliVTrackSelection& ref):
45 0 : TObject(ref),
46 0 : fListOfTracks(NULL),
47 0 : fListOfTrackBitmaps(NULL),
48 0 : fTrackBitmap(64),
49 0 : fListOfCuts(NULL),
50 0 : fSelectionModeAny(kFALSE)
51 0 : {
52 0 : if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
53 0 : if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
54 0 : if(ref.fListOfCuts){
55 0 : fListOfCuts = new TObjArray;
56 0 : fListOfCuts->SetOwner(false);
57 0 : for(TIter cutIter = TIter(ref.fListOfCuts).Begin(); cutIter != TIter::End(); ++cutIter)
58 0 : fListOfCuts->Add(*cutIter);
59 0 : }
60 0 : }
61 :
62 : /**
63 : * Assingment operator, makes a flat copy
64 : * \param ref Reference for the copy
65 : * \return Result of the copy
66 : */
67 : AliVTrackSelection& AliVTrackSelection::operator=(const AliVTrackSelection& ref) {
68 0 : TObject::operator=(ref);
69 0 : if(this != &ref){
70 0 : this->~AliVTrackSelection();
71 0 : if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
72 0 : if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
73 0 : if(ref.fListOfCuts){
74 0 : fListOfCuts = new TObjArray;
75 0 : fListOfCuts->SetOwner(false);
76 0 : for(TIter cutIter = TIter(ref.fListOfCuts).Begin(); cutIter != TIter::End(); ++cutIter)
77 0 : fListOfCuts->Add(*cutIter);
78 0 : } else fListOfCuts = NULL;
79 : }
80 0 : return *this;
81 0 : }
82 :
83 : /**
84 : * Destructor, deletes track and track cut arrays
85 : * In case the object has ownership over the track cuts itself, it also deletes those
86 : */
87 0 : AliVTrackSelection::~AliVTrackSelection() {
88 0 : if(fListOfTracks) delete fListOfTracks;
89 0 : if(fListOfTrackBitmaps) delete fListOfTrackBitmaps;
90 0 : if(fListOfCuts) delete fListOfCuts;
91 0 : }
92 :
93 : /**
94 : * Add new track cuts to the list of cuts. Takes ownership over the cuts
95 : * \param cuts New cuts to add
96 : */
97 : void AliVTrackSelection::AddTrackCuts(AliVCuts *cuts){
98 0 : if(!fListOfCuts){
99 0 : fListOfCuts = new TObjArray;
100 0 : fListOfCuts->SetOwner(true);
101 0 : }
102 0 : fListOfCuts->Add(cuts);
103 0 : }
104 :
105 : /**
106 : * Add new track cuts to the list of cuts. Takes ownership over the cuts
107 : * \param cuts New cuts to add
108 : */
109 : void AliVTrackSelection::AddTrackCuts(TObjArray *cuts){
110 0 : TIter next(cuts);
111 : AliVCuts* item = 0;
112 0 : while ((item = static_cast<AliVCuts*>(next())))
113 : {
114 0 : AddTrackCuts(item);
115 : }
116 0 : }
117 :
118 : /**
119 : * Get the number of cut objects assigned.
120 : * \return The number of cut objects
121 : */
122 : Int_t AliVTrackSelection::GetNumberOfCutObjects() const {
123 0 : if(!fListOfCuts) return 0;
124 0 : return fListOfCuts->GetEntries();
125 0 : }
126 :
127 : /**
128 : * Access to track cuts at a given position
129 : * \param icut Cut at position in array
130 : * \return The cuts (NULL for invalid positions)
131 : */
132 : AliVCuts* AliVTrackSelection::GetTrackCuts(Int_t icut) {
133 0 : if(!fListOfCuts) return NULL;
134 0 : if(icut < fListOfCuts->GetEntries())
135 0 : return static_cast<AliVCuts *>(fListOfCuts->At(icut));
136 0 : return NULL;
137 0 : }
138 :
139 : /**
140 : * Select tracks from a TClonesArray of input tracks
141 : *
142 : * \param tracks TClonesArray of tracks (must not be null)
143 : * \return: TObjArray of selected tracks
144 : */
145 : TObjArray* AliVTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
146 : {
147 0 : if (!fListOfTracks) {
148 0 : fListOfTracks = new TObjArray;
149 0 : }
150 : else {
151 0 : fListOfTracks->Clear();
152 : }
153 :
154 0 : if (!fListOfTrackBitmaps) {
155 0 : fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
156 0 : fListOfTrackBitmaps->SetOwner(kTRUE);
157 0 : }
158 : else {
159 0 : fListOfTrackBitmaps->Clear();
160 : }
161 :
162 0 : TIter next(tracks);
163 : AliVTrack* track = 0;
164 : Int_t i = 0;
165 0 : while((track = static_cast<AliVTrack*>(next()))) {
166 0 : if (IsTrackAccepted(track)) {
167 0 : fListOfTracks->AddLast(track);
168 : }
169 : else {
170 0 : fListOfTracks->AddLast(0);
171 : }
172 0 : new ((*fListOfTrackBitmaps)[i]) TBits(fTrackBitmap);
173 0 : i++;
174 : }
175 0 : return fListOfTracks;
176 0 : }
177 :
178 : /**
179 : * Select tracks from a virtual event. Delegates selection process to function IsTrackAccepted
180 : *
181 : * \param event AliESDEvent, via interface of virtual event (must not be null)
182 : * \return TObjArray of selected tracks
183 : */
184 : TObjArray* AliVTrackSelection::GetAcceptedTracks(const AliVEvent* const event)
185 : {
186 0 : if (!fListOfTracks) {
187 0 : fListOfTracks = new TObjArray;
188 0 : }
189 : else {
190 0 : fListOfTracks->Clear();
191 : }
192 :
193 0 : if (!fListOfTrackBitmaps) {
194 0 : fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
195 0 : fListOfTrackBitmaps->SetOwner(kTRUE);
196 0 : }
197 : else {
198 0 : fListOfTrackBitmaps->Clear();
199 : }
200 :
201 0 : for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
202 0 : AliVTrack *trk = static_cast<AliVTrack*>(event->GetTrack(itrk));
203 0 : if (IsTrackAccepted(trk)) {
204 0 : fListOfTracks->AddLast(trk);
205 : }
206 : else {
207 : fListOfTracks->AddLast(trk);
208 : }
209 0 : new ((*fListOfTrackBitmaps)[itrk]) TBits(fTrackBitmap);
210 : }
211 0 : return fListOfTracks;
212 0 : }
|