CbmRoot
Loading...
Searching...
No Matches
PairAnalysisHF.cxx
Go to the documentation of this file.
1/*************************************************************************
2* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3**************************************************************************/
4
6// PairAnalysis HF //
7// //
8// //
9/*
10Detailed description
11
12
13*/
14// //
16
17#include "PairAnalysisHF.h"
18
19#include "CbmMCTrack.h"
20
21#include <TAxis.h>
22#include <TFile.h>
23#include <TH1.h>
24#include <TH1F.h>
25#include <TH2.h>
26#include <TH3.h>
27#include <THnSparse.h>
28#include <TKey.h>
29#include <TObjArray.h>
30#include <TObjString.h>
31#include <TProfile.h>
32#include <TProfile2D.h>
33#include <TProfile3D.h>
34#include <TString.h>
35#include <TVectorD.h>
36
37#include "PairAnalysis.h"
38#include "PairAnalysisHelper.h"
39#include "PairAnalysisHistos.h"
40#include "PairAnalysisMC.h"
41#include "PairAnalysisPair.h"
43#include "PairAnalysisStyler.h"
44#include "PairAnalysisTrack.h"
45
47
49 : //TNamed(),
50 PairAnalysisHistos()
51 , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
52 , fArrDielHistos()
53 , fSignalsMC(0x0)
54 , fVarCutType(new TBits(fMaxCuts))
55 , fAxes(fMaxCuts)
56{
57 //
58 // Default Constructor
59 //
60 for (Int_t i = 0; i < fMaxCuts; ++i) {
61 fVarCuts[i] = 0;
62 // fVarCutType[i]=0;
63 }
64 fAxes.SetOwner(kTRUE);
65 fArrDielHistos.SetOwner(kTRUE);
66}
67
68//______________________________________________
69PairAnalysisHF::PairAnalysisHF(const char* name, const char* title)
70 : // TNamed(name, title),
71 PairAnalysisHistos(name, title)
72 , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
73 , fArrDielHistos()
74 , fSignalsMC(0x0)
75 , fVarCutType(new TBits(fMaxCuts))
76 , fAxes(fMaxCuts)
77{
78 //
79 // Named Constructor
80 //
81 for (Int_t i = 0; i < fMaxCuts; ++i) {
82 fVarCuts[i] = 0;
83 // fVarCutType[i]=0;
84 }
85 fAxes.SetOwner(kTRUE);
86 fArrDielHistos.SetOwner(kTRUE);
87}
88
89//______________________________________________
91{
92 //
93 // Default Destructor
94 //
95 if (fUsedVars) delete fUsedVars;
96 if (fVarCutType) delete fVarCutType;
97 fAxes.Delete();
98 fArrDielHistos.Delete(); //TODO: better Clear?
99}
100
101//________________________________________________________________
103{
104 //
105 // Add a variable to the histogram array with a vector
106 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
107 //
108
109 // limit number of variables to fMaxCuts
110 if (fAxes.GetEntriesFast() >= fMaxCuts) return;
111
112 if (!binLimits) return;
113
114 Int_t size = fAxes.GetEntriesFast();
115 fVarCuts[size] = (UShort_t) type;
116 // fVarCutType[size]=leg;
117 fVarCutType->SetBitNumber(size, leg);
118 fAxes.Add(binLimits);
119 fUsedVars->SetBitNumber(type, kTRUE);
120}
121
122//_____________________________________________________________________________
123void PairAnalysisHF::FillClass(const char* histClass, const Double_t* values)
124{
125 //
126 // Fill the histograms if cuts are passed
127 //
128
129 // find cell described by values
130 Int_t cell = FindCell(values);
131 // printf("cell: %d \n",cell);
132 if (cell < 0) return;
133 // printf(" --> %s \n",fArrDielHistos.UncheckedAt(cell)->GetName());
134
135 // do NOT set the ownership otherwise you will delete all histos!!
136 SetHistogramList(*static_cast<THashList*>(fArrDielHistos.UncheckedAt(cell)), kFALSE);
137 PairAnalysisHistos::FillClass(histClass, values);
138}
139
140//______________________________________________
141void PairAnalysisHF::ReadFromFile(const char* file, const char* task, const char* config)
142{
143 //
144 // Read histos from file
145 //
146 // TODO: to be tested!
147 TFile f(file);
148 TIter nextKey(f.GetListOfKeys());
149 TKey* key = 0;
150 while ((key = (TKey*) nextKey())) {
151 TString name = key->GetName();
152 if (!name.Contains("PairAnalysisHistos")) continue;
153 if (!strlen(task) && !name.Contains(task)) continue;
154 TObject* o = f.Get(key->GetName());
155 TList* list = dynamic_cast<TList*>(o);
156 if (!list) continue;
158 TObjArray* listCfg = dynamic_cast<TObjArray*>(list->FindObject(Form("%s_HF", config)));
159 if (!listCfg) continue;
161 break;
162 }
163 f.Close();
164 // load style
166}
167
168//______________________________________________
169void PairAnalysisHF::Fill(Int_t /*label1*/, Int_t /*label2*/, Int_t /*nSignal*/)
170{
171 return; //TODO: OBSOLETE?
172 /*
173 //
174 // fill the pure MC part of the container starting from a pair of 2 particles (part1 and part2 are legs)
175 //
176 // fill only if we have asked for these steps
177 if(!fStepGenerated || fEventArray) return;
178
179 CbmMCTrack* part1 = PairAnalysisMC::Instance()->GetMCTrackFromMCEvent(label1);
180 CbmMCTrack* part2 = PairAnalysisMC::Instance()->GetMCTrackFromMCEvent(label2);
181 if(!part1 || !part2) return;
182
183 PairAnalysisMC* papaMC = PairAnalysisMC::Instance();
184
185 Int_t mLabel1 = papaMC->GetMothersLabel(label1);
186 Int_t mLabel2 = papaMC->GetMothersLabel(label2);
187
188 // check the same mother option
189 PairAnalysisSignalMC* sigMC = (PairAnalysisSignalMC*)fSignalsMC->At(nSignal);
190 if(sigMC->GetMothersRelation()==PairAnalysisSignalMC::kSame && mLabel1!=mLabel2) return;
191 if(sigMC->GetMothersRelation()==PairAnalysisSignalMC::kDifferent && mLabel1==mLabel2) return;
192
193 PairAnalysisVarManager::SetFillMap(fUsedVars);
194 // fill the leg variables
195 Double_t valuesLeg1[PairAnalysisVarManager::kNMaxValuesMC];
196 Double_t valuesLeg2[PairAnalysisVarManager::kNMaxValuesMC];
197 PairAnalysisVarManager::Fill(part1,valuesLeg1);
198 PairAnalysisVarManager::Fill(part2,valuesLeg2);
199
200 // fill the pair and event variables
201 Double_t valuesPair[PairAnalysisVarManager::kNMaxValuesMC];
202 //TODO PairAnalysisVarManager::Fill(papaMC->GetMCEvent(), valuesPair);
203 PairAnalysisVarManager::FillVarMCParticle(part1,part2,valuesPair);
204
205 // if pair types are filled, fill mc sources at the end
206 Int_t istep=0;
207 if(fPairType!=kMConly) istep=PairAnalysis::kSEPMRot+1;
208
209 // only OS at the moment
210 if(part1->GetCharge()*part2->GetCharge()<0) {
211 Fill(istep+nSignal+fSignalsMC->GetEntriesFast(), valuesPair, valuesLeg1, valuesLeg2);
212 }
213
214 return;
215 */
216}
217//______________________________________________
218void PairAnalysisHF::Fill(Int_t /*pairIndex*/, const PairAnalysisPair* /*particle*/)
219{
220 //
221 // fill histograms for event, pair and daughter cuts and pair types
222 //
223 return; //TODO: OBSOLETE?
224 /*
225 // only OS pairs in case of MC
227
228 // only selected pair types in case of data
229 if(!IsPairTypeSelected(pairIndex) || fEventArray) return;
230
231 // get event and pair variables
232 Double_t valuesPair[PairAnalysisVarManager::kNMaxValuesMC];
233 PairAnalysisVarManager::SetFillMap(fUsedVars);
234 PairAnalysisVarManager::Fill(particle,valuesPair);
235
236 // get leg variables (TODO: do not fill for the moment since leg cuts are not opened)
237 Double_t valuesLeg1[PairAnalysisVarManager::kNMaxValuesMC]={0};
238 if(fVarCutType->CountBits()) PairAnalysisVarManager::Fill(particle->GetFirstDaughter(),valuesLeg1);
239 Double_t valuesLeg2[PairAnalysisVarManager::kNMaxValuesMC]={0};
240 if(fVarCutType->CountBits()) PairAnalysisVarManager::Fill(particle->GetSecondDaughter(),valuesLeg2);
241
242 // fill
243
244 // if pair types are filled, fill mc sources at the end
245 Int_t istep = 0;
246 if(fPairType!=kMConly) istep=PairAnalysis::kSEPMRot+1;
247
248 // mc source steps (only OS SE pairs)
249 if(fHasMC && fSignalsMC && pairIndex==PairAnalysis::kSEPM) {
250 for(Int_t i=0; i<fSignalsMC->GetEntriesFast(); i++) {
252 Fill(istep+i, valuesPair, valuesLeg1, valuesLeg2);
253 }
254 }
255
256 // all pair types w/o use of mc information
257 if(fPairType==kMConly) return;
258
259 // remove comments
262 Fill(pairIndex, valuesPair, valuesLeg1, valuesLeg2);
263
264 return;
265 */
266}
267
268//______________________________________________
269void PairAnalysisHF::Fill(Int_t /*index*/, Double_t* const /*valuesPair*/, Double_t* const /*valuesLeg1*/,
270 Double_t* const /*valuesLeg2*/)
271{
272 //
273 // main fill function using index and values as input
274 //
275 return; //TODO: OBSOLETE?
276 /*
277 TObjArray *histArr = static_cast<TObjArray*>(fArrDielHistos.At(index));
278 if(!histArr) return;
279
280 Int_t size = GetNumberOfBins();
281 // loop over all histograms
282 for(Int_t ihist=0; ihist<size; ihist++) {
283
284 Int_t sizeAdd = 1;
285 Bool_t selected = kTRUE;
286
287 // loop over all cut variables
288 Int_t nvars = fAxes.GetEntriesFast();
289 for(Int_t ivar=0; ivar<nvars; ivar++) {
290
291 // get bin limits
292 TVectorD *bins = static_cast<TVectorD*>(fAxes.At(ivar));
293 Int_t nbins = bins->GetNrows()-1;
294
295 // bin limits for current ivar bin
296 Int_t ibin = (ihist/sizeAdd)%nbins;
297 Double_t lowEdge = (*bins)[ibin];
298 Double_t upEdge = (*bins)[ibin+1];
299 switch(fBinType[ivar]) {
300 case kStdBin: upEdge=(*bins)[ibin+1]; break;
301 case kBinToMax: upEdge=(*bins)[nbins]; break;
302 case kBinFromMin: lowEdge=(*bins)[0]; break;
303 case kSymBin: upEdge=(*bins)[nbins-ibin];
304 if(ibin>=((Double_t)(nbins+1))/2) upEdge=(*bins)[nbins]; // to avoid low>up
305 break;
306 }
307
308 // leg variable
309 if(fVarCutType->TestBitNumber(ivar)) {
310 if( (valuesLeg1[fVarCuts[ivar]] < lowEdge || valuesLeg1[fVarCuts[ivar]] >= upEdge) ||
311 (valuesLeg2[fVarCuts[ivar]] < lowEdge || valuesLeg2[fVarCuts[ivar]] >= upEdge) ) {
312 selected=kFALSE;
313 break;
314 }
315 }
316 else { // pair and event variables
317 if( (valuesPair[fVarCuts[ivar]] < lowEdge || valuesPair[fVarCuts[ivar]] >= upEdge) ) {
318 selected=kFALSE;
319 break;
320 }
321 }
322
323 sizeAdd*=nbins;
324 } //end of var cut loop
325
326 // do not fill the histogram
327 if(!selected) continue;
328
329 // fill the object with Pair and event values
330 TObjArray *tmp = (TObjArray*) histArr->At(ihist);
331 TString title = tmp->GetName();
333 for(Int_t i=0; i<tmp->GetEntriesFast(); i++) {
334 PairAnalysisHistos::FillValues(tmp->At(i), valuesPair);
335 }
336 // Debug(10,Form("Fill var %d %s value %f in %s \n",fVar,PairAnalysisVarManager::GetValueName(fVar),valuesPair[fVar],tmp->GetName()));
337 } //end of hist loop
338 */
339}
340
341//______________________________________________
343{
344 //
345 // initialise the HF array
346 //
347
348 // create an TObjArray of 'size' with PairAnalysisHistos objects
349 Int_t size = GetNumberOfBins();
350
351 fArrDielHistos.SetName(Form("%s_HF", GetName()));
352 fArrDielHistos.Expand(size);
354
355 // add 'PairAnalysisHistos'-list to each cell
356 for (Int_t icell = 0; icell < size; icell++) {
357 fArrDielHistos.AddAt(fHistoList.Clone(""), icell);
358 }
359
360 // loop over all cut variables and do the naming according to its bin cell
361 Int_t sizeAdd = 1; // counter for processed cells
362 Int_t nvars = fAxes.GetEntriesFast();
363 for (Int_t ivar = 0; ivar < nvars; ivar++) {
364
365 // get bin limits for variabvle ivar
366 TVectorD* bins = static_cast<TVectorD*>(fAxes.At(ivar));
367 Int_t nbins = bins->GetNrows() - 1;
368
369 // loop over all cells
370 // Add 'variable' name and current 'bin limits' to
371 // the title of the 'PairAnalysisHistos'-list title
372 // which is unique
373 for (Int_t icell = 0; icell < size; icell++) {
374
375 // get the lower limit for current ivar bin
376 Int_t ibin = (icell / sizeAdd) % nbins;
377 Double_t lowEdge = (*bins)[ibin];
378 Double_t upEdge = (*bins)[ibin + 1];
379
380 // modify title of hashlist
381 TString title = fArrDielHistos.UncheckedAt(icell)->GetName();
382 if (!ivar) title = "";
383 else
384 title += ":"; // delimiter for new variable
385 if (fVarCutType->TestBitNumber(ivar)) title += "Leg"; // for leg variable Identification
387 title += Form("#%.2f#%.2f", lowEdge, upEdge); // TODO: precision enough?
388 static_cast<THashList*>(fArrDielHistos.UncheckedAt(icell))->SetName(title.Data());
390
391 } // end: array of cells
392
393 sizeAdd *= nbins;
394
395 } //end: loop variables
396
397 // clean up
398 // if(fArrDielHistos) {
399 // fArrDielHistos.Delete();
400 // fArrDielHistos=0;
401 // }
402}
403
404//______________________________________________
406{
407 //
408 // return the number of bins this histogram grid has
409 //
410 Int_t size = 1;
411 for (Int_t i = 0; i < fAxes.GetEntriesFast(); ++i)
412 size *= ((static_cast<TVectorD*>(fAxes.At(i)))->GetNrows() - 1);
413 return size;
414}
415
416//______________________________________________
417Int_t PairAnalysisHF::FindCell(const Double_t* values)
418{
419 //
420 // cell described by 'values'
421 // if the values are outside the binning range -1 is returned
422 //
423
424 if (fAxes.GetEntriesFast() == 0) return 0;
425
426 Int_t sizeAdd = 1;
427 Int_t cell = 0;
428 for (Int_t i = 0; i < fAxes.GetEntriesFast(); ++i) {
429 Double_t val = values[fVarCuts[i]];
430 TVectorD* bins = static_cast<TVectorD*>(fAxes.At(i));
431 Int_t nRows = bins->GetNrows();
432 if ((val < (*bins)[0]) || (val > (*bins)[nRows - 1])) { return -1; }
433
434 Int_t pos = TMath::BinarySearch(nRows, bins->GetMatrixArray(), val);
435 cell += sizeAdd * pos;
436 // printf(" \t %s: %.2f-%.2f %d \n",
437 // PairAnalysisVarManager::GetValueName(fVarCuts[i]), (*bins)[pos], (*bins)[pos+1], pos);
438 sizeAdd *= (nRows - 1);
439 }
440
441 return cell;
442}
static constexpr size_t size()
Definition KfSimdPseudo.h:2
ClassImp(PairAnalysisHF) PairAnalysisHF
Int_t GetNumberOfBins() const
static const Int_t fMaxCuts
array of MC signals to be stupapad
void Fill(Int_t pairIndex, const PairAnalysisPair *particle)
TObjArray fArrDielHistos
UShort_t fVarCuts[fMaxCuts]
void ReadFromFile(const char *file="histos.root", const char *task="", const char *config="")
virtual ~PairAnalysisHF()
Int_t FindCell(const Double_t *values)
void FillClass(const char *histClass, const Double_t *values)
void AddCutVariable(PairAnalysisVarManager::ValueTypes type, TVectorD *binLimits, Bool_t leg=kFALSE)
static const char * GetValueName(Int_t i)