remove C/C++ file

This commit is contained in:
liuyihui 2022-07-13 13:32:31 +08:00
parent 1789321035
commit c07d215891
15 changed files with 0 additions and 781 deletions

View File

@ -1,208 +0,0 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"].*\.h[>"]'
Priority: 0
SortPriority: 0
CaseSensitive: false
- Regex: '^[<"].*\.hh[>"]'
Priority: 1
SortPriority: 1
CaseSensitive: false
- Regex: '.*'
Priority: 2
SortPriority: 2
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

3
.gitignore vendored
View File

@ -4,7 +4,6 @@
*.csv
*.json
*.png
cal.txt
2016Q3D/
result/
@ -12,7 +11,6 @@ result/
venv/
# build cache
build/
__pycache__
# config
@ -23,4 +21,3 @@ __pycache__
*.ipynb
*.code-workspace
*.exe

View File

@ -1,19 +0,0 @@
cmake_minimum_required(VERSION 3.16)
project(Q3D)
set(Eigen3_DIR D:/Microsoft/vcpkg/installed/x64-windows/share/eigen3)
SET(CMAKE_TOOLCHAIN_FILE D:/Microsoft/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(ROOT REQUIRED Spectrum)
find_package(Eigen3 CONFIG REQUIRED)
include(${ROOT_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include)
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.h)
add_executable(Q3D main.cpp ${sources} ${headers})
target_link_libraries(Q3D ${ROOT_LIBRARIES} Eigen3::Eigen)
install(TARGETS Q3D DESTINATION F:/NuclearAstroPhy/Q3D-Calibration)

View File

@ -1,27 +0,0 @@
#pragma once
#ifndef bind_handler_h
#define bind_handler_h
#include "GaussFit.h"
#include "utils.h"
#include <Eigen/Dense>
class BindHandler {
public:
BindHandler(){};
~BindHandler(){};
public:
std::vector<Eigen::Vector2d> data;
public:
void addData(std::vector<Eigen::Vector2d>);
};
void BindHandler::addData(std::vector<Eigen::Vector2d> newData) {
data.insert(data.end(), newData.begin(), newData.end());
}
#endif

View File

@ -1,38 +0,0 @@
#pragma once
#ifndef block_handler_h
#define block_handler_h
#include "BindHandler.h"
#include "FileHandler.h"
class BlockHandler {
public:
BlockHandler(){};
BlockHandler(int n_, int m_ = 8) { n = n_, m = m_; };
~BlockHandler(){};
public:
int n, m = 8;
BindHandler bind[8];
std::vector<FileHandler> data;
public:
void addData(FileHandler);
void splitData();
};
void BlockHandler::addData(FileHandler FH) { data.push_back(FH); }
void BlockHandler::splitData() {
FileHandler FH;
for (int i = 0; i < data.size(); i++) {
FileHandler FH = data.at(i);
for (int j = 0; j < m; j++) {
bind[j].addData(FH.adcValue[n][j]);
std::vector<Eigen::Vector2d>().swap(FH.adcValue[n][j]);
}
}
}
#endif

View File

@ -1,72 +0,0 @@
#pragma once
#ifndef csv_reader_h
#define csv_reader_h
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using std::string;
using std::vector;
class CsvReader {
public:
CsvReader(string);
~CsvReader() {};
public:
string file;
vector<vector<string>> strArray;
public:
int rows();
void readData();
string operator()(int i, int j) const;
};
CsvReader::CsvReader(string file_) { file = file_; }
int CsvReader::rows() { return strArray.size(); }
void CsvReader::readData() {
std::ifstream inFile(file);
string lineStr;
while (std::getline(inFile, lineStr)) {
std::stringstream ss(lineStr);
string str;
vector<string> lineArray;
while (std::getline(ss, str, ',')) lineArray.push_back(str);
strArray.push_back(lineArray);
}
}
string CsvReader::operator()(int i, int j) const {
vector<string> lineArray;
int n = strArray.size(), m;
if (i < 0 || i > n - 1) std::cout << "Row Index Out Of Bounds " << std::endl;
lineArray = strArray.at(i);
m = lineArray.size();
if (j < 0 || j > m - 1) std::cout << "Column Index Out Of Bounds " << std::endl;
return lineArray.at(j);
}
std::ostream& operator<<(std::ostream& cout, CsvReader& cR) {
vector<string> lineArray;
int n = cR.strArray.size(), m;
for (int i = 0; i < n; i++) {
lineArray = cR.strArray.at(i);
m = lineArray.size();
for (int j = 0; j < m; j++) cout << lineArray.at(j) << " ";
if (i < n - 1) cout << std::endl;
}
return cout;
}
#endif

View File

@ -1,67 +0,0 @@
#pragma once
#ifndef file_handler_h
#define file_handler_h
#include "utils.h"
#include <TFile.h>
#include <TH1F.h>
#include <TTree.h>
#include <Eigen/Dense>
class FileHandler {
public:
FileHandler(){};
FileHandler(string, int n_ = 6, int thMin_ = 800, int thMax_ = 4000);
~FileHandler(){};
public:
int n = 6, m = 8;
int thMin, thMax, pX;
string file;
std::vector<Eigen::Vector2d> adcValue[6][8];
public:
void readData();
};
FileHandler::FileHandler(string file_, int n_, int thMin_, int thMax_) {
file = file_;
n = n_;
thMin = thMin_;
thMax = thMax_;
}
void FileHandler::readData() {
TFile *fRun = new TFile(file.c_str());
TTree *t = (TTree *)fRun->Get("Tree1");
int na, nc, ntot = t->GetEntriesFast();
UInt_t dataArray[6][16];
double x1, x2;
string adc;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
na = i / 2;
nc = j + 2 * m * (i % 2);
adc = "adc" + to_string(na) + "ch" + to_string(nc);
t->SetBranchAddress(adc.c_str(), &dataArray[i][j]);
adc = "adc" + to_string(na) + "ch" + to_string(nc + m);
t->SetBranchAddress(adc.c_str(), &dataArray[i][j + m]);
}
for (int i = 0; i < ntot; i++) {
t->GetEntry(i);
for (int j = 0; j < n; j++)
for (int k = 0; k < m; k++) {
x1 = dataArray[j][k];
x2 = dataArray[j][k + m];
if ((x1 + x2) < thMin || (x1 + x2) > thMax) continue;
adcValue[j][k].push_back(Eigen::Vector2d(x1, x2));
}
}
}
#endif

