AlignLibToVtx_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file AlignLibToVtx_module.cc
3 // \brief Rewrite a library file with events aligned according to vertex
4 // \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 // Framework includes
16 #include "fhiclcpp/ParameterSet.h"
18 
19 #include "TFile.h"
20 #include "TTree.h"
21 
22 #include "Geometry/Geometry.h"
24 #include "RecoBase/Cluster.h"
25 #include "RecoBase/Vertex.h"
26 
27 #include "LEM/func/EventSummary.h"
28 
29 #include "LEM/Util.h"
30 
31 namespace lem
32 {
33  /// Rewrite a library file with events aligned according to vertex
35  {
36  public:
37  explicit AlignLibToVtx(const fhicl::ParameterSet& pset);
39 
40  virtual void reconfigure(const fhicl::ParameterSet& pset);
41  virtual void beginJob();
42  virtual void respondToOpenInputFile(const art::FileBlock& fb);
43  virtual void produce(art::Event& evt);
44 
45  protected:
46  TTree* fTreeIn;
47  TTree* fTreeOut;
48 
51  };
52 
53  //.......................................................................
55  : fTreeIn(0), fTreeOut(0)
56  {
57  reconfigure(pset);
58 
59  // Just to mark where the vertex is so you can check it's right
60  produces<std::vector<geo::OfflineChan> >();
61  }
62 
63  //......................................................................
65  {
66  }
67 
68  //......................................................................
70  {
71  fVertexLabel = pset.get<std::string>("VertexLabel");
72  fSlicerLabel = pset.get<std::string>("SlicerLabel");
73 
74  // We want to store exactly the values of the hits, only rescale them later
75  // when actually doing matching.
78  }
79 
80  //......................................................................
82  {
84  fTreeOut = tfs->make<TTree>("tree", "tree");
86  }
87 
88  //......................................................................
90  {
91  TFile* fin = new TFile(fb.fileName().c_str());
92  assert(!fin->IsZombie());
93  fTreeIn = (TTree*)fin->Get("makelib/tree");
94  assert(fTreeIn);
95 
97  }
98 
99  //......................................................................
101  {
102  std::unique_ptr<std::vector<geo::OfflineChan> > chancol(new std::vector<geo::OfflineChan>);
103 
105 
107  evt.getByLabel(fVertexLabel, vtxs);
108 
110  evt.getByLabel(fSlicerLabel, slices);
111  assert(slices->size() == 2); // The real slice, plus the noise slice
112  const rb::Cluster& slice = (*slices)[1];
113  assert(!slice.IsNoise());
114 
115  int plane, cell, cellOther;
116  if(vtxs->size() == 1){
117  VertexToPlaneAndCell((*vtxs)[0].GetXYZ(), slice, plane, cell, cellOther);
118  }
119  else{
120  DefaultVertex(slice, plane, cell, cellOther);
121  }
122 
123  chancol->push_back(geo::OfflineChan(plane, cell));
124  // Should really be nextPlane, but that's lost inside of Util.cxx. This is
125  // almost always right, and only for display purposes anyway.
126  chancol->push_back(geo::OfflineChan(plane+1, cellOther));
127 
128  evt.put(std::move(chancol));
129 
130 
131  const int trIdx = evt.event()-1;
132  // Should be exactly the same file
133  assert(trIdx < fTreeIn->GetEntries());
134 
135  // This is the offset GenFromLib applied to put the event in the middle of
136  // the detector. Take it out again here.
137  const int plane0 = geom->NPlanes()/2-128;
138  const int cell0 = geom->Plane(0)->Ncells()/2-128;
139 
140  // Doesn't matter if we say it's enriched or not
142 
143  // Occasionally fails, should just be a warning.
144  // assert(sum.hits.size() == slice.NCell());
145 
146  const int recoVtxPlane = plane-plane0;
147  const int recoVtxCell = cell-cell0;
148  const int recoVtxCellOtherView = cellOther-cell0;
149 
150  for(int i = 0; i < sum.nhits; ++i){
151  lem::LiteHit& h = sum.hits[i];
152 
153  const int planeDelta = h.Plane()-recoVtxPlane;
154  const int cellDelta = ((abs(planeDelta)%2) ?
155  h.Cell()-recoVtxCellOtherView :
156  h.Cell()-recoVtxCell);
157 
158  h.SetPlane(planeDelta+lem::kVertexPlane);
159  h.SetCell(cellDelta+lem::kVertexCell);
160  }
161 
162  // Transform the true vertex the same way
163  const int planeDelta = sum.trueVtxPlane-recoVtxPlane;
164  const int cellDelta = ((abs(planeDelta)%2) ?
165  sum.trueVtxCell-recoVtxCellOtherView :
166  sum.trueVtxCell-recoVtxCell);
167  const int cellDeltaOther = ((abs(planeDelta)%2) ?
168  sum.trueVtxCellOther-recoVtxCell :
169  sum.trueVtxCellOther-recoVtxCellOtherView);
170 
171  sum.trueVtxPlane = planeDelta+lem::kVertexPlane;
172  sum.trueVtxCell = cellDelta+lem::kVertexCell;
173  sum.trueVtxCellOther = cellDeltaOther+lem::kVertexCell;
174 
175  sum.ToTree(fTreeOut);
176  }
177 
179 
180 } // end namespace lem
181 ////////////////////////////////////////////////////////////////////////
unsigned short nhits
Definition: EventSummary.h:53
TString fin
Definition: Style.C:24
Simple representation of event for LEM use.
Definition: EventSummary.h:26
static double fgChargePower
Definition: EventSummary.h:76
virtual void reconfigure(const fhicl::ParameterSet &pset)
void VertexToPlaneAndCell(const TVector3 vtx, const rb::Cluster &slice, int &plane, int &cell, int &cellOtherView, bool reverse)
Definition: Util.cxx:60
virtual void respondToOpenInputFile(const art::FileBlock &fb)
unsigned int Ncells() const
Number of cells in this plane.
Definition: PlaneGeo.h:43
std::string const & fileName() const
Definition: FileBlock.h:38
const int kVertexPlane
Definition: EventSummary.h:22
A collection of associated CellHits.
Definition: Cluster.h:47
void abs(TH1 *hist)
int Cell() const
Definition: LiteHit.h:39
const PlaneGeo * Plane(unsigned int i) const
DEFINE_ART_MODULE(TestTMapFile)
cout<< t1-> GetEntries()
Definition: plottest35.C:29
static void InitFromTree(TTree *tr)
void SetPlane(int p)
Definition: LiteHit.h:41
PID
Definition: FillPIDs.h:14
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void DefaultVertex(const rb::Cluster &slice, int &plane, int &cell, int &cellOtherView, bool reverse)
Definition: Util.cxx:20
static void InitToTree(TTree *tr)
int Plane() const
Definition: LiteHit.h:38
const int kVertexCell
Definition: EventSummary.h:23
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
static EventSummary FromTree(TTree *tr, int evtIdx, bool enrich)
EventNumber_t event() const
Definition: Event.h:67
void ToTree(TTree *tr) const
Vertex location in position and time.
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
A (plane, cell) pair.
Definition: OfflineChan.h:17
void geom(int which=0)
Definition: geom.C:163
static double fgDecayRate
Definition: EventSummary.h:75
assert(nhit_max >=nhit_nbins)
void SetCell(int c)
Definition: LiteHit.h:42
AlignLibToVtx(const fhicl::ParameterSet &pset)
Rewrite a library file with events aligned according to vertex.
virtual void produce(art::Event &evt)
unsigned int NPlanes() const
Simple representation of event for LEM use.
Compressed hit info, basic component of LEM events.
Definition: LiteHit.h:18
Double_t sum
Definition: plot.C:31
Simple object representing a (plane, cell) pair.
Encapsulate the geometry of one entire detector (near, far, ndos)
enum BeamMode string