3 // All the definitions needed for building a RSN histogram
5 // -- properties of resonance (mass, PDG code if needed)
6 // -- properties of daughters (assigned mass, charges)
7 // -- definition of output histogram
10 #include "Riostream.h"
17 #include "THnSparse.h"
19 #include "TClonesArray.h"
21 #include "AliRsnMiniParticle.h"
22 #include "AliRsnMiniPair.h"
23 #include "AliRsnMiniEvent.h"
26 #include "AliRsnCutSet.h"
27 #include "AliRsnMiniAxis.h"
28 #include "AliRsnMiniOutput.h"
29 #include "AliRsnMiniValue.h"
31 ClassImp(AliRsnMiniOutput)
33 //__________________________________________________________________________________________________
34 AliRsnMiniOutput::AliRsnMiniOutput() :
37 fComputation(kComputations),
42 fAxes("AliRsnMiniAxis", 0),
53 fCutID[0] = fCutID[1] = -1;
54 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
55 fCharge[0] = fCharge[1] = 0;
58 //__________________________________________________________________________________________________
59 AliRsnMiniOutput::AliRsnMiniOutput(const char *name, EOutputType type, EComputation src) :
67 fAxes("AliRsnMiniAxis", 0),
78 fCutID[0] = fCutID[1] = -1;
79 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
80 fCharge[0] = fCharge[1] = 0;
83 //__________________________________________________________________________________________________
84 AliRsnMiniOutput::AliRsnMiniOutput(const char *name, const char *outType, const char *compType) :
87 fComputation(kComputations),
92 fAxes("AliRsnMiniAxis", 0),
100 // Constructor, with a more user friendly implementation, where
101 // the user sets the type of output and computations through conventional strings:
104 // -- "HIST" --> common histogram (up to 3 dimensions)
105 // -- "SPARSE" --> sparse histogram
108 // -- "EVENT" --> event-only computations
109 // -- "PAIR" --> track pair computations (default)
110 // -- "MIX" --> event mixing (like track pair, but different events)
111 // -- "ROTATE1" --> rotated background (rotate first track)
112 // -- "ROTATE2" --> rotated background (rotate second track)
113 // -- "TRUE" --> true pairs (like track pair, but checking that come from same mother)
114 // -- "MOTHER" --> mother (loop on MC directly for mothers --> denominator of efficiency)
119 // understand output type
122 if (!input.CompareTo("HIST"))
123 fOutputType = kHistogram;
124 else if (!input.CompareTo("SPARSE"))
125 fOutputType = kHistogramSparse;
127 AliWarning(Form("String '%s' does not define a meaningful output type", outType));
129 // understand computation type
132 if (!input.CompareTo("EVENT"))
133 fComputation = kEventOnly;
134 else if (!input.CompareTo("PAIR"))
135 fComputation = kTrackPair;
136 else if (!input.CompareTo("MIX"))
137 fComputation = kTrackPairMix;
138 else if (!input.CompareTo("ROTATE1"))
139 fComputation = kTrackPairRotated1;
140 else if (!input.CompareTo("ROTATE2"))
141 fComputation = kTrackPairRotated2;
142 else if (!input.CompareTo("TRUE"))
143 fComputation = kTruePair;
144 else if (!input.CompareTo("MOTHER"))
145 fComputation = kMother;
147 AliWarning(Form("String '%s' does not define a meaningful computation type", compType));
149 fCutID[0] = fCutID[1] = -1;
150 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
151 fCharge[0] = fCharge[1] = 0;
154 //__________________________________________________________________________________________________
155 AliRsnMiniOutput::AliRsnMiniOutput(const AliRsnMiniOutput ©) :
157 fOutputType(copy.fOutputType),
158 fComputation(copy.fComputation),
159 fMotherPDG(copy.fMotherPDG),
160 fMotherMass(copy.fMotherMass),
161 fPairCuts(copy.fPairCuts),
162 fOutputID(copy.fOutputID),
164 fComputed(copy.fComputed),
175 for (i = 0; i < 2; i++) {
176 fCutID[i] = copy.fCutID[i];
177 fDaughter[i] = copy.fDaughter[i];
178 fCharge[i] = copy.fCharge[i];
182 //__________________________________________________________________________________________________
183 AliRsnMiniOutput &AliRsnMiniOutput::operator=(const AliRsnMiniOutput ©)
186 // Assignment operator
190 fOutputType = copy.fOutputType;
191 fComputation = copy.fComputation;
192 fMotherPDG = copy.fMotherPDG;
193 fMotherMass = copy.fMotherMass;
194 fPairCuts = copy.fPairCuts;
195 fOutputID = copy.fOutputID;
197 fComputed = copy.fComputed;
201 for (i = 0; i < 2; i++) {
202 fCutID[i] = copy.fCutID[i];
203 fDaughter[i] = copy.fDaughter[i];
204 fCharge[i] = copy.fCharge[i];
214 //__________________________________________________________________________________________________
215 void AliRsnMiniOutput::AddAxis(Int_t i, Int_t nbins, Double_t min, Double_t max)
218 // Create a new axis reference
221 Int_t size = fAxes.GetEntries();
222 new (fAxes[size]) AliRsnMiniAxis(i, nbins, min, max);
225 //__________________________________________________________________________________________________
226 void AliRsnMiniOutput::AddAxis(Int_t i, Double_t min, Double_t max, Double_t step)
229 // Create a new axis reference
232 Int_t size = fAxes.GetEntries();
233 new (fAxes[size]) AliRsnMiniAxis(i, min, max, step);
236 //__________________________________________________________________________________________________
237 void AliRsnMiniOutput::AddAxis(Int_t i, Int_t nbins, Double_t *values)
240 // Create a new axis reference
243 Int_t size = fAxes.GetEntries();
244 new (fAxes[size]) AliRsnMiniAxis(i, nbins, values);
247 //__________________________________________________________________________________________________
248 Bool_t AliRsnMiniOutput::Init(const char *prefix, TList *list)
251 // Initialize properly the histogram and add it to the argument list
255 AliError("Required an output list");
260 Int_t size = fAxes.GetEntries();
262 AliWarning(Form("[%s] Cannot initialize histogram with less than 1 axis", GetName()));
266 switch (fOutputType) {
269 CreateHistogram(Form("%s_%s", prefix, GetName()));
271 AliInfo(Form("[%s] Added %d > 3 axes. Creating a sparse histogram", GetName(), size));
272 fOutputType = kHistogramSparse;
273 CreateHistogramSparse(Form("%s_%s", prefix, GetName()));
276 case kHistogramSparse:
277 CreateHistogramSparse(Form("%s_%s", prefix, GetName()));
280 AliError("Wrong output histogram definition");
285 //__________________________________________________________________________________________________
286 void AliRsnMiniOutput::CreateHistogram(const char *name)
289 // Initialize the 'default' TH1 output object.
290 // In case one of the expected axes is NULL, the initialization fails.
293 Int_t size = fAxes.GetEntries();
294 AliInfo(Form("Histogram name = '%s', with %d axes", name, size));
296 // we expect to have maximum 3 axes in this case
297 AliRsnMiniAxis *xAxis = 0x0, *yAxis = 0x0, *zAxis = 0x0;
298 if (size >= 1) xAxis = (AliRsnMiniAxis *)fAxes[0];
299 if (size >= 2) yAxis = (AliRsnMiniAxis *)fAxes[1];
300 if (size >= 3) zAxis = (AliRsnMiniAxis *)fAxes[2];
302 // create histogram depending on the number of axes
304 if (xAxis && yAxis && zAxis) {
305 h1 = new TH3F(name, "", xAxis->NBins(), xAxis->BinArray(), yAxis->NBins(), yAxis->BinArray(), zAxis->NBins(), zAxis->BinArray());
306 } else if (xAxis && yAxis) {
307 h1 = new TH2F(name, "", xAxis->NBins(), xAxis->BinArray(), yAxis->NBins(), yAxis->BinArray());
309 h1 = new TH1F(name, "", xAxis->NBins(), xAxis->BinArray());
311 AliError("No axis was initialized");
315 // switch the correct computation of errors
319 fOutputID = fList->IndexOf(h1);
323 //________________________________________________________________________________________
324 void AliRsnMiniOutput::CreateHistogramSparse(const char *name)
327 // Initialize the THnSparse output object.
328 // In case one of the expected axes is NULL, the initialization fails.
331 Int_t size = fAxes.GetEntries();
332 AliInfo(Form("Sparse histogram name = '%s', with %d axes", name, size));
334 // retrieve binnings and sizes of all axes
335 // since the check for null values is done in Init(),
336 // we assume that here they must all be well defined
337 Int_t i, *nbins = new Int_t[size];
338 for (i = 0; i < size; i++) {
339 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
340 nbins[i] = axis->NBins();
343 // create fHSparseogram
344 THnSparseF *h1 = new THnSparseF(name, "", size, nbins);
346 // update the various axes using the definitions given in the array of axes here
347 for (i = 0; i < size; i++) {
348 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
349 h1->GetAxis(i)->Set(nbins[i], axis->BinArray());
359 fOutputID = fList->IndexOf(h1);
363 //________________________________________________________________________________________
364 Bool_t AliRsnMiniOutput::FillEvent(AliRsnMiniEvent *event, TClonesArray *valueList)
367 // Compute values for event-based computations (does not use the pair)
370 // check computation type
371 if (fComputation != kEventOnly) {
372 AliError("This method can be called only for event-based computations");
377 ComputeValues(event, valueList);
382 //________________________________________________________________________________________
383 Bool_t AliRsnMiniOutput::FillMother(const AliRsnMiniPair *pair, AliRsnMiniEvent *event, TClonesArray *valueList)
386 // Compute values for mother-based computations
389 // check computation type
390 if (fComputation != kMother) {
391 AliError("This method can be called only for mother-based computations");
395 // copy passed pair info
398 // check pair against cuts
399 if (fPairCuts) if (!fPairCuts->IsSelected(&fPair)) return kFALSE;
402 ComputeValues(event, valueList);
407 //________________________________________________________________________________________
408 Int_t AliRsnMiniOutput::FillPair(AliRsnMiniEvent *event1, AliRsnMiniEvent *event2, TClonesArray *valueList, Bool_t refFirst)
411 // Loops on the passed mini-event, and for each pair of particles
412 // which satisfy the charge and cut requirements defined here, add an entry.
413 // Returns the number of successful fillings.
414 // Last argument tells if the reference event for event-based values is the first or the second.
417 // check computation type
418 Bool_t okComp = kFALSE;
419 if (fComputation == kTrackPair) okComp = kTRUE;
420 if (fComputation == kTrackPairMix) okComp = kTRUE;
421 if (fComputation == kTrackPairRotated1) okComp = kTRUE;
422 if (fComputation == kTrackPairRotated2) okComp = kTRUE;
423 if (fComputation == kTruePair) okComp = kTRUE;
425 AliError(Form("[%s] This method can be called only for pair-based computations", GetName()));
430 Int_t i1, i2, start, nadded = 0;
431 AliRsnMiniParticle *p1, *p2;
433 // it is necessary to know if criteria for the two daughters are the same
434 // and if the two events are the same or not (mixing)
435 //Bool_t sameCriteria = ((fCharge[0] == fCharge[1]) && (fCutID[0] == fCutID[1]));
436 Bool_t sameCriteria = ((fCharge[0] == fCharge[1]) && (fDaughter[0] == fDaughter[1]));
437 Bool_t sameEvent = (event1->ID() == event2->ID());
439 TString selList1 = "";
440 TString selList2 = "";
441 Int_t n1 = event1->CountParticles(fSel1, fCharge[0], fCutID[0]);
442 Int_t n2 = event2->CountParticles(fSel2, fCharge[1], fCutID[1]);
443 for (i1 = 0; i1 < n1; i1++) selList1.Append(Form("%d ", fSel1[i1]));
444 for (i2 = 0; i2 < n2; i2++) selList2.Append(Form("%d ", fSel2[i2]));
445 AliDebugClass(1, Form("[%10s] Part #1: [%s] -- evID %6d -- charge = %c -- cut ID = %d --> %4d tracks (%s)", GetName(), (event1 == event2 ? "def" : "mix"), event1->ID(), fCharge[0], fCutID[0], n1, selList1.Data()));
446 AliDebugClass(1, Form("[%10s] Part #2: [%s] -- evID %6d -- charge = %c -- cut ID = %d --> %4d tracks (%s)", GetName(), (event1 == event2 ? "def" : "mix"), event2->ID(), fCharge[1], fCutID[1], n2, selList2.Data()));
448 AliDebugClass(1, "No pairs to mix");
453 for (i1 = 0; i1 < n1; i1++) {
454 p1 = event1->GetParticle(fSel1[i1]);
455 //p1 = event1->GetParticle(i1);
456 //if (p1->Charge() != fCharge[0]) continue;
457 //if (!p1->HasCutBit(fCutID[0])) continue;
458 // define starting point for inner loop
459 // if daughter selection criteria (charge, cuts) are the same
460 // and the two events coincide, internal loop must start from
461 // the first track *after* current one;
462 // otherwise it starts from the beginning
463 start = ((sameEvent && sameCriteria) ? i1 + 1 : 0);
464 AliDebugClass(2, Form("Start point = %d", start));
466 for (i2 = start; i2 < n2; i2++) {
467 p2 = event2->GetParticle(fSel2[i2]);
468 //p2 = event2->GetParticle(i2);
469 //if (p2->Charge() != fCharge[1]) continue;
470 //if (!p2->HasCutBit(fCutID[1])) continue;
471 // avoid to mix a particle with itself
472 if (sameEvent && (p1->Index() == p2->Index())) {
473 AliDebugClass(2, "Skipping same index");
477 fPair.Fill(p1, p2, GetMass(0), GetMass(1), fMotherMass);
478 // do rotation if needed
479 if (fComputation == kTrackPairRotated1) fPair.InvertP(kTRUE);
480 if (fComputation == kTrackPairRotated2) fPair.InvertP(kFALSE);
481 // if required, check that this is a true pair
482 if (fComputation == kTruePair) {
483 if (fPair.Mother() < 0) {
485 } else if (TMath::Abs(fPair.MotherPDG()) != fMotherPDG) {
488 Bool_t decayMatch = kFALSE;
489 if (p1->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[0]) && p2->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[1]))
491 if (p2->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[0]) && p1->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[1]))
493 if (!decayMatch) continue;
495 // check pair against cuts
497 if (!fPairCuts->IsSelected(&fPair)) continue;
499 // get computed values & fill histogram
501 if (refFirst) ComputeValues(event1, valueList); else ComputeValues(event2, valueList);
503 } // end internal loop
504 } // end external loop
506 AliDebugClass(1, Form("Pairs added in total = %4d", nadded));
510 //________________________________________________________________________________________
511 void AliRsnMiniOutput::ComputeValues(AliRsnMiniEvent *event, TClonesArray *valueList)
514 // Using the arguments and the internal 'fPair' data member,
515 // compute all values to be stored in the histogram
518 // check size of computed array
519 Int_t size = fAxes.GetEntries();
520 if (fComputed.GetSize() != size) fComputed.Set(size);
522 Int_t i, ival, nval = valueList->GetEntries();
524 for (i = 0; i < size; i++) {
526 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
528 AliError("Null axis");
531 ival = axis->GetValueID();
532 if (ival < 0 || ival >= nval) {
533 AliError(Form("Required value #%d, while maximum is %d", ival, nval));
536 AliRsnMiniValue *val = (AliRsnMiniValue *)valueList->At(ival);
538 AliError(Form("Value in position #%d is NULL", ival));
541 // if none of the above exit points is taken, compute value
542 fComputed[i] = val->Eval(&fPair, event);
546 //________________________________________________________________________________________
547 void AliRsnMiniOutput::FillHistogram()
550 // Fills the internal histogram using the current values stored in the
551 // 'fComputed' array, in the order as they are stored, up to the max
552 // dimension of the initialized histogram itself.
555 // retrieve object from list
557 AliError("List pointer is NULL");
560 TObject *obj = fList->At(fOutputID);
562 if (obj->InheritsFrom(TH1F::Class())) {
563 ((TH1F *)obj)->Fill(fComputed[0]);
564 } else if (obj->InheritsFrom(TH2F::Class())) {
565 ((TH2F *)obj)->Fill(fComputed[0], fComputed[1]);
566 } else if (obj->InheritsFrom(TH3F::Class())) {
567 ((TH3F *)obj)->Fill(fComputed[0], fComputed[1], fComputed[2]);
568 } else if (obj->InheritsFrom(THnSparseF::Class())) {
569 ((THnSparseF *)obj)->Fill(fComputed.GetArray());
571 AliError("No output initialized");