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"
24 #include "AliAODEvent.h"
27 #include "AliRsnCutSet.h"
28 #include "AliRsnMiniAxis.h"
29 #include "AliRsnMiniOutput.h"
30 #include "AliRsnMiniValue.h"
32 ClassImp(AliRsnMiniOutput)
34 //__________________________________________________________________________________________________
35 AliRsnMiniOutput::AliRsnMiniOutput() :
38 fComputation(kComputations),
43 fAxes("AliRsnMiniAxis", 0),
51 fCheckFeedDown(kFALSE),
52 fOriginDselection(kFALSE),
54 fKeepDfromBOnly(kFALSE),
55 fRejectIfNoQuark(kFALSE),
56 fCheckHistRange(kTRUE)
62 fCutID[0] = fCutID[1] = -1;
63 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
64 fCharge[0] = fCharge[1] = 0;
67 //__________________________________________________________________________________________________
68 AliRsnMiniOutput::AliRsnMiniOutput(const char *name, EOutputType type, EComputation src) :
76 fAxes("AliRsnMiniAxis", 0),
84 fCheckFeedDown(kFALSE),
85 fOriginDselection(kFALSE),
87 fKeepDfromBOnly(kFALSE),
88 fRejectIfNoQuark(kFALSE),
89 fCheckHistRange(kTRUE)
95 fCutID[0] = fCutID[1] = -1;
96 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
97 fCharge[0] = fCharge[1] = 0;
100 //__________________________________________________________________________________________________
101 AliRsnMiniOutput::AliRsnMiniOutput(const char *name, const char *outType, const char *compType) :
104 fComputation(kComputations),
109 fAxes("AliRsnMiniAxis", 0),
117 fCheckFeedDown(kFALSE),
118 fOriginDselection(kFALSE),
120 fKeepDfromBOnly(kFALSE),
121 fRejectIfNoQuark(kFALSE),
122 fCheckHistRange(kTRUE)
125 // Constructor, with a more user friendly implementation, where
126 // the user sets the type of output and computations through conventional strings:
129 // -- "HIST" --> common histogram (up to 3 dimensions)
130 // -- "SPARSE" --> sparse histogram
133 // -- "EVENT" --> event-only computations
134 // -- "PAIR" --> track pair computations (default)
135 // -- "MIX" --> event mixing (like track pair, but different events)
136 // -- "ROTATE1" --> rotated background (rotate first track)
137 // -- "ROTATE2" --> rotated background (rotate second track)
138 // -- "TRUE" --> true pairs (like track pair, but checking that come from same mother)
139 // -- "MOTHER" --> mother (loop on MC directly for mothers --> denominator of efficiency)
144 // understand output type
147 if (!input.CompareTo("HIST"))
148 fOutputType = kHistogram;
149 else if (!input.CompareTo("SPARSE"))
150 fOutputType = kHistogramSparse;
152 AliWarning(Form("String '%s' does not define a meaningful output type", outType));
154 // understand computation type
157 if (!input.CompareTo("EVENT"))
158 fComputation = kEventOnly;
159 else if (!input.CompareTo("PAIR"))
160 fComputation = kTrackPair;
161 else if (!input.CompareTo("MIX"))
162 fComputation = kTrackPairMix;
163 else if (!input.CompareTo("ROTATE1"))
164 fComputation = kTrackPairRotated1;
165 else if (!input.CompareTo("ROTATE2"))
166 fComputation = kTrackPairRotated2;
167 else if (!input.CompareTo("TRUE"))
168 fComputation = kTruePair;
169 else if (!input.CompareTo("MOTHER"))
170 fComputation = kMother;
172 AliWarning(Form("String '%s' does not define a meaningful computation type", compType));
174 fCutID[0] = fCutID[1] = -1;
175 fDaughter[0] = fDaughter[1] = AliRsnDaughter::kUnknown;
176 fCharge[0] = fCharge[1] = 0;
179 //__________________________________________________________________________________________________
180 AliRsnMiniOutput::AliRsnMiniOutput(const AliRsnMiniOutput ©) :
182 fOutputType(copy.fOutputType),
183 fComputation(copy.fComputation),
184 fMotherPDG(copy.fMotherPDG),
185 fMotherMass(copy.fMotherMass),
186 fPairCuts(copy.fPairCuts),
187 fOutputID(copy.fOutputID),
189 fComputed(copy.fComputed),
196 fCheckFeedDown(kFALSE),
197 fOriginDselection(kFALSE),
199 fKeepDfromBOnly(kFALSE),
200 fRejectIfNoQuark(kFALSE),
201 fCheckHistRange(copy.fCheckHistRange)
208 for (i = 0; i < 2; i++) {
209 fCutID[i] = copy.fCutID[i];
210 fDaughter[i] = copy.fDaughter[i];
211 fCharge[i] = copy.fCharge[i];
215 //__________________________________________________________________________________________________
216 AliRsnMiniOutput &AliRsnMiniOutput::operator=(const AliRsnMiniOutput ©)
219 // Assignment operator
223 fOutputType = copy.fOutputType;
224 fComputation = copy.fComputation;
225 fMotherPDG = copy.fMotherPDG;
226 fMotherMass = copy.fMotherMass;
227 fPairCuts = copy.fPairCuts;
228 fOutputID = copy.fOutputID;
230 fComputed = copy.fComputed;
234 for (i = 0; i < 2; i++) {
235 fCutID[i] = copy.fCutID[i];
236 fDaughter[i] = copy.fDaughter[i];
237 fCharge[i] = copy.fCharge[i];
242 fMaxNSisters = copy.fMaxNSisters;
243 fCheckP = copy.fCheckP;
244 fCheckFeedDown = copy.fCheckFeedDown;
245 fOriginDselection = copy.fOriginDselection;
246 fKeepDfromB = copy.fOriginDselection;
247 fKeepDfromBOnly = copy.fKeepDfromBOnly;
248 fRejectIfNoQuark = copy.fRejectIfNoQuark;
249 fCheckHistRange = copy.fCheckHistRange;
255 //__________________________________________________________________________________________________
256 void AliRsnMiniOutput::AddAxis(Int_t i, Int_t nbins, Double_t min, Double_t max)
259 // Create a new axis reference
262 Int_t size = fAxes.GetEntries();
263 new (fAxes[size]) AliRsnMiniAxis(i, nbins, min, max);
266 //__________________________________________________________________________________________________
267 void AliRsnMiniOutput::AddAxis(Int_t i, Double_t min, Double_t max, Double_t step)
270 // Create a new axis reference
273 Int_t size = fAxes.GetEntries();
274 new (fAxes[size]) AliRsnMiniAxis(i, min, max, step);
277 //__________________________________________________________________________________________________
278 void AliRsnMiniOutput::AddAxis(Int_t i, Int_t nbins, Double_t *values)
281 // Create a new axis reference
284 Int_t size = fAxes.GetEntries();
285 new (fAxes[size]) AliRsnMiniAxis(i, nbins, values);
288 //__________________________________________________________________________________________________
289 Bool_t AliRsnMiniOutput::Init(const char *prefix, TList *list)
292 // Initialize properly the histogram and add it to the argument list
296 AliError("Required an output list");
301 Int_t size = fAxes.GetEntries();
303 AliWarning(Form("[%s] Cannot initialize histogram with less than 1 axis", GetName()));
307 switch (fOutputType) {
310 CreateHistogram(Form("%s_%s", prefix, GetName()));
312 AliInfo(Form("[%s] Added %d > 3 axes. Creating a sparse histogram", GetName(), size));
313 fOutputType = kHistogramSparse;
314 CreateHistogramSparse(Form("%s_%s", prefix, GetName()));
317 case kHistogramSparse:
318 CreateHistogramSparse(Form("%s_%s", prefix, GetName()));
321 AliError("Wrong output histogram definition");
326 //__________________________________________________________________________________________________
327 void AliRsnMiniOutput::CreateHistogram(const char *name)
330 // Initialize the 'default' TH1 output object.
331 // In case one of the expected axes is NULL, the initialization fails.
334 Int_t size = fAxes.GetEntries();
335 AliInfo(Form("Histogram name = '%s', with %d axes", name, size));
337 // we expect to have maximum 3 axes in this case
338 AliRsnMiniAxis *xAxis = 0x0, *yAxis = 0x0, *zAxis = 0x0;
339 if (size >= 1) xAxis = (AliRsnMiniAxis *)fAxes[0];
340 if (size >= 2) yAxis = (AliRsnMiniAxis *)fAxes[1];
341 if (size >= 3) zAxis = (AliRsnMiniAxis *)fAxes[2];
343 // create histogram depending on the number of axes
345 if (xAxis && yAxis && zAxis) {
346 h1 = new TH3F(name, "", xAxis->NBins(), xAxis->BinArray(), yAxis->NBins(), yAxis->BinArray(), zAxis->NBins(), zAxis->BinArray());
347 } else if (xAxis && yAxis) {
348 h1 = new TH2F(name, "", xAxis->NBins(), xAxis->BinArray(), yAxis->NBins(), yAxis->BinArray());
350 h1 = new TH1F(name, "", xAxis->NBins(), xAxis->BinArray());
352 AliError("No axis was initialized");
356 // switch the correct computation of errors
360 fOutputID = fList->IndexOf(h1);
364 //________________________________________________________________________________________
365 void AliRsnMiniOutput::CreateHistogramSparse(const char *name)
368 // Initialize the THnSparse output object.
369 // In case one of the expected axes is NULL, the initialization fails.
372 Int_t size = fAxes.GetEntries();
373 AliInfo(Form("Sparse histogram name = '%s', with %d axes", name, size));
375 // retrieve binnings and sizes of all axes
376 // since the check for null values is done in Init(),
377 // we assume that here they must all be well defined
378 Int_t i, *nbins = new Int_t[size];
379 for (i = 0; i < size; i++) {
380 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
381 nbins[i] = axis->NBins();
384 // create fHSparseogram
385 THnSparseF *h1 = new THnSparseF(name, "", size, nbins);
387 // update the various axes using the definitions given in the array of axes here
388 for (i = 0; i < size; i++) {
389 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
390 h1->GetAxis(i)->Set(nbins[i], axis->BinArray());
400 fOutputID = fList->IndexOf(h1);
404 //________________________________________________________________________________________
405 Bool_t AliRsnMiniOutput::FillEvent(AliRsnMiniEvent *event, TClonesArray *valueList)
408 // Compute values for event-based computations (does not use the pair)
411 // check computation type
412 if (fComputation != kEventOnly) {
413 AliError("This method can be called only for event-based computations");
418 ComputeValues(event, valueList);
423 //________________________________________________________________________________________
424 Bool_t AliRsnMiniOutput::FillMother(const AliRsnMiniPair *pair, AliRsnMiniEvent *event, TClonesArray *valueList)
427 // Compute values for mother-based computations
430 // check computation type
431 if (fComputation != kMother) {
432 AliError("This method can be called only for mother-based computations");
436 // copy passed pair info
439 // check pair against cuts
440 if (fPairCuts) if (!fPairCuts->IsSelected(&fPair)) return kFALSE;
443 ComputeValues(event, valueList);
448 //________________________________________________________________________________________
449 Int_t AliRsnMiniOutput::FillPair(AliRsnMiniEvent *event1, AliRsnMiniEvent *event2, TClonesArray *valueList, Bool_t refFirst)
452 // Loops on the passed mini-event, and for each pair of particles
453 // which satisfy the charge and cut requirements defined here, add an entry.
454 // Returns the number of successful fillings.
455 // Last argument tells if the reference event for event-based values is the first or the second.
458 // check computation type
459 Bool_t okComp = kFALSE;
460 if (fComputation == kTrackPair) okComp = kTRUE;
461 if (fComputation == kTrackPairMix) okComp = kTRUE;
462 if (fComputation == kTrackPairRotated1) okComp = kTRUE;
463 if (fComputation == kTrackPairRotated2) okComp = kTRUE;
464 if (fComputation == kTruePair) okComp = kTRUE;
466 AliError(Form("[%s] This method can be called only for pair-based computations", GetName()));
471 Int_t i1, i2, start, nadded = 0;
472 AliRsnMiniParticle *p1, *p2;
474 // it is necessary to know if criteria for the two daughters are the same
475 // and if the two events are the same or not (mixing)
476 //Bool_t sameCriteria = ((fCharge[0] == fCharge[1]) && (fCutID[0] == fCutID[1]));
477 Bool_t sameCriteria = ((fCharge[0] == fCharge[1]) && (fDaughter[0] == fDaughter[1]));
478 Bool_t sameEvent = (event1->ID() == event2->ID());
480 TString selList1 = "";
481 TString selList2 = "";
482 Int_t n1 = event1->CountParticles(fSel1, fCharge[0], fCutID[0]);
483 Int_t n2 = event2->CountParticles(fSel2, fCharge[1], fCutID[1]);
484 for (i1 = 0; i1 < n1; i1++) selList1.Append(Form("%d ", fSel1[i1]));
485 for (i2 = 0; i2 < n2; i2++) selList2.Append(Form("%d ", fSel2[i2]));
486 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()));
487 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()));
489 AliDebugClass(1, "No pairs to mix");
494 for (i1 = 0; i1 < n1; i1++) {
495 p1 = event1->GetParticle(fSel1[i1]);
496 //p1 = event1->GetParticle(i1);
497 //if (p1->Charge() != fCharge[0]) continue;
498 //if (!p1->HasCutBit(fCutID[0])) continue;
499 // define starting point for inner loop
500 // if daughter selection criteria (charge, cuts) are the same
501 // and the two events coincide, internal loop must start from
502 // the first track *after* current one;
503 // otherwise it starts from the beginning
504 start = ((sameEvent && sameCriteria) ? i1 + 1 : 0);
505 AliDebugClass(2, Form("Start point = %d", start));
507 for (i2 = start; i2 < n2; i2++) {
508 p2 = event2->GetParticle(fSel2[i2]);
509 //p2 = event2->GetParticle(i2);
510 //if (p2->Charge() != fCharge[1]) continue;
511 //if (!p2->HasCutBit(fCutID[1])) continue;
512 // avoid to mix a particle with itself
513 if (sameEvent && (p1->Index() == p2->Index())) {
514 AliDebugClass(2, "Skipping same index");
518 fPair.Fill(p1, p2, GetMass(0), GetMass(1), fMotherMass);
519 // do rotation if needed
520 if (fComputation == kTrackPairRotated1) fPair.InvertP(kTRUE);
521 if (fComputation == kTrackPairRotated2) fPair.InvertP(kFALSE);
522 // if required, check that this is a true pair
523 if (fComputation == kTruePair) {
524 if (fPair.Mother() < 0) {
526 } else if (fPair.MotherPDG() != fMotherPDG) {
529 Bool_t decayMatch = kFALSE;
530 if (p1->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[0]) && p2->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[1]))
532 if (p2->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[0]) && p1->PDGAbs() == AliRsnDaughter::SpeciesPDG(fDaughter[1]))
534 if (!decayMatch) continue;
535 if ( (fMaxNSisters>0) && (p1->NTotSisters()==p2->NTotSisters()) && (p1->NTotSisters()>fMaxNSisters)) continue;
536 if ( fCheckP &&(TMath::Abs(fPair.PmotherX()-(p1->Px(1)+p2->Px(1)))/(TMath::Abs(fPair.PmotherX())+1.e-13)) > 0.00001 &&
537 (TMath::Abs(fPair.PmotherY()-(p1->Py(1)+p2->Py(1)))/(TMath::Abs(fPair.PmotherY())+1.e-13)) > 0.00001 &&
538 (TMath::Abs(fPair.PmotherZ()-(p1->Pz(1)+p2->Pz(1)))/(TMath::Abs(fPair.PmotherZ())+1.e-13)) > 0.00001 ) continue;
539 if ( fCheckFeedDown ){
541 Bool_t isFromB=kFALSE;
542 Bool_t isQuarkFound=kFALSE;
544 if(fPair.IsFromB() == kTRUE) isFromB = kTRUE;
545 if(fPair.IsQuarkFound() == kTRUE) isQuarkFound = kTRUE;
546 if(fRejectIfNoQuark && !isQuarkFound) pdgGranma = -99999;
548 if (!fKeepDfromB) pdgGranma = -9999; //skip particle if come from a B meson.
551 if (fKeepDfromBOnly) pdgGranma = -999;
553 if (pdgGranma == -99999){
554 AliDebug(2,"This particle does not have a quark in his genealogy\n");
557 if (pdgGranma == -9999){
558 AliDebug(2,"This particle come from a B decay channel but according to the settings of the task, we keep only the prompt charm particles\n");
562 if (pdgGranma == -999){
563 AliDebug(2,"This particle come from a prompt charm particles but according to the settings of the task, we want only the ones coming from B\n");
568 // check pair against cuts
570 if (!fPairCuts->IsSelected(&fPair)) continue;
572 // get computed values & fill histogram
574 if (refFirst) ComputeValues(event1, valueList); else ComputeValues(event2, valueList);
576 } // end internal loop
577 } // end external loop
579 AliDebugClass(1, Form("Pairs added in total = %4d", nadded));
582 //___________________________________________________________
583 void AliRsnMiniOutput::SetDselection(UShort_t originDselection)
585 // setting the way the D0 will be selected
586 // 0 --> only from c quarks
587 // 1 --> only from b quarks
588 // 2 --> from both c quarks and b quarks
590 fOriginDselection = originDselection;
592 if (fOriginDselection == 0) {
593 fKeepDfromB = kFALSE;
594 fKeepDfromBOnly = kFALSE;
597 if (fOriginDselection == 1) {
599 fKeepDfromBOnly = kTRUE;
602 if (fOriginDselection == 2) {
604 fKeepDfromBOnly = kFALSE;
609 //________________________________________________________________________________________
610 void AliRsnMiniOutput::ComputeValues(AliRsnMiniEvent *event, TClonesArray *valueList)
613 // Using the arguments and the internal 'fPair' data member,
614 // compute all values to be stored in the histogram
617 // check size of computed array
618 Int_t size = fAxes.GetEntries();
619 if (fComputed.GetSize() != size) fComputed.Set(size);
621 Int_t i, ival, nval = valueList->GetEntries();
623 for (i = 0; i < size; i++) {
625 AliRsnMiniAxis *axis = (AliRsnMiniAxis *)fAxes[i];
627 AliError("Null axis");
630 ival = axis->GetValueID();
631 if (ival < 0 || ival >= nval) {
632 AliError(Form("Required value #%d, while maximum is %d", ival, nval));
635 AliRsnMiniValue *val = (AliRsnMiniValue *)valueList->At(ival);
637 AliError(Form("Value in position #%d is NULL", ival));
640 // if none of the above exit points is taken, compute value
641 fComputed[i] = val->Eval(&fPair, event);
645 //________________________________________________________________________________________
646 void AliRsnMiniOutput::FillHistogram()
649 // Fills the internal histogram using the current values stored in the
650 // 'fComputed' array, in the order as they are stored, up to the max
651 // dimension of the initialized histogram itself.
654 // retrieve object from list
656 AliError("List pointer is NULL");
659 TObject *obj = fList->At(fOutputID);
661 if (obj->InheritsFrom(TH1F::Class())) {
662 ((TH1F *)obj)->Fill(fComputed[0]);
663 } else if (obj->InheritsFrom(TH2F::Class())) {
664 ((TH2F *)obj)->Fill(fComputed[0], fComputed[1]);
665 } else if (obj->InheritsFrom(TH3F::Class())) {
666 ((TH3F *)obj)->Fill(fComputed[0], fComputed[1], fComputed[2]);
667 } else if (obj->InheritsFrom(THnSparseF::Class())) {
668 THnSparseF *h = (THnSparseF *)obj;
669 if (fCheckHistRange) {
670 for (Int_t iAxis = 0; iAxis<h->GetNdimensions(); iAxis++) {
671 if (fComputed.At(iAxis)>h->GetAxis(iAxis)->GetXmax() || fComputed.At(iAxis)<h->GetAxis(iAxis)->GetXmin()) return;
674 h->Fill(fComputed.GetArray());
676 AliError("No output initialized");