1 ////////////////////////////////////////////////////////////////////////////////
3 // AliFemtoEventReaderESDChainKine - the reader class for the Alice ESD and //
4 // the model Kinematics information tailored for the Task framework and the //
5 // Reads in AliESDfriend to create shared hit/quality information //
6 // Authors: Adam Kisiel kisiel@mps.ohio-state.edu //
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "AliFemtoEventReaderESDChainKine.h"
14 #include "AliESDEvent.h"
15 #include "AliESDtrack.h"
16 #include "AliESDVertex.h"
18 #include "AliFmPhysicalHelixD.h"
19 #include "AliFmThreeVectorF.h"
21 #include "SystemOfUnits.h"
23 #include "AliFemtoEvent.h"
25 #include "TParticle.h"
26 #include "AliFemtoModelHiddenInfo.h"
27 #include "AliFemtoModelGlobalHiddenInfo.h"
28 #include "AliGenHijingEventHeader.h"
29 #include "AliGenCocktailEventHeader.h"
31 #include "AliVertexerTracks.h"
33 ClassImp(AliFemtoEventReaderESDChainKine)
35 #if !(ST_NO_NAMESPACES)
36 using namespace units;
40 //____________________________
41 AliFemtoEventReaderESDChainKine::AliFemtoEventReaderESDChainKine():
51 fRotateToEventPlane(0)
53 //constructor with 0 parameters , look at default settings
57 AliFemtoEventReaderESDChainKine::AliFemtoEventReaderESDChainKine(const AliFemtoEventReaderESDChainKine& aReader):
58 AliFemtoEventReader(aReader),
68 fRotateToEventPlane(0)
71 fConstrained = aReader.fConstrained;
72 fUseTPCOnly = aReader.fUseTPCOnly;
73 fNumberofEvent = aReader.fNumberofEvent;
74 fCurEvent = aReader.fCurEvent;
75 fCurFile = aReader.fCurFile;
76 fEvent = new AliESDEvent();
77 fStack = aReader.fStack;
78 fRotateToEventPlane = aReader.fRotateToEventPlane;
81 AliFemtoEventReaderESDChainKine::~AliFemtoEventReaderESDChainKine()
88 AliFemtoEventReaderESDChainKine& AliFemtoEventReaderESDChainKine::operator=(const AliFemtoEventReaderESDChainKine& aReader)
90 // Assignment operator
94 fConstrained = aReader.fConstrained;
95 fUseTPCOnly = aReader.fUseTPCOnly;
96 fNumberofEvent = aReader.fNumberofEvent;
97 fCurEvent = aReader.fCurEvent;
98 fCurFile = aReader.fCurFile;
99 if (fEvent) delete fEvent;
100 fEvent = new AliESDEvent();
101 fStack = aReader.fStack;
102 fGenHeader = aReader.fGenHeader;
103 fRotateToEventPlane = aReader.fRotateToEventPlane;
108 AliFemtoString AliFemtoEventReaderESDChainKine::Report()
110 AliFemtoString temp = "\n This is the AliFemtoEventReaderESDChainKine\n";
115 void AliFemtoEventReaderESDChainKine::SetConstrained(const bool constrained)
117 // Select whether to read constrained or not constrained momentum
118 fConstrained=constrained;
121 bool AliFemtoEventReaderESDChainKine::GetConstrained() const
123 // Check whether we read constrained or not constrained momentum
127 AliFemtoEvent* AliFemtoEventReaderESDChainKine::ReturnHbtEvent()
129 // Get the event, read all the relevant information
130 // and fill the AliFemtoEvent class
131 // Returns a valid AliFemtoEvent
132 AliFemtoEvent *hbtEvent = 0;
133 string tFriendFileName;
135 // Get the friend information
136 cout << "AliFemtoEventReaderESDChainKine::Starting to read event: "<<fCurEvent<<endl;
137 // fEvent->SetESDfriend(fEventFriend);
139 hbtEvent = new AliFemtoEvent;
140 //setting basic things
141 // hbtEvent->SetEventNumber(fEvent->GetEventNumber());
142 hbtEvent->SetRunNumber(fEvent->GetRunNumber());
143 //hbtEvent->SetNumberOfTracks(fEvent->GetNumberOfTracks());
144 hbtEvent->SetMagneticField(fEvent->GetMagneticField()*kilogauss);//to check if here is ok
145 hbtEvent->SetZDCN1Energy(fEvent->GetZDCN1Energy());
146 hbtEvent->SetZDCP1Energy(fEvent->GetZDCP1Energy());
147 hbtEvent->SetZDCN2Energy(fEvent->GetZDCN2Energy());
148 hbtEvent->SetZDCP2Energy(fEvent->GetZDCP2Energy());
149 hbtEvent->SetZDCEMEnergy(fEvent->GetZDCEMEnergy());
150 hbtEvent->SetZDCParticipants(fEvent->GetZDCParticipants());
151 hbtEvent->SetTriggerMask(fEvent->GetTriggerMask());
152 hbtEvent->SetTriggerCluster(fEvent->GetTriggerCluster());
158 fEvent->GetPrimaryVertexTPC()->GetXYZ(fV1);
159 fEvent->GetPrimaryVertexTPC()->GetCovMatrix(fVCov);
160 if (!fEvent->GetPrimaryVertexTPC()->GetStatus())
164 if (fEvent->GetPrimaryVertex()) {
165 fEvent->GetPrimaryVertex()->GetXYZ(fV1);
166 fEvent->GetPrimaryVertex()->GetCovMatrix(fVCov);
168 if (!fEvent->GetPrimaryVertex()->GetStatus()) {
169 // Get the vertex from SPD
170 fEvent->GetPrimaryVertexSPD()->GetXYZ(fV1);
171 fEvent->GetPrimaryVertexSPD()->GetCovMatrix(fVCov);
174 if (!fEvent->GetPrimaryVertexSPD()->GetStatus())
177 fEvent->GetPrimaryVertexSPD()->GetXYZ(fV1);
178 fEvent->GetPrimaryVertexSPD()->GetCovMatrix(fVCov);
183 if (fEvent->GetPrimaryVertexSPD()) {
184 fEvent->GetPrimaryVertexSPD()->GetXYZ(fV1);
185 fEvent->GetPrimaryVertexSPD()->GetCovMatrix(fVCov);
188 if ((!fEvent->GetPrimaryVertex()) && (!fEvent->GetPrimaryVertexSPD()))
190 cout << "No vertex found !!!" << endl;
198 AliFmThreeVectorF vertex(fV1[0],fV1[1],fV1[2]);
200 hbtEvent->SetPrimVertPos(vertex);
201 hbtEvent->SetPrimVertCov(fVCov);
203 Double_t tReactionPlane = 0;
205 AliGenHijingEventHeader *hdh = dynamic_cast<AliGenHijingEventHeader *> (fGenHeader);
207 AliGenCocktailEventHeader *cdh = dynamic_cast<AliGenCocktailEventHeader *> (fGenHeader);
209 TList *tGenHeaders = cdh->GetHeaders();
210 for (int ihead = 0; ihead<tGenHeaders->GetEntries(); ihead++) {
211 hdh = dynamic_cast<AliGenHijingEventHeader *> (fGenHeader);
219 tReactionPlane = hdh->ReactionPlaneAngle();
220 cout << "Got reaction plane " << tReactionPlane << endl;
223 hbtEvent->SetReactionPlaneAngle(tReactionPlane);
225 //starting to reading tracks
226 int nofTracks=0; //number of reconstructed tracks in event
227 nofTracks=fEvent->GetNumberOfTracks();
228 int realnofTracks=0;//number of track which we use ina analysis
232 motherids = new Int_t[fStack->GetNtrack()];
233 for (int ip=0; ip<fStack->GetNtrack(); ip++) motherids[ip] = 0;
235 // Read in mother ids
236 TParticle *motherpart;
237 for (int ip=0; ip<fStack->GetNtrack(); ip++) {
238 motherpart = fStack->Particle(ip);
239 if (motherpart->GetDaughter(0) > 0)
240 motherids[motherpart->GetDaughter(0)] = ip;
241 if (motherpart->GetDaughter(1) > 0)
242 motherids[motherpart->GetDaughter(1)] = ip;
244 // if (motherpart->GetPdgCode() == 211) {
245 // cout << "Mother " << ip << " has daughters "
246 // << motherpart->GetDaughter(0) << " "
247 // << motherpart->GetDaughter(1) << " "
248 // << motherpart->Vx() << " "
249 // << motherpart->Vy() << " "
250 // << motherpart->Vz() << " "
257 printf ("No Stack ???\n");
261 for (int i=0;i<nofTracks;i++)
263 // cout << "Reading track " << i << endl;
264 bool tGoodMomentum=true; //flaga to chcek if we can read momentum of this track
266 AliFemtoTrack* trackCopy = new AliFemtoTrack();
267 const AliESDtrack *esdtrack=fEvent->GetTrack(i);//getting next track
268 // const AliESDfriendTrack *tESDfriendTrack = esdtrack->GetFriendTrack();
270 trackCopy->SetCharge((short)esdtrack->GetSign());
272 //in aliroot we have AliPID
273 //0-electron 1-muon 2-pion 3-kaon 4-proton 5-photon 6-pi0 7-neutron 8-kaon0 9-eleCon
274 //we use only 5 first
276 esdtrack->GetESDpid(esdpid);
277 trackCopy->SetPidProbElectron(esdpid[0]);
278 trackCopy->SetPidProbMuon(esdpid[1]);
279 trackCopy->SetPidProbPion(esdpid[2]);
280 trackCopy->SetPidProbKaon(esdpid[3]);
281 trackCopy->SetPidProbProton(esdpid[4]);
289 if (!esdtrack->GetTPCInnerParam()) {
290 cout << "No TPC inner param !" << endl;
295 AliExternalTrackParam *param = new AliExternalTrackParam(*esdtrack->GetTPCInnerParam());
297 param->PropagateToDCA(fEvent->GetPrimaryVertexTPC(), (fEvent->GetMagneticField()), 10000, impact, covimpact);
298 param->GetPxPyPz(pxyz);//reading noconstarined momentum
300 if (fRotateToEventPlane) {
301 double tPhi = TMath::ATan2(pxyz[1], pxyz[0]);
302 double tRad = TMath::Hypot(pxyz[0], pxyz[1]);
304 pxyz[0] = tRad*TMath::Cos(tPhi - tReactionPlane);
305 pxyz[1] = tRad*TMath::Sin(tPhi - tReactionPlane);
308 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
309 if (v.Mag() < 0.0001) {
310 // cout << "Found 0 momentum ???? " << pxyz[0] << " " << pxyz[1] << " " << pxyz[2] << endl;
315 trackCopy->SetP(v);//setting momentum
316 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
318 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
319 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
320 //setting helix I do not if it is ok
321 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
322 trackCopy->SetHelix(helix);
324 //some stuff which could be useful
325 trackCopy->SetImpactD(impact[0]);
326 trackCopy->SetImpactZ(impact[1]);
327 trackCopy->SetCdd(covimpact[0]);
328 trackCopy->SetCdz(covimpact[1]);
329 trackCopy->SetCzz(covimpact[2]);
330 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact, covimpact));
335 if (fConstrained==true)
336 tGoodMomentum=esdtrack->GetConstrainedPxPyPz(pxyz); //reading constrained momentum
338 tGoodMomentum=esdtrack->GetPxPyPz(pxyz);//reading noconstarined momentum
341 if (fRotateToEventPlane) {
342 double tPhi = TMath::ATan2(pxyz[1], pxyz[0]);
343 double tRad = TMath::Hypot(pxyz[0], pxyz[1]);
345 pxyz[0] = tRad*TMath::Cos(tPhi - tReactionPlane);
346 pxyz[1] = tRad*TMath::Sin(tPhi - tReactionPlane);
349 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
350 if (v.Mag() < 0.0001) {
351 // cout << "Found 0 momentum ???? " << pxyz[0] << " " << pxyz[1] << " " << pxyz[2] << endl;
356 trackCopy->SetP(v);//setting momentum
357 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
358 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
359 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
360 //setting helix I do not if it is ok
361 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
362 trackCopy->SetHelix(helix);
364 //some stuff which could be useful
367 esdtrack->GetImpactParameters(imp,cim);
371 covimpact[0] = cim[0];
372 covimpact[1] = cim[1];
373 covimpact[2] = cim[2];
375 trackCopy->SetImpactD(impact[0]);
376 trackCopy->SetImpactZ(impact[1]);
377 trackCopy->SetCdd(covimpact[0]);
378 trackCopy->SetCdz(covimpact[1]);
379 trackCopy->SetCzz(covimpact[2]);
380 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact,covimpact));
383 trackCopy->SetTrackId(esdtrack->GetID());
384 trackCopy->SetFlags(esdtrack->GetStatus());
385 trackCopy->SetLabel(esdtrack->GetLabel());
387 trackCopy->SetITSchi2(esdtrack->GetITSchi2());
388 trackCopy->SetITSncls(esdtrack->GetNcls(0));
389 trackCopy->SetTPCchi2(esdtrack->GetTPCchi2());
390 trackCopy->SetTPCncls(esdtrack->GetTPCNcls());
391 trackCopy->SetTPCnclsF(esdtrack->GetTPCNclsF());
392 trackCopy->SetTPCsignalN((short)esdtrack->GetTPCsignalN()); //due to bug in aliesdtrack class
393 trackCopy->SetTPCsignalS(esdtrack->GetTPCsignalSigma());
396 trackCopy->SetTPCClusterMap(esdtrack->GetTPCClusterMap());
397 trackCopy->SetTPCSharedMap(esdtrack->GetTPCSharedMap());
400 esdtrack->GetInnerXYZ(xtpc);
402 trackCopy->SetNominalTPCEntrancePoint(xtpc);
404 esdtrack->GetOuterXYZ(xtpc);
406 trackCopy->SetNominalTPCExitPoint(xtpc);
409 for (int ik=0; ik<3; ik++) {
410 indexes[ik] = esdtrack->GetKinkIndex(ik);
412 trackCopy->SetKinkIndexes(indexes);
414 // Fill the hidden information with the simulated data
415 if (TMath::Abs(esdtrack->GetLabel()) < fStack->GetNtrack()) {
416 TParticle *tPart = fStack->Particle(TMath::Abs(esdtrack->GetLabel()));
418 // Check the mother information
420 // Using the new way of storing the freeze-out information
421 // Final state particle is stored twice on the stack
422 // one copy (mother) is stored with original freeze-out information
423 // and is not tracked
424 // the other one (daughter) is stored with primary vertex position
427 // Freeze-out coordinates
428 double fpx=0.0, fpy=0.0, fpz=0.0, fpt=0.0;
429 fpx = tPart->Vx() - fV1[0];
430 fpy = tPart->Vy() - fV1[1];
431 fpz = tPart->Vz() - fV1[2];
434 AliFemtoModelGlobalHiddenInfo *tInfo = new AliFemtoModelGlobalHiddenInfo();
435 tInfo->SetGlobalEmissionPoint(fpx, fpy, fpz);
442 // cout << "Looking for mother ids " << endl;
443 if (motherids[TMath::Abs(esdtrack->GetLabel())]>0) {
444 // cout << "Got mother id" << endl;
445 TParticle *mother = fStack->Particle(motherids[TMath::Abs(esdtrack->GetLabel())]);
446 // Check if this is the same particle stored twice on the stack
447 if ((mother->GetPdgCode() == tPart->GetPdgCode() || (mother->Px() == tPart->Px()))) {
448 // It is the same particle
449 // Read in the original freeze-out information
450 // and convert it from to [fm]
453 fpx = mother->Vx()*1e13*0.197327;
454 fpy = mother->Vy()*1e13*0.197327;
455 fpz = mother->Vz()*1e13*0.197327;
456 fpt = mother->T() *1e13*0.197327;
460 // fpx = mother->Vx()*1e13;
461 // fpy = mother->Vy()*1e13;
462 // fpz = mother->Vz()*1e13;
463 // fpt = mother->T() *1e13*3e10;
468 if (fRotateToEventPlane) {
469 double tPhi = TMath::ATan2(fpy, fpx);
470 double tRad = TMath::Hypot(fpx, fpy);
472 fpx = tRad*TMath::Cos(tPhi - tReactionPlane);
473 fpy = tRad*TMath::Sin(tPhi - tReactionPlane);
476 tInfo->SetPDGPid(tPart->GetPdgCode());
478 if (fRotateToEventPlane) {
479 double tPhi = TMath::ATan2(tPart->Py(), tPart->Px());
480 double tRad = TMath::Hypot(tPart->Px(), tPart->Py());
482 tInfo->SetTrueMomentum(tRad*TMath::Cos(tPhi - tReactionPlane),
483 tRad*TMath::Sin(tPhi - tReactionPlane),
487 tInfo->SetTrueMomentum(tPart->Px(), tPart->Py(), tPart->Pz());
488 Double_t mass2 = (tPart->Energy() *tPart->Energy() -
489 tPart->Px()*tPart->Px() -
490 tPart->Py()*tPart->Py() -
491 tPart->Pz()*tPart->Pz());
493 tInfo->SetMass(TMath::Sqrt(mass2));
497 tInfo->SetEmissionPoint(fpx, fpy, fpz, fpt);
498 trackCopy->SetHiddenInfo(tInfo);
501 AliFemtoModelGlobalHiddenInfo *tInfo = new AliFemtoModelGlobalHiddenInfo();
503 double fpx=0.0, fpy=0.0, fpz=0.0, fpt=0.0;
508 tInfo->SetEmissionPoint(fpx, fpy, fpz, fpt);
510 tInfo->SetTrueMomentum(pxyz[0],pxyz[1],pxyz[2]);
512 trackCopy->SetHiddenInfo(tInfo);
514 // cout << "Got freeze-out " << fpx << " " << fpy << " " << fpz << " " << fpt << " " << mass2 << " " << tPart->GetPdgCode() << endl;
516 //decision if we want this track
517 //if we using diffrent labels we want that this label was use for first time
518 //if we use hidden info we want to have match between sim data and ESD
519 if (tGoodMomentum==true)
521 hbtEvent->TrackCollection()->push_back(trackCopy);//adding track to analysis
522 realnofTracks++;//real number of tracks
534 hbtEvent->SetNumberOfTracks(realnofTracks);//setting number of track which we read in event
536 // cout<<"end of reading nt "<<nofTracks<<" real number "<<realnofTracks<<endl;
539 //___________________
540 void AliFemtoEventReaderESDChainKine::SetESDSource(AliESDEvent *aESD)
542 // The chain loads the ESD for us
543 // You must provide the address where it can be found
546 //___________________
547 void AliFemtoEventReaderESDChainKine::SetStackSource(AliStack *aStack)
549 // The chain loads the stack for us
550 // You must provide the address where it can be found
553 //___________________
554 void AliFemtoEventReaderESDChainKine::SetGenEventHeader(AliGenEventHeader *aGenHeader)
556 // The chain loads the generator event header for us
557 // You must provide the address where it can be found
558 fGenHeader = aGenHeader;
562 void AliFemtoEventReaderESDChainKine::SetUseTPCOnly(const bool usetpconly)
564 fUseTPCOnly=usetpconly;
566 void AliFemtoEventReaderESDChainKine::SetRotateToEventPlane(short dorotate)
568 fRotateToEventPlane=dorotate;
571 bool AliFemtoEventReaderESDChainKine::GetUseTPCOnly() const
575 Float_t AliFemtoEventReaderESDChainKine::GetSigmaToVertex(double *impact, double *covar)
577 // Calculates the number of sigma to the vertex.
589 bRes[0] = TMath::Sqrt(bCov[0]);
590 bRes[1] = TMath::Sqrt(bCov[2]);
592 // -----------------------------------
593 // How to get to a n-sigma cut?
595 // The accumulated statistics from 0 to d is
597 // -> Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
598 // -> 1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
600 // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
601 // Can this be expressed in a different way?
603 if (bRes[0] == 0 || bRes[1] ==0)
606 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
608 // stupid rounding problem screws up everything:
609 // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
610 if (TMath::Exp(-d * d / 2) < 1e-10)
613 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);