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