Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/creetz16/O2Physics
Browse files Browse the repository at this point in the history
  • Loading branch information
creetz16 committed Feb 1, 2024
2 parents a4144f9 + 375831a commit 88a62e6
Show file tree
Hide file tree
Showing 313 changed files with 26,837 additions and 10,389 deletions.
2 changes: 2 additions & 0 deletions Common/CCDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
o2physics_add_library(AnalysisCCDB
SOURCES EventSelectionParams.cxx
SOURCES TriggerAliases.cxx
SOURCES ctpRateFetcher.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)

o2physics_target_root_dictionary(AnalysisCCDB
HEADERS EventSelectionParams.h
HEADERS TriggerAliases.h
HEADERS ctpRateFetcher.h
LINKDEF AnalysisCCDBLinkDef.h)
137 changes: 137 additions & 0 deletions Common/CCDB/ctpRateFetcher.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// 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.

#include "ctpRateFetcher.h"

#include <map>
#include <vector>

#include "CommonConstants/LHCConstants.h"
#include "DataFormatsCTP/Configuration.h"
#include "DataFormatsCTP/Scalers.h"
#include "DataFormatsParameters/GRPLHCIFData.h"
#include "CCDB/BasicCCDBManager.h"

namespace o2
{

using framework::Service;

double ctpRateFetcher::fetch(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, std::string sourceName)
{
if (sourceName.find("ZNC") != std::string::npos) {
if (runNumber < 544448) {
return fetchCTPratesInputs(ccdb, timeStamp, runNumber, 26) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
} else {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "C1ZNC-B-NOPF-CRU", 6) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
}
} else if (sourceName == "T0CE") {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVXTCE-B-NOPF-CRU");
} else if (sourceName == "T0SC") {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVXTSC-B-NOPF-CRU");
} else if (sourceName == "T0VTX") {
if (runNumber < 534202) {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "minbias_TVX_L0"); // 2022
} else {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVX-B-NOPF-CRU");
}
}
LOG(error) << "CTP rate for " << sourceName << " not available";
return -1.;
}

double ctpRateFetcher::fetchCTPratesClasses(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, std::string className, int inputType)
{
getCTPscalers(ccdb, timeStamp, runNumber);
getCTPconfig(ccdb, timeStamp, runNumber);

std::vector<ctp::CTPClass> ctpcls = mConfig->getCTPClasses();
std::vector<int> clslist = mConfig->getTriggerClassList();
int classIndex = -1;
for (size_t i = 0; i < clslist.size(); i++) {
if (ctpcls[i].name == className) {
classIndex = i;
break;
}
}
if (classIndex == -1) {
LOG(fatal) << "Trigger class " << className << " not found in CTPConfiguration";
}

auto rate{mScalers->getRateGivenT(timeStamp, classIndex, inputType)};

return pileUpCorrection(rate.second);
}

double ctpRateFetcher::fetchCTPratesInputs(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, int input)
{
getCTPscalers(ccdb, timeStamp, runNumber);
getLHCIFdata(ccdb, timeStamp, runNumber);

std::vector<ctp::CTPScalerRecordO2> recs = mScalers->getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
return pileUpCorrection(mScalers->getRateGivenT(timeStamp, input, 7).second);
} else {
LOG(error) << "Inputs not available";
return -1.;
}
}

void ctpRateFetcher::getCTPscalers(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber)
{
if (runNumber == mRunNumber && mScalers != nullptr) {
return;
}
std::map<string, string> metadata;
metadata["runNumber"] = std::to_string(runNumber);
mScalers = ccdb->getSpecific<ctp::CTPRunScalers>("CTP/Calib/Scalers", timeStamp, metadata);
if (mScalers == nullptr) {
LOG(fatal) << "CTPRunScalers not in database, timestamp:" << timeStamp;
}
mScalers->convertRawToO2();
}

