]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AliAODMuonReplicator.cxx
some fixes wrt to the AliAODExtension behavior (Laurent)
[u/mrichter/AliRoot.git] / PWG3 / muon / AliAODMuonReplicator.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 // $Id$
17
18 //
19 // Implementation of a branch replicator 
20 // to produce slim muon and dimuon aods.
21 //
22 // This replicator is in charge of replicating the tracks,vertices and dimuons
23 // branches of the standard AOD into muon AODs (AliAOD.Muons.root and
24 // AliAOD.Dimuons.root)
25 // 
26 // The tracks are filtered so that only muon tracks (and only muon tracks
27 // that pass the trackCut if present) make it to the output aods
28 //
29 // The vertices are filtered so that only the primary vertices make it
30 // to the output aods.
31 //
32 // The dimuons are recreated here, according to the set of tracks
33 // that pass the trackCut (that set may be the same as the input set,
34 // but to be 100% safe, we always recreate the dimuons).
35 // 
36 // Author: L. Aphecetche (Subatech)
37
38 #include "AliAODMuonReplicator.h"
39 #include "AliAnalysisCuts.h"
40 #include "AliAODEvent.h"
41 #include "AliAODTrack.h"
42 #include "AliAODDimuon.h"
43 #include <cassert>
44
45 ClassImp(AliAODMuonReplicator)
46
47 //_____________________________________________________________________________
48 AliAODMuonReplicator::AliAODMuonReplicator(const char* name, const char* title,
49                                                  AliAnalysisCuts* trackCut,
50                                                  AliAnalysisCuts* vertexCut)
51 : AliAODBranchReplicator(name,title), 
52 fTrackCut(trackCut), fTracks(0x0), 
53 fVertexCut(vertexCut), fVertices(0x0), 
54 fDimuons(0x0),
55 fList(0x0)
56 {
57   // default ctor
58 }
59
60 //_____________________________________________________________________________
61 AliAODMuonReplicator::~AliAODMuonReplicator()
62 {
63   // dtor
64   delete fTrackCut;
65   delete fVertexCut;
66   delete fList;
67 }
68
69 //_____________________________________________________________________________
70 TList* AliAODMuonReplicator::GetList() const
71 {
72   // return (and build if not already done) our internal list of managed objects
73   if (!fList)
74   {
75     fTracks = new TClonesArray("AliAODTrack",30);
76                 fTracks->SetName("tracks");    
77     
78     fVertices = new TClonesArray("AliAODVertex",2);
79                 fVertices->SetName("vertices");    
80
81     fDimuons = new TClonesArray("AliAODDimuon",2);
82     fDimuons->SetName("dimuons");
83     
84     fList = new TList;
85     fList->SetOwner(kTRUE);
86     
87     fList->Add(fTracks);
88     fList->Add(fVertices);
89     fList->Add(fDimuons);
90   }
91   return fList;
92 }
93
94 //_____________________________________________________________________________
95 void AliAODMuonReplicator::ReplicateAndFilter(const AliAODEvent& source)
96 {
97   // Replicate (and filter if filters are there) the relevant parts we're interested in AODEvent
98   
99   static int n(0);
100   
101   ++n;
102   
103   assert(fTracks!=0x0);
104   fTracks->Clear("C");
105   TIter next(source.GetTracks());
106   AliAODTrack* t;
107   Int_t ntracks(0);
108   
109   
110   while ( ( t = static_cast<AliAODTrack*>(next()) ) )
111   {
112     if ( !fTrackCut || fTrackCut->IsSelected(t) ) 
113     {
114       new((*fTracks)[ntracks++]) AliAODTrack(*t);
115     }
116   }
117   
118   assert(fVertices!=0x0);
119   fVertices->Clear("C");
120   TIter nextV(source.GetVertices());
121   AliAODVertex* v;
122   Int_t nvertices(0);
123   
124   while ( ( v = static_cast<AliAODVertex*>(nextV()) ) )
125   {
126     if ( !fVertexCut || fVertexCut->IsSelected(v) ) 
127     {
128       AliAODVertex* tmp = v->CloneWithoutRefs();
129       new((*fVertices)[nvertices++]) AliAODVertex(*tmp);
130       delete tmp;
131     }
132   }
133   
134   fDimuons->Clear("C");
135   
136   // as there might be a track cut (different from the one of the main filtering),
137   // we must recreate the dimuon completely from scratch to be 100% safe...
138
139   Int_t ndimuons(0);
140
141   for ( Int_t i = 0; i < ntracks; ++i ) 
142   {
143     for ( Int_t j = i+1; j < ntracks; ++j ) 
144     {
145       new((*fDimuons)[ndimuons++]) AliAODDimuon(fTracks->At(i),fTracks->At(j));
146     }
147   }
148   
149   AliDebug(1,Form("n=%d tracks=%d vertices=%d ndimuons=%d",n,fTracks->GetEntries(),fVertices->GetEntries(),fDimuons->GetEntries()));
150 }
151