]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muon/AliAnalysisMuMuCutCombination.cxx
Coverity fixes (Laurent)
[u/mrichter/AliRoot.git] / PWG / muon / AliAnalysisMuMuCutCombination.cxx
1 #include "AliAnalysisMuMuCutCombination.h"
2
3 /**
4  *
5  * \ingroup pwg-muon-mumu
6  *
7  * \class AliAnalysisMuMuCutCombination
8  *
9  * A cut combination is the real cut class that is used in the sub-analysis. It is composed
10  * of one or several AliAnalysisMuMuCutElement.
11  *
12  * Unlike the cut elements, it can be of several types at the same time (i.e. it can
13  * be an event cutter and a track cutter for instance). The work is done in the
14  * Pass method(s).
15  *
16  */
17
18 #include "AliAnalysisMuMuCutElement.h"
19 #include "TList.h"
20 #include "Riostream.h"
21 #include "AliInputEventHandler.h"
22 #include "AliLog.h"
23
24 ClassImp(AliAnalysisMuMuCutCombination)
25
26 //_____________________________________________________________________________
27 AliAnalysisMuMuCutCombination::AliAnalysisMuMuCutCombination()
28 : TObject(), fCuts(0x0), fName(""),
29 fIsEventCutter(kFALSE), fIsEventHandlerCutter(kFALSE),
30 fIsTrackCutter(kFALSE), fIsTrackPairCutter(kFALSE),
31 fIsTriggerClassCutter(kFALSE)
32 {
33   /// Default ctor.
34 }
35
36 //_____________________________________________________________________________
37 AliAnalysisMuMuCutCombination::~AliAnalysisMuMuCutCombination()
38 {
39   /// Dtor
40   delete fCuts;
41 }
42   
43 //_____________________________________________________________________________
44 void AliAnalysisMuMuCutCombination::Add(AliAnalysisMuMuCutElement* ce)
45 {
46   /** Add a cut element to this combination, if the cut is not void and
47    *  not already part of the combination
48    */
49   
50   if (!ce || !ce->IsValid()) return;
51   
52   if (!fCuts)
53   {
54     fCuts = new TObjArray;
55     fCuts->SetOwner(kFALSE);
56     fIsEventCutter = ce->IsEventCutter();
57     fIsEventHandlerCutter = ce->IsEventHandlerCutter();
58     fIsTrackCutter = ce->IsTrackCutter();
59     fIsTrackPairCutter = ce->IsTrackPairCutter();
60     fIsTriggerClassCutter = ce->IsTriggerClassCutter();
61   }
62   
63   if (!fCuts->FindObject(ce))
64   {
65     fCuts->Add(ce);
66     fName += ce->GetName();
67     
68     fIsEventCutter = fIsEventCutter || ce->IsEventCutter();
69     fIsEventHandlerCutter = fIsEventHandlerCutter || ce->IsEventHandlerCutter();
70     fIsTrackCutter = fIsTrackCutter || ce->IsTrackCutter();
71     fIsTrackPairCutter = fIsTrackPairCutter || ce->IsTrackPairCutter();
72     fIsTriggerClassCutter = fIsTriggerClassCutter || ce->IsTriggerClassCutter();
73
74   }
75   
76   // update the name
77   
78   if ( IsTrackPairCutter() )
79   {
80     if ( fName[0] == 's' )
81     {
82       fName[0] = 'p';
83     }
84     else if ( fName[0] == 'p')
85     {
86       // already ok
87     }
88     else
89     {
90       TString tmp = fName;
91       fName = "p";
92       fName += tmp;
93     }
94   }
95   else if ( IsTrackCutter() )
96   {
97     if ( fName[0] == 's')
98     {
99       // already ok
100     }
101     else
102     {
103       TString tmp = fName;
104       fName = "s";
105       fName += tmp;
106     }
107   }
108 }
109
110 //_____________________________________________________________________________
111 Bool_t AliAnalysisMuMuCutCombination::IsEqual(const TObject* obj) const
112 {
113   /// Whether or not we are the same cut combination as obj
114   
115   if ( obj->IsA() != AliAnalysisMuMuCutCombination::Class() )
116   {
117     return kFALSE;
118   }
119   
120   const AliAnalysisMuMuCutCombination* other = static_cast<const AliAnalysisMuMuCutCombination*>(obj);
121
122   if ( IsEventCutter() != other->IsEventCutter() ) return kFALSE;
123   if ( IsTrackCutter() != other->IsTrackCutter() ) return kFALSE;
124   if ( IsTrackPairCutter() != other->IsTrackPairCutter() ) return kFALSE;
125   if ( IsTriggerClassCutter() != other->IsTriggerClassCutter() ) return kFALSE;
126
127   if ( !fCuts && !other->fCuts ) return kTRUE;
128
129   // no cuts, nothing to check further...
130   
131   if ( ( fCuts && !other->fCuts ) || ( !fCuts && other->fCuts ) ) return kFALSE;
132   
133   if ( fCuts->GetEntries() != other->fCuts->GetEntries() ) return kFALSE;
134   
135   // ok, looks similar so far, now have compute the set of cuts in common
136   // (whatever the order) to see if they really are the same combination or not
137   
138   Int_t n1in2(0);
139   Int_t n2in1(0);
140   
141   for ( Int_t i = 0; i <= fCuts->GetLast(); ++i )
142   {
143     AliAnalysisMuMuCutElement* thisCuti = static_cast<AliAnalysisMuMuCutElement*>(fCuts->At(i));
144   
145     if ( other->fCuts->FindObject(thisCuti) )
146     {
147       ++n1in2;
148     }
149   }
150
151   for ( Int_t i = 0; i <= fCuts->GetLast(); ++i )
152   {
153     AliAnalysisMuMuCutElement* otherCuti = static_cast<AliAnalysisMuMuCutElement*>(other->fCuts->At(i));
154     
155     if ( fCuts->FindObject(otherCuti) )
156     {
157       ++n2in1;
158     }
159   }
160
161   return (n1in2==n2in1 && n1in2==fCuts->GetLast()+1);
162 }
163
164 //_____________________________________________________________________________
165 Bool_t AliAnalysisMuMuCutCombination::Pass(const AliInputEventHandler& eventHandler) const
166 {
167   /// Whether or not the event handler is passing the cut
168   
169   if (!fCuts) return kFALSE;
170   TIter next(fCuts);
171   AliAnalysisMuMuCutElement* ce;
172   
173   const AliVEvent* event = eventHandler.GetEvent();
174   
175   Bool_t passEvent(kTRUE);
176   Bool_t passEventHandler(kTRUE);
177   
178   while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
179   {
180     if ( ce->IsEventCutter() && !ce->Pass(*event) )
181     {
182       passEvent = kFALSE;
183     }
184
185     if ( ce->IsEventHandlerCutter() && !ce->Pass(eventHandler) )
186     {
187       passEventHandler = kFALSE;
188     }
189   }
190   
191   if ( IsEventCutter() && IsEventHandlerCutter() )
192   {
193     return passEvent && passEventHandler;
194   }
195
196   if ( IsEventHandlerCutter() )
197   {
198     return passEventHandler;
199   }
200
201   if ( IsEventCutter() )
202   {
203     return passEvent;
204   }
205   
206   return kFALSE;
207 }
208   
209
210 //_____________________________________________________________________________
211 Bool_t AliAnalysisMuMuCutCombination::Pass(const AliVParticle& particle) const
212 {
213   /// Whether or not the particle is passing the cut
214
215   if (!fCuts) return kFALSE;
216   TIter next(fCuts);
217   AliAnalysisMuMuCutElement* ce;
218   
219   while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
220   {
221     if (ce->IsTrackCutter() && !ce->Pass(particle))
222     {
223       return kFALSE;
224     }
225   }
226
227   return kTRUE;
228 }
229   
230 //_____________________________________________________________________________
231 Bool_t AliAnalysisMuMuCutCombination::Pass(const AliVParticle& p1, const AliVParticle& p2) const
232 {
233   /// Whether or not the particle pair is passing the cut
234
235   if (!fCuts) return kFALSE;
236   TIter next(fCuts);
237   AliAnalysisMuMuCutElement* ce;
238   
239   while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
240   {
241     if (ce->IsTrackPairCutter() && !ce->Pass(p1,p2))
242     {
243       return kFALSE;
244     }
245   }
246   
247   return kTRUE;
248 }
249
250 //_____________________________________________________________________________
251 Bool_t AliAnalysisMuMuCutCombination::Pass(const TString& firedTriggerClasses,
252                                            TString& acceptedTriggerClasses,
253                                            UInt_t L0, UInt_t L1, UInt_t L2) const
254 {
255   /** Whether or not the firedTriggerClasses pass the cut.
256    * \param firedTriggerClasses (input) list of fired trigger classes (separated by space)
257    * \param acceptedTriggerClasses (output) list of accepted classes
258    * \param L0 (input, optional) level 0 trigger mask
259    * \param L1 (input, optional) level 1 trigger mask
260    * \param L2 (input, optional) level 2 trigger mask
261    */
262
263   if (!fCuts) return kFALSE;
264   TIter next(fCuts);
265   AliAnalysisMuMuCutElement* ce;
266   Bool_t rv(kFALSE);
267   
268   // contrary to the other cut types, here we make a full loop on all
269   // the cuts, as we need to give each cut a chance to update the acceptedTriggerClasses
270   // string
271   
272   acceptedTriggerClasses = "";
273   
274   while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
275   {
276     TString tmp;
277     
278     if (ce->IsTriggerClassCutter() && ce->Pass(firedTriggerClasses,tmp,L0,L1,L2))
279     {
280       acceptedTriggerClasses += tmp;
281       acceptedTriggerClasses += " ";
282       rv = kTRUE;
283     }
284   }
285   
286   return rv;
287 }
288
289 //_____________________________________________________________________________
290 void AliAnalysisMuMuCutCombination::Print(Option_t* space) const
291 {
292   /// Printout of the cut combination
293   std::cout << Form("%s(%p) [",GetName(),this);
294   if ( IsEventCutter() ) std::cout << " E";
295   if ( IsEventHandlerCutter() ) std::cout << " EH";
296   if ( IsTrackCutter() ) std::cout << " T";
297   if ( IsTrackPairCutter() ) std::cout << " TP";
298   if ( IsTriggerClassCutter() ) std::cout << " TC";
299   std::cout << " ]" << std::endl;
300   
301   TIter next(fCuts);
302   AliAnalysisMuMuCutElement* ce;
303   
304   while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
305   {
306     std::cout << space;
307     ce->Print();
308   }
309 }
310