void ctpRateFetcher::getLHCIFdata(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber)
{
if (runNumber == mRunNumber && mLHCIFdata != nullptr) {
return;
}
std::map<string, string> metadata;
mLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
if (mLHCIFdata == nullptr) {
LOG(fatal) << "GRPLHCIFData not in database, timestamp:" << timeStamp;
}
}

void ctpRateFetcher::getCTPconfig(Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber)
{
if (runNumber == mRunNumber && mConfig != nullptr) {
return;
}
std::map<string, string> metadata;
metadata["runNumber"] = std::to_string(runNumber);
mConfig = ccdb->getSpecific<ctp::CTPConfiguration>("CTP/Config/Config", timeStamp, metadata);
if (mConfig == nullptr) {
LOG(fatal) << "CTPRunConfig not in database, timestamp:" << timeStamp;
}
}

double ctpRateFetcher::pileUpCorrection(double triggerRate)
{
auto bfilling = mLHCIFdata->getBunchFilling();
std::vector<int> bcs = bfilling.getFilledBCs();
double nbc = bcs.size();
double nTriggersPerFilledBC = triggerRate / nbc / constants::lhc::LHCRevFreq;
double mu = -std::log(1 - nTriggersPerFilledBC);
return mu * nbc * constants::lhc::LHCRevFreq;
}

} // namespace o2
55 changes: 55 additions & 0 deletions Common/CCDB/ctpRateFetcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.

#ifndef COMMON_CCDB_CTPRATEFETCHER_H_
#define COMMON_CCDB_CTPRATEFETCHER_H_

#include <string>

#include "CCDB/BasicCCDBManager.h"
#include "Framework/AnalysisHelpers.h"

namespace o2
{

namespace ctp
{
class CTPRunScalers;
class CTPConfiguration;
} // namespace ctp

namespace parameters
{
class GRPLHCIFData;
}

class ctpRateFetcher
{
public:
ctpRateFetcher() = default;
double fetch(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, std::string sourceName);

private:
void getCTPconfig(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber);
void getCTPscalers(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber);
void getLHCIFdata(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber);
double fetchCTPratesInputs(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, int input);
double fetchCTPratesClasses(framework::Service<o2::ccdb::BasicCCDBManager>& ccdb, uint64_t timeStamp, int runNumber, std::string className, int inputType = 1);
double pileUpCorrection(double rate);

int mRunNumber = -1;
ctp::CTPConfiguration* mConfig = nullptr;
ctp::CTPRunScalers* mScalers = nullptr;
parameters::GRPLHCIFData* mLHCIFdata = nullptr;
};
} // namespace o2

#endif // COMMON_CCDB_CTPRATEFETCHER_H_
2 changes: 1 addition & 1 deletion Common/Core/PID/PIDTOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class ExpTimes
/// Gets the number of sigmas with respect the expected time
/// \param parameters Detector response parameters
/// \param track Track of interest
static float GetSeparation(const TOFResoParamsV2& parameters, const TrackType& track) { return GetSeparation(parameters, track, track.tofEvTime(), track.tofEvTimeErr()); }
static float GetSeparation(const TOFResoParamsV2& parameters, const TrackType& track) { return GetSeparation(parameters, track, track.tofEvTime(), GetExpectedSigma(parameters, track)); }
};

/// \brief Class to convert the trackTime to the tofSignal used for PID
Expand Down
6 changes: 5 additions & 1 deletion Common/DataModel/PIDResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ enum PIDFlags : uint8_t {
};
}

