OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
PeakFinder.h
Go to the documentation of this file.
1 //
2 // Class PeakFinder
3 // Find peaks of radial profile.
4 // It computes a histogram based on the radial distribution of the particle
5 // bunch. After that all peaks of the histogram are searched.
6 // The radii are written in ASCII format to a file.
7 // This class is used for the cyclotron probe element.
8 //
9 // Copyright (c) 2017 - 2021, Matthias Frey, Jochem Snuverink, Paul Scherrer Institut, Villigen PSI, Switzerland
10 // All rights reserved
11 //
12 // This file is part of OPAL.
13 //
14 // OPAL is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21 //
22 #ifndef PEAKFINDER_H
23 #define PEAKFINDER_H
24 
25 #include "Algorithms/Vektor.h"
26 
27 #include <fstream>
28 #include <string>
29 #include <vector>
30 #include <list>
31 
32 class PeakFinder {
33 
34 public:
35  using container_t = std::vector<double>;
36 
37 public:
38 
39  PeakFinder() = delete;
40 
41  PeakFinder(std::string elem, double min, double max, double binwidth, bool singlemode);
42 
47  void addParticle(const Vector_t& R);
48 
52  void evaluate(const int& turn);
53 
54  void save();
55 
56 private:
57 
58  // compute global histogram, involves some inter-node communication
59  void createHistogram_m();
60 
61  /***************
62  * Output file *
63  ***************/
65  void open_m();
67  void append_m();
69  void close_m();
71  void saveASCII_m();
72 
73  void computeCentroid_m();
74 
75 private:
79 
81  std::string fn_m;
82 
84  std::string hist_m;
85 
87  std::ofstream os_m;
88 
90  std::ofstream hos_m;
91 
93  std::string outputName_m;
94 
95  // Histogram details
97  unsigned int nBins_m;
99  double binWidth_m;
101  double min_m, max_m;
102 
103  int turn_m;
104  double peakRadius_m;
106  std::list<double> peaks_m;
108  bool first_m;
110 };
111 
112 #endif
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
std::vector< double > container_t
Definition: PeakFinder.h:35
void open_m()
Open output file.
Definition: PeakFinder.cpp:178
std::list< double > peaks_m
Definition: PeakFinder.h:106
std::ofstream hos_m
used to write out the histrogram
Definition: PeakFinder.h:90
PeakFinder()=delete
std::string fn_m
filename with extension (.peaks)
Definition: PeakFinder.h:81
std::ofstream os_m
used to write out the data
Definition: PeakFinder.h:87
double binWidth_m
Bin width in mm.
Definition: PeakFinder.h:99
double peakRadius_m
Definition: PeakFinder.h:104
container_t globHist_m
global histogram values
Definition: PeakFinder.h:78
bool singlemode_m
Definition: PeakFinder.h:107
void save()
Definition: PeakFinder.cpp:98
container_t radius_m
Definition: PeakFinder.h:76
bool finished_m
Definition: PeakFinder.h:109
void createHistogram_m()
Definition: PeakFinder.cpp:149
void computeCentroid_m()
Definition: PeakFinder.cpp:130
double min_m
histogram size
Definition: PeakFinder.h:101
unsigned int nBins_m
Number of bins.
Definition: PeakFinder.h:97
std::string outputName_m
Element/probe name, for name output file.
Definition: PeakFinder.h:93
void append_m()
Open output file in append mode.
Definition: PeakFinder.cpp:184
std::string hist_m
histogram filename with extension (.hist)
Definition: PeakFinder.h:84
bool first_m
Definition: PeakFinder.h:108
int registered_m
Definition: PeakFinder.h:105
void evaluate(const int &turn)
Definition: PeakFinder.cpp:66
void saveASCII_m()
Write to output file.
Definition: PeakFinder.cpp:196
void addParticle(const Vector_t &R)
Definition: PeakFinder.cpp:56
double max_m
Definition: PeakFinder.h:101
void close_m()
Close output file.
Definition: PeakFinder.cpp:190