Skip to content

Commit 96327f9

Browse files
committed
Fix for tableReader_withAss_direct task (Zorro and CCDB paths) + minor fix in dqEff-direct task
1 parent 8105cad commit 96327f9

File tree

3 files changed

+169
-15
lines changed

3 files changed

+169
-15
lines changed

PWGDQ/Tasks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ o2physics_add_dpl_workflow(table-reader-with-assoc
2121

2222
o2physics_add_dpl_workflow(table-reader-with-assoc-direct
2323
SOURCES tableReader_withAssoc_direct.cxx
24-
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsBase O2Physics::AnalysisCore O2Physics::AnalysisCCDB O2Physics::PWGDQCore O2Physics::MLCore O2::ReconstructionDataFormats O2::DetectorsCommonDataFormats O2::DetectorsVertexing
24+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsBase O2Physics::AnalysisCore O2Physics::AnalysisCCDB O2Physics::PWGDQCore O2Physics::MLCore O2::ReconstructionDataFormats O2::DetectorsCommonDataFormats O2::DetectorsVertexing O2Physics::EventFilteringUtils
2525
COMPONENT_NAME Analysis)
2626

2727
o2physics_add_dpl_workflow(efficiency

PWGDQ/Tasks/dqEfficiency_withAssoc_direct.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,11 @@ struct AnalysisTrackSelection {
736736
trackSel(0);
737737
continue;
738738
}
739-
739+
///
740+
auto track = tracks.rawIteratorAt(assoc.trackId());
741+
auto evFromTrack = events.rawIteratorAt(track.collisionId());
742+
if (!evFromTrack.isEventSelected_bit(0)) { trackSel(0); continue;}
743+
740744
// cout << "Processing association: event global index " << event.globalIndex() << endl;
741745
VarManager::ResetValues(VarManager::kNTFWiseVariables, VarManager::kNBarrelTrackVariables);
742746
// fill event information which might be needed in histograms/cuts that combine track and event properties
@@ -746,9 +750,9 @@ struct AnalysisTrackSelection {
746750
}
747751
// cout << "Filled event observables for association" << endl;
748752

749-
auto track = tracks.rawIteratorAt(assoc.trackId());
750753
VarManager::FillTrack<TTrackFillMap>(track);
751754
// compute quantities which depend on the associated collision, such as DCA
755+
if(track.collisionId() != event.globalIndex())
752756
VarManager::FillTrackCollision<TTrackFillMap>(track, event);
753757
// cout << "Filled track observables for association" << endl;
754758

PWGDQ/Tasks/tableReader_withAssoc_direct.cxx

Lines changed: 162 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#include "Common/DataModel/TrackSelectionTables.h"
3232
#include <Common/Core/trackUtilities.h>
3333

34+
#include "Common/CCDB/TriggerAliases.h"
35+
#include "Common/CCDB/ctpRateFetcher.h"
36+
#include "Common/Core/Zorro.h"
37+
38+
3439
#include "CCDB/BasicCCDBManager.h"
3540
#include "DataFormatsParameters/GRPMagField.h"
3641
#include "DataFormatsParameters/GRPObject.h"
@@ -70,6 +75,8 @@ using namespace o2::framework;
7075
using namespace o2::framework::expressions;
7176
using namespace o2::aod;
7277

78+
Zorro zorro;
79+
7380
// Some definitions
7481
namespace o2::aod
7582
{
@@ -233,10 +240,17 @@ void PrintBitMap(TMap map, int nbits)
233240
}
234241
}
235242

243+
// Enum containing the ordering of statistics histograms to be written in the QA file
244+
enum ZorroStatHist {
245+
kStatsZorroInfo=0,
246+
kStatsZorroSel
247+
};
248+
236249
struct AnalysisEventSelection {
237250
Produces<aod::EventCuts> eventSel;
238251
Produces<aod::MixingHashes> hash;
239252
OutputObj<THashList> fOutputList{"output"};
253+
OutputObj<TList> fStatsList{"Statistics"};
240254
Configurable<std::string> fConfigMixingVariables{"cfgMixingVars", "", "Mixing configs separated by a comma, default no mixing"};
241255
Configurable<std::string> fConfigEventCuts{"cfgEventCuts", "eventStandard", "Event selection"};
242256
Configurable<std::string> fConfigEventCutsJSON{"cfgEventCutsJSON", "", "Additional event cuts specified in JSON format"};
@@ -248,14 +262,55 @@ struct AnalysisEventSelection {
248262
Configurable<unsigned int> fConfigSplitCollisionsDeltaBC{"cfgSplitCollisionsDeltaBC", 100, "maximum delta-BC between two collisions to consider them as split candidates; do not apply if value is negative"};
249263
Configurable<bool> fConfigCheckSplitCollisions{"cfgCheckSplitCollisions", false, "If true, run the split collision check and fill histograms"};
250264

251-
Configurable<std::string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
252-
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
265+
// Zorro selection
266+
struct : ConfigurableGroup {
267+
Configurable<bool> fConfigRunZorro{"cfgRunZorro", false, "Enable event selection with zorro"};
268+
Configurable<std::string> fConfigZorroTrigMask{"cfgZorroTriggerMask", "fDiMuon", "DQ Trigger masks: fSingleE,fLMeeIMR,fLMeeHMR,fDiElectron,fSingleMuLow,fSingleMuHigh,fDiMuon"};
269+
Configurable<bool> fConfigRunZorroSel{"cfgRunZorroSel", false, "Select events with trigger mask"};
270+
Configurable<uint64_t> fBcTolerance{"cfgBcTolerance", 100, "Number of BCs of margin for software triggers"};
271+
Configurable<std::string> fConfigCcdbPathZorro{"ccdb-path-zorro", "/Users/m/mpuccio/EventFiltering/OTS/Chunked/", "base path to the ccdb object for zorro"};
272+
} fConfigZorro;
273+
274+
// RCT selection
275+
struct : ConfigurableGroup {
276+
Configurable<bool> fConfigUseRCT{"cfgUseRCT", false, "Enable event selection with RCT flags"};
277+
Configurable<std::string> fConfigRCTLabel{"cfgRCTLabel", "CBT", "RCT flag labels : CBT, CBT_hadronPID, CBT_electronPID, CBT_calo, CBT_muon, CBT_muon_glo"};
278+
} fConfigRCT;
279+
280+
// CCDB connection configurables
281+
struct : ConfigurableGroup {
282+
Configurable<std::string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
283+
Configurable<std::string> fConfigCcdbPathTPC{"ccdb-path-tpc", "Users/z/zhxiong/TPCPID/PostCalib", "base path to the ccdb object"};
284+
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
285+
Configurable<std::string> fConfigGeoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
286+
Configurable<std::string> fConfigGrpMagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
287+
Configurable<std::string> fZShiftPath{"zShiftPath", "Users/m/mcoquet/ZShift", "CCDB path for z shift to apply to forward tracks"};
288+
Configurable<std::string> fConfigGrpMagPathRun2{"grpmagPathRun2", "GLO/GRP/GRP", "CCDB path of the GRPObject (Usage for Run 2)"};
289+
} fConfigCCDB;
290+
291+
// TPC postcalibration related options
292+
struct : ConfigurableGroup {
293+
Configurable<bool> fConfigComputeTPCpostCalib{"cfgTPCpostCalib", false, "If true, compute TPC post-calibrated n-sigmas(electrons, pions, protons)"};
294+
Configurable<int> fConfigTPCpostCalibType{"cfgTPCpostCalibType", 1, "1: (TPCncls,pIN,eta) calibration typically for pp, 2: (eta,nPV,nLong,tLong) calibration typically for PbPb"};
295+
Configurable<bool> fConfigTPCuseInterpolatedCalib{"cfgTPCpostCalibUseInterpolation", true, "If true, use interpolated calibration values (default: true)"};
296+
Configurable<bool> fConfigComputeTPCpostCalibKaon{"cfgTPCpostCalibKaon", false, "If true, compute TPC post-calibrated n-sigmas for kaons"};
297+
Configurable<bool> fConfigIsOnlyforMaps{"cfgIsforMaps", false, "If true, run for postcalibration maps only"};
298+
Configurable<bool> fConfigSaveElectronSample{"cfgSaveElectronSample", false, "If true, only save electron sample"};
299+
} fConfigPostCalibTPC;
300+
301+
Configurable<bool> fIsRun2{"cfgIsRun2", false, "Whether we analyze Run-2 or Run-3 data"};
302+
303+
// RCT flag checker
304+
o2::aod::rctsel::RCTFlagsChecker rctChecker{"CBT"};
253305

254306
HistogramManager* fHistMan = nullptr;
255307
MixingHandler* fMixHandler = nullptr;
256308

257309
AnalysisCompositeCut* fEventCut;
258310

311+
o2::parameters::GRPObject* fGrpMagRun2 = nullptr; // for run 2, we access the GRPObject from GLO/GRP/GRP
312+
o2::parameters::GRPMagField* fGrpMag = nullptr; // for run 3, we access GRPMagField from GLO/Config/GRPMagField
313+
259314
Service<o2::ccdb::BasicCCDBManager> fCCDB;
260315
o2::ccdb::CcdbApi fCCDBApi;
261316

@@ -304,6 +359,16 @@ struct AnalysisEventSelection {
304359
fOutputList.setObject(fHistMan->GetMainHistogramList());
305360
}
306361

362+
// Zorro information: kStatsZorroInfo
363+
// Zorro trigger selection: kStatsZorroSel
364+
fStatsList.setObject(new TList());
365+
fStatsList->SetOwner(kTRUE);
366+
TH2D* histZorroInfo = new TH2D("ZorroInfo", "Zorro information", 1, -0.5, 0.5, 1, -0.5, 0.5);
367+
fStatsList->AddAt(histZorroInfo, kStatsZorroInfo);
368+
369+
TH2D* histZorroSel = new TH2D("ZorroSel", "trigger of interested", 1, -0.5, 0.5, 1, -0.5, 0.5);
370+
fStatsList->AddAt(histZorroSel, kStatsZorroSel);
371+
307372
TString mixVarsString = fConfigMixingVariables.value;
308373
std::unique_ptr<TObjArray> objArray(mixVarsString.Tokenize(","));
309374
if (objArray->GetEntries() > 0) {
@@ -315,25 +380,78 @@ struct AnalysisEventSelection {
315380
}
316381

317382
fCurrentRun = -1;
318-
fCCDB->setURL(fConfigCcdbUrl.value);
383+
fCCDB->setURL(fConfigCCDB.fConfigCcdbUrl.value);
319384
fCCDB->setCaching(true);
320385
fCCDB->setLocalObjectValidityChecking();
321-
fCCDB->setCreatedNotAfter(fConfigNoLaterThan.value);
322-
fCCDBApi.init(fConfigCcdbUrl.value);
386+
fCCDB->setCreatedNotAfter(fConfigCCDB.fConfigNoLaterThan.value);
387+
fCCDBApi.init(fConfigCCDB.fConfigCcdbUrl.value);
388+
389+
if (!o2::base::GeometryManager::isGeometryLoaded()) {
390+
fCCDB->get<TGeoManager>(fConfigCCDB.fConfigGeoPath.value);
391+
}
392+
393+
if (fConfigRCT.fConfigUseRCT.value) {
394+
rctChecker.init(fConfigRCT.fConfigRCTLabel);
395+
}
396+
323397
cout << "AnalysisEventSelection::init() completed" << endl;
324398
}
325399

326400
template <uint32_t TEventFillMap, typename TEvents>
327401
void runEventSelection(TEvents const& events, BCsWithTimestamps const& bcs)
328402
{
329403
cout << "AnalysisEventSelection::runEventSelection() called with " << events.size() << " events and " << bcs.size() << " BCs" << endl;
330-
if (bcs.size() > 0 && bcs.begin().runNumber() != fCurrentRun) {
404+
405+
if (bcs.size() > 0 && fCurrentRun != bcs.begin().runNumber()) {
406+
if (fConfigPostCalibTPC.fConfigComputeTPCpostCalib) {
407+
auto calibList = fCCDB->getForTimeStamp<TList>(fConfigCCDB.fConfigCcdbPathTPC.value, bcs.begin().timestamp());
408+
VarManager::SetCalibrationObject(VarManager::kTPCElectronMean, calibList->FindObject("mean_map_electron"));
409+
VarManager::SetCalibrationObject(VarManager::kTPCElectronSigma, calibList->FindObject("sigma_map_electron"));
410+
VarManager::SetCalibrationObject(VarManager::kTPCPionMean, calibList->FindObject("mean_map_pion"));
411+
VarManager::SetCalibrationObject(VarManager::kTPCPionSigma, calibList->FindObject("sigma_map_pion"));
412+
VarManager::SetCalibrationObject(VarManager::kTPCProtonMean, calibList->FindObject("mean_map_proton"));
413+
VarManager::SetCalibrationObject(VarManager::kTPCProtonSigma, calibList->FindObject("sigma_map_proton"));
414+
if (fConfigPostCalibTPC.fConfigComputeTPCpostCalibKaon) {
415+
VarManager::SetCalibrationObject(VarManager::kTPCKaonMean, calibList->FindObject("mean_map_kaon"));
416+
VarManager::SetCalibrationObject(VarManager::kTPCKaonSigma, calibList->FindObject("sigma_map_kaon"));
417+
}
418+
if (fConfigPostCalibTPC.fConfigTPCpostCalibType == 2) {
419+
VarManager::SetCalibrationObject(VarManager::kTPCElectronStatus, calibList->FindObject("status_map_electron"));
420+
VarManager::SetCalibrationObject(VarManager::kTPCPionStatus, calibList->FindObject("status_map_pion"));
421+
VarManager::SetCalibrationObject(VarManager::kTPCProtonStatus, calibList->FindObject("status_map_proton"));
422+
if (fConfigPostCalibTPC.fConfigComputeTPCpostCalibKaon) {
423+
VarManager::SetCalibrationObject(VarManager::kTPCKaonStatus, calibList->FindObject("status_map_kaon"));
424+
}
425+
}
426+
VarManager::SetCalibrationType(fConfigPostCalibTPC.fConfigTPCpostCalibType, fConfigPostCalibTPC.fConfigTPCuseInterpolatedCalib);
427+
}
428+
if (fIsRun2 == true) {
429+
fGrpMagRun2 = fCCDB->getForTimeStamp<o2::parameters::GRPObject>(fConfigCCDB.fConfigGrpMagPathRun2, bcs.begin().timestamp());
430+
if (fGrpMagRun2 != nullptr) {
431+
o2::base::Propagator::initFieldFromGRP(fGrpMagRun2);
432+
}
433+
} else {
434+
fGrpMag = fCCDB->getForTimeStamp<o2::parameters::GRPMagField>(fConfigCCDB.fConfigGrpMagPath, bcs.begin().timestamp());
435+
auto* fZShift = fCCDB->getForTimeStamp<std::vector<float>>(fConfigCCDB.fZShiftPath, bcs.begin().timestamp());
436+
if (fGrpMag != nullptr) {
437+
o2::base::Propagator::initFieldFromGRP(fGrpMag);
438+
VarManager::SetMagneticField(fGrpMag->getNominalL3Field());
439+
}
440+
if (fZShift != nullptr && !fZShift->empty()) {
441+
VarManager::SetZShift((*fZShift)[0]);
442+
}
443+
/*if (fConfigVariousOptions.fPropMuon) {
444+
VarManager::SetupMuonMagField();
445+
}*/
446+
}
331447
std::map<std::string, std::string> metadataRCT, header;
332448
header = fCCDBApi.retrieveHeaders(Form("RCT/Info/RunInformation/%i", bcs.begin().runNumber()), metadataRCT, -1);
333449
uint64_t sor = std::atol(header["SOR"].c_str());
334450
uint64_t eor = std::atol(header["EOR"].c_str());
335451
VarManager::SetSORandEOR(sor, eor);
336-
}
452+
453+
fCurrentRun = bcs.begin().runNumber();
454+
} // end updating the CCDB quantities at change of run
337455

338456
cout << "Filling TimeFrame statistics histograms" << endl;
339457
VarManager::ResetValues(0, VarManager::kNEventWiseVariables);
@@ -358,12 +476,33 @@ struct AnalysisEventSelection {
358476
if (fConfigQA) {
359477
fHistMan->FillHistClass("Event_BeforeCuts", VarManager::fgValues);
360478
}
361-
if (fEventCut->IsSelected(VarManager::fgValues)) {
362-
if (fConfigQA) {
363-
fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
479+
480+
if (fConfigZorro.fConfigRunZorro) {
481+
zorro.setBaseCCDBPath(fConfigZorro.fConfigCcdbPathZorro.value);
482+
zorro.setBCtolerance(fConfigZorro.fBcTolerance);
483+
zorro.initCCDB(fCCDB.service, fCurrentRun, bc.timestamp(), fConfigZorro.fConfigZorroTrigMask.value);
484+
zorro.populateExternalHists(fCurrentRun, reinterpret_cast<TH2D*>(fStatsList->At(kStatsZorroInfo)), reinterpret_cast<TH2D*>(fStatsList->At(kStatsZorroSel)));
485+
486+
if (!fEventCut->IsSelected(VarManager::fgValues) || (fConfigRCT.fConfigUseRCT.value && !rctChecker(event))) {
487+
continue;
364488
}
365-
decision = true;
489+
490+
bool zorroSel = zorro.isSelected(bc.globalBC(), fConfigZorro.fBcTolerance, reinterpret_cast<TH2D*>(fStatsList->At(kStatsZorroSel)));
491+
if (fConfigZorro.fConfigRunZorroSel && (!zorroSel)) {
492+
continue;
493+
}
494+
} else {
495+
496+
if (!fEventCut->IsSelected(VarManager::fgValues) || (fConfigRCT.fConfigUseRCT.value && !rctChecker(event))) {
497+
continue;
498+
}
499+
}
500+
501+
decision = true;
502+
if (fConfigQA) {
503+
fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
366504
}
505+
367506
fSelMap[event.globalIndex()] = decision;
368507
if (fBCCollMap.find(bc.globalBC()) == fBCCollMap.end()) {
369508
std::vector<int64_t> evIndices = {event.globalIndex()};
@@ -616,13 +755,19 @@ struct AnalysisTrackSelection {
616755
continue;
617756
}
618757

758+
///
759+
auto track = tracks.rawIteratorAt(assoc.trackId());
760+
auto evFromTrack = events.rawIteratorAt(track.collisionId());
761+
if (!evFromTrack.isEventSelected_bit(0)) { trackSel(0); continue;}
762+
763+
619764
VarManager::ResetValues(VarManager::kNTFWiseVariables, VarManager::kNBarrelTrackVariables);
620765
// fill event information which might be needed in histograms/cuts that combine track and event properties
621766
VarManager::FillEvent<TEventFillMap>(event);
622767

623-
auto track = tracks.rawIteratorAt(assoc.trackId());
624768
VarManager::FillTrack<TTrackFillMap>(track);
625769
// compute quantities which depend on the associated collision, such as DCA
770+
if(track.collisionId() != event.globalIndex())
626771
VarManager::FillTrackCollision<TTrackFillMap>(track, event);
627772

628773
if (fConfigQA)
@@ -946,6 +1091,7 @@ struct AnalysisSameEventPairing {
9461091
Configurable<std::string> track{"cfgTrackCuts", "jpsiO2MCdebugCuts2", "Comma separated list of barrel track cuts"};
9471092
Configurable<std::string> muon{"cfgMuonCuts", "", "Comma separated list of muon cuts"};
9481093
Configurable<std::string> pair{"cfgPairCuts", "", "Comma separated list of pair cuts, !!! Use only if you know what you are doing, otherwise leave empty"};
1094+
Configurable<bool> collSplitting{"cfgRemoveCollSplittingCandidates", false, "If true, remove collision splitting candidates as determined by the event selection task upstream"};
9491095
Configurable<bool> fConfigQA{"cfgQA", false, "If true, fill QA histograms"};
9501096
Configurable<std::string> fConfigAddSEPHistogram{"cfgAddSEPHistogram", "", "Comma separated list of histograms"};
9511097
Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
@@ -1356,6 +1502,10 @@ struct AnalysisSameEventPairing {
13561502
if (!event.isEventSelected_bit(0))
13571503
continue;
13581504

1505+
if (fConfigOptions.collSplitting && event.isEventSelected_bit(2)) {
1506+
continue;
1507+
}
1508+
13591509
VarManager::ResetValues(0, VarManager::kNVars);
13601510
VarManager::FillEvent<TEventFillMap>(event, VarManager::fgValues);
13611511

0 commit comments

Comments
 (0)