43 class NNFastMMTrigger;
53 void NumberOfCellsPerLength(
HitList const &hits,
double tracklength_of_xview,
double tracklength_of_yview,
double &number_of_cells_per_length_xview,
double &number_of_cells_per_length_yview)
const;
54 float Distance(
unsigned const &xcell1,
unsigned const &ycell1,
unsigned const &plane1,
unsigned const &xcell2,
unsigned const &ycell2 ,
unsigned const &plane2)
const;
56 double WeightedCenterCut(
HitList const &hits,
float PX_min,
float PX_max,
float PY_min,
float PY_max,
float CX_min,
float CX_max,
float CY_min,
float CY_max,
double &weighted_off_center_xx,
double &weighted_off_center_xz,
double &weighted_off_center_yy,
double &weighted_off_center_yz)
const;
68 void LinFit(
const std::vector<double>&
x,
const std::vector<double>&
y,
double *fitpar);
90 produces<std::vector<TriggerDecision>>();
106 std::unique_ptr<std::vector<TriggerDecision>>
107 trigger_decisions(
new std::vector<TriggerDecision>);
111 for (
unsigned i = 0;
i!= slices->size(); ++
i) {
121 TX_max = hits.front().TDC().val;
123 TX_min = hits.back().TDC().val;
126 int nb_hits = hits.size();
129 int entry_id = 0, nx = 0, ny = 0;
130 bool PassThrough =
false, Intrusion =
false;
131 double meanADC = 0, stdevADC = 0, sq_sum_ADC = 0;
133 std::vector<double> x_hit, y_hit, zy_hit, zx_hit;
134 for (
auto const hit: hits) {
137 meanADC +=
hit.ADC().val;
138 sq_sum_ADC +=
hit.ADC().val*
hit.ADC().val;
142 x_hit.push_back(
hit.Cell().val);
143 zx_hit.push_back(
hit.Plane().val);
160 else if (!PassThrough) {
161 if (
hit.Cell().val <
_xMin+
_deltx && entry_id != 1) PassThrough =
true;
162 else if (
hit.Cell().val>
_xMax-
_deltx && entry_id != 2) PassThrough =
true;
169 y_hit.push_back(
hit.Cell().val);
170 zy_hit.push_back(
hit.Plane().val);
187 else if (!PassThrough) {
188 if (
hit.Cell().val <
_yMin+
_delty && entry_id != 3) PassThrough =
true;
189 else if (
hit.Cell().val>
_yMax-
_delty && entry_id != 4) PassThrough =
true;
203 else if (!PassThrough) {
204 if (
hit.Plane().val <
_zMin+
_deltz && entry_id != 5) PassThrough=
true;
205 else if (
hit.Plane().val >
_zMax-
_deltz && entry_id != 6) PassThrough=
true;
208 meanADC = meanADC/(nx+ny);
212 if (nx<10 || ny<10)
continue;
215 if (!PassThrough)
continue;
242 LinFit(x_hit, zx_hit, fitpar);
246 LinFit(y_hit, zy_hit, fitpar);
249 double number_of_cells_per_length_xview=0;
250 double number_of_cells_per_length_yview=0;
254 if(
_verbose != 0)
std::cout<<
"number of cells per length xview: "<<number_of_cells_per_length_xview<<
" yview: "<<number_of_cells_per_length_yview<<
std::endl;
255 double stdev_cells_per_plane_xview=0, stdev_cells_per_plane_yview=0;
257 if(
_verbose != 0)
std::cout<<
"stdev cells per plane xview: "<<stdev_cells_per_plane_xview<<
" yview: "<<stdev_cells_per_plane_yview<<
std::endl;
258 double weighted_off_center_xx=0, weighted_off_center_xz=0, weighted_off_center_yy=0, weighted_off_center_yz=0;
259 WeightedCenterCut(hits,
PX_min,
PX_max,
PY_min,
PY_max,
CX_min,
CX_max,
CY_min,
CY_max, weighted_off_center_xx, weighted_off_center_xz, weighted_off_center_yy, weighted_off_center_yz );
263 stdevADC =
std::sqrt( sq_sum_ADC*1.0/(nx+ny) - meanADC*meanADC);
267 float myfloats[] = {(hits.size()/tracklength-0.0206254683435)/94.6383405961,
268 (stdev_cells_per_plane_xview-0.816496580928)/12.9743518339,
269 (stdev_cells_per_plane_yview-0.816496580928)/15.2366123639,
270 (weighted_off_center_yy-0.0)/0.499630220584,
271 (number_of_surface_hits-1.0)/30304.0,
272 (meanADC-239.074074074)/3603.61013645,
273 (stdevADC-8.75437337874)/1912.00668817,
275 (deltaTDC-0.0)/27478.0,
279 std::vector<float>
v (myfloats, myfloats +
sizeof(myfloats) /
sizeof(
float) );
281 for (
auto data_i : v)
288 if(score<0.5)
continue;
299 e.
put(std::move(trigger_decisions));
305 const auto n = x_val.size();
306 const auto x = (std::accumulate(x_val.begin(), x_val.end(), 0.0))/
n;
307 const auto y = (std::accumulate(y_val.begin(), y_val.end(), 0.0))/
n;
308 const auto xx = (std::inner_product(x_val.begin(), x_val.end(), x_val.begin(), 0.0))/
n;
309 const auto yy = (std::inner_product(y_val.begin(), y_val.end(), y_val.begin(), 0.0))/
n;
310 const auto xy = (std::inner_product(x_val.begin(), x_val.end(), y_val.begin(), 0.0))/
n;
312 const auto b = (xy -
x*
y)/(
xx -
x*
x);
313 const auto a =
y -
b*
x;
314 const auto r = (xy - x*
y)/
sqrt((
xx - x*x)*(yy -
y*
y));
321 std::vector<std::vector<int>> x_hits_plane(
PX_max-
PX_min+1,std::vector<int>(0));
322 std::vector<std::vector<int>> y_hits_plane(
PY_max-
PY_min+1,std::vector<int>(0));
323 for (
auto const hit: hits) {
326 x_hits_plane[
hit.Plane().val-
PX_min].push_back(
hit.Cell().val);
330 y_hits_plane[
hit.Plane().val-
PY_min].push_back(
hit.Cell().val);
336 for (
unsigned i=0;
i!=x_hits_plane.size();
i++){
337 std::sort(x_hits_plane[
i].begin(),x_hits_plane[
i].
end());
338 std::vector<int>::iterator
it;
339 it = std::unique (x_hits_plane[
i].begin(),x_hits_plane[
i].
end());
341 x_cells_plane[
i]=x_hits_plane[
i].size();
343 for (
unsigned i=0;
i!=y_hits_plane.size();
i++){
344 std::sort(y_hits_plane[
i].begin(),y_hits_plane[
i].
end());
345 std::vector<int>::iterator
it;
346 it = std::unique (y_hits_plane[
i].begin(),y_hits_plane[
i].
end());
348 y_cells_plane[
i]=y_hits_plane[
i].size();
352 for (
unsigned i=0;
i!=x_cells_plane.size();
i++){
353 sum_of_cells+=x_cells_plane[
i];
355 number_of_cells_per_length_xview=sum_of_cells/tracklength_of_xview;
357 for (
unsigned i=0;
i!=y_cells_plane.size();
i++){
358 sum_of_cells+=y_cells_plane[
i];
360 number_of_cells_per_length_yview=sum_of_cells/tracklength_of_yview;
365 std::vector<std::vector<int>> x_hits_plane(
PX_max-
PX_min+1,std::vector<int>(0));
366 std::vector<std::vector<int>> y_hits_plane(
PY_max-
PY_min+1,std::vector<int>(0));
367 for (
auto const hit: hits) {
370 x_hits_plane[
hit.Plane().val-
PX_min].push_back(
hit.Cell().val);
374 y_hits_plane[
hit.Plane().val-
PY_min].push_back(
hit.Cell().val);
385 for (
unsigned i=0;
i!=x_hits_plane.size();
i++){
386 std::sort(x_hits_plane[
i].begin(),x_hits_plane[
i].
end());
387 std::vector<int>::iterator
it;
388 it = std::unique (x_hits_plane[
i].begin(),x_hits_plane[
i].
end());
390 x_cells_plane[
i]=x_hits_plane[
i].size();
392 for (
unsigned i=0;
i!=y_hits_plane.size();
i++){
393 std::sort(y_hits_plane[
i].begin(),y_hits_plane[
i].
end());
394 std::vector<int>::iterator
it;
395 it = std::unique (y_hits_plane[
i].begin(),y_hits_plane[
i].
end());
397 y_cells_plane[
i]=y_hits_plane[
i].size();
399 sum = std::accumulate(x_cells_plane.begin(),x_cells_plane.end(),0.0);
400 mean = sum / x_cells_plane.size();
401 sq_sum = std::inner_product(x_cells_plane.begin(),x_cells_plane.end(),x_cells_plane.begin(),0.0);
402 stdev =
std::sqrt(sq_sum / x_cells_plane.size()-mean *
mean);
403 stdev_cells_per_plane_xview=stdev/
mean;
404 sum = std::accumulate(y_cells_plane.begin(),y_cells_plane.end(),0.0);
405 mean = sum / y_cells_plane.size();
406 sq_sum = std::inner_product(y_cells_plane.begin(),y_cells_plane.end(),y_cells_plane.begin(),0.0);
407 stdev =
std::sqrt(sq_sum / y_cells_plane.size()-mean *
mean);
408 stdev_cells_per_plane_yview=stdev/
mean;
410 float novaddt::NNFastMMTrigger::Distance(
unsigned const &xcell1,
unsigned const &ycell1,
unsigned const &plane1,
unsigned const &xcell2,
unsigned const &ycell2 ,
unsigned const &plane2)
const {
411 return std::sqrt((plane1-plane2)*(plane1-plane2)*2.82072+(xcell1-xcell2)*(xcell1-xcell2)+(ycell1-ycell2)*(ycell1-ycell2));
424 int number_of_surface_hits=0;
425 for(
unsigned i=0;
i!=hits.size();++
i){
426 if(
SurfAssign(hits[
i])==
true) number_of_surface_hits++;
428 return number_of_surface_hits;
430 double novaddt::NNFastMMTrigger::WeightedCenterCut(
HitList const &
hits,
float PX_min,
float PX_max,
float PY_min,
float PY_max,
float CX_min,
float CX_max,
float CY_min,
float CY_max,
double &weighted_off_center_xx,
double &weighted_off_center_xz,
double &weighted_off_center_yy,
double &weighted_off_center_yz )
const{
431 float Weighted_PX_Center=0.5,Weighted_CX_Center=0.5,Weighted_PY_Center=0.5,Weighted_CY_Center=0.5,SumOfXHitsADC=0,SumOfYHitsADC=0;
432 for (
auto const hit: hits) {
434 SumOfXHitsADC+=
hit.ADC().val;
435 Weighted_PX_Center+=
hit.ADC().val*(
hit.Plane().val-
PX_min);
436 Weighted_CX_Center+=
hit.ADC().val*(
hit.Cell().val-
CX_min);
439 SumOfYHitsADC+=
hit.ADC().val;
440 Weighted_PY_Center+=
hit.ADC().val*(
hit.Plane().val-
PY_min);
441 Weighted_CY_Center+=
hit.ADC().val*(
hit.Cell().val-
CY_min);
444 if(PX_max!=PX_min) Weighted_PX_Center=Weighted_PX_Center/SumOfXHitsADC/(PX_max-
PX_min);
445 if(PY_max!=PY_min) Weighted_PY_Center=Weighted_PY_Center/SumOfYHitsADC/(PY_max-
PY_min);
446 if(CX_max!=CX_min) Weighted_CX_Center=Weighted_CX_Center/SumOfXHitsADC/(CX_max-
CX_min);
447 if(CY_max!=CY_min) Weighted_CY_Center=Weighted_CY_Center/SumOfYHitsADC/(CY_max-
CY_min);
448 weighted_off_center_xx=
std::abs(Weighted_CX_Center-0.5);
449 weighted_off_center_xz=
std::abs(Weighted_PX_Center-0.5);
450 weighted_off_center_yy=
std::abs(Weighted_CY_Center-0.5);
451 weighted_off_center_yz=
std::abs(Weighted_PY_Center-0.5);
458 double number_hits_in_overlap_planes=0;
459 for (
auto const hit: hits) {
460 if(
hit.Plane().val<=max &&
hit.Plane().val>=
min) number_hits_in_overlap_planes++;
462 return number_hits_in_overlap_planes/hits.size();
T max(const caf::Proxy< T > &a, T b)
bool isfinite(const stan::math::var &v)
novaddt::Plane const & Plane() const
virtual ~NNFastMMTrigger()
void LinFit(const std::vector< double > &x, const std::vector< double > &y, double *fitpar)
std::vector< DAQHit > HitList
virtual void set_data(std::vector< std::vector< std::vector< float > > > const &)
std::string _monopole_id_lib_path
DEFINE_ART_MODULE(TestTMapFile)
unsigned distance(const T &t1, const T &t2)
bool SurfAssign(DAQHit const &hit) const
std::vector< float > compute_output(keras::DataChunk *dc)
Identifier for the Y measuring view of the detector (side)
ProductID put(std::unique_ptr< PROD > &&product)
unsigned long long value_type
Identifier for the X measuring view of the detector (top)
double deltaTDC(const novaddt::TDC &h1, const novaddt::TDC &h2)
NNFastMMTrigger(fhicl::ParameterSet const &p)
static float min(const float a, const float b, const float c)
std::string _sliceinstance
float Distance(unsigned const &xcell1, unsigned const &ycell1, unsigned const &plane1, unsigned const &xcell2, unsigned const &ycell2, unsigned const &plane2) const
void StdevCellsPerPlane(HitList const &hits, double &stdev_cells_per_plane_xview, double &stdev_cells_per_plane_yview) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
double NumberOfHitsInOverlapPlanesCut(HitList const &hits, float PX_min, float PX_max, float PY_min, float PY_max) const
novaddt::Cell const & Cell() const
void NumberOfCellsPerLength(HitList const &hits, double tracklength_of_xview, double tracklength_of_yview, double &number_of_cells_per_length_xview, double &number_of_cells_per_length_yview) const
T min(const caf::Proxy< T > &a, T b)
double WeightedCenterCut(HitList const &hits, float PX_min, float PX_max, float PY_min, float PY_max, float CX_min, float CX_max, float CY_min, float CY_max, double &weighted_off_center_xx, double &weighted_off_center_xz, double &weighted_off_center_yy, double &weighted_off_center_yz) const
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
int NumberOfSurfaceHits(HitList const &hits) const
keras::KerasModel * _model
virtual bool filter(art::Event &e) override