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"
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"
24 #include "TParticle.h"
25 #include "AliFemtoModelHiddenInfo.h"
26 #include "AliGenHijingEventHeader.h"
28 ClassImp(AliFemtoEventReaderESDChainKine)
30 #if !(ST_NO_NAMESPACES)
31 using namespace units;
35 //____________________________
36 AliFemtoEventReaderESDChainKine::AliFemtoEventReaderESDChainKine():
47 //constructor with 0 parameters , look at default settings
51 AliFemtoEventReaderESDChainKine::AliFemtoEventReaderESDChainKine(const AliFemtoEventReaderESDChainKine& aReader):
52 AliFemtoEventReader(aReader),
64 fConstrained = aReader.fConstrained;
65 fUseTPCOnly = aReader.fUseTPCOnly;
66 fNumberofEvent = aReader.fNumberofEvent;
67 fCurEvent = aReader.fCurEvent;
68 fCurFile = aReader.fCurFile;
69 fEvent = new AliESDEvent();
70 fStack = aReader.fStack;
73 AliFemtoEventReaderESDChainKine::~AliFemtoEventReaderESDChainKine()
80 AliFemtoEventReaderESDChainKine& AliFemtoEventReaderESDChainKine::operator=(const AliFemtoEventReaderESDChainKine& aReader)
82 // Assignment operator
86 fConstrained = aReader.fConstrained;
87 fUseTPCOnly = aReader.fUseTPCOnly;
88 fNumberofEvent = aReader.fNumberofEvent;
89 fCurEvent = aReader.fCurEvent;
90 fCurFile = aReader.fCurFile;
91 if (fEvent) delete fEvent;
92 fEvent = new AliESDEvent();
93 fStack = aReader.fStack;
94 fGenHeader = aReader.fGenHeader;
100 AliFemtoString AliFemtoEventReaderESDChainKine::Report()
102 AliFemtoString temp = "\n This is the AliFemtoEventReaderESDChainKine\n";
107 void AliFemtoEventReaderESDChainKine::SetConstrained(const bool constrained)
109 // Select whether to read constrained or not constrained momentum
110 fConstrained=constrained;
113 bool AliFemtoEventReaderESDChainKine::GetConstrained() const
115 // Check whether we read constrained or not constrained momentum
119 AliFemtoEvent* AliFemtoEventReaderESDChainKine::ReturnHbtEvent()
121 // Get the event, read all the relevant information
122 // and fill the AliFemtoEvent class
123 // Returns a valid AliFemtoEvent
124 AliFemtoEvent *hbtEvent = 0;
125 string tFriendFileName;
127 // Get the friend information
128 cout<<"starting to read event "<<fCurEvent<<endl;
129 // fEvent->SetESDfriend(fEventFriend);
131 hbtEvent = new AliFemtoEvent;
132 //setting basic things
133 // hbtEvent->SetEventNumber(fEvent->GetEventNumber());
134 hbtEvent->SetRunNumber(fEvent->GetRunNumber());
135 //hbtEvent->SetNumberOfTracks(fEvent->GetNumberOfTracks());
136 hbtEvent->SetMagneticField(fEvent->GetMagneticField()*kilogauss);//to check if here is ok
137 hbtEvent->SetZDCN1Energy(fEvent->GetZDCN1Energy());
138 hbtEvent->SetZDCP1Energy(fEvent->GetZDCP1Energy());
139 hbtEvent->SetZDCN2Energy(fEvent->GetZDCN2Energy());
140 hbtEvent->SetZDCP2Energy(fEvent->GetZDCP2Energy());
141 hbtEvent->SetZDCEMEnergy(fEvent->GetZDCEMEnergy());
142 hbtEvent->SetZDCParticipants(fEvent->GetZDCParticipants());
143 hbtEvent->SetTriggerMask(fEvent->GetTriggerMask());
144 hbtEvent->SetTriggerCluster(fEvent->GetTriggerCluster());
149 fEvent->GetPrimaryVertexTPC()->GetXYZ(fV1);
152 fEvent->GetPrimaryVertex()->GetXYZ(fV1);
155 AliFmThreeVectorF vertex(fV1[0],fV1[1],fV1[2]);
156 hbtEvent->SetPrimVertPos(vertex);
158 AliGenHijingEventHeader *hdh = dynamic_cast<AliGenHijingEventHeader *> (fGenHeader);
160 Double_t tReactionPlane = 0;
163 tReactionPlane = hdh->ReactionPlaneAngle();
165 //starting to reading tracks
166 int nofTracks=0; //number of reconstructed tracks in event
167 nofTracks=fEvent->GetNumberOfTracks();
168 int realnofTracks=0;//number of track which we use ina analysis
171 motherids = new Int_t[fStack->GetNtrack()];
172 for (int ip=0; ip<fStack->GetNtrack(); ip++) motherids[ip] = 0;
174 // Read in mother ids
175 TParticle *motherpart;
176 for (int ip=0; ip<fStack->GetNtrack(); ip++) {
177 motherpart = fStack->Particle(ip);
178 if (motherpart->GetDaughter(0) > 0)
179 motherids[motherpart->GetDaughter(0)] = ip;
180 if (motherpart->GetDaughter(1) > 0)
181 motherids[motherpart->GetDaughter(1)] = ip;
183 // if (motherpart->GetPdgCode() == 211) {
184 // cout << "Mother " << ip << " has daughters "
185 // << motherpart->GetDaughter(0) << " "
186 // << motherpart->GetDaughter(1) << " "
187 // << motherpart->Vx() << " "
188 // << motherpart->Vy() << " "
189 // << motherpart->Vz() << " "
195 for (int i=0;i<nofTracks;i++)
197 bool tGoodMomentum=true; //flaga to chcek if we can read momentum of this track
199 AliFemtoTrack* trackCopy = new AliFemtoTrack();
200 const AliESDtrack *esdtrack=fEvent->GetTrack(i);//getting next track
201 // const AliESDfriendTrack *tESDfriendTrack = esdtrack->GetFriendTrack();
203 trackCopy->SetCharge((short)esdtrack->GetSign());
205 //in aliroot we have AliPID
206 //0-electron 1-muon 2-pion 3-kaon 4-proton 5-photon 6-pi0 7-neutron 8-kaon0 9-eleCon
207 //we use only 5 first
209 esdtrack->GetESDpid(esdpid);
210 trackCopy->SetPidProbElectron(esdpid[0]);
211 trackCopy->SetPidProbMuon(esdpid[1]);
212 trackCopy->SetPidProbPion(esdpid[2]);
213 trackCopy->SetPidProbKaon(esdpid[3]);
214 trackCopy->SetPidProbProton(esdpid[4]);
222 if (!esdtrack->GetTPCInnerParam()) {
227 AliExternalTrackParam *param = new AliExternalTrackParam(*esdtrack->GetTPCInnerParam());
229 param->PropagateToDCA(fEvent->GetPrimaryVertexTPC(), (fEvent->GetMagneticField()), 10000, impact, covimpact);
230 param->GetPxPyPz(pxyz);//reading noconstarined momentum
232 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
233 if (v.mag() < 0.0001) {
234 // cout << "Found 0 momentum ???? " <<endl;
238 trackCopy->SetP(v);//setting momentum
239 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
241 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
242 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
243 //setting helix I do not if it is ok
244 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
245 trackCopy->SetHelix(helix);
247 //some stuff which could be useful
248 trackCopy->SetImpactD(impact[0]);
249 trackCopy->SetImpactZ(impact[1]);
250 trackCopy->SetCdd(covimpact[0]);
251 trackCopy->SetCdz(covimpact[1]);
252 trackCopy->SetCzz(covimpact[2]);
253 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact, covimpact));
258 if (fConstrained==true)
259 tGoodMomentum=esdtrack->GetConstrainedPxPyPz(pxyz); //reading constrained momentum
261 tGoodMomentum=esdtrack->GetPxPyPz(pxyz);//reading noconstarined momentum
263 AliFemtoThreeVector v(pxyz[0],pxyz[1],pxyz[2]);
264 if (v.mag() < 0.0001) {
265 // cout << "Found 0 momentum ???? " <<endl;
269 trackCopy->SetP(v);//setting momentum
270 trackCopy->SetPt(sqrt(pxyz[0]*pxyz[0]+pxyz[1]*pxyz[1]));
271 const AliFmThreeVectorD kP(pxyz[0],pxyz[1],pxyz[2]);
272 const AliFmThreeVectorD kOrigin(fV1[0],fV1[1],fV1[2]);
273 //setting helix I do not if it is ok
274 AliFmPhysicalHelixD helix(kP,kOrigin,(double)(fEvent->GetMagneticField())*kilogauss,(double)(trackCopy->Charge()));
275 trackCopy->SetHelix(helix);
277 //some stuff which could be useful
280 esdtrack->GetImpactParameters(imp,cim);
284 covimpact[0] = cim[0];
285 covimpact[1] = cim[1];
286 covimpact[2] = cim[2];
288 trackCopy->SetImpactD(impact[0]);
289 trackCopy->SetImpactZ(impact[1]);
290 trackCopy->SetCdd(covimpact[0]);
291 trackCopy->SetCdz(covimpact[1]);
292 trackCopy->SetCzz(covimpact[2]);
293 trackCopy->SetSigmaToVertex(GetSigmaToVertex(impact,covimpact));
296 trackCopy->SetTrackId(esdtrack->GetID());
297 trackCopy->SetFlags(esdtrack->GetStatus());
298 trackCopy->SetLabel(esdtrack->GetLabel());
300 trackCopy->SetITSchi2(esdtrack->GetITSchi2());
301 trackCopy->SetITSncls(esdtrack->GetNcls(0));
302 trackCopy->SetTPCchi2(esdtrack->GetTPCchi2());
303 trackCopy->SetTPCncls(esdtrack->GetTPCNcls());
304 trackCopy->SetTPCnclsF(esdtrack->GetTPCNclsF());
305 trackCopy->SetTPCsignalN((short)esdtrack->GetTPCsignalN()); //due to bug in aliesdtrack class
306 trackCopy->SetTPCsignalS(esdtrack->GetTPCsignalSigma());
309 trackCopy->SetTPCClusterMap(esdtrack->GetTPCClusterMap());
310 trackCopy->SetTPCSharedMap(esdtrack->GetTPCSharedMap());
313 esdtrack->GetInnerXYZ(xtpc);
315 trackCopy->SetNominalTPCEntrancePoint(xtpc);
317 esdtrack->GetOuterXYZ(xtpc);
319 trackCopy->SetNominalTPCExitPoint(xtpc);
322 for (int ik=0; ik<3; ik++) {
323 indexes[ik] = esdtrack->GetKinkIndex(ik);
325 trackCopy->SetKinkIndexes(indexes);
327 // Fill the hidden information with the simulated data
328 TParticle *tPart = fStack->Particle(TMath::Abs(esdtrack->GetLabel()));
330 // Check the mother information
332 // Using the new way of storing the freeze-out information
333 // Final state particle is stored twice on the stack
334 // one copy (mother) is stored with original freeze-out information
335 // and is not tracked
336 // the other one (daughter) is stored with primary vertex position
339 // Freeze-out coordinates
340 double fpx=0.0, fpy=0.0, fpz=0.0, fpt=0.0;
346 if (motherids[TMath::Abs(esdtrack->GetLabel())]>0) {
347 TParticle *mother = fStack->Particle(motherids[TMath::Abs(esdtrack->GetLabel())]);
348 // Check if this is the same particle stored twice on the stack
349 if ((mother->GetPdgCode() == tPart->GetPdgCode() || (mother->Px() == tPart->Px()))) {
350 // It is the same particle
351 // Read in the original freeze-out information
352 // and convert it from to [fm]
353 fpx = mother->Vx()*1e13;
354 fpy = mother->Vy()*1e13;
355 fpz = mother->Vz()*1e13;
356 fpt = mother->T()*1e13*3e10;
361 AliFemtoModelHiddenInfo *tInfo = new AliFemtoModelHiddenInfo();
362 tInfo->SetPDGPid(tPart->GetPdgCode());
363 tInfo->SetTrueMomentum(tPart->Px(), tPart->Py(), tPart->Pz());
364 Double_t mass2 = (tPart->Energy() *tPart->Energy() -
365 tPart->Px()*tPart->Px() -
366 tPart->Py()*tPart->Py() -
367 tPart->Pz()*tPart->Pz());
369 tInfo->SetMass(TMath::Sqrt(mass2));
373 tInfo->SetEmissionPoint(fpx, fpy, fpz, fpt);
374 trackCopy->SetHiddenInfo(tInfo);
376 //decision if we want this track
377 //if we using diffrent labels we want that this label was use for first time
378 //if we use hidden info we want to have match between sim data and ESD
379 if (tGoodMomentum==true)
381 hbtEvent->TrackCollection()->push_back(trackCopy);//adding track to analysis
382 realnofTracks++;//real number of tracks
392 hbtEvent->SetNumberOfTracks(realnofTracks);//setting number of track which we read in event
394 cout<<"end of reading nt "<<nofTracks<<" real number "<<realnofTracks<<endl;
397 //___________________
398 void AliFemtoEventReaderESDChainKine::SetESDSource(AliESDEvent *aESD)
400 // The chain loads the ESD for us
401 // You must provide the address where it can be found
404 //___________________
405 void AliFemtoEventReaderESDChainKine::SetStackSource(AliStack *aStack)
407 // The chain loads the stack for us
408 // You must provide the address where it can be found
411 //___________________
412 void AliFemtoEventReaderESDChainKine::SetGenEventHeader(AliGenEventHeader *aGenHeader)
414 // The chain loads the generator event header for us
415 // You must provide the address where it can be found
416 fGenHeader = aGenHeader;
420 void AliFemtoEventReaderESDChainKine::SetUseTPCOnly(const bool usetpconly)
422 fUseTPCOnly=usetpconly;
425 bool AliFemtoEventReaderESDChainKine::GetUseTPCOnly() const
429 Float_t AliFemtoEventReaderESDChainKine::GetSigmaToVertex(double *impact, double *covar)
431 // Calculates the number of sigma to the vertex.
443 bRes[0] = TMath::Sqrt(bCov[0]);
444 bRes[1] = TMath::Sqrt(bCov[2]);
446 // -----------------------------------
447 // How to get to a n-sigma cut?
449 // The accumulated statistics from 0 to d is
451 // -> Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
452 // -> 1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
454 // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
455 // Can this be expressed in a different way?
457 if (bRes[0] == 0 || bRes[1] ==0)
460 Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
462 // stupid rounding problem screws up everything:
463 // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
464 if (TMath::Exp(-d * d / 2) < 1e-10)
467 d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);