DECLARE_SOA_COLUMN(TOFFlags, tofFlags, uint8_t); //! Flag for the complementary TOF PID information
DECLARE_SOA_COLUMN(GoodTOFMatch, goodTOFMatch, bool); //! Bool for the TOF PID information on the single track information
DECLARE_SOA_COLUMN(TOFFlags, tofFlags, uint8_t); //! Flag for the complementary TOF PID information for the event time
DECLARE_SOA_DYNAMIC_COLUMN(IsEvTimeDefined, isEvTimeDefined, //! True if the Event Time was computed with any method i.e. there is a usable event time
[](uint8_t flags) -> bool { return (flags > 0); });
DECLARE_SOA_DYNAMIC_COLUMN(IsEvTimeTOF, isEvTimeTOF, //! True if the Event Time was computed with the TOF
Expand Down Expand Up @@ -529,6 +530,9 @@ DEFINE_UNWRAP_NSIGMA_COLUMN(TOFNSigmaAl, tofNSigmaAl); //! Unwrapped (float) nsi
DECLARE_SOA_TABLE(TOFSignal, "AOD", "TOFSignal", //! Table of the TOF signal
pidtofsignal::TOFSignal);

DECLARE_SOA_TABLE(pidTOFFlags, "AOD", "pidTOFFlags", //! Table of the flags for TOF signal quality on the track level
pidflags::GoodTOFMatch);

DECLARE_SOA_TABLE(pidTOFbeta, "AOD", "pidTOFbeta", //! Table of the TOF beta
pidtofbeta::Beta, pidtofbeta::BetaError);

Expand Down
52 changes: 48 additions & 4 deletions Common/TableProducer/PID/pidTOFBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Common/DataModel/TrackSelectionTables.h"
#include "Common/DataModel/EventSelection.h"
#include "Common/DataModel/FT0Corrected.h"
#include "Common/DataModel/Multiplicity.h"
#include "TableHelper.h"
#include "pidTOFBase.h"

Expand All @@ -47,14 +48,36 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)

#include "Framework/runDataProcessing.h"

/// Selection criteria for tracks used for TOF event time
float trackDistanceForGoodMatch = 999.f;
float trackDistanceForGoodMatchLowMult = 999.f;
int multiplicityThreshold = 0;
using Run3Trks = o2::soa::Join<aod::TracksIU, aod::TracksExtra>;
using Run3Cols = o2::soa::Join<aod::Collisions, aod::PVMults>;
bool isTrackGoodMatchForTOFPID(const Run3Trks::iterator& tr, const Run3Cols& ev)
{
if (!tr.hasTOF()) {
return false;
}
if (tr.has_collision() && tr.collision_as<Run3Cols>().multNTracksPVeta1() < multiplicityThreshold) {
return tr.tofChi2() < trackDistanceForGoodMatchLowMult;
}
return tr.tofChi2() < trackDistanceForGoodMatch;
}

