|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file eventSelectionTester.cxx |
| 13 | +/// \brief unified, self-configuring event selection task |
| 14 | +/// \author ALICE |
| 15 | + |
| 16 | +//=============================================================== |
| 17 | +// |
| 18 | +// Unified, self-configuring event selection task |
| 19 | +// |
| 20 | +//=============================================================== |
| 21 | + |
| 22 | +#include "MetadataHelper.h" |
| 23 | + |
| 24 | +#include "Common/Core/trackUtilities.h" |
| 25 | +#include "Common/DataModel/TrackSelectionTables.h" |
| 26 | +#include "Common/Tools/EventSelectionTools.h" |
| 27 | + |
| 28 | +#include "CCDB/BasicCCDBManager.h" |
| 29 | +#include "CCDB/CcdbApi.h" |
| 30 | +#include "CommonConstants/GeomConstants.h" |
| 31 | +#include "CommonUtils/NameConf.h" |
| 32 | +#include "DataFormatsCalibration/MeanVertexObject.h" |
| 33 | +#include "DataFormatsParameters/GRPMagField.h" |
| 34 | +#include "DetectorsBase/GeometryManager.h" |
| 35 | +#include "DetectorsBase/Propagator.h" |
| 36 | +#include "Framework/AnalysisDataModel.h" |
| 37 | +#include "Framework/AnalysisTask.h" |
| 38 | +#include "Framework/HistogramRegistry.h" |
| 39 | +#include "Framework/RunningWorkflowInfo.h" |
| 40 | +#include "Framework/runDataProcessing.h" |
| 41 | +#include "ReconstructionDataFormats/DCA.h" |
| 42 | + |
| 43 | +using namespace o2; |
| 44 | +using namespace o2::framework; |
| 45 | + |
| 46 | +MetadataHelper metadataInfo; // Metadata helper |
| 47 | + |
| 48 | +using BCsWithRun2InfosTimestampsAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Timestamps, aod::Run2MatchedToBCSparse>; |
| 49 | +using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Timestamps, aod::Run3MatchedToBCSparse>; |
| 50 | +using FullTracks = soa::Join<aod::Tracks, aod::TracksExtra>; |
| 51 | +using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>; |
| 52 | + |
| 53 | +struct eventselectionRun2 { |
| 54 | + o2::common::eventselection::bcselConfigurables bcselOpts; |
| 55 | + o2::common::eventselection::BcSelectionModule bcselmodule; |
| 56 | + |
| 57 | + o2::common::eventselection::evselConfigurables evselOpts; |
| 58 | + o2::common::eventselection::EventSelectionModule evselmodule; |
| 59 | + |
| 60 | + Produces<aod::BcSels> bcsel; |
| 61 | + Produces<aod::EvSels> evsel; |
| 62 | + |
| 63 | + // for slicing |
| 64 | + SliceCache cache; |
| 65 | + |
| 66 | + // CCDB boilerplate declarations |
| 67 | + o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 68 | + Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 69 | + |
| 70 | + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; |
| 71 | + |
| 72 | + // the best: have readable cursors |
| 73 | + // this: a stopgap solution to avoid spawning yet another device |
| 74 | + std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer; |
| 75 | + |
| 76 | + // auxiliary |
| 77 | + Partition<FullTracks> tracklets = (aod::track::trackType == static_cast<uint8_t>(o2::aod::track::TrackTypeEnum::Run2Tracklet)); |
| 78 | + Preslice<FullTracks> perCollision = aod::track::collisionId; |
| 79 | + |
| 80 | + void init(o2::framework::InitContext& context) |
| 81 | + { |
| 82 | + // CCDB boilerplate init |
| 83 | + ccdb->setCaching(true); |
| 84 | + ccdb->setLocalObjectValidityChecking(); |
| 85 | + ccdb->setURL(ccdburl.value); |
| 86 | + |
| 87 | + // task-specific |
| 88 | + bcselmodule.init(context, bcselOpts, histos); |
| 89 | + evselmodule.init(context, evselOpts, histos, metadataInfo); |
| 90 | + } |
| 91 | + |
| 92 | + void process(BCsWithRun2InfosTimestampsAndMatches const& bcs, |
| 93 | + aod::Collisions const& collisions, |
| 94 | + aod::Zdcs const&, |
| 95 | + aod::FV0As const&, |
| 96 | + aod::FV0Cs const&, |
| 97 | + aod::FT0s const&, |
| 98 | + aod::FDDs const&, |
| 99 | + FullTracks const&) |
| 100 | + { |
| 101 | + bcselmodule.processRun2(ccdb, bcs, bcselsbuffer, bcsel); |
| 102 | + evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, bcselsbuffer, evsel); |
| 103 | + } |
| 104 | +}; |
| 105 | + |
| 106 | +struct eventselectionRun3 { |
| 107 | + o2::common::eventselection::bcselConfigurables bcselOpts; |
| 108 | + o2::common::eventselection::BcSelectionModule bcselmodule; |
| 109 | + |
| 110 | + o2::common::eventselection::evselConfigurables evselOpts; |
| 111 | + o2::common::eventselection::EventSelectionModule evselmodule; |
| 112 | + |
| 113 | + o2::common::eventselection::lumiConfigurables lumiOpts; |
| 114 | + o2::common::eventselection::LumiModule lumimodule; |
| 115 | + |
| 116 | + Produces<aod::BcSels> bcsel; |
| 117 | + Produces<aod::EvSels> evsel; |
| 118 | + |
| 119 | + // for slicing |
| 120 | + SliceCache cache; |
| 121 | + |
| 122 | + // CCDB boilerplate declarations |
| 123 | + o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 124 | + Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 125 | + |
| 126 | + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; |
| 127 | + |
| 128 | + // the best: have readable cursors |
| 129 | + // this: a stopgap solution to avoid spawning yet another device |
| 130 | + std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer; |
| 131 | + |
| 132 | + // auxiliary |
| 133 | + Partition<FullTracksIU> pvTracks = ((aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor)); |
| 134 | + Preslice<FullTracksIU> perCollisionIU = aod::track::collisionId; |
| 135 | + |
| 136 | + void init(o2::framework::InitContext& context) |
| 137 | + { |
| 138 | + // CCDB boilerplate init |
| 139 | + ccdb->setCaching(true); |
| 140 | + ccdb->setLocalObjectValidityChecking(); |
| 141 | + ccdb->setURL(ccdburl.value); |
| 142 | + |
| 143 | + // task-specific |
| 144 | + bcselmodule.init(context, bcselOpts, histos); |
| 145 | + evselmodule.init(context, evselOpts, histos, metadataInfo); |
| 146 | + lumimodule.init(context, lumiOpts, histos); |
| 147 | + } |
| 148 | + |
| 149 | + void process(aod::Collisions const& collisions, |
| 150 | + BCsWithRun3Matchings const& bcs, |
| 151 | + aod::Zdcs const&, |
| 152 | + aod::FV0As const&, |
| 153 | + aod::FT0s const& ft0s, // to resolve iterator |
| 154 | + aod::FDDs const&, |
| 155 | + FullTracksIU const&) |
| 156 | + { |
| 157 | + bcselmodule.processRun3(ccdb, histos, bcs, bcselsbuffer, bcsel); |
| 158 | + evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, bcselsbuffer, evsel); |
| 159 | + lumimodule.process(ccdb, histos, bcs, bcselsbuffer); |
| 160 | + } |
| 161 | +}; |
| 162 | + |
| 163 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 164 | +{ |
| 165 | + // Parse the metadata for later too |
| 166 | + metadataInfo.initMetadata(cfgc); |
| 167 | + |
| 168 | + bool isRun3 = true, hasRunInfo = false; |
| 169 | + if (cfgc.options().hasOption("aod-metadata-Run") == true) { |
| 170 | + hasRunInfo = true; |
| 171 | + if (cfgc.options().get<std::string>("aod-metadata-Run") == "2") { |
| 172 | + isRun3 = false; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + LOGF(info, "Event selection autoconfiguring from metadata. Availability of info for Run 2/3 is %i", hasRunInfo); |
| 177 | + if (!hasRunInfo) { |
| 178 | + LOGF(info, "Metadata info missing or incomplete. Make sure --aod-file is provided at the end of the last workflow and that the AO2D has metadata stored."); |
| 179 | + LOGF(info, "Initializing with Run 3 data as default. Please note you will not be able to change settings manually."); |
| 180 | + LOGF(info, "You should instead make sure the metadata is read in correctly."); |
| 181 | + return WorkflowSpec{adaptAnalysisTask<eventselectionRun3>(cfgc)}; |
| 182 | + } else { |
| 183 | + LOGF(info, "Metadata successfully read in. Is this Run 3? %i - will self-configure.", isRun3); |
| 184 | + if (isRun3) { |
| 185 | + return WorkflowSpec{adaptAnalysisTask<eventselectionRun3>(cfgc)}; |
| 186 | + } else { |
| 187 | + return WorkflowSpec{adaptAnalysisTask<eventselectionRun2>(cfgc)}; |
| 188 | + } |
| 189 | + } |
| 190 | + throw std::runtime_error("Unsupported run type / problem when configuring event selection!"); |
| 191 | +} |
0 commit comments