]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEV0taginfo.cxx
fix coverity defects
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEV0taginfo.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 //
16 // Class AliHFEV0taginfo
17 // Creates list of tracks with V0 information
18 //
19 // Author:
20 //   Jan Wagner <J.Wagner@gsi.de>
21 //
22
23
24
25
26 #include <iostream>
27 #include <TClass.h>
28 #include <TList.h>
29 #include <TMath.h>
30
31
32 #include "AliLog.h"
33 #include "AliAODEvent.h"
34 #include "AliAODv0.h"
35 #include "AliESDEvent.h"
36 #include "AliESDv0.h"
37
38 #include "AliHFEV0taginfo.h"
39
40
41 ClassImp(AliHFEV0taginfo)
42 ClassImp(AliHFEV0taginfo::AliHFEV0tag)
43
44 //___________________________________________________________________
45 AliHFEV0taginfo::AliHFEV0taginfo():
46     TNamed(), 
47     fIsAODana(NULL),
48     fTaggedTracks(NULL),
49     fV0finder(NULL),
50     fAODV0finder(NULL)
51 {
52     //
53     // default constructor
54     //
55 }
56 //___________________________________________________________________
57 AliHFEV0taginfo::AliHFEV0taginfo(const char* name):
58     TNamed(name, ""), 
59     fIsAODana(kFALSE),
60     fTaggedTracks(NULL),
61     fV0finder(NULL),
62     fAODV0finder(NULL)
63 {
64     //
65     // constructor
66     //
67
68     fTaggedTracks = new TList();
69     if(fTaggedTracks){
70         fTaggedTracks->SetOwner();
71     }
72     fV0finder = new AliESDv0KineCuts();
73     fAODV0finder = new AliAODv0KineCuts();
74 }
75
76 //__________________________________________________________________
77 AliHFEV0taginfo::AliHFEV0taginfo(const AliHFEV0taginfo &ref):
78   TNamed(ref),
79     fIsAODana(ref.fIsAODana),
80     fTaggedTracks(NULL),
81     fV0finder(ref.fV0finder),
82     fAODV0finder(ref.fAODV0finder)
83 {
84   //
85   // Copy constructor
86   // creates a new object with new (empty) containers
87   //
88     fTaggedTracks = new TList();
89     if(fTaggedTracks){
90         fTaggedTracks->SetOwner();
91     }
92
93
94     AliHFEV0tag *tmp = NULL;
95     for(Int_t ien = 0; ien < ref.fTaggedTracks->GetEntries(); ien++){
96         tmp = static_cast<AliHFEV0tag *>(ref.fTaggedTracks->At(ien));
97         fTaggedTracks->Add(new AliHFEV0tag(tmp->GetTrackID(),tmp->GetPinfo()));
98     }
99 }
100
101 //__________________________________________________________________
102 AliHFEV0taginfo &AliHFEV0taginfo::operator=(const AliHFEV0taginfo &ref){
103     //
104     // Assignment operator
105     // Cleanup old object, create a new one with new containers inside
106     //
107     if(this == &ref) return *this;
108     this->~AliHFEV0taginfo(); 
109     TNamed::operator=(ref);
110     fIsAODana = ref.fIsAODana;
111     fTaggedTracks = new TList();
112     AliHFEV0tag *tmp = NULL;
113     for(Int_t ien = 0; ien < ref.fTaggedTracks->GetEntries(); ien++){
114         tmp = static_cast<AliHFEV0tag *>(ref.fTaggedTracks->At(ien));
115         fTaggedTracks->Add(new AliHFEV0tag(tmp->GetTrackID(),tmp->GetPinfo()));
116     }
117     fV0finder=ref.fV0finder;
118     fAODV0finder=ref.fAODV0finder;
119     return *this;
120 }
121 //___________________________________________________________________
122 AliHFEV0taginfo::~AliHFEV0taginfo(){
123
124     //
125     // Destructor
126     //
127     delete fTaggedTracks;
128     delete fV0finder;
129     AliDebug(6, "DESTRUCTOR");
130 }
131
132 //________________________________________________________________________________
133 // loops over V0s in event and fills fTaggedTracks with V0 tracks
134 void AliHFEV0taginfo::TagV0Tracks(AliVEvent *fEvent){
135
136     if (!fEvent) return;
137
138     const Int_t nTracks = fEvent->GetNumberOfTracks();
139     if(nTracks < 2) return;
140
141     const Int_t nV0s = fEvent->GetNumberOfV0s();
142     if(nV0s < 1) return;
143     AliDebug(3,Form("%d V0s found!",nV0s));
144   
145     if(fEvent->IsA() == AliESDEvent::Class()){
146         AliDebug(4, "ESD part");
147         AliESDEvent *esdevent = static_cast<AliESDEvent *>(fEvent);
148         fV0finder->SetEvent(esdevent);
149
150         for(Int_t i=0; i<nV0s; ++i){
151             Int_t pdgP = 0;
152             Int_t pdgN = 0;
153             AliESDv0 *fV0 = esdevent->GetV0(i);
154             if(!fV0) continue;
155             if(fV0finder->ProcessV0(fV0,pdgP,pdgN)){
156                 AliDebug(5,Form("V0 has: pos pdg: %d, neg pdg: %d",pdgP,pdgN));
157                 AddTrack(fV0->GetPindex(),pdgP);
158                 AddTrack(fV0->GetNindex(),pdgN);
159             }
160         }
161     } else if(fEvent->IsA() == AliAODEvent::Class()){
162         AliDebug(4,"AOD part");
163         AliAODEvent *aodevent = static_cast<AliAODEvent *>(fEvent);
164         fAODV0finder->SetEvent(aodevent);
165
166         for(Int_t i=0; i<nV0s; ++i){
167             Int_t pdgP = 0;
168             Int_t pdgN = 0;
169             AliAODv0 *fV0 = aodevent->GetV0(i);
170             if(!fV0) continue;
171             if(fAODV0finder->ProcessV0(fV0,pdgP,pdgN)){
172                 AliDebug(5,Form("V0 has: pos pdg: %d, neg pdg: %d",pdgP,pdgN));
173                 AddTrack(fV0->GetPosID(),pdgP);
174                 AddTrack(fV0->GetNegID(),pdgN);
175             }
176         }
177     }
178 }
179
180 //________________________________________________________________________________
181 //Translates the pdg code to AliPID enum and adds track to tagged list
182 void AliHFEV0taginfo::AddTrack(Int_t TrackID, Int_t pdgCode){
183
184     if(TrackID<0) return;
185     AliPID::EParticleType Pinfo;
186     switch (TMath::Abs(pdgCode)){
187         case  11:
188             Pinfo = AliPID::kElectron;
189             break;
190         case  211:
191             Pinfo = AliPID::kPion;
192             break;
193         case  2212:
194             Pinfo = AliPID::kProton;
195             break;
196         default:
197             return;
198     }
199     fTaggedTracks->Add(new AliHFEV0tag(TrackID, Pinfo));
200     AliDebug(4,Form("Added new Track ID: %d with PID: %d, #entry: %d",TrackID, Pinfo, fTaggedTracks->GetEntries()));
201 }
202
203
204 //________________________________________________________________________________
205 //check for V0 information from track ID 
206 //returns AliPID::kUnknown if track ID not found
207 AliPID::EParticleType AliHFEV0taginfo::GetV0Info(Int_t trackID){
208
209     AliHFEV0tag test(trackID, AliPID::kUnknown);
210     AliHFEV0tag *result = dynamic_cast<AliHFEV0tag *>(fTaggedTracks->FindObject(&test));
211     if(!result){ 
212         AliDebug(6, Form("Could not find track ID %d", trackID));
213         return AliPID::kUnknown;
214     }
215     return result->GetPinfo();
216 }
217
218 //________________________________________________________________________________
219 //resets the fTaggedTracks TList
220 void AliHFEV0taginfo::Reset(){
221     fTaggedTracks->Delete();
222 }
223
224
225 //___________________________________________________________________
226 AliHFEV0taginfo::AliHFEV0tag::AliHFEV0tag():
227     TObject(), 
228     fTrackID(0),
229     fPinfo(AliPID::kUnknown)
230 {
231     // default constructor
232 }
233 //___________________________________________________________________
234 AliHFEV0taginfo::AliHFEV0tag::AliHFEV0tag(Int_t TrackID, AliPID::EParticleType Pinfo):
235     TObject(), 
236     fTrackID(TrackID),
237     fPinfo(Pinfo)
238 {
239 }
240
241 //____________________________________________________________
242 AliHFEV0taginfo::AliHFEV0tag::AliHFEV0tag(const AliHFEV0tag &ref):
243     TObject(ref),
244     fTrackID(ref.fTrackID),
245     fPinfo(ref.fPinfo)
246 {
247     // Copy constructor
248 }
249
250 //____________________________________________________________
251 AliHFEV0taginfo::AliHFEV0tag &AliHFEV0taginfo::AliHFEV0tag::operator=(const AliHFEV0tag &ref){
252     // Assignment operator
253     if(this != &ref){
254         TObject::operator=(ref);
255
256         fTrackID = ref.fTrackID;
257         fPinfo = ref.fPinfo;
258     }
259     return *this;
260 }
261
262 //___________________________________________________________________
263 AliHFEV0taginfo::AliHFEV0tag::~AliHFEV0tag(){
264     //
265     // Destructor
266     //
267     AliDebug(6, "DESTRUCTOR");
268 }
269
270 //Set track ID and particle info 
271 //___________________________________________________________________
272 void AliHFEV0taginfo::AliHFEV0tag::SetTrack(const Int_t trackID, const AliPID::EParticleType Pinfo){
273     fTrackID = trackID;
274     fPinfo = Pinfo;
275 }
276 //____________________________________________________________
277 Bool_t AliHFEV0taginfo::AliHFEV0tag::IsEqual(const TObject *ref) const {
278     //
279     // Check for equality  of track ID
280     //
281     const AliHFEV0tag *refObj = dynamic_cast<const AliHFEV0tag *>(ref);
282     if(!refObj) return kFALSE;
283     return (fTrackID == refObj->GetTrackID());
284 }
285 //____________________________________________________________
286 Int_t AliHFEV0taginfo::AliHFEV0tag::Compare(const TObject *ref) const{
287     //
288     // Compares two objects
289     // Order:
290     //   First compare track ID then particle info
291     //
292     const AliHFEV0tag *refObj = static_cast<const AliHFEV0tag *>(ref);
293     if(fTrackID < refObj->GetTrackID()) return -1;
294     else if(fTrackID > refObj->GetTrackID()) return 1;
295     else{
296         if(fPinfo < refObj->GetPinfo()) return -1;
297         else if(fPinfo > refObj->GetPinfo()) return 1;
298         else return 0;
299     }
300 }
301
302