star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StiHifyHistContainer.cxx
Go to the documentation of this file.
1 #include <cmath>
2 #include <boost/algorithm/string/replace.hpp>
3 
4 #include "TVector3.h"
5 
8 
9 
10 StiHifyHistContainer::StiHifyHistContainer(const StiHifyPrgOptions& prgOpts, const char* name, TDirectory* motherDir, Option_t* option) :
11  tvx::HistContainer(name, motherDir, option),
12  fPrgOptions(prgOpts),
13  hDiffProjToFitPositionWRTHit(nullptr),
14  hDiffProjToFitError(nullptr),
15  hDist2AcceptedHit(nullptr),
16  hDist2ClosestHit(nullptr),
17  hPullClosestHit1D(nullptr),
18  hPullClosestHit2D(nullptr),
19  hPullCandidateHits2D(nullptr),
20  hChi2CandidateHits(nullptr),
21  hCountCandidateHits(nullptr),
22  hActiveLayerCounts(nullptr),
23  hProjErrorMag(nullptr)
24 {
25  const double suggestBinWidth = 1; // desired bin width in cm
26 
27  const double z_max = fPrgOptions.GetHistZMax();
28  const double z_min = fPrgOptions.GetHistZMin();
29  const double y_max = fPrgOptions.GetHistYMax();
30  const double y_min = fPrgOptions.GetHistYMin();
31 
32  int n_z_bins = ceil( (z_max - z_min) / suggestBinWidth );
33  int n_y_bins = ceil( (y_max - y_min) / suggestBinWidth );
34 
35  n_z_bins = ( n_z_bins <= 10 ? 10 : (n_z_bins > 20 ? 20 : n_z_bins) );
36  n_y_bins = ( n_y_bins <= 10 ? 10 : (n_y_bins > 20 ? 20 : n_y_bins) );
37 
38  this->cd();
39 
40  hDiffProjToFitPositionWRTHit = new TH1I("hDiffProjToFitPositionWRTHit", " ; Diff. (Projection - Final) Position w.r.t. Hit, cm; Num. of Track Nodes; ", 50, -0.5, 0.5);
41  hDiffProjToFitPositionWRTHit->SetOption("XY hist");
43 
44  hDiffProjToFitError = new TH2I("hDiffProjToFitError", " ; Diff. (Projection - Final) Error_z, cm; Diff. Error_y, cm; Num. of Track Nodes; ", 50, 0, 0.25, 50, 0, 0.25);
45  hDiffProjToFitError->SetOption("colz");
47 
48  hDist2AcceptedHit = new TH1I("hDist2AcceptedHit", " ; Closest to Accepted Hits: Distance R, cm; Num. of Track Nodes; ", 100, 0, 1);
49  hDist2AcceptedHit->SetOption("XY hist");
50  Add(hDist2AcceptedHit);
51 
52  hDist2ClosestHit = new TH1I("hDist2ClosestHit", " ; Closest to Accepted Hits: Distance R, cm; Num. of Track Nodes; ", 100, 0, 1);
53  hDist2ClosestHit->SetOption("XY hist");
54  Add(hDist2ClosestHit);
55 
56  hPullClosestHit1D = new TH1I("hPullClosestHit1D", " ; Track Proj. to Closest Hit Pull Dist.: Distance R, #sigma-units; Num. of Track Nodes; ", 100, 0, 10);
57  Add(hPullClosestHit1D);
58 
59  hPullClosestHit2D = new TH2I("hPullClosestHit2D", " ; Track Proj. to Closest Hit Pull Dist.: Local Z, #sigma-units; Local Y, #sigma-units; Num. of Track Nodes", 50, -6, 6, 50, -6, 6);
60  hPullClosestHit2D->SetOption("colz");
61  Add(hPullClosestHit2D);
62 
63  hPullCandidateHits2D = new TH2I("hPullCandidateHits2D", " ; Track Proj. to Candidate Hit Pull Dist.: Local Z, #sigma-units; Local Y, #sigma-units; Num. of Track Nodes", 50, -6, 6, 50, -6, 6);
64  hPullCandidateHits2D->SetOption("colz");
66 
67  hChi2CandidateHits = new TH1I("hChi2CandidateHits", " ; Track Proj. to Candidate Hit: #chi^{2}; Num. of Track Nodes", 100, 0, 20);
68  Add(hChi2CandidateHits);
69 
70  hCountCandidateHits = new TH1I("hCountCandidateHits", " ; Num. of Candidate Hits; Num. of Track Nodes", 20, 0, 20);
72 
73  hActiveLayerCounts = new TH2F("hActiveLayerCounts", " ; Track Local Z, cm; Local Y, cm; Num. of Track Nodes", n_z_bins, z_min, z_max, n_y_bins, y_min, y_max);
74  hActiveLayerCounts->SetOption("colz");
75  Add(hActiveLayerCounts);
76 
77  hProjErrorMag = new TH1I("hProjErrorMag", "Projection Error; Projection Error Mag",200,0.,1.0);
78  Add(hProjErrorMag);
79 }
80 
81 
82 void StiHifyHistContainer::FillHists(const StiHifyEvent &event, StiNodeHitStatus hitStatus, bool onlyNodesWithCandidates)
83 {
84  for (const auto& kalmTrack : event.GetTStiKalmanTracks())
85  {
86  for (const auto& trkNode : kalmTrack.GetNodes())
87  {
88  // Ignore nodes with 0 candidate hits when requested by user
89  if ( onlyNodesWithCandidates && !trkNode.GetCandidateProxyHits().size() )
90  continue;
91 
92  switch (hitStatus)
93  {
95  FillHists(trkNode);
96  break;
98  FillHistsHitsAccepted(trkNode);
99  break;
101  FillHistsHitsRejected(trkNode);
102  break;
103  default:
104  Error("FillHists", "Internal type of Sti hit assigned to this node "
105  "is not specified or implemented. Histograms won't be filled");
106  break;
107  }
108  }
109  }
110 }
111 
112 
117 {
118  this->cd();
119 
120  Add( hPullCandidateHits2D->ProjectionX() );
121  Add( hPullCandidateHits2D->ProjectionY() );
122 
123  Add( hActiveLayerCounts->ProjectionX() );
124  Add( hActiveLayerCounts->ProjectionY() );
125 }
126 
127 
129 {
130  if (trkNode.GetVolumeName().empty() || !trkNode.IsInsideVolume())
131  return;
132 
133  if ( !fPrgOptions.MatchedVolName(trkNode.GetVolumeName()) )
134  return;
135 
136  // Start filling histograms
138  hDiffProjToFitError->Fill( trkNode.CalcDiffProjToFitError().Z(), trkNode.CalcDiffProjToFitError().Y() );
139  hDist2AcceptedHit->Fill( trkNode.CalcDistanceToHit() );
140  hDist2ClosestHit->Fill( trkNode.CalcDistanceToClosestHit() );
141 
142  hPullClosestHit1D->Fill(trkNode.CalcDistanceToClosestHit() < 0 ? -1 : (trkNode.CalcDistanceToClosestHit()/trkNode.GetProjError().Mag()) );
143 
144  // Add by ZWM
145  hProjErrorMag->Fill( trkNode.GetProjError().Mag() );
146 
147  const std::set<TStiHitProxy>& hitCandidates = trkNode.GetCandidateProxyHits();
148 
149  hCountCandidateHits->Fill(hitCandidates.size());
150 
151  // Consider the first candidate hit only. This histogram is used in hit
152  // efficiency calculation
153  bool foundClosestCandidate = false;
154 
155  for (const auto& hitCandidate : hitCandidates)
156  {
157  TVector3 pull = trkNode.CalcPullToHit( *hitCandidate.GetTStiHit() );
158 
159  hPullCandidateHits2D->Fill(pull.Z(), pull.Y());
160  hChi2CandidateHits->Fill(hitCandidate.GetChi2());
161 
162  // Choose the first (i.e. the closest) candidate hit
163  if (hitCandidate.GetDistanceToNode() >= 0 && !foundClosestCandidate)
164  {
165  hPullClosestHit2D->Fill(pull.Z(), pull.Y());
166  foundClosestCandidate = true;
167  }
168  }
169 
170  hActiveLayerCounts->Fill(trkNode.GetPositionLocal().Z(), trkNode.GetPositionLocal().Y());
171 
172  // Fill individual histograms for each volume matching the regex only when
173  // requested by the user
175  {
176  std::string histName("hActiveLayerCounts_" + boost::replace_all_copy<string>(trkNode.GetVolumeName(), "/", "__"));
177 
178  TH1* hActiveLayerCounts_det = h(histName);
179 
180  if (!hActiveLayerCounts_det) {
181  this->cd();
182  hActiveLayerCounts_det = static_cast<TH1*>(hActiveLayerCounts->Clone());
183  hActiveLayerCounts_det->SetName(histName.c_str());
184  hActiveLayerCounts_det->SetOption("colz");
185  Add(hActiveLayerCounts_det);
186  }
187 
188  hActiveLayerCounts_det->Fill( trkNode.GetPositionLocal().Z(), trkNode.GetPositionLocal().Y() );
189  }
190 }
191 
192 
194 {
195  if (!trkNode.GetHit())
196  return;
197 
198  FillHists(trkNode);
199 }
200 
201 
203 {
204  if (trkNode.GetHit())
205  return;
206 
207  FillHists(trkNode);
208 }
double GetHistYMin() const
const std::set< TStiHitProxy > & GetCandidateProxyHits() const
double GetHistZMin() const
double GetHistYMax() const
TVector3 CalcPullToHit(const TStiHit &hit) const
void FillHistsHitsAccepted(const TStiKalmanTrackNode &trkNode)
Processes and controls user options provided in the command line.
std::string GetVolumeName() const
const TStiHit * GetHit() const
TVector3 CalcDiffProjToFitError() const
double CalcDistanceToHit() const
bool SplitHistsByVolume() const
void FillHistsHitsRejected(const TStiKalmanTrackNode &trkNode)
void FillHists(const StiHifyEvent &event, StiNodeHitStatus hitStatus=StiNodeHitStatus::Any, bool onlyNodesWithCandidates=false)
const TVector3 & GetPositionLocal() const
const StiHifyPrgOptions & fPrgOptions
Command line arguments and options requested by the user.
bool MatchedVolName(const std::string &volName) const
Note that the function returns true when the internal list of regex'es formed by the user specified o...
StiNodeHitStatus
StiHifyHistContainer(const StiHifyPrgOptions &prgOpts, const char *name, TDirectory *motherDir=0, Option_t *option="")
virtual void FillDerivedHists()
Creates X and Y projections from filled 2D histograms.
const std::vector< TStiKalmanTrack > & GetTStiKalmanTracks() const
Definition: TStiEvent.h:38
double CalcDistanceToClosestHit() const
double CalcDiffProjToFitPositionWRTHit() const
double GetHistZMax() const
bool IsInsideVolume() const
const TVector3 & GetProjError() const