forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
008317b
commit 618a89c
Showing
12 changed files
with
247 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Detectors/TPC/calibration/include/TPCCalibration/TPCVShapeScaler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
/// \file TPCVShapeScaler.h | ||
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de> | ||
|
||
#ifndef ALICEO2_TPC_TPCVShapeScaler | ||
#define ALICEO2_TPC_TPCVShapeScaler | ||
|
||
#include "DataFormatsTPC/Defs.h" | ||
#include <vector> | ||
|
||
class TTree; | ||
|
||
namespace o2::tpc | ||
{ | ||
|
||
/* | ||
Class for storing the scalers which are used to calculate an estimate for the mean space-charge density for the last ion drift time | ||
*/ | ||
|
||
class TPCVShapeScaler | ||
{ | ||
public: | ||
/// default constructor | ||
TPCVShapeScaler() = default; | ||
|
||
/// default move assignment | ||
TPCVShapeScaler& operator=(TPCVShapeScaler&& other) = default; | ||
|
||
/// \return returns number of stored TPC scaler values | ||
int getNValues() const { return mScalerA.size(); } | ||
|
||
/// setting the scalers <time, value> | ||
void setScaler(const std::vector<std::pair<double, float>>& values) { mScalerA = values; } | ||
|
||
/// \return returns run number for which this object is valid | ||
void setRun(int run) { mRun = run; } | ||
|
||
/// dump this object to a file | ||
/// \param file output file | ||
void dumpToFile(const char* file, const char* name); | ||
|
||
/// load parameters from input file (which were written using the writeToFile method) | ||
/// \param inpf input file | ||
void loadFromFile(const char* inpf, const char* name); | ||
|
||
/// set this object from input tree | ||
void setFromTree(TTree& tpcScalerTree); | ||
|
||
/// set sampling time of the stored values | ||
float setSamplingTimeMS(float t) { return mSamplingTimeMS = t; } | ||
|
||
/// \return returns stored scalers for given side and data index | ||
std::pair<double, float> getScalers(unsigned int idx) const { return mScalerA[idx]; } | ||
|
||
/// \return returns stored scalers for given side | ||
const auto& getScalers() const { return mScalerA; } | ||
|
||
/// \return returns run number for which this object is valid | ||
int getRun() const { return mRun; } | ||
|
||
/// \return returns mean scaler value for last ion drift time | ||
/// \param timestamp timestamp for which the last values are used to calculate the mean | ||
float getScaler(const double timestamp) const; | ||
|
||
/// \return returns sampling time of the stored values | ||
float getSamplingTimeMS() const { return mSamplingTimeMS; } | ||
|
||
private: | ||
int mRun{}; ///< run for which this object is valid | ||
std::vector<std::pair<double, float>> mScalerA{}; ///< TPC scaler for A-side | ||
float mSamplingTimeMS = 1; ///< sampling time of the V-shape values | ||
|
||
/// if distance to neighbouring data is larger than sampling time return 0 for the scaling | ||
bool checkDeltaTime(double deltaTime) const { return deltaTime < 1.5 * mSamplingTimeMS; } | ||
|
||
ClassDefNV(TPCVShapeScaler, 1); | ||
}; | ||
|
||
} // namespace o2::tpc | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
// All rights not expressly granted are reserved. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
// | ||
// In applying this license CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
/// \file TPCVShapeScaler.cxx | ||
/// \brief Definition of TPCVShapeScaler class | ||
/// | ||
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de> | ||
|
||
#include "TPCCalibration/TPCVShapeScaler.h" | ||
#include <TFile.h> | ||
#include <TTree.h> | ||
#include "Framework/Logger.h" | ||
#include "CommonConstants/LHCConstants.h" | ||
|
||
using namespace o2::tpc; | ||
|
||
void TPCVShapeScaler::dumpToFile(const char* file, const char* name) | ||
{ | ||
TFile out(file, "RECREATE"); | ||
TTree tree(name, name); | ||
tree.SetAutoSave(0); | ||
tree.Branch("TPCVShapeScaler", this); | ||
tree.Fill(); | ||
out.WriteObject(&tree, name); | ||
} | ||
|
||
void TPCVShapeScaler::loadFromFile(const char* inpf, const char* name) | ||
{ | ||
TFile out(inpf, "READ"); | ||
TTree* tree = (TTree*)out.Get(name); | ||
setFromTree(*tree); | ||
} | ||
|
||
void TPCVShapeScaler::setFromTree(TTree& TPCVShapeScalerTree) | ||
{ | ||
TPCVShapeScaler* scalerTmp = this; | ||
TPCVShapeScalerTree.SetBranchAddress("TPCVShapeScaler", &scalerTmp); | ||
const int entries = TPCVShapeScalerTree.GetEntries(); | ||
if (entries > 0) { | ||
TPCVShapeScalerTree.GetEntry(0); | ||
} else { | ||
LOGP(error, "TPCVShapeScaler not found in input file"); | ||
} | ||
TPCVShapeScalerTree.SetBranchAddress("TPCVShapeScaler", nullptr); | ||
} | ||
|
||
float TPCVShapeScaler::getScaler(const double timestamp) const | ||
{ | ||
auto idx = std::distance(mScalerA.begin(), std::lower_bound(mScalerA.begin(), mScalerA.end(), std::pair<double, float>(timestamp, std::numeric_limits<float>::min()))); | ||
|
||
if (idx == mScalerA.size()) { | ||
// check end range | ||
const double deltaTime = std::abs(mScalerA.back().first - timestamp); | ||
if (checkDeltaTime(deltaTime)) { | ||
return mScalerA.back().second; | ||
} | ||
} else if (idx == 0) { | ||
const double deltaTime = std::abs(mScalerA.front().first - timestamp); | ||
if (checkDeltaTime(deltaTime)) { | ||
return mScalerA.front().second; | ||
} | ||
} else { | ||
// check if upper or lower value is closer | ||
const double deltaTimeLow = std::abs(mScalerA[idx - 1].first - timestamp); | ||
const double deltaTimeUp = std::abs(mScalerA[idx].first - timestamp); | ||
|
||
// return closes value | ||
if ((deltaTimeLow < deltaTimeUp) && checkDeltaTime(deltaTimeLow)) { | ||
return mScalerA[idx - 1].second; | ||
} else if (checkDeltaTime(deltaTimeUp)) { | ||
return mScalerA[idx - 1].second; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.