Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
JClusterBuilder.cc
Go to the documentation of this file.
1/**
2 * \file
3 Example program to demonstrate the usage of JClusterBuilder
4
5 If the option -v ("verbose") is used, the number of coincidence clusters
6 is printed for each DOM for each time slice.
7**/
8
9// c++ standard library
10#include <string>
11
12// root
13#include "TH2D.h"
14
15// JPP
16
18
22#include "JSupport/JSupport.hh"
26#include "JMonitor/JCluster.hh"
28#include "Jeep/JParser.hh"
29
30// namespaces
31using namespace std ;
32using namespace KM3NETDAQ ;
33using namespace JPP;
34using namespace JDETECTOR ;
35using namespace JTRIGGER ;
36using namespace JMONITOR ;
37
38int main(int argc, char **argv) {
39 const unsigned int max_multiplicity = 31 ;
40
41 //------------------------------------------------------------
42 // READ COMMAND-LINE OPTIONS
43 //------------------------------------------------------------
45 string detectorFile ;
46 double window ;
47 int maxnslices ;
48 bool verbose ;
49 string ofname ;
50
51 try {
52 JParser<> zap;
53
54 zap['f'] = make_field(input) ;
55 zap['m'] = make_field(maxnslices) = 100 ;
56 zap['a'] = make_field(detectorFile) ;
57 zap['w'] = make_field(window) ;
58 zap['v'] = make_field(verbose) ;
59 zap['o'] = make_field(ofname) = "out.root" ;
60 zap(argc, argv);
61 }
62 catch(const exception &error) {
63 cerr << error.what() << endl ;
64 cout << "Use option -h! to display command line options." << endl ;
65 exit(1) ;
66 }
67
68 //------------------------------------------------------------
69 // OPEN DETECTOR FILE
70 //------------------------------------------------------------
72 try {
73 load(detectorFile, detector);
74 }
75 catch(const JException& error) {
76 cerr << "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl ;
77 exit(1) ;
78 }
79 JModuleRouter moduleRouter(detector) ;
80
81 //------------------------------------------------------------
82 // ALLOCATE HISTOGRAMS
83 //------------------------------------------------------------
84 const int ncolors = 5 ;
85 const int nice_colors[ncolors] = { kRed, kBlue, kBlack, kViolet, kCyan } ;
86
87 // demonstration plots: the ToT distribution for hits in clusters
88 // of different sizes
89 vector<TH1D*> hToT(max_multiplicity+1,NULL) ;
90 for( unsigned int m=0; m<max_multiplicity+1; ++m ) {
91 char hname[200] ;
92 sprintf( hname, "hToT_m%u", m ) ;
93 char htitle[300] ;
94 sprintf( htitle, "Exclusive %u-fold coincidence clusters;ToT [ns];a.u. (normalized)", m ) ;
95 hToT[m] = new TH1D( hname, htitle, 256, -0.5, 255.5 ) ;
96 hToT[m]->SetLineColor( nice_colors[m%ncolors] ) ;
97 hToT[m]->SetLineWidth(2) ;
98 }
99
100 // demonstration plots: the time distribution of the hits in the clusters
101 vector<TH1D*> ht(max_multiplicity+1,NULL) ;
102 for( unsigned int m=0; m<max_multiplicity+1; ++m ) {
103 char hname[200] ;
104 sprintf( hname, "ht_m%u", m ) ;
105 char htitle[300] ;
106 sprintf( htitle, "Exclusive %u-fold coincidence clusters;Time after first hits [ns];a.u. (normalized)", m ) ;
107 const int margin = 5 ; // ns
108 double xmin = -margin ;
109 double xmax = ceil(window) + margin ;
110 int nbins = (int) round(xmax-xmin) ;
111 ht[m] = new TH1D( hname, htitle, nbins, xmin, xmax ) ;
112 ht[m]->SetLineColor( nice_colors[m%ncolors] ) ;
113 ht[m]->SetLineWidth(2) ;
114 }
115
116
117 // another demonstration plot showing the relation between cluster size
118 // and cluster multiplicity (they are practically always the same)
119 TH2D hSizeVsMultiplicity("hSizeVsMultiplicity",";cluster size;cluster multiplicity",
120 32,-0.5,31.5,
121 32,-0.5,31.5 ) ;
122 hSizeVsMultiplicity.SetOption("colz") ;
123
124 //------------------------------------------------------------
125 // READ FILES
126 //------------------------------------------------------------
127 cout << endl ;
128 cout << "---------- Reading file(s) ----------" << endl ;
129
131
132 JMONITOR::JClusterBuilder cluster_builder(window,true) ;
133
134 unsigned int nTS = 0 ; // time slice counter
135 while( scan.hasNext() ) {
136 JDAQTimeslice* ts = scan.next() ;
137 if( (int)nTS == maxnslices ) break ;
138 ++nTS ;
139
140 if( verbose ) {
141 cout << "------ Frame index = " << ts->getFrameIndex() << endl ;
142 }
143
144 // loop over the JDAQSuperFrames
145 for(JDAQTimeslice::const_iterator sf = ts->begin() ; sf!=ts->end() ; ++sf ) {
146 // ignore frames without hits
147 if( sf->size() == 0 ) continue ;
148
149 int moduleID = sf->getModuleID() ;
150 int localID = moduleRouter.getAddress(moduleID).first ;
151 JModule module = detector[localID] ;
152
153 // build clusters
154 cluster_builder.reset(*sf,module) ;
155
156 // print number of clusters found in this frame
157 if( verbose ) {
158 cout << "--- " << "S" << module.getString() << "F" << module.getFloor() << endl ;
159 cout << setw(10) << "multiplicity"
160 << setw(20) << "excl. nclusters"
161 << setw(20) << "incl. nclusters"
162 << endl ;
163 for( unsigned int m=2; m<=max_multiplicity; ++m) {
164 if( cluster_builder.getNclusters(m) != 0 ) {
165 cout << setw(10) << m
166 << setw(20) << cluster_builder.getNclusters(m)
167 << setw(20) << cluster_builder.getInclusiveNclusters(m)
168 << endl ;
169 }
170 }
171 }
172
173 /**
174 loop over all clusters
175 the begin/end_inclusive_m(M) methods return the begin and end iterator
176 for clusters of multiplicity M or higher
177 **/
178 for( vector<JCluster>::const_iterator it=cluster_builder.begin_inclusive_m(0); it!=cluster_builder.end_inclusive_m(0); ++it ) {
179 hSizeVsMultiplicity.Fill( it->size(), it->getMultiplicity() ) ;
180 }
181
182 /**
183 loop over clusters of a given multiplicity
184 the begin/end_m(M) methods return the begin and end iterator for
185 clusters of multiplicity exactly M
186 **/
187 for( unsigned int m=0; m<=max_multiplicity; ++m) {
188 for( vector<JCluster>::const_iterator it=cluster_builder.begin_m(m); it!=cluster_builder.end_m(m); ++it ) {
189 // loop over the hits in the cluster to fill ToT histogram
190 for( JHitL1::const_iterator hit=it->begin(); hit!=it->end(); ++hit ) {
191 hToT[m]->Fill( hit->getToT() ) ;
192 }
193 // loop over the hits after the first hit to fill dt histogram
194 if( it->size() > 1 ) {
195 JHitL1::const_iterator first_hit = it->begin() ;
196 JHitL1::const_iterator hit(first_hit) ;
197 for( ++hit; hit!=it->end(); ++hit ) {
198 ht[m]->Fill( hit->getT() - first_hit->getT() ) ;
199 }
200 }
201 }
202 }
203
204 } // end of loop over JDAQSuperFrames
205
206 if( verbose ) cout << endl ;
207
208 } // end of loop over JDAQTimeSlices
209
210 cout << "Read " << nTS << " time slices." << endl ;
211
212 TFile* f = new TFile( ofname.c_str(), "recreate" ) ;
213
214 hSizeVsMultiplicity.Write() ;
215
216 for( unsigned int m=0; m<=max_multiplicity; ++m) {
217 if( hToT[m]->GetEntries()>0 ) {
218 // normalize
219 hToT[m]->Scale( 1.0/hToT[m]->Integral() ) ;
220 // write
221 hToT[m]->Write() ;
222 }
223 if( ht[m]->GetEntries()>0 ) {
224 // normalize
225 ht[m]->Scale( 1.0/ht[m]->Integral() ) ;
226 // write
227 ht[m]->Write() ;
228 }
229 }
230
231 f->Close() ;
232 delete f ;
233 cout << "Output in '" << ofname << "'." << endl ;
234
235 cout << endl ;
236}
KM3NeT DAQ constants, bit handling, etc.
Data structure for detector geometry and calibration.
Direct access to module in detector data structure.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
ROOT TTree parameter settings of various packages.
Detector data structure.
Definition JDetector.hh:96
int getString() const
Get string number.
Definition JLocation.hh:135
int first
index of module in detector data structure
Router for direct addressing of module data in detector data structure.
const JModuleAddress & getAddress(const JModuleIdentifier &id) const
Get address of module.
Data structure for a composite optical module.
Definition JModule.hh:76
General exception.
Definition JException.hh:25
Local coincidence cluster builder.
vector< JCluster >::const_iterator end_m(unsigned int multiplicity) const
returns end iterator for clusters with exactly the given multiplicity
vector< JCluster >::const_iterator end_inclusive_m(unsigned int multiplicity) const
returns end iterator for clusters with at least the given multiplicity
vector< JCluster >::const_iterator begin_inclusive_m(unsigned int multiplicity) const
returns begin iterator for clusters with at least the given multiplicity
void reset(const JDAQSuperFrame &frame, const JModule &module)
This is a way to re-use the allocated memory.
vector< JCluster >::const_iterator begin_m(unsigned int multiplicity) const
returns begin iterator for clusters with exactly the given multiplicity
unsigned int getInclusiveNclusters(const unsigned int multiplicity) const
return the number of clusters with at least the given multiplicity
unsigned int getNclusters(const unsigned int multiplicity) const
return the number of clusters with exactly the given multiplicity
Utility class to parse command line options.
Definition JParser.hh:1697
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
int getFrameIndex() const
Get frame index.
int main()
int verbose
Definition elog.cc:70
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Detector file.
Definition JHead.hh:227