star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StiScanHistContainer.cxx
Go to the documentation of this file.
1 #include <cmath>
2 
3 #include "TH2S.h"
4 #include "TProfile2D.h"
5 #include "TVector3.h"
6 
9 
10 
11 StiScanHistContainer::StiScanHistContainer(StiScanPrgOptions& prgOpts, const char* name, TDirectory* motherDir, bool doProjection, Option_t* option) :
12  tvx::HistContainer(name, motherDir, option),
13  fPrgOptions(prgOpts),
14  mNodeZMin(-250), mNodeZMax(250),
15  mNodeRMin(0), mNodeRMax(30),
16  mDoProjection(doProjection),
17  hNStepsVsPhiVsRVsZ(nullptr),
18  hELossVsPhiVsRVsZ(nullptr),
19  hELossVsXVsYVsZ(nullptr),
20  hDensityVsPhiVsRVsZ(nullptr),
21  hRelRadLengthVsPhiVsRVsZ(nullptr)
22 {
23  InitRange();
24  BookHists();
25 }
26 
27 
30 {
34  }
35 
39  }
40 }
41 
42 
44 {
45  const double minZBinWidth = 1; // desired bin width in cm
46  const double minRBinWidth = 0.2; // desired bin width in cm
47 
48  int nZBins = ceil( (mNodeZMax - mNodeZMin) / minZBinWidth );
49  int nRBins = ceil( (mNodeRMax - mNodeRMin) / minRBinWidth );
50 
51  nRBins = nRBins > 1000 ? 1000 : nRBins;
52 
53  int nXYBins = nRBins*floor(mNodeRMax/(mNodeRMax - mNodeRMin));
54 
55  nZBins = nZBins > 500 ? 500 : nZBins;
56 
57  this->cd();
58 
59  TH1* h;
60 
61  h = new TH2S("hTrackCountVsEtaVsPhi", " ; #eta; #phi, rad; Num. of Tracks", 50, -2, 2, 120, -M_PI, M_PI);
62  h->SetOption("colz");
63  Add(h);
64 
65  h = new TH2S("hTrackCountVsZVsPhi", " ; z, cm; #phi, rad; Num. of Tracks", nZBins, mNodeZMin, mNodeZMax, 120, -M_PI, M_PI);
66  h->SetOption("colz");
67  Add(h);
68 
69  h = new TProfile2D("hELossVsEtaVsPhi_trk", " ; Track #eta; Track #phi, rad; Energy Losses in Select Volumes, keV", 50, -2, 2, 120, -M_PI, M_PI);
70  h->SetOption("colz");
71  Add(h);
72 
73  h = new TProfile2D("hELossVsEtaVsPhi", " ; #eta; #phi, rad; Energy Losses in Select Volumes, keV", 50, -2, 2, 120, -M_PI, M_PI);
74  h->SetOption("colz");
75  Add(h);
76 
77  h = new TProfile2D("hELossVsZVsPhi", " ; z, cm; #phi, rad; Energy Losses in Select Volumes, keV", nZBins, mNodeZMin, mNodeZMax, 120, -M_PI, M_PI);
78  h->SetOption("colz");
79  Add(h);
80 
81  h = new TProfile2D("hELossVsZVsR", " ; z, cm; r, cm; Energy Losses in Select Volumes, keV", nZBins, mNodeZMin, mNodeZMax, nRBins, mNodeRMin, mNodeRMax);
82  h->SetOption("colz");
83  Add(h);
84 
85  h = new Profile2D("hELossVsPhiVsR", " ; #phi, rad; r, cm; Energy Losses in Select Volumes, keV", 120, -M_PI, M_PI, nRBins, mNodeRMin, mNodeRMax, "colz");
86  Add(h);
87 
88  hNStepsVsPhiVsRVsZ = new Profile3D("hNStepsVsPhiVsRVsZ", "Num. of Steps per Track ; #phi, rad; r, cm; z, cm", 120, -M_PI, M_PI, nRBins, mNodeRMin, mNodeRMax, nZBins, mNodeZMin, mNodeZMax);
89  Add(hNStepsVsPhiVsRVsZ);
90 
91  hELossVsPhiVsRVsZ = new Profile3D("hELossVsPhiVsRVsZ", "Energy Losses in Select Volumes, keV ; #phi, rad; r, cm; z, cm", 120, -M_PI, M_PI, nRBins, mNodeRMin, mNodeRMax, nZBins, mNodeZMin, mNodeZMax);
92  Add(hELossVsPhiVsRVsZ);
93 
94  hELossVsXVsYVsZ = new Profile3D("hELossVsXVsYVsZ", "Energy Losses in Select Volumes, keV ; x, cm; y, cm; z, cm", nXYBins, -mNodeRMax, mNodeRMax, nXYBins, -mNodeRMax, mNodeRMax, nZBins, mNodeZMin, mNodeZMax);
95  Add(hELossVsXVsYVsZ);
96 
97  hDensityVsPhiVsRVsZ = new Profile3D("hDensityVsPhiVsRVsZ", "Material Density, g/cm^{3}; #phi, rad; r, cm; z, cm", 120, -M_PI, M_PI, nRBins, mNodeRMin, mNodeRMax, nZBins, mNodeZMin, mNodeZMax);
99 
100  hRelRadLengthVsPhiVsRVsZ = new Profile3D("hRelRadLengthVsPhiVsRVsZ", "Rel. Radiation Length, %; #phi, rad; r, cm; z, cm", 120, -M_PI, M_PI, nRBins, mNodeRMin, mNodeRMax, nZBins, mNodeZMin, mNodeZMax);
102 }
103 
104 
105 void StiScanHistContainer::FillHists(const StiScanEvent &eventT, const std::set<std::string> *volumeList)
106 {
107  for (const auto& kalmTrack : eventT.GetTStiKalmanTracks())
108  {
109  FillHists(kalmTrack, volumeList);
110  }
111 }
112 
113 
114 void StiScanHistContainer::FillHists(const TGeaEvent &eventG, const std::set<std::string> *volumeList)
115 {
116  TIter iGeaTrack(eventG.tracks);
117 
118  while (TGeaTrack* trackG = static_cast<TGeaTrack*>(iGeaTrack()) )
119  {
120  FillHists(*trackG, volumeList);
121  }
122 }
123 
124 
126 {
127  this->cd();
128 
129  TProfile2D* profile2D;
130 
131  profile2D = hNStepsVsPhiVsRVsZ->Project3DProfile("yx");
132  profile2D->SetOption("colz");
133  Add(profile2D);
134  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
135 
136  profile2D = hNStepsVsPhiVsRVsZ->Project3DProfile("yz");
137  profile2D->SetOption("colz");
138  Add(profile2D);
139  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
140 
141  profile2D = hNStepsVsPhiVsRVsZ->Project3DProfile("xz");
142  profile2D->SetOption("colz");
143  Add(profile2D);
144  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
145 
146 
147  profile2D = hELossVsPhiVsRVsZ->Project3DProfile("yx");
148  profile2D->SetOption("colz XZ");
149  Add(profile2D);
150  TH1* h = mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX();
151  h->SetOption("XY");
152  Add(h);
153 
154  profile2D = hELossVsPhiVsRVsZ->Project3DProfile("yz");
155  profile2D->SetOption("colz XZ");
156  Add(profile2D);
157  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
158 
159  profile2D = hELossVsPhiVsRVsZ->Project3DProfile("xz");
160  profile2D->SetOption("colz XZ");
161  Add(profile2D);
162  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
163 
164 
165  profile2D = hELossVsXVsYVsZ->Project3DProfile("yx");
166  profile2D->SetOption("colz XZ");
167  Add(profile2D);
168 
169 
170  // For 1D density profiles we always calculate the average density
171  profile2D = hDensityVsPhiVsRVsZ->Project3DProfile("yx");
172  profile2D->SetOption("colz");
173  Add(profile2D);
174  h = profile2D->ProfileX();
175  h->SetOption("XY");
176  Add(h);
177 
178  profile2D = hDensityVsPhiVsRVsZ->Project3DProfile("yz");
179  profile2D->SetOption("colz");
180  Add(profile2D);
181  Add(profile2D->ProfileX());
182 
183  profile2D = hDensityVsPhiVsRVsZ->Project3DProfile("xz");
184  profile2D->SetOption("colz");
185  Add(profile2D);
186  Add(profile2D->ProfileX());
187 
188 
189  profile2D = hRelRadLengthVsPhiVsRVsZ->Project3DProfile("yx");
190  profile2D->SetOption("colz");
191  Add(profile2D);
192  h = mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX();
193  h->SetOption("XY");
194  Add(h);
195 
196  profile2D = hRelRadLengthVsPhiVsRVsZ->Project3DProfile("yz");
197  profile2D->SetOption("colz");
198  Add(profile2D);
199  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
200 
201  profile2D = hRelRadLengthVsPhiVsRVsZ->Project3DProfile("xz");
202  profile2D->SetOption("colz");
203  Add(profile2D);
204  Add(mDoProjection ? profile2D->ProjectionX() : profile2D->ProfileX());
205 }
206 
207 
208 void StiScanHistContainer::FillHists(const TStiKalmanTrack &kalmTrack, const std::set<std::string> *volumeList)
209 {
210  // Take the first node with the smallest radius
211  const TStiKalmanTrackNode& dcaNode = kalmTrack.GetDcaNode();
212 
213  h("hTrackCountVsEtaVsPhi")->Fill(dcaNode.GetTrackP().Eta(), dcaNode.GetTrackP().Phi());
214  h("hTrackCountVsZVsPhi")->Fill(dcaNode.GetPosition().Z(), dcaNode.GetTrackP().Phi());
215 
216  for (const auto& kalmNode : kalmTrack.GetNodes())
217  {
218  if (volumeList && volumeList->size() && !kalmNode.MatchedVolName(*volumeList) ) continue;
219 
220  if (kalmNode.GetNodeMaterialDensity() <= 0) continue;
221 
222  hNStepsVsPhiVsRVsZ->FillAsCumulative(kalmNode.GetPosition().Phi(), kalmNode.GetPosition().Perp(), kalmNode.GetPosition().Z(), 1);
223  dynamic_cast<TProfile2D&>( *h("hELossVsEtaVsPhi_trk")).Fill(kalmNode.GetTrackP().Eta(), kalmNode.GetTrackP().Phi(), kalmNode.GetEnergyLosses());
224 
225  dynamic_cast<TProfile2D&>( *h("hELossVsEtaVsPhi")).Fill(kalmNode.GetPosition().Eta(), kalmNode.GetPosition().Phi(), kalmNode.GetEnergyLosses());
226  dynamic_cast<TProfile2D&>( *h("hELossVsZVsPhi") ).Fill(kalmNode.GetPosition().Z(), kalmNode.GetPosition().Phi(), kalmNode.GetEnergyLosses());
227  dynamic_cast<TProfile2D&>( *h("hELossVsZVsR") ).Fill(kalmNode.GetPosition().Z(), kalmNode.GetPosition().Perp(), kalmNode.GetEnergyLosses());
228  dynamic_cast<TProfile2D&>( *h("hELossVsPhiVsR") ).Fill(kalmNode.GetPosition().Phi(), kalmNode.GetPosition().Perp(), kalmNode.GetEnergyLosses());
229  // Record the total energy deposited by this track
230  hELossVsPhiVsRVsZ->FillAsCumulative(kalmNode.GetPosition().Phi(), kalmNode.GetPosition().Perp(), kalmNode.GetPosition().Z(), kalmNode.GetEnergyLosses());
231  hELossVsXVsYVsZ->FillAsCumulative(kalmNode.GetPosition().X(), kalmNode.GetPosition().Y(), kalmNode.GetPosition().Z(), kalmNode.GetEnergyLosses());
232  hDensityVsPhiVsRVsZ->Fill(kalmNode.GetPosition().Phi(), kalmNode.GetPosition().Perp(), kalmNode.GetPosition().Z(), kalmNode.GetNodeMaterialDensity());
233  hRelRadLengthVsPhiVsRVsZ->FillAsCumulative(kalmNode.GetPosition().Phi(), kalmNode.GetPosition().Perp(), kalmNode.GetPosition().Z(), kalmNode.GetNodeRelRadLength());
234  }
235 
240 }
241 
242 
243 void StiScanHistContainer::FillHists(const TGeaTrack &trackG, const std::set<std::string> *volumeList)
244 {
245  TIter iGeaStep(&trackG.steps);
246 
247  while (TGeaStep* stepG = static_cast<TGeaStep*>(iGeaStep()) )
248  {
249  double dEStep = stepG->dEstep * 1e6; // convert GeV to keV
250 
251  TVector3 step_pos(stepG->x, stepG->y, stepG->z);
252 
253  if (volumeList && volumeList->size() && !stepG->MatchedVolName(*volumeList) ) continue;
254 
255  hNStepsVsPhiVsRVsZ->FillAsCumulative(step_pos.Phi(), step_pos.Perp(), step_pos.Z(), 1);
256 
257  dynamic_cast<TProfile2D&>( *h("hELossVsZVsPhi") ).Fill(step_pos.Z(), step_pos.Phi(), dEStep);
258  dynamic_cast<TProfile2D&>( *h("hELossVsZVsR") ).Fill(step_pos.Z(), step_pos.Perp(), dEStep);
259  dynamic_cast<TProfile2D&>( *h("hELossVsPhiVsR") ).Fill(step_pos.Phi(), step_pos.Perp(), dEStep);
260  hELossVsPhiVsRVsZ->FillAsCumulative(step_pos.Phi(), step_pos.Perp(), step_pos.Z(), dEStep);
261  hELossVsXVsYVsZ->FillAsCumulative(step_pos.X(), step_pos.Y(), step_pos.Z(), dEStep);
262  hDensityVsPhiVsRVsZ->Fill(step_pos.Phi(), step_pos.Perp(), step_pos.Z(), stepG->dens);
263  hRelRadLengthVsPhiVsRVsZ->FillAsCumulative(step_pos.Phi(), step_pos.Perp(), step_pos.Z(), stepG->relRadLength);
264  }
265 
270 }
Int_t FillAsCumulative(Double_t x, Double_t y, Double_t z, Double_t t)
Definition: Profile3D.cxx:43
Profile2D * Project3DProfile(Option_t *option) const
Definition: Profile3D.cxx:185
const TVector3 & GetPosition() const
Profile3D * hRelRadLengthVsPhiVsRVsZ
TClonesArray * tracks
Definition: TGeaEvent.h:30
double GetHistZMin() const
double GetHistZMax() const
void ResetBinCumulMode()
Definition: Profile3D.cxx:36
const StiScanPrgOptions & fPrgOptions
Command line arguments and options requested by the user.
const TStiKalmanTrackNode & GetDcaNode() const
double GetHistRMax() const
Processes and controls user options provided in the command line.
const std::set< TStiKalmanTrackNode > & GetNodes() const
const std::vector< TStiKalmanTrack > & GetTStiKalmanTracks() const
Definition: TStiEvent.h:38
TRefArray steps
Definition: TGeaEvent.h:56
double GetHistRMin() const
const TVector3 & GetTrackP() const
void InitRange()
The default limits will be used if user provided values for min >= max.
void FillHists(const StiScanEvent &eventT, const std::set< std::string > *volumeList=0)
bool mDoProjection
If true will create integral projections of 2D profiles instead of creating 1D profiles with bin aver...
StiScanHistContainer(StiScanPrgOptions &prgOpts, const char *name, TDirectory *motherDir=0, bool doProjection=true, Option_t *option="")