MatchableEvent.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MatchableEvent.cxx
3 /// \brief Attach some information used in matching to an EventSummary
4 /// \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 
8 
9 #include "LEM/func/DistanceMap.h"
10 
11 #include <algorithm>
12 
13 namespace lem
14 {
15  //......................................................................
17  : EventSummary(evt), weight(1)
18  {
19  const DistanceMap& dm = DistanceMap::Instance();
20 
21  selfEnergy = 0;
22 
23  for(unsigned int i = 0; i < nhits; ++i){
24  const LiteHit& hi = hits[i];
25 
26  selfEnergy += .5*hi.pecorr*hi.pecorr*dm.InvDist(hi, hi);
27 
28  for(unsigned int j = i+1; j < nhits; ++j){
29  const LiteHit& hj = hits[j];
30 
31  // Only if they're in the same view
32  if(hi.Plane()%2 == hj.Plane()%2)
33  selfEnergy += hi.pecorr*hj.pecorr*dm.InvDist(hi, hj);
34  } // end for j
35  } // end for i
36  }
37 
38  //......................................................................
40  {
41  std::vector<LiteHit> tmp(hits, hits+nhits);
42 
43  for(unsigned int i = 0; i < nhits; ++i){
44  int p = tmp[i].Plane();
45  int c = tmp[i].Cell();
46  p = ((p>>(factor+1))<<1)+p%2;
47  c = c>>factor;
48  // This encoding screws up Plane() and Cell(), but it collapses all the
49  // possible hits into a small range of indices, so should be better for
50  // looking them up in the Potential map?
51  tmp[i].cellIdx = (p<<(8-factor))+c;
52  } // end for i
53 
54  // Put in order of cellIdx
55  std::sort(tmp.begin(), tmp.end());
56 
57  // Merge identical cellIdxs
58  std::vector<LiteHit> tmp2;
59  for(unsigned int i = 0; i < nhits; ++i){
60  if(tmp2.empty() || tmp2.back().cellIdx != tmp[i].cellIdx)
61  tmp2.push_back(tmp[i]);
62  else
63  tmp2.back().pecorr += tmp[i].pecorr;
64  } // end for i
65 
66  MatchableEvent ret = *this;
67  ret.nhits = tmp2.size();
68  delete[] ret.hits;
69  ret.hits = new LiteHit[ret.nhits];
70  for(int i = 0; i < ret.nhits; ++i) ret.hits[i] = tmp2[i];
71 
72  return ret;
73  }
74 
75  //......................................................................
76  MatchableEvent MatchableEvent::Flipped(bool flipEven, bool flipOdd) const
77  {
78  MatchableEvent ret = *this;
79 
80  for(int i = 0; i < ret.nhits; ++i){
81  LiteHit& h = ret.hits[i];
82  if((h.Plane()%2 == 0 && flipEven) ||
83  (h.Plane()%2 == 1 && flipOdd)){
84  h.SetCell(2*kVertexCell-h.Cell());
85  }
86  }
87 
88  // TODO: can we try and use move to not have to call another copy
89  // constructor here?
90  return ret;
91  }
92 
93 } // namespace
unsigned short nhits
Definition: EventSummary.h:53
Simple representation of event for LEM use.
Definition: EventSummary.h:26
Attach some information used in matching to an EventSummary.
const Var weight
MatchableEvent Flipped(bool flipEven, bool flipOdd) const
const char * p
Definition: xmltok.h:285
float pecorr
Definition: LiteHit.h:24
int Cell() const
Definition: LiteHit.h:39
Float_t tmp
Definition: plot.C:36
PID
Definition: FillPIDs.h:14
TSpline3 hi("hi", xhi, yhi, 18,"0")
int Plane() const
Definition: LiteHit.h:38
static const DistanceMap & Instance()
Singleton.
Definition: DistanceMap.cxx:26
const int kVertexCell
Definition: EventSummary.h:23
int evt
MatchableEvent Downsampled(int factor) const
const double j
Definition: BetheBloch.cxx:29
Attach some information used in matching to an EventSummary.
void SetCell(int c)
Definition: LiteHit.h:42
Compressed hit info, basic component of LEM events.
Definition: LiteHit.h:18
Calculate and cache electrostatic potential between cells.
double InvDist(int aplane, int bplane, int acell, int bcell) const
Definition: DistanceMap.cxx:99
Calculate and cache electrostatic potential between cells.
Definition: DistanceMap.h:20