1 ////////////////////////////////////////////////////////////////////////////////
3 /// AliFemtoEventReaderESDChain - the reader class for the Alice ESD ///
4 /// tailored for the Task framework ///
5 /// Reads in AliESDfriend to create shared hit/quality information ///
6 /// Authors: Adam Kisiel kisiel@mps.ohio-state.edu ///
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "AliFemtoEventReaderESDChain.h"
13 #include "AliESDEvent.h"
14 #include "AliESDtrack.h"
15 #include "AliESDVertex.h"
17 #include "AliFmPhysicalHelixD.h"
18 #include "AliFmThreeVectorF.h"
20 #include "SystemOfUnits.h"
22 #include "AliFemtoEvent.h"
23 #include "AliFemtoModelHiddenInfo.h"
25 ClassImp(AliFemtoEventReaderESDChain)
27 #if !(ST_NO_NAMESPACES)
28 using namespace units;
32 //____________________________
33 AliFemtoEventReaderESDChain::AliFemtoEventReaderESDChain():
43 //constructor with 0 parameters , look at default settings
44 // fClusterPerPadrow = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
45 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
46 // fClusterPerPadrow[tPad] = new list<Int_t>();
48 // fSharedList = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
49 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
50 // fSharedList[tPad] = new list<Int_t>();
55 AliFemtoEventReaderESDChain::AliFemtoEventReaderESDChain(const AliFemtoEventReaderESDChain& aReader):
56 AliFemtoEventReader(aReader),
67 fConstrained = aReader.fConstrained;
68 fReadInner = aReader.fReadInner;
69 fUseTPCOnly = aReader.fUseTPCOnly;
70 fNumberofEvent = aReader.fNumberofEvent;
71 fCurEvent = aReader.fCurEvent;
72 fCurFile = aReader.fCurFile;
73 // fEvent = new AliESD(*aReader.fEvent);
74 fEvent = new AliESDEvent();
75 // fEventFriend = aReader.fEventFriend;
76 // fClusterPerPadrow = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
77 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
78 // fClusterPerPadrow[tPad] = new list<Int_t>();
79 // list<Int_t>::iterator iter;
80 // for (iter=aReader.fClusterPerPadrow[tPad]->begin(); iter!=aReader.fClusterPerPadrow[tPad]->end(); iter++) {
81 // fClusterPerPadrow[tPad]->push_back(*iter);
84 // fSharedList = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
85 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
86 // fSharedList[tPad] = new list<Int_t>();
87 // list<Int_t>::iterator iter;
88 // for (iter=aReader.fSharedList[tPad]->begin(); iter!=aReader.fSharedList[tPad]->end(); iter++) {
89 // fSharedList[tPad]->push_back(*iter);
94 AliFemtoEventReaderESDChain::~AliFemtoEventReaderESDChain()
99 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
100 // fClusterPerPadrow[tPad]->clear();
101 // delete fClusterPerPadrow[tPad];
103 // delete [] fClusterPerPadrow;
104 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
105 // fSharedList[tPad]->clear();
106 // delete fSharedList[tPad];
108 // delete [] fSharedList;
112 AliFemtoEventReaderESDChain& AliFemtoEventReaderESDChain::operator=(const AliFemtoEventReaderESDChain& aReader)
114 // Assignment operator
115 if (this == &aReader)
118 fConstrained = aReader.fConstrained;
119 fReadInner = aReader.fReadInner;
120 fUseTPCOnly = aReader.fUseTPCOnly;
121 fNumberofEvent = aReader.fNumberofEvent;
122 fCurEvent = aReader.fCurEvent;
123 fCurFile = aReader.fCurFile;
124 if (fEvent) delete fEvent;
125 fEvent = new AliESDEvent();
127 // fEventFriend = aReader.fEventFriend;
129 // if (fClusterPerPadrow) {
130 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
131 // fClusterPerPadrow[tPad]->clear();
132 // delete fClusterPerPadrow[tPad];
134 // delete [] fClusterPerPadrow;
137 // if (fSharedList) {
138 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
139 // fSharedList[tPad]->clear();
140 // delete fSharedList[tPad];
142 // delete [] fSharedList;
145 // fClusterPerPadrow = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
146 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
147 // fClusterPerPadrow[tPad] = new list<Int_t>();
148 // list<Int_t>::iterator iter;
149 // for (iter=aReader.fClusterPerPadrow[tPad]->begin(); iter!=aReader.fClusterPerPadrow[tPad]->end(); iter++) {
150 // fClusterPerPadrow[tPad]->push_back(*iter);
153 // fSharedList = (list<Int_t> **) malloc(sizeof(list<Int_t> *) * AliESDfriendTrack::kMaxTPCcluster);
154 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
155 // fSharedList[tPad] = new list<Int_t>();
156 // list<Int_t>::iterator iter;
157 // for (iter=aReader.fSharedList[tPad]->begin(); iter!=aReader.fSharedList[tPad]->end(); iter++) {
158 // fSharedList[tPad]->push_back(*iter);
166 AliFemtoString AliFemtoEventReaderESDChain::Report()
168 AliFemtoString temp = "\n This is the AliFemtoEventReaderESDChain\n";
173 void AliFemtoEventReaderESDChain::SetConstrained(const bool constrained)
175 // Select whether to read constrained or not constrained momentum
176 fConstrained=constrained;
179 bool AliFemtoEventReaderESDChain::GetConstrained() const
181 // Check whether we read constrained or not constrained momentum
185 void AliFemtoEventReaderESDChain::SetReadTPCInner(const bool readinner)
187 fReadInner=readinner;
190 bool AliFemtoEventReaderESDChain::GetReadTPCInner() const
196 void AliFemtoEventReaderESDChain::SetUseTPCOnly(const bool usetpconly)
198 fUseTPCOnly=usetpconly;
201 bool AliFemtoEventReaderESDChain::GetUseTPCOnly() const
206 AliFemtoEvent* AliFemtoEventReaderESDChain::ReturnHbtEvent()
208 // Get the event, read all the relevant information
209 // and fill the AliFemtoEvent class
210 // Returns a valid AliFemtoEvent
211 AliFemtoEvent *hbtEvent = 0;
212 string tFriendFileName;
214 // Get the friend information
215 cout<<"starting to read event "<<fCurEvent<<endl;
216 // fEvent->SetESDfriend(fEventFriend);
218 hbtEvent = new AliFemtoEvent;
219 //setting basic things
220 // hbtEvent->SetEventNumber(fEvent->GetEventNumber());
221 hbtEvent->SetRunNumber(fEvent->GetRunNumber());
222 //hbtEvent->SetNumberOfTracks(fEvent->GetNumberOfTracks());
223 hbtEvent->SetMagneticField(fEvent->GetMagneticField()*kilogauss);//to check if here is ok
224 hbtEvent->SetZDCN1Energy(fEvent->GetZDCN1Energy());
225 hbtEvent->SetZDCP1Energy(fEvent->GetZDCP1Energy());
226 hbtEvent->SetZDCN2Energy(fEvent->GetZDCN2Energy());
227 hbtEvent->SetZDCP2Energy(fEvent->GetZDCP2Energy());
228 hbtEvent->SetZDCEMEnergy(fEvent->GetZDCEMEnergy());
229 hbtEvent->SetZDCParticipants(fEvent->GetZDCParticipants());
230 hbtEvent->SetTriggerMask(fEvent->GetTriggerMask());
231 hbtEvent->SetTriggerCluster(fEvent->GetTriggerCluster());
237 fEvent->GetPrimaryVertexTPC()->GetXYZ(fV1);
238 fEvent->GetPrimaryVertexTPC()->GetCovMatrix(fVCov);
239 if (!fEvent->GetPrimaryVertexTPC()->GetStatus())
243 fEvent->GetPrimaryVertex()->GetXYZ(fV1);
244 fEvent->GetPrimaryVertex()->GetCovMatrix(fVCov);
245 if (!fEvent->GetPrimaryVertex()->GetStatus())
249 AliFmThreeVectorF vertex(fV1[0],fV1[1],fV1[2]);
250 hbtEvent->SetPrimVertPos(vertex);
251 hbtEvent->SetPrimVertCov(fVCov);
253 //starting to reading tracks
254 int nofTracks=0; //number of reconstructed tracks in event
255 nofTracks=fEvent->GetNumberOfTracks();
256 int realnofTracks=0;//number of track which we use ina analysis
258 // // Clear the shared cluster list
259 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
260 // fClusterPerPadrow[tPad]->clear();
262 // for (int tPad=0; tPad<AliESDfriendTrack::kMaxTPCcluster; tPad++) {
263 // fSharedList[tPad]->clear();
267 // for (int i=0;i<nofTracks;i++) {
268 // const AliESDtrack *esdtrack=fEvent->GetTrack(i);//getting next track
270 // list<Int_t>::iterator tClustIter;
272 // Int_t tTrackIndices[AliESDfriendTrack::kMaxTPCcluster];
273 // Int_t tNClusters = esdtrack->GetTPCclusters(tTrackIndices);
274 // for (int tNcl=0; tNcl<AliESDfriendTrack::kMaxTPCcluster; tNcl++) {
275 // if (tTrackIndices[tNcl] >= 0) {
276 // tClustIter = find(fClusterPerPadrow[tNcl]->begin(), fClusterPerPadrow[tNcl]->end(), tTrackIndices[tNcl]);
277 // if (tClustIter == fClusterPerPadrow[tNcl]->end()) {
278 // fClusterPerPadrow[tNcl]->push_back(tTrackIndices[tNcl]);
281 // fSharedList[tNcl]->push_back(tTrackIndices[tNcl]);
288 for (int i=0;i<nofTracks;i++)
290 bool tGoodMomentum=true; //flaga to chcek if we can read momentum of this track
292 AliFemtoTrack* trackCopy = new AliFemtoTrack();
293 const AliESDtrack *esdtrack=fEvent->GetTrack(i);//getting next track
294 // const AliESDfriendTrack *tESDfriendTrack = esdtrack->GetFriendTrack();
296 trackCopy->SetCharge((short)esdtrack->GetSign());
298 //in aliroot we have AliPID
299 //0-electron 1-muon 2-pion 3-kaon 4-proton 5-photon 6-pi0 7-neutron 8-kaon0 9-eleCon
300 //we use only 5 first
302 esdtrack->GetESDpid(esdpid);
303 trackCopy->SetPidProbElectron(esdpid[0]);
304 trackCopy->SetPidProbMuon(esdpid[1]);
305 trackCopy->SetPidProbPion(esdpid[2]);
306 trackCopy->SetPidProbKaon(esdpid[3]);
307 trackCopy->SetPidProbProton(esdpid[4]);
315 if (!esdtrack->GetTPCInnerParam()) {
321 AliExternalTrackParam *param = new AliExternalTrackParam(*esdtrack->GetTPCInnerParam());
323 param->PropagateToDCA(fEvent->GetPrimaryVertexTPC(), (fEvent->GetMagneticField()), 10000, impact, covimpact);
324 param->GetPxPyPz(pxyz);//reading noconstarined momentum
326 if (fReadInner == true) {
327 AliFemtoModelHiddenInfo *tInfo = new AliFemtoModelHiddenInfo();
328 tInfo->SetPDGPid(211);
329 tInfo->SetTrueMomentum(pxyz[0], pxyz[1], pxyz[2]);
330 tInfo->SetMass(0.13957);
331 // tInfo->SetEmissionPoint(rxyz[0], rxyz[1], rxyz[2], 0.0);
332 // tInfo->SetEmissionPoint(fV1[0], fV1[1], fV1[2], 0.0);
333 tInfo->SetEmissionPoint(rxyz[0]-fV1[0], rxyz[1]-fV1[1], rxyz[2]-fV1[2], 0.0);
334 trackCopy->SetHiddenInfo(tInfo);
337 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
338 if (v.mag() < 0.0001) {
339 // cout << "Found 0 momentum ???? " <<endl;
343 trackCopy->SetP(v);//setting momentum
344 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
346 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
347 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
348 //setting helix I do not if it is ok
349 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
350 trackCopy->SetHelix(helix);
352 //some stuff which could be useful
353 trackCopy->SetImpactD(impact[0]);
354 trackCopy->SetImpactZ(impact[1]);
355 trackCopy->SetCdd(covimpact[0]);
356 trackCopy->SetCdz(covimpact[1]);
357 trackCopy->SetCzz(covimpact[2]);
358 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact, covimpact));
363 if (fReadInner == true) {
365 if (esdtrack->GetTPCInnerParam()) {
366 AliExternalTrackParam *param = new AliExternalTrackParam(*esdtrack->GetTPCInnerParam());
368 param->PropagateToDCA(fEvent->GetPrimaryVertex(), (fEvent->GetMagneticField()), 10000);
369 param->GetPxPyPz(pxyz);//reading noconstarined momentum
372 AliFemtoModelHiddenInfo *tInfo = new AliFemtoModelHiddenInfo();
373 tInfo->SetPDGPid(211);
374 tInfo->SetTrueMomentum(pxyz[0], pxyz[1], pxyz[2]);
375 tInfo->SetMass(0.13957);
376 // tInfo->SetEmissionPoint(rxyz[0], rxyz[1], rxyz[2], 0.0);
377 //tInfo->SetEmissionPoint(fV1[0], fV1[1], fV1[2], 0.0);
378 tInfo->SetEmissionPoint(rxyz[0]-fV1[0], rxyz[1]-fV1[1], rxyz[2]-fV1[2], 0.0);
379 trackCopy->SetHiddenInfo(tInfo);
382 if (fConstrained==true)
383 tGoodMomentum=esdtrack->GetConstrainedPxPyPz(pxyz); //reading constrained momentum
385 tGoodMomentum=esdtrack->GetPxPyPz(pxyz);//reading noconstarined momentum
387 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
388 if (v.mag() < 0.0001) {
389 // cout << "Found 0 momentum ???? " <<endl;
393 trackCopy->SetP(v);//setting momentum
394 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
395 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
396 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
397 //setting helix I do not if it is ok
398 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
399 trackCopy->SetHelix(helix);
401 //some stuff which could be useful
404 esdtrack->GetImpactParameters(imp,cim);
408 covimpact[0] = cim[0];
409 covimpact[1] = cim[1];
410 covimpact[2] = cim[2];
412 trackCopy->SetImpactD(impact[0]);
413 trackCopy->SetImpactZ(impact[1]);
414 trackCopy->SetCdd(covimpact[0]);
415 trackCopy->SetCdz(covimpact[1]);
416 trackCopy->SetCzz(covimpact[2]);
417 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact,covimpact));
420 trackCopy->SetTrackId(esdtrack->GetID());
421 trackCopy->SetFlags(esdtrack->GetStatus());
422 trackCopy->SetLabel(esdtrack->GetLabel());
424 trackCopy->SetITSchi2(esdtrack->GetITSchi2());
425 trackCopy->SetITSncls(esdtrack->GetNcls(0));
426 trackCopy->SetTPCchi2(esdtrack->GetTPCchi2());
427 trackCopy->SetTPCncls(esdtrack->GetTPCNcls());
428 trackCopy->SetTPCnclsF(esdtrack->GetTPCNclsF());
429 trackCopy->SetTPCsignalN((short)esdtrack->GetTPCsignalN()); //due to bug in aliesdtrack class
430 trackCopy->SetTPCsignalS(esdtrack->GetTPCsignalSigma());
432 trackCopy->SetTPCClusterMap(esdtrack->GetTPCClusterMap());
433 trackCopy->SetTPCSharedMap(esdtrack->GetTPCSharedMap());
436 esdtrack->GetInnerXYZ(xtpc);
438 trackCopy->SetNominalTPCEntrancePoint(xtpc);
440 esdtrack->GetOuterXYZ(xtpc);
442 trackCopy->SetNominalTPCExitPoint(xtpc);
445 for (int ik=0; ik<3; ik++) {
446 indexes[ik] = esdtrack->GetKinkIndex(ik);
448 trackCopy->SetKinkIndexes(indexes);
449 //decision if we want this track
450 //if we using diffrent labels we want that this label was use for first time
451 //if we use hidden info we want to have match between sim data and ESD
452 if (tGoodMomentum==true)
454 hbtEvent->TrackCollection()->push_back(trackCopy);//adding track to analysis
455 realnofTracks++;//real number of tracks
465 hbtEvent->SetNumberOfTracks(realnofTracks);//setting number of track which we read in event
467 cout<<"end of reading nt "<<nofTracks<<" real number "<<realnofTracks<<endl;
470 //___________________
471 void AliFemtoEventReaderESDChain::SetESDSource(AliESDEvent *aESD)
473 // The chain loads the ESD for us
474 // You must provide the address where it can be found
477 //___________________
478 // void AliFemtoEventReaderESDChain::SetESDfriendSource(AliESDfriend *aFriend)
480 // // We need the ESD tree to obtain
481 // // information about the friend file location
482 // fEventFriend = aFriend;
485 //____________________________________________________________________
486 Float_t AliFemtoEventReaderESDChain::GetSigmaToVertex(double *impact, double *covar)
488 // Calculates the number of sigma to the vertex.
500 bRes[0] = TMath::Sqrt(bCov[0]);
501 bRes[1] = TMath::Sqrt(bCov[2]);
503 // -----------------------------------
504 // How to get to a n-sigma cut?
506 // The accumulated statistics from 0 to d is
508 // -> Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
509 // -> 1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
511 // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
512 // Can this be expressed in a different way?
514 if (bRes[0] == 0 || bRes[1] ==0)
517 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
519 // stupid rounding problem screws up everything:
520 // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
521 if (TMath::Exp(-d * d / 2) < 1e-10)
524 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);