diff --git a/PWGMM/Lumi/Tasks/CMakeLists.txt b/PWGMM/Lumi/Tasks/CMakeLists.txt index cc7418c07f5..154414e30cd 100644 --- a/PWGMM/Lumi/Tasks/CMakeLists.txt +++ b/PWGMM/Lumi/Tasks/CMakeLists.txt @@ -25,3 +25,12 @@ o2physics_add_dpl_workflow(lumifddft0 O2::DetectorsCommonDataFormats O2::DetectorsVertexing COMPONENT_NAME Analysis) + +o2physics_add_dpl_workflow(fitvdm + SOURCES fitLumi.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore + O2::ReconstructionDataFormats + O2::DetectorsBase + O2::DetectorsCommonDataFormats + O2::DetectorsVertexing + COMPONENT_NAME Analysis) diff --git a/PWGMM/Lumi/Tasks/fitLumi.cxx b/PWGMM/Lumi/Tasks/fitLumi.cxx new file mode 100644 index 00000000000..b1f153c3be9 --- /dev/null +++ b/PWGMM/Lumi/Tasks/fitLumi.cxx @@ -0,0 +1,115 @@ +// 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. + +// author: arvind.khuntia@cern.ch + +#include "Framework/runDataProcessing.h" +#include "Framework/AnalysisTask.h" +#include "Framework/AnalysisDataModel.h" +#include "Common/DataModel/EventSelection.h" +#include "DataFormatsFDD/Digit.h" +#include "DataFormatsFIT/Triggers.h" +#include "Common/DataModel/FT0Corrected.h" + +#include "CCDB/CcdbApi.h" +#include "CommonDataFormat/BunchFilling.h" +#include "CCDB/BasicCCDBManager.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DataFormatsParameters/GRPLHCIFData.h" +#include "TH1F.h" +#include "TH2F.h" + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; +using BCPattern = std::bitset; +const int nBCsPerOrbit = o2::constants::lhc::LHCMaxBunches; + +struct fitLumi { + int nTF = 0; + HistogramRegistry registry; + int nBins, nCollBins; + int relTS; + Configurable startTimeInS{"startTime", 1668079200, "unix start time"}; + Configurable endTimeInS{"endTime", 1668098700, "unix end time"}; + Configurable> collBCArray{"collBCArray", {1022, 1062, 1102, 1142, 2015, 2055, 2161, 2201, 2241, 2281, 2321, 2361, 2401, 2441, 2481, 2521, 2561, 2601, 2641, 2681}, "Colliding BC for the VdM"}; + + void init(InitContext&) + { + nBins = uint64_t(endTimeInS - startTimeInS) / 2.; + nCollBins = collBCArray->size(); + // Hist for FT0 + registry.add("FT0/VtxTrig", "vertex trigger;ts (s); Counts", {HistType::kTH1F, {{nBins, 0., static_cast(endTimeInS - startTimeInS)}}}); + registry.add("FT0/VtxTrigPerBC", "vertex trigger per BC;ts (s); Counts", {HistType::kTH2F, {{nBins, 0., static_cast(endTimeInS - startTimeInS)}, {nCollBins - 1, 0., static_cast(nCollBins)}}}); + registry.add("FT0/TF", "TF ;ts (s); Counts (nTF)", {HistType::kTH1F, {{nBins, 0., static_cast(endTimeInS - startTimeInS)}}}); + registry.add("FT0/CollBCMap", "BC map for the colliding bcsr;BC entry; entries", {HistType::kTH1F, {{nCollBins - 1, 0., static_cast(nCollBins)}}}); + // Hist for FDD + registry.add("FDD/VtxTrig", "vertex trigger;ts (s); Counts", {HistType::kTH1F, {{nBins, 0., static_cast(endTimeInS - startTimeInS)}}}); + registry.add("FDD/VtxTrigPerBC", "vertex trigger per BC;ts (s); Counts", {HistType::kTH2F, {{nBins, 0., static_cast(endTimeInS - startTimeInS)}, {nCollBins - 1, 0., static_cast(nCollBins)}}}); + } + + using BCsWithTimestamps = soa::Join; + void process(aod::FT0s const& ft0s, aod::FDDs const& fdds, aod::BCsWithTimestamps const&) + { + if (nTF < 1) { + for (int iBin = 0; iBin < nCollBins; iBin++) { + registry.get(HIST("FT0/CollBCMap"))->SetBinContent(iBin + 1, collBCArray->at(iBin)); + LOG(debug) << "bin " << iBin << " value " << collBCArray->at(iBin); + } + } + + for (auto const& ft0 : ft0s) { + auto bc = ft0.bc_as(); + if (!bc.timestamp()) { + continue; + } + std::bitset<8> fT0Triggers = ft0.triggerMask(); + auto localBC = bc.globalBC() % nBCsPerOrbit; + auto pos = std::find(collBCArray->begin(), collBCArray->end(), localBC); + bool vertex = fT0Triggers[o2::fdd::Triggers::bitVertex]; + auto tsInSecond = ((bc.timestamp() * 1.e-3) - startTimeInS); // covert ts from ms to second + if (vertex) { + registry.get(HIST("FT0/VtxTrig"))->Fill(tsInSecond); + if (pos != collBCArray->end()) { + registry.get(HIST("FT0/VtxTrigPerBC"))->Fill(tsInSecond, std::distance(collBCArray->begin(), pos)); + } + } // vertex + } // ft0 + + for (auto const& fdd : fdds) { + auto bc = fdd.bc_as(); + if (!bc.timestamp()) { + continue; + } + std::bitset<8> fddTriggers = fdd.triggerMask(); + auto localBC = bc.globalBC() % nBCsPerOrbit; + auto pos = std::find(collBCArray->begin(), collBCArray->end(), localBC); + bool vertex = fddTriggers[o2::fdd::Triggers::bitVertex]; + auto tsInSecond = ((bc.timestamp() * 1.e-3) - startTimeInS); // covert ts from ms to second + if (vertex) { + registry.get(HIST("FDD/VtxTrig"))->Fill(tsInSecond); + if (pos != collBCArray->end()) { + registry.get(HIST("FDD/VtxTrigPerBC"))->Fill(tsInSecond, std::distance(collBCArray->begin(), pos)); + } + } // vertex + } // fdd + + auto timeFirstInTFinS = ft0s.iteratorAt(0).bc_as().timestamp() * 1.e-3; + registry.get(HIST("FT0/TF"))->Fill(timeFirstInTFinS - startTimeInS); + nTF++; + } // process +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{ + adaptAnalysisTask(cfgc, TaskName{"ft0qavdm"})}; +}