]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/FEMTOSCOPY/AliFemto/AliFemtoEventReaderAOD.cxx
correction to AOD MC (sometimes going out of range in array) + new AddTask for Train
[u/mrichter/AliRoot.git] / PWGCF / FEMTOSCOPY / AliFemto / AliFemtoEventReaderAOD.cxx
1 ////////////////////////////////////////////////////////////////////////////////
2 //                                                                            //
3 // AliFemtoEventReaderAOD - the reader class for the Alice AOD                //
4 // Reads in AOD information and converts it into internal AliFemtoEvent       //
5 // Authors: Marek Chojnacki mchojnacki@knf.pw.edu.pl                          //
6 //          Adam Kisiel kisiel@mps.ohio-state.edu                             //
7 //                                                                            //
8 ////////////////////////////////////////////////////////////////////////////////
9
10 #include "AliFemtoEventReaderAOD.h"
11
12 #include "TFile.h"
13 #include "TTree.h"
14 #include "TRandom3.h"
15 #include "AliAODEvent.h"
16 #include "AliAODTrack.h"
17 #include "AliAODVertex.h"
18 #include "AliAODMCHeader.h"
19 #include "AliESDtrack.h"
20
21 #include "AliFmPhysicalHelixD.h"
22 #include "AliFmThreeVectorF.h"
23
24 #include "SystemOfUnits.h"
25
26 #include "AliFemtoEvent.h"
27 #include "AliFemtoModelHiddenInfo.h"
28 #include "AliFemtoModelGlobalHiddenInfo.h"
29 #include "AliPID.h"
30
31 #include "AliAODpidUtil.h"
32 #include "AliAnalysisUtils.h"
33
34 ClassImp(AliFemtoEventReaderAOD)
35
36 #if !(ST_NO_NAMESPACES)
37 using namespace units;
38 #endif
39
40 using namespace std;
41
42 double fV1[3];
43
44 //____________________________
45 //constructor with 0 parameters , look at default settings
46 AliFemtoEventReaderAOD::AliFemtoEventReaderAOD():
47   fNumberofEvent(0),
48   fCurEvent(0),
49   fEvent(0x0),
50   fAllTrue(160),
51   fAllFalse(160),
52   fFilterBit(0),
53   fFilterMask(0),
54   //  fPWG2AODTracks(0x0),
55   fReadMC(0),
56   fReadV0(0),
57   fUsePreCent(0),
58   fEstEventMult(kCentrality),
59   fAODpidUtil(0),
60   fAODheader(0),
61   fInputFile(""),
62   fTree(0x0),
63   fAodFile(0x0),
64   fMagFieldSign(1),
65   fisEPVZ(kTRUE),
66   fpA2013(kFALSE),
67   fisPileUp(kFALSE),
68   fMVPlp(kFALSE),
69   fMinVtxContr(0),
70   fMinPlpContribMV(0),
71   fMinPlpContribSPD(0),
72   fDCAglobalTrack(kFALSE),
73   fFlatCent(kFALSE)
74 {
75   // default constructor
76   fAllTrue.ResetAllBits(kTRUE);
77   fAllFalse.ResetAllBits(kFALSE);
78   fCentRange[0] = 0;
79   fCentRange[1] = 1000;
80 }
81
82 AliFemtoEventReaderAOD::AliFemtoEventReaderAOD(const AliFemtoEventReaderAOD &aReader) :
83   AliFemtoEventReader(),
84   fNumberofEvent(0),
85   fCurEvent(0),
86   fEvent(0x0),
87   fAllTrue(160),
88   fAllFalse(160),
89   fFilterBit(0),
90   fFilterMask(0),
91   //  fPWG2AODTracks(0x0),
92   fReadMC(0),
93   fReadV0(0),
94   fUsePreCent(0),
95   fEstEventMult(kCentrality),
96   fAODpidUtil(0),
97   fAODheader(0),
98   fInputFile(""),
99   fTree(0x0),
100   fAodFile(0x0),
101   fMagFieldSign(1),
102   fisEPVZ(kTRUE),
103   fpA2013(kFALSE),
104   fisPileUp(kFALSE),
105   fMVPlp(kFALSE),
106   fMinVtxContr(0),
107   fMinPlpContribMV(0),
108   fMinPlpContribSPD(0),
109   fDCAglobalTrack(kFALSE),
110   fFlatCent(kFALSE)
111 {
112   // copy constructor
113   fReadMC = aReader.fReadMC;
114   fReadV0 = aReader.fReadV0;
115   fInputFile = aReader.fInputFile;
116   fNumberofEvent = aReader.fNumberofEvent;
117   fCurEvent = aReader.fCurEvent;
118   fEvent = new AliAODEvent();
119   fAodFile = new TFile(aReader.fAodFile->GetName());
120   fAllTrue.ResetAllBits(kTRUE);
121   fAllFalse.ResetAllBits(kFALSE);
122   fFilterBit = aReader.fFilterBit;
123   //  fPWG2AODTracks = aReader.fPWG2AODTracks;
124   fAODpidUtil = aReader.fAODpidUtil;
125   fAODheader = aReader.fAODheader;
126   fCentRange[0] = aReader.fCentRange[0];
127   fCentRange[1] = aReader.fCentRange[1];
128   fEstEventMult = aReader.fEstEventMult;
129   fUsePreCent = aReader.fUsePreCent;
130   fpA2013 = aReader.fpA2013;
131   fisPileUp = aReader.fisPileUp;
132   fMVPlp = aReader.fMVPlp;
133   fMinVtxContr = aReader.fMinVtxContr;
134   fMinPlpContribMV = aReader.fMinPlpContribMV;
135   fMinPlpContribSPD = aReader.fMinPlpContribSPD;
136   fDCAglobalTrack = aReader.fDCAglobalTrack;
137
138 }
139 //__________________
140 //Destructor
141 AliFemtoEventReaderAOD::~AliFemtoEventReaderAOD()
142 {
143   // destructor
144   delete fTree;
145   delete fEvent;
146   delete fAodFile;
147 //   if (fPWG2AODTracks) {
148 //     fPWG2AODTracks->Delete();
149 //     delete fPWG2AODTracks;
150 //   }
151 }
152
153 //__________________
154 AliFemtoEventReaderAOD& AliFemtoEventReaderAOD::operator=(const AliFemtoEventReaderAOD& aReader)
155 {
156   // assignment operator
157   if (this == &aReader)
158     return *this;
159
160   fInputFile = aReader.fInputFile;
161   fNumberofEvent = aReader.fNumberofEvent;
162   fCurEvent = aReader.fCurEvent;
163   if (fTree) delete fTree;
164   if (fEvent) delete fEvent;
165   fEvent = new AliAODEvent();
166   if (fAodFile) delete fAodFile;
167   fAodFile = new TFile(aReader.fAodFile->GetName());
168   fAllTrue.ResetAllBits(kTRUE);
169   fAllFalse.ResetAllBits(kFALSE);
170   fFilterBit = aReader.fFilterBit;
171   fFilterMask = aReader.fFilterMask;
172   //  fPWG2AODTracks = aReader.fPWG2AODTracks;
173   fAODpidUtil = aReader.fAODpidUtil;
174   fAODheader = aReader.fAODheader;
175   fCentRange[0] = aReader.fCentRange[0];
176   fCentRange[1] = aReader.fCentRange[1];
177   fUsePreCent = aReader.fUsePreCent;
178   fEstEventMult = aReader.fEstEventMult;
179   fpA2013 = aReader.fpA2013;
180   fisPileUp = aReader.fisPileUp;
181   fMVPlp = aReader.fMVPlp;
182   fMinVtxContr = aReader.fMinVtxContr;
183   fMinPlpContribMV = aReader.fMinPlpContribMV;
184   fMinPlpContribSPD = aReader.fMinPlpContribSPD;
185   fDCAglobalTrack = aReader.fDCAglobalTrack;
186   fFlatCent= aReader.fFlatCent;
187
188   return *this;
189 }
190 //__________________
191 AliFemtoString AliFemtoEventReaderAOD::Report()
192 {
193   // create reader report
194   AliFemtoString temp = "\n This is the AliFemtoEventReaderAOD\n";
195   return temp;
196 }
197
198 //__________________
199 void AliFemtoEventReaderAOD::SetInputFile(const char* inputFile)
200 {
201   //setting the name of file where names of AOD file are written
202   //it takes only this files which have good trees
203   char buffer[256];
204   fInputFile=string(inputFile);
205   ifstream infile(inputFile);
206
207   fTree = new TChain("aodTree");
208
209   if(infile.good()==true)
210   {
211     //checking if all give files have good tree inside
212     while (infile.eof()==false)
213     {
214       infile.getline(buffer,256);
215       TFile *aodFile=TFile::Open(buffer,"READ");
216       if (aodFile!=0x0)
217             {
218               TTree* tree = (TTree*) aodFile->Get("aodTree");
219               if (tree!=0x0)
220         {
221           //              cout<<"putting file  "<<string(buffer)<<" into analysis"<<endl;
222           fTree->AddFile(buffer);
223           delete tree;
224         }
225               aodFile->Close();
226             }
227       delete aodFile;
228     }
229   }
230 }
231
232 AliFemtoEvent* AliFemtoEventReaderAOD::ReturnHbtEvent()
233 {
234   // read in a next hbt event from the chain
235   // convert it to AliFemtoEvent and return
236   // for further analysis
237   AliFemtoEvent *hbtEvent = 0;
238   // cout<<"reader"<<endl;
239   if (fCurEvent==fNumberofEvent)//open next file
240   {
241     if(fNumberofEvent==0)
242     {
243       fEvent=new AliAODEvent();
244       fEvent->ReadFromTree(fTree);
245
246       // Check for the existence of the additional information
247 //        fPWG2AODTracks = (TClonesArray *) fEvent->GetList()->FindObject("pwg2aodtracks");
248
249 //        if (fPWG2AODTracks) {
250 //          cout << "Found additional PWG2 specific information in the AOD!" << endl;
251 //          cout << "Reading only tracks with the additional information" << endl;
252 //        }
253
254       fNumberofEvent=fTree->GetEntries();
255       //          cout<<"Number of Entries in file "<<fNumberofEvent<<endl;
256       fCurEvent=0;
257     }
258     else //no more data to read
259     {
260       // cout<<"no more files "<<hbtEvent<<endl;
261       fReaderStatus=1;
262       return hbtEvent;
263     }
264   }
265
266   // cout<<"starting to read event "<<fCurEvent<<endl;
267   fTree->GetEvent(fCurEvent);//getting next event
268   //  cout << "Read event " << fEvent << " from file " << fTree << endl;
269
270   hbtEvent = new AliFemtoEvent;
271
272   CopyAODtoFemtoEvent(hbtEvent);
273   fCurEvent++;
274
275
276   return hbtEvent;
277 }
278
279 void AliFemtoEventReaderAOD::CopyAODtoFemtoEvent(AliFemtoEvent *tEvent)
280 {
281
282   // A function that reads in the AOD event
283   // and transfers the neccessary information into
284   // the internal AliFemtoEvent
285
286   // setting global event characteristics
287   tEvent->SetRunNumber(fEvent->GetRunNumber());
288   tEvent->SetMagneticField(fEvent->GetMagneticField()*kilogauss);//to check if here is ok
289   tEvent->SetZDCN1Energy(fEvent->GetZDCN1Energy());
290   tEvent->SetZDCP1Energy(fEvent->GetZDCP1Energy());
291   tEvent->SetZDCN2Energy(fEvent->GetZDCN2Energy());
292   tEvent->SetZDCP2Energy(fEvent->GetZDCP2Energy());
293   tEvent->SetZDCEMEnergy(fEvent->GetZDCEMEnergy(0));
294   tEvent->SetZDCParticipants(0);
295   tEvent->SetTriggerMask(fEvent->GetTriggerMask());
296   tEvent->SetTriggerCluster(fEvent->GetTriggerCluster());
297
298   // Attempt to access MC header
299   AliAODMCHeader *mcH;
300   TClonesArray *mcP=0;
301   if (fReadMC) {
302     mcH = (AliAODMCHeader *) fEvent->FindListObject(AliAODMCHeader::StdBranchName());
303     if (!mcH) {
304       cout << "AOD MC information requested, but no header found!" << endl;
305     }
306
307     mcP = (TClonesArray *) fEvent->FindListObject(AliAODMCParticle::StdBranchName());
308     if (!mcP) {
309       cout << "AOD MC information requested, but no particle array found!" << endl;
310     }
311   }
312
313   tEvent->SetReactionPlaneAngle(fEvent->GetHeader()->GetQTheta(0)/2.0);
314
315   Int_t *motherids=0;
316   if (mcP) {
317     const int motherTabSize = ((AliAODMCParticle *) mcP->At(mcP->GetEntries()-1))->GetLabel();
318     motherids = new int[motherTabSize+1];
319     for (int ip=0; ip<motherTabSize+1; ip++) motherids[ip] = 0;
320
321     // Read in mother ids
322     AliAODMCParticle *motherpart;
323     for (int ip=0; ip<mcP->GetEntries(); ip++) {
324       motherpart = (AliAODMCParticle *) mcP->At(ip);
325       if (motherpart->GetDaughter(0) > 0)
326         motherids[motherpart->GetDaughter(0)] = ip;
327       if (motherpart->GetDaughter(1) > 0)
328         motherids[motherpart->GetDaughter(1)] = ip;
329     }
330   }
331
332   //AliAnalysisUtils
333   if(fisPileUp||fpA2013)
334     {
335       AliAnalysisUtils *anaUtil=new AliAnalysisUtils();
336       if(fMinVtxContr)
337         anaUtil->SetMinVtxContr(fMinVtxContr);
338       if(fpA2013)
339         if(anaUtil->IsVertexSelected2013pA(fEvent)==kFALSE) return; //Vertex rejection for pA analysis.
340       if(fMVPlp) anaUtil->SetUseMVPlpSelection(kTRUE);
341       else anaUtil->SetUseMVPlpSelection(kFALSE);
342       if(fMinPlpContribMV) anaUtil->SetMinPlpContribMV(fMinPlpContribMV);
343       if(fMinPlpContribSPD) anaUtil->SetMinPlpContribSPD(fMinPlpContribSPD);
344       if(fisPileUp)
345         if(anaUtil->IsPileUpEvent(fEvent)) return; //Pile-up rejection.
346       delete anaUtil;   
347     }
348
349   // Primary Vertex position
350   const AliAODVertex* aodvertex = (AliAODVertex*) fEvent->GetPrimaryVertex();
351   if(!aodvertex || aodvertex->GetNContributors() < 1) return; //Bad vertex, skip event.
352
353   aodvertex->GetPosition(fV1);
354   AliFmThreeVectorF vertex(fV1[0],fV1[1],fV1[2]);
355   tEvent->SetPrimVertPos(vertex);
356
357   //starting to reading tracks
358   int nofTracks=0;  //number of reconstructed tracks in event
359
360   nofTracks=fEvent->GetNumberOfTracks();
361
362   AliEventplane *ep = fEvent->GetEventplane();
363   if (ep) {
364     tEvent->SetEP(ep);
365     if (fisEPVZ)
366       tEvent->SetReactionPlaneAngle(ep->GetEventplane("V0",fEvent,2));
367     else
368       tEvent->SetReactionPlaneAngle(ep->GetEventplane("Q"));
369   }
370
371   AliCentrality *cent = fEvent->GetCentrality();
372
373   if (!fEstEventMult && cent && fUsePreCent) {
374     if ((cent->GetCentralityPercentile("V0M")*10 < fCentRange[0]) ||
375         (cent->GetCentralityPercentile("V0M")*10 > fCentRange[1]))
376     {
377       // cout << "Centrality " << cent->GetCentralityPercentile("V0M") << " outside of preselection range " << fCentRange[0] << " - " << fCentRange[1] << endl;
378
379       return;
380     }
381   }
382
383   float percent = cent->GetCentralityPercentile("V0M");
384 //flatten centrality dist.
385   if(percent < 9){
386     if(fFlatCent){
387       if(RejectEventCentFlat(fEvent->GetMagneticField(),percent)) return;
388     }
389   }
390
391   int realnofTracks=0;   // number of track which we use in a analysis
392   int tracksPrim=0;
393
394   int labels[20000];
395   for (int il=0; il<20000; il++) labels[il] = -1;
396
397   // looking for global tracks and saving their numbers to copy from them PID information to TPC-only tracks in the main loop over tracks
398   for (int i=0;i<nofTracks;i++) {
399     const AliAODTrack *aodtrack=fEvent->GetTrack(i);
400     if (!aodtrack->TestFilterBit(fFilterBit)) {
401       if(aodtrack->GetID() < 0) continue;
402       labels[aodtrack->GetID()] = i;
403     }
404   }
405
406   int tNormMult = 0;
407   for (int i=0;i<nofTracks;i++)
408   {
409     AliFemtoTrack* trackCopy = new AliFemtoTrack();
410
411 //       if (fPWG2AODTracks) {
412 //      // Read tracks from the additional pwg2 specific AOD part
413 //      // if they exist
414 //      // Note that in that case all the AOD tracks without the
415 //      // additional information will be ignored !
416 //      AliPWG2AODTrack *pwg2aodtrack = (AliPWG2AODTrack *) fPWG2AODTracks->At(i);
417
418 //      // Getting the AOD track through the ref of the additional info
419 //      AliAODTrack *aodtrack = pwg2aodtrack->GetRefAODTrack();
420 //      if (!aodtrack->TestFilterBit(fFilterBit)) {
421 //        delete trackCopy;
422 //        continue;
423 //      }
424
425
426 //      if (aodtrack->IsOn(AliESDtrack::kTPCrefit))
427 //        if (aodtrack->Chi2perNDF() < 6.0)
428 //          if (aodtrack->Eta() < 0.9)
429 //            tNormMult++;
430
431
432 //      CopyAODtoFemtoTrack(aodtrack, trackCopy, pwg2aodtrack);
433
434 //      if (mcP) {
435 //        // Fill the hidden information with the simulated data
436 //        //      Int_t pLabel = aodtrack->GetLabel();
437 //        AliAODMCParticle *tPart = GetParticleWithLabel(mcP, (TMath::Abs(aodtrack->GetLabel())));
438
439 //        // Check the mother information
440
441 //        // Using the new way of storing the freeze-out information
442 //        // Final state particle is stored twice on the stack
443 //        // one copy (mother) is stored with original freeze-out information
444 //        //   and is not tracked
445 //        // the other one (daughter) is stored with primary vertex position
446 //        //   and is tracked
447
448 //        // Freeze-out coordinates
449 //        double fpx=0.0, fpy=0.0, fpz=0.0, fpt=0.0;
450 //        fpx = tPart->Xv() - fV1[0];
451 //        fpy = tPart->Yv() - fV1[1];
452 //        fpz = tPart->Zv() - fV1[2];
453 //        fpt = tPart->T();
454
455 //        AliFemtoModelGlobalHiddenInfo *tInfo = new AliFemtoModelGlobalHiddenInfo();
456 //        tInfo->SetGlobalEmissionPoint(fpx, fpy, fpz);
457
458 //        fpx *= 1e13;
459 //        fpy *= 1e13;
460 //        fpz *= 1e13;
461 //        fpt *= 1e13;
462
463 //        //      cout << "Looking for mother ids " << endl;
464 //        if (motherids[TMath::Abs(aodtrack->GetLabel())]>0) {
465 //          //  cout << "Got mother id" << endl;
466 //          AliAODMCParticle *mother = GetParticleWithLabel(mcP, motherids[TMath::Abs(aodtrack->GetLabel())]);
467 //          // Check if this is the same particle stored twice on the stack
468 //          if ((mother->GetPdgCode() == tPart->GetPdgCode() || (mother->Px() == tPart->Px()))) {
469 //            // It is the same particle
470 //            // Read in the original freeze-out information
471 //            // and convert it from to [fm]
472
473 //            // EPOS style
474 //            //          fpx = mother->Xv()*1e13*0.197327;
475 //            //          fpy = mother->Yv()*1e13*0.197327;
476 //            //          fpz = mother->Zv()*1e13*0.197327;
477 //            //          fpt = mother->T() *1e13*0.197327*0.5;
478
479
480 //            // Therminator style
481 //            fpx = mother->Xv()*1e13;
482 //            fpy = mother->Yv()*1e13;
483 //            fpz = mother->Zv()*1e13;
484 //            fpt = mother->T() *1e13*3e10;
485
486 //          }
487 //        }
488
489 //        //       if (fRotateToEventPlane) {
490 //        //    double tPhi = TMath::ATan2(fpy, fpx);
491 //        //    double tRad = TMath::Hypot(fpx, fpy);
492
493 //        //    fpx = tRad*TMath::Cos(tPhi - tReactionPlane);
494 //        //    fpy = tRad*TMath::Sin(tPhi - tReactionPlane);
495 //        //       }
496
497 //        tInfo->SetPDGPid(tPart->GetPdgCode());
498
499 //        //      if (fRotateToEventPlane) {
500 //        //        double tPhi = TMath::ATan2(tPart->Py(), tPart->Px());
501 //        //        double tRad = TMath::Hypot(tPart->Px(), tPart->Py());
502
503 //        //        tInfo->SetTrueMomentum(tRad*TMath::Cos(tPhi - tReactionPlane),
504 //        //                               tRad*TMath::Sin(tPhi - tReactionPlane),
505 //        //                               tPart->Pz());
506 //        //      }
507 //        //       else
508 //        tInfo->SetTrueMomentum(tPart->Px(), tPart->Py(), tPart->Pz());
509 //        Double_t mass2 = (tPart->E() *tPart->E() -
510 //                          tPart->Px()*tPart->Px() -
511 //                          tPart->Py()*tPart->Py() -
512 //                          tPart->Pz()*tPart->Pz());
513 //        if (mass2>0.0)
514 //          tInfo->SetMass(TMath::Sqrt(mass2));
515 //        else
516 //          tInfo->SetMass(0.0);
517
518 //        tInfo->SetEmissionPoint(fpx, fpy, fpz, fpt);
519 //        trackCopy->SetHiddenInfo(tInfo);
520
521 //      }
522
523 //      double pxyz[3];
524 //      aodtrack->PxPyPz(pxyz);//reading noconstarined momentum
525 //      const AliFmThreeVectorD ktP(pxyz[0],pxyz[1],pxyz[2]);
526 //      // Check the sanity of the tracks - reject zero momentum tracks
527 //      if (ktP.Mag() == 0) {
528 //        delete trackCopy;
529 //        continue;
530 //      }
531 //       }
532 //       else {
533     // No additional information exists
534     // Read in the normal AliAODTracks
535
536     //  const AliAODTrack *aodtrack=fEvent->GetTrack(i); // getting the AODtrack directly
537     AliAODTrack *aodtrack=fEvent->GetTrack(i); // getting the AODtrack directly
538
539
540
541     if (aodtrack->IsPrimaryCandidate()) tracksPrim++;
542
543     if (fFilterBit && !aodtrack->TestFilterBit(fFilterBit)) {
544       delete trackCopy;
545       continue;
546     }
547
548     if (fFilterMask && !aodtrack->TestFilterBit(fFilterMask)) {
549       delete trackCopy;
550       continue;
551     }
552
553     // cout << "Muon? " << aodtrack->IsMuonTrack() << endl;
554     // cout << "Type? " << aodtrack->GetType() << endl;
555
556     // if (aodtrack->IsMuonTrack()) {
557     //   cout << "muon" << endl;
558     //   delete trackCopy;
559     //   continue;
560     // }
561
562     //counting particles to set multiplicity
563     if(fEstEventMult==kGlobalCount){
564       AliAODTrack* trk_clone = (AliAODTrack*)aodtrack->Clone("trk_clone"); //no DCA cut for global count
565       //if (aodtrack->IsPrimaryCandidate()) //? instead of kinks?
566       if (aodtrack->Chi2perNDF() < 4.0)
567         if (aodtrack->Pt() > 0.15 && aodtrack->Pt() < 20)
568           if (aodtrack->GetTPCNcls() > 70)
569             if (aodtrack->Eta() < 0.8)
570               tNormMult++;
571       delete trk_clone;
572     }
573
574     CopyAODtoFemtoTrack(aodtrack, trackCopy);
575
576     // copying PID information from the correspondent track
577     //  const AliAODTrack *aodtrackpid = fEvent->GetTrack(labels[-1-fEvent->GetTrack(i)->GetID()]);
578
579
580     AliAODTrack *aodtrackpid;
581     if((fFilterBit ==  (1 << (7))) || fFilterMask == 128) {//for TPC Only tracks we have to copy PID information from corresponding global tracks
582       aodtrackpid = fEvent->GetTrack(labels[-1-fEvent->GetTrack(i)->GetID()]);
583     }
584     else {
585       aodtrackpid = fEvent->GetTrack(i);
586     }
587
588     CopyPIDtoFemtoTrack(aodtrackpid, trackCopy);
589
590     if (mcP) {
591       // Fill the hidden information with the simulated data
592       //          Int_t pLabel = aodtrack->GetLabel();
593       AliAODMCParticle *tPart = GetParticleWithLabel(mcP, (TMath::Abs(aodtrack->GetLabel())));
594
595       AliFemtoModelGlobalHiddenInfo *tInfo = new AliFemtoModelGlobalHiddenInfo();
596       double fpx=0.0, fpy=0.0, fpz=0.0, fpt=0.0;
597       if (!tPart) {
598         fpx = fV1[0];
599         fpy = fV1[1];
600         fpz = fV1[2];
601         tInfo->SetGlobalEmissionPoint(fpx, fpy, fpz);
602         tInfo->SetPDGPid(0);
603         tInfo->SetTrueMomentum(0.0, 0.0, 0.0);
604         tInfo->SetEmissionPoint(0.0, 0.0, 0.0, 0.0);
605         tInfo->SetMass(0);
606       }
607       else {
608         // Check the mother information
609
610         // Using the new way of storing the freeze-out information
611         // Final state particle is stored twice on the stack
612         // one copy (mother) is stored with original freeze-out information
613         //   and is not tracked
614         // the other one (daughter) is stored with primary vertex position
615         //   and is tracked
616
617         // Freeze-out coordinates
618         fpx = tPart->Xv() - fV1[0];
619         fpy = tPart->Yv() - fV1[1];
620         fpz = tPart->Zv() - fV1[2];
621         //        fpt = tPart->T();
622
623         tInfo->SetGlobalEmissionPoint(fpx, fpy, fpz);
624
625
626         fpx *= 1e13;
627         fpy *= 1e13;
628         fpz *= 1e13;
629         //        fpt *= 1e13;
630
631         //      cout << "Looking for mother ids " << endl;
632         if (motherids[TMath::Abs(aodtrack->GetLabel())]>0) {
633           //    cout << "Got mother id" << endl;
634           AliAODMCParticle *mother = GetParticleWithLabel(mcP, motherids[TMath::Abs(aodtrack->GetLabel())]);
635           // Check if this is the same particle stored twice on the stack
636           if (mother) {
637             if ((mother->GetPdgCode() == tPart->GetPdgCode() || (mother->Px() == tPart->Px()))) {
638               // It is the same particle
639               // Read in the original freeze-out information
640               // and convert it from to [fm]
641
642               // EPOS style
643               //          fpx = mother->Xv()*1e13*0.197327;
644               //          fpy = mother->Yv()*1e13*0.197327;
645               //          fpz = mother->Zv()*1e13*0.197327;
646               //          fpt = mother->T() *1e13*0.197327*0.5;
647
648
649               // Therminator style
650               fpx = mother->Xv()*1e13;
651               fpy = mother->Yv()*1e13;
652               fpz = mother->Zv()*1e13;
653               //              fpt = mother->T() *1e13*3e10;
654
655             }
656           }
657         }
658
659         //       if (fRotateToEventPlane) {
660         //      double tPhi = TMath::ATan2(fpy, fpx);
661         //      double tRad = TMath::Hypot(fpx, fpy);
662
663         //      fpx = tRad*TMath::Cos(tPhi - tReactionPlane);
664         //      fpy = tRad*TMath::Sin(tPhi - tReactionPlane);
665         //       }
666
667         tInfo->SetPDGPid(tPart->GetPdgCode());
668
669         //        if (fRotateToEventPlane) {
670         //          double tPhi = TMath::ATan2(tPart->Py(), tPart->Px());
671         //          double tRad = TMath::Hypot(tPart->Px(), tPart->Py());
672
673         //          tInfo->SetTrueMomentum(tRad*TMath::Cos(tPhi - tReactionPlane),
674         //                                 tRad*TMath::Sin(tPhi - tReactionPlane),
675         //                                 tPart->Pz());
676         //        }
677         //       else
678         tInfo->SetTrueMomentum(tPart->Px(), tPart->Py(), tPart->Pz());
679         Double_t mass2 = (tPart->E() *tPart->E() -
680                           tPart->Px()*tPart->Px() -
681                           tPart->Py()*tPart->Py() -
682                           tPart->Pz()*tPart->Pz());
683         if (mass2>0.0)
684           tInfo->SetMass(TMath::Sqrt(mass2));
685         else
686           tInfo->SetMass(0.0);
687
688         tInfo->SetEmissionPoint(fpx, fpy, fpz, fpt);
689
690         // // fillDCA
691         // //if (TMath::Abs(impact[0]) > 0.001) {
692         // if (tPart->IsPhysicalPrimary()){
693         //   tInfo->SetPartOrigin(0);
694         //   // trackCopy->SetImpactDprim(impact[0]);
695         //   //cout << "Read prim" << endl;
696         // }
697         // else if (tPart->IsSecondaryFromWeakDecay()) {
698         //   tInfo->SetPartOrigin(1);
699         //   // trackCopy->SetImpactDweak(impact[0]);
700         //   //cout << "Read wea" << endl;
701         // }
702         // else if (tPart->IsSecondaryFromMaterial()) {
703         //   tInfo->SetPartOrigin(2);
704         //   // trackCopy->SetImpactDmat(impact[0]);
705         //   //cout << "Read mat" << endl;
706         // }
707         // //}
708         // //  end fillDCA
709
710
711       }
712       trackCopy->SetHiddenInfo(tInfo);
713     }
714
715     double pxyz[3];
716
717     //AliExternalTrackParam *param = new AliExternalTrackParam(*aodtrack->GetInnerParam());
718     trackCopy->SetInnerMomentum(aodtrack->GetTPCmomentum());
719
720     aodtrack->PxPyPz(pxyz);//reading noconstarined momentum
721     const AliFmThreeVectorD ktP(pxyz[0],pxyz[1],pxyz[2]);
722     // Check the sanity of the tracks - reject zero momentum tracks
723     if (ktP.Mag() == 0) {
724       delete trackCopy;
725       continue;
726     }
727     //    }
728
729     tEvent->TrackCollection()->push_back(trackCopy);//adding track to analysis
730     realnofTracks++;//real number of tracks
731   }
732
733   tEvent->SetNumberOfTracks(realnofTracks);//setting number of track which we read in event
734   tEvent->SetNormalizedMult(tracksPrim);
735
736   if (cent) {
737     tEvent->SetCentralityV0(cent->GetCentralityPercentile("V0M"));
738     tEvent->SetCentralityV0A(cent->GetCentralityPercentile("V0A"));
739     tEvent->SetCentralityV0C(cent->GetCentralityPercentile("V0C"));
740     tEvent->SetCentralityZNA(cent->GetCentralityPercentile("ZNA"));
741     tEvent->SetCentralityZNC(cent->GetCentralityPercentile("ZNC"));
742     tEvent->SetCentralityCL1(cent->GetCentralityPercentile("CL1"));
743     tEvent->SetCentralityCL0(cent->GetCentralityPercentile("CL0"));
744     tEvent->SetCentralityTKL(cent->GetCentralityPercentile("TKL"));
745     tEvent->SetCentralityFMD(cent->GetCentralityPercentile("FMD"));
746     tEvent->SetCentralityFMD(cent->GetCentralityPercentile("NPA"));
747     //    tEvent->SetCentralitySPD1(cent->GetCentralityPercentile("CL1"));
748     tEvent->SetCentralityTrk(cent->GetCentralityPercentile("TRK"));
749     tEvent->SetCentralityCND(cent->GetCentralityPercentile("CND"));
750   }
751
752   if (fEstEventMult==kCentrality) {
753     //AliCentrality *cent = fEvent->GetCentrality();
754     //cout<<"AliFemtoEventReaderAOD:"<<lrint(10*cent->GetCentralityPercentile("V0M"))<<endl;
755     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("V0M")));
756     //  if (cent) tEvent->SetNormalizedMult((int) cent->GetCentralityPercentile("V0M"));
757   }
758   else if (fEstEventMult==kCentralityV0A) {
759     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("V0A")));
760   }
761   else if (fEstEventMult==kCentralityV0C) {
762     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("V0C")));
763   }
764   else if (fEstEventMult==kCentralityZNA) {
765     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("ZNA")));
766   }
767   else if (fEstEventMult==kCentralityZNC) {
768     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("ZNC")));
769   }
770   else if (fEstEventMult==kCentralityCL1) {
771     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("CL1")));
772   }
773   else if (fEstEventMult==kCentralityCL0) {
774     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("CL0")));
775   }
776   else if (fEstEventMult==kCentralityTRK) {
777     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("TRK")));
778   }
779   else if (fEstEventMult==kCentralityTKL) {
780     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("TKL")));
781   }
782   else if (fEstEventMult==kCentralityCND) {
783     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("CND")));
784   }
785   else if (fEstEventMult==kCentralityNPA) {
786     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("NPA")));
787   }
788   else if (fEstEventMult==kCentralityFMD) {
789     if (cent) tEvent->SetNormalizedMult(lrint(10*cent->GetCentralityPercentile("FMD")));
790   }
791   else if(fEstEventMult==kGlobalCount){
792     tEvent->SetNormalizedMult(tNormMult); //particles counted in the loop, trying to reproduce GetReferenceMultiplicity. If better (default) method appears it should be changed
793   }
794   else if(fEstEventMult==kReference)
795   {
796     tEvent->SetNormalizedMult(fAODheader->GetRefMultiplicity());
797   }
798   else if(fEstEventMult==kTPCOnlyRef)
799   {
800     tEvent->SetNormalizedMult(fAODheader->GetTPConlyRefMultiplicity());
801   }
802   else if(fEstEventMult == kVZERO)
803   {
804     Float_t multV0 = 0;
805     for (Int_t i=0; i<64; i++)
806       multV0 += fEvent->GetVZEROData()->GetMultiplicity(i);
807     tEvent->SetNormalizedMult(multV0);
808   }
809
810   if (mcP) delete [] motherids;
811
812   // cout<<"end of reading nt "<<nofTracks<<" real number "<<realnofTracks<<endl;
813
814   if(fReadV0)
815   {
816     int count_pass = 0;
817     for (Int_t i = 0; i < fEvent->GetNumberOfV0s(); i++) {
818       AliAODv0* aodv0 = fEvent->GetV0(i);
819       if (!aodv0) continue;
820       if(aodv0->GetNDaughters()>2) continue;
821       if(aodv0->GetNProngs()>2) continue;
822       if(aodv0->GetCharge()!=0) continue;
823       if(aodv0->ChargeProng(0)==aodv0->ChargeProng(1)) continue;
824       if(aodv0->CosPointingAngle(fV1)<0.998) continue;
825       AliFemtoV0* trackCopyV0 = new AliFemtoV0();
826       count_pass++;
827       CopyAODtoFemtoV0(aodv0, trackCopyV0);
828       tEvent->V0Collection()->push_back(trackCopyV0);
829       //cout<<"Pushback v0 to v0collection"<<endl;
830     }
831   }
832
833 }
834
835 void AliFemtoEventReaderAOD::CopyAODtoFemtoTrack(AliAODTrack *tAodTrack,
836                                                  AliFemtoTrack *tFemtoTrack
837                                                  //                                              AliPWG2AODTrack *tPWG2AODTrack
838   )
839 {
840   // Copy the track information from the AOD into the internal AliFemtoTrack
841   // If it exists, use the additional information from the PWG2 AOD
842
843   // Primary Vertex position
844
845   fEvent->GetPrimaryVertex()->GetPosition(fV1);
846   //  fEvent->GetPrimaryVertex()->GetXYZ(fV1);
847
848   tFemtoTrack->SetCharge(tAodTrack->Charge());
849
850   double pxyz[3];
851   tAodTrack->PxPyPz(pxyz);//reading noconstrained momentum
852
853   AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
854   tFemtoTrack->SetP(v);//setting momentum
855   tFemtoTrack->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
856   const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
857   //setting track helix
858   const AliFmThreeVectorD ktP(pxyz[0],pxyz[1],pxyz[2]);
859   AliFmPhysicalHelixD helix(ktP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(tFemtoTrack->Charge()));
860   tFemtoTrack->SetHelix(helix);
861
862   // Flags
863   tFemtoTrack->SetTrackId(tAodTrack->GetID());
864   tFemtoTrack->SetFlags(tAodTrack->GetFlags());
865   tFemtoTrack->SetLabel(tAodTrack->GetLabel());
866
867   // Track quality information
868   float covmat[6];
869   tAodTrack->GetCovMatrix(covmat);
870
871   if (!fDCAglobalTrack) {
872
873     tFemtoTrack->SetImpactD(tAodTrack->DCA());
874     tFemtoTrack->SetImpactZ(tAodTrack->ZAtDCA());
875
876
877     // double impact[2];
878     // double covimpact[3];
879
880     // AliAODTrack* trk_clone = (AliAODTrack*)tAodTrack->Clone("trk_clone");
881     // // if(!trk_clone->PropagateToDCA(fAODVertex,aod->GetMagneticField(),300.,dca,cov)) continue;
882     // // if (!tAodTrack->PropagateToDCA(fEvent->GetPrimaryVertex(),fEvent->GetMagneticField(),10000,impact,covimpact)) {
883     // if (!trk_clone->PropagateToDCA(fEvent->GetPrimaryVertex(),fEvent->GetMagneticField(),10000,impact,covimpact)) {
884     //   //cout << "sth went wrong with dca propagation" << endl;
885     //   tFemtoTrack->SetImpactD(-1000.0);
886     //   tFemtoTrack->SetImpactZ(-1000.0);
887
888     // }
889     // else {
890     //   tFemtoTrack->SetImpactD(impact[0]);
891     //   tFemtoTrack->SetImpactZ(impact[1]);
892     // }
893     // delete trk_clone;
894
895   }
896
897   //   if (TMath::Abs(tAodTrack->Xv()) > 0.00000000001)
898   //     tFemtoTrack->SetImpactD(TMath::Hypot(tAodTrack->Xv(), tAodTrack->Yv())*(tAodTrack->Xv()/TMath::Abs(tAodTrack->Xv())));
899   //   else
900   //     tFemtoTrack->SetImpactD(0.0);
901   //   tFemtoTrack->SetImpactD(tAodTrack->DCA());
902
903   //   tFemtoTrack->SetImpactZ(tAodTrack->ZAtDCA());
904
905
906   //   tFemtoTrack->SetImpactD(TMath::Hypot(tAodTrack->Xv() - fV1[0], tAodTrack->Yv() - fV1[1]));
907   //   tFemtoTrack->SetImpactZ(tAodTrack->Zv() - fV1[2]);
908
909
910   //   cout
911   //    << "dca" << TMath::Hypot(tAodTrack->Xv() - fV1[0], tAodTrack->Yv() - fV1[1])
912   //    << "xv - fv10 = "<< tAodTrack->Xv() - fV1[0]
913   //    << tAodTrack->Yv() - fV1[1]
914 //     << "xv = " << tAodTrack->Xv() << endl
915 //     << "fv1[0] = " << fV1[0]  << endl
916 //     << "yv = " << tAodTrack->Yv()  << endl
917 //     << "fv1[1] = " << fV1[1]  << endl
918 //     << "zv = " << tAodTrack->Zv()  << endl
919 //     << "fv1[2] = " << fV1[2]  << endl
920 //     << "impact[0] = " << impact[0]  << endl
921 //     << "impact[1] = " << impact[1]  << endl
922 //     << endl << endl ;
923
924   tFemtoTrack->SetCdd(covmat[0]);
925   tFemtoTrack->SetCdz(covmat[1]);
926   tFemtoTrack->SetCzz(covmat[2]);
927   tFemtoTrack->SetITSchi2(tAodTrack->Chi2perNDF());
928   tFemtoTrack->SetITSncls(tAodTrack->GetITSNcls());
929   tFemtoTrack->SetTPCchi2(tAodTrack->Chi2perNDF());
930   tFemtoTrack->SetTPCncls(tAodTrack->GetTPCNcls());
931   tFemtoTrack->SetTPCnclsF(tAodTrack->GetTPCNcls());
932   tFemtoTrack->SetTPCsignalN(1);
933   tFemtoTrack->SetTPCsignalS(1);
934   tFemtoTrack->SetTPCsignal(tAodTrack->GetTPCsignal());
935
936 //   if (tPWG2AODTrack) {
937 //     // Copy the PWG2 specific information if it exists
938 //     tFemtoTrack->SetTPCClusterMap(tPWG2AODTrack->GetTPCClusterMap());
939 //     tFemtoTrack->SetTPCSharedMap(tPWG2AODTrack->GetTPCSharedMap());
940
941 //     double xtpc[3] = {0,0,0};
942 //     tPWG2AODTrack->GetTPCNominalEntrancePoint(xtpc);
943 //     tFemtoTrack->SetNominalTPCEntrancePoint(xtpc);
944 //     tPWG2AODTrack->GetTPCNominalExitPoint(xtpc);
945 //     tFemtoTrack->SetNominalTPCExitPoint(xtpc);
946 //   }
947 //   else {
948   // If not use dummy values
949   tFemtoTrack->SetTPCClusterMap(tAodTrack->GetTPCClusterMap());
950   tFemtoTrack->SetTPCSharedMap(tAodTrack->GetTPCSharedMap());
951
952   float globalPositionsAtRadii[9][3];
953   float bfield = 5*fMagFieldSign;
954
955   GetGlobalPositionAtGlobalRadiiThroughTPC(tAodTrack,bfield,globalPositionsAtRadii);
956   double tpcEntrance[3]={globalPositionsAtRadii[0][0],globalPositionsAtRadii[0][1],globalPositionsAtRadii[0][2]};
957   double **tpcPositions;
958   tpcPositions = new double*[9];
959   for(int i=0;i<9;i++)
960     tpcPositions[i] = new double[3];
961   double tpcExit[3]={globalPositionsAtRadii[8][0],globalPositionsAtRadii[8][1],globalPositionsAtRadii[8][2]};
962   for(int i=0;i<9;i++)
963   {
964     tpcPositions[i][0] = globalPositionsAtRadii[i][0];
965     tpcPositions[i][1] = globalPositionsAtRadii[i][1];
966     tpcPositions[i][2] = globalPositionsAtRadii[i][2];
967   }
968
969   tFemtoTrack->SetNominalTPCEntrancePoint(tpcEntrance);
970   tFemtoTrack->SetNominalTPCPoints(tpcPositions);
971   tFemtoTrack->SetNominalTPCExitPoint(tpcExit);
972   for(int i=0;i<9;i++)
973     delete [] tpcPositions[i];
974   delete [] tpcPositions;
975   //   }
976
977   //   //  cout << "Track has " << TMath::Hypot(tAodTrack->Xv(), tAodTrack->Yv()) << "  " << tAodTrack->Zv() << "  " << tAodTrack->GetTPCNcls() << endl;
978
979
980   int indexes[3];
981   for (int ik=0; ik<3; ik++) {
982     indexes[ik] = 0;
983   }
984   tFemtoTrack->SetKinkIndexes(indexes);
985
986
987   for (int ii=0; ii<6; ii++){
988     tFemtoTrack->SetITSHitOnLayer(ii,tAodTrack->HasPointOnITSLayer(ii));
989   }
990
991
992 }
993
994 void AliFemtoEventReaderAOD::CopyAODtoFemtoV0(AliAODv0 *tAODv0, AliFemtoV0 *tFemtoV0)
995 {
996   tFemtoV0->SetdecayLengthV0(tAODv0->DecayLength(fV1));
997   tFemtoV0->SetdecayVertexV0X(tAODv0->DecayVertexV0X());
998   tFemtoV0->SetdecayVertexV0Y(tAODv0->DecayVertexV0Y());
999   tFemtoV0->SetdecayVertexV0Z(tAODv0->DecayVertexV0Z());
1000   AliFemtoThreeVector decayvertex(tAODv0->DecayVertexV0X(),tAODv0->DecayVertexV0Y(),tAODv0->DecayVertexV0Z());
1001   tFemtoV0->SetdecayVertexV0(decayvertex);
1002   tFemtoV0->SetdcaV0Daughters(tAODv0->DcaV0Daughters());
1003   tFemtoV0->SetdcaV0ToPrimVertex(tAODv0->DcaV0ToPrimVertex());
1004   tFemtoV0->SetdcaPosToPrimVertex(tAODv0->DcaPosToPrimVertex());
1005   tFemtoV0->SetdcaNegToPrimVertex(tAODv0->DcaNegToPrimVertex());
1006   tFemtoV0->SetmomPosX(tAODv0->MomPosX());
1007   tFemtoV0->SetmomPosY(tAODv0->MomPosY());
1008   tFemtoV0->SetmomPosZ(tAODv0->MomPosZ());
1009   AliFemtoThreeVector mompos(tAODv0->MomPosX(),tAODv0->MomPosY(),tAODv0->MomPosZ());
1010   tFemtoV0->SetmomPos(mompos);
1011   tFemtoV0->SetmomNegX(tAODv0->MomNegX());
1012   tFemtoV0->SetmomNegY(tAODv0->MomNegY());
1013   tFemtoV0->SetmomNegZ(tAODv0->MomNegZ());
1014   AliFemtoThreeVector momneg(tAODv0->MomNegX(),tAODv0->MomNegY(),tAODv0->MomNegZ());
1015   tFemtoV0->SetmomNeg(momneg);
1016
1017   //jest cos takiego w AliFemtoV0.h czego nie ma w AliAODv0.h
1018   //void SettpcHitsPos(const int& i);
1019   //void SettpcHitsNeg(const int& i);
1020
1021   //void SetTrackTopologyMapPos(unsigned int word, const unsigned long& m);
1022   //void SetTrackTopologyMapNeg(unsigned int word, const unsigned long& m);
1023
1024   tFemtoV0->SetmomV0X(tAODv0->MomV0X());
1025   tFemtoV0->SetmomV0Y(tAODv0->MomV0Y());
1026   tFemtoV0->SetmomV0Z(tAODv0->MomV0Z());
1027   AliFemtoThreeVector momv0(tAODv0->MomV0X(),tAODv0->MomV0Y(),tAODv0->MomV0Z());
1028   tFemtoV0->SetmomV0(momv0);
1029   tFemtoV0->SetalphaV0(tAODv0->AlphaV0());
1030   tFemtoV0->SetptArmV0(tAODv0->PtArmV0());
1031   tFemtoV0->SeteLambda(tAODv0->ELambda());
1032   tFemtoV0->SeteK0Short(tAODv0->EK0Short());
1033   tFemtoV0->SetePosProton(tAODv0->EPosProton());
1034   tFemtoV0->SeteNegProton(tAODv0->ENegProton());
1035   tFemtoV0->SetmassLambda(tAODv0->MassLambda());
1036   tFemtoV0->SetmassAntiLambda(tAODv0->MassAntiLambda());
1037   tFemtoV0->SetmassK0Short(tAODv0->MassK0Short());
1038   tFemtoV0->SetrapLambda(tAODv0->RapLambda());
1039   tFemtoV0->SetrapK0Short(tAODv0->RapK0Short());
1040
1041   //void SetcTauLambda( float x);
1042   //void SetcTauK0Short( float x);
1043
1044   //tFemtoV0->SetptV0(::sqrt(tAODv0->Pt2V0())); //!
1045   tFemtoV0->SetptV0(tAODv0->Pt());
1046   tFemtoV0->SetptotV0(::sqrt(tAODv0->Ptot2V0()));
1047   //tFemtoV0->SetptPos(::sqrt(tAODv0->MomPosX()*tAODv0->MomPosX()+tAODv0->MomPosY()*tAODv0->MomPosY()));
1048   //tFemtoV0->SetptotPos(::sqrt(tAODv0->Ptot2Pos()));
1049   //tFemtoV0->SetptNeg(::sqrt(tAODv0->MomNegX()*tAODv0->MomNegX()+tAODv0->MomNegY()*tAODv0->MomNegY()));
1050   //tFemtoV0->SetptotNeg(::sqrt(tAODv0->Ptot2Neg()));
1051
1052   tFemtoV0->SetidNeg(tAODv0->GetNegID());
1053   //cout<<"tAODv0->GetNegID(): "<<tAODv0->GetNegID()<<endl;
1054   //cout<<"tFemtoV0->IdNeg(): "<<tFemtoV0->IdNeg()<<endl;
1055   tFemtoV0->SetidPos(tAODv0->GetPosID());
1056
1057   tFemtoV0->SetEtaV0(tAODv0->Eta());
1058   tFemtoV0->SetPhiV0(tAODv0->Phi());
1059   tFemtoV0->SetCosPointingAngle(tAODv0->CosPointingAngle(fV1));
1060   //tFemtoV0->SetYV0(tAODv0->Y());
1061
1062   //void SetdedxNeg(float x);
1063   //void SeterrdedxNeg(float x);//Gael 04Fev2002
1064   //void SetlendedxNeg(float x);//Gael 04Fev2002
1065   //void SetdedxPos(float x);
1066   //void SeterrdedxPos(float x);//Gael 04Fev2002
1067   //void SetlendedxPos(float x);//Gael 04Fev2002
1068
1069   //tFemtoV0->SetEtaPos(tAODv0->PseudoRapPos());
1070   //tFemtoV0->SetEtaNeg(tAODv0->PseudoRapNeg());
1071
1072   AliAODTrack *trackpos = (AliAODTrack*)tAODv0->GetDaughter(0);
1073   AliAODTrack *trackneg = (AliAODTrack*)tAODv0->GetDaughter(1);
1074
1075   if(trackpos && trackneg)
1076   {
1077     tFemtoV0->SetEtaPos(trackpos->Eta());
1078     tFemtoV0->SetEtaNeg(trackneg->Eta());
1079     tFemtoV0->SetptotPos(tAODv0->PProng(0));
1080     tFemtoV0->SetptotNeg(tAODv0->PProng(1));
1081     tFemtoV0->SetptPos(trackpos->Pt());
1082     tFemtoV0->SetptNeg(trackneg->Pt());
1083
1084     //tFemtoV0->SetEtaPos(trackpos->Eta()); //tAODv0->PseudoRapPos()
1085     //tFemtoV0->SetEtaNeg(trackneg->Eta()); //tAODv0->PseudoRapNeg()
1086     tFemtoV0->SetTPCNclsPos(trackpos->GetTPCNcls());
1087     tFemtoV0->SetTPCNclsNeg(trackneg->GetTPCNcls());
1088     tFemtoV0->SetTPCclustersPos(trackpos->GetTPCClusterMap());
1089     tFemtoV0->SetTPCclustersNeg(trackneg->GetTPCClusterMap());
1090     tFemtoV0->SetTPCsharingPos(trackpos->GetTPCSharedMap());
1091     tFemtoV0->SetTPCsharingNeg(trackneg->GetTPCSharedMap());
1092     tFemtoV0->SetNdofPos(trackpos->Chi2perNDF());
1093     tFemtoV0->SetNdofNeg(trackneg->Chi2perNDF());
1094     tFemtoV0->SetStatusPos(trackpos->GetStatus());
1095     tFemtoV0->SetStatusNeg(trackneg->GetStatus());
1096
1097     tFemtoV0->SetPosNSigmaTPCK(fAODpidUtil->NumberOfSigmasTPC(trackpos,AliPID::kKaon));
1098     tFemtoV0->SetNegNSigmaTPCK(fAODpidUtil->NumberOfSigmasTPC(trackneg,AliPID::kKaon));
1099     tFemtoV0->SetPosNSigmaTPCP(fAODpidUtil->NumberOfSigmasTPC(trackpos,AliPID::kProton));
1100     tFemtoV0->SetNegNSigmaTPCP(fAODpidUtil->NumberOfSigmasTPC(trackneg,AliPID::kProton));
1101     tFemtoV0->SetPosNSigmaTPCPi(fAODpidUtil->NumberOfSigmasTPC(trackpos,AliPID::kPion));
1102     tFemtoV0->SetNegNSigmaTPCPi(fAODpidUtil->NumberOfSigmasTPC(trackneg,AliPID::kPion));
1103
1104
1105     float bfield = 5*fMagFieldSign;
1106     float globalPositionsAtRadiiPos[9][3];
1107     GetGlobalPositionAtGlobalRadiiThroughTPC(trackpos,bfield,globalPositionsAtRadiiPos);
1108     double tpcEntrancePos[3]={globalPositionsAtRadiiPos[0][0],globalPositionsAtRadiiPos[0][1],globalPositionsAtRadiiPos[0][2]};
1109     double tpcExitPos[3]={globalPositionsAtRadiiPos[8][0],globalPositionsAtRadiiPos[8][1],globalPositionsAtRadiiPos[8][2]};
1110
1111     float globalPositionsAtRadiiNeg[9][3];
1112     GetGlobalPositionAtGlobalRadiiThroughTPC(trackneg,bfield,globalPositionsAtRadiiNeg);
1113     double tpcEntranceNeg[3]={globalPositionsAtRadiiNeg[0][0],globalPositionsAtRadiiNeg[0][1],globalPositionsAtRadiiNeg[0][2]};
1114     double tpcExitNeg[3]={globalPositionsAtRadiiNeg[8][0],globalPositionsAtRadiiNeg[8][1],globalPositionsAtRadiiNeg[8][2]};
1115
1116     AliFemtoThreeVector tmpVec;
1117     tmpVec.SetX(tpcEntrancePos[0]); tmpVec.SetY(tpcEntrancePos[1]); tmpVec.SetZ(tpcEntrancePos[2]);
1118     tFemtoV0->SetNominalTpcEntrancePointPos(tmpVec);
1119
1120     tmpVec.SetX(tpcExitPos[0]); tmpVec.SetY(tpcExitPos[1]); tmpVec.SetZ(tpcExitPos[2]);
1121     tFemtoV0->SetNominalTpcExitPointPos(tmpVec);
1122
1123     tmpVec.SetX(tpcEntranceNeg[0]); tmpVec.SetY(tpcEntranceNeg[1]); tmpVec.SetZ(tpcEntranceNeg[2]);
1124     tFemtoV0->SetNominalTpcEntrancePointNeg(tmpVec);
1125
1126     tmpVec.SetX(tpcExitNeg[0]); tmpVec.SetY(tpcExitNeg[1]); tmpVec.SetZ(tpcExitNeg[2]);
1127     tFemtoV0->SetNominalTpcExitPointNeg(tmpVec);
1128
1129     AliFemtoThreeVector vecTpcPos[9];
1130     AliFemtoThreeVector vecTpcNeg[9];
1131     for(int i=0;i<9;i++)
1132     {
1133       vecTpcPos[i].SetX(globalPositionsAtRadiiPos[i][0]); vecTpcPos[i].SetY(globalPositionsAtRadiiPos[i][1]); vecTpcPos[i].SetZ(globalPositionsAtRadiiPos[i][2]);
1134       vecTpcNeg[i].SetX(globalPositionsAtRadiiNeg[i][0]); vecTpcNeg[i].SetY(globalPositionsAtRadiiNeg[i][1]); vecTpcNeg[i].SetZ(globalPositionsAtRadiiNeg[i][2]);
1135     }
1136     tFemtoV0->SetNominalTpcPointPos(vecTpcPos);
1137     tFemtoV0->SetNominalTpcPointNeg(vecTpcNeg);
1138
1139     tFemtoV0->SetTPCMomentumPos(trackpos->GetTPCmomentum());
1140     tFemtoV0->SetTPCMomentumNeg(trackneg->GetTPCmomentum());
1141
1142     tFemtoV0->SetdedxPos(trackpos->GetTPCsignal());
1143     tFemtoV0->SetdedxNeg(trackneg->GetTPCsignal());
1144
1145     if((tFemtoV0->StatusPos()&AliESDtrack::kTOFpid)==0 || (tFemtoV0->StatusPos()&AliESDtrack::kTIME)==0 || (tFemtoV0->StatusPos()&AliESDtrack::kTOFout)==0 )
1146     {
1147       if((tFemtoV0->StatusNeg()&AliESDtrack::kTOFpid)==0 || (tFemtoV0->StatusNeg()&AliESDtrack::kTIME)==0 || (tFemtoV0->StatusNeg()&AliESDtrack::kTOFout)==0 )
1148             {
1149               tFemtoV0->SetPosNSigmaTOFK(-1000);
1150               tFemtoV0->SetNegNSigmaTOFK(-1000);
1151               tFemtoV0->SetPosNSigmaTOFP(-1000);
1152               tFemtoV0->SetNegNSigmaTOFP(-1000);
1153               tFemtoV0->SetPosNSigmaTOFPi(-1000);
1154               tFemtoV0->SetNegNSigmaTOFPi(-1000);
1155
1156               tFemtoV0->SetTOFProtonTimePos(-1000);
1157               tFemtoV0->SetTOFPionTimePos(-1000);
1158               tFemtoV0->SetTOFKaonTimePos(-1000);
1159               tFemtoV0->SetTOFProtonTimeNeg(-1000);
1160               tFemtoV0->SetTOFPionTimeNeg(-1000);
1161               tFemtoV0->SetTOFKaonTimeNeg(-1000);
1162             }
1163     }
1164     else
1165     {
1166       tFemtoV0->SetPosNSigmaTOFK(fAODpidUtil->NumberOfSigmasTOF(trackpos,AliPID::kKaon));
1167       tFemtoV0->SetNegNSigmaTOFK(fAODpidUtil->NumberOfSigmasTOF(trackneg,AliPID::kKaon));
1168       tFemtoV0->SetPosNSigmaTOFP(fAODpidUtil->NumberOfSigmasTOF(trackpos,AliPID::kProton));
1169       tFemtoV0->SetNegNSigmaTOFP(fAODpidUtil->NumberOfSigmasTOF(trackneg,AliPID::kProton));
1170       tFemtoV0->SetPosNSigmaTOFPi(fAODpidUtil->NumberOfSigmasTOF(trackpos,AliPID::kPion));
1171       tFemtoV0->SetNegNSigmaTOFPi(fAODpidUtil->NumberOfSigmasTOF(trackneg,AliPID::kPion));
1172
1173       double TOFSignalPos = trackpos->GetTOFsignal();
1174       double TOFSignalNeg = trackneg->GetTOFsignal();
1175       double pidPos[5];
1176       double pidNeg[5];
1177       trackpos->GetIntegratedTimes(pidPos);
1178       trackneg->GetIntegratedTimes(pidNeg);
1179
1180       tFemtoV0->SetTOFPionTimePos(TOFSignalPos-pidPos[2]);
1181       tFemtoV0->SetTOFKaonTimePos(TOFSignalPos-pidPos[3]);
1182       tFemtoV0->SetTOFProtonTimePos(TOFSignalPos-pidPos[4]);
1183       tFemtoV0->SetTOFPionTimeNeg(TOFSignalNeg-pidNeg[2]);
1184       tFemtoV0->SetTOFKaonTimeNeg(TOFSignalNeg-pidNeg[3]);
1185       tFemtoV0->SetTOFProtonTimeNeg(TOFSignalNeg-pidNeg[4]);
1186     }
1187   }
1188   else
1189   {
1190     tFemtoV0->SetStatusPos(999);
1191     tFemtoV0->SetStatusNeg(999);
1192   }
1193   tFemtoV0->SetOnFlyStatusV0(tAODv0->GetOnFlyStatus());
1194 }
1195
1196 void AliFemtoEventReaderAOD::SetFilterBit(UInt_t ibit)
1197 {
1198   fFilterBit = (1 << (ibit));
1199 }
1200
1201
1202 void AliFemtoEventReaderAOD::SetFilterMask(int ibit)
1203 {
1204   fFilterMask = ibit;
1205 }
1206
1207 void AliFemtoEventReaderAOD::SetReadMC(unsigned char a)
1208 {
1209   fReadMC = a;
1210 }
1211
1212
1213 void AliFemtoEventReaderAOD::SetReadV0(unsigned char a)
1214 {
1215   fReadV0 = a;
1216 }
1217
1218 void AliFemtoEventReaderAOD::SetUseMultiplicity(EstEventMult aType)
1219 {
1220   fEstEventMult = aType;
1221 }
1222
1223 AliAODMCParticle* AliFemtoEventReaderAOD::GetParticleWithLabel(TClonesArray *mcP, Int_t aLabel)
1224 {
1225   if (aLabel < 0) return 0;
1226   AliAODMCParticle *aodP;
1227   Int_t posstack = 0;
1228   if (aLabel > mcP->GetEntries())
1229     posstack = mcP->GetEntries();
1230   else
1231     posstack = aLabel;
1232
1233   aodP = (AliAODMCParticle *) mcP->At(posstack);
1234   if (aodP->GetLabel() > posstack) {
1235     do {
1236       aodP = (AliAODMCParticle *) mcP->At(posstack);
1237       if (aodP->GetLabel() == aLabel) return aodP;
1238       posstack--;
1239     }
1240     while (posstack > 0);
1241   }
1242   else {
1243     do {
1244       aodP = (AliAODMCParticle *) mcP->At(posstack);
1245       if (aodP->GetLabel() == aLabel) return aodP;
1246       posstack++;
1247     }
1248     while (posstack < mcP->GetEntries());
1249   }
1250
1251   return 0;
1252 }
1253
1254 void AliFemtoEventReaderAOD::CopyPIDtoFemtoTrack(AliAODTrack *tAodTrack,
1255                                                  AliFemtoTrack *tFemtoTrack)
1256 {
1257
1258   if (fDCAglobalTrack) {
1259
1260     // code from Michael and Prabhat from AliAnalysisTaskDptDptCorrelations
1261     const AliAODVertex* vertex = (AliAODVertex*) fEvent->GetPrimaryVertex();
1262     float vertexX  = -999.;
1263     float vertexY  = -999.;
1264     float vertexZ  = -999.;
1265
1266     if(vertex) {
1267       Double32_t fCov[6];
1268       vertex->GetCovarianceMatrix(fCov);
1269       if(vertex->GetNContributors() > 0) {
1270         if(fCov[5] != 0) {
1271           vertexX = vertex->GetX();
1272           vertexY = vertex->GetY();
1273           vertexZ = vertex->GetZ();
1274
1275         }
1276       }
1277     }
1278
1279     Double_t pos[3];
1280     tAodTrack->GetXYZ(pos);
1281
1282     Double_t DCAX = pos[0] - vertexX;
1283     Double_t DCAY = pos[1] - vertexY;
1284     Double_t DCAZ = pos[2] - vertexZ;
1285
1286     Double_t DCAXY = TMath::Sqrt((DCAX*DCAX) + (DCAY*DCAY));
1287
1288     tFemtoTrack->SetImpactD(DCAXY);
1289     tFemtoTrack->SetImpactZ(DCAZ);
1290
1291
1292     // // // copying DCA information (taking it from global tracks gives better resolution than from TPC-only)
1293
1294     // double impact[2];
1295     // double covimpact[3];
1296
1297     // AliAODTrack* trk_clone = (AliAODTrack*)tAodTrack->Clone("trk_clone");
1298     // // if(!trk_clone->PropagateToDCA(fAODVertex,aod->GetMagneticField(),300.,dca,cov)) continue;
1299     // // if (!tAodTrack->PropagateToDCA(fEvent->GetPrimaryVertex(),fEvent->GetMagneticField(),10000,impact,covimpact)) {
1300     // if (!trk_clone->PropagateToDCA(fEvent->GetPrimaryVertex(),fEvent->GetMagneticField(),10000,impact,covimpact)) {
1301
1302     // // if (!tAodTrack->PropagateToDCA(fEvent->GetPrimaryVertex(),fEvent->GetMagneticField(),10000,impact,covimpact)) {
1303     //   //cout << "sth went wrong with dca propagation" << endl;
1304     //   tFemtoTrack->SetImpactD(-1000.0);
1305     //   tFemtoTrack->SetImpactZ(-1000.0);
1306
1307     // }
1308     // else {
1309     //   tFemtoTrack->SetImpactD(impact[0]);
1310     //   tFemtoTrack->SetImpactZ(impact[1]);
1311     // }
1312     // delete trk_clone;
1313   }
1314
1315   double aodpid[10];
1316   tAodTrack->GetPID(aodpid);
1317   tFemtoTrack->SetPidProbElectron(aodpid[0]);
1318   tFemtoTrack->SetPidProbMuon(aodpid[1]);
1319   tFemtoTrack->SetPidProbPion(aodpid[2]);
1320   tFemtoTrack->SetPidProbKaon(aodpid[3]);
1321   tFemtoTrack->SetPidProbProton(aodpid[4]);
1322
1323   aodpid[0] = -100000.0;
1324   aodpid[1] = -100000.0;
1325   aodpid[2] = -100000.0;
1326   aodpid[3] = -100000.0;
1327   aodpid[4] = -100000.0;
1328
1329   double tTOF = 0.0;
1330   Float_t probMis = 1.0;
1331
1332   //what is that code? for what do we need it? nsigma values are not enough?
1333   if (tAodTrack->GetStatus() & AliESDtrack::kTOFpid) {  //AliESDtrack::kTOFpid=0x8000
1334     tTOF = tAodTrack->GetTOFsignal();
1335     tAodTrack->GetIntegratedTimes(aodpid);
1336
1337     tTOF -= fAODpidUtil->GetTOFResponse().GetStartTime(tAodTrack->P());
1338
1339     probMis = fAODpidUtil->GetTOFMismatchProbability(tAodTrack);
1340   }
1341
1342
1343
1344   tFemtoTrack->SetTofExpectedTimes(tTOF-aodpid[2], tTOF-aodpid[3], tTOF-aodpid[4]);
1345
1346   //////  TPC ////////////////////////////////////////////
1347
1348   float nsigmaTPCK=-1000.;
1349   float nsigmaTPCPi=-1000.;
1350   float nsigmaTPCP=-1000.;
1351   float nsigmaTPCE=-1000.;
1352
1353   //   cout<<"in reader fESDpid"<<fESDpid<<endl;
1354
1355   if (tAodTrack->IsOn(AliESDtrack::kTPCpid)){ //AliESDtrack::kTPCpid=0x0080
1356     nsigmaTPCK = fAODpidUtil->NumberOfSigmasTPC(tAodTrack,AliPID::kKaon);
1357     nsigmaTPCPi = fAODpidUtil->NumberOfSigmasTPC(tAodTrack,AliPID::kPion);
1358     nsigmaTPCP = fAODpidUtil->NumberOfSigmasTPC(tAodTrack,AliPID::kProton);
1359     nsigmaTPCE = fAODpidUtil->NumberOfSigmasTPC(tAodTrack,AliPID::kElectron);
1360   }
1361
1362   tFemtoTrack->SetNSigmaTPCPi(nsigmaTPCPi);
1363   tFemtoTrack->SetNSigmaTPCK(nsigmaTPCK);
1364   tFemtoTrack->SetNSigmaTPCP(nsigmaTPCP);
1365   tFemtoTrack->SetNSigmaTPCE(nsigmaTPCE);
1366
1367   tFemtoTrack->SetTPCchi2(tAodTrack->Chi2perNDF());
1368   tFemtoTrack->SetTPCncls(tAodTrack->GetTPCNcls());
1369   tFemtoTrack->SetTPCnclsF(tAodTrack->GetTPCNcls());
1370
1371   tFemtoTrack->SetTPCsignalN(1);
1372   tFemtoTrack->SetTPCsignalS(1);
1373   tFemtoTrack->SetTPCsignal(tAodTrack->GetTPCsignal());
1374
1375   ///////TOF//////////////////////
1376
1377   float vp=-1000.;
1378   float nsigmaTOFPi=-1000.;
1379   float nsigmaTOFK=-1000.;
1380   float nsigmaTOFP=-1000.;
1381   float nsigmaTOFE=-1000.;
1382
1383   if ((tAodTrack->GetStatus() & AliESDtrack::kTOFpid) && //AliESDtrack::kTOFpid=0x8000
1384       (tAodTrack->GetStatus() & AliESDtrack::kTOFout) && //AliESDtrack::kTOFout=0x2000
1385       (tAodTrack->GetStatus() & AliESDtrack::kTIME) //AliESDtrack::kTIME=0x80000000
1386       && probMis < 0.01) // TOF mismatch probaility
1387   {
1388     if(tAodTrack->IsOn(AliESDtrack::kTOFpid)) //AliESDtrack::kTOFpid=0x8000
1389           {
1390
1391             nsigmaTOFPi = fAODpidUtil->NumberOfSigmasTOF(tAodTrack,AliPID::kPion);
1392             nsigmaTOFK = fAODpidUtil->NumberOfSigmasTOF(tAodTrack,AliPID::kKaon);
1393             nsigmaTOFP = fAODpidUtil->NumberOfSigmasTOF(tAodTrack,AliPID::kProton);
1394             nsigmaTOFE = fAODpidUtil->NumberOfSigmasTOF(tAodTrack,AliPID::kElectron);
1395
1396             Double_t len=200;// esdtrack->GetIntegratedLength(); !!!!!
1397             Double_t tof=tAodTrack->GetTOFsignal();
1398             if(tof > 0.) vp=len/tof/0.03;
1399           }
1400   }
1401   tFemtoTrack->SetVTOF(vp);
1402   tFemtoTrack->SetNSigmaTOFPi(nsigmaTOFPi);
1403   tFemtoTrack->SetNSigmaTOFK(nsigmaTOFK);
1404   tFemtoTrack->SetNSigmaTOFP(nsigmaTOFP);
1405   tFemtoTrack->SetNSigmaTOFE(nsigmaTOFE);
1406
1407
1408   //////////////////////////////////////
1409
1410 }
1411
1412 void AliFemtoEventReaderAOD::SetCentralityPreSelection(double min, double max)
1413 {
1414   fCentRange[0] = min; fCentRange[1] = max;
1415   fUsePreCent = 1;
1416   fEstEventMult = kCentrality;
1417 }
1418
1419 void AliFemtoEventReaderAOD::SetNoCentrality(bool anocent)
1420 {
1421   if(anocent==false) {fEstEventMult=kCentrality;}
1422   else {fEstEventMult=kReference; fUsePreCent = 0; }
1423 }
1424
1425 void AliFemtoEventReaderAOD::SetAODpidUtil(AliAODpidUtil *aAODpidUtil)
1426 {
1427   fAODpidUtil = aAODpidUtil;
1428   //  printf("fAODpidUtil: %x\n",fAODpidUtil);
1429 }
1430
1431 void AliFemtoEventReaderAOD::SetAODheader(AliAODHeader *aAODheader)
1432 {
1433   fAODheader = aAODheader;
1434 }
1435
1436
1437 void AliFemtoEventReaderAOD::SetMagneticFieldSign(int s)
1438 {
1439   if(s>0)
1440     fMagFieldSign = 1;
1441   else if(s<0)
1442     fMagFieldSign = -1;
1443   else
1444     fMagFieldSign = 0;
1445 }
1446
1447 void AliFemtoEventReaderAOD::SetEPVZERO(Bool_t iepvz)
1448 {
1449   fisEPVZ = iepvz;
1450 }
1451
1452 void AliFemtoEventReaderAOD::GetGlobalPositionAtGlobalRadiiThroughTPC(AliAODTrack *track, Float_t bfield, Float_t globalPositionsAtRadii[9][3])
1453 {
1454   // Gets the global position of the track at nine different radii in the TPC
1455   // track is the track you want to propagate
1456   // bfield is the magnetic field of your event
1457   // globalPositionsAtRadii is the array of global positions in the radii and xyz
1458
1459   // Initialize the array to something indicating there was no propagation
1460   for(Int_t i=0;i<9;i++){
1461     for(Int_t j=0;j<3;j++){
1462       globalPositionsAtRadii[i][j]=-9999.;
1463     }
1464   }
1465
1466   // Make a copy of the track to not change parameters of the track
1467   AliExternalTrackParam etp; etp.CopyFromVTrack(track);
1468   //printf("\nAfter CopyFromVTrack\n");
1469   //etp.Print();
1470
1471   // The global position of the the track
1472   Double_t xyz[3]={-9999.,-9999.,-9999.};
1473
1474   // Counter for which radius we want
1475   Int_t iR=0;
1476   // The radii at which we get the global positions
1477   // IROC (OROC) from 84.1 cm to 132.1 cm (134.6 cm to 246.6 cm)
1478   Float_t Rwanted[9]={85.,105.,125.,145.,165.,185.,205.,225.,245.};
1479   // The global radius we are at
1480   Float_t globalRadius=0;
1481
1482   // Propagation is done in local x of the track
1483   for (Float_t x = etp.GetX();x<247.;x+=1.){ // GetX returns local coordinates
1484     // Starts at the tracks fX and goes outwards. x = 245 is the outer radial limit
1485     // of the TPC when the track is straight, i.e. has inifinite pt and doesn't get bent.
1486     // If the track's momentum is smaller than infinite, it will develop a y-component, which
1487     // adds to the global radius
1488
1489     // Stop if the propagation was not succesful. This can happen for low pt tracks
1490     // that don't reach outer radii
1491     if(!etp.PropagateTo(x,bfield))break;
1492     etp.GetXYZ(xyz); // GetXYZ returns global coordinates
1493     globalRadius = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]); //Idea to speed up: compare squared radii
1494
1495     // Roughly reached the radius we want
1496     if(globalRadius > Rwanted[iR]){
1497
1498       // Bigger loop has bad precision, we're nearly one centimeter too far, go back in small steps.
1499       while (globalRadius>Rwanted[iR]){
1500         x-=.1;
1501         //      printf("propagating to x %5.2f\n",x);
1502         if(!etp.PropagateTo(x,bfield))break;
1503         etp.GetXYZ(xyz); // GetXYZ returns global coordinates
1504         globalRadius = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]); //Idea to speed up: compare squared radii
1505       }
1506       //printf("At Radius:%05.2f (local x %5.2f). Setting position to x %4.1f y %4.1f z %4.1f\n",globalRadius,x,xyz[0],xyz[1],xyz[2]);
1507       globalPositionsAtRadii[iR][0]=xyz[0];
1508       globalPositionsAtRadii[iR][1]=xyz[1];
1509       globalPositionsAtRadii[iR][2]=xyz[2];
1510       // Indicate we want the next radius
1511       iR+=1;
1512     }
1513     if(iR>=8){
1514       // TPC edge reached
1515       return;
1516     }
1517   }
1518 }
1519
1520 void AliFemtoEventReaderAOD::SetpA2013(Bool_t pa2013)
1521 {
1522   fpA2013 = pa2013;
1523 }
1524
1525 void AliFemtoEventReaderAOD::SetUseMVPlpSelection(Bool_t mvplp)
1526 {
1527   fMVPlp = mvplp;
1528 }
1529
1530 void AliFemtoEventReaderAOD::SetIsPileUpEvent(Bool_t ispileup)
1531 {
1532   fisPileUp = ispileup;
1533 }
1534
1535
1536
1537 void AliFemtoEventReaderAOD::SetDCAglobalTrack(Bool_t dcagt)
1538 {
1539   fDCAglobalTrack = dcagt;
1540 }
1541
1542
1543 bool AliFemtoEventReaderAOD::RejectEventCentFlat(float MagField, float CentPercent)
1544 { // to flatten centrality distribution
1545   bool RejectEvent = kFALSE;
1546   int weightBinSign;
1547   TRandom3* fRandomNumber = new TRandom3();  //for 3D, random sign switching
1548   fRandomNumber->SetSeed(0);
1549
1550   if(MagField > 0) weightBinSign = 0;
1551   else weightBinSign = 1;
1552   float kCentWeight[2][9] = {{.878,.876,.860,.859,.859,.88,.873,.879,.894},
1553                              {.828,.793,.776,.772,.775,.796,.788,.804,.839}};
1554   int weightBinCent = (int) CentPercent;
1555   if(fRandomNumber->Rndm() > kCentWeight[weightBinSign][weightBinCent]) RejectEvent = kTRUE;
1556
1557   return RejectEvent;
1558 }
1559
1560 void AliFemtoEventReaderAOD::SetCentralityFlattening(Bool_t dcagt)
1561 {
1562   fFlatCent = dcagt;
1563 }