-Move cent, z axis into sparse
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliGammaConversionAODBGHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: Ana Marin, Kathrin Koch, Kenneth Aamodt                        *
5  * Version 1.0                                                            *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////
17 //--------------------------------------------- 
18 // Class for handling of background calculation
19 //---------------------------------------------
20 ////////////////////////////////////////////////
21
22 #include "AliGammaConversionAODBGHandler.h"
23 #include "AliKFParticle.h"
24 #include "AliAODConversionPhoton.h"
25 #include "AliAODConversionMother.h"
26
27 using namespace std;
28
29 ClassImp(AliGammaConversionAODBGHandler)
30
31 AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler() :
32   TObject(),
33   fNEvents(10),
34   fBGEventCounter(NULL),
35   fBGEventENegCounter(NULL),
36   fBGProbability(NULL),
37   fBGEventVertex(NULL),
38   fNBinsZ(0),
39   fNBinsMultiplicity(0),
40   fBinLimitsArrayZ(NULL),
41   fBinLimitsArrayMultiplicity(NULL),
42   fBGEvents(),
43   fBGEventsENeg()
44 {
45   // constructor
46 }
47
48 AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler(UInt_t binsZ,UInt_t binsMultiplicity,UInt_t nEvents) :
49   TObject(),
50   fNEvents(nEvents),
51   fBGEventCounter(NULL),
52   fBGEventENegCounter(NULL),
53   fBGProbability(NULL),
54   fBGEventVertex(NULL),
55   fNBinsZ(binsZ),
56   fNBinsMultiplicity(binsMultiplicity),
57   fBinLimitsArrayZ(NULL),
58   fBinLimitsArrayMultiplicity(NULL),
59   fBGEvents(binsZ,AliGammaConversionMultipicityVector(binsMultiplicity,AliGammaConversionBGEventVector(nEvents))),
60   fBGEventsENeg(binsZ,AliGammaConversionMultipicityVector(binsMultiplicity,AliGammaConversionBGEventVector(nEvents)))
61 {
62   // constructor
63 }
64
65
66 AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler(UInt_t collisionSystem,UInt_t centMin,UInt_t centMax,UInt_t nEvents, Bool_t useTrackMult) :
67   TObject(),
68   fNEvents(nEvents),
69   fBGEventCounter(NULL),
70   fBGEventENegCounter(NULL),
71   fBGProbability(NULL),
72   fBGEventVertex(NULL),
73   fNBinsZ(8),
74   fNBinsMultiplicity(5),
75   fBinLimitsArrayZ(NULL),
76   fBinLimitsArrayMultiplicity(NULL),
77   fBGEvents(fNBinsZ,AliGammaConversionMultipicityVector(fNBinsMultiplicity,AliGammaConversionBGEventVector(nEvents))),
78   fBGEventsENeg(fNBinsZ,AliGammaConversionMultipicityVector(fNBinsMultiplicity,AliGammaConversionBGEventVector(nEvents)))
79 {
80   // constructor
81    
82    fBinLimitsArrayZ= new Double_t[8] ;
83    if(collisionSystem > 0 && collisionSystem < 8){ // PbPb
84       fBinLimitsArrayZ[0] = -50.00;
85       fBinLimitsArrayZ[1] = -5.5;
86       fBinLimitsArrayZ[2] = -2.9;
87       fBinLimitsArrayZ[3] = -0.65;
88       fBinLimitsArrayZ[4] = 1.45;
89       fBinLimitsArrayZ[5] = 3.65;
90       fBinLimitsArrayZ[6] = 6.15;
91       fBinLimitsArrayZ[7] = 50;
92    }
93    else if(collisionSystem == 0){
94       fBinLimitsArrayZ[0] = -50.00;
95       fBinLimitsArrayZ[1] = -3.375;
96       fBinLimitsArrayZ[2] = -1.605;
97       fBinLimitsArrayZ[3] = -0.225;
98       fBinLimitsArrayZ[4] = 1.065;
99       fBinLimitsArrayZ[5] = 2.445;
100       fBinLimitsArrayZ[6] = 4.245;
101       fBinLimitsArrayZ[7] = 50.00;
102    }
103    else{ 
104       fBinLimitsArrayZ[0] = -50.00;
105       fBinLimitsArrayZ[1] = -5.85;
106       fBinLimitsArrayZ[2] = -3.35;
107       fBinLimitsArrayZ[3] = -1.15;
108       fBinLimitsArrayZ[4] = 0.85;
109       fBinLimitsArrayZ[5] = 2.95;
110       fBinLimitsArrayZ[6] = 5.55;
111       fBinLimitsArrayZ[7] = 50.00;
112    }
113
114
115
116    fBinLimitsArrayMultiplicity= new Double_t[5];
117    if(useTrackMult){ // pp
118       fBinLimitsArrayMultiplicity[0] = 0;
119       fBinLimitsArrayMultiplicity[1] = 8.5;
120       fBinLimitsArrayMultiplicity[2] = 16.5;
121       fBinLimitsArrayMultiplicity[3] = 27.5;
122       fBinLimitsArrayMultiplicity[4] = 200.;
123       if(collisionSystem > 0 && collisionSystem < 8){ // PbPb
124          if(centMin == 0 && centMax == 5){
125             fBinLimitsArrayMultiplicity[0] = 0.;
126             fBinLimitsArrayMultiplicity[1] = 1540.;
127             fBinLimitsArrayMultiplicity[2] = 1665.;
128             fBinLimitsArrayMultiplicity[3] = 1780.;
129             fBinLimitsArrayMultiplicity[4] = 5000.;
130          }
131          else if(centMin == 0 && centMax == 10){
132             fBinLimitsArrayMultiplicity[0] = 0.;
133             fBinLimitsArrayMultiplicity[1] = 1360.;
134             fBinLimitsArrayMultiplicity[2] = 1520.;
135             fBinLimitsArrayMultiplicity[3] = 1685.;
136             fBinLimitsArrayMultiplicity[4] = 5000.;
137          }
138          else if(centMin == 0 && centMax == 20){
139             fBinLimitsArrayMultiplicity[0] = 0.;
140             fBinLimitsArrayMultiplicity[1] = 1110.;
141             fBinLimitsArrayMultiplicity[2] = 1360.;
142             fBinLimitsArrayMultiplicity[3] = 1600.;
143             fBinLimitsArrayMultiplicity[4] = 5000.;
144          }
145          else if(centMin == 0 && centMax == 80){
146             fBinLimitsArrayMultiplicity[0] = 0.;
147             fBinLimitsArrayMultiplicity[1] = 890.;
148             fBinLimitsArrayMultiplicity[2] = 1240.;
149             fBinLimitsArrayMultiplicity[3] = 1540.;
150             fBinLimitsArrayMultiplicity[4] = 5000.;
151          }
152          else if(centMin == 5 && centMax == 10){
153             fBinLimitsArrayMultiplicity[0] = 0.;
154             fBinLimitsArrayMultiplicity[1] = 1250.;
155             fBinLimitsArrayMultiplicity[2] = 1345.;
156             fBinLimitsArrayMultiplicity[3] = 1445.;
157             fBinLimitsArrayMultiplicity[4] = 5000.;
158          }
159          else if(centMin == 10 && centMax == 20){
160             fBinLimitsArrayMultiplicity[0] = 0.;
161             fBinLimitsArrayMultiplicity[1] = 915.;
162             fBinLimitsArrayMultiplicity[2] = 1020.;
163             fBinLimitsArrayMultiplicity[3] = 1130.;
164             fBinLimitsArrayMultiplicity[4] = 5000.;
165          }
166          else if(centMin == 20 && centMax == 40){
167             fBinLimitsArrayMultiplicity[0] = 0.;
168             fBinLimitsArrayMultiplicity[1] = 510.;
169             fBinLimitsArrayMultiplicity[2] = 625.;
170             fBinLimitsArrayMultiplicity[3] = 730.;
171             fBinLimitsArrayMultiplicity[4] = 5000.;
172          }
173          else if(centMin == 40 && centMax == 80){
174             fBinLimitsArrayMultiplicity[0] = 0.;
175             fBinLimitsArrayMultiplicity[1] = 185.;
176             fBinLimitsArrayMultiplicity[2] = 250.;
177             fBinLimitsArrayMultiplicity[3] = 300.;
178             fBinLimitsArrayMultiplicity[4] = 5000.;
179          }
180          else if(centMin == 60 && centMax == 80){
181             fBinLimitsArrayMultiplicity[0] = 0.;
182             fBinLimitsArrayMultiplicity[1] = 55.;
183             fBinLimitsArrayMultiplicity[2] = 80.;
184             fBinLimitsArrayMultiplicity[3] = 100.;
185             fBinLimitsArrayMultiplicity[4] = 5000.;
186          }
187          else{ // Std 20-40
188             fBinLimitsArrayMultiplicity[0] = 0.;
189             fBinLimitsArrayMultiplicity[1] = 510.;
190             fBinLimitsArrayMultiplicity[2] = 625.;
191             fBinLimitsArrayMultiplicity[3] = 730.;
192             fBinLimitsArrayMultiplicity[4] = 5000.;
193          }
194       }
195
196       else if(collisionSystem == 8 || collisionSystem == 9){ //pPb
197
198         fBinLimitsArrayMultiplicity[0] = 0.;
199         fBinLimitsArrayMultiplicity[1] = 7.5;
200         fBinLimitsArrayMultiplicity[2] = 16.5;
201         fBinLimitsArrayMultiplicity[3] = 29.5;
202         fBinLimitsArrayMultiplicity[4] = 500.;  
203         
204         if(centMin == 0 && centMax == 20){
205           fBinLimitsArrayMultiplicity[0] = 0.;
206           fBinLimitsArrayMultiplicity[1] = 31.5;
207           fBinLimitsArrayMultiplicity[2] = 40.5;
208           fBinLimitsArrayMultiplicity[3] = 50.5;
209           fBinLimitsArrayMultiplicity[4] = 500.;
210          }      
211         else if(centMin == 20 && centMax == 40){
212           fBinLimitsArrayMultiplicity[0] = 0.;
213           fBinLimitsArrayMultiplicity[1] = 19.5;
214           fBinLimitsArrayMultiplicity[2] = 25.5;
215           fBinLimitsArrayMultiplicity[3] = 32.5;
216           fBinLimitsArrayMultiplicity[4] = 500.;
217          }      
218         else if(centMin == 40 && centMax == 60){
219           fBinLimitsArrayMultiplicity[0] = 0.;
220           fBinLimitsArrayMultiplicity[1] = 12.5;
221           fBinLimitsArrayMultiplicity[2] = 16.5;
222           fBinLimitsArrayMultiplicity[3] = 22.5;
223           fBinLimitsArrayMultiplicity[4] = 500.;
224          }      
225         else if(centMin == 60 && centMax == 80){
226           fBinLimitsArrayMultiplicity[0] = 0.;
227           fBinLimitsArrayMultiplicity[1] = 5.5;
228           fBinLimitsArrayMultiplicity[2] = 9.5;
229           fBinLimitsArrayMultiplicity[3] = 13.5;
230           fBinLimitsArrayMultiplicity[4] = 500.;
231          }      
232       }
233    }
234    else{// pp or pPb V0 Mult
235       fBinLimitsArrayMultiplicity[0] = 2;
236       fBinLimitsArrayMultiplicity[1] = 3;
237       fBinLimitsArrayMultiplicity[2] = 4;
238       fBinLimitsArrayMultiplicity[3] = 5;
239       fBinLimitsArrayMultiplicity[4] = 9999;
240       if(collisionSystem > 0 && collisionSystem < 8){ // PbPb
241          if(centMin == 0 && centMax == 5){
242             fBinLimitsArrayMultiplicity[0] = 0.;
243             fBinLimitsArrayMultiplicity[1] = 27.;
244             fBinLimitsArrayMultiplicity[2] = 31.;
245             fBinLimitsArrayMultiplicity[3] = 36.;
246             fBinLimitsArrayMultiplicity[4] = 100.;
247          }
248          else if(centMin == 0 && centMax == 10){
249             fBinLimitsArrayMultiplicity[0] = 0.;
250             fBinLimitsArrayMultiplicity[1] = 25.;
251             fBinLimitsArrayMultiplicity[2] = 30.;
252             fBinLimitsArrayMultiplicity[3] = 36.;
253             fBinLimitsArrayMultiplicity[4] = 100.;
254          }
255          else if(centMin == 0 && centMax == 20){
256             fBinLimitsArrayMultiplicity[0] = 0.;
257             fBinLimitsArrayMultiplicity[1] = 22.;
258             fBinLimitsArrayMultiplicity[2] = 27.;
259             fBinLimitsArrayMultiplicity[3] = 33.;
260             fBinLimitsArrayMultiplicity[4] = 100.;
261          }
262          else if(centMin == 0 && centMax == 80){
263             fBinLimitsArrayMultiplicity[0] = 0.;
264             fBinLimitsArrayMultiplicity[1] = 18.;
265             fBinLimitsArrayMultiplicity[2] = 25.;
266             fBinLimitsArrayMultiplicity[3] = 32.;
267             fBinLimitsArrayMultiplicity[4] = 100.;
268          }
269          else if(centMin == 5 && centMax == 10){
270             fBinLimitsArrayMultiplicity[0] = 0.;
271             fBinLimitsArrayMultiplicity[1] = 23.;
272             fBinLimitsArrayMultiplicity[2] = 27.;
273             fBinLimitsArrayMultiplicity[3] = 32.;
274             fBinLimitsArrayMultiplicity[4] = 100.;
275          }
276          else if(centMin == 10 && centMax == 20){
277             fBinLimitsArrayMultiplicity[0] = 0.;
278             fBinLimitsArrayMultiplicity[1] = 18.;
279             fBinLimitsArrayMultiplicity[2] = 22.;
280             fBinLimitsArrayMultiplicity[3] = 27.;
281             fBinLimitsArrayMultiplicity[4] = 100.;
282          }
283          else if(centMin == 20 && centMax == 40){
284             fBinLimitsArrayMultiplicity[0] = 0.;
285             fBinLimitsArrayMultiplicity[1] = 11.;
286             fBinLimitsArrayMultiplicity[2] = 14.;
287             fBinLimitsArrayMultiplicity[3] = 18.;
288             fBinLimitsArrayMultiplicity[4] = 100.;
289          }
290          else if(centMin == 40 && centMax == 80){
291             fBinLimitsArrayMultiplicity[0] = 0.;
292             fBinLimitsArrayMultiplicity[1] = 5.;
293             fBinLimitsArrayMultiplicity[2] = 7.;
294             fBinLimitsArrayMultiplicity[3] = 11.;
295             fBinLimitsArrayMultiplicity[4] = 100.;
296          }
297          else if(centMin == 60 && centMax == 80){
298             fBinLimitsArrayMultiplicity[0] = 0.;
299             fBinLimitsArrayMultiplicity[1] = 2.;
300             fBinLimitsArrayMultiplicity[2] = 3.;
301             fBinLimitsArrayMultiplicity[3] = 5.;
302             fBinLimitsArrayMultiplicity[4] = 100.;
303          }
304          else{ // Std 20-40
305             fBinLimitsArrayMultiplicity[0] = 0.;
306             fBinLimitsArrayMultiplicity[1] = 11.;
307             fBinLimitsArrayMultiplicity[2] = 14.;
308             fBinLimitsArrayMultiplicity[3] = 18.;
309             fBinLimitsArrayMultiplicity[4] = 100.;
310          }
311       }
312    }
313    
314    Initialize(fBinLimitsArrayZ,fBinLimitsArrayMultiplicity);
315
316 }
317
318 AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler(const AliGammaConversionAODBGHandler & original) :
319   TObject(original),
320   fNEvents(original.fNEvents),
321   fBGEventCounter(original.fBGEventCounter),
322   fBGEventENegCounter(original.fBGEventENegCounter),
323   fBGProbability(original.fBGProbability),
324   fBGEventVertex(original.fBGEventVertex),
325   fNBinsZ(original.fNBinsZ),
326   fNBinsMultiplicity(original.fNBinsMultiplicity),
327   fBinLimitsArrayZ(original.fBinLimitsArrayZ),
328   fBinLimitsArrayMultiplicity(original.fBinLimitsArrayMultiplicity),
329   fBGEvents(original.fBGEvents),
330   fBGEventsENeg(original.fBGEventsENeg)
331 {
332   //copy constructor    
333 }
334
335 AliGammaConversionAODBGHandler & AliGammaConversionAODBGHandler::operator = (const AliGammaConversionAODBGHandler & /*source*/)
336 {
337   // assignment operator
338   return *this;
339 }
340
341 AliGammaConversionAODBGHandler::~AliGammaConversionAODBGHandler(){
342
343   //Kenneth remember to clear memory!!!!!!!!!!!!!!!!!!!!!
344   if(fBGEventCounter){
345     for(Int_t z=0;z<fNBinsZ;z++){
346       delete[] fBGEventCounter[z];
347     }
348     delete[] fBGEventCounter;
349     fBGEventCounter = NULL;
350   }
351
352   if(fBGEventVertex){
353     for(Int_t z=0;z<fNBinsZ;z++){
354       for(Int_t m=0;m<fNBinsMultiplicity;m++){
355         delete [] fBGEventVertex[z][m];
356       }
357       delete [] fBGEventVertex[z];
358     }
359     delete [] fBGEventVertex;
360   }
361
362    if(fBGEventENegCounter){
363     for(Int_t z=0;z<fNBinsZ;z++){
364       delete[] fBGEventENegCounter[z];
365     }
366     delete[] fBGEventENegCounter;
367     fBGEventENegCounter = NULL;
368   }
369
370   if(fBinLimitsArrayZ){
371     delete[] fBinLimitsArrayZ;
372   }
373
374   if(fBinLimitsArrayMultiplicity){
375     delete[] fBinLimitsArrayMultiplicity;
376   }
377 }
378
379 void AliGammaConversionAODBGHandler::Initialize(Double_t * const zBinLimitsArray, Double_t * const multiplicityBinLimitsArray){
380   // see header file for documantation  
381
382   if(zBinLimitsArray){
383     fBinLimitsArrayZ = zBinLimitsArray;
384   }
385   else{
386     //Print warning
387   }
388   
389   if(multiplicityBinLimitsArray){
390     fBinLimitsArrayMultiplicity = multiplicityBinLimitsArray ;
391   }
392   else{
393     //Print warning
394   }
395   if(fBGEventCounter == NULL){
396     fBGEventCounter= new Int_t*[fNBinsZ];
397   }
398   for(Int_t z=0;z<fNBinsZ;z++){
399     fBGEventCounter[z]=new Int_t[fNBinsMultiplicity];
400   }
401
402   for(Int_t z=0;z<fNBinsZ;z++){
403     for(Int_t m=0;m<fNBinsMultiplicity;m++){
404       fBGEventCounter[z][m]=0;
405     }
406   }
407
408   if(fBGEventVertex == NULL){
409     fBGEventVertex = new GammaConversionVertex**[fNBinsZ];
410   }
411   for(Int_t z=0; z < fNBinsZ; z++){
412     fBGEventVertex[z]= new GammaConversionVertex*[fNBinsMultiplicity];
413   }
414   for(Int_t z=0;z<fNBinsZ;z++){
415     for(Int_t m=0;m<fNBinsMultiplicity; m++){
416       fBGEventVertex[z][m]= new GammaConversionVertex[fNEvents];
417     }
418   }
419   if( fBGEventENegCounter == NULL){
420     fBGEventENegCounter = new Int_t*[fNBinsZ];
421   }
422
423   for(Int_t z=0; z < fNBinsZ; z++){
424     fBGEventENegCounter[z] = new Int_t[fNBinsMultiplicity];
425   }
426
427   for(Int_t z=0;z<fNBinsZ;z++){
428     for(Int_t m=0;m<fNBinsMultiplicity; m++){
429       fBGEventENegCounter[z][m] = 0;
430     }
431   }
432
433   if(fBGProbability == NULL){
434     fBGProbability = new Double_t*[fNBinsZ];
435   }
436   for(Int_t z=0; z < fNBinsZ; z++){
437     fBGProbability[z] = new Double_t[fNBinsMultiplicity];
438   }
439
440   for(Int_t z=0;z<fNBinsZ;z++){
441     for(Int_t m=0;m<fNBinsMultiplicity; m++){
442       fBGProbability[z][m] = 0;
443     }
444   }
445   //filling the probability
446   fBGProbability[0][0] = 0.243594;
447   fBGProbability[0][1] = 0.279477;
448   fBGProbability[0][2] = 0.305104;
449   fBGProbability[0][3] = 0.315927;
450   fBGProbability[1][0] = 0.241964;
451   fBGProbability[1][1] = 0.272995;
452   fBGProbability[1][2] = 0.307165;
453   fBGProbability[1][3] = 0.292248;
454   fBGProbability[2][0] = 0.241059;
455   fBGProbability[2][1] = 0.27509;
456   fBGProbability[2][2] = 0.283657;
457   fBGProbability[2][3] = 0.310512;
458   fBGProbability[3][0] = 0.23888;
459   fBGProbability[3][1] = 0.283418;
460   fBGProbability[3][2] = 0.297232;
461   fBGProbability[3][3] = 0.348188;
462   fBGProbability[4][0] = 0.245555;
463   fBGProbability[4][1] = 0.281218;
464   fBGProbability[4][2] = 0.317236;
465   fBGProbability[4][3] = 0.323495;
466   fBGProbability[5][0] = 0.244572;
467   fBGProbability[5][1] = 0.259498;
468   fBGProbability[5][2] = 0.278383;
469   fBGProbability[5][3] = 0.284696;
470   fBGProbability[6][0] = 0.24703;
471   fBGProbability[6][1] = 0.275265;
472   fBGProbability[6][2] = 0.284004;
473   fBGProbability[6][3] = 0.343584;
474  
475 }
476
477 Int_t AliGammaConversionAODBGHandler::GetZBinIndex(Double_t zvalue) const{
478   // see header file for documantation
479   if(fNBinsZ<2 || zvalue<=fBinLimitsArrayZ[0]){
480      return 0;
481   }
482
483   for(Int_t i=0; i<fNBinsZ-1 ;i++){
484     if(zvalue >= fBinLimitsArrayZ[i] && zvalue <= fBinLimitsArrayZ[i+1]){
485       return i;
486     }
487   }
488   return fNBinsZ-1;
489 }
490
491 Int_t AliGammaConversionAODBGHandler::GetMultiplicityBinIndex(Int_t multiplicity) const{
492   // see header file for documantation  
493   if(fNBinsMultiplicity<2){
494     return 0;
495   }
496
497   for(Int_t i=0; i<fNBinsMultiplicity-1 ;i++){
498     if(multiplicity >= fBinLimitsArrayMultiplicity[i] && multiplicity < fBinLimitsArrayMultiplicity[i+1]){
499       return i;
500     }
501   }
502   return fNBinsMultiplicity-1;
503 }
504
505 void AliGammaConversionAODBGHandler::AddEvent(TList* const eventGammas,Double_t xvalue, Double_t yvalue, Double_t zvalue, Int_t multiplicity){
506   // see header file for documantation  
507
508   //  cout<<"Entering the AddEvent function"<<endl;
509
510   Int_t z = GetZBinIndex(zvalue);
511   Int_t m = GetMultiplicityBinIndex(multiplicity);
512
513   if(fBGEventCounter[z][m] >= fNEvents){
514     fBGEventCounter[z][m]=0;
515   }
516   Int_t eventCounter=fBGEventCounter[z][m];
517   
518   /*
519   if(fBGEventVertex[z][m][eventCounter]){
520     delete fBGEventVertex[z][m][eventCounter];
521   }
522   */
523   fBGEventVertex[z][m][eventCounter].fX = xvalue;
524   fBGEventVertex[z][m][eventCounter].fY = yvalue;
525   fBGEventVertex[z][m][eventCounter].fZ = zvalue;
526
527   //first clear the vector
528   // cout<<"Size of vector: "<<fBGEvents[z][m][eventCounter].size()<<endl;
529   //  cout<<"Checking the entries: Z="<<z<<", M="<<m<<", eventCounter="<<eventCounter<<endl;
530
531   //  cout<<"The size of this vector is: "<<fBGEvents[z][m][eventCounter].size()<<endl;
532   for(UInt_t d=0;d<fBGEvents[z][m][eventCounter].size();d++){
533     delete (AliAODConversionPhoton*)(fBGEvents[z][m][eventCounter][d]);
534   }
535   fBGEvents[z][m][eventCounter].clear();
536   
537   // add the gammas to the vector
538   for(Int_t i=0; i< eventGammas->GetEntries();i++){
539     //    AliKFParticle *t = new AliKFParticle(*(AliKFParticle*)(eventGammas->At(i)));
540     fBGEvents[z][m][eventCounter].push_back(new AliAODConversionPhoton(*(AliAODConversionPhoton*)(eventGammas->At(i))));
541   }
542   fBGEventCounter[z][m]++;
543 }
544 void AliGammaConversionAODBGHandler::AddElectronEvent(TClonesArray* const eventENeg, Double_t zvalue, Int_t multiplicity){
545
546   Int_t z = GetZBinIndex(zvalue);
547   Int_t m = GetMultiplicityBinIndex(multiplicity);
548
549   if(fBGEventENegCounter[z][m] >= fNEvents){
550      fBGEventENegCounter[z][m]=0;
551   }
552  
553
554    Int_t eventENegCounter=fBGEventENegCounter[z][m];
555   
556   //first clear the vector
557   // cout<<"Size of vector: "<<fBGEvents[z][m][eventCounter].size()<<endl;
558   //  cout<<"Checking the entries: Z="<<z<<", M="<<m<<", eventCounter="<<eventCounter<<endl;
559
560   //  cout<<"The size of this vector is: "<<fBGEvents[z][m][eventCounter].size()<<endl;
561   for(UInt_t d=0;d<fBGEventsENeg[z][m][eventENegCounter].size();d++){
562     delete (AliAODConversionPhoton*)(fBGEventsENeg[z][m][eventENegCounter][d]);
563   }
564
565   fBGEventsENeg[z][m][eventENegCounter].clear();
566
567   // add the electron to the vector
568   for(Int_t i=0; i< eventENeg->GetEntriesFast();i++){
569     //    AliKFParticle *t = new AliKFParticle(*(AliKFParticle*)(eventGammas->At(i)));
570     fBGEventsENeg[z][m][eventENegCounter].push_back(new AliAODConversionPhoton(*(AliAODConversionPhoton*)(eventENeg->At(i))));
571   }
572
573   fBGEventENegCounter[z][m]++;
574
575
576 }
577 AliGammaConversionAODVector* AliGammaConversionAODBGHandler::GetBGGoodV0s(Int_t zbin, Int_t mbin, Int_t event){
578   //see headerfile for documentation
579   return &(fBGEvents[zbin][mbin][event]);
580 }
581 AliGammaConversionAODVector* AliGammaConversionAODBGHandler::GetBGGoodENeg(Int_t event, Double_t zvalue, Int_t multiplicity){
582
583
584   //see headerfile for documentation
585   Int_t z = GetZBinIndex(zvalue);
586   Int_t m = GetMultiplicityBinIndex(multiplicity);
587   return &(fBGEventsENeg[z][m][event]);
588
589
590 }
591 void AliGammaConversionAODBGHandler::PrintBGArray(){
592   //see headerfile for documentation
593   for(Int_t z=0;z<fNBinsZ;z++){
594     if(z==2){
595       cout<<"Getting the data for z bin: "<<z<<endl;
596       for(Int_t multiplicity=0;multiplicity<fNBinsMultiplicity;multiplicity++){
597         if(multiplicity==2){
598           cout<<"Getting the data for multiplicity bin: "<<multiplicity<<endl;  
599           for(Int_t event=0;event<fNEvents;event++){
600             if(fBGEvents[z][multiplicity][event].size()>0){
601               cout<<"Event: "<<event<<" has: "<<fBGEvents[z][multiplicity][event].size()<<endl;
602             }
603           }
604         }
605       }
606     }
607   }
608 }