DataHit_module.cc
Go to the documentation of this file.
1 #include <functional> // std::greater
2 
3 //ROOT includes
4 #include "TH1I.h"
5 #include "TH1F.h"
6 #include "TH2F.h"
7 #include "TTree.h"
8 #include "TMath.h"
9 #include "TGeoMatrix.h" // TGeoHMatrix
10 
11 // LArSoft libraries
12 
13 //LArSoft includes
15 
18 
21 
23 #include "lardataobj/RawData/raw.h"
27 
30 
31 //ART includes
38 #include "art_root_io/TFileDirectory.h"
39 #include "art_root_io/TFileService.h"
42 #include "canvas/Persistency/Common/FindMany.h"
43 #include "canvas/Persistency/Common/FindManyP.h"
44 #include "canvas/Persistency/Common/FindOneP.h"
45 #include "fhiclcpp/ParameterSet.h"
47 
48 
49 class DataHit : public art::EDAnalyzer {
50 
51 public:
52  explicit DataHit(fhicl::ParameterSet const & p);
53 
54  DataHit(DataHit const &) = delete;
55  DataHit(DataHit &&) = delete;
56  DataHit & operator = (DataHit const &) = delete;
57  DataHit & operator = (DataHit &&) = delete;
58 
59  void analyze(art::Event const & evt) override;
60  void reconfigure(fhicl::ParameterSet const & p);
61  void beginJob() override;
62  void endJob() override;
63 
64 private:
65 
66  void ResetVariables();
67 
68  // void FillMyMaps ( std::map< int, simb::MCParticle> &MyMap,
69  // art::FindManyP<simb::MCParticle> Assn,
70  // art::ValidHandle< std::vector<simb::MCTruth> > Hand,
71  // std::map<int, int>* indexMap=nullptr);
72  // PType WhichParType( int TrID );
73  // bool InMyMap ( int TrID, std::map< int, simb::MCParticle> ParMap );
74  // void FillTruth(const art::FindManyP<simb::MCParticle> Assn,
75  // const art::ValidHandle<std::vector<simb::MCTruth>>& Hand,
76  // const PType type) ;
77 
78  // void SaveIDEs(art::Event const & evt);
79 
80  // int firstCatch;
81  // int secondCatch;
82  // int thirdCatch;
83 
84  // std::string fRawDigitLabel;
86  // std::string fCalDataModuleLabel;
87  // std::string fOpFlashModuleLabel;
88  // std::string fOpHitModuleLabel;
89 
90  // std::string fGEANTLabel;
91  // std::string fMARLLabel ; std::map< int, simb::MCParticle > MarlParts;
92  // std::string fAPALabel ; std::map< int, simb::MCParticle > APAParts ;
93  // std::string fCPALabel ; std::map< int, simb::MCParticle > CPAParts ;
94  // std::string fAr39Label ; std::map< int, simb::MCParticle > Ar39Parts;
95  // std::string fNeutLabel ; std::map< int, simb::MCParticle > NeutParts;
96  // std::string fKrypLabel ; std::map< int, simb::MCParticle > KrypParts;
97  // std::string fPlonLabel ; std::map< int, simb::MCParticle > PlonParts;
98  // std::string fRdonLabel ; std::map< int, simb::MCParticle > RdonParts;
99  // std::string fAr42Label ; std::map< int, simb::MCParticle > Ar42Parts;
100  // std::map<int, const simb::MCParticle*> truthmap;
101  // // Which MARLEY interaction (if any) caused this true track ID?
102  // std::map<int, int> trkIDToMarleyIndex;
103 
104  // // Mapping from track ID to particle type, for use in WhichParType()
105  // std::map<int, PType> trkIDToPType;
106 
107  // bool fSaveNeighbourADCs;
108  // bool fSaveIDEs;
109 
110  TTree* fDataHitTree;
111 
112  int Run;
113  int SubRun;
114  int Event;
115 
116  int NTotHit ;
117  int NColHit ;
118  int NIndHit ;
119 
120  std::vector<int> Hit_View ;
121  std::vector<int> Hit_Size ;
122  std::vector<int> Hit_TPC ;
123  std::vector<int> Hit_Chan ;
124  std::vector<float> Hit_Time ;
125  std::vector<float> Hit_RMS ;
126  std::vector<float> Hit_SADC ;
127  std::vector<float> Hit_Int ;
128  std::vector<float> Hit_Peak ;
129 
131 };
132 
134 {
135  this->reconfigure(p);
136 }
137 
138 
140 {
141  fHitLabel = p.get<std::string>("HitLabel" );
142 }
143 
144 
146 {
147  Run = SubRun = Event = -1;
148 
149  NTotHit = 0;
150  NColHit = 0;
151  NIndHit = 0;
152 
153  Hit_View .clear();
154  Hit_Size .clear();
155  Hit_TPC .clear();
156  Hit_Chan .clear();
157  Hit_Time .clear();
158  Hit_RMS .clear();
159  Hit_SADC .clear();
160  Hit_Int .clear();
161  Hit_Peak .clear();
162 }
163 
164 
166 {
168 
169 
170  fDataHitTree = tfs->make<TTree>("DataHitTree","A tree of data hits");
171 
172  fDataHitTree->Branch("Run" , &Run , "Run/I" );
173  fDataHitTree->Branch("SubRun" , &SubRun , "SubRun/I" );
174  fDataHitTree->Branch("Event" , &Event , "Event/I" );
175  fDataHitTree->Branch("NTotHit" , &NTotHit , "NTotHit/I" );
176  fDataHitTree->Branch("NColHit" , &NColHit , "NColHit/I" );
177  fDataHitTree->Branch("NIndHit" , &NIndHit , "NIndHit/I" );
178 
179  fDataHitTree->Branch("Hit_View" , &Hit_View );
180  fDataHitTree->Branch("Hit_Size" , &Hit_Size );
181  fDataHitTree->Branch("Hit_TPC" , &Hit_TPC );
182  fDataHitTree->Branch("Hit_Chan" , &Hit_Chan );
183  fDataHitTree->Branch("Hit_Time" , &Hit_Time );
184  fDataHitTree->Branch("Hit_RMS" , &Hit_RMS );
185  fDataHitTree->Branch("Hit_SADC" , &Hit_SADC );
186  fDataHitTree->Branch("Hit_Int" , &Hit_Int );
187  fDataHitTree->Branch("Hit_Peak" , &Hit_Peak );
188 }
189 
190 
192 {
193  ResetVariables();
194 
195  Run = evt.run();
196  SubRun = evt.subRun();
197  Event = evt.event();
198 
199  //GET INFORMATION ABOUT THE DETECTOR'S GEOMETRY.
200  // auto const* geo = lar::providerFrom<geo::Geometry>();
201 
202  //GET THE RECO HITS.
203  auto reco_hits = evt.getValidHandle<std::vector<recob::Hit> >(fHitLabel);
204 
205  NTotHit = reco_hits->size();
206 
207  for(int hit = 0; hit < NTotHit; ++hit)
208  {
209  recob::Hit const& ThisHit = reco_hits->at(hit);
210 
211  if(ThisHit.View() == geo::kU || ThisHit.View() == geo::kV) {
212  ++NIndHit;
213  } else {
214  ++NColHit;
215  }
216 
217  Hit_View.push_back(ThisHit.View());
218  Hit_Size.push_back(ThisHit.EndTick() - ThisHit.StartTick());
219  Hit_TPC .push_back(ThisHit.WireID().TPC);
220  int channel = ThisHit.Channel();
221  Hit_Chan.push_back(channel);
222  Hit_Time .push_back(ThisHit.PeakTime());
223  Hit_RMS .push_back(ThisHit.RMS());
224  Hit_SADC .push_back(ThisHit.SummedADC());
225  Hit_Int .push_back(ThisHit.Integral());
226  Hit_Peak .push_back(ThisHit.PeakAmplitude());
227  }
228 
229  fDataHitTree->Fill();
230 }
231 
233 {
234 }
235 
void reconfigure(fhicl::ParameterSet const &p)
std::vector< int > Hit_Size
EventNumber_t event() const
Definition: DataViewImpl.cc:85
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:130
geo::WireID WireID() const
Definition: Hit.h:233
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:220
std::vector< float > Hit_Int
void ResetVariables()
std::vector< float > Hit_SADC
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
geo::View_t View() const
View for the plane of the hit.
Definition: Hit.h:232
uint8_t channel
Definition: CRTFragment.hh:201
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::vector< int > Hit_TPC
art framework interface to geometry description
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
Definition: Hit.h:221
std::string fHitLabel
void analyze(art::Event const &evt) override
Planes which measure U.
Definition: geo_types.h:129
std::vector< float > Hit_Peak
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Local-to-world transformations with LArSoft geometry vectors.
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< float > Hit_Time
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
std::vector< int > Hit_Chan
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
art::ServiceHandle< geo::Geometry > geo
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
Definition: Hit.h:216
DataHit(fhicl::ParameterSet const &p)
Detector simulation of raw signals on wires.
std::vector< float > Hit_RMS
Encapsulate the geometry of a wire.
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
Definition: Hit.h:217
DataHit & operator=(DataHit const &)=delete
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
Declaration of signal hit object.
void endJob() override
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:223
Definitions of geometry vector data types.
Declaration of basic channel signal object.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
Tools and modules for checking out the basics of the Monte Carlo.
TCEvent evt
Definition: DataStructs.cxx:7
void beginJob() override
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
std::vector< int > Hit_View
TTree * fDataHitTree