]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnManager.cxx
0224065a6dd6fa01812ae15bb2ff615987851c28
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnManager.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 //-------------------------------------------------------------------------
17 //                     Class AliRsnManager
18 //-------------------------------------------------------------------------
19 // This class is a manager to process one or more pair analysis with a 
20 // given event sample, specified as a TTree passed to this object.
21 // Each single pair analysis must be defined with its specifications, like
22 // histogram binning, cuts and everything else.
23 // This class utiliy consists in defining a unique event sample which is 
24 // used for all pairs analysis, and all kinds of event mixing (if required).
25 // All histograms computed in a single execution, are then saved into a file.
26 // This object contains a two TObjArray's:
27 //  - one to contain single event pair analysis objects (signal, like-sign)
28 //  - one to contain all event-mixing pair analysis objects
29 // When a new pair is added, it must be then specified in what container it 
30 // must be placed, in order to avoid meaningless results.
31 //       
32 // author: A. Pulvirenti
33 // email : alberto.pulvirenti@ct.infn.it
34 //-------------------------------------------------------------------------
35
36 #include <TH1.h>
37 #include <TTree.h>
38 #include <TFile.h>
39 #include <TArray.h>
40 #include <TClonesArray.h>
41
42 #include "AliLog.h"
43
44 #include "AliRsnEvent.h"
45 #include "AliRsnPair.h"
46 #include "AliRsnManager.h"
47
48 ClassImp(AliRsnManager)
49
50 //_____________________________________________________________________________
51 AliRsnManager::AliRsnManager() :
52   TObject(),
53   fUsePID(kTRUE),
54   fStep(100),
55   fMixEvents(10),
56   fMixMultCut(10),
57   fMixVzCut(0.5),
58   fQueuePos(-1),
59   fPairs(0x0),
60   fMixPairs(0x0),
61   fBuffer(0x0),
62   fOutputList(0x0)
63
64 {
65 //
66 // Constructor
67 //
68 }
69
70 //_____________________________________________________________________________
71 void AliRsnManager::Clear(Option_t* /*option*/)
72 {
73 //
74 // Clear heap
75 //
76         
77         if (fPairs) {
78            fPairs->Delete();
79            delete fPairs;
80     }
81     if (fMixPairs) {
82            fMixPairs->Delete();
83            delete fMixPairs;
84     }
85         if (fBuffer) delete fBuffer;
86         if (fOutputList) {
87            fOutputList->Delete();
88            delete fOutputList;
89     }
90 }
91
92 //_____________________________________________________________________________
93 void AliRsnManager::SetQueueSize(Int_t size)
94 {
95     if (fBuffer) {
96         fBuffer->Delete();
97         delete fBuffer;
98     }
99     fBuffer = new TObjArray(size);
100     fBuffer->SetOwner();
101     fQueuePos = -1;
102 }
103
104 //_____________________________________________________________________________
105 void AliRsnManager::AddPair(AliRsnPair *pair)
106 {
107 //
108 // Add a pair of particle types to be analyzed.
109 // Second argument tells if the added object is for event mixing.
110 //
111
112     Bool_t mixing = pair->IsForMixing();
113         TObjArray* &target = mixing ? fMixPairs : fPairs;
114         if (!target) target = new TObjArray(0);
115         target->AddLast(pair);
116         
117         if (!fOutputList) fOutputList = new TList;
118         
119         fOutputList->Add(pair->GetHistogram());
120 }
121
122 //_____________________________________________________________________________
123 Stat_t AliRsnManager::Process(AliRsnEvent *event)
124 {
125 //
126 // For each AliRsnPair definition, fills its histogram 
127 // taking particles from the passed event.
128 //
129     Stat_t nPairs = 0;
130     if (!event) return nPairs;
131     
132     // check pair list
133     if (!fPairs) {
134         AliError("Uninitialized array");
135         return 0.0;
136     }
137     if (fPairs->IsEmpty()) {
138         AliError("No pairs defined");
139         return 0.0;
140     }
141     if (!fBuffer) {
142         AliError("Buffer uninitialized");
143         return 0.0;
144     }
145
146         // create an iterator which run over all pairs
147         TObjArrayIter pairIterator(fPairs);
148         AliRsnPair *pair = 0;
149     while ( (pair = (AliRsnPair*)pairIterator.Next()) ) {
150         nPairs += pair->Process(event, event);
151     }
152     
153     // if there are mix pairs, do event mixing
154     if (fMixPairs) Mix(event);
155     
156     // add this event to the queue
157     fQueuePos++;
158     if (fQueuePos >= fBuffer->GetSize()) fQueuePos = 0;
159     AliRsnEvent *prev = (AliRsnEvent*) fBuffer->At(fQueuePos);
160     if (prev) fBuffer->RemoveAt(fQueuePos);
161     fBuffer->AddAt(event, fQueuePos);
162     
163     return nPairs;
164 }
165
166
167 //_____________________________________________________________________________
168 Stat_t AliRsnManager::Mix(AliRsnEvent *event)
169 {
170 //
171 // Performs event mixing.
172 // It takes the array of fMixPairDefs and stores results in fMixHistograms.
173 // First parameter defines how many events must be mixed with each one.
174 // Events to be mixed are chosen using the other parameters:
175 //
176 // - multDiffMax defines the maximum allowed difference in particle multiplicity,
177 //   a) when last argument is kFALSE (default) the multiplicity comparison is made with respect
178 //      to the particles of 'type 2' in the pair
179 //   b) when last argument is kTRUE, the multiplicity comparison is made with respect of total
180 //      particle multiplicity in the events
181 //
182 // - vzDiffMax defines maximum allowed difference in Z coordinate of prim. vertex.
183 //
184 // If one wants to exchange the particle types, one has to add both combinations of particles
185 // as different pair defs.
186 //
187     Stat_t nPairs = 0;
188
189         if (!fBuffer) {
190         AliError("Uninitialized queue");
191         return 0.0;
192     }
193         
194         // iterator for pairs
195         TObjArrayIter pairIterator(fMixPairs);
196         AliRsnPair *pair = 0;
197         
198         // iterator for events
199         TObjArrayIter eventIterator(fBuffer);
200         AliRsnEvent *mixed = 0;
201             
202     // loop on array and mix with passed event
203     while ( (mixed = (AliRsnEvent*)eventIterator.Next()) ) {
204         if (!CanBeMixed(event, mixed)) continue;
205         pairIterator.Reset();
206         while ( (pair = (AliRsnPair*)pairIterator.Next()) ) {
207             nPairs += pair->Process(event, mixed);
208                 }
209         }
210         
211         return nPairs;
212 }
213
214 //_____________________________________________________________________________
215 Bool_t AliRsnManager::CanBeMixed(AliRsnEvent *ev1, AliRsnEvent *ev2)
216 {
217 //
218 // Checks if two events are within the mixing cuts
219 //
220     
221     Int_t diffMult = TMath::Abs(ev1->GetMultiplicity() - ev2->GetMultiplicity());
222     Bool_t diffVz = TMath::Abs(ev1->GetPrimaryVertexZ() - ev2->GetPrimaryVertexZ());
223     if (diffMult <= fMixMultCut && diffVz <= fMixVzCut) {
224         return kTRUE;
225     }
226     else {
227         return kFALSE;
228     }
229 }