View File

@ -1,132 +0,0 @@
#pragma once
#ifndef gauss_fit_h
#define gauss_fit_h
#include "GaussNewton.h"
#include "LevenbergMarquardt.h"
#include "clip.h"
#include "utils.h"
#include <TCanvas.h>
#include <TH1F.h>
#include <Eigen/Dense>
#include <iostream>
double Gaussian(double x, double* p) {
return p[0] * std::exp(-(x - p[1]) * (x - p[1]) / (2 * p[2] * p[2]));
}
double* GaussianJacobian(double x, double* p) {
double* resJ = new double[3];
resJ[0] = -Gaussian(x, p) / p[0];
resJ[1] = -(x - p[1]) * Gaussian(x, p) / (p[2] * p[2]);
resJ[2] = -(x - p[1]) * (x - p[1]) * Gaussian(x, p) / (p[2] * p[2] * p[2]);
return resJ;
}
class GaussFit {
public:
GaussFit(){};
~GaussFit(){};
public:
double* parma = new double[3];
std::vector<Eigen::Vector2d> data;
public:
void addData(double x, double y);
double* fit(int type_ = 0);
double RSquare();
int getTotal();
void draw(std::string title = "./Figure.png");
};
void GaussFit::addData(double x, double y) { data.push_back(Eigen::Vector2d(x, y)); }
double* GaussFit::fit(int type_) {
double x, y;
SigmaClip* SC2 = new SigmaClip();
data = SC2->clip(data);
parma[0] = dataMax2D(data);
parma[1] = dataAvg2D(data);
parma[2] = dataStd2D(data);
if (DEBUG > 1)
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d& point = data.at(i);
x = point(0), y = point(1);
std::cout << x << " " << y << std::endl;
}
if (type_ == 0) {
LevenbergMarquardt LM(3, parma, Gaussian, GaussianJacobian);
LM.data = data;
parma = LM.solve();
} else if (type_ == 1) {
LevenbergMarquardt LM(3, parma, Gaussian, GaussianJacobian, type_ = type_);
LM.data = data;
parma = LM.solve();
} else {
GaussNewton GN(3, parma, Gaussian, GaussianJacobian);
GN.data = data;
parma = GN.solve();
}
if (DEBUG) std::cout << parma[0] << " " << parma[1] << ", " << parma[2] << std::endl;
if (DEBUG) std::cout << RSquare() << std::endl;
if (RSquare() < 0.6)
for (int i = 0; i < 3; i++) parma[i] = 0;
return parma;
}
double GaussFit::RSquare() {
double x, y, mu;
double RSS = 0, TSS = 0;
std::vector<double> yData;
for (int i = 0; i < data.size(); i++) yData.push_back(data.at(i)(1));
mu = dataAvg(yData);
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d& point = data.at(i);
x = point(0), y = point(1);
RSS += std::pow(y - Gaussian(x, parma), 2);
TSS += std::pow(y - mu, 2);
}
return 1 - RSS / TSS;
}
int GaussFit::getTotal() {
int sum = 0;
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d& point = data.at(i);
sum += point(1);
}
return sum;
}
void GaussFit::draw(std::string title) {
TCanvas* c1 = new TCanvas("Gauss Fit", "Gauss Fit", 0, 0, 1600, 1200);
TH1F* h1 = new TH1F("", "Raw Data", CHANNEL_NUMBER, 0, CHANNEL_NUMBER);
TH1F* h2 = new TH1F("", "Fit Data", CHANNEL_NUMBER, 0, CHANNEL_NUMBER);
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d& point = data.at(i);
h1->SetBinContent(point(0), point(1));
}
for (int i = 0; i < CHANNEL_NUMBER; i++) h2->SetBinContent(i, Gaussian(i, parma));
c1->cd(1);
h1->Draw("L");
h2->SetLineColor(kRed);
h2->Draw("SAME");
c1->SaveAs(title.c_str());
}
#endif

