MpdTofHitProducerQA.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //------------------------------------------------------------------------------------------------------------------------
  2. #include <iostream>
  3. #include <TFile.h>
  4. #include <TMath.h>
  5. #include <TClonesArray.h>
  6. #include <FairLogger.h>
  7. #include "MpdTofHit.h"
  8. #include "MpdTof.h"
  9. #include "MpdTofPoint.h"
  10. #include "MpdTofGeoUtils.h"
  11. #include "MpdTofHitProducerQA.h"
  12. using namespace std;
  13. //------------------------------------------------------------------------------------------------------------------------
  14. MpdTofHitProducerQA::MpdTofHitProducerQA(const char *flnm, bool isEndcap)
  15. : fFlnm(flnm), fIsEndcap(isEndcap)
  16. {
  17. fList.SetOwner(); // all objects will be deleted whenever the collection itself is delete.
  18. Add(hOccup = new TH1D(mangling("Occupancy"), "occupancy per strips;occupancy;Events", 100, -0.5, 99.5));
  19. Add(hMergedTimes = new TH2D(mangling("MergedTimes"), "Merged hits on strip times test;faster hit time, ns;slower hit time, ns", 1000, 0., 150., 1000, 0., 150.));
  20. Add(hHitPointPerEvent = new TH2D(mangling("NHitNPointPerEvent"), ";N points per event;N hits per event", 1000, 0.5, 4000.5, 1000, 0.5, 1500.5));
  21. Add(hPointDistanceSame = new TH2D(mangling("TwoPointDistanceSame"), "distances between a pair points(same tids);distance, cm;time between hits, ns", 1000, 0., 50., 1000, 0., 50.));
  22. Add(hPointDistanceDiff = new TH2D(mangling("TwoPointDistanceDiff"), "distances between a pair points(different tids);distance, cm;time between hits, ns", 1000, 0., 50., 1000, 0., 50.));
  23. Add(effHitGap2 = new TEfficiency(mangling("efficiencyHitsMiddle"), "Efficiency of middle gap hits;R, cm;efficiency", 1000, -0.1, 1.));
  24. Add(effHitGap13 = (TEfficiency*) effHitGap2->Clone(mangling("efficiencyHitsOuter")));
  25. effHitGap13->SetTitle("Efficiency of outer gaps hits;R, cm;efficiency");
  26. Add(effCrossHit = (TEfficiency*) effHitGap2->Clone(mangling("efficiencyCrossHits")));
  27. effCrossHit->SetTitle("Efficiency of cross hits;R, cm;efficiency");
  28. // geometrical tests
  29. Add(hDistance = new TH1D(mangling("geoDistance"), "Distance between strips(minus-left side, plus-right side);Distance, cm;Side", 1000, -100., 100.));
  30. Add(h2Strips = new TH2D(mangling("geoStripsMap"), ";Z, cm;#phi, rads", 2000, -300., 300., 500, -3.5, 3.5));
  31. Add(h2Detectors = new TH2D(mangling("geoDetectorMap"), ";Z, cm;#phi, rads", 2000, -300., 300., 500, -3.5, 3.5));
  32. Add(hNeighborPair = new TH2D(mangling("geoNeighborPair"), "Neighbor strip pairs test;stripID1;stripID2", 75, -0.5, 74.5, 75, -0.5, 74.5));
  33. Add(hEtaPhi = new TH2D(mangling("geoEtaPhi"), ";#eta;#phi, degree", 1000, -1.5, 1.5, 1000, -181., 181.));
  34. Add(hRZ = new TH2D(mangling("geoRZ"), ";Z, cm;R, cm", 1000, -300., 300., 1000, 150., 160.));
  35. // hit smearing tests
  36. Add(hXYSmeared = new TH2D(mangling("XYSmeared_ZPhi"), "single hits;#Delta_{Z}, cm;#Delta_{#phi}, cm", 1000, -0.7, 0.7, 1000, -5., 5.));
  37. Add(hXYSmeared2 = new TH2D(mangling("XYSmeared_DevR"), "single hits;#Delta, cm;#DeltaRperp, cm", 1000, 0., 2., 1000, -2., 2.));
  38. Add(hXYSmearedCross = new TH2D(mangling("XYSmearedCross_ZPhi"), "cross hits;#Delta_{Z}, cm;#Delta_{#phi}, cm", 1000, -2., 2., 1000, -1., 1.));
  39. Add(hXYSmearedCross2 = new TH2D(mangling("XYSmearedCross_DevR"), "cross hits;#Delta, cm;#DeltaRperp, cm", 1000, 0., 3., 1000, -3., 3.));
  40. Add(hHitPositionInsideStrip = new TH2D(mangling("HitPositionInsideStrip"),
  41. "Hit position deviation from strip center(single hits);#Delta_{#phi}, cm;#Delta_{Z}, cm", 1000, -50., 50., 1000, -0.5, 0.5));
  42. Add(hMCPositionInsideStrip = new TH2D(mangling("MCPositionInsideStrip"),
  43. "MC point position deviation from strip center(single hits);#Delta_{#phi}, cm;#Delta_{Z}, cm", 1000, -50., 50., 1000, -5., 5.));
  44. Add(hPointXZOrigin = new TH2D(mangling("PointXZOrigin"), "MC point XZ position at origin LRS;Z, cm;X, cm", 1000, -1., 1., 1000, -50., 50.));
  45. Add(hPointYZOrigin = new TH2D(mangling("PointYZOrigin"), "MC point YZ position at origin LRS;Z, cm;Y, cm", 1000, -1., 1., 1000, -0.2, 0.2));
  46. Add(hHitXZOrigin = new TH2D(mangling("HitXZOrigin"), "Hit XZ position at origin LRS;X, cm;Z, cm", 1000, -50., 50., 1000, -0.05, 0.05));
  47. Add(hHitYZOrigin = new TH2D(mangling("HitYZOrigin"), "Hit YZ position at origin LRS;Y, cm;Z, cm", 1000, -0.1, 0.1, 1000, -0.05, 0.05));
  48. Add(hDevHitXZOrigin = new TH2D(mangling("DevHitXZOrigin"), "Hit XZ position deviation from MC point position at origin LRS;X, cm;Z, cm", 1000, -10., 10., 1000, -1., 1.));
  49. Add(hDevHitYZOrigin = new TH2D(mangling("DevHitYZOrigin"), "Hit YZ position deviation from MC point position at origin LRS;Y, cm;Z, cm", 1000, -0.1, 0.1, 1000, -1., 1.));
  50. Add(hXZCentralDetector = new TH2D(mangling("XZCentralDetector"), "central detector hits.;Z, cm;X, cm", 1000, -10., 40., 1000, -50., 50.));
  51. Add(hYZCentralDetector = new TH2D(mangling("YZCentralDetector"), "central detector hits.;Z, cm;Y, cm", 1000, -10., 40., 1000, 149., 152.));
  52. Add(hXZDetector = new TH2D(mangling("XYDetector"), "central detector hits.;X, cm;Y, cm", 1000, -40., 40., 1000, -0.6, 0.6));
  53. Add(hYZDetector = new TH2D(mangling("YZDetector"), "central detector hits.;Z, cm;Y, cm", 1000, -0.05, 0.05, 1000, -0.6, 0.6));
  54. }
  55. //------------------------------------------------------------------------------------------------------------------------
  56. void MpdTofHitProducerQA::Finish()
  57. {
  58. LOG(DEBUG2)<<"[MpdTofHitProducerQA::Finish] Update "<<fFlnm.Data()<<" file. ";
  59. auto ptr = gFile;
  60. TFile file(fFlnm.Data(), "RECREATE");
  61. fList.Write();
  62. file.Close();
  63. gFile = ptr;
  64. }
  65. //------------------------------------------------------------------------------------------------------------------------
  66. void MpdTofHitProducerQA::PointDistanceTest(const TClonesArray *aMcPoints)
  67. {
  68. TVector3 pos1, pos2;
  69. for(Int_t i = 0, n1 = aMcPoints->GetEntriesFast(); i < n1; i++) // cycle by tof hits
  70. {
  71. auto point1 = (MpdTofPoint*) aMcPoints->At(i);
  72. point1->Position(pos1);
  73. for(Int_t j = i, n2 = aMcPoints->GetEntriesFast(); j < n2; j++)
  74. {
  75. if(i == j) continue;
  76. auto point2 = (MpdTofPoint*) aMcPoints->At(j);
  77. point2->Position(pos2);
  78. double dT = fabs(point1->GetTime() - point2->GetTime());
  79. if(point1->GetTrackID() == point2->GetTrackID()) hPointDistanceSame->Fill((pos1-pos2).Mag(), dT);
  80. else hPointDistanceDiff->Fill((pos1-pos2).Mag(), dT);
  81. }
  82. }
  83. }
  84. //------------------------------------------------------------------------------------------------------------------------
  85. void MpdTofHitProducerQA::FillDetectorsMap(const TVector3& A, const TVector3& B, const TVector3& C, const TVector3& D) // detector edges
  86. {
  87. h2Detectors->Fill(A.Z(), A.Phi());
  88. h2Detectors->Fill(B.Z(), B.Phi());
  89. h2Detectors->Fill(C.Z(), C.Phi());
  90. h2Detectors->Fill(D.Z(), D.Phi());
  91. }
  92. //------------------------------------------------------------------------------------------------------------------------
  93. void MpdTofHitProducerQA::FillStripsMap(const TVector3& A, const TVector3& B, const TVector3& C, const TVector3& D) // strip edges
  94. {
  95. h2Strips->Fill(A.Z(), A.Phi());
  96. h2Strips->Fill(B.Z(), B.Phi());
  97. h2Strips->Fill(C.Z(), C.Phi());
  98. h2Strips->Fill(D.Z(), D.Phi());
  99. }
  100. //------------------------------------------------------------------------------------------------------------------------
  101. void MpdTofHitProducerQA::Point2HitSmearingTest(const TVector3& mcPosition, const TVector3& hitPosition)
  102. {
  103. double delta, deltaZ, deltaR, deltaPhi;
  104. MpdTof::GetDelta(mcPosition, hitPosition, delta, deltaZ, deltaR, deltaPhi);
  105. hXYSmeared->Fill(deltaZ, deltaPhi);
  106. hXYSmeared2->Fill(delta, deltaR);
  107. hEtaPhi->Fill(mcPosition.Eta(), mcPosition.Phi()*TMath::RadToDeg());
  108. hRZ->Fill(mcPosition.Z(), mcPosition.Perp());
  109. }
  110. //------------------------------------------------------------------------------------------------------------------------
  111. void MpdTofHitProducerQA::HitGapEfficiencyTest(bool fired, Double_t distance, Int_t gap)
  112. {
  113. if(2 == gap) effHitGap2->Fill(fired, distance);
  114. else effHitGap13->Fill(fired, distance);
  115. }
  116. //------------------------------------------------------------------------------------------------------------------------
  117. void MpdTofHitProducerQA::PositionInsideStripTest(const TVector3& stripCenter, const TVector3& mcPosition, const TVector3& hitPosition)
  118. {
  119. double hitMeanR = (stripCenter.Perp() + hitPosition.Perp())/2.;
  120. hHitPositionInsideStrip->Fill((stripCenter.Phi() - hitPosition.Phi())*hitMeanR, stripCenter.Z() - hitPosition.Z());
  121. //double mcMeanR = (stripCenter.Perp() + mcPosition.Perp())/2.;
  122. hMCPositionInsideStrip->Fill((stripCenter.Phi() - mcPosition.Phi())*hitMeanR, stripCenter.Z() - mcPosition.Z());
  123. }
  124. //------------------------------------------------------------------------------------------------------------------------
  125. void MpdTofHitProducerQA::RotationToOriginTest(const TGeoCombiTrans& matrix, const TVector3& mcPosition, const TVector3& hitPosition)
  126. {
  127. // rotate stip to origin LRS
  128. Double_t localHit[3], localPoint[3], master[3] = {mcPosition.X(), mcPosition.Y(), mcPosition.Z()};
  129. matrix.MasterToLocal(master, localPoint);
  130. hPointXZOrigin->Fill(localPoint[2], localPoint[0]);
  131. hPointYZOrigin->Fill(localPoint[2], localPoint[1]);
  132. master[0] = hitPosition.X(); master[1] = hitPosition.Y(); master[2] = hitPosition.Z();
  133. matrix.MasterToLocal(master, localHit);
  134. hHitXZOrigin->Fill(localHit[0], localHit[2]);
  135. hHitYZOrigin->Fill(localHit[1], localHit[2]);
  136. hDevHitXZOrigin->Fill(localHit[0] - localPoint[0], localHit[2] - localPoint[2]); // (Xhit - Xpoint) vs (Zhit - Zpoint)
  137. hDevHitYZOrigin->Fill(localHit[1] - localPoint[1], localHit[2] - localPoint[2]); // (Yhit - Ypoint) vs (Zhit - Zpoint)
  138. }
  139. //------------------------------------------------------------------------------------------------------------------------
  140. void MpdTofHitProducerQA::CentralDetectorTest(Int_t suid, const TVector3& hitPosition)
  141. {
  142. if(MpdTofPoint::GetSector(suid) == 4 && MpdTofPoint::GetDetector(suid) == 11) // select unrotated detector (strips along X axis, perp. to strip along Y axis)
  143. {
  144. hXZCentralDetector->Fill(hitPosition.Z(), hitPosition.X());
  145. hYZCentralDetector->Fill(hitPosition.Z(), hitPosition.Y());
  146. }
  147. // back transform to the central gap LRS
  148. const auto& matrix = MpdTofGeoUtils::Instance()->FindStrip(MpdTofPoint::SetCentralGap(suid))->fMatrix;
  149. Double_t local[3], master[3] = {hitPosition.X(), hitPosition.Y(), hitPosition.Z()};
  150. matrix.MasterToLocal(master, local);
  151. hXZDetector->Fill(local[0], local[1]);
  152. hYZDetector->Fill(local[2], local[1]);
  153. }
  154. //------------------------------------------------------------------------------------------------------------------------
  155. void MpdTofHitProducerQA::FillCrossHitEfficiency(bool fired, Double_t distance, size_t gap, const TVector3& position, const TVector3& smearedPosition)
  156. {
  157. effCrossHit->Fill(fired, distance);
  158. if(fired)
  159. {
  160. double delta, deltaZ, deltaR, deltaPhi;
  161. MpdTof::GetDelta(position, smearedPosition, delta, deltaZ, deltaR, deltaPhi);
  162. hXYSmearedCross->Fill(deltaZ, deltaPhi);
  163. hXYSmearedCross2->Fill(delta, deltaR);
  164. }
  165. }
  166. //------------------------------------------------------------------------------------------------------------------------