/// Task to produce the TOF signal from the trackTime information
struct tofSignal {
o2::framework::Produces<o2::aod::TOFSignal> table;
bool enableTable = false;
o2::framework::Produces<o2::aod::pidTOFFlags> tableFlags;
bool enableTable = false; // Flag to check if the TOF signal table is requested or not
bool enableTableFlags = false; // Flag to check if the TOF signal flags table is requested or not
// CCDB configuration
Configurable<std::string> url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<int64_t> timestamp{"ccdb-timestamp", -1, "timestamp of the object"};
Configurable<std::string> timeShiftCCDBPath{"timeShiftCCDBPath", "", "Path of the TOF time shift vs eta. If empty none is taken"};
Configurable<float> distanceForGoodMatch{"distanceForGoodMatch", 999.f, "Maximum distance to consider a good match"};
Configurable<float> distanceForGoodMatchLowMult{"distanceForGoodMatchLowMult", 999.f, "Maximum distance to consider a good match for low multiplicity events"};
Configurable<int> multThreshold{"multThreshold", 0, "Multiplicity threshold to consider a low multiplicity event"};

void init(o2::framework::InitContext& initContext)
{
Expand All @@ -70,16 +93,30 @@ struct tofSignal {
if (enableTable) {
LOG(info) << "Table TOFSignal enabled!";
}
enableTableFlags = isTableRequiredInWorkflow(initContext, "pidTOFFlags");
if (enableTableFlags) {
LOG(info) << "Table pidTOFFlags enabled!";
}
trackDistanceForGoodMatch = distanceForGoodMatch;
trackDistanceForGoodMatchLowMult = distanceForGoodMatchLowMult;
multiplicityThreshold = multThreshold;
LOG(info) << "Configuring selections for good match: " << trackDistanceForGoodMatch << " low mult " << trackDistanceForGoodMatchLowMult << " mult. threshold " << multiplicityThreshold;
}
using Trks = o2::soa::Join<aod::TracksIU, aod::TracksExtra>;
void processRun3(Trks const& tracks)
void processRun3(Run3Trks const& tracks, Run3Cols const& collisions)
{
if (!enableTable) {
return;
}
table.reserve(tracks.size());
if (enableTableFlags) {
tableFlags.reserve(tracks.size());
}
for (auto& t : tracks) {
table(o2::pid::tof::TOFSignal<Trks::iterator>::GetTOFSignal(t));
table(o2::pid::tof::TOFSignal<Run3Trks::iterator>::GetTOFSignal(t));
if (!enableTableFlags) {
continue;
}
tableFlags(isTrackGoodMatchForTOFPID(t, collisions));
}
}
PROCESS_SWITCH(tofSignal, processRun3, "Process Run3 data i.e. input is TrackIU", true);
Expand All @@ -91,8 +128,15 @@ struct tofSignal {
return;
}
table.reserve(tracks.size());
if (enableTableFlags) {
tableFlags.reserve(tracks.size());
}
for (auto& t : tracks) {
table(o2::pid::tof::TOFSignal<TrksRun2::iterator>::GetTOFSignal(t));
if (!enableTableFlags) {
continue;
}
tableFlags(true);
}
}
PROCESS_SWITCH(tofSignal, processRun2, "Process Run2 data i.e. input is Tracks", false);
Expand Down
4 changes: 2 additions & 2 deletions Common/TableProducer/eventSelection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ struct BcSelectionTask {
float csZEM = isPP ? -1. : 415.2e6;
float csZNC = isPP ? -1. : 214.5e6;
if (run > 543437 && run < 543514) {
csTCE = 8.3;
csTCE = 8.3e6;
}
if (run >= 543514) {
csTCE = 3.97;
csTCE = 3.97e6;
}

// Fill TVX (T0 vertex) counters
Expand Down
17 changes: 9 additions & 8 deletions Common/TableProducer/ft0CorrectedTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
// 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.
#include "Framework/ConfigParamSpec.h"

using namespace o2;
using namespace o2::framework;

#include <bitset>
#include "Common/DataModel/FT0Corrected.h"
#include "Framework/ConfigParamSpec.h"
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "Common/DataModel/EventSelection.h"
#include "Framework/AnalysisDataModel.h"
#include "CommonConstants/LHCConstants.h"
#include "CommonConstants/PhysicsConstants.h"
#include "Common/DataModel/FT0Corrected.h"
#include "DataFormatsFT0/Digit.h"
#include <bitset>

using namespace o2;
using namespace o2::framework;

using namespace o2::aod;
struct FT0CorrectedTable {
Expand All @@ -36,17 +36,18 @@ struct FT0CorrectedTable {
float vertex_corr = vertexPV / o2::constants::physics::LightSpeedCm2NS;
float t0A = 1e10;
float t0C = 1e10;
constexpr float dummyTime = 30.; // Due to HW limitations time can be only within range (-25,25) ns, dummy time is around 32 ns
if (collision.has_foundFT0()) {
auto ft0 = collision.foundFT0();
std::bitset<8> triggers = ft0.triggerMask();
bool ora = triggers[o2::ft0::Triggers::bitA];
bool orc = triggers[o2::ft0::Triggers::bitC];
LOGF(debug, "triggers OrA %i OrC %i ", ora, orc);
LOGF(debug, " T0A = %f, T0C %f, vertex_corr %f", ft0.timeA(), ft0.timeC(), vertex_corr);
if (ora) {
if (ora && ft0.timeA() < dummyTime) {
t0A = ft0.timeA() + vertex_corr;
}
if (orc) {
if (orc && ft0.timeC() < dummyTime) {
t0C = ft0.timeC() - vertex_corr;
}
}
Expand Down
Loading

0 comments on commit 88a62e6

Please sign in to comment.