All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlashHypothesisComparison.cxx
Go to the documentation of this file.
1 /*!
2  * Title: FlashHypothesisComparison Class
3  * Author: Wes Ketchum (wketchum@lanl.gov)
4  *
5  * Description:
6  * Class for comparing a flash hypothesis to MC truth (via SimPhotonCounter).
7  * Needs a flash hypothesis and a SimPhotonCounter object as input.
8  * Outputs a Tree with relevent info.
9  */
10 
12 
16 
17 #include "TTree.h"
18 #include "TH1F.h"
19 
20 #include <iostream>
21 
23  TH1F* h_h_p, TH1F* h_s_p, TH1F* h_c_p,
24  TH1F* h_h_l, TH1F* h_s_l, TH1F* h_c_l,
25  TH1F* h_h_t, TH1F* h_s_t, TH1F* h_c_t,
26  const unsigned int n_opdet,
27  bool fill)
28 {
29  fTree = tree;
30  fFillTree = fill;
31  fTree->SetName("ctree");
32 
33  fTree->Branch("run",&fRun,"run/i");
34  fTree->Branch("event",&fEvent,"event/i");
35 
36  fHypHist_p = h_h_p;
37  fSimHist_p = h_s_p;
38  fCompareHist_p = h_c_p;
39 
40  fHypHist_p->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
41  fSimHist_p->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
42  fCompareHist_p->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
43 
44  fHypHist_p->SetNameTitle("hHypHist_p","Hypothesis (Prompt);Opdet;PEs");
45  fSimHist_p->SetNameTitle("hSimHist_p","SimPhoton (Prompt);Opdet;PEs");
46  fCompareHist_p->SetNameTitle("hCompareHist_p","Comparison (Hyp - Sim) (Prompt);Opdet;PEs");
47 
48  fTree->Branch("hyp_PEs_p",&fHypPEs_p,"hyp_PEs_p/F");
49  fTree->Branch("hyp_PEsError_p",&fHypPEsError_p,"hyp_PEsError_p/F");
50  fTree->Branch("sim_PEs_p",&fSimPEs_p,"sim_PEs_p/F");
51 
52  fTree->Branch("hyp_Y_p",&fHypY_p,"hyp_Y_p/F");
53  fTree->Branch("sim_Y_p",&fSimY_p,"sim_Y_p/F");
54 
55  fTree->Branch("hyp_RMSY_p",&fHypRMSY_p,"hyp_RMSY_p/F");
56  fTree->Branch("sim_RMSY_p",&fSimRMSY_p,"sim_RMSY_p/F");
57 
58  fTree->Branch("hyp_Z_p",&fHypZ_p,"hyp_Z_p/F");
59  fTree->Branch("sim_Z_p",&fSimZ_p,"sim_Z_p/F");
60 
61  fTree->Branch("hyp_RMSZ_p",&fHypRMSZ_p,"hyp_RMSZ_p/F");
62  fTree->Branch("sim_RMSZ_p",&fSimRMSZ_p,"sim_RMSZ_p/F");
63 
64  fTree->Branch("comp_total_p",&fCompare_p,"comp_total_p/F");
65 
66  fTree->Branch("hHypHist_p",&fHypHist_p);
67  fTree->Branch("hSimHist_p",&fSimHist_p);
68  fTree->Branch("hCompareHist_p",&fCompareHist_p);
69 
70  fHypHist_l = h_h_l;
71  fSimHist_l = h_s_l;
72  fCompareHist_l = h_c_l;
73 
74  fHypHist_l->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
75  fSimHist_l->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
76  fCompareHist_l->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
77 
78  fHypHist_l->SetNameTitle("hHypHist_l","Hypothesis (Late);Opdet;PEs");
79  fSimHist_l->SetNameTitle("hSimHist_l","SimPhoton (Late);Opdet;PEs");
80  fCompareHist_l->SetNameTitle("hCompareHist_l","Comparison (Hyp - Sim) (Late);Opdet;PEs");
81 
82  fTree->Branch("hyp_PEs_l",&fHypPEs_l,"hyp_PEs_l/F");
83  fTree->Branch("hyp_PEsError_l",&fHypPEsError_l,"hyp_PEsError_l/F");
84  fTree->Branch("sim_PEs_l",&fSimPEs_l,"sim_PEs_l/F");
85 
86  fTree->Branch("hyp_Y_l",&fHypY_l,"hyp_Y_l/F");
87  fTree->Branch("sim_Y_l",&fSimY_l,"sim_Y_l/F");
88 
89  fTree->Branch("hyp_RMSY_l",&fHypRMSY_l,"hyp_RMSY_l/F");
90  fTree->Branch("sim_RMSY_l",&fSimRMSY_l,"sim_RMSY_l/F");
91 
92  fTree->Branch("hyp_Z_l",&fHypZ_l,"hyp_Z_l/F");
93  fTree->Branch("sim_Z_l",&fSimZ_l,"sim_Z_l/F");
94 
95  fTree->Branch("hyp_RMSZ_l",&fHypRMSZ_l,"hyp_RMSZ_l/F");
96  fTree->Branch("sim_RMSZ_l",&fSimRMSZ_l,"sim_RMSZ_l/F");
97 
98  fTree->Branch("comp_total_l",&fCompare_l,"comp_total_l/F");
99 
100  fTree->Branch("hHypHist_l",&fHypHist_l);
101  fTree->Branch("hSimHist_l",&fSimHist_l);
102  fTree->Branch("hCompareHist_l",&fCompareHist_l);
103 
104  fHypHist_t = h_h_t;
105  fSimHist_t = h_s_t;
106  fCompareHist_t = h_c_t;
107 
108  fHypHist_t->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
109  fSimHist_t->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
110  fCompareHist_t->SetBins(n_opdet,-0.5,(float)n_opdet - 0.5);
111 
112  fHypHist_t->SetNameTitle("hHypHist_t","Hypothesis (Total);Opdet;PEs");
113  fSimHist_t->SetNameTitle("hSimHist_t","SimPhoton (Total);Opdet;PEs");
114  fCompareHist_t->SetNameTitle("hCompareHist_t","Comparison (Hyp - Sim) (Total);Opdet;PEs");
115 
116  fTree->Branch("hyp_PEs_t",&fHypPEs_t,"hyp_PEs_t/F");
117  fTree->Branch("hyp_PEsError_t",&fHypPEsError_t,"hyp_PEsError_t/F");
118  fTree->Branch("sim_PEs_t",&fSimPEs_t,"sim_PEs_t/F");
119 
120  fTree->Branch("hyp_Y_t",&fHypY_t,"hyp_Y_t/F");
121  fTree->Branch("sim_Y_t",&fSimY_t,"sim_Y_t/F");
122 
123  fTree->Branch("hyp_RMSY_t",&fHypRMSY_t,"hyp_RMSY_t/F");
124  fTree->Branch("sim_RMSY_t",&fSimRMSY_t,"sim_RMSY_t/F");
125 
126  fTree->Branch("hyp_Z_t",&fHypZ_t,"hyp_Z_t/F");
127  fTree->Branch("sim_Z_t",&fSimZ_t,"sim_Z_t/F");
128 
129  fTree->Branch("hyp_RMSZ_t",&fHypRMSZ_t,"hyp_RMSZ_t/F");
130  fTree->Branch("sim_RMSZ_t",&fSimRMSZ_t,"sim_RMSZ_t/F");
131 
132  fTree->Branch("comp_total_t",&fCompare_t,"comp_total_t/F");
133 
134  fTree->Branch("hHypHist_t",&fHypHist_t);
135  fTree->Branch("hSimHist_t",&fSimHist_t);
136  fTree->Branch("hCompareHist_t",&fCompareHist_t);
137 }
138 
140  const unsigned int event,
141  const FlashHypothesisCollection& fhc,
142  const SimPhotonCounter& spc,
143  const std::vector<float>& posY,
144  const std::vector<float>& posZ)
145 {
146  if(fhc.GetVectorSize() != (unsigned int)fHypHist_p->GetNbinsX() ||
147  fhc.GetVectorSize() != spc.PromptPhotonVector().size() ||
148  fhc.GetVectorSize() != posY.size() ||
149  fhc.GetVectorSize() != posZ.size() ){
150  std::cout << (unsigned int)fHypHist_p->GetNbinsX() << " " << spc.PromptPhotonVector().size() << " " << posY.size() << " " << posZ.size() << std::endl;
151  throw std::runtime_error("ERROR in FlashHypothesisComparison: Mismatch in vector sizes.");
152  }
153  fRun = run;
154  fEvent = event;
155 
156  FillFlashHypothesisInfo(fhc,posY,posZ);
157  FillSimPhotonCounterInfo(spc,posY,posZ);
158  FillComparisonInfo(fhc,spc);
159 
160  if(fFillTree) fTree->Fill();
161 }
162 
164  const std::vector<float>& posY,
165  const std::vector<float>& posZ)
166 {
167  fHypPEs_p = fhc.GetPromptHypothesis().GetTotalPEs();
168  fHypPEsError_p = fhc.GetPromptHypothesis().GetTotalPEsError();
169  fUtil.GetPosition(fhc.GetPromptHypothesis().GetHypothesisVector(),posY,fHypY_p,fHypRMSY_p);
170  fUtil.GetPosition(fhc.GetPromptHypothesis().GetHypothesisVector(),posZ,fHypZ_p,fHypRMSZ_p);
171 
172  for(size_t i=0; i<fhc.GetVectorSize(); i++)
173  fHypHist_p->SetBinContent(i+1,fhc.GetPromptHypothesis().GetHypothesis(i));
174 
175  fHypPEs_l = fhc.GetLateHypothesis().GetTotalPEs();
176  fHypPEsError_l = fhc.GetLateHypothesis().GetTotalPEsError();
177  fUtil.GetPosition(fhc.GetLateHypothesis().GetHypothesisVector(),posY,fHypY_l,fHypRMSY_l);
178  fUtil.GetPosition(fhc.GetLateHypothesis().GetHypothesisVector(),posZ,fHypZ_l,fHypRMSZ_l);
179 
180  for(size_t i=0; i<fhc.GetVectorSize(); i++)
181  fHypHist_l->SetBinContent(i+1,fhc.GetLateHypothesis().GetHypothesis(i));
182 
183  fHypPEs_t = fhc.GetTotalHypothesis().GetTotalPEs();
184  fHypPEsError_t = fhc.GetTotalHypothesis().GetTotalPEsError();
185  fUtil.GetPosition(fhc.GetTotalHypothesis().GetHypothesisVector(),posY,fHypY_t,fHypRMSY_t);
186  fUtil.GetPosition(fhc.GetTotalHypothesis().GetHypothesisVector(),posZ,fHypZ_t,fHypRMSZ_t);
187 
188  for(size_t i=0; i<fhc.GetVectorSize(); i++)
189  fHypHist_t->SetBinContent(i+1,fhc.GetLateHypothesis().GetHypothesis(i));
190 }
191 
193  const std::vector<float>& posY,
194  const std::vector<float>& posZ)
195 {
196  fSimPEs_p = spc.PromptPhotonTotal();
197  fUtil.GetPosition(spc.PromptPhotonVector(),posY,fSimY_p,fSimRMSY_p);
198  fUtil.GetPosition(spc.PromptPhotonVector(),posZ,fSimZ_p,fSimRMSZ_p);
199 
200  for(size_t i=0; i<spc.PromptPhotonVector().size(); i++)
201  fSimHist_p->SetBinContent(i+1,spc.PromptPhotonVector()[i]);
202 
203  fSimPEs_l = spc.LatePhotonTotal();
204  fUtil.GetPosition(spc.LatePhotonVector(),posY,fSimY_l,fSimRMSY_l);
205  fUtil.GetPosition(spc.LatePhotonVector(),posZ,fSimZ_l,fSimRMSZ_l);
206 
207  for(size_t i=0; i<spc.LatePhotonVector().size(); i++)
208  fSimHist_l->SetBinContent(i+1,spc.LatePhotonVector()[i]);
209 
210  fSimPEs_t = fSimPEs_p+fSimPEs_l;
211  fUtil.GetPosition(spc.TotalPhotonVector(),posY,fSimY_t,fSimRMSY_t);
212  fUtil.GetPosition(spc.TotalPhotonVector(),posZ,fSimZ_t,fSimRMSZ_t);
213 
214  for(size_t i=0; i<spc.GetVectorSize(); i++)
215  fSimHist_t->SetBinContent(i+1,spc.TotalPhotonVector(i));
216 
217 }
218 
220  const SimPhotonCounter& spc)
221 {
222  std::vector<float> result_p,result_l,result_t;
223  fCompare_p = fUtil.CompareByError(fhc.GetPromptHypothesis(),spc.PromptPhotonVector(),result_p);
224  fCompare_l = fUtil.CompareByError(fhc.GetLateHypothesis(),spc.LatePhotonVector(),result_l);
225  fCompare_t = fUtil.CompareByError(fhc.GetTotalHypothesis(),spc.TotalPhotonVector(),result_t);
226 
227  for(size_t i=0; i<result_p.size(); i++){
228  fCompareHist_p->SetBinContent(i+1,result_p[i]);
229  fCompareHist_l->SetBinContent(i+1,result_l[i]);
230  fCompareHist_t->SetBinContent(i+1,result_t[i]);
231  }
232 
233 }
Class def header for a class FlashHypothesis.
void FillSimPhotonCounterInfo(const SimPhotonCounter &, const std::vector< float > &, const std::vector< float > &)
float GetTotalPEsError() const
const FlashHypothesis & GetLateHypothesis() const
const std::vector< float > & PromptPhotonVector() const
void FillComparisonInfo(const FlashHypothesisCollection &, const SimPhotonCounter &)
float GetTotalPEs() const
std::vector< float > TotalPhotonVector() const
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
const FlashHypothesis & GetPromptHypothesis() const
void SetOutputObjects(TTree *, TH1F *, TH1F *, TH1F *, TH1F *, TH1F *, TH1F *, TH1F *, TH1F *, TH1F *, const unsigned int, bool fill=true)
const std::vector< float > & LatePhotonVector() const
float const & GetHypothesis(size_t i_opdet) const
float PromptPhotonTotal() const
void RunComparison(const unsigned int, const unsigned int, const FlashHypothesisCollection &, const SimPhotonCounter &, const std::vector< float > &, const std::vector< float > &)
const FlashHypothesis & GetTotalHypothesis() const
void FillFlashHypothesisInfo(const FlashHypothesisCollection &, const std::vector< float > &, const std::vector< float > &)
size_t GetVectorSize() const
std::vector< float > const & GetHypothesisVector() const
BEGIN_PROLOG could also be cout
float LatePhotonTotal() const