Binary file not shown.

Binary file not shown.

View File

@ -1,62 +0,0 @@
#pragma once
#ifndef clip_h
#define clip_h
#include "utils.h"
#include <Eigen/Dense>
class SigmaClip {
private:
int maxiters = 5;
double sigma = 3, minValue = INF, maxValue = -INF;
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr;
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr;
public:
SigmaClip(double sigma = 3, int maxiters = 5,
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr,
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr);
~SigmaClip(){};
std::vector<Eigen::Vector2d> clip(std::vector<Eigen::Vector2d> data);
private:
void computeBound(std::vector<Eigen::Vector2d> data);
};
SigmaClip::SigmaClip(double sigma_, int maxiters_,
double (*cenF_)(std::vector<Eigen::Vector2d> data),
double (*stdF_)(std::vector<Eigen::Vector2d> data)) {
sigma = sigma_;
maxiters = maxiters_;
cenF = cenF_ == nullptr ? dataAvg2D : cenF_;
stdF = stdF_ == nullptr ? dataStd2D : stdF_;
}
void SigmaClip::computeBound(std::vector<Eigen::Vector2d> data) {
double std = (*stdF)(data);
double mean = (*cenF)(data);
minValue = mean - (std * sigma);
maxValue = mean + (std * sigma);
}
std::vector<Eigen::Vector2d> SigmaClip::clip(std::vector<Eigen::Vector2d> data) {
std::vector<Eigen::Vector2d>::iterator itor;
minValue = INF, maxValue = -INF;
for (int k = 1; k <= maxiters; k++) {
computeBound(data);
for (itor = data.begin(); itor != data.end();) {
if ((*itor)(0) < minValue || (*itor)(0) > maxValue)
data.erase(itor);
else
itor++;
}
}
return data;
}
#endif

View File

@ -1,96 +0,0 @@
#pragma once
#ifndef utils_h
#define utils_h
#include <Eigen/Dense>
#include <iostream>
#define DEBUG 0
#define INF 1e9
#define CHANNEL_NUMBER 4096
using namespace std;
using std::string;
using std::to_string;
double dataMax(std::vector<double> data) {
double x, m = -INF;
for (int i = 0; i < data.size(); i++) {
x = data.at(i);
m = std::max(m, x);
}
return m;
}
double dataAvg(std::vector<double> data) {
double m = 0;
for (int i = 0; i < data.size(); i++) m += data.at(i);
return m / data.size();
}
double dataStd(std::vector<double> data) {
double m = 0;
double mu = dataAvg(data);
for (int i = 0; i < data.size(); i++) m += std::pow(data.at(i) - mu, 2);
return m / (data.size() - 1);
}
double dataMax2D(std::vector<Eigen::Vector2d> data) {
double m = -INF;
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d &point = data.at(i);
m = std::max(m, point(1));
}
return m;
}
double dataAvg2D(std::vector<Eigen::Vector2d> data) {
int n = 0;
double m = 0;
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d &point = data.at(i);
n += point(1);
m += point(0) * point(1);
}
return m / n;
}
double dataStd2D(std::vector<Eigen::Vector2d> data) {
int n = 0;
double m = 0;
double mu = dataAvg2D(data);
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d &point = data.at(i);
n += point(1);
m += std::pow(point(0) - mu, 2) * point(1);
}
return std::sqrt(m / (n - 1));
}
double dataMax2DInd(std::vector<Eigen::Vector2d> data) {
double x = 0, m = -INF;
for (int i = 0; i < data.size(); i++) {
Eigen::Vector2d &point = data.at(i);
if (point(1) > m) {
x = point(0);
m = point(1);
}
}
return x;
}
double dataStd2DSQRT(std::vector<Eigen::Vector2d> data) { return std::sqrt(dataMax2D(data)); }
string rmString(string str, string substr) {
int pos;
int len = substr.length();
while (true) {
pos = str.find(substr);
if (pos < 0) break;
str.erase(pos, len);
}
return str;
}
#endif

View File

@ -1,48 +0,0 @@
#include "BlockHandler.h"
#include "CsvReader.h"
#include "FileHandler.h"
#include "utils.h"
#include <iostream>
using namespace std;
int main() {
int n, id, E;
string run;
FileHandler *FH;
BlockHandler *BH;
CsvReader CR("config1.csv");
CR.readData();
n = CR.rows();
E = stoi(CR(0, 3));
FH = new FileHandler[n - 1];
BH = new BlockHandler[5];
for (int i = 0; i < 5; i++) BH[i] = BlockHandler(i);
for (int i = 1; i < n; i++) {
run = CR(i, 0);
FH[i - 1] = FileHandler("2016Q3D/root/raw/201609Q3D" + run + ".root", 5);
FH[i - 1].pX = stoi(CR(i, 2));
FH[i - 1].readData();
BH[stoi(CR(i, 1))].addData(FH[i - 1]);
}
for (int i = 0; i < 5; i++) BH[i].splitData();
string s;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 8; j++) {
s = "result/bind/" + to_string(E) + "-" + to_string(i) + "-" + to_string(j) + ".txt";
std::ofstream ofs(s);
for (int k = 0; k < BH[i].bind[j].data.size(); k++) {
auto p = BH[i].bind[j].data.at(k);
ofs << p(0) << " " << p(1) << std::endl;
}
}
}
return 0;
}

View File

@ -1,9 +0,0 @@
#include <TInterpreter.h>
#include <TROOT.h>
#include <TSystem.h>
void process() {
gInterpreter->AddIncludePath("./include");
gROOT->ProcessLine(".L getADC.cpp");
gROOT->ProcessLine("getADC(\"2016Q3D/root/raw/201609Q3D1002.root\")");
}

Binary file not shown.