AliPhysics  8d00e07 (8d00e07)
AliFlowVZEROResults.cxx
Go to the documentation of this file.
1 #include<stdio.h>
2 #include "AliFlowVZEROResults.h"
3 #include "TList.h"
4 
5 ClassImp(AliFlowVZEROResults);
6 
7 AliFlowVZEROResults::AliFlowVZEROResults(const char *name,const Int_t nvar,const Int_t* binVar) :
8  TNamed(name,name),
9  fNbinVar(new TArrayI(nvar)),
10  fXmin(new TArrayF(nvar)),
11  fXmax(new TArrayF(nvar)),
12  fNameVar(new TClonesArray("TNamed")),
13  fV2(new TClonesArray("TProfile"))
14 {
15 
16  for(Int_t i=0;i < GetNvar();i++){
17  (*fNbinVar)[i] = binVar[i];
18  }
19 
20  for(Int_t i=0; i<GetNvar();i++){
21  new((*fNameVar)[i]) TNamed("","");
22  }
23 }
24 
26  TNamed("v2","v2"),
27  fNbinVar(new TArrayI(0)),
28  fXmin(new TArrayF(0)),
29  fXmax(new TArrayF(0)),
30  fNameVar(new TClonesArray("TNamed")),
31  fV2(new TClonesArray("TProfile"))
32 {
33 
34 }
35 
37  for(Int_t i=fNameVar->GetEntries();i>0;i--){
38  delete fNameVar->At(i-1);
39  fNameVar->RemoveAt(i-1);
40  }
41 
42  for(Int_t i=fV2->GetEntries();i>0;i--){
43  delete fV2->At(i-1);
44  fV2->RemoveAt(i-1);
45  }
46 
47  delete fNbinVar;
48  delete fXmin;
49  delete fXmax;
50 }
51 
53  for(Int_t i=fNameVar->GetEntries();i>0;i--){
54  delete fNameVar->At(i-1);
55  fNameVar->RemoveAt(i-1);
56  }
57 
58  for(Int_t i=fV2->GetEntries();i>0;i--){
59  delete fV2->At(i-1);
60  fV2->RemoveAt(i-1);
61  }
62 
63  delete fNbinVar;
64  delete fXmin;
65  delete fXmax;
66 
67  fNbinVar = new TArrayI(0);
68  fXmin = new TArrayF(0);
69  fXmax = new TArrayF(0);
70 
71 }
72 
74  TNamed(old),
75  fNbinVar(NULL),
76  fXmin(NULL),
77  fXmax(NULL),
78  fNameVar(new TClonesArray("TNamed")),
79  fV2(new TClonesArray("TProfile"))
80 {
81 
82  fNbinVar = new TArrayI(old.GetNvar());
83  fXmin = new TArrayF(old.GetNvar());
84  fXmax = new TArrayF(old.GetNvar());
85 
86  for(Int_t i=0; i<old.GetNhistos();i++){
87  new((*fV2)[i]) TProfile(*((TProfile *) old.GetV2(i)));
88  }
89 
90  for(Int_t i=0; i<old.GetNvar();i++){
91  new((*fNameVar)[i]) TNamed(old.GetVarName(i),old.GetVarName(i));
92  }
93 
94  for(Int_t i=0;i < GetNvar();i++){
95  (*fNbinVar)[i] = (*old.fNbinVar)[i];
96  (*fXmin)[i] = (*old.fXmin)[i];
97  (*fXmax)[i] = (*old.fXmax)[i];
98  }
99 
100 }
101 
103 
104  if(this != &old){
105  printf("different\n");
106  }
107 
108  for(Int_t i=0; i<old.GetNhistos();i++){
109  new((*fV2)[i]) TProfile(*((TProfile *) old.GetV2(i)));
110  }
111 
112  fNbinVar = new TArrayI(old.GetNvar());
113  fXmin = new TArrayF(old.GetNvar());
114  fXmax = new TArrayF(old.GetNvar());
115 
116  for(Int_t i=0;i < old.GetNvar();i++){
117  (*fNbinVar)[i] = (*old.fNbinVar)[i];
118  (*fXmin)[i] = (*old.fXmin)[i];
119  (*fXmax)[i] = (*old.fXmax)[i];
120  }
121 
122  fNameVar = new TClonesArray("TNamed");
123  for(Int_t i=0; i<old.GetNvar();i++){
124  new((*fNameVar)[i]) TNamed(old.GetVarName(i),old.GetVarName(i));
125  }
126 
127  return *this;
128 }
129 
131  Int_t n = fV2->GetEntries();
132 
133  for(Int_t i=0;i < GetNvar();i++){
134  n /= (*fNbinVar)[i];
135  }
136 
137  return n;
138 }
139 
140 void AliFlowVZEROResults::AddSpecies(const char *name,Int_t nXbin,const Double_t *bin){
141 
142  Bool_t kErr = kFALSE;
143  for(Int_t i=0;i < GetNvar();i++){ // check the var ranges are set properly
144  if((*fNbinVar)[i] < 1 || (*fXmin)[i] >= (*fXmax)[i]){
145  printf("var ranges are not set properly for variable %i please chek it before to define the species\n",i);
146  kErr = kTRUE;
147  }
148  }
149  if(kErr){
150  printf("AddSpecies: NOTHING DONE\n");
151  return;
152  }
153 
154  Int_t ncomb = 1;
155  for(Int_t i=0;i < GetNvar();i++){
156  ncomb *= (*fNbinVar)[i];
157  }
158 
159  char nameHisto[200];
160  char title[300];
161  char title2[300];
162  for(Int_t i=0; i < ncomb;i++){
163  snprintf(nameHisto,200,"%s_%s_%i",GetName(),name,i);
164  snprintf(title,300,"%s",name);
165  Int_t ncombTemp = i;
166  for(Int_t j=0;j < GetNvar();j++){
167  Int_t ibin = ncombTemp%(*fNbinVar)[j];
168  snprintf(title2,300,"%s",title);
169  snprintf(title,300,"%s_%04.1f<%s<%04.1f",title2,(*fXmin)[j] + ((*fXmax)[j]-(*fXmin)[j])/(*fNbinVar)[j]*ibin,fNameVar->At(j)->GetName(),(*fXmin)[j] + ((*fXmax)[j]-(*fXmin)[j])/(*fNbinVar)[j]*(ibin+1));
170  ncombTemp /= (*fNbinVar)[j];
171  }
172 
173  new((*fV2)[GetNhistos()]) TProfile(nameHisto,title,nXbin,bin);
174  ((TProfile *) GetV2(GetNhistos()-1))->GetXaxis()->SetTitle("p_{t} (GeV/c)");
175  ((TProfile *) GetV2(GetNhistos()-1))->GetYaxis()->SetTitle("v_{2}");
176  }
177 }
178 
180  if(GetNhistos() == oth->GetNhistos()){
181  for(Int_t i=0;i < GetNhistos();i++){
182  GetV2(i)->Add(oth->GetV2(i));
183  }
184  return 0;
185  }
186  else{
187  printf("ADD error: number of objects is different (%i != %i)\n",GetNhistos(),oth->GetNhistos());
188  return 1;
189  }
190 }
191 
193  if(!GetNhistos()){
194  (*fXmin)[ivar]=xMin;
195  (*fXmax)[ivar]=xMax;
196  }
197  else{ // to avoid different range among the histos
198  printf("Ranges should be set before to define the species\nNOTHING DONE\n");
199  }
200 
201 }
202 
204  Int_t ncomb = 1;
205  Int_t histo = 0;
206 
207  for(Int_t i=0;i < GetNvar();i++){
208  Int_t ibin = GetBin(i,x[i]);
209  if(ibin < 0 || ibin >= (*fNbinVar)[i]){
210  printf("%i) %i not good w.r.t. %i (%f) (%f,%f)\n",i,ibin,(*fNbinVar)[i],x[i],(*fXmin)[i],(*fXmax)[i]);
211  return;
212  }
213  histo += ncomb * ibin;
214  ncomb *= (*fNbinVar)[i];
215  }
216  histo += species*ncomb;
217  DirectFill(histo,pt,v2);
218  };
219 
220 TProfile *AliFlowVZEROResults::GetV2(Int_t species,Float_t x[]) const{
221  Int_t ncomb = 1;
222  Int_t histo = 0;
223 
224  for(Int_t i=0;i < GetNvar();i++){
225  Int_t ibin = GetBin(i,x[i]);
226  if(ibin < 0 || ibin >= (*fNbinVar)[i]){
227  printf("%i) %i not good w.r.t. %i (%f) (%f,%f)\n",i,ibin,(*fNbinVar)[i],x[i],(*fXmin)[i],(*fXmax)[i]);
228  return NULL;
229  }
230  histo += ncomb * ibin;
231  ncomb *= (*fNbinVar)[i];
232  }
233  histo += species*ncomb;
234 
235 
236  return GetV2(histo);
237 
238 }
239 
240 TProfile *AliFlowVZEROResults::GetV2(Int_t species,Float_t xMin[],Float_t xMax[]) const{
241  if(GetNvar()){
242  char title[300];
243  char title2[300];
244  Int_t ncomb = 1;
245  for(Int_t i=0;i < GetNvar();i++){
246  ncomb *= (*fNbinVar)[i];
247  }
248 
249  TProfile *htemplate = GetV2(species*ncomb);
250  TProfile *temp = new TProfile(*htemplate);
251  temp->SetName("histo");
252  temp->Reset();
253  snprintf(title,300,"%i",species);
254  for(Int_t i=0;i < GetNvar();i++){
255  Int_t imin = GetBin(i,xMin[i]);
256  if(imin < 0) imin = 0;
257  else if(imin >= (*fNbinVar)[i]) imin = (*fNbinVar)[i]-1;
258  Int_t imax = GetBin(i,xMax[i]);
259  if(imax < imin) imax = imin;
260  else if(imax >= (*fNbinVar)[i]) imax = (*fNbinVar)[i]-1;
261  snprintf(title2,300,"%s",title);
262  snprintf(title,300,"%s_%04.1f<%s<%04.1f",title2,
263  (*fXmin)[i] + ((*fXmax)[i]-(*fXmin)[i])/(*fNbinVar)[i]*imin,
264  fNameVar->At(i)->GetName(),
265  (*fXmin)[i] + ((*fXmax)[i]-(*fXmin)[i])/(*fNbinVar)[i]*(imax+1));
266  }
267  temp->SetTitle(title);
268 
269  for(Int_t i=species*ncomb;i < (species+1)*ncomb;i++){
270  Bool_t kGood = kTRUE;
271 
272  Int_t ncombTemp = i;
273  for(Int_t j=0;j < GetNvar();j++){
274  Int_t imin = GetBin(j,xMin[j]);
275  if(imin < 0) imin = 0;
276  else if(imin >= (*fNbinVar)[j]) imin = (*fNbinVar)[j]-1;
277  Int_t imax = GetBin(j,xMax[j]);
278  if(imax < imin) imax = imin;
279  else if(imax >= (*fNbinVar)[j]) imax = (*fNbinVar)[j]-1;
280 
281  Int_t ibin = ncombTemp%(*fNbinVar)[j];
282  ncombTemp /= (*fNbinVar)[j];
283 
284  if(ibin < imin || ibin > imax){
285  kGood = kFALSE;
286  j = GetNvar();
287  }
288  }
289 
290  if(kGood) temp->Add(GetV2(i));
291  }
292  return temp;
293  }
294 
295  return GetV2(species);
296 }
297 TProfile *AliFlowVZEROResults::GetV2reweight(Int_t species,Float_t xMin[],Float_t xMax[],Int_t varRW,Float_t rw[]) const{
298  if(GetNvar()){
299  char title[300];
300  char title2[300];
301  Int_t ncomb = 1;
302  for(Int_t i=0;i < GetNvar();i++){
303  ncomb *= (*fNbinVar)[i];
304  }
305 
306  TProfile *htemplate = GetV2(species*ncomb);
307  TProfile *temp = new TProfile(*htemplate);
308  temp->SetName("histo");
309  temp->Reset();
310  snprintf(title,300,"%i",species);
311  for(Int_t i=0;i < GetNvar();i++){
312  Int_t imin = GetBin(i,xMin[i]);
313  if(imin < 0) imin = 0;
314  else if(imin >= (*fNbinVar)[i]) imin = (*fNbinVar)[i]-1;
315  Int_t imax = GetBin(i,xMax[i]);
316  if(imax < imin) imax = imin;
317  else if(imax >= (*fNbinVar)[i]) imax = (*fNbinVar)[i]-1;
318  snprintf(title2,300,"%s",title);
319  snprintf(title,300,"%s_%04.1f<%s<%04.1f",title2,
320  (*fXmin)[i] + ((*fXmax)[i]-(*fXmin)[i])/(*fNbinVar)[i]*imin,
321  fNameVar->At(i)->GetName(),
322  (*fXmin)[i] + ((*fXmax)[i]-(*fXmin)[i])/(*fNbinVar)[i]*(imax+1));
323  }
324  temp->SetTitle(title);
325 
326  for(Int_t i=species*ncomb;i < (species+1)*ncomb;i++){
327  Bool_t kGood = kTRUE;
328 
329  Int_t currentBin=0;
330 
331  Int_t ncombTemp = i;
332  for(Int_t j=0;j < GetNvar();j++){
333  Int_t imin = GetBin(j,xMin[j]);
334  if(imin < 0) imin = 0;
335  else if(imin >= (*fNbinVar)[j]) imin = (*fNbinVar)[j]-1;
336  Int_t imax = GetBin(j,xMax[j]);
337  if(imax < imin) imax = imin;
338  else if(imax >= (*fNbinVar)[j]) imax = (*fNbinVar)[j]-1;
339 
340  Int_t ibin = ncombTemp%(*fNbinVar)[j];
341  ncombTemp /= (*fNbinVar)[j];
342 
343  if(j == varRW) currentBin = ibin;
344 
345  if(ibin < imin || ibin > imax){
346  kGood = kFALSE;
347  j = GetNvar();
348  }
349  }
350 
351  if(kGood) temp->Add(GetV2(i),rw[currentBin]);
352  }
353  return temp;
354  }
355 
356  return GetV2(species);
357 }
358 
359 
361  Long64_t res=0;
362  if (!list) return 0;
363  if (list->IsEmpty()) return 0;
364 
365  TList *listObj = new TList();
366  listObj->AddAll(list);
367 
368  for(Int_t i=0;i < listObj->GetEntries();i++){
369  AliFlowVZEROResults *obj = (AliFlowVZEROResults *) listObj->At(i);
370  Add(obj);
371  res++;
372  }
373  return res;
374 }
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:27
long long Long64_t
Definition: External.C:43
void DirectFill(Int_t histo, Float_t pt, Float_t v2)
AliFlowVZEROResults & operator=(const AliFlowVZEROResults &source)
void Fill(Int_t species, Float_t pt, Float_t v2, Float_t x[])
Int_t GetNhistos() const
Int_t Add(const AliFlowVZEROResults *oth)
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
TProfile * GetV2(Int_t histo) const
void AddSpecies(const char *name, Int_t nXbin, const Double_t *bin)
Int_t GetBin(Int_t ivar, Float_t x) const
void SetVarRange(Int_t ivar, Float_t xMin, Float_t xMax)
bool Bool_t
Definition: External.C:53
const char * GetVarName(Int_t ivar) const
TProfile * GetV2reweight(Int_t species, Float_t xMin[], Float_t xMax[], Int_t varRW, Float_t rw[]) const
Long64_t Merge(TCollection *list)