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