X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=PWG2%2FRESONANCES%2FAliRsnFunction.cxx;h=bcbe014c660113c7ae16c73f2cc518327589bcfe;hb=9a838fb778f46ceb900c62c1c1c9480dcdfcae5a;hp=4b7a645b099ea980de6a5901961c1f5a76badfda;hpb=6f4a992cae2bd2295c0b56d75c38b6bba5c41336;p=u%2Fmrichter%2FAliRoot.git diff --git a/PWG2/RESONANCES/AliRsnFunction.cxx b/PWG2/RESONANCES/AliRsnFunction.cxx index 4b7a645b099..bcbe014c660 100644 --- a/PWG2/RESONANCES/AliRsnFunction.cxx +++ b/PWG2/RESONANCES/AliRsnFunction.cxx @@ -19,29 +19,32 @@ // author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it) // -#include #include +#include #include "AliLog.h" #include "AliRsnDaughter.h" #include "AliRsnEvent.h" #include "AliRsnPairDef.h" -#include "AliRsnCut.h" +#include "AliRsnMother.h" +#include "AliRsnValue.h" #include "AliRsnFunction.h" ClassImp(AliRsnFunction) //________________________________________________________________________________________ -AliRsnFunction::AliRsnFunction() : - TNamed(), - fPairDef(0x0), - fAxisList("AliRsnFunctionAxis", 0), - fTrack(0x0), - fPair(0x0), - fEvent(0x0), - fHistogram(0x0) +AliRsnFunction::AliRsnFunction(Bool_t useTH1) : + TObject(), + fPairDef(0x0), + fAxisList("AliRsnValue", 0), + fPair(0x0), + fEvent(0x0), + fUseTH1(useTH1), + fSize(0), + fH1(0x0), + fHSparse(0x0) { // // Constructor. @@ -50,13 +53,15 @@ AliRsnFunction::AliRsnFunction() : //________________________________________________________________________________________ AliRsnFunction::AliRsnFunction(const AliRsnFunction ©) : - TNamed(copy), - fPairDef(copy.fPairDef), - fAxisList(copy.fAxisList), - fTrack(copy.fTrack), - fPair(copy.fPair), - fEvent(copy.fEvent), - fHistogram(0x0) + TObject(copy), + fPairDef(copy.fPairDef), + fAxisList(copy.fAxisList), + fPair(copy.fPair), + fEvent(copy.fEvent), + fUseTH1(copy.fUseTH1), + fSize(copy.fSize), + fH1(0x0), + fHSparse(0x0) { // // Copy constructor. @@ -70,16 +75,20 @@ const AliRsnFunction& AliRsnFunction::operator=(const AliRsnFunction& copy) // Assignment operator. // - SetName(copy.GetName()); - SetTitle(copy.GetTitle()); + //SetName(copy.GetName()); + //SetTitle(copy.GetTitle()); fPairDef = copy.fPairDef; - fTrack = copy.fTrack; fPair = copy.fPair; fEvent = copy.fEvent; + fUseTH1 = copy.fUseTH1; + fSize = copy.fSize; - if (fHistogram) delete fHistogram; - fHistogram = 0x0; + if (fH1) delete fH1; + fH1 = 0x0; + + if (fHSparse) delete fHSparse; + fHSparse = 0x0; return (*this); } @@ -95,10 +104,9 @@ const char* AliRsnFunction::GetName() const TString name(""); TObjArrayIter next(&fAxisList); - AliRsnFunctionAxis *axis = 0; + AliRsnValue *axis = 0; - while ( (axis = (AliRsnFunctionAxis*)next()) ) - { + while ((axis = (AliRsnValue*)next())) { if (name.Length() > 1) name += '_'; name += axis->GetName(); } @@ -107,14 +115,22 @@ const char* AliRsnFunction::GetName() const } //________________________________________________________________________________________ -void AliRsnFunction::AddAxis(AliRsnFunctionAxis *axis) +void AliRsnFunction::AddAxis(AliRsnValue *const axis) { + AliDebug(AliLog::kDebug+2,"<-"); Int_t size = fAxisList.GetEntries(); - new (fAxisList[size]) AliRsnFunctionAxis(*axis); + new(fAxisList[size]) AliRsnValue(*axis); + AliDebug(AliLog::kDebug+2,"->"); + + if (fAxisList.GetEntries() > 3) + { + AliWarning("A TH1-type output cannot add more than 3 axes: switching to THnSparse -- THIS COULD CAUSE VERY LARGE FILES!!!"); + fUseTH1 = kFALSE; + } } //________________________________________________________________________________________ -THnSparseD* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle) +TH1* AliRsnFunction::CreateHistogram(const char *histoName, const char *histoTitle) { // // Creates and returns the histogram defined using @@ -122,42 +138,117 @@ THnSparseD* AliRsnFunction::CreateHistogram(const char *histoName, const char *h // Variable-sized histogram binning is always called, due to use of histoDef, // even if the bins are equal, since they are defined in this class. // Eventually present histoDef's in other slots of array (1, 2) are ignored. +// +// This version produces a THnSparseF. // - Int_t size = fAxisList.GetEntries(); - if (!size) { + fSize = fAxisList.GetEntries(); + if (!fSize) { AliError("No axes defined"); return 0x0; } - - Int_t *nbins = new Int_t[size]; - Double_t *min = new Double_t[size]; - Double_t *max = new Double_t[size]; + else if (fSize < 1 || fSize > 3) + { + AliError("Too few or too many axes defined"); + return 0x0; + } // retrieve binnings for main and secondary axes - AliRsnFunctionAxis *fcnAxis = 0; - for (Int_t i = 0; i < size; i++) + AliRsnValue *fcnAxis; + TArrayD array[3]; + for (Int_t i = 0; i < fSize; i++) { - fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i); - if (!fcnAxis) { - nbins[i] = 0; - min[i] = 0.0; - max[i] = 0.0; + fcnAxis = (AliRsnValue*)fAxisList.At(i); + if (!fcnAxis) + { + AliError("Empty axis"); + array[i].Set(2); + array[i][0] = -1E5; + array[i][1] = -1E5; + continue; + } + else + { + array[i] = fcnAxis->GetArray(); + } + } + + // create histogram depending on the number of axes + switch (fSize) + { + case 1: + fH1 = new TH1F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray()); + break; + case 2: + fH1 = new TH2F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray()); + break; + case 3: + fH1 = new TH3F(histoName, histoTitle, array[0].GetSize() - 1, array[0].GetArray(), array[1].GetSize() - 1, array[1].GetArray(), array[2].GetSize() - 1, array[2].GetArray()); + break; + } + fH1->Sumw2(); + + return fH1; +} + +//________________________________________________________________________________________ +THnSparseF* AliRsnFunction::CreateHistogramSparse(const char *histoName, const char *histoTitle) +{ +// +// Creates and returns the histogram defined using +// arguments fo name and title, and the first histoDef for binning. +// Variable-sized histogram binning is always called, due to use of histoDef, +// even if the bins are equal, since they are defined in this class. +// Eventually present histoDef's in other slots of array (1, 2) are ignored. +// +// This version produces a THnSparseF. +// + + fSize = fAxisList.GetEntries(); + if (!fSize) { + AliError("No axes defined"); + return 0x0; + } + + // initialize the array of number of bins for each axis + // taking it from the stored values, while for the bins + // they are set as summied and defined later + Double_t dummyD; + Int_t *nbins = new Int_t[fSize]; + AliRsnValue *fcnAxis = 0; + for (Int_t i = 0; i < fSize; i++) + { + fcnAxis = (AliRsnValue*)fAxisList.At(i); + if (!fcnAxis) + { + nbins[i] = 1; AliError("Empty axis"); continue; } - nbins[i] = fcnAxis->GetNBins(); - min[i] = fcnAxis->GetMin(); - max[i] = fcnAxis->GetMax(); + nbins[i] = fcnAxis->GetArray().GetSize() - 1; } // create histogram - fHistogram = new THnSparseD(histoName, histoTitle, size, nbins, min, max); - fHistogram->Sumw2(); + fHSparse = new THnSparseF(histoName, histoTitle, fSize, nbins, &dummyD, &dummyD); + fHSparse->Sumw2(); + + // update the various axes using the definitions given in the array of axes here + for (Int_t i = 0; i < fSize; i++) + { + fcnAxis = (AliRsnValue*)fAxisList.At(i); + if (!fcnAxis) { + AliError("Empty axis: doing unique bin betweeen -100000 and 100000"); + continue; + } + fHSparse->SetBinEdges(i, fcnAxis->GetArray().GetArray()); + } + + delete [] nbins; - return fHistogram; + return fHSparse; } + //________________________________________________________________________________________ Bool_t AliRsnFunction::Fill() { @@ -167,40 +258,70 @@ Bool_t AliRsnFunction::Fill() AliDebug(AliLog::kDebug +2,"->"); - Int_t i, nAxes = fAxisList.GetEntries(); - Double_t *values = new Double_t[nAxes]; + Int_t i; + Double_t *values = new Double_t[fSize]; - AliRsnFunctionAxis *fcnAxis = 0; - for (i = 0; i < nAxes; i++) - { - fcnAxis = (AliRsnFunctionAxis*)fAxisList.At(i); - if (!fcnAxis) { + AliRsnValue *fcnAxis = 0; + for (i = 0; i < fSize; i++) { + fcnAxis = (AliRsnValue*)fAxisList.At(i); + if (!fcnAxis) + { values[i] = 0.0; continue; } - switch (fcnAxis->GetAxisObject()) + if (fcnAxis->Eval(fPair, fPairDef, fEvent)) values[i] = (Double_t)((Float_t)fcnAxis->GetValue()); + } + + // fill histogram + if (fUseTH1) + { + // check presence of output histogram + if (!fH1) { + AliError("Required a TH1 which is not initialized"); + delete [] values; + return kFALSE; + } + + // fill according to dimensions + switch (fSize) { - case AliRsnFunctionAxis::kParticle: - values[i] = fcnAxis->Eval(fTrack); + case 1: + { + TH1F *h1 = (TH1F*)fH1; + h1->Fill(values[0]); + } break; - case AliRsnFunctionAxis::kPair: - values[i] = fcnAxis->Eval(fPair, fPairDef); + case 2: + { + TH2F *h2 = (TH2F*)fH1; + h2->Fill(values[0], values[1]); + } break; - case AliRsnFunctionAxis::kEvent: - values[i] = fcnAxis->Eval(fEvent); + case 3: + { + TH3F *h3 = (TH3F*)fH1; + h3->Fill(values[0], values[1], values[2]); + } break; default: - values[i] = 0.0; + AliError(Form("Wrong size : %d", fSize)); + delete [] values; + return kFALSE; } } - - // check presence of output histogram - if (!fHistogram) { - AliError("Histogram is not yet initialized"); - return kFALSE; + else + { + // check presence of output histogram + if (!fHSparse) { + AliError("Required a THnSparseF which is not initialized"); + delete [] values; + return kFALSE; + } + + fHSparse->Fill(values); } - //TArrayD val(values); val->Print(); - fHistogram->Fill(values); + + delete [] values; AliDebug(AliLog::kDebug +2,"->"); return kTRUE;