Skip to content

Commit e49653e

Browse files
authored
[PWGEM/Dilepton] add a task for BC counter (#9626)
1 parent b9ce77d commit e49653e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

PWGEM/Dilepton/Tasks/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ o2physics_add_dpl_workflow(table-reader-barrel
4646
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2::DetectorsBase O2Physics::PWGDQCore
4747
COMPONENT_NAME Analysis)
4848

49+
o2physics_add_dpl_workflow(bc-counter
50+
SOURCES bcCounter.cxx
51+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore
52+
COMPONENT_NAME Analysis)
53+
4954
o2physics_add_dpl_workflow(event-qc
5055
SOURCES eventQC.cxx
5156
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore

PWGEM/Dilepton/Tasks/bcCounter.cxx

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
// ========================
13+
//
14+
// This code is for bc counter.
15+
// Please write to: daiki.sekihata@cern.ch
16+
17+
#include <string>
18+
#include <vector>
19+
#include <algorithm>
20+
#include <type_traits>
21+
#include <optional>
22+
23+
#include "TString.h"
24+
#include "Framework/runDataProcessing.h"
25+
#include "Framework/AnalysisTask.h"
26+
#include "Framework/ASoAHelpers.h"
27+
#include "Common/Core/RecoDecay.h"
28+
#include "MathUtils/Utils.h"
29+
#include "Framework/AnalysisDataModel.h"
30+
#include "Common/DataModel/EventSelection.h"
31+
#include "Common/DataModel/Multiplicity.h"
32+
#include "Common/DataModel/Centrality.h"
33+
#include "Common/DataModel/Qvectors.h"
34+
#include "Common/DataModel/PIDResponse.h"
35+
#include "Common/DataModel/PIDResponseITS.h"
36+
#include "Common/DataModel/TrackSelectionTables.h"
37+
#include "CCDB/BasicCCDBManager.h"
38+
#include "PWGEM/PhotonMeson/DataModel/gammaTables.h"
39+
#include "PWGLF/DataModel/LFStrangenessTables.h"
40+
41+
using namespace o2;
42+
using namespace o2::aod;
43+
using namespace o2::framework;
44+
using namespace o2::framework::expressions;
45+
using namespace o2::soa;
46+
47+
using MyBCs = soa::Join<aod::BCsWithTimestamps, aod::BcSels>;
48+
using MyCollisions = soa::Join<aod::Collisions, aod::EvSels>;
49+
using MyMCCollisions = soa::Join<MyCollisions, aod::McCollisionLabels>;
50+
51+
struct bcCounter {
52+
// Configurables
53+
// Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
54+
// Service<o2::ccdb::BasicCCDBManager> ccdb;
55+
56+
HistogramRegistry fRegistry{"output", {}, OutputObjHandlingPolicy::AnalysisObject, false, false};
57+
58+
void init(InitContext&)
59+
{
60+
// ccdb->setURL(ccdburl);
61+
// ccdb->setCaching(true);
62+
// ccdb->setLocalObjectValidityChecking();
63+
// ccdb->setFatalWhenNull(false);
64+
addhistograms();
65+
}
66+
67+
~bcCounter() {}
68+
69+
void addhistograms()
70+
{
71+
// event info
72+
73+
const int nbin_ev = 3;
74+
auto hBCCounter = fRegistry.add<TH1>("Data/hBCCounter", "bc counter;;Number of bcs", kTH1D, {{nbin_ev, 0.5, nbin_ev + 0.5}}, false);
75+
hBCCounter->GetXaxis()->SetBinLabel(1, "all");
76+
hBCCounter->GetXaxis()->SetBinLabel(2, "FT0AND");
77+
hBCCounter->GetXaxis()->SetBinLabel(3, "FT0AND && vertex found");
78+
fRegistry.add("Data/hNcollsPerBC", "Number of rec. collisions per BC", kTH1D, {{21, -0.5, 20.5}}, false);
79+
80+
fRegistry.addClone("Data/", "MC/");
81+
}
82+
83+
SliceCache cache;
84+
PresliceUnsorted<MyCollisions> preslice_collisions_per_bc = o2::aod::evsel::foundBCId;
85+
// std::unordered_map<uint64_t, int> map_ncolls_per_bc;
86+
87+
void processData(MyBCs const& bcs, MyCollisions const& collisions)
88+
{
89+
// first count the number of collisions per bc
90+
for (const auto& bc : bcs) {
91+
auto collisions_per_bc = collisions.sliceBy(preslice_collisions_per_bc, bc.globalIndex());
92+
// map_ncolls_per_bc[bc.globalIndex()] = collisions_per_bc.size();
93+
fRegistry.fill(HIST("Data/hNcollsPerBC"), collisions_per_bc.size());
94+
// LOGF(info, "bc-loop | bc.globalIndex() = %d , collisions_per_bc.size() = %d", bc.globalIndex(), collisions_per_bc.size());
95+
96+
fRegistry.fill(HIST("Data/hBCCounter"), 1.0);
97+
if (bc.selection_bit(o2::aod::evsel::kIsTriggerTVX)) {
98+
fRegistry.fill(HIST("Data/hBCCounter"), 2.0);
99+
100+
if (collisions_per_bc.size() > 0) { // at least 1 reconstructed vertex exists.
101+
fRegistry.fill(HIST("Data/hBCCounter"), 3.0);
102+
}
103+
}
104+
} // end of bc loop
105+
106+
// for (const auto& collision : collisions) {
107+
// auto bc = collision.template foundBC_as<MyBCs>();
108+
// // LOGF(info, "collision-loop | bc.globalIndex() = %d, ncolls_per_bc = %d", bc.globalIndex(), map_ncolls_per_bc[bc.globalIndex()]);
109+
// } // end of collision loop
110+
111+
// map_ncolls_per_bc.clear();
112+
}
113+
PROCESS_SWITCH(bcCounter, processData, "process Data", true);
114+
115+
// void processMC(MyBCs const& bcs, MyMCCollisions const& collisions, aod::McCollisions const& mccollisions)
116+
// {
117+
118+
// // first count the number of collisions per bc
119+
// for (const auto& bc : bcs) {
120+
// auto collisions_per_bc = collisions.sliceBy(preslice_collisions_per_bc, bc.globalIndex());
121+
// // map_ncolls_per_bc[bc.globalIndex()] = collisions_per_bc.size();
122+
// fRegistry.fill(HIST("hNcollsPerBC"), collisions_per_bc.size());
123+
// // LOGF(info, "bc-loop | bc.globalIndex() = %d , collisions_per_bc.size() = %d", bc.globalIndex(), collisions_per_bc.size());
124+
125+
// fRegistry.fill(HIST("hBCCounter"), 1.0);
126+
// if (bc.selection_bit(o2::aod::evsel::kIsTriggerTVX)) {
127+
// fRegistry.fill(HIST("hBCCounter"), 2.0);
128+
129+
// if (collisions_per_bc.size() > 0) { // at least 1 reconstructed vertex exists.
130+
// fRegistry.fill(HIST("hBCCounter"), 3.0);
131+
// }
132+
// }
133+
// } // end of bc loop
134+
// }
135+
// PROCESS_SWITCH(bcCounter, processMC, "process MC", false);
136+
};
137+
138+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
139+
{
140+
return WorkflowSpec{
141+
adaptAnalysisTask<bcCounter>(cfgc, TaskName{"bc-counter"})};
142+
}

0 commit comments

Comments
 (0)