]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisPhiKK.cxx
Add some specific tasks for specific resonances and additional macros
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisPhiKK.cxx
1 //
2 // Class AliRsnAnalysisPhiKK
3 //
4 // Virtual Class derivated from AliRsnVAnalysisTaskSE which will be base class
5 // for all RSN SE tasks
6 //
7 // authors: Martin Vala (martin.vala@cern.ch)
8 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
9 //
10
11 #include <Riostream.h>
12 #include <TList.h>
13
14 #include "AliRsnFunction.h"
15 #include "AliRsnAnalysisPhiKK.h"
16
17 ClassImp(AliRsnAnalysisPhiKK)
18
19 //_____________________________________________________________________________
20 AliRsnAnalysisPhiKK::AliRsnAnalysisPhiKK(const char *name, Bool_t useKine) :
21   AliRsnVAnalysisTaskSE(name, useKine),
22   fGood(0),
23   fMother(),
24   fPairDef(AliPID::kKaon, '+', AliPID::kKaon, '-', 333, 1.019455),
25   fCutEvent(Form("%s_cutEvent", name), AliRsnTarget::kEvent),
26   fCutTrackCommon(Form("%s_cutTrackCom", name), AliRsnTarget::kDaughter),
27   fCutTrackPos(Form("%s_cutTrackPos", name), AliRsnTarget::kDaughter),
28   fCutTrackNeg(Form("%s_cutTrackNeg", name), AliRsnTarget::kDaughter),
29   fCutPair(Form("%s_cutPair", name), AliRsnTarget::kMother),
30   fFuncPM("AliRsnFunction", 0),
31   fFuncPP("AliRsnFunction", 0),
32   fFuncMM("AliRsnFunction", 0),
33   fFuncTrue("AliRsnFunction", 0),
34   fOutList(0x0)
35 {
36 //
37 // Default constructor.
38 // Defines another output slot for histograms/ntuples
39 //
40
41   DefineOutput(2, TList::Class());
42 }
43
44 //_____________________________________________________________________________
45 AliRsnAnalysisPhiKK::AliRsnAnalysisPhiKK(const AliRsnAnalysisPhiKK& copy) :
46   AliRsnVAnalysisTaskSE(copy),
47   fGood(0),
48   fMother(),
49   fPairDef(AliPID::kKaon, '+', AliPID::kKaon, '-', 333, 1.019455),
50   fCutEvent(Form("%s_cutEvent", copy.GetName()), AliRsnTarget::kEvent),
51   fCutTrackCommon(Form("%s_cutTrackCom", copy.GetName()), AliRsnTarget::kDaughter),
52   fCutTrackPos(Form("%s_cutTrackPos", copy.GetName()), AliRsnTarget::kDaughter),
53   fCutTrackNeg(Form("%s_cutTrackNeg", copy.GetName()), AliRsnTarget::kDaughter),
54   fCutPair(Form("%s_cutPair", copy.GetName()), AliRsnTarget::kMother),
55   fFuncPM(copy.fFuncPM),
56   fFuncPP(copy.fFuncPP),
57   fFuncMM(copy.fFuncMM),
58   fFuncTrue(copy.fFuncTrue),
59   fOutList(0x0)
60 {
61 //
62 // Copy constructor.
63 //
64 }
65
66 //_____________________________________________________________________________
67 AliRsnAnalysisPhiKK& AliRsnAnalysisPhiKK::operator=(const AliRsnAnalysisPhiKK& copy)
68 {
69 //
70 // Assigment operator.
71 //
72
73   AliRsnVAnalysisTaskSE::operator=(copy);
74   
75   fFuncPM   = copy.fFuncPM;
76   fFuncPP   = copy.fFuncPP;
77   fFuncMM   = copy.fFuncMM;
78   fFuncTrue = copy.fFuncTrue;
79   
80   fCutEvent       = copy.fCutEvent;
81   fCutTrackCommon = copy.fCutTrackCommon;
82   fCutTrackPos    = copy.fCutTrackPos;
83   fCutTrackNeg    = copy.fCutTrackNeg;
84   fCutPair        = copy.fCutPair;
85   
86   if (fOutList) fOutList->Clear();
87   
88   return (*this);
89 }
90
91 //_____________________________________________________________________________
92 void AliRsnAnalysisPhiKK::AddFunction(AliRsnFunction* const fcn)
93 {
94 //
95 // Adds a new computing function to each collection,
96 // in order to have exactly the sames for each kind of pair.
97 //
98   
99   Int_t size = fFuncPM.GetEntries();
100   
101   new (fFuncPM  [size]) AliRsnFunction(*fcn);
102   new (fFuncPP  [size]) AliRsnFunction(*fcn);
103   new (fFuncMM  [size]) AliRsnFunction(*fcn);
104   new (fFuncTrue[size]) AliRsnFunction(*fcn);
105 }
106
107 //_____________________________________________________________________________
108 void AliRsnAnalysisPhiKK::RsnUserCreateOutputObjects()
109 {
110 //
111 // Creation of output objects.
112 // These are created through the utility methods in the analysis manager,
113 // which asks all the AliRsnPair objects to initialize their output which
114 // is then linked to the TList data member of this, which will contain all the output.
115 //
116
117   if (!fOutList) fOutList = new TList;
118   fOutList->Clear();
119   
120   Int_t   i, j, nFunc = fFuncPM.GetEntries();
121   TString hName(""), suf[4] = {"PM", "PP", "MM", "True"};
122   AliRsnFunction *fcn[4] = {0, 0, 0, 0};
123   
124   for (i = 0; i < nFunc; i++)
125   {
126     fcn[0] = (AliRsnFunction*)fFuncPM.At(i);
127     fcn[1] = (AliRsnFunction*)fFuncPP.At(i);
128     fcn[2] = (AliRsnFunction*)fFuncMM.At(i);
129     fcn[3] = (AliRsnFunction*)fFuncTrue.At(i);
130     for (j = 0; j < 4; j++)
131     {
132       fcn[j]->SetPairDef(&fPairDef);
133       fcn[j]->SetPair(&fMother);
134       
135       hName  = GetName();
136       hName += '_';
137       hName += suf[j];
138       hName += '_';
139       hName += fcn[j]->GetName();
140       if (fcn[j]->IsUsingTH1()) fOutList->Add(fcn[j]->CreateHistogram(hName.Data(), ""));
141       else fOutList->Add(fcn[j]->CreateHistogramSparse(hName.Data(), ""));
142     }
143   }
144
145   PostData(2, fOutList);
146 }
147
148 //_____________________________________________________________________________
149 void AliRsnAnalysisPhiKK::RsnUserExec(Option_t*)
150 {
151 //
152 // Execution of the analysis task.
153 // Recovers the input event and processes it with all included pair objects,
154 // using 'reconstructed' or 'MonteCarlo' functions depending on MC-only flag.
155 //
156
157   // skip if the global event pointers are NULL
158   // and point to first event in the target 
159   AliRsnEvent *event = AliRsnEvent::GetCurrentEvent1();
160   if (!event) return;
161   AliRsnTarget::SwitchToFirst();
162   
163   // select good kaons, applying all cuts
164   Int_t i, index, tot = event->GetAbsoluteSum(), ngood = 0;
165   Bool_t assignOK;
166   AliRsnDaughter::ERefType type;
167   fGood.Set(tot);
168   for (i = 0; i < tot; i++)
169   {
170     // assign track and skip all that are not charged tracks
171     assignOK = event->ConvertAbsoluteIndex(i, index, type);
172     if (!assignOK || type != AliRsnDaughter::kTrack) continue;
173     event->SetDaughter(fDaughter[0], index, AliRsnDaughter::kTrack);
174     
175     // skip tracks which don't pass common cuts
176     if (!fCutTrackCommon.IsSelected(fDaughter)) continue;
177     
178     // accept tracks which pass also charge-related cuts
179     if ((fDaughter[0].Charge() > 0) && (fCutTrackPos.IsSelected(&fDaughter[0])))
180     {
181       fGood[ngood] = index;
182       ++ngood;
183     }
184     else if ((fDaughter[0].Charge() < 0) && (fCutTrackNeg.IsSelected(&fDaughter[0])))
185     {
186       fGood[ngood] = index;
187       ++ngood;
188     }
189   }
190   fGood.Set(ngood);
191   
192   // now that the 'tot' value is useless, set it to
193   // the total number of functions, which by construction is THE SAME
194   // for all collections
195   tot = fFuncPM.GetEntries();
196   
197   // loop on selected tracks and fill histograms
198   Int_t i0, i1, m0, m1, motherPDG;
199   const Double_t  kaonMass = 0.493677;
200   const Int_t     phiPDG   = 333;
201   const Int_t     kaonPDG  = 313;
202   AliRsnFunction *fcn;
203   for (i0 = 0; i0 < ngood; i0++)
204   {
205     index = fGood[i0];
206     event->SetDaughter(fDaughter[0], index, AliRsnDaughter::kTrack);
207     
208     for (i1 = i0 + 1; i1 < ngood; i1++)
209     {
210       index = fGood[i1];
211       event->SetDaughter(fDaughter[1], index, AliRsnDaughter::kTrack);
212       
213       // skip in case the two indexes match
214       if (fDaughter[0].GetID() == fDaughter[1].GetID()) continue;
215       
216       // adjust charges of pair def
217       fPairDef.SetDaughters(AliPID::kKaon, fDaughter[0].ChargeChar(), AliPID::kKaon, fDaughter[1].ChargeChar());
218     
219       // fill the pair using the kaon masses and the passed daughters
220       fMother.SetDaughters(&fDaughter[0], kaonMass, &fDaughter[1], kaonMass);
221       
222       // check pair cuts
223       if (!fCutPair.IsSelected(&fMother)) continue;
224       
225       // if pair is like-sign, fill appropriate histos
226       if (fPairDef.IsLikeSign())
227       {
228         if (fDaughter[0].Charge() > 0)
229         {
230           for (i = 0; i < tot; i++)
231           {
232             fcn = (AliRsnFunction*)fFuncPP[i];
233             fcn->Fill();
234           }
235         }
236         else
237         {
238           for (i = 0; i < tot; i++)
239           {
240             fcn = (AliRsnFunction*)fFuncMM[i];
241             fcn->Fill();
242           }
243         }
244       }
245       else
246       {
247         // if pair is unlike-sign, check that it is true
248         motherPDG = fMother.CommonMother(m0, m1);
249         if (motherPDG == phiPDG)
250         {
251           if (m0 < 0 || m1 < 0) motherPDG = 0;
252           if (TMath::Abs(fDaughter[0].GetPDG()) != kaonPDG) motherPDG = 0;
253           if (TMath::Abs(fDaughter[1].GetPDG()) != kaonPDG) motherPDG = 0;
254         }
255         
256         // fill unlike-sign histo
257         for (i = 0; i < tot; i++)
258         {
259           fcn = (AliRsnFunction*)fFuncPM[i];
260           fcn->Fill();
261           if (motherPDG == phiPDG)
262           {
263             fcn = (AliRsnFunction*)fFuncTrue[i];
264             fcn->Fill();
265           }
266         }
267       }
268     } // for (i1)
269   } // for (i0)
270   
271   PostData(2, fOutList);
272 }
273
274 //_____________________________________________________________________________
275 void AliRsnAnalysisPhiKK::RsnTerminate(Option_t*)
276 {
277 //
278 // Termination.
279 // Could be added some monitor histograms here.
280 //
281 }
282
283 //______________________________________________________________________________
284 Bool_t AliRsnAnalysisPhiKK::EventProcess()
285 {
286 //
287 // Customized event pre-processing.
288 // First checks if the current event passes all cuts,
289 // and if it does, updates the informations and then
290 // call the operations which are already defined in the
291 // omonyme function in mother class
292 //
293
294   // initially, an event is expected to be bad
295   fTaskInfo.SetEventUsed(kFALSE);
296   
297   // check #1: number of tracks in event (reject empty events)
298   Int_t ntracks = fRsnEvent.GetMultiplicity();
299   if (ntracks < 1) 
300   {
301     // empty events are rejected by default
302     fTaskInfo.SetEventUsed(kFALSE);
303     AliDebug(AliLog::kDebug, "Empty event. Skipping...");
304     return kFALSE;
305   }
306
307   // check the event cuts and update the info data accordingly
308   // events not passing the cuts must be rejected
309   if (!fCutEvent.IsSelected(&fRsnEvent))
310   {
311     fTaskInfo.SetEventUsed(kFALSE);
312     return kFALSE;
313   }
314   
315   // if we reach this point, cuts were passed;
316   // then additional operations can be done
317   
318   // find leading particle (without any PID/momentum restriction)
319   fRsnEvent.SelectLeadingParticle(0);
320   
321   // final return value is positive
322   // but call the mother class method which updates info object
323   fTaskInfo.SetEventUsed(kTRUE);
324   return AliRsnVAnalysisTaskSE::EventProcess();
325 }