-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdunezsanalysis_module.cc
252 lines (204 loc) · 8.59 KB
/
dunezsanalysis_module.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// dunezsanalysis_module.cc
// A basic "skeleton" to read in art::Event records from a file,
// access their information, and do something with them.
// See
// <https://cdcvs.fnal.gov/redmine/projects/larsoftsvn/wiki/Using_the_Framework>
// for a description of the ART classes used here.
// Almost everything you see in the code below may have to be changed
// by you to suit your task. The example task is to make histograms
// and n-tuples related to dE/dx of particle tracks in the detector.
// As you try to understand why things are done a certain way in this
// example ("What's all this stuff about 'auto const&'?"), it will help
// to read ADDITIONAL_NOTES.txt in the same directory as this file.
#ifndef dunezsanalysis_Module
#define dunezsanalysis_Module
// LArSoft includes
#include "lardataobj/Simulation/SimChannel.h"
#include "larsim/Simulation/LArG4Parameters.h"
#include "lardataobj/RawData/raw.h"
#include "lardataobj/RawData/RawDigit.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/Cluster.h"
#include "larcore/Geometry/Geometry.h"
#include "nusimdata/SimulationBase/MCParticle.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"
#include "lardataobj/RawData/raw.h"
// Framework includes
#include "art/Framework/Core/EDAnalyzer.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "art_root_io/TFileService.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "canvas/Persistency/Common/FindManyP.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "fhiclcpp/ParameterSet.h"
// ROOT includes. Note: To look up the properties of the ROOT classes,
// use the ROOT web site; e.g.,
// <http://root.cern.ch/root/html532/ClassIndex.html>
#include "TH1.h"
#include "TH2.h"
#include "TTree.h"
#include "TLorentzVector.h"
#include "TVector3.h"
// C++ Includes
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
namespace dunezsanalysis {
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class definition
class dunezsanalysis : public art::EDAnalyzer
{
public:
// Standard constructor and destructor for an ART module.
explicit dunezsanalysis(fhicl::ParameterSet const& pset);
virtual ~dunezsanalysis();
// This method is called once, at the start of the job. In this
// example, it will define the histograms and n-tuples we'll write.
void beginJob();
// This method is called once, at the start of each run. It's a
// good place to read databases or files that may have
// run-dependent information.
void beginRun(const art::Run& run);
// This method reads in any parameters from the .fcl files. This
// method is called 'reconfigure' because it might be called in the
// middle of a job; e.g., if the user changes parameter values in an
// interactive event display.
void reconfigure(fhicl::ParameterSet const& pset);
// The analysis routine, called once per event.
void analyze (const art::Event& evt);
private:
// The stuff below is the part you'll most likely have to change to
// go from this custom example to your own task.
// The parameters we'll read from the .fcl file.
std::string fRawProducerLabel; // The name of the producer that tracked simulated particles through the detector
// The n-tuples we'll create.
//TTree* fSimulationNtuple; // unused
TTree* fReconstructionNtuple;
// The variables that will go into the n-tuple.
int fEvent;
int fRun;
// array of sums of charges for different choices of zero-suppression thresholds.
double fChargeSum[200];
// Other variables that will be shared between different methods.
art::ServiceHandle<geo::Geometry> fGeometry; // pointer to Geometry service
}; // class dunezsanalysis
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// class implementation
//-----------------------------------------------------------------------
// Constructor
dunezsanalysis::dunezsanalysis(fhicl::ParameterSet const& parameterSet) : EDAnalyzer(parameterSet)
{
// Read in the parameters from the .fcl file.
this->reconfigure(parameterSet);
}
//-----------------------------------------------------------------------
// Destructor
dunezsanalysis::~dunezsanalysis()
{}
//-----------------------------------------------------------------------
void dunezsanalysis::beginJob()
{
// Access ART's TFileService, which will handle creating and writing
// histograms and n-tuples for us.
art::ServiceHandle<art::TFileService> tfs;
// The arguments to 'make<whatever>' are the same as those passed
// to the 'whatever' constructor, provided 'whatever' is a ROOT
// class that TFileService recognizes.
// Define our n-tuples, which are limited forms of ROOT
// TTrees. Start with the TTree itself.
fReconstructionNtuple = tfs->make<TTree>("dunezsanalysisReconstruction","dunezsanalysisReconstruction");
// Define the branches (columns) of our simulation n-tuple. When
// we write a variable, we give the address of the variable to
// TTree::Branch.
fReconstructionNtuple->Branch("Event", &fEvent, "Event/I");
fReconstructionNtuple->Branch("Run", &fRun, "Run/I");
// When we write arrays, we give the address of the array to
// TTree::Branch; in C++ this is simply the array name.
fReconstructionNtuple->Branch("ChargeSum", fChargeSum, "ChargeSum[200]/D");
}
//-----------------------------------------------------------------------
void dunezsanalysis::beginRun(const art::Run& /*run*/)
{
// How to convert from number of electrons to GeV. The ultimate
// source of this conversion factor is
// ${SRT_PUBLIC_CONTEXT}/SimpleTypesAndConstants/PhysicalConstants.h.
art::ServiceHandle<sim::LArG4Parameters> larParameters;
//fElectronsToGeV = 1./larParameters->GeVToElectrons();
}
//-----------------------------------------------------------------------
void dunezsanalysis::reconfigure(fhicl::ParameterSet const& /*p*/)
{
// no parameters for now. Just read in raw data
return;
}
//-----------------------------------------------------------------------
void dunezsanalysis::analyze(const art::Event& event)
{
// Start by fetching some basic event information for our n-tuple.
fEvent = event.id().event();
fRun = event.run();
art::Handle< std::vector<raw::RawDigit> > rawDigitHandle;
event.getByLabel("daq", rawDigitHandle); // hard-code the module name
for (int i=0;i<200;i++)
{
fChargeSum[i] = 0;
}
unsigned int nNeighbors = 0;
// add up all the digits on the collection wires in the entire event, for each value of
// the zero-suppression threshold
// put it in a more easily usable form
std::vector< art::Ptr<raw::RawDigit> > Digits;
art::fill_ptr_vector(Digits, rawDigitHandle);
//loop through all RawDigits (over entire channels)
for(size_t d = 0; d < Digits.size(); d++)
{
art::Ptr<raw::RawDigit> digit;
digit=Digits.at(d);
uint32_t chan = digit->Channel();
std::vector<short> uncompressed(digit->Samples());
if (fGeometry->View(chan) == geo::kZ) // for now only do charge sums for collection hits
{
raw::Uncompress(digit->ADCs(), uncompressed, digit->Compression());
for(unsigned int tick=0;tick<uncompressed.size();tick++)
{
//std::cout << "trjadc: " << fEvent << " " << chan << " " << uncompressed.at(tick) << std::endl;
unsigned int tlow = (tick < nNeighbors)? 0: tick - nNeighbors;
unsigned int thigh = tick + nNeighbors;
if (thigh>=uncompressed.size()) thigh = uncompressed.size()-1;
for (short zscut=0;zscut<200;zscut++)
{
if (uncompressed.at(tick) >= zscut)
{
fChargeSum[zscut] += uncompressed.at(tick);
}
else
{
for (unsigned int k=tlow;k<=thigh;k++)
{
if (uncompressed.at(k) >= zscut)
{
fChargeSum[zscut] += uncompressed.at(tick);
break;
}
}
}
}
}
}
}
fReconstructionNtuple->Fill();
return;
}
// This macro has to be defined for this module to be invoked from a
// .fcl file; see dunezsanalysis.fcl for more information.
DEFINE_ART_MODULE(dunezsanalysis)
} // namespace dunezsanalysis
#endif // dunezsanalysis_Module