NoiseClusterAnalysis_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: NoiseClusterAnalysis
3 // Plugin Type: analyzer (art v2_12_01)
4 // File: NoiseClusterAnalysis_module.cc
5 //
6 // Generated at Wed Sep 18 19:58:01 2019 by Adam Lister using cetskelgen
7 // from cetlib version v3_06_00.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
20 // art
22 
23 // nova
24 #include "RecoBaseHit/CellHit.h"
25 #include "RecoBase/Cluster.h"
26 #include "SummaryData/POTSum.h"
27 
28 // root
29 #include "TTree.h"
30 
31 namespace validation {
33 }
34 
35 
37 public:
38  explicit NoiseClusterAnalysis(fhicl::ParameterSet const & p);
39  // The compiler-generated destructor is fine for non-base
40  // classes without bare pointers or other resource use.
41 
42  // Plugins should not be copied or assigned.
47 
48  void beginSubRun(art::SubRun const & sr) override;
49 
50  // Required functions.
51  void analyze(art::Event const & e) override;
52 
53  // Selected optional functions.
54  void beginJob() override;
55 
56  // resize vectors to zero
57  void resizeVectors();
58 
59 private:
60 
61  // services
63 
64  // fhicl
66 
67  // TTree and variables
68  TTree* tree;
69  int run;
70  int subRun;
71  int event;
72  bool isRealData;
73  int nClusters;
74 
75  TTree* pottree;
76  int potRun;
77  int potSubRun;
78  double pot;
79 
80  std::vector< int >* clusterNHits = nullptr;
81  std::vector< int >* clusterIsNoise = nullptr;
82 
83  std::vector<std::vector< int >>* hitPlane = nullptr;
84  std::vector<std::vector< int >>* hitCell = nullptr;
85  std::vector<std::vector< int >>* hitIsX = nullptr;
86  std::vector<std::vector< int >>* hitIsY = nullptr;
87  std::vector<std::vector< double >>* hitPE = nullptr;
88  std::vector<std::vector< int >>* hitTNS = nullptr;
89 
90 };
91 
92 
94  :
95  EDAnalyzer(p) // ,
96 {
97 
98  fClusterLabel = p.get< std::string >("ClusterLabel");
99 
100 }
101 
103 {
104 
105  resizeVectors();
106 
107  run = e.run();
108  subRun = e.subRun();
109  event = e.event();
110  isRealData = e.isRealData();
111 
112  LOG_VERBATIM("validation::NoiseClusterAnalysis::analyze()")
113  << "Processing " << run << "." << subRun << "." << event;
114 
116  e.getByLabel(fClusterLabel, clusterHandle);
117  std::vector< art::Ptr< rb::Cluster > > clusterPtrVector;
118  art::fill_ptr_vector(clusterPtrVector, clusterHandle);
119 
120  nClusters = (int)clusterPtrVector.size();
121 
122  LOG_DEBUG("validation::NoiseClusterAnalysis::analyze()")
123  << "Number of clusters: " << nClusters;
124 
125  // loop cluster ptr vector and find noise cluster
126  for (int i = 0; i < nClusters; i++){
127 
128  art::Ptr< rb::Cluster > thisCluster = clusterPtrVector.at(i);
129 
130  LOG_DEBUG("validation::NoiseClusterAnalysis::analyze()")
131  << "-- thisCluster->IsNoise: " << thisCluster->IsNoise();
132 
133  clusterIsNoise->push_back(thisCluster->IsNoise());
134 
135  // if in noise cluster, then we want to get the hits
136  art::PtrVector< rb::CellHit > noiseCellHitsPtrVector = thisCluster->AllCells();
137 
138  clusterNHits ->push_back(noiseCellHitsPtrVector.size());
139 
140  std::vector< int > tHitPlane;
141  std::vector< int > tHitCell;
142  std::vector< int > tHitIsX;
143  std::vector< int > tHitIsY;
144  std::vector< double > tHitPE;
145  std::vector< int > tHitTNS;
146 
147  for (int j = 0; j < clusterNHits->back(); j++){
148 
149  art::Ptr< rb::CellHit > thisNoiseHit = noiseCellHitsPtrVector.at(j);
150 
151  tHitPlane.push_back(thisNoiseHit->Plane());
152  tHitCell .push_back(thisNoiseHit->Cell());
153  tHitPE .push_back(thisNoiseHit->PE());
154  tHitTNS .push_back(thisNoiseHit->TNS());
155 
156  if (thisNoiseHit->View() == geo::kX){
157  tHitIsX.push_back(1);
158  tHitIsY.push_back(0);
159  }
160  else if (thisNoiseHit->View() == geo::kY){
161  tHitIsX.push_back(0);
162  tHitIsY.push_back(1);
163  }
164  else{
165  tHitIsX.push_back(-1);
166  tHitIsY.push_back(-1);
167  }
168 
169  LOG_DEBUG("validation::NoiseClusterAnalysis::analyze()")
170  << "Found hit with ID"
171  << thisNoiseHit->ID()
172  << ", printing information";
173 
174  LOG_DEBUG("validation::NoiseClusterAnalysis::analyze()")
175  << "-- Hit Plane : " << thisNoiseHit->Plane()
176  << "\n-- Hit Cell : " << thisNoiseHit->Cell()
177  << "\n-- Hit PE : " << thisNoiseHit->PE()
178  << "\n-- Hit TNS : " << thisNoiseHit->TNS();
179 
180  }
181 
182  hitPlane -> push_back(tHitPlane);
183  hitCell -> push_back(tHitCell);
184  hitIsX -> push_back(tHitIsX);
185  hitIsY -> push_back(tHitIsY);
186  hitPE -> push_back(tHitPE);
187  hitTNS -> push_back(tHitTNS);
188 
189  }
190 
191  tree->Fill();
192 
193 }
194 
196 {
197  tree = tfs->make<TTree>("noiseana" , "noise cluster analysis tree");
198 
199  tree->Branch("run" , &run );
200  tree->Branch("subRun" , &subRun );
201  tree->Branch("event" , &event );
202  tree->Branch("isRealData" , &isRealData );
203 
204  tree->Branch("clusterIsNoise" , "std::vector<int>", &clusterIsNoise);
205  tree->Branch("clusterNHits" , "std::vector<int>", &clusterNHits);
206 
207  tree->Branch("hitPlane" , "std::vector< std::vector<int> >" , &hitPlane );
208  tree->Branch("hitCell" , "std::vector< std::vector<int> >" , &hitCell );
209  tree->Branch("hitIsX" , "std::vector< std::vector<int> >" , &hitIsX );
210  tree->Branch("hitIsY" , "std::vector< std::vector<int> >" , &hitIsY );
211  tree->Branch("hitPE" , "std::vector< std::vector<double> >" , &hitPE );
212  tree->Branch("hitTNS" , "std::vector< std::vector<int> >" , &hitTNS );
213 
214  pottree = tfs->make<TTree>("pottree", "pot information tree");
215 
216  pottree->Branch("pot", &pot);
217  pottree->Branch("run", &potRun);
218  pottree->Branch("subrun", &potSubRun);
219 }
220 
221 
223 {
224  clusterIsNoise -> resize(0);
225  clusterNHits -> resize(0);
226  hitPlane -> resize(0);
227  hitCell -> resize(0);
228  hitIsX -> resize(0);
229  hitIsY -> resize(0);
230  hitPE -> resize(0);
231  hitTNS -> resize(0);
232 }
233 
235 {
237  if (sr.getByLabel("ifdbspillinfo", p))
238  pot = p->totgoodpot;
239 
240  if (sr.getByLabel("generator", p))
241  pot = p->totgoodpot;
242 
243  potRun = sr.run();
244  potSubRun = sr.subRun();
245 
246  pottree->Fill();
247 
248 }
249 
float TNS() const
Definition: CellHit.h:46
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
SubRunNumber_t subRun() const
Definition: Event.h:72
SubRunNumber_t subRun() const
Definition: SubRun.h:44
art::ServiceHandle< art::TFileService > tfs
unsigned short Plane() const
Definition: CellHit.h:39
std::vector< std::vector< int > > * hitPlane
geo::View_t View() const
Definition: CellHit.h:41
const char * p
Definition: xmltok.h:285
std::vector< std::vector< int > > * hitIsX
Vertical planes which measure X.
Definition: PlaneGeo.h:28
void analyze(art::Event const &e) override
bool isRealData() const
Definition: Event.h:83
DEFINE_ART_MODULE(TestTMapFile)
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
art::PtrVector< rb::CellHit > AllCells() const
Get all cells from both views.
Definition: Cluster.cxx:180
std::vector< std::vector< int > > * hitIsY
Class to run in order to validate ChannelInfo.
unsigned short Cell() const
Definition: CellHit.h:40
if(dump)
std::vector< std::vector< double > > * hitPE
void resize(T &x, std::vector< int > dims)
Definition: resize.hpp:41
T get(std::string const &key) const
Definition: ParameterSet.h:231
base_types push_back(int_type())
float PE() const
Definition: CellHit.h:42
void beginSubRun(art::SubRun const &sr) override
caf::StandardRecord * sr
const double j
Definition: BetheBloch.cxx:29
EventNumber_t event() const
Definition: Event.h:67
reference at(size_type n)
Definition: PtrVector.h:365
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Definition: run.py:1
size_type size() const
Definition: PtrVector.h:308
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T * make(ARGS...args) const
const int ID() const
Definition: CellHit.h:47
NoiseClusterAnalysis(fhicl::ParameterSet const &p)
NoiseClusterAnalysis & operator=(NoiseClusterAnalysis const &)=delete
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< std::vector< int > > * hitCell
std::vector< std::vector< int > > * hitTNS
#define LOG_VERBATIM(category)
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
double totgoodpot
normalized by 10^12 POT
Definition: POTSum.h:28
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.h:77
RunNumber_t run() const
Definition: SubRun.h:49