LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CFAlgoTimeProf.cxx
Go to the documentation of this file.
1 #ifndef RECOTOOL_CFALGOTIMEPROF_CXX
2 #define RECOTOOL_CFALGOTIMEPROF_CXX
3 
4 #include "CFAlgoTimeProf.h"
5 // ROOT includes
6 #include "TF1.h"
7 #include "TH2F.h"
8 #include "TH1F.h"
9 #include "TPrincipal.h"
10 #include "TVectorD.h"
11 #include "TGraph.h"
12 #include "TMath.h"
13 #include "TH1D.h"
14 #include "TVirtualFitter.h"
16 
17 namespace cmtool {
18 
19  //-------------------------------------------------------
21  //-------------------------------------------------------
22  {
23 
24  }
25 
26  //-------------------------------
28  //-------------------------------
29  {
30  }
31 
32  //-----------------------------
34  //-----------------------------
35  {
36 
37  }
38 
39  //----------------------------------------------------------------------------------------------
40  float CFAlgoTimeProf::Float(const std::vector<const cluster::ClusterParamsAlg*> &clusters)
41  //----------------------------------------------------------------------------------------------
42  {
43  // We now have a vector a clusters.
44 
45  //### need a pointer to the cluster just return -1
46  for(auto const& ptr : clusters) if(!ptr) return -1;
47 
48  std::vector<util::PxHit> hits0;
49  std::vector<util::PxHit> hits1;
50  std::vector<util::PxHit> hits2;
51 
52  // loop over the clusters
53  for(auto const& c : clusters)
54  {
55 // std::cout<<"Size of the xluster vector"<<clusters.size()<<std::endl;
56 // auto Plane = c->Plane();
57 // auto StartPoint = c->GetParams().start_point.t;
58 // auto EndPoint = c->GetParams().end_point.t;
59 // std::cout<<"\t RG Cluster info:\n \t plane: "<<Plane<<std::endl;
60 // std::cout<<"\tStart point: "<<StartPoint<<std::endl;
61 // std::cout<<"\tEnd Point: "<<EndPoint <<std::endl;
62 
63  // Get assosiations for this cluster
64  if(c->Plane() ==0) hits0 = c->GetHitVector();
65  if(c->Plane() ==1) hits1 = c->GetHitVector();
66  if(c->Plane() ==2) hits2 = c->GetHitVector();
67 
68  }// for over the clusters
69 
70 // std::cout<<"Looking for the hits vector size"<<hits0.size()<<","<<hits1.size()<<","<<hits2.size()<<std::endl;
71 // std::cout<<"############# End of loop############# "<<std::endl;
72  // make an integrale over the cluster
73  //bool pl0 = false;
74  //bool pl1 = false;
75  //bool pl2 = false;
76  float tprof01 = -1;
77  float tprof02 = -1;
78  float tprof12 = -1;
79  if(hits0.size()>0)
80  {
81  //pl0 = true;
82  if(hits1.size()>0)
83  {
84  //pl1 = true;
85  //we need to do a profile
86  tprof01 =TProfCompare(hits0,hits1);
87  }// hits1size>0
88  if(hits2.size()>0)
89  {
90  //pl2 = true;
91  //we need to do a profile
92  tprof02 =TProfCompare(hits0,hits2);
93  }// hits2size>0
94  }// hits0size >0
95 
96  if(hits1.size()>0)
97  {
98  //pl1 = true;
99  if(hits2.size()>0)
100  {
101  //pl2 = true;
102  //we need to do a profile
103  tprof12 =TProfCompare(hits1,hits2);
104  }//hits2.size>0
105  }// hits1size>0
106 
107  // This is going to be slow is we are having to re-calutlate this ever time. For now it will have to do
108 
109  // std::cout<< " \t summary of timeprof Planes that are accepted :" <<pl0<<" | " <<pl1<<" | " <<pl2<<" |"<<std::endl;
110  std::vector<float> tprofmatches;
111 // std::cout<< " \t Value of timeprof(01,02,12) :" <<tprof01<<" | " <<tprof02<<" | " <<tprof12<<" |"<<std::endl;
112  tprofmatches.push_back(tprof01);
113  tprofmatches.push_back(tprof02);
114  tprofmatches.push_back(tprof12);
115 
116  float matchscore=0;
117  float avgcounter=0;
118 // std::cout<<"SIZE of trpfmoatch"<< tprofmatches.size()<<std::endl;
119  for( unsigned int a=0;a<tprofmatches.size();a++)
120  {
121  if(tprofmatches[a]==-1) continue;
122  else {
123  matchscore +=tprofmatches[a];
124  avgcounter +=1;
125  }// end of else
126  }//for over the tprofmatchs
127  if(avgcounter!=0){
128 // std::cout << " Match Score pree "<< matchscore<<std::endl;
129 // std::cout<< " Counter "<< avgcounter;
130  matchscore /= avgcounter;
131 // std::cout << " Match Score "<< matchscore<<std::endl;
132  }
133  else{
134 // std::cout << " Match Score "<< -1<<std::endl;
135  return -1;
136  }
137  return matchscore;
138 
139 
140 
141 
142  //if(clusters.size()) return 1.;
143  //else return -1.;
144  }
145 
146 // Making a function to do the profile test
147  float CFAlgoTimeProf::TProfCompare(std::vector<util::PxHit> hita ,std::vector<util::PxHit> hitb)
148  {
150  const detinfo::DetectorProperties* detp = lar::providerFrom<detinfo::DetectorPropertiesService>();
151 // int nts = larutil::DetectorProperties::GetME()->NumberTimeSamples()*larutil::GeometryUtilities::GetME()->TimeToCm();
152  // Where is this?
153  //int nplanes = geom->Nplanes();
154  int nplanes = 3;
155  double ks = 0.0;
156  std::vector< std::vector<TH1D*> > signals(nplanes);
157  std::vector< std::vector<TH1D*> > pulses(nplanes);
158 
159  double time_diff = ( detp->GetXTicksOffset((int)(hita.at(0).plane),0,0) -
160  detp->GetXTicksOffset((int)(hitb.at(0).plane),0,0) ) * geou.TimeToCm();
161 
162  // First go look for the min & max of hits
163  double min_time = detp->NumberTimeSamples() * geou.TimeToCm();
164  double max_time = 0;
165  for(auto const& h : hita) {
166  if(h.t > max_time) max_time = h.t;
167  if(h.t < min_time) min_time = h.t;
168  }
169  for(auto const& h : hitb) {
170  if( (h.t + time_diff) > max_time ) max_time = h.t + time_diff;
171  if( (h.t + time_diff) < min_time ) min_time = h.t + time_diff;
172  }
173 
174  TH1D histo_a("ha", "", 200, min_time-1, max_time+1);
175  TH1D histo_b("hb", "", 200, min_time-1, max_time+1);
176  TH1D histo_inta("hinta", "", 200, min_time-1, max_time+1);
177  TH1D histo_intb("hintb", "", 200, min_time-1, max_time+1);
178 
179  // First loop over hits in A and make the hist
180  // in this case let's just use plane 0,1
181  for( auto const& ha : hita){
182  double time = ha.t;
183  //time -= larutil::DetectorProperties::GetME()->GetXTicksOffset(ha.plane)*larutil::GeometryUtilities::GetME()->TimeToCm();
184  double charge = ha.charge;
185 
186  int bin = histo_a.FindBin(time);
187  histo_a.SetBinContent(bin,histo_a.GetBinContent(bin)+charge);
188  for (int j = bin; j<=histo_a.GetNbinsX(); ++j){
189  histo_inta.SetBinContent(j,histo_inta.GetBinContent(j)+charge);
190  }
191  }
192  if (histo_inta.Integral()) histo_inta.Scale(1./histo_inta.GetBinContent(histo_inta.GetNbinsX()));
193  for( auto const& hb : hitb){
194  double time = hb.t + time_diff;
195  //time -= larutil::DetectorProperties::GetME()->GetXTicksOffset(hb.plane)*larutil::GeometryUtilities::GetME()->TimeToCm();
196  double charge = hb.charge;
197  int bin = histo_b.FindBin(time);
198  histo_b.SetBinContent(bin,histo_b.GetBinContent(bin)+charge);
199  for (int j = bin; j<=histo_b.GetNbinsX(); ++j){
200  histo_intb.SetBinContent(j,histo_intb.GetBinContent(j)+charge);
201  }
202  }
203 
204 /*
205  std::cout
206  << "siga: "<< histo_a.GetEntries() << std::endl
207  << "sigb: "<< histo_b.GetEntries() << std::endl
208  << "siginta: "<<histo_inta.GetEntries() << std::endl
209  << "sigintb: "<<histo_intb.GetEntries() << std::endl
210  << std::endl;
211 */
212 
213  if (histo_intb.Integral()) histo_intb.Scale(1./histo_intb.GetBinContent(histo_intb.GetNbinsX()));
214  ks = histo_inta.KolmogorovTest(&histo_intb);
215 
216  std::cout<<ks<<std::endl;
217  return ks;
218  }
219 
220  //------------------------------
222  //------------------------------
223  {
224 
225  }
226 
227 }
228 #endif
Double_t TimeToCm() const
virtual ~CFAlgoTimeProf()
Default destructor.
virtual float Float(const std::vector< const cluster::ClusterParamsAlg * > &clusters)
CFAlgoTimeProf()
Default constructor.
virtual unsigned int NumberTimeSamples() const =0
float bin[41]
Definition: plottest35.C:14
virtual void Reset()
Function to reset the algorithm instance, called together with manager&#39;s Reset()
Class def header for a class CFAlgoTimeProf.
float TProfCompare(std::vector< util::PxHit > hita, std::vector< util::PxHit > hitb)
virtual double GetXTicksOffset(int p, int t, int c) const =0