KFTopoPerformance.cxx 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182
  1. //----------------------------------------------------------------------------
  2. // Implementation of the KFParticle class
  3. // .
  4. // @author I.Kisel, I.Kulakov, M.Zyzak
  5. // @version 1.0
  6. // @since 20.08.13
  7. //
  8. //
  9. // -= Copyright &copy ALICE HLT and CBM L1 Groups =-
  10. //____________________________________________________________________________
  11. #define DO_TPCCATRACKER_EFF_PERFORMANCE
  12. #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
  13. #include "KFTopoPerformance.h"
  14. #ifdef KFPWITHTRACKER
  15. #ifdef MAIN_DRAW
  16. #include "AliHLTTPCCADisplay.h"
  17. #endif //DRAW
  18. #include "AliHLTTPCCATracker.h"
  19. #include "AliHLTTPCCAPerformance.h"
  20. #endif
  21. #include "KFParticleTopoReconstructor.h"
  22. #include "KFParticleSIMD.h"
  23. #include "KFPHistogram/KFPHistogram.h"
  24. #include "TParticlePDG.h"
  25. #include "TDatabasePDG.h"
  26. #include "TMath.h"
  27. #include "TH1.h"
  28. #include "TH2.h"
  29. #include "TH3.h"
  30. #include "TProfile.h"
  31. #include "TProfile2D.h"
  32. #include <map>
  33. #include <algorithm>
  34. using std::sort;
  35. using std::vector;
  36. KFTopoPerformance::KFTopoPerformance():KFParticlePerformanceBase(),fTopoReconstructor(0),fPrimVertices(0), fMCTrackToMCPVMatch(0),
  37. fPVPurity(0), fNCorrectPVTracks(0), fTrackMatch(0), vMCTracks(0), vMCParticles(0), fNeutralIndex(0), MCtoRParticleId(0), RtoMCParticleId(0),
  38. MCtoRPVId(0), RtoMCPVId(0), fPrintEffFrequency(1), fCentralityBin(-1), fCentralityWeight(0.f)
  39. {
  40. }
  41. KFTopoPerformance::~KFTopoPerformance()
  42. {
  43. }
  44. #ifdef KFPWITHTRACKER
  45. void KFTopoPerformance::SetNewEvent(
  46. const AliHLTTPCCAGBTracker * const tracker,
  47. AliHLTResizableArray<AliHLTTPCCAHitLabel> *hitLabels,
  48. AliHLTResizableArray<AliHLTTPCCAMCTrack> *mcTracks,
  49. AliHLTResizableArray<AliHLTTPCCALocalMCPoint> *localMCPoints)
  50. {
  51. vMCTracks.resize(mcTracks->Size());
  52. for(int iTr=0; iTr<vMCTracks.size(); iTr++)
  53. {
  54. for(int iP=0; iP<3; iP++)
  55. vMCTracks[iTr].SetPar(iP, (*mcTracks)[iTr].Par(iP));
  56. for(int iP=3; iP<6; iP++)
  57. vMCTracks[iTr].SetPar(iP, (*mcTracks)[iTr].Par(iP) * (*mcTracks)[iTr].P());
  58. vMCTracks[iTr].SetPar(6, (*mcTracks)[iTr].Par(6));
  59. vMCTracks[iTr].SetPDG( (*mcTracks)[iTr].PDG() );
  60. vMCTracks[iTr].SetMotherId( (*mcTracks)[iTr].MotherId() );
  61. vMCTracks[iTr].SetNMCPoints( (*mcTracks)[iTr].NMCPoints() );
  62. }
  63. } // void KFTopoPerformance::SetNewEvent
  64. #endif
  65. void KFTopoPerformance::SetTopoReconstructor( const KFParticleTopoReconstructor * const TopoReconstructor)
  66. {
  67. /** Sets a pointer to the external KFParticleTopoReconstructor object. */
  68. fTopoReconstructor = TopoReconstructor;
  69. } // void KFTopoPerformance::SetTopoReconstructor
  70. void KFTopoPerformance::CheckMCTracks()
  71. {
  72. /** Cleans Monte Carlo information on primary vertices, and refill it with the current event. */
  73. fMCTrackToMCPVMatch.clear();
  74. fPrimVertices.clear();
  75. // find prim vertex
  76. if (vMCTracks.size() <= 0) return;
  77. fMCTrackToMCPVMatch.resize(vMCTracks.size(),-1);
  78. vector<int> pvIndex;
  79. for(unsigned int iTr=0; iTr<vMCTracks.size(); iTr++)
  80. {
  81. KFMCTrack &mctr = vMCTracks[iTr];
  82. int motherID = mctr.MotherId();
  83. if(motherID <0 )
  84. {
  85. bool newPV = 1;
  86. for(unsigned int iPV=0; iPV<pvIndex.size(); iPV++)
  87. {
  88. if(motherID == pvIndex[iPV])
  89. {
  90. fPrimVertices[iPV].AddDaughterTrack(iTr);
  91. fMCTrackToMCPVMatch[iTr] = iPV;
  92. newPV = 0;
  93. }
  94. }
  95. if(newPV)
  96. {
  97. KFMCVertex primVertex;
  98. primVertex.SetX( mctr.X() );
  99. primVertex.SetY( mctr.Y() );
  100. primVertex.SetZ( mctr.Z() );
  101. primVertex.AddDaughterTrack(iTr);
  102. if(motherID == -1)
  103. primVertex.SetTriggerPV();
  104. fPrimVertices.push_back(primVertex);
  105. fMCTrackToMCPVMatch[iTr] = pvIndex.size();
  106. pvIndex.push_back(motherID);
  107. }
  108. }
  109. }
  110. } // void KFTopoPerformance::CheckMCTracks()
  111. void KFTopoPerformance::GetMCParticles()
  112. {
  113. /** Fills information on relations between Monte Carlo particles. */
  114. vMCParticles.clear();
  115. vMCParticles.reserve(vMCTracks.size());
  116. // all MC tracks are copied into KF MC Particles
  117. for(unsigned int iMC=0; iMC < vMCTracks.size(); iMC++)
  118. {
  119. KFMCTrack &mtra = vMCTracks[iMC];
  120. KFMCParticle part;
  121. part.SetMCTrackID( iMC );
  122. part.SetMotherId ( mtra.MotherId() );
  123. part.SetPDG ( mtra.PDG() );
  124. vMCParticles.push_back( part );
  125. }
  126. // find relations between mother and daughter MC particles
  127. const int nMCParticles = vMCParticles.size();
  128. for (int iP = 0; iP < nMCParticles; iP++ ) {
  129. KFMCParticle &part = vMCParticles[iP];
  130. int motherId = part.GetMotherId();
  131. if(motherId < 0) continue;
  132. if(motherId >= nMCParticles)
  133. {
  134. std::cout << "ERROR!!!!! KF Particle Performance: MC track mother Id is out of range." << std::endl;
  135. exit(1);
  136. }
  137. KFMCParticle &motherPart = vMCParticles[motherId];
  138. motherPart.AddDaughter(iP);
  139. }
  140. fNeutralIndex.clear();
  141. fNeutralIndex.resize(nMCParticles, -1);
  142. for(unsigned int iMC=0; iMC < vMCParticles.size(); iMC++)
  143. {
  144. KFMCParticle &part = vMCParticles[iMC];
  145. part.SetMCTrackID( iMC );
  146. }
  147. const int NmmPDG = 7;
  148. vector<int> mmMotherPDG(NmmPDG); //PDG for particles found by the missing mass method
  149. vector<int> mmChargedDaughterPDG(NmmPDG);
  150. vector<int> mmNeutralDaughterPDG(NmmPDG);
  151. vector<int> newMotherPDG(NmmPDG);
  152. vector<int> newNeutralPDG(NmmPDG);
  153. mmMotherPDG[ 0] = 3112; mmChargedDaughterPDG[ 0] = 211; mmNeutralDaughterPDG[ 0] = 2112;
  154. mmMotherPDG[ 1] = 3222; mmChargedDaughterPDG[ 1] = 211; mmNeutralDaughterPDG[ 1] = 2112;
  155. mmMotherPDG[ 2] = 3312; mmChargedDaughterPDG[ 2] = 211; mmNeutralDaughterPDG[ 2] = 3122;
  156. mmMotherPDG[ 3] = 3334; mmChargedDaughterPDG[ 3] = 211; mmNeutralDaughterPDG[ 3] = 3322;
  157. mmMotherPDG[ 4] = 321; mmChargedDaughterPDG[ 4] = 211; mmNeutralDaughterPDG[ 4] = 111;
  158. mmMotherPDG[ 5] = 3334; mmChargedDaughterPDG[ 5] = 321; mmNeutralDaughterPDG[ 5] = 3122;
  159. mmMotherPDG[ 6] = 3222; mmChargedDaughterPDG[ 6] = 2212; mmNeutralDaughterPDG[ 6] = 111;
  160. newMotherPDG[ 0] = 7003112; newNeutralPDG[ 0] = 7002112;
  161. newMotherPDG[ 1] = 7003222; newNeutralPDG[ 1] = 8002112;
  162. newMotherPDG[ 2] = 7003312; newNeutralPDG[ 2] = 7003122;
  163. newMotherPDG[ 3] = 7003334; newNeutralPDG[ 3] = 7003322;
  164. newMotherPDG[ 4] = 9000321; newNeutralPDG[ 4] = 9000111;
  165. newMotherPDG[ 5] = 8003334; newNeutralPDG[ 5] = 8003122;
  166. newMotherPDG[ 6] = 8003222; newNeutralPDG[ 6] = 8000111;
  167. //add neutrinos, if they are not saved
  168. for(int iMC=0; iMC<nMCParticles; iMC++)
  169. {
  170. if( abs(vMCParticles[iMC].GetPDG()) == 211 || abs(vMCParticles[iMC].GetPDG()) == 321 )
  171. {
  172. int muonIndex = -1;
  173. for(int iD=0; iD<vMCParticles[iMC].NDaughters(); iD++)
  174. if( abs(vMCParticles[vMCParticles[iMC].GetDaughterIds()[iD]].GetPDG()) == 13 )
  175. muonIndex = vMCParticles[iMC].GetDaughterIds()[iD];
  176. if(muonIndex > -1)
  177. {
  178. int newPDG = 0;
  179. if(vMCParticles[iMC].GetPDG() >0)
  180. newPDG = vMCParticles[iMC].GetPDG() + 7000000;
  181. else
  182. newPDG = vMCParticles[iMC].GetPDG() - 7000000;
  183. KFMCParticle motherPart = vMCParticles[iMC];
  184. KFMCTrack motherTrack = vMCTracks[motherPart.GetMCTrackID()];
  185. motherTrack.SetPDG(newPDG);
  186. motherTrack.SetNotReconstructed();
  187. int newMotherIndex = vMCTracks.size();
  188. motherPart.SetPDG(newPDG);
  189. motherPart.SetMCTrackID(newMotherIndex);
  190. const KFMCParticle& daughterPart = vMCParticles[muonIndex];
  191. const KFMCTrack& daughterTrack = vMCTracks[daughterPart.GetMCTrackID()];
  192. int neutrinoPDG = 7000014;
  193. if(vMCParticles[iMC].GetPDG() == -211) neutrinoPDG = -7000014;
  194. if(vMCParticles[iMC].GetPDG() == 321) neutrinoPDG = 8000014;
  195. if(vMCParticles[iMC].GetPDG() == -321) neutrinoPDG = -8000014;
  196. int neutrinoIndex = vMCTracks.size()+1;
  197. vMCParticles[iMC].AddDaughter(neutrinoIndex);
  198. fNeutralIndex[iMC] = neutrinoIndex;
  199. KFMCParticle neutrinoPart;
  200. KFMCTrack neutrinoTrack;
  201. neutrinoTrack.SetX(daughterTrack.X());
  202. neutrinoTrack.SetY(daughterTrack.Y());
  203. neutrinoTrack.SetZ(daughterTrack.Z());
  204. neutrinoTrack.SetPx(motherTrack.Px() - daughterTrack.Px());
  205. neutrinoTrack.SetPy(motherTrack.Py() - daughterTrack.Py());
  206. neutrinoTrack.SetPz(motherTrack.Pz() - daughterTrack.Pz());
  207. neutrinoTrack.SetQP(0);
  208. neutrinoTrack.SetMotherId(newMotherIndex);
  209. neutrinoTrack.SetPDG(neutrinoPDG);
  210. motherPart.CleanDaughters();
  211. motherPart.AddDaughter(muonIndex);
  212. motherPart.AddDaughter(neutrinoIndex);
  213. motherPart.SetInitialParticleId(iMC);
  214. vMCTracks.push_back(motherTrack);
  215. vMCParticles.push_back(motherPart);
  216. fNeutralIndex.push_back(-1);
  217. neutrinoPart.SetMCTrackID(neutrinoIndex);
  218. neutrinoPart.SetMotherId(newMotherIndex);
  219. neutrinoPart.SetPDG(neutrinoPDG);
  220. neutrinoPart.AddDaughter(iMC);
  221. neutrinoPart.AddDaughter(muonIndex);
  222. vMCTracks.push_back(neutrinoTrack);
  223. vMCParticles.push_back(neutrinoPart);
  224. fNeutralIndex.push_back(-1);
  225. vMCParticles[iMC].SetAsReconstructable(4);
  226. vMCParticles[muonIndex].SetAsReconstructable(4);
  227. }
  228. }
  229. // add sigmas, omegas, xis ...
  230. if( vMCParticles[iMC].NDaughters() >= 2 &&
  231. (abs(vMCParticles[iMC].GetPDG()) == 3112 ||
  232. abs(vMCParticles[iMC].GetPDG()) == 3222 ||
  233. abs(vMCParticles[iMC].GetPDG()) == 3312 ||
  234. abs(vMCParticles[iMC].GetPDG()) == 3334 ||
  235. abs(vMCParticles[iMC].GetPDG()) == 321) )
  236. {
  237. int neutralDaughterId = -1, chargedDaughterId = -1;
  238. int newPDG = 0;
  239. int neutralPDG = 0;
  240. for(int iPDG=0; iPDG<NmmPDG; iPDG++)
  241. {
  242. if(abs(vMCParticles[iMC].GetPDG()) == mmMotherPDG[iPDG])
  243. {
  244. bool isDaughter[2] = {0,0};
  245. vector<float> xDaughter;
  246. vector<float> yDaughter;
  247. vector<float> zDaughter;
  248. vector< vector<int> > nDaughtersAtPoint;
  249. for(int iMCDaughter=0; iMCDaughter<vMCParticles[iMC].NDaughters(); iMCDaughter++)
  250. {
  251. bool isNewDecayPoint = 1;
  252. for(unsigned int iPoint=0; iPoint<xDaughter.size(); iPoint++)
  253. {
  254. float dx = fabs(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].X() - xDaughter[iPoint]);
  255. float dy = fabs(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].Y() - yDaughter[iPoint]);
  256. float dz = fabs(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].Z() - zDaughter[iPoint]);
  257. bool isSamePoint = (dx < 1.e-5 && dy < 1.e-5 && dz < 1.e-5);
  258. if(isSamePoint)
  259. nDaughtersAtPoint[iPoint].push_back(iMCDaughter);
  260. isNewDecayPoint &= !isSamePoint;
  261. }
  262. if(isNewDecayPoint)
  263. {
  264. xDaughter.push_back(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].X());
  265. yDaughter.push_back(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].Y());
  266. zDaughter.push_back(vMCTracks[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].Z());
  267. vector<int> newPointIndex;
  268. newPointIndex.push_back(iMCDaughter);
  269. nDaughtersAtPoint.push_back(newPointIndex);
  270. }
  271. }
  272. for(unsigned int iPoint = 0; iPoint<nDaughtersAtPoint.size(); iPoint++)
  273. {
  274. if(nDaughtersAtPoint[iPoint].size() == 2)
  275. {
  276. for(unsigned int iDaughter=0; iDaughter<nDaughtersAtPoint[iPoint].size(); iDaughter++)
  277. {
  278. int iMCDaughter = nDaughtersAtPoint[iPoint][iDaughter];
  279. if(abs(vMCParticles[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].GetPDG()) == mmChargedDaughterPDG[iPDG])
  280. {
  281. isDaughter[0] = 1;
  282. chargedDaughterId = vMCParticles[iMC].GetDaughterIds()[iMCDaughter];
  283. }
  284. if(abs(vMCParticles[vMCParticles[iMC].GetDaughterIds()[iMCDaughter]].GetPDG()) == mmNeutralDaughterPDG[iPDG])
  285. {
  286. isDaughter[1] = 1;
  287. neutralDaughterId = vMCParticles[iMC].GetDaughterIds()[iMCDaughter];
  288. }
  289. }
  290. if(isDaughter[0] && isDaughter[1])
  291. {
  292. int signPDG = vMCParticles[iMC].GetPDG()/abs(vMCParticles[iMC].GetPDG());
  293. newPDG = signPDG * newMotherPDG[iPDG];
  294. neutralPDG = signPDG * newNeutralPDG[iPDG];
  295. }
  296. }
  297. }
  298. }
  299. }
  300. if(newPDG != 0)
  301. {
  302. KFMCParticle motherPart = vMCParticles[iMC];
  303. KFMCTrack motherTrack = vMCTracks[motherPart.GetMCTrackID()];
  304. motherTrack.SetPDG(newPDG);
  305. motherTrack.SetNotReconstructed();
  306. int newMotherIndex = vMCTracks.size();
  307. motherPart.SetPDG(newPDG);
  308. motherPart.SetMCTrackID(newMotherIndex);
  309. int neutrinoIndex = vMCTracks.size()+1;
  310. fNeutralIndex[iMC] = neutrinoIndex;
  311. KFMCTrack neutralTrack = vMCTracks[neutralDaughterId];
  312. neutralTrack.SetMotherId(newMotherIndex);
  313. neutralTrack.SetPDG(neutralPDG);
  314. motherPart.CleanDaughters();
  315. motherPart.AddDaughter(chargedDaughterId);
  316. motherPart.AddDaughter(neutrinoIndex);
  317. motherPart.SetInitialParticleId(iMC);
  318. vMCTracks.push_back(motherTrack);
  319. vMCParticles.push_back(motherPart);
  320. fNeutralIndex.push_back(-1);
  321. KFMCParticle neutralPart;
  322. neutralPart.SetMCTrackID(neutrinoIndex);
  323. neutralPart.SetMotherId(newMotherIndex);
  324. neutralPart.SetPDG(neutralPDG);
  325. neutralPart.AddDaughter(iMC);
  326. neutralPart.AddDaughter(chargedDaughterId);
  327. vMCTracks.push_back(neutralTrack);
  328. vMCParticles.push_back(neutralPart);
  329. fNeutralIndex.push_back(-1);
  330. vMCParticles[iMC].SetAsReconstructable(4);
  331. vMCParticles[chargedDaughterId].SetAsReconstructable(4);
  332. }
  333. }
  334. }
  335. //clean Lambda c daughters
  336. for(unsigned int iMC=0; iMC < vMCParticles.size(); iMC++)
  337. {
  338. KFMCParticle &part = vMCParticles[iMC];
  339. // if(abs(part.GetPDG()) == 4122)
  340. {
  341. //add daughters into one pool
  342. vector<int> newDaughters;
  343. for(unsigned int iD=0; iD<part.GetDaughterIds().size(); iD++)
  344. {
  345. KFMCParticle &d = vMCParticles[part.GetDaughterIds()[iD]];
  346. if( abs(d.GetPDG())==3224 ||
  347. abs(d.GetPDG())==3114 ||
  348. abs(d.GetPDG())==113 ||
  349. abs(d.GetPDG())==313 ||
  350. abs(d.GetPDG())==323 ||
  351. abs(d.GetPDG())==2224 ||
  352. abs(d.GetPDG())==2214 ||
  353. abs(d.GetPDG())==2114 ||
  354. abs(d.GetPDG())==1114
  355. )
  356. {
  357. for(unsigned int iDaughter=0; iDaughter<d.GetDaughterIds().size(); iDaughter++)
  358. {
  359. newDaughters.push_back(d.GetDaughterIds()[iDaughter]);
  360. vMCParticles[d.GetDaughterIds()[iDaughter]].SetMotherId(iMC);
  361. }
  362. }
  363. else
  364. // if(d.GetDaughterIds().size() == 0 || abs(d.GetPDG())==310 || abs(d.GetPDG())==3122)
  365. newDaughters.push_back(part.GetDaughterIds()[iD]);
  366. }
  367. part.CleanDaughters();
  368. for(unsigned int iDaughter=0; iDaughter<newDaughters.size(); iDaughter++)
  369. part.AddDaughter(newDaughters[iDaughter]);
  370. //change PDG to separate channels
  371. int indexPDG = fParteff.GetParticleIndex(part.GetPDG());
  372. for(int iPDG=indexPDG; iPDG<indexPDG+10; iPDG++)
  373. {
  374. const int nDaughters = part.GetDaughterIds().size();
  375. if(int(fParteff.partDaughterPdg[iPDG].size()) != nDaughters)
  376. continue;
  377. vector<bool> isDaughterFound(nDaughters);
  378. vector<bool> isDaughterUsed(nDaughters);
  379. for(int iDMC=0; iDMC<nDaughters; iDMC++)
  380. {
  381. isDaughterFound[iDMC] = 0;
  382. isDaughterUsed[iDMC] = 0;
  383. }
  384. bool isCorrectPDG = 1;
  385. for(int iDMC=0; iDMC<nDaughters; iDMC++)
  386. for(int iD=0; iD<nDaughters; iD++)
  387. {
  388. if(isDaughterUsed[iD]) continue;
  389. if(vMCParticles[part.GetDaughterIds()[iD]].GetPDG() == fParteff.partDaughterPdg[iPDG][iDMC])
  390. {
  391. isDaughterUsed[iD] = 1;
  392. isDaughterFound[iDMC] = 1;
  393. break;
  394. }
  395. }
  396. for(int iDMC=0; iDMC<nDaughters; iDMC++)
  397. isCorrectPDG &= isDaughterFound[iDMC];
  398. if(isCorrectPDG)
  399. {
  400. part.SetPDG(fParteff.partPDG[iPDG]);
  401. break;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. void KFTopoPerformance::FindReconstructableMCParticles()
  408. {
  409. /** Check each Monte Carlo particle if it can be reconstructed. */
  410. const unsigned int nMCParticles = vMCParticles.size();
  411. for ( unsigned int iP = 0; iP < nMCParticles; iP++ ) {
  412. KFMCParticle &part = vMCParticles[iP];
  413. CheckMCParticleIsReconstructable(part);
  414. }
  415. }
  416. void KFTopoPerformance::CheckMCParticleIsReconstructable(KFMCParticle &part)
  417. {
  418. /** Checks if the given Monte Carlo particle can be reconstructed. */
  419. if ( part.IsReconstructable(0) ) return;
  420. if ( vMCTracks[part.GetMCTrackID()].IsOutOfDetector() ) return;
  421. if( abs(part.GetPDG()) == 211 ||
  422. abs(part.GetPDG()) == 2212 ||
  423. abs(part.GetPDG()) == 321 ||
  424. abs(part.GetPDG()) == 13 ||
  425. abs(part.GetPDG()) == 3112 ||
  426. abs(part.GetPDG()) == 3222 ||
  427. abs(part.GetPDG()) == 3312 ||
  428. abs(part.GetPDG()) == 3334 )
  429. {
  430. int iMCTrack = part.GetMCTrackID();
  431. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  432. // reconstructable in 4pi is defined in GetMCParticles, when decay is found
  433. if(mcTrack.IsReconstructed())
  434. part.SetAsReconstructable(3);
  435. }
  436. // tracks
  437. if ( abs(part.GetPDG()) == 211 ||
  438. abs(part.GetPDG()) == 2212 ||
  439. abs(part.GetPDG()) == 321 ||
  440. abs(part.GetPDG()) == 11 ||
  441. abs(part.GetPDG()) == 13 ||
  442. abs(part.GetPDG()) == 1000010020 ||
  443. abs(part.GetPDG()) == 1000010030 ||
  444. abs(part.GetPDG()) == 1000020030 ||
  445. abs(part.GetPDG()) == 1000020040 ||
  446. ( (part.GetPDG() == 22) && (vMCTracks[part.GetMCTrackID()].IsReconstructed()) ) )
  447. {
  448. int iMCTrack = part.GetMCTrackID();
  449. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  450. part.SetAsReconstructable(0);
  451. if(mcTrack.NMCPoints() >= 15)
  452. part.SetAsReconstructable(1);
  453. // if(mc.IsReconstructable())
  454. // part.SetAsReconstructable2();
  455. if(mcTrack.IsReconstructed())
  456. part.SetAsReconstructable(2);
  457. }
  458. // mother particles
  459. else
  460. {
  461. //Check if the particle is V0
  462. if(part.NDaughters() >= 2)
  463. {
  464. bool isPositiveDaughter[5] = {0,0,0,0,0};
  465. bool isNegativeDaughter[5] = {0,0,0,0,0};
  466. int nRecoDaughters[5] = {0,0,0,0,0};
  467. for(int iD=0; iD < part.NDaughters(); iD++)
  468. {
  469. KFMCParticle &daughter = vMCParticles[part.GetDaughterIds()[iD]];
  470. CheckMCParticleIsReconstructable(daughter);
  471. TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(daughter.GetPDG());
  472. Double_t charge = (particlePDG) ? particlePDG->Charge()/3 : 0;
  473. for(int iEff=0; iEff<5; iEff++)
  474. {
  475. if(charge > 0)
  476. isPositiveDaughter[iEff] |= daughter.IsReconstructable(iEff);
  477. else
  478. isNegativeDaughter[iEff] |= daughter.IsReconstructable(iEff);
  479. if(daughter.IsReconstructable(iEff))
  480. nRecoDaughters[iEff]++;
  481. }
  482. }
  483. // for(int iEff=0; iEff<3; iEff++)
  484. // if(isPositiveDaughter[iEff] && isNegativeDaughter[iEff])
  485. // part.SetAsReconstructableV0(iEff);
  486. for(int iEff=0; iEff<3; iEff++)
  487. if(nRecoDaughters[iEff] > 1)
  488. part.SetAsReconstructableV0(iEff);
  489. }
  490. for(int iPart=0; iPart<fParteff.nParticles; iPart++)
  491. {
  492. if(part.GetPDG() == fParteff.partPDG[iPart])
  493. {
  494. const unsigned int nDaughters = fParteff.partDaughterPdg[iPart].size();
  495. if( part.GetDaughterIds().size() != nDaughters ) return;
  496. vector<int> pdg(nDaughters);
  497. for(unsigned int iD=0; iD<nDaughters; iD++)
  498. pdg[iD] = vMCParticles[part.GetDaughterIds()[iD]].GetPDG();
  499. vector<bool> isDaughterFound(nDaughters);
  500. for(unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
  501. isDaughterFound[iDMC] = 0;
  502. bool isReco = 1;
  503. for(unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
  504. for(unsigned int iD=0; iD<nDaughters; iD++)
  505. if(pdg[iD] == fParteff.partDaughterPdg[iPart][iDMC]) isDaughterFound[iDMC] = 1;
  506. for(unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
  507. isReco = isReco && isDaughterFound[iDMC];
  508. if(!isReco) return;
  509. }
  510. }
  511. const vector<int>& dIds = part.GetDaughterIds();
  512. const unsigned int nD = dIds.size();
  513. if(nD == 0) return; //TODO optimize for all species
  514. bool reco1 = 1;
  515. bool reco2 = 1;
  516. bool reco3 = 1;
  517. bool reco4 = 1;
  518. bool reco5 = 1;
  519. for ( unsigned int iD = 0; iD < nD && (reco1 || reco2 || reco3 || reco4 || reco5); iD++ ) {
  520. KFMCParticle &dp = vMCParticles[dIds[iD]];
  521. CheckMCParticleIsReconstructable(dp);
  522. reco1 &= dp.IsReconstructable(0);
  523. reco2 &= dp.IsReconstructable(1);
  524. reco3 &= dp.IsReconstructable(2);
  525. reco4 &= dp.IsReconstructable(3);
  526. reco5 &= dp.IsReconstructable(4);
  527. }
  528. if (reco1) part.SetAsReconstructable(0);
  529. if (reco2) part.SetAsReconstructable(1);
  530. if (reco3) part.SetAsReconstructable(2);
  531. int iParticle = fParteff.GetParticleIndex(part.GetPDG());
  532. if (reco4 && iParticle>=KFPartEfficiencies::fFirstMissingMassParticleIndex &&
  533. iParticle<=KFPartEfficiencies::fLastMissingMassParticleIndex ) part.SetAsReconstructable(3);
  534. if (reco5 && iParticle>=KFPartEfficiencies::fFirstMissingMassParticleIndex &&
  535. iParticle<=KFPartEfficiencies::fLastMissingMassParticleIndex ) part.SetAsReconstructable(4);
  536. }
  537. }
  538. void KFTopoPerformance::FindReconstructableMCVertices()
  539. {
  540. /** Checks which Monte Carlo primary vertices can be reconstructed. */
  541. const unsigned int nMCVertices = fPrimVertices.size();
  542. for ( unsigned int iV = 0; iV < nMCVertices; iV++ ) {
  543. KFMCVertex &vert = fPrimVertices[iV];
  544. int nReconstructableDaughters = 0;
  545. int nMCReconstructableDaughters = 0;
  546. for(int iP=0; iP<vert.NDaughterTracks(); iP++)
  547. {
  548. int idDaughter = vert.DaughterTrack(iP);
  549. KFMCParticle &part = vMCParticles[idDaughter];
  550. if(part.IsReconstructable(2)) nReconstructableDaughters++;
  551. if(part.IsReconstructable(1)) nMCReconstructableDaughters++;
  552. }
  553. if(nReconstructableDaughters >= 2) vert.SetReconstructable();
  554. else vert.SetUnReconstructable();
  555. if(nMCReconstructableDaughters >= 2) vert.SetMCReconstructable();
  556. else vert.SetMCUnReconstructable();
  557. }
  558. }
  559. void KFTopoPerformance::MatchParticles()
  560. {
  561. /** Matches Monte Carlo and reconstructed particles. */
  562. MCtoRParticleId.clear();
  563. RtoMCParticleId.clear();
  564. MCtoRParticleId.resize(vMCParticles.size());
  565. RtoMCParticleId.resize(fTopoReconstructor->GetParticles().size() );
  566. // match tracks ( particles which are direct copies of tracks )
  567. for( unsigned int iRP = 0; iRP < fTopoReconstructor->GetParticles().size(); iRP++ )
  568. {
  569. const KFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
  570. if (rPart.NDaughters() != 1) continue;
  571. const int rTrackId = rPart.DaughterIds()[0];
  572. const int mcTrackId = fTrackMatch[rTrackId];
  573. if(mcTrackId < 0) continue;
  574. KFMCParticle &mPart = vMCParticles[mcTrackId];
  575. if( mPart.GetPDG() == rPart.GetPDG() )
  576. {
  577. MCtoRParticleId[mcTrackId].ids.push_back(iRP);
  578. RtoMCParticleId[iRP].ids.push_back(mcTrackId);
  579. }
  580. else {
  581. MCtoRParticleId[mcTrackId].idsMI.push_back(iRP);
  582. RtoMCParticleId[iRP].idsMI.push_back(mcTrackId);
  583. }
  584. }
  585. // match created mother particles
  586. for( unsigned int iRP = 0; iRP < fTopoReconstructor->GetParticles().size(); iRP++ ) {
  587. const KFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
  588. const unsigned int NRDaughters = rPart.NDaughters();
  589. if (NRDaughters < 2) continue;
  590. bool isMissingMass = ((abs(rPart.GetPDG()) == 7000211)||(abs(rPart.GetPDG()) == 7000321)||(abs(rPart.GetPDG()) == 7003112) || (abs(rPart.GetPDG()) == 7003222)|| (abs(rPart.GetPDG()) == 7003312)|| (abs(rPart.GetPDG()) == 7003334)|| (abs(rPart.GetPDG()) == 9000321)|| (abs(rPart.GetPDG()) == 8003334)||(abs(rPart.GetPDG()) == 8003222));
  591. //missing mass method
  592. if ( (abs(rPart.GetPDG()) == 7000014 ) || (abs(rPart.GetPDG()) == 8000014 ) || (abs(rPart.GetPDG()) == 7002112 ) ||
  593. (abs(rPart.GetPDG()) == 8002112 ) || (abs(rPart.GetPDG()) == 7003122 ) || (abs(rPart.GetPDG()) == 7003322 ) ||
  594. (abs(rPart.GetPDG()) == 9000111 ) || (abs(rPart.GetPDG()) == 8003122 ) || (abs(rPart.GetPDG()) == 8000111 ) )
  595. {
  596. //During the reconstruction 1st daughter - mother particle, 2nd daughter - charged daughter
  597. int mcNeutralDaughterId = -1;
  598. const int recoMotherId = rPart.DaughterIds()[0];
  599. if ( !RtoMCParticleId[recoMotherId].IsMatched() ) continue;
  600. const int mcMotherId = RtoMCParticleId[recoMotherId].GetBestMatch();
  601. const int recoChargedDaughterId = rPart.DaughterIds()[1];
  602. if ( !RtoMCParticleId[recoChargedDaughterId].IsMatched() ) continue;
  603. const int mcChargedDaughterId = RtoMCParticleId[recoChargedDaughterId].GetBestMatch();
  604. const KFMCParticle& chargedDaughter = vMCParticles[mcChargedDaughterId];
  605. if(chargedDaughter.GetMotherId() != mcMotherId) continue;
  606. const KFMCParticle& mother = vMCParticles[mcMotherId];
  607. if(fNeutralIndex[mcMotherId] > -1)
  608. mcNeutralDaughterId = fNeutralIndex[mcMotherId];
  609. if(mcNeutralDaughterId > -1)
  610. {
  611. KFMCParticle &neutralDaughter = vMCParticles[mcNeutralDaughterId];
  612. int iParticle = fParteff.GetParticleIndex(rPart.GetPDG());
  613. bool allCorrectDaughters = mother.GetPDG() == fParteff.partDaughterPdg[iParticle][0] &&
  614. chargedDaughter.GetPDG() == fParteff.partDaughterPdg[iParticle][1];
  615. if( neutralDaughter.GetPDG() == rPart.GetPDG() &&
  616. neutralDaughter.NDaughters() == rPart.NDaughters() &&
  617. allCorrectDaughters) {
  618. MCtoRParticleId[mcNeutralDaughterId].ids.push_back(iRP);
  619. RtoMCParticleId[iRP].ids.push_back(mcNeutralDaughterId);
  620. }
  621. else {
  622. MCtoRParticleId[mcNeutralDaughterId].idsMI.push_back(iRP);
  623. RtoMCParticleId[iRP].idsMI.push_back(mcNeutralDaughterId);
  624. }
  625. }
  626. }
  627. //normal decays
  628. else
  629. {
  630. unsigned int iD = 0;
  631. vector<int> mcDaughterIds;
  632. int mmId = -2; // MC id for rPart
  633. {
  634. const int rdId = rPart.DaughterIds()[iD];
  635. if ( !RtoMCParticleId[rdId].IsMatched() ) continue;
  636. const int mdId = RtoMCParticleId[rdId].GetBestMatch();
  637. mcDaughterIds.push_back(mdId);
  638. mmId = vMCParticles[mdId].GetMotherId();
  639. }
  640. iD++;
  641. for ( ; iD < NRDaughters; iD++ ) {
  642. const int rdId = rPart.DaughterIds()[iD];
  643. if ( !RtoMCParticleId[rdId].IsMatched() ) break;
  644. const int mdId = RtoMCParticleId[rdId].GetBestMatch();
  645. mcDaughterIds.push_back(mdId);
  646. if(isMissingMass)
  647. {
  648. const KFMCParticle &neutralDaughter = vMCParticles[mdId];
  649. if(mmId != vMCParticles[neutralDaughter.GetMotherId()].InitialParticleId()) break;
  650. mmId = neutralDaughter.GetMotherId();
  651. }
  652. if( !(isMissingMass) && (vMCParticles[mdId].GetMotherId() != mmId) ) break;
  653. }
  654. int nClones = 0;
  655. sort(mcDaughterIds.begin(), mcDaughterIds.end());
  656. for(unsigned int ie=1; ie<mcDaughterIds.size(); ie++)
  657. {
  658. if(mcDaughterIds[ie] == mcDaughterIds[ie-1])
  659. nClones++;
  660. }
  661. if(nClones > 0) continue;
  662. if ( iD == NRDaughters && mmId > -1 ) { // match is found and it is not primary vertex
  663. KFMCParticle &mmPart = vMCParticles[mmId];
  664. if( mmPart.GetPDG() == rPart.GetPDG() &&
  665. mmPart.NDaughters() == rPart.NDaughters() ) {
  666. MCtoRParticleId[mmId].ids.push_back(iRP);
  667. RtoMCParticleId[iRP].ids.push_back(mmId);
  668. }
  669. else {
  670. MCtoRParticleId[mmId].idsMI.push_back(iRP);
  671. RtoMCParticleId[iRP].idsMI.push_back(mmId);
  672. }
  673. }
  674. }
  675. }
  676. }
  677. void KFTopoPerformance::MatchPV()
  678. {
  679. /** Matches Monte Carlo and reconstructed primary vertices. */
  680. MCtoRPVId.clear();
  681. RtoMCPVId.clear();
  682. MCtoRPVId.resize(fPrimVertices.size());
  683. RtoMCPVId.resize(fTopoReconstructor->NPrimaryVertices() );
  684. fPVPurity.clear();
  685. fPVPurity.resize(fTopoReconstructor->NPrimaryVertices(), 0.);
  686. fNCorrectPVTracks.clear();
  687. fNCorrectPVTracks.resize(fTopoReconstructor->NPrimaryVertices(), 0);
  688. for(int iE = 0; iE<4; iE++)
  689. {
  690. fPVTracksRate[iE].clear();
  691. fPVTracksRate[iE].resize(fTopoReconstructor->NPrimaryVertices(),0);
  692. }
  693. for( unsigned int iMCPV=0; iMCPV<fPrimVertices.size(); iMCPV++)
  694. {
  695. KFMCVertex &mcPV = fPrimVertices[iMCPV];
  696. int nReconstructedDaughters = 0;
  697. for(int iD=0; iD<mcPV.NDaughterTracks(); iD++)
  698. if(MCtoRParticleId[ mcPV.DaughterTrack(iD) ].IsMatched())
  699. nReconstructedDaughters++;
  700. mcPV.SetNReconstructedDaughters(nReconstructedDaughters);
  701. }
  702. for( int iPV = 0; iPV < fTopoReconstructor->NPrimaryVertices(); iPV++ ) {
  703. vector<int> &tracks = fTopoReconstructor->GetPVTrackIndexArray(iPV);
  704. int nPVTracks = tracks.size()>0 ? tracks.size() : -1;//tracks.size();
  705. vector<short int> nTracksFromMCPV(fPrimVertices.size() + vMCParticles.size(), 0);
  706. vector< vector<int> > mcIDs(fPrimVertices.size() + vMCParticles.size());
  707. int nGhostTracks = 0;
  708. int nTriggerTracks = 0;
  709. int nPileupTracks = 0;
  710. int nBGTracks = 0;
  711. for(int iRP=0; iRP < nPVTracks; iRP++)
  712. {
  713. const int rTrackId = tracks[iRP];
  714. if ( !RtoMCParticleId[rTrackId].IsMatched() )
  715. {
  716. nGhostTracks++;
  717. continue;
  718. }
  719. int iMCPart = RtoMCParticleId[rTrackId].GetBestMatch();
  720. KFMCParticle &mcPart = vMCParticles[iMCPart];
  721. int iMCTrack = mcPart.GetMCTrackID();
  722. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  723. int motherId = mcTrack.MotherId();
  724. if(motherId < 0) //real PV
  725. {
  726. if(motherId == -1)
  727. nTriggerTracks++;
  728. if(motherId < -1)
  729. nPileupTracks++;
  730. int iMCPV = fMCTrackToMCPVMatch[iMCTrack];
  731. if(iMCPV < 0)
  732. {
  733. std::cout << "Error!!! iMCPV < 0" << std::endl;
  734. continue;
  735. }
  736. nTracksFromMCPV[iMCPV]++;
  737. mcIDs[iMCPV].push_back(iMCTrack);
  738. }
  739. else // pchysics background
  740. {
  741. if(motherId >-1)
  742. {
  743. nBGTracks++;
  744. int iMCPV = motherId + fPrimVertices.size();
  745. nTracksFromMCPV[iMCPV]++;
  746. mcIDs[iMCPV].push_back(iMCTrack);
  747. }
  748. }
  749. }
  750. for(unsigned int iMCPV=0; iMCPV<nTracksFromMCPV.size(); iMCPV++)
  751. {
  752. int nClones = 0;
  753. sort(mcIDs[iMCPV].begin(), mcIDs[iMCPV].end());
  754. for(unsigned int ie=1; ie<mcIDs[iMCPV].size(); ie++)
  755. {
  756. if(mcIDs[iMCPV][ie] == mcIDs[iMCPV][ie-1])
  757. nClones++;
  758. }
  759. nTracksFromMCPV[iMCPV] = nTracksFromMCPV[iMCPV] - nClones;
  760. nPVTracks -= nClones;
  761. }
  762. // calculate rate of each type of tracks in reconstructed PV
  763. fPVTracksRate[0][iPV] = double(nGhostTracks)/double(nPVTracks);
  764. fPVTracksRate[1][iPV] = double(nTriggerTracks)/double(nPVTracks);
  765. fPVTracksRate[2][iPV] = double(nPileupTracks)/double(nPVTracks);
  766. fPVTracksRate[3][iPV] = double(nBGTracks)/double(nPVTracks);
  767. int iBestMCPV=-1;
  768. int nTracksBestMCPV = 1;
  769. for(unsigned int iMCPV=0; iMCPV<nTracksFromMCPV.size(); iMCPV++ )
  770. {
  771. if(nTracksFromMCPV[iMCPV] > nTracksBestMCPV )
  772. {
  773. nTracksBestMCPV = nTracksFromMCPV[iMCPV];
  774. iBestMCPV = iMCPV;
  775. }
  776. }
  777. if( (iBestMCPV > -1) && (iBestMCPV<int(fPrimVertices.size())) )
  778. {
  779. fNCorrectPVTracks[iPV] = nTracksFromMCPV[iBestMCPV];
  780. }
  781. else
  782. fNCorrectPVTracks[iPV] = 0;
  783. double purity = double(nTracksBestMCPV)/double(nPVTracks);
  784. fPVPurity[iPV] = purity;
  785. // if(purity < 0.7) continue;
  786. if(iBestMCPV < 0) continue;
  787. if(iBestMCPV < int(fPrimVertices.size()))
  788. {
  789. fPrimVertices[iBestMCPV].SetReconstructed();
  790. MCtoRPVId[iBestMCPV].ids.push_back(iPV);
  791. RtoMCPVId[iPV].ids.push_back(iBestMCPV);
  792. }
  793. else
  794. {
  795. RtoMCPVId[iPV].idsMI.push_back(iBestMCPV);
  796. }
  797. }
  798. }
  799. void KFTopoPerformance::MatchTracks()
  800. {
  801. /** Runs reading of Monte Carlo particles and vertices, their matching, calculation of efficiency. */
  802. #ifdef KFPWITHTRACKER
  803. for(int iTr=0; iTr<vMCTracks.size(); iTr++)
  804. {
  805. if( (AliHLTTPCCAPerformance::Instance().GetSubPerformance("Global Performance")->GetMCData())[iTr].IsReconstructed() )
  806. vMCTracks[iTr].SetReconstructed();
  807. }
  808. fTrackMatch.resize(AliHLTTPCCAPerformance::Instance().GetSubPerformance("Global Performance")->GetRecoData().size());
  809. for(int iTr=0; iTr<fTrackMatch.size(); iTr++)
  810. {
  811. const AliHLTTPCCAPerformanceRecoTrackData& matchInfo = (AliHLTTPCCAPerformance::Instance().GetSubPerformance("Global Performance")->GetRecoData())[iTr];
  812. if( matchInfo.IsGhost(PParameters::MinTrackPurity) || matchInfo.GetMCTrackId()<0 )
  813. fTrackMatch[iTr] = -1;
  814. else
  815. fTrackMatch[iTr] = matchInfo.GetMCTrackId();
  816. }
  817. #endif
  818. GetMCParticles();
  819. FindReconstructableMCParticles();
  820. MatchParticles();
  821. CalculateEfficiency();
  822. FindReconstructableMCVertices();
  823. MatchPV();
  824. CalculatePVEfficiency();
  825. } // void KFTopoPerformance::MatchTracks()
  826. void KFTopoPerformance::CalculateEfficiency()
  827. {
  828. /** Calculates reconstruction efficiency of short-lived particles. */
  829. KFPartEfficiencies partEff; // efficiencies for current event
  830. const int NRP = fTopoReconstructor->GetParticles().size();
  831. for ( int iP = 0; iP < NRP; ++iP ) {
  832. // const CbmKFParticle &part = fPF->GetParticles()[iP];
  833. const KFParticle &part = fTopoReconstructor->GetParticles()[iP];
  834. const int pdg = part.GetPDG();
  835. const bool isBG = RtoMCParticleId[iP].idsMI.size() != 0;
  836. const bool isGhost = !RtoMCParticleId[iP].IsMatched();
  837. for(int iPart=0; iPart<fParteff.nParticles; iPart++)
  838. if ( pdg == fParteff.partPDG[iPart] )
  839. partEff.IncReco(isGhost, isBG, fParteff.partName[iPart].data());
  840. // Calculate the gost level for V0
  841. if(abs(pdg) == 310 /*||
  842. CAMath::Abs(pdg) == 3122 ||
  843. CAMath::Abs(pdg) == 421 ||
  844. CAMath::Abs(pdg) == 22 */)
  845. {
  846. partEff.IncReco(isGhost, 0, fParteff.partName[fParteff.nParticles - 1].data());
  847. }
  848. }
  849. const int NMP = vMCParticles.size();
  850. for ( int iP = 0; iP < NMP; ++iP ) {
  851. const KFMCParticle &part = vMCParticles[iP];
  852. const int pdg = part.GetPDG();
  853. const int mId = part.GetMotherId();
  854. vector<bool> isReco;
  855. vector<int> nClones;
  856. vector<int> iParticle;
  857. iParticle.push_back(fParteff.GetParticleIndex(pdg));
  858. vector< vector<bool> > isReconstructable;
  859. vector<bool> isRecPart;
  860. const std::map<int,bool>& decays = fTopoReconstructor->GetKFParticleFinder()->GetReconstructionList();
  861. if(!(decays.empty()) && (iParticle[0] < fParteff.fFirstStableParticleIndex || iParticle[0] > fParteff.fLastStableParticleIndex))
  862. if(decays.find(pdg) == decays.end()) continue;
  863. if( fParteff.GetParticleIndex(pdg)>=KFPartEfficiencies::fFirstMissingMassParticleIndex &&
  864. fParteff.GetParticleIndex(pdg)<=KFPartEfficiencies::fLastMissingMassParticleIndex )
  865. {
  866. isRecPart.push_back(part.IsReconstructable(4));
  867. isRecPart.push_back(part.IsReconstructable(1));
  868. isRecPart.push_back(part.IsReconstructable(3));
  869. }
  870. else
  871. for(int iEff = 0; iEff < 3; iEff++)
  872. isRecPart.push_back(part.IsReconstructable(iEff));
  873. isReconstructable.push_back(isRecPart);
  874. isReco.push_back( MCtoRParticleId[iP].ids.size() != 0 );
  875. nClones.push_back( MCtoRParticleId[iP].ids.size() - 1 );
  876. if(decays.empty() && (part.IsReconstructableV0(0) || part.IsReconstructableV0(1) || part.IsReconstructableV0(2)) )
  877. {
  878. iParticle.push_back(fParteff.nParticles - 1);
  879. vector<bool> isRecV0;
  880. for(int iEff = 0; iEff < 3; iEff++)
  881. isRecV0.push_back(part.IsReconstructableV0(iEff));
  882. isReconstructable.push_back(isRecV0);
  883. isReco.push_back( (MCtoRParticleId[iP].ids.size() != 0) || (MCtoRParticleId[iP].idsMI.size() != 0) );
  884. int nClonesV0 = MCtoRParticleId[iP].ids.size() + MCtoRParticleId[iP].idsMI.size() - 1;
  885. nClones.push_back( nClonesV0 );
  886. }
  887. {
  888. for(unsigned int iPType=0; iPType<iParticle.size(); iPType++)
  889. {
  890. int iPart = iParticle[iPType];
  891. if(iPart<0) continue;
  892. partEff.Inc(isReco[iPType], nClones[iPType], isReconstructable[iPType][0], isReconstructable[iPType][1], isReconstructable[iPType][2], fParteff.partName[iPart].data());
  893. if ( mId == -1 )
  894. partEff.Inc(isReco[iPType], nClones[iPType], isReconstructable[iPType][0], isReconstructable[iPType][1], isReconstructable[iPType][2], (fParteff.partName[iPart]+"_prim").data());
  895. else
  896. partEff.Inc(isReco[iPType], nClones[iPType], isReconstructable[iPType][0], isReconstructable[iPType][1], isReconstructable[iPType][2], (fParteff.partName[iPart]+"_sec").data());
  897. for(int iEff=0; iEff<3; iEff++)
  898. {
  899. if(!isReconstructable[iPType][iEff]) continue;
  900. int iMCTrack = part.GetMCTrackID();
  901. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  902. Double_t massMC = fParteff.partMass[iPart];
  903. Double_t E = sqrt(mcTrack.P()*mcTrack.P() + massMC*massMC);
  904. Double_t Y = 0.5*log((E + mcTrack.Pz())/(E - mcTrack.Pz()));
  905. Double_t Z = mcTrack.Z();
  906. Double_t R = -1, L=-1;
  907. Double_t Mt_mc = sqrt(mcTrack.Pt()*mcTrack.Pt()+massMC*massMC)-massMC;
  908. Double_t cT = -1.e10;
  909. Double_t decayLength = -1.e10;
  910. if(part.NDaughters() > 0)
  911. {
  912. int mcDaughterId = part.GetDaughterIds()[0];
  913. KFMCTrack &mcDaughter = vMCTracks[mcDaughterId];
  914. R = sqrt(mcDaughter.X()*mcDaughter.X() + mcDaughter.Y()*mcDaughter.Y());
  915. L = sqrt(mcDaughter.X()*mcDaughter.X() + mcDaughter.Y()*mcDaughter.Y());
  916. Z = mcDaughter.Z();
  917. if(mcTrack.MotherId() < 0)
  918. {
  919. KFParticle motherKFParticle;
  920. float decayPoint[3] = { mcDaughter.X(), mcDaughter.Y(), mcDaughter.Z() };
  921. for(int iP=0; iP<6; iP++)
  922. motherKFParticle.Parameter(iP) = mcTrack.Par()[iP];
  923. float dsdr[6];
  924. double s = motherKFParticle.GetDStoPoint(decayPoint, dsdr);
  925. int jParticlePDG = fParteff.GetParticleIndex(mcTrack.PDG());
  926. Double_t massMC = (jParticlePDG>=0) ? fParteff.partMass[jParticlePDG] :0.13957;
  927. cT = s*massMC;
  928. decayLength = s*mcTrack.P();
  929. }
  930. }
  931. if(fStoreMCHistograms)
  932. {
  933. hPartEfficiency[iPart][iEff][0]->Fill( mcTrack.P(), isReco[iPType] );
  934. hPartEfficiency[iPart][iEff][1]->Fill( mcTrack.Pt(), isReco[iPType] );
  935. hPartEfficiency[iPart][iEff][2]->Fill( Y, isReco[iPType] );
  936. hPartEfficiency[iPart][iEff][3]->Fill( Z, isReco[iPType] );
  937. if(cT > -1.e10) hPartEfficiency[iPart][iEff][4]->Fill( cT, isReco[iPType] );
  938. if(decayLength > -1.e10) hPartEfficiency[iPart][iEff][5]->Fill( decayLength, isReco[iPType] );
  939. hPartEfficiency[iPart][iEff][3]->Fill( Z, isReco[iPType] );
  940. hPartEfficiency[iPart][iEff][6]->Fill( L, isReco[iPType] );
  941. hPartEfficiency[iPart][iEff][7]->Fill( R, isReco[iPType] );
  942. hPartEfficiency[iPart][iEff][8]->Fill( Mt_mc, isReco[iPType] );
  943. hPartEfficiency2D[iPart][iEff][0]->Fill( Y, mcTrack.Pt(), isReco[iPType] );
  944. hPartEfficiency2D[iPart][iEff][1]->Fill( Y, Mt_mc, isReco[iPType] );
  945. }
  946. }
  947. }
  948. }
  949. }
  950. fNEvents++;
  951. fParteff += partEff;
  952. partEff.CalcEff();
  953. fParteff.CalcEff();
  954. if(fNEvents%fPrintEffFrequency == 0)
  955. {
  956. std::cout << " ---- KF Particle finder --- " << std::endl;
  957. std::cout << "ACCUMULATED STAT : " << fNEvents << " EVENTS " << std::endl << std::endl;
  958. fParteff.PrintEff();
  959. std::cout<<std::endl;
  960. }
  961. }
  962. void KFTopoPerformance::CalculatePVEfficiency()
  963. {
  964. /** Calculates reconstruction efficiency of primary vertices. */
  965. KFPVEfficiencies pvEff; // efficiencies for current event
  966. KFPVEfficiencies pvEffMCReconstructable;
  967. int nTracks = 0;
  968. //calculate N reco tracks
  969. for( unsigned int iRP = 0; iRP < fTopoReconstructor->GetParticles().size(); iRP++ ) {
  970. // CbmKFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
  971. const KFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
  972. if (rPart.NDaughters() != 1) continue;
  973. nTracks++;
  974. }
  975. const int NRecoPV = fTopoReconstructor->NPrimaryVertices();
  976. for ( int iP = 0; iP < NRecoPV; ++iP ) {
  977. const bool isBG = RtoMCPVId[iP].idsMI.size() != 0;
  978. const bool isGhost = !RtoMCPVId[iP].IsMatched();
  979. pvEff.IncReco(isGhost, isBG, "PV");
  980. pvEffMCReconstructable.IncReco(isGhost, isBG, "PV");
  981. }
  982. const int NMCPV = fPrimVertices.size();
  983. for ( int iV = 0; iV < NMCPV; ++iV ) {
  984. const KFMCVertex &pvMC = fPrimVertices[iV];
  985. if ( pvMC.IsReconstructable() )
  986. {
  987. const bool isReco = pvMC.IsReconstructed();
  988. const int nClones = MCtoRPVId[iV].ids.size() - 1;
  989. pvEff.Inc(isReco, nClones, "PV");
  990. if ( pvMC.IsTriggerPV() )
  991. {
  992. pvEff.Inc(isReco, nClones, "PVtrigger");
  993. hPVefficiency[0][0]->Fill( pvMC.NDaughterTracks(), isReco );
  994. hPVefficiency[0][1]->Fill( NMCPV, isReco );
  995. hPVefficiency[0][2]->Fill( vMCTracks.size(), isReco );
  996. hPVefficiency[0][3]->Fill( pvMC.NReconstructedDaughterTracks(), isReco );
  997. hPVefficiency[0][4]->Fill( NRecoPV, isReco );
  998. hPVefficiency[0][5]->Fill( nTracks, isReco );
  999. }
  1000. else
  1001. {
  1002. pvEff.Inc(isReco, nClones, "PVpileup");
  1003. hPVefficiency[1][0]->Fill( pvMC.NDaughterTracks(), isReco );
  1004. hPVefficiency[1][1]->Fill( NMCPV, isReco );
  1005. hPVefficiency[1][2]->Fill( vMCTracks.size(), isReco );
  1006. hPVefficiency[1][3]->Fill( pvMC.NReconstructedDaughterTracks(), isReco );
  1007. hPVefficiency[1][4]->Fill( NRecoPV, isReco );
  1008. hPVefficiency[1][5]->Fill( nTracks, isReco );
  1009. }
  1010. }
  1011. if ( pvMC.IsMCReconstructable() )
  1012. {
  1013. const bool isReco = pvMC.IsReconstructed();
  1014. const int nClones = MCtoRPVId[iV].ids.size() - 1;
  1015. pvEffMCReconstructable.Inc(isReco, nClones, "PV");
  1016. if ( pvMC.IsTriggerPV() )
  1017. {
  1018. pvEffMCReconstructable.Inc(isReco, nClones, "PVtrigger");
  1019. hPVefficiency[2][0]->Fill( pvMC.NDaughterTracks(), isReco );
  1020. hPVefficiency[2][1]->Fill( NMCPV, isReco );
  1021. hPVefficiency[2][2]->Fill( vMCTracks.size(), isReco );
  1022. hPVefficiency[2][3]->Fill( pvMC.NReconstructedDaughterTracks(), isReco );
  1023. hPVefficiency[2][4]->Fill( NRecoPV, isReco );
  1024. hPVefficiency[2][5]->Fill( nTracks, isReco );
  1025. }
  1026. else
  1027. {
  1028. pvEffMCReconstructable.Inc(isReco, nClones, "PVpileup");
  1029. hPVefficiency[3][0]->Fill( pvMC.NDaughterTracks(), isReco );
  1030. hPVefficiency[3][1]->Fill( NMCPV, isReco );
  1031. hPVefficiency[3][2]->Fill( vMCTracks.size(), isReco );
  1032. hPVefficiency[3][3]->Fill( pvMC.NReconstructedDaughterTracks(), isReco );
  1033. hPVefficiency[3][4]->Fill( NRecoPV, isReco );
  1034. hPVefficiency[3][5]->Fill( nTracks, isReco );
  1035. }
  1036. }
  1037. }
  1038. fPVeff += pvEff;
  1039. pvEff.CalcEff();
  1040. fPVeff.CalcEff();
  1041. fPVeffMCReconstructable += pvEffMCReconstructable;
  1042. pvEffMCReconstructable.CalcEff();
  1043. fPVeffMCReconstructable.CalcEff();
  1044. if(fNEvents%fPrintEffFrequency == 0)
  1045. {
  1046. std::cout << " ---- KF PV finder --- " << std::endl;
  1047. std::cout << "ACCUMULATED STAT : " << fNEvents << " EVENTS " << std::endl << std::endl;
  1048. std::cout << "PV with at least 2 reconstructed tracks is reconstructable:" << std::endl;
  1049. fPVeff.PrintEff();
  1050. std::cout << std::endl;
  1051. std::cout << "PV with at least 2 MC tracks with 15 MC points is reconstructable:" << std::endl;
  1052. fPVeffMCReconstructable.PrintEff();
  1053. std::cout<<std::endl;
  1054. }
  1055. }
  1056. void KFTopoPerformance::FillParticleParameters(KFParticle& TempPart,
  1057. int iParticle,
  1058. int iP,
  1059. int iPV,
  1060. TH1F* histoParameters[nParametersSet][KFPartEfficiencies::nParticles][nHistoPartParam],
  1061. TH2F* histoParameters2D[nParametersSet][KFPartEfficiencies::nParticles][nHistoPartParam2D],
  1062. TH3F* histoParameters3D[1][KFPartEfficiencies::nParticles][nHistoPartParam3D],
  1063. TH1F* histoFit[KFPartEfficiencies::nParticles][nFitQA],
  1064. TH1F* histoFitDaughtersQA[KFPartEfficiencies::nParticles][nFitQA],
  1065. TH1F* histoDSToParticleQA[KFPartEfficiencies::nParticles][nDSToParticleQA],
  1066. vector<int>* multiplicities)
  1067. {
  1068. /** Fills provided histograms with the parameters of the given particle. */
  1069. const std::map<int,bool>& decays = fTopoReconstructor->GetKFParticleFinder()->GetReconstructionList();
  1070. if(!(decays.empty()) && (iParticle < fParteff.fFirstStableParticleIndex || iParticle > fParteff.fLastStableParticleIndex))
  1071. if(decays.find(TempPart.GetPDG()) == decays.end()) return;
  1072. float M, M_t, ErrM;
  1073. float dL, ErrdL; // decay length
  1074. float cT, ErrcT; // c*tau
  1075. float P, ErrP;
  1076. float Pt;
  1077. float Rapidity;
  1078. float Theta;
  1079. float Phi;
  1080. float X,Y,Z,R;
  1081. float QtAlpha[2];
  1082. TempPart.GetMass(M,ErrM);
  1083. TempPart.GetMomentum(P,ErrP);
  1084. Pt = TempPart.GetPt();
  1085. Rapidity = TempPart.GetRapidity();
  1086. KFParticle TempPartTopo = TempPart;
  1087. TempPartTopo.SetProductionVertex(fTopoReconstructor->GetPrimVertex(0));
  1088. TempPartTopo.GetDecayLength(dL,ErrdL);
  1089. TempPartTopo.GetLifeTime(cT,ErrcT);
  1090. float chi2 = TempPart.GetChi2();
  1091. Int_t ndf = TempPart.GetNDF();
  1092. float prob = TMath::Prob(chi2, ndf);//(TDHelper<float>::Chi2IProbability( ndf, chi2 ));
  1093. Theta = TempPart.GetTheta();
  1094. Phi = TempPart.GetPhi();
  1095. X = TempPart.GetX();
  1096. Y = TempPart.GetY();
  1097. Z = TempPart.GetZ();
  1098. #ifdef CBM
  1099. if(Z>=1. && iParticle>=54 && iParticle<=64) return;
  1100. #endif
  1101. R = sqrt(X*X+Y*Y);
  1102. M_t = sqrt(Pt*Pt+fParteff.GetMass(iParticle)*fParteff.GetMass(iParticle))-fParteff.GetMass(iParticle);
  1103. KFParticleSIMD tempSIMDPart(TempPart);
  1104. float_v l,dl;
  1105. KFParticleSIMD pv(fTopoReconstructor->GetPrimVertex(iPV));
  1106. tempSIMDPart.GetDistanceToVertexLine(pv, l, dl);
  1107. #ifdef __ROOT__
  1108. if( (l[0] > 0.2f || Pt < 0.f) && (abs( TempPart.GetPDG() ) == 4122 ||
  1109. abs( TempPart.GetPDG() ) == 104122 ||
  1110. abs( TempPart.GetPDG() ) == 204122 ||
  1111. abs( TempPart.GetPDG() ) == 304122 ||
  1112. abs( TempPart.GetPDG() ) == 404122 ||
  1113. abs( TempPart.GetPDG() ) == 504122 ) ) return;
  1114. if( (l[0] > 0.2f || Pt < 0.f) && (abs( TempPart.GetPDG() ) == 421 ||
  1115. abs( TempPart.GetPDG() ) == 420 ||
  1116. abs( TempPart.GetPDG() ) == 425 ||
  1117. abs( TempPart.GetPDG() ) == 426 ||
  1118. abs( TempPart.GetPDG() ) == 427 ||
  1119. abs( TempPart.GetPDG() ) == 429) ) return;
  1120. if( (l[0] > 0.4f || Pt < 0.f) && (abs( TempPart.GetPDG() ) == 411 ||
  1121. abs( TempPart.GetPDG() ) == 100411 ||
  1122. abs( TempPart.GetPDG() ) == 200411 ||
  1123. abs( TempPart.GetPDG() ) == 300411) ) return;
  1124. if( (l[0] > 0.2f || Pt < 0.f) && (abs( TempPart.GetPDG() ) == 431 ||
  1125. abs( TempPart.GetPDG() ) == 100431 ||
  1126. abs( TempPart.GetPDG() ) == 200431 ||
  1127. abs( TempPart.GetPDG() ) == 300431 ||
  1128. abs( TempPart.GetPDG() ) == 400431) ) return;
  1129. // if(Pt < 2. && (abs( TempPart.GetPDG() ) == 443 ||
  1130. // abs( TempPart.GetPDG() ) == 100443 ||
  1131. // abs( TempPart.GetPDG() ) == 200443 ||
  1132. // abs( TempPart.GetPDG() ) == 300443 ||
  1133. // abs( TempPart.GetPDG() ) == 400443 ||
  1134. // abs( TempPart.GetPDG() ) == 500443) ) return;
  1135. if(Pt < 0.5f && (abs( TempPart.GetPDG() ) == 3000 ||
  1136. abs( TempPart.GetPDG() ) == 3001) ) return;
  1137. #endif
  1138. float parameters[17] = {M, P, Pt, Rapidity, dL, cT, chi2/ndf, prob, Theta, Phi, X, Y, Z, R, l[0], l[0]/dl[0], M_t };
  1139. //for all particle-candidates
  1140. for(int iParam=0; iParam<17; iParam++)
  1141. histoParameters[0][iParticle][iParam]->Fill(parameters[iParam]);
  1142. if(multiplicities)
  1143. multiplicities[0][iParticle]++;
  1144. histoParameters2D[0][iParticle][0]->Fill(Rapidity,Pt,1);
  1145. histoParameters2D[0][iParticle][3]->Fill(Rapidity,M_t,1);
  1146. const bool drawZR = IsCollectZRHistogram(iParticle);
  1147. if(histoParameters2D[0][iParticle][1] && drawZR)
  1148. {
  1149. histoParameters2D[0][iParticle][1]->Fill(Z,R,1);
  1150. }
  1151. if(TempPart.NDaughters() == 2 && IsCollectArmenteros(iParticle))
  1152. {
  1153. int index1 = TempPart.DaughterIds()[0];
  1154. int index2 = TempPart.DaughterIds()[1];
  1155. if(index1 >= int(fTopoReconstructor->GetParticles().size()) ||
  1156. index2 >= int(fTopoReconstructor->GetParticles().size()) ||
  1157. index1 < 0 || index2 < 0 )
  1158. return;
  1159. KFParticle posDaughter, negDaughter;
  1160. if(int(fTopoReconstructor->GetParticles()[index1].Q()) > 0)
  1161. {
  1162. posDaughter = fTopoReconstructor->GetParticles()[index1];
  1163. negDaughter = fTopoReconstructor->GetParticles()[index2];
  1164. }
  1165. else
  1166. {
  1167. negDaughter = fTopoReconstructor->GetParticles()[index1];
  1168. posDaughter = fTopoReconstructor->GetParticles()[index2];
  1169. }
  1170. float vertex[3] = {TempPart.GetX(), TempPart.GetY(), TempPart.GetZ()};
  1171. posDaughter.TransportToPoint(vertex);
  1172. negDaughter.TransportToPoint(vertex);
  1173. KFParticle::GetArmenterosPodolanski(posDaughter, negDaughter, QtAlpha );
  1174. histoParameters2D[0][iParticle][2]->Fill(QtAlpha[1],QtAlpha[0],1);
  1175. }
  1176. //Fill 3D histograms for multi differential analysis
  1177. if( histoParameters3D && IsCollect3DHistogram(iParticle))
  1178. {
  1179. histoParameters3D[0][iParticle][0]->Fill(Rapidity,Pt,M,1);
  1180. histoParameters3D[0][iParticle][1]->Fill(Rapidity,M_t,M,1);
  1181. if(fCentralityBin>=0)
  1182. {
  1183. histoParameters3D[0][iParticle][2]->Fill(fCentralityBin, Pt, M, fCentralityWeight);
  1184. histoParameters3D[0][iParticle][3]->Fill(fCentralityBin, Rapidity, M, fCentralityWeight);
  1185. histoParameters3D[0][iParticle][4]->Fill(fCentralityBin, M_t, M, fCentralityWeight);
  1186. }
  1187. histoParameters3D[0][iParticle][5]->Fill(cT, Pt, M, 1);
  1188. }
  1189. //Fill histograms for the side bands analysis
  1190. if(histoDSToParticleQA && IsCollect3DHistogram(iParticle))
  1191. {
  1192. if(fabs(fParteff.GetMass(iParticle)-M) < 3.f*fParteff.GetMassSigma(iParticle))//SignalReco
  1193. {
  1194. for(int iParam=0; iParam<17; iParam++)
  1195. histoParameters[4][iParticle][iParam]->Fill(parameters[iParam]);
  1196. if(multiplicities)
  1197. multiplicities[4][iParticle]++;
  1198. histoParameters2D[4][iParticle][0]->Fill(Rapidity,Pt,1);
  1199. histoParameters2D[4][iParticle][3]->Fill(Rapidity,M_t,1);
  1200. if(drawZR)
  1201. {
  1202. if(histoParameters2D[4][iParticle][1])
  1203. histoParameters2D[4][iParticle][1]->Fill(Z,R,1);
  1204. if(histoParameters2D[4][iParticle][2])
  1205. histoParameters2D[4][iParticle][2]->Fill(QtAlpha[1],QtAlpha[0],1);
  1206. }
  1207. }
  1208. if( fabs(fParteff.GetMass(iParticle)-M) > 3.f*fParteff.GetMassSigma(iParticle) &&
  1209. fabs(fParteff.GetMass(iParticle)-M) <= 6.f*fParteff.GetMassSigma(iParticle) )//BGReco
  1210. {
  1211. for(int iParam=0; iParam<17; iParam++)
  1212. histoParameters[5][iParticle][iParam]->Fill(parameters[iParam]);
  1213. if(multiplicities)
  1214. multiplicities[5][iParticle]++;
  1215. histoParameters2D[5][iParticle][0]->Fill(Rapidity,Pt,1);
  1216. histoParameters2D[5][iParticle][3]->Fill(Rapidity,M_t,1);
  1217. if(drawZR)
  1218. {
  1219. if(histoParameters2D[5][iParticle][1])
  1220. histoParameters2D[5][iParticle][1]->Fill(Z,R,1);
  1221. if(histoParameters2D[5][iParticle][2])
  1222. histoParameters2D[5][iParticle][2]->Fill(QtAlpha[1],QtAlpha[0],1);
  1223. }
  1224. }
  1225. }
  1226. if(!fStoreMCHistograms) return;
  1227. int iSet = 1;
  1228. if(!RtoMCParticleId[iP].IsMatchedWithPdg()) //background
  1229. {
  1230. if(!RtoMCParticleId[iP].IsMatched()) iSet = 3; // for ghost particles - combinatorial background
  1231. else iSet = 2; // for physical background
  1232. }
  1233. //Check if PV association is correct
  1234. if(!histoDSToParticleQA && iSet == 1)
  1235. {
  1236. int iMCPart = RtoMCParticleId[iP].GetBestMatchWithPdg();
  1237. KFMCParticle &mcPart = vMCParticles[iMCPart];
  1238. int iMCTrack = mcPart.GetMCTrackID();
  1239. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  1240. int motherId = mcTrack.MotherId();
  1241. bool isSecondaryParticle = motherId >= 0;
  1242. if(iPV >=0)
  1243. {
  1244. if(isSecondaryParticle)
  1245. iSet = 4;
  1246. else
  1247. {
  1248. int iMCPV = -1;
  1249. if(RtoMCPVId[iPV].IsMatchedWithPdg())
  1250. iMCPV = RtoMCPVId[iPV].GetBestMatch();
  1251. int iMCPVFromParticle = fMCTrackToMCPVMatch[iMCTrack];
  1252. if(iMCPV != iMCPVFromParticle)
  1253. iSet = 4;
  1254. }
  1255. }
  1256. else
  1257. {
  1258. if(!isSecondaryParticle)
  1259. iSet = 4;
  1260. }
  1261. }
  1262. //for signal particles
  1263. for(int iParam=0; iParam<17; iParam++)
  1264. histoParameters[iSet][iParticle][iParam]->Fill(parameters[iParam]);
  1265. if(multiplicities)
  1266. multiplicities[iSet][iParticle]++;
  1267. histoParameters2D[iSet][iParticle][0]->Fill(Rapidity,Pt,1);
  1268. if(drawZR)
  1269. {
  1270. if(histoParameters2D[iSet][iParticle][1])
  1271. histoParameters2D[iSet][iParticle][1]->Fill(Z,R,1);
  1272. if(histoParameters2D[iSet][iParticle][2])
  1273. histoParameters2D[iSet][iParticle][2]->Fill(QtAlpha[1],QtAlpha[0],1);
  1274. }
  1275. histoParameters2D[iSet][iParticle][3]->Fill(Rapidity,M_t,1);
  1276. if(iSet != 1) return;
  1277. int iMCPart = RtoMCParticleId[iP].GetBestMatchWithPdg();
  1278. KFMCParticle &mcPart = vMCParticles[iMCPart];
  1279. // Fit quality of the mother particle
  1280. if(histoFit)
  1281. {
  1282. int iMCTrack = mcPart.GetMCTrackID();
  1283. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  1284. int mcDaughterId = -1;
  1285. if(iParticle >= fParteff.fFirstStableParticleIndex && iParticle <= fParteff.fLastStableParticleIndex)
  1286. mcDaughterId = iMCTrack;
  1287. else if(mcTrack.PDG() == 22 && TempPart.NDaughters() == 1)
  1288. mcDaughterId = iMCTrack;
  1289. else if(iParticle >= fParteff.fFirstMissingMassParticleIndex && iParticle <= fParteff.fLastMissingMassParticleIndex)
  1290. mcDaughterId = mcPart.GetDaughterIds()[1]; //the charged daughter
  1291. else
  1292. mcDaughterId = mcPart.GetDaughterIds()[0];
  1293. KFMCTrack &mcDaughter = vMCTracks[mcDaughterId];
  1294. float mcX = mcTrack.X();
  1295. float mcY = mcTrack.Y();
  1296. float mcZ = mcTrack.Z();
  1297. if(histoDSToParticleQA || hPartParamPrimary == histoParameters)
  1298. {
  1299. mcX = mcDaughter.X();
  1300. mcY = mcDaughter.Y();
  1301. mcZ = mcDaughter.Z();
  1302. }
  1303. const float mcPx = mcTrack.Par(3);
  1304. const float mcPy = mcTrack.Par(4);
  1305. const float mcPz = mcTrack.Par(5);
  1306. float decayVtx[3] = { mcTrack.X(), mcTrack.Y(), mcTrack.Z() };
  1307. float recParam[8] = { 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f };
  1308. float errParam[8] = { 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f };
  1309. for(int iPar=0; iPar<3; iPar++)
  1310. {
  1311. recParam[iPar] = TempPart.GetParameter(iPar);
  1312. Double_t error = TempPart.GetCovariance(iPar,iPar);
  1313. if(error < 0.) { error = 1.e20;}
  1314. errParam[iPar] = TMath::Sqrt(error);
  1315. }
  1316. TempPart.TransportToPoint(decayVtx);
  1317. for(int iPar=3; iPar<7; iPar++)
  1318. {
  1319. recParam[iPar] = TempPart.GetParameter(iPar);
  1320. Double_t error = TempPart.GetCovariance(iPar,iPar);
  1321. if(error < 0.) { error = 1.e20;}
  1322. errParam[iPar] = TMath::Sqrt(error);
  1323. }
  1324. int jParticlePDG = fParteff.GetParticleIndex(mcTrack.PDG());
  1325. Double_t massMC = (jParticlePDG>=0) ? fParteff.partMass[jParticlePDG] :0.13957;
  1326. Double_t Emc = sqrt(mcTrack.P()*mcTrack.P() + massMC*massMC);
  1327. Double_t res[8] = {0},
  1328. pull[8] = {0},
  1329. mcParam[8] = { mcX, mcY, mcZ,
  1330. mcPx, mcPy, mcPz, Emc, massMC };
  1331. for(int iPar=0; iPar < 7; iPar++ )
  1332. {
  1333. res[iPar] = recParam[iPar] - mcParam[iPar];
  1334. if(fabs(errParam[iPar]) > 1.e-20) pull[iPar] = res[iPar]/errParam[iPar];
  1335. }
  1336. res[7] = M - mcParam[7];
  1337. if(fabs(ErrM) > 1.e-20) pull[7] = res[7]/ErrM;
  1338. for(int iPar=0; iPar < 8; iPar++ )
  1339. {
  1340. histoFit[iParticle][iPar]->Fill(res[iPar]);
  1341. histoFit[iParticle][iPar+8]->Fill(pull[iPar]);
  1342. }
  1343. }
  1344. // Fit quality of daughters
  1345. int daughterIndex[2] = {-1, -1};
  1346. if(histoFitDaughtersQA)
  1347. {
  1348. for(int iD=0; iD<mcPart.NDaughters(); ++iD)
  1349. {
  1350. int mcDaughterId = mcPart.GetDaughterIds()[iD];
  1351. // if(!MCtoRParticleId[mcDaughterId].IsMatchedWithPdg()) continue;
  1352. if(!MCtoRParticleId[mcDaughterId].IsMatched()) continue;
  1353. KFMCTrack &mcTrack = vMCTracks[mcDaughterId];
  1354. // int recDaughterId = MCtoRParticleId[mcDaughterId].GetBestMatchWithPdg();
  1355. int recDaughterId = MCtoRParticleId[mcDaughterId].GetBestMatch();
  1356. KFParticle Daughter = fTopoReconstructor->GetParticles()[recDaughterId];
  1357. Daughter.GetMass(M,ErrM);
  1358. const float mcX = mcTrack.X();
  1359. const float mcY = mcTrack.Y();
  1360. const float mcZ = mcTrack.Z();
  1361. const float mcPx = mcTrack.Px();
  1362. const float mcPy = mcTrack.Py();
  1363. const float mcPz = mcTrack.Pz();
  1364. float_v decayVtx[3] = {mcX, mcY, mcZ};
  1365. KFParticleSIMD DaughterSIMD(Daughter);
  1366. DaughterSIMD.TransportToPoint(decayVtx);
  1367. int jParticlePDG = fParteff.GetParticleIndex(mcTrack.PDG());
  1368. Double_t massMC = (jParticlePDG>=0) ? fParteff.partMass[jParticlePDG] :0.13957;
  1369. Double_t Emc = sqrt(mcTrack.P()*mcTrack.P() + massMC*massMC);
  1370. Double_t res[8] = {0},
  1371. pull[8] = {0},
  1372. mcParam[8] = { mcX, mcY, mcZ,
  1373. mcPx, mcPy, mcPz, Emc, massMC };
  1374. for(int iPar=0; iPar < 7; iPar++ )
  1375. {
  1376. Double_t error = DaughterSIMD.GetCovariance(iPar,iPar)[0];
  1377. if(error < 0.) { error = 1.e20;}
  1378. error = TMath::Sqrt(error);
  1379. Double_t recoPar = DaughterSIMD.GetParameter(iPar)[0];
  1380. res[iPar] = recoPar - mcParam[iPar];
  1381. if(fabs(error) > 1.e-20) pull[iPar] = res[iPar]/error;
  1382. }
  1383. res[7] = M - mcParam[7];
  1384. if(fabs(ErrM) > 1.e-20) pull[7] = res[7]/ErrM;
  1385. for(int iPar=0; iPar < 8; iPar++ )
  1386. {
  1387. histoFitDaughtersQA[iParticle][iPar]->Fill(res[iPar]);
  1388. histoFitDaughtersQA[iParticle][iPar+8]->Fill(pull[iPar]);
  1389. }
  1390. //fill Histos for GetDStoParticle
  1391. if(iD == 0)
  1392. daughterIndex[0] = recDaughterId;
  1393. if(iD == 1 && daughterIndex[0] > -1 && histoDSToParticleQA)
  1394. {
  1395. daughterIndex[1] = recDaughterId;
  1396. KFParticle d1 = fTopoReconstructor->GetParticles()[daughterIndex[0]];
  1397. KFParticle d2 = fTopoReconstructor->GetParticles()[daughterIndex[1]];
  1398. KFParticleSIMD daughters[2] = {d2, d1};
  1399. float_v dS[2] = {0.f, 0.f};
  1400. float_v dsdr[4][6];
  1401. for(int i1=0; i1<4; i1++)
  1402. for(int i2=0; i2<6; i2++)
  1403. dsdr[i1][i2] = 0.f;
  1404. daughters[0].GetDStoParticle(daughters[1], dS, dsdr);
  1405. float_v pD[2][8], cD[2][36], corrPD[2][36], corrCD[2][36];
  1406. for(int iDR=0; iDR<2; iDR++)
  1407. {
  1408. for(int iPD = 0; iPD<8; iPD++)
  1409. {
  1410. pD[iDR][iPD] = 0;
  1411. corrPD[iDR][iPD] = 0;
  1412. }
  1413. for(int iCD=0; iCD<36; iCD++)
  1414. {
  1415. cD[iDR][iCD] = 0;
  1416. corrCD[iDR][iCD] = 0;
  1417. }
  1418. }
  1419. float_v F[4][36];
  1420. {
  1421. for(int i1=0; i1<4; i1++)
  1422. for(int i2=0; i2<36; i2++)
  1423. F[i1][i2] = 0;
  1424. }
  1425. daughters[0].Transport(dS[0], dsdr[0], pD[0], cD[0], dsdr[1], F[0], F[1]);
  1426. daughters[1].Transport(dS[1], dsdr[3], pD[1], cD[1], dsdr[2], F[3], F[2]);
  1427. daughters[0].MultQSQt( F[1], daughters[1].CovarianceMatrix(), corrCD[0], 6);
  1428. daughters[0].MultQSQt( F[2], daughters[0].CovarianceMatrix(), corrCD[1], 6);
  1429. for(int iDR=0; iDR<2; iDR++)
  1430. for(int iC=0; iC<6; iC++)
  1431. cD[iDR][iC] += corrCD[iDR][iC];
  1432. for(int iDR=0; iDR<2; iDR++)
  1433. {
  1434. cD[iDR][1] = cD[iDR][2];
  1435. cD[iDR][2] = cD[iDR][5];
  1436. for(int iPar=0; iPar<3; iPar++)
  1437. {
  1438. res[iPar] = pD[iDR][iPar][0] - decayVtx[iPar][0];
  1439. Double_t error = cD[iDR][iPar][0];
  1440. if(error < 0.) { error = 1.e20;}
  1441. error = sqrt(error);
  1442. pull[iPar] = res[iPar] / error;
  1443. histoDSToParticleQA[iParticle][iPar]->Fill(res[iPar]);
  1444. histoDSToParticleQA[iParticle][iPar+3]->Fill(pull[iPar]);
  1445. }
  1446. }
  1447. Double_t dXds = pD[0][0][0] - pD[1][0][0];
  1448. Double_t dYds = pD[0][1][0] - pD[1][1][0];
  1449. Double_t dZds = pD[0][2][0] - pD[1][2][0];
  1450. Double_t dRds = sqrt(dXds*dXds + dYds*dYds + dZds*dZds);
  1451. histoDSToParticleQA[iParticle][6]->Fill(dRds);
  1452. }
  1453. }
  1454. }
  1455. }
  1456. void KFTopoPerformance::FillHistos()
  1457. {
  1458. /** Fills histograms with parameter distributions and fit quality for all particle and primary vertex candidates. */
  1459. vector<int> multiplicities[6];
  1460. for(int iV=0; iV<6; iV++)
  1461. multiplicities[iV].resize(KFPartEfficiencies::nParticles, 0);
  1462. //fill histograms for found short-lived particles
  1463. for(unsigned int iP=0; iP<fTopoReconstructor->GetParticles().size(); iP++)
  1464. {
  1465. int iParticle = fParteff.GetParticleIndex(fTopoReconstructor->GetParticles()[iP].GetPDG());
  1466. if(iParticle < 0) continue;
  1467. KFParticle TempPart = fTopoReconstructor->GetParticles()[iP];
  1468. FillParticleParameters(TempPart,iParticle, iP, 0, hPartParam, hPartParam2D, hPartParam3D,
  1469. hFitQA, hFitDaughtersQA, hDSToParticleQA, multiplicities);
  1470. }
  1471. if(fStoreMCHistograms)
  1472. {
  1473. for(int iSet=0; iSet<KFParticleFinder::GetNSecondarySets(); iSet++)
  1474. {
  1475. const std::vector<KFParticle>& SecondaryCandidates = fTopoReconstructor->GetKFParticleFinder()->GetSecondaryCandidates()[iSet];
  1476. for(unsigned int iP=0; iP<SecondaryCandidates.size(); iP++)
  1477. {
  1478. KFParticle TempPart = SecondaryCandidates[iP];
  1479. int iParticle = fParteff.GetParticleIndex(TempPart.GetPDG());
  1480. if(iParticle < 0) continue;
  1481. const int id = TempPart.Id();
  1482. FillParticleParameters(TempPart, iParticle, id, 0, hPartParamSecondaryMass, hPartParam2DSecondaryMass, 0);
  1483. TempPart = fTopoReconstructor->GetParticles()[id];
  1484. FillParticleParameters(TempPart, iParticle, id, 0, hPartParamSecondary, hPartParam2DSecondary, 0);
  1485. }
  1486. }
  1487. for(int iSet=0; iSet<KFParticleFinder::GetNPrimarySets(); iSet++)
  1488. {
  1489. for(int iPV=0; iPV<fTopoReconstructor->NPrimaryVertices(); iPV++)
  1490. {
  1491. const std::vector<KFParticle>& PrimaryCandidates = fTopoReconstructor->GetKFParticleFinder()->GetPrimaryCandidates()[iSet][iPV];
  1492. for(unsigned int iP=0; iP<PrimaryCandidates.size(); iP++)
  1493. {
  1494. KFParticle TempPart = PrimaryCandidates[iP];
  1495. int iParticle = fParteff.GetParticleIndex(TempPart.GetPDG());
  1496. if(iParticle < 0) continue;
  1497. const int id = TempPart.Id();
  1498. FillParticleParameters(TempPart,iParticle, id, iPV, hPartParamPrimaryMass, hPartParam2DPrimaryMass, 0, hFitQAMassConstraint);
  1499. TempPart = fTopoReconstructor->GetParticles()[id];
  1500. FillParticleParameters(TempPart,iParticle, id, iPV, hPartParamPrimary, hPartParam2DPrimary, 0, hFitQANoConstraint);
  1501. }
  1502. const std::vector<KFParticle>& PrimaryCandidatesTopo = fTopoReconstructor->GetKFParticleFinder()->GetPrimaryTopoCandidates()[iSet][iPV];
  1503. for(unsigned int iP=0; iP<PrimaryCandidatesTopo.size(); iP++)
  1504. {
  1505. KFParticle TempPart = PrimaryCandidatesTopo[iP];
  1506. int iParticle = fParteff.GetParticleIndex(TempPart.GetPDG());
  1507. if(iParticle < 0) continue;
  1508. FillParticleParameters(TempPart,iParticle, TempPart.Id(), iPV, hPartParamPrimaryTopo, hPartParam2DPrimaryTopo, 0, hFitQATopoConstraint);
  1509. }
  1510. const std::vector<KFParticle>& PrimaryCandidatesTopoMass = fTopoReconstructor->GetKFParticleFinder()->GetPrimaryTopoMassCandidates()[iSet][iPV];
  1511. for(unsigned int iP=0; iP<PrimaryCandidatesTopoMass.size(); iP++)
  1512. {
  1513. KFParticle TempPart = PrimaryCandidatesTopoMass[iP];
  1514. int iParticle = fParteff.GetParticleIndex(TempPart.GetPDG());
  1515. if(iParticle < 0) continue;
  1516. FillParticleParameters(TempPart,iParticle, TempPart.Id(), iPV, hPartParamPrimaryTopoMass, hPartParam2DPrimaryTopoMass, 0, hFitQATopoMassConstraint);
  1517. }
  1518. }
  1519. }
  1520. }
  1521. //fill histograms with ChiPrim for every particle
  1522. for(unsigned int iP=0; iP<fTopoReconstructor->GetParticles().size(); iP++)
  1523. {
  1524. KFParticle TempPart = fTopoReconstructor->GetParticles()[iP];
  1525. KFParticle vtx = fTopoReconstructor->GetPrimVertex(0);
  1526. if(RtoMCParticleId[iP].IsMatched())
  1527. {
  1528. int iMCPV = vMCParticles[RtoMCParticleId[iP].GetBestMatch()].GetMotherId();
  1529. if(iMCPV<0.)
  1530. {
  1531. iMCPV = -iMCPV - 1;
  1532. if(MCtoRPVId[iMCPV].IsMatched())
  1533. {
  1534. vtx = fTopoReconstructor->GetPrimVertex(MCtoRPVId[iMCPV].GetBestMatch());
  1535. }
  1536. }
  1537. }
  1538. // else
  1539. // KFParticle & vtx = fTopoReconstructor->GetPrimVertex(0);
  1540. float chi2 = TempPart.GetDeviationFromVertex(vtx);
  1541. int ndf = 2;
  1542. hTrackParameters[KFPartEfficiencies::nParticles]->Fill(chi2);
  1543. hTrackParameters[KFPartEfficiencies::nParticles+4]->Fill(TMath::Prob(chi2, ndf));
  1544. if(!RtoMCParticleId[iP].IsMatched())
  1545. {
  1546. hTrackParameters[KFPartEfficiencies::nParticles+3]->Fill(chi2);
  1547. hTrackParameters[KFPartEfficiencies::nParticles+7]->Fill(TMath::Prob(chi2, ndf));
  1548. continue;
  1549. }
  1550. int iMCPart = RtoMCParticleId[iP].GetBestMatch();
  1551. KFMCParticle &mcPart = vMCParticles[iMCPart];
  1552. if(mcPart.GetMotherId() < 0)
  1553. {
  1554. hTrackParameters[KFPartEfficiencies::nParticles+1]->Fill(chi2 );
  1555. hTrackParameters[KFPartEfficiencies::nParticles+5]->Fill(TMath::Prob(chi2, ndf));
  1556. }
  1557. else
  1558. {
  1559. hTrackParameters[KFPartEfficiencies::nParticles+2]->Fill(chi2 );
  1560. hTrackParameters[KFPartEfficiencies::nParticles+6]->Fill(TMath::Prob(chi2, ndf));
  1561. }
  1562. int iParticle = fParteff.GetParticleIndex(fTopoReconstructor->GetParticles()[iP].GetPDG());
  1563. if(iParticle > -1 && iParticle<KFPartEfficiencies::nParticles)
  1564. hTrackParameters[iParticle]->Fill(chi2 );
  1565. }
  1566. //fill histograms of the primary vertex quality
  1567. for(int iPV = 0; iPV<fTopoReconstructor->NPrimaryVertices(); iPV++)
  1568. {
  1569. KFParticle & vtx = fTopoReconstructor->GetPrimVertex(iPV);
  1570. vector<int> &tracks = fTopoReconstructor->GetPVTrackIndexArray(iPV);
  1571. Double_t probPV = TMath::Prob(vtx.Chi2(), vtx.NDF());//(TDHelper<float>::Chi2IProbability( ndf, chi2 ));
  1572. vector<Double_t> dzPV;
  1573. if(RtoMCPVId[iPV].IsMatched())
  1574. {
  1575. int iCurrMCPV = RtoMCPVId[iPV].GetBestMatch();
  1576. for(int iPV2 = iPV+1; iPV2 < fTopoReconstructor->NPrimaryVertices(); iPV2++)
  1577. {
  1578. if(!RtoMCPVId[iPV2].IsMatched()) continue;
  1579. int iCurrMCPV2 = RtoMCPVId[iPV2].GetBestMatch();
  1580. if(iCurrMCPV != iCurrMCPV2) continue;
  1581. KFParticle & vtx2 = fTopoReconstructor->GetPrimVertex(iPV2);
  1582. dzPV.push_back(fabs(vtx.Z() - vtx2.Z()));
  1583. }
  1584. }
  1585. hPVParam[ 0]->Fill(vtx.X());
  1586. hPVParam[ 1]->Fill(vtx.Y());
  1587. hPVParam[ 2]->Fill(vtx.Z());
  1588. hPVParam[ 3]->Fill(sqrt(vtx.X()*vtx.X() + vtx.Y()*vtx.Y()));
  1589. hPVParam[ 4]->Fill(tracks.size());
  1590. hPVParam[ 5]->Fill(vtx.Chi2());
  1591. hPVParam[ 6]->Fill(vtx.NDF());
  1592. hPVParam[ 7]->Fill(vtx.Chi2()/vtx.NDF());
  1593. hPVParam[ 8]->Fill(probPV);
  1594. hPVParam[ 9]->Fill(fPVPurity[iPV]);
  1595. hPVParam[10]->Fill(fPVTracksRate[0][iPV]);
  1596. hPVParam[11]->Fill(fPVTracksRate[1][iPV]);
  1597. hPVParam[12]->Fill(fPVTracksRate[2][iPV]);
  1598. hPVParam[13]->Fill(fPVTracksRate[3][iPV]);
  1599. for(unsigned int iZ=0; iZ<dzPV.size(); iZ++)
  1600. hPVParam[14]->Fill(dzPV[iZ]);
  1601. hPVParam2D[0]->Fill(vtx.X(),vtx.Y());
  1602. if(!RtoMCPVId[iPV].IsMatchedWithPdg())
  1603. {
  1604. if(!RtoMCPVId[iPV].IsMatched())
  1605. {
  1606. hPVParamGhost[ 0]->Fill(vtx.X());
  1607. hPVParamGhost[ 1]->Fill(vtx.Y());
  1608. hPVParamGhost[ 2]->Fill(vtx.Z());
  1609. hPVParamGhost[ 3]->Fill(sqrt(vtx.X()*vtx.X() + vtx.Y()*vtx.Y()));
  1610. hPVParamGhost[ 4]->Fill(tracks.size());
  1611. hPVParamGhost[ 5]->Fill(vtx.Chi2());
  1612. hPVParamGhost[ 6]->Fill(vtx.NDF());
  1613. hPVParamGhost[ 7]->Fill(vtx.Chi2()/vtx.NDF());
  1614. hPVParamGhost[ 8]->Fill(probPV);
  1615. hPVParamGhost[ 9]->Fill(fPVPurity[iPV]);
  1616. hPVParamGhost[10]->Fill(fPVTracksRate[0][iPV]);
  1617. hPVParamGhost[11]->Fill(fPVTracksRate[1][iPV]);
  1618. hPVParamGhost[12]->Fill(fPVTracksRate[2][iPV]);
  1619. hPVParamGhost[13]->Fill(fPVTracksRate[3][iPV]);
  1620. for(unsigned int iZ=0; iZ<dzPV.size(); iZ++)
  1621. hPVParamGhost[14]->Fill(dzPV[iZ]);
  1622. }
  1623. else
  1624. {
  1625. hPVParamBG[ 0]->Fill(vtx.X());
  1626. hPVParamBG[ 1]->Fill(vtx.Y());
  1627. hPVParamBG[ 2]->Fill(vtx.Z());
  1628. hPVParamBG[ 3]->Fill(sqrt(vtx.X()*vtx.X() + vtx.Y()*vtx.Y()));
  1629. hPVParamBG[ 4]->Fill(tracks.size());
  1630. hPVParamBG[ 5]->Fill(vtx.Chi2());
  1631. hPVParamBG[ 6]->Fill(vtx.NDF());
  1632. hPVParamBG[ 7]->Fill(vtx.Chi2()/vtx.NDF());
  1633. hPVParamBG[ 8]->Fill(probPV);
  1634. hPVParamBG[ 9]->Fill(fPVPurity[iPV]);
  1635. hPVParamBG[10]->Fill(fPVTracksRate[0][iPV]);
  1636. hPVParamBG[11]->Fill(fPVTracksRate[1][iPV]);
  1637. hPVParamBG[12]->Fill(fPVTracksRate[2][iPV]);
  1638. hPVParamBG[13]->Fill(fPVTracksRate[3][iPV]);
  1639. for(unsigned int iZ=0; iZ<dzPV.size(); iZ++)
  1640. hPVParamBG[14]->Fill(dzPV[iZ]);
  1641. }
  1642. continue;
  1643. }
  1644. int iMCPV = RtoMCPVId[iPV].GetBestMatch();
  1645. KFMCVertex &mcPV = fPrimVertices[iMCPV]; // primary vertex positions (currently only one vertex is implemented)
  1646. int iPVType = 0;
  1647. if(mcPV.IsTriggerPV())
  1648. {
  1649. hPVParamSignal[ 0]->Fill(vtx.X());
  1650. hPVParamSignal[ 1]->Fill(vtx.Y());
  1651. hPVParamSignal[ 2]->Fill(vtx.Z());
  1652. hPVParamSignal[ 3]->Fill(sqrt(vtx.X()*vtx.X() + vtx.Y()*vtx.Y()));
  1653. hPVParamSignal[ 4]->Fill(tracks.size());
  1654. hPVParamSignal[ 5]->Fill(vtx.Chi2());
  1655. hPVParamSignal[ 6]->Fill(vtx.NDF());
  1656. hPVParamSignal[ 7]->Fill(vtx.Chi2()/vtx.NDF());
  1657. hPVParamSignal[ 8]->Fill(probPV);
  1658. hPVParamSignal[ 9]->Fill(fPVPurity[iPV]);
  1659. hPVParamSignal[10]->Fill(fPVTracksRate[0][iPV]);
  1660. hPVParamSignal[11]->Fill(fPVTracksRate[1][iPV]);
  1661. hPVParamSignal[12]->Fill(fPVTracksRate[2][iPV]);
  1662. hPVParamSignal[13]->Fill(fPVTracksRate[3][iPV]);
  1663. for(unsigned int iZ=0; iZ<dzPV.size(); iZ++)
  1664. hPVParamSignal[14]->Fill(dzPV[iZ]);
  1665. }
  1666. else
  1667. {
  1668. hPVParamPileup[ 0]->Fill(vtx.X());
  1669. hPVParamPileup[ 1]->Fill(vtx.Y());
  1670. hPVParamPileup[ 2]->Fill(vtx.Z());
  1671. hPVParamPileup[ 3]->Fill(sqrt(vtx.X()*vtx.X() + vtx.Y()*vtx.Y()));
  1672. hPVParamPileup[ 4]->Fill(tracks.size());
  1673. hPVParamPileup[ 5]->Fill(vtx.Chi2());
  1674. hPVParamPileup[ 6]->Fill(vtx.NDF());
  1675. hPVParamPileup[ 7]->Fill(vtx.Chi2()/vtx.NDF());
  1676. hPVParamPileup[ 8]->Fill(probPV);
  1677. hPVParamPileup[ 9]->Fill(fPVPurity[iPV]);
  1678. hPVParamPileup[10]->Fill(fPVTracksRate[0][iPV]);
  1679. hPVParamPileup[11]->Fill(fPVTracksRate[1][iPV]);
  1680. hPVParamPileup[12]->Fill(fPVTracksRate[2][iPV]);
  1681. hPVParamPileup[13]->Fill(fPVTracksRate[3][iPV]);
  1682. for(unsigned int iZ=0; iZ<dzPV.size(); iZ++)
  1683. hPVParamPileup[14]->Fill(dzPV[iZ]);
  1684. iPVType = 1;
  1685. }
  1686. //Find MC parameters of the primary vertex
  1687. float mcPVx[3]={mcPV.X(), mcPV.Y(), mcPV.Z()};
  1688. float errPV[3] = {vtx.CovarianceMatrix()[0], vtx.CovarianceMatrix()[2], vtx.CovarianceMatrix()[5]};
  1689. for(int iErr=0; iErr<3; iErr++)
  1690. if(fabs(errPV[iErr]) < 1.e-8f) errPV[iErr] = 1.e8;
  1691. float dRPVr[3] = {vtx.X()-mcPVx[0],
  1692. vtx.Y()-mcPVx[1],
  1693. vtx.Z()-mcPVx[2]};
  1694. float dRPVp[3] = {static_cast<float>(dRPVr[0]/sqrt(errPV[0])),
  1695. static_cast<float>(dRPVr[1]/sqrt(errPV[1])),
  1696. static_cast<float>(dRPVr[2]/sqrt(errPV[2]))};
  1697. for(unsigned int iHPV=0; iHPV<3; ++iHPV)
  1698. hPVFitQa[iPVType][iHPV]->Fill(dRPVr[iHPV]);
  1699. for(unsigned int iHPV=3; iHPV<6; ++iHPV)
  1700. hPVFitQa[iPVType][iHPV]->Fill(dRPVp[iHPV-3]);
  1701. for(unsigned int iHPV=0; iHPV<3; ++iHPV)
  1702. hPVFitQa2D[iPVType][1][iHPV]->Fill(fNCorrectPVTracks[iPV],dRPVr[iHPV]);
  1703. for(unsigned int iHPV=3; iHPV<6; ++iHPV)
  1704. hPVFitQa2D[iPVType][1][iHPV]->Fill(fNCorrectPVTracks[iPV],dRPVp[iHPV-3]);
  1705. for(unsigned int iHPV=0; iHPV<3; ++iHPV)
  1706. hPVFitQa2D[iPVType][0][iHPV]->Fill(mcPV.NReconstructedDaughterTracks(),dRPVr[iHPV]);
  1707. for(unsigned int iHPV=3; iHPV<6; ++iHPV)
  1708. hPVFitQa2D[iPVType][0][iHPV]->Fill(mcPV.NReconstructedDaughterTracks(),dRPVp[iHPV-3]);
  1709. hPVFitQa[iPVType][6]->Fill( double(mcPV.NReconstructedDaughterTracks() - fNCorrectPVTracks[iPV])/double(mcPV.NReconstructedDaughterTracks()) );
  1710. }
  1711. //fill histograms with quality of input tracks from PV
  1712. for(unsigned int iP=0; iP<fTopoReconstructor->GetParticles().size(); iP++)
  1713. {
  1714. KFParticle TempPart = fTopoReconstructor->GetParticles()[iP];
  1715. int nDaughters = TempPart.NDaughters();
  1716. if(nDaughters > 1) continue; //use only tracks, not short lived particles
  1717. if(!RtoMCParticleId[iP].IsMatchedWithPdg()) continue; //ghost
  1718. int iMCPart = RtoMCParticleId[iP].GetBestMatchWithPdg();
  1719. KFMCParticle &mcPart = vMCParticles[iMCPart];
  1720. int iMCTrack = mcPart.GetMCTrackID();
  1721. KFMCTrack &mcTrack = vMCTracks[iMCTrack];
  1722. if( mcTrack.MotherId() > -1 ) continue; // select only PV tracks
  1723. const float mcX = mcTrack.X();
  1724. const float mcY = mcTrack.Y();
  1725. const float mcZ = mcTrack.Z();
  1726. const float mcPx = mcTrack.Px();
  1727. const float mcPy = mcTrack.Py();
  1728. const float mcPz = mcTrack.Pz();
  1729. float decayVtx[3] = {mcX, mcY, mcZ};
  1730. TempPart.TransportToPoint(decayVtx);
  1731. Double_t res[6] = {0},
  1732. pull[6] = {0},
  1733. mcParam[6] = { mcX, mcY, mcZ,
  1734. mcPx, mcPy, mcPz };
  1735. for(int iPar=0; iPar < 6; iPar++ )
  1736. {
  1737. Double_t error = TempPart.GetCovariance(iPar,iPar);
  1738. if(error < 0.) { error = 1.e20;}
  1739. error = TMath::Sqrt(error);
  1740. res[iPar] = TempPart.GetParameter(iPar) - mcParam[iPar];
  1741. if(fabs(error) > 1.e-20) pull[iPar] = res[iPar]/error;
  1742. hFitPVTracksQA[iPar]->Fill(res[iPar]);
  1743. hFitPVTracksQA[iPar+6]->Fill(pull[iPar]);
  1744. }
  1745. }
  1746. if(fStoreMCHistograms)
  1747. {
  1748. for(int iV=0; iV<6; iV++)
  1749. for(int iP=0; iP < KFPartEfficiencies::nParticles; iP++)
  1750. if(hPartParam[iV][iP][17])
  1751. hPartParam[iV][iP][17]->Fill(multiplicities[iV][iP]);
  1752. FillMCHistos();
  1753. }
  1754. else
  1755. for(int iP=0; iP < KFPartEfficiencies::nParticles; iP++)
  1756. if(hPartParam[0][iP][17])
  1757. hPartParam[0][iP][17]->Fill(multiplicities[0][iP]);
  1758. } // void KFTopoPerformance::FillHistos()
  1759. void KFTopoPerformance::FillMCHistos()
  1760. {
  1761. /** Fills histograms of Monte Carlo particles. */
  1762. for(unsigned int iMCTrack=0; iMCTrack<vMCTracks.size(); iMCTrack++)
  1763. {
  1764. int iPDG = fParteff.GetParticleIndex(vMCTracks[iMCTrack].PDG());
  1765. if(iPDG < 0) continue;
  1766. if(vMCTracks[iMCTrack].MotherId()>=0) continue;
  1767. KFMCParticle &part = vMCParticles[iMCTrack];
  1768. float M = fParteff.partMass[iPDG];
  1769. float P = vMCTracks[iMCTrack].P();
  1770. float Pt = vMCTracks[iMCTrack].Pt();
  1771. float E = sqrt(M*M+P*P);
  1772. float Rapidity = 0.5*log((E+vMCTracks[iMCTrack].Pz())/(E-vMCTracks[iMCTrack].Pz()));
  1773. float M_t = sqrt(Pt*Pt+M*M)-M;
  1774. float X;
  1775. float Y;
  1776. float Z;
  1777. float R;
  1778. if (part.NDaughters()>0)
  1779. {
  1780. X = vMCTracks[part.GetDaughterIds()[0]].X();
  1781. Y = vMCTracks[part.GetDaughterIds()[0]].Y();
  1782. Z = vMCTracks[part.GetDaughterIds()[0]].Z();
  1783. }
  1784. else
  1785. {
  1786. X = vMCTracks[iMCTrack].X();
  1787. Y = vMCTracks[iMCTrack].Y();
  1788. Z = vMCTracks[iMCTrack].Z();
  1789. }
  1790. R = sqrt(X*X+Y*Y);
  1791. float parameters[17] = {M, P, Pt, Rapidity, 0, 0, 0, 0, 0, 0, X, Y, Z, R, 0, 0, M_t};
  1792. //for all particle-candidates
  1793. for(int iParam=0; iParam<17; iParam++)
  1794. if(hPartParam[6][iPDG][iParam]) hPartParam[6][iPDG][iParam]->Fill(parameters[iParam]);
  1795. if(hPartParam2D[6][iPDG][0]) hPartParam2D[6][iPDG][0]->Fill(Rapidity,Pt,1);
  1796. if(hPartParam2D[6][iPDG][3]) hPartParam2D[6][iPDG][3]->Fill(Rapidity,M_t,1);
  1797. if(IsCollectZRHistogram(iPDG))
  1798. if(hPartParam2D[6][iPDG][1]) hPartParam2D[6][iPDG][1]->Fill(Z,R,1);
  1799. if( part.IsReconstructable(2) && IsCollectArmenteros(iPDG))
  1800. {
  1801. int index1 = part.GetDaughterIds()[0];
  1802. int index2 = part.GetDaughterIds()[1];
  1803. KFMCTrack positive, negative;
  1804. if(vMCTracks[index1].Par(6) > 0)
  1805. {
  1806. positive = vMCTracks[index1];
  1807. negative = vMCTracks[index2];
  1808. }
  1809. else
  1810. {
  1811. negative = vMCTracks[index1];
  1812. positive = vMCTracks[index2];
  1813. }
  1814. float alpha = 0., qt = 0.;
  1815. float spx = positive.Px() + negative.Px();
  1816. float spy = positive.Py() + negative.Py();
  1817. float spz = positive.Pz() + negative.Pz();
  1818. float sp = sqrt(spx*spx + spy*spy + spz*spz);
  1819. float pn, pln, plp;
  1820. pn = sqrt(negative.Px()*negative.Px() + negative.Py()*negative.Py() + negative.Pz()*negative.Pz());
  1821. pln = (negative.Px()*spx+negative.Py()*spy+negative.Pz()*spz)/sp;
  1822. plp = (positive.Px()*spx+positive.Py()*spy+positive.Pz()*spz)/sp;
  1823. float ptm = (1.-((pln/pn)*(pln/pn)));
  1824. qt= (ptm>=0.)? pn*sqrt(ptm) :0;
  1825. alpha = (plp-pln)/(plp+pln);
  1826. if(hPartParam2D[6][iPDG][2]) hPartParam2D[6][iPDG][2]->Fill(alpha,qt,1);
  1827. }
  1828. }
  1829. }
  1830. void KFTopoPerformance::AddV0Histos()
  1831. {
  1832. /** Copies histograms of K0s candidates to V0 folder. */
  1833. int iV0 = fParteff.nParticles - 1;
  1834. int iK0 = fParteff.GetParticleIndex(310);
  1835. for(int iH=0; iH<nFitQA; iH++)
  1836. {
  1837. hFitDaughtersQA[iV0][iH]->Add(hFitDaughtersQA[iK0][iH]);
  1838. hFitQA[iV0][iH]->Add(hFitQA[iK0][iH]);
  1839. }
  1840. for(int iV=0; iV<4; iV++)
  1841. for(int iH=0; iH<nHistoPartParam; iH++)
  1842. hPartParam[iV][iV0][iH]->Add(hPartParam[iV][iK0][iH]);
  1843. }
  1844. void KFTopoPerformance::FillHistos(const KFPHistogram* histograms)
  1845. {
  1846. /** Fill histograms with the histograms from the provided KFPHistogram object. */
  1847. for(int iParticle=0; iParticle<KFPartEfficiencies::nParticles; iParticle++)
  1848. {
  1849. const int& nHistograms = histograms->GetHistogramSet(0).GetNHisto1D();
  1850. for(int iHistogram=0; iHistogram<nHistograms; iHistogram++)
  1851. {
  1852. const KFPHistogram1D& histogram = histograms->GetHistogram(iParticle,iHistogram);
  1853. for(int iBin=0; iBin<histogram.Size(); iBin++)
  1854. hPartParam[0][iParticle][iHistogram]->SetBinContent( iBin, histogram.GetHistogram()[iBin] );
  1855. }
  1856. }
  1857. }
  1858. #endif //DO_TPCCATRACKER_EFF_PERFORMANCE