AlignInspect_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Simple analyzer module to print to text file information
3 /// required for c++ based block alignment study.
4 /// It does very rudimentary stuf, loop over tracks and garnering
5 /// track information - all passed to a .txt.
6 /// \author gsdavies@iastate.edu
7 ////////////////////////////////////////////////////////////////////////
8 
9 // C/C++ includes
10 #include <cmath>
11 #include <iostream>
12 #include <ostream>
13 #include <fstream>
14 #include <sstream>
15 #include <string>
16 #include <cstdlib>
17 #include <vector>
18 
19 // NOvASoft includes
21 #include "Geometry/Geometry.h"
22 #include "RecoBase/CellHit.h"
23 #include "RecoBase/Track.h"
24 #include "NovaDAQConventions/DAQConventions.h"
25 
26 // ART includes
33 
34 
35 namespace align {
36  class AlignInspect : public art::EDAnalyzer {
37  public:
38  explicit AlignInspect(fhicl::ParameterSet const& pset);
39  virtual ~AlignInspect();
40 
41  void analyze(art::Event const& evt);
42  void reconfigure(const fhicl::ParameterSet& pset);
43 
44  void beginJob();
45  void endJob();
46 
47  private:
48 
50  double x,
51  double y,
52  double z); ///< yes/no is "track" entering within a buffer window
53 
54  std::string fCellHitsListLabel; ///< Where to find CellHit
55  std::string fTrackLabel; ///< Where to find Tracks
56 
57  unsigned int fMuonNhit; ///< Required # hits on muon track
58  unsigned int fMuonNhitX; ///< # required in x view
59  unsigned int fMuonNhitY; ///< # required in y view
60  double fDetEdgeBuffer; ///< Detector edge buffer zone for entering cosmic ray track decision [cm]
61  unsigned int fNevents;
62 
63  };
64 }
65 
66 ////////////////////////////////////////////////////////////////////////
67 namespace align{
68 
70  EDAnalyzer(pset),
71  fCellHitsListLabel(pset.get< std::string >("CellHitsListLabel")),
72  fTrackLabel (pset.get< std::string >("TrackLabel") ),
73  fMuonNhit (pset.get< unsigned int >("MuonNhit") ),
74  fMuonNhitX (pset.get< unsigned int >("MuonNhitX") ),
75  fMuonNhitY (pset.get< unsigned int >("MuonNhitY") ),
76  fDetEdgeBuffer (pset.get< double >("DetEdgeBuffer") ),
77  fNevents(0)
78  {
79  reconfigure(pset);
80  }
81 
82  //......................................................................
84  {
85  }
86 
87  //......................................................................
89  {
90  }
91 
92  //......................................................................
94  {
95  ++fNevents;
98 
99  // Get the tracks that were made by CosmicTrack
100  // and test that there are tracks in the event
102  evt.getByLabel(fTrackLabel,trks);
103  if (trks->size()==0) {
104  mf::LogWarning("AlignWarn") << "There are " << trks->size()
105  << " Tracks in this event, skip";
106  return;
107  }
108  LOG_DEBUG("AlignInspect") << "There are " << trks->size() << " Tracks in this event";
109 
110 
111  const unsigned int trkMax = trks->size();
112  //const unsigned int trkMax = 1;
113  if(trkMax < 2) return;
114  for(unsigned int trkIdx = 0; trkIdx < trkMax; ++trkIdx){
115  art::Ptr<rb::Track> track(trks, trkIdx);
116 
117  TVector3 start(track->Start());
118  TVector3 end(track->Stop());
119  if(end.Y() > start.Y()) std::swap(start, end);
120 
121  // Is this a good track?? i.e. entering and extends across at least 8 planes
122  if (this->IsGoodTrack(track,start.X(),start.Y(),start.Z()) == false) return;
123  assert(track->ExtentPlane() >= 8);
124 
125  const unsigned int hitMax = track->NCell(); // maximum number of CellHits on track
126  const unsigned int hitX = track->NXCell(); // maximum number of CellHits on track in XZ
127  const unsigned int hitY = track->NYCell(); // maximum number of CellHits on track in YZ
128 
129  // Do NOT select tracks if max number of hits or XZ- YZ-hits less than configurable values
130  if ( (hitMax < fMuonNhit) || (hitX < fMuonNhitX) || (hitY < fMuonNhitY) ) return;
131  assert(hitMax >= fMuonNhit);
132  const int detid = novadaq::cnv::kNDOS;
133  // Grab the block ID here from DAQChannelMap
134  daqchannelmap::lchan logchan = cmap->Map()->encodeLChan(detid, track->MinPlane(),1);
135  const int bID = cmap->Map()->computeBlock(logchan);
136  // std::cout << bID << ", plane: " << track->MinPlane() << ", det: " << detid << std::endl;
137  // write out track start/end positions and track index + event number, run number
138  // Note: hard-coded output directory an output names here!
139  std::ostringstream oss;
140  oss << "/nova/data/users/gsdavies/alignment/mc/inspect/blkshift10_" << evt.subRun() << ".txt";
141 
142  std::string fname(oss.str());
143  std::ofstream fout(fname.c_str(),std::ios::app);
144 
145  if(fout){
146  fout << evt.subRun() << " " << evt.id().event() << " " << trkIdx << " "
147  << bID << " " << start.X() << " " << start.Y() << " " << start.Z() << " "
148  << end.X() << " " << end.Y() << " " << end.Z() << " "
149  << track->MinTNS() << " " << track->MaxTNS() << std::endl;
150  }
151  fout.close();
152 
153  } // end for trkIdx
154 
155  return;
156  }
157 
158  //......................................................................
160  {
161  }
162 
163  //......................................................................
165  {
166  }
167 
168  //.....................................................................
169  bool AlignInspect::IsGoodTrack(art::Ptr<rb::Track> t, double x, double y, double z)
170  {
172  if (t->ExtentPlane() >= 8) return true;
173  else return false;
174  if (y > geom->DetHalfHeight()-fDetEdgeBuffer) return true;
175  if (fabs(x) > geom->DetHalfWidth()-fDetEdgeBuffer) return true;
176  if (z < fDetEdgeBuffer) return true;
177  if (z > geom->DetLength()-fDetEdgeBuffer) return true;
178  return false;
179  }
180 } //namespace align
181 
182 ////////////////////////////////////////////////////////////////////////
184 ////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
Simple analyzer module to print to text file information required for c++ based block alignment study...
SubRunNumber_t subRun() const
Definition: Event.h:72
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
void reconfigure(const fhicl::ParameterSet &pset)
double DetLength() const
unsigned int fMuonNhitX
required in x view
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
DEFINE_ART_MODULE(TestTMapFile)
virtual TVector3 Start() const
Definition: Prong.h:73
void analyze(art::Event const &evt)
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
AlignInspect(fhicl::ParameterSet const &pset)
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
double MinTNS() const
Definition: Cluster.cxx:482
unsigned int fMuonNhit
Required # hits on muon track.
Prototype Near Detector on the surface at FNAL.
int evt
double DetHalfHeight() const
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
std::string fTrackLabel
Where to find Tracks.
z
Definition: test.py:28
double MaxTNS() const
Definition: Cluster.cxx:528
bool IsGoodTrack(art::Ptr< rb::Track > t, double x, double y, double z)
yes/no is "track" entering within a buffer window
unsigned int NYCell() const
Number of cells in the y-view.
Definition: Cluster.h:108
unsigned int MinPlane(geo::View_t view=geo::kXorY) const
Definition: Cluster.cxx:462
EventNumber_t event() const
Definition: EventID.h:116
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
double DetHalfWidth() const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
unsigned int NXCell() const
Number of cells in the x-view.
Definition: Cluster.h:106
app
Definition: demo.py:189
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void geom(int which=0)
Definition: geom.C:163
unsigned int ExtentPlane(geo::View_t view=geo::kXorY) const
Definition: Cluster.h:250
assert(nhit_max >=nhit_nbins)
double fDetEdgeBuffer
Detector edge buffer zone for entering cosmic ray track decision [cm].
TVector3 Stop() const
Position of the final trajectory point.
Definition: Track.cxx:186
virtual block_t computeBlock(lchan logicalchan) const =0
Which block is this lchan in?
Float_t track
Definition: plot.C:35
EventID id() const
Definition: Event.h:56
unsigned int fMuonNhitY
required in y view
std::string fCellHitsListLabel
Where to find CellHit.
Encapsulate the geometry of one entire detector (near, far, ndos)