diff --git a/PWGJE/TableProducer/emcalCorrectionTask.cxx b/PWGJE/TableProducer/emcalCorrectionTask.cxx index 0a84a66b23b..e2a0b1a3a9d 100644 --- a/PWGJE/TableProducer/emcalCorrectionTask.cxx +++ b/PWGJE/TableProducer/emcalCorrectionTask.cxx @@ -8,14 +8,17 @@ // 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. - -// EMCAL Correction Task -// -/// \author Raymond Ehlers , ORNL -/// \author Florian Jonas +/// +/// EMCAL Correction Task +/// +/// \file emcalCorrectionTask.cxx +/// +/// \brief Task that provides EMCal clusters and applies necessary corrections +/// +/// \author Raymond Ehlers (raymond.ehlers@cern.ch) ORNL, Florian Jonas (florian.jonas@cern.ch) +/// #include -#include #include #include #include @@ -51,12 +54,12 @@ using namespace o2; using namespace o2::framework; using namespace o2::framework::expressions; -using myGlobTracks = o2::soa::Join; -using bcEvSels = o2::soa::Join; -using collEventSels = o2::soa::Join; -using filteredCells = o2::soa::Filtered; -using mcCells = o2::soa::Join; -using filteredMCCells = o2::soa::Filtered; +using MyGlobTracks = o2::soa::Join; +using BcEvSels = o2::soa::Join; +using CollEventSels = o2::soa::Join; +using FilteredCells = o2::soa::Filtered; +using McCells = o2::soa::Join; +using FilteredMcCells = o2::soa::Filtered; struct EmcalCorrectionTask { Produces clusters; @@ -68,22 +71,22 @@ struct EmcalCorrectionTask { Produces emcalcollisionmatch; // Preslices - Preslice perCollision = o2::aod::track::collisionId; - PresliceUnsorted collisionsPerFoundBC = aod::evsel::foundBCId; + Preslice perCollision = o2::aod::track::collisionId; + PresliceUnsorted collisionsPerFoundBC = aod::evsel::foundBCId; Preslice collisionsPerBC = aod::collision::bcId; - Preslice cellsPerFoundBC = aod::calo::bcId; - Preslice mcCellsPerFoundBC = aod::calo::bcId; + Preslice cellsPerFoundBC = aod::calo::bcId; + Preslice mcCellsPerFoundBC = aod::calo::bcId; // Options for the clusterization // 1 corresponds to EMCAL cells based on the Run2 definition. Configurable selectedCellType{"selectedCellType", 1, "EMCAL Cell type"}; - Configurable clusterDefinitions{"clusterDefinition", "kV3Default", "cluster definition to be selected, e.g. V3Default. Multiple definitions can be specified separated by comma"}; + Configurable clusterDefinitions{"clusterDefinitions", "kV3Default", "cluster definition to be selected, e.g. V3Default. Multiple definitions can be specified separated by comma"}; Configurable maxMatchingDistance{"maxMatchingDistance", 0.4f, "Max matching distance track-cluster"}; Configurable nonlinearityFunction{"nonlinearityFunction", "DATA_TestbeamFinal", "Nonlinearity correction at cluster level"}; Configurable disableNonLin{"disableNonLin", false, "Disable NonLin correction if set to true"}; Configurable hasShaperCorrection{"hasShaperCorrection", true, "Apply correction for shaper saturation"}; Configurable applyCellAbsScale{"applyCellAbsScale", 0, "Enable absolute cell energy scale to correct for energy loss in material in front of EMCal"}; - Configurable> vCellAbsScaleFactor{"cellAbsScaleFactor", {1.f}, "values for absolute cell energy calibration. Different values correspond to different regions or SM types of EMCal"}; + Configurable> cellAbsScaleFactors{"cellAbsScaleFactors", {1.f}, "values for absolute cell energy calibration. Different values correspond to different regions or SM types of EMCal"}; Configurable logWeight{"logWeight", 4.5, "logarithmic weight for the cluster center of gravity calculation"}; Configurable exoticCellFraction{"exoticCellFraction", 0.97, "Good cell if fraction < 1-ecross/ecell"}; Configurable exoticCellDiffTime{"exoticCellDiffTime", 1.e6, "If time of candidate to exotic and close cell is larger than exoticCellDiffTime (in ns), it must be noisy, set amp to 0"}; @@ -159,7 +162,7 @@ struct EmcalCorrectionTask { mClusterFactories.setExoticCellMinAmplitude(exoticCellMinAmplitude); mClusterFactories.setExoticCellInCrossMinAmplitude(exoticCellInCrossMinAmplitude); mClusterFactories.setUseWeightExotic(useWeightExotic); - for (auto& clusterDefinition : mClusterDefinitions) { + for (const auto& clusterDefinition : mClusterDefinitions) { mClusterizers.emplace_back(std::make_unique>(1E9, clusterDefinition.timeMin, clusterDefinition.timeMax, clusterDefinition.gradientCut, clusterDefinition.doGradientCut, clusterDefinition.seedEnergy, clusterDefinition.minCellEnergy)); LOG(info) << "Cluster definition initialized: " << clusterDefinition.toString(); LOG(info) << "timeMin: " << clusterDefinition.timeMin; @@ -169,7 +172,7 @@ struct EmcalCorrectionTask { LOG(info) << "minCellEnergy: " << clusterDefinition.minCellEnergy; LOG(info) << "storageID" << clusterDefinition.storageID; } - for (auto& clusterizer : mClusterizers) { + for (const auto& clusterizer : mClusterizers) { clusterizer->setGeometry(geometry); } @@ -194,39 +197,38 @@ struct EmcalCorrectionTask { // Setup QA hists. // NOTE: This is not comprehensive. - using o2HistType = o2::framework::HistType; - using o2Axis = o2::framework::AxisSpec; - o2Axis energyAxis{200, 0., 100., "E (GeV)"}, + using O2HistType = o2::framework::HistType; + o2::framework::AxisSpec energyAxis{200, 0., 100., "E (GeV)"}, timeAxis{300, -100, 200., "t (ns)"}, etaAxis{160, -0.8, 0.8, "#eta"}, phiAxis{72, 0, 2 * 3.14159, "phi"}, nlmAxis{50, -0.5, 49.5, "NLM"}; - mHistManager.add("hCellE", "hCellE", o2HistType::kTH1F, {energyAxis}); - mHistManager.add("hCellTowerID", "hCellTowerID", o2HistType::kTH1D, {{20000, 0, 20000}}); - mHistManager.add("hCellEtaPhi", "hCellEtaPhi", o2HistType::kTH2F, {etaAxis, phiAxis}); - mHistManager.add("hHGCellTimeEnergy", "hCellTime", o2HistType::kTH2F, {{300, -30, 30}, cellEnergyBins}); // Cell time vs energy for high gain cells (low energies) - mHistManager.add("hLGCellTimeEnergy", "hCellTime", o2HistType::kTH2F, {{300, -30, 30}, cellEnergyBins}); // Cell time vs energy for low gain cells (high energies) + mHistManager.add("hCellE", "hCellE", O2HistType::kTH1F, {energyAxis}); + mHistManager.add("hCellTowerID", "hCellTowerID", O2HistType::kTH1D, {{20000, 0, 20000}}); + mHistManager.add("hCellEtaPhi", "hCellEtaPhi", O2HistType::kTH2F, {etaAxis, phiAxis}); + mHistManager.add("hHGCellTimeEnergy", "hCellTime", O2HistType::kTH2F, {{300, -30, 30}, cellEnergyBins}); // Cell time vs energy for high gain cells (low energies) + mHistManager.add("hLGCellTimeEnergy", "hCellTime", O2HistType::kTH2F, {{300, -30, 30}, cellEnergyBins}); // Cell time vs energy for low gain cells (high energies) // NOTE: Reversed column and row because it's more natural for presentation. - mHistManager.add("hCellRowCol", "hCellRowCol;Column;Row", o2HistType::kTH2D, {{96, -0.5, 95.5}, {208, -0.5, 207.5}}); - mHistManager.add("hClusterE", "hClusterE", o2HistType::kTH1F, {energyAxis}); - mHistManager.add("hClusterNLM", "hClusterNLM", o2HistType::kTH1F, {nlmAxis}); - mHistManager.add("hClusterEtaPhi", "hClusterEtaPhi", o2HistType::kTH2F, {etaAxis, phiAxis}); - mHistManager.add("hClusterTime", "hClusterTime", o2HistType::kTH1F, {timeAxis}); - mHistManager.add("hGlobalTrackEtaPhi", "hGlobalTrackEtaPhi", o2HistType::kTH2F, {etaAxis, phiAxis}); - mHistManager.add("hGlobalTrackMult", "hGlobalTrackMult", o2HistType::kTH1D, {{200, -0.5, 199.5, "N_{trk}"}}); - mHistManager.add("hCollisionType", "hCollisionType;;#it{count}", o2HistType::kTH1D, {{3, -0.5, 2.5}}); + mHistManager.add("hCellRowCol", "hCellRowCol;Column;Row", O2HistType::kTH2D, {{96, -0.5, 95.5}, {208, -0.5, 207.5}}); + mHistManager.add("hClusterE", "hClusterE", O2HistType::kTH1F, {energyAxis}); + mHistManager.add("hClusterNLM", "hClusterNLM", O2HistType::kTH1F, {nlmAxis}); + mHistManager.add("hClusterEtaPhi", "hClusterEtaPhi", O2HistType::kTH2F, {etaAxis, phiAxis}); + mHistManager.add("hClusterTime", "hClusterTime", O2HistType::kTH1F, {timeAxis}); + mHistManager.add("hGlobalTrackEtaPhi", "hGlobalTrackEtaPhi", O2HistType::kTH2F, {etaAxis, phiAxis}); + mHistManager.add("hGlobalTrackMult", "hGlobalTrackMult", O2HistType::kTH1D, {{200, -0.5, 199.5, "N_{trk}"}}); + mHistManager.add("hCollisionType", "hCollisionType;;#it{count}", O2HistType::kTH1D, {{3, -0.5, 2.5}}); auto hCollisionType = mHistManager.get(HIST("hCollisionType")); hCollisionType->GetXaxis()->SetBinLabel(1, "no collision"); hCollisionType->GetXaxis()->SetBinLabel(2, "normal collision"); hCollisionType->GetXaxis()->SetBinLabel(3, "mult. collisions"); - mHistManager.add("hClusterType", "hClusterType;;#it{count}", o2HistType::kTH1D, {{3, -0.5, 2.5}}); + mHistManager.add("hClusterType", "hClusterType;;#it{count}", O2HistType::kTH1D, {{3, -0.5, 2.5}}); auto hClusterType = mHistManager.get(HIST("hClusterType")); hClusterType->GetXaxis()->SetBinLabel(1, "no collision"); hClusterType->GetXaxis()->SetBinLabel(2, "normal collision"); hClusterType->GetXaxis()->SetBinLabel(3, "mult. collisions"); - mHistManager.add("hCollPerBC", "hCollPerBC;#it{N}_{coll.};#it{count}", o2HistType::kTH1D, {{100, -0.5, 99.5}}); - mHistManager.add("hBC", "hBC;;#it{count}", o2HistType::kTH1D, {{8, -0.5, 7.5}}); - mHistManager.add("hCollisionTimeReso", "hCollisionTimeReso;#Delta t_{coll};#it{count}", o2HistType::kTH1D, {{2000, 0, 2000}}); + mHistManager.add("hCollPerBC", "hCollPerBC;#it{N}_{coll.};#it{count}", O2HistType::kTH1D, {{100, -0.5, 99.5}}); + mHistManager.add("hBC", "hBC;;#it{count}", O2HistType::kTH1D, {{8, -0.5, 7.5}}); + mHistManager.add("hCollisionTimeReso", "hCollisionTimeReso;#Delta t_{coll};#it{count}", O2HistType::kTH1D, {{2000, 0, 2000}}); auto hBC = mHistManager.get(HIST("hBC")); hBC->GetXaxis()->SetBinLabel(1, "with EMCal cells"); hBC->GetXaxis()->SetBinLabel(2, "with EMCal cells but no collision"); @@ -237,8 +239,8 @@ struct EmcalCorrectionTask { hBC->GetXaxis()->SetBinLabel(7, "no EMCal cells and mult. collisions"); hBC->GetXaxis()->SetBinLabel(8, "all BC"); if (isMC) { - mHistManager.add("hContributors", "hContributors;contributor per cell hit;#it{counts}", o2HistType::kTH1I, {{20, 0, 20}}); - mHistManager.add("hMCParticleEnergy", "hMCParticleEnergy;#it{E} (GeV/#it{c});#it{counts}", o2HistType::kTH1F, {energyAxis}); + mHistManager.add("hContributors", "hContributors;contributor per cell hit;#it{counts}", O2HistType::kTH1I, {{20, 0, 20}}); + mHistManager.add("hMCParticleEnergy", "hMCParticleEnergy;#it{E} (GeV/#it{c});#it{counts}", O2HistType::kTH1F, {energyAxis}); } } @@ -247,7 +249,7 @@ struct EmcalCorrectionTask { // void process(aod::BCs const& bcs, aod::Collision const& collision, aod::Calos const& cells) // Appears to need the BC to be accessed to be available in the collision table... - void processFull(bcEvSels const& bcs, collEventSels const& collisions, myGlobTracks const& tracks, filteredCells const& cells) + void processFull(BcEvSels const& bcs, CollEventSels const& collisions, MyGlobTracks const& tracks, FilteredCells const& cells) { LOG(debug) << "Starting process full."; @@ -255,7 +257,7 @@ struct EmcalCorrectionTask { int nCellsProcessed = 0; std::unordered_map numberCollsInBC; // Number of collisions mapped to the global BC index of all BCs std::unordered_map numberCellsInBC; // Number of cells mapped to the global BC index of all BCs to check whether EMCal was readout - for (auto bc : bcs) { + for (const auto& bc : bcs) { LOG(debug) << "Next BC"; // Convert aod::Calo to o2::emcal::Cell which can be used with the clusterizer. // In particular, we need to filter only EMCAL cells. @@ -276,13 +278,13 @@ struct EmcalCorrectionTask { countBC(collisionsInFoundBC.size(), true); std::vector cellsBC; std::vector cellIndicesBC; - for (auto& cell : cellsInBC) { + for (const auto& cell : cellsInBC) { auto amplitude = cell.amplitude(); if (static_cast(hasShaperCorrection)) { amplitude = o2::emcal::NonlinearityHandler::evaluateShaperCorrectionCellEnergy(amplitude); } if (applyCellAbsScale) { - amplitude *= GetAbsCellScale(cell.cellNumber()); + amplitude *= getAbsCellScale(cell.cellNumber()); } cellsBC.emplace_back(cell.cellNumber(), amplitude, @@ -297,7 +299,7 @@ struct EmcalCorrectionTask { // TODO: Helpful for now, but should be removed. LOG(debug) << "Converted EMCAL cells"; - for (auto& cell : cellsBC) { + for (const auto& cell : cellsBC) { LOG(debug) << cell.getTower() << ": E: " << cell.getEnergy() << ", time: " << cell.getTimeStamp() << ", type: " << cell.getType(); } @@ -315,17 +317,17 @@ struct EmcalCorrectionTask { mHistManager.fill(HIST("hCollisionTimeReso"), col.collisionTimeRes()); mHistManager.fill(HIST("hCollPerBC"), 1); mHistManager.fill(HIST("hCollisionType"), 1); - math_utils::Point3D vertex_pos = {col.posX(), col.posY(), col.posZ()}; + math_utils::Point3D vertexPos = {col.posX(), col.posY(), col.posZ()}; std::vector> clusterToTrackIndexMap; std::vector> trackToClusterIndexMap; - std::tuple>, std::vector>> IndexMapPair{clusterToTrackIndexMap, trackToClusterIndexMap}; + std::tuple>, std::vector>> indexMapPair{clusterToTrackIndexMap, trackToClusterIndexMap}; std::vector trackGlobalIndex; - doTrackMatching(col, tracks, IndexMapPair, vertex_pos, trackGlobalIndex); + doTrackMatching(col, tracks, indexMapPair, vertexPos, trackGlobalIndex); // Store the clusters in the table where a matching collision could // be identified. - FillClusterTable(col, vertex_pos, iClusterizer, cellIndicesBC, IndexMapPair, trackGlobalIndex); + fillClusterTable(col, vertexPos, iClusterizer, cellIndicesBC, indexMapPair, trackGlobalIndex); } } } else { // ambiguous @@ -338,7 +340,7 @@ struct EmcalCorrectionTask { hasCollision = true; mHistManager.fill(HIST("hCollisionType"), 2); } - FillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); + fillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); } LOG(debug) << "Cluster loop done for clusterizer " << iClusterizer; @@ -349,7 +351,7 @@ struct EmcalCorrectionTask { // Loop through all collisions and fill emcalcollisionmatch with a boolean stating, whether the collision was ambiguous (not the only collision in its BC) for (const auto& collision : collisions) { - auto globalbcid = collision.foundBC_as().globalIndex(); + auto globalbcid = collision.foundBC_as().globalIndex(); auto foundColls = numberCollsInBC.find(globalbcid); auto foundCells = numberCellsInBC.find(globalbcid); if (foundColls != numberCollsInBC.end() && foundCells != numberCellsInBC.end()) { @@ -363,7 +365,7 @@ struct EmcalCorrectionTask { } PROCESS_SWITCH(EmcalCorrectionTask, processFull, "run full analysis", true); - void processMCFull(bcEvSels const& bcs, collEventSels const& collisions, myGlobTracks const& tracks, filteredMCCells const& cells, aod::StoredMcParticles_001 const&) + void processMCFull(BcEvSels const& bcs, CollEventSels const& collisions, MyGlobTracks const& tracks, FilteredMcCells const& cells, aod::StoredMcParticles_001 const&) { LOG(debug) << "Starting process full."; @@ -371,7 +373,7 @@ struct EmcalCorrectionTask { int nCellsProcessed = 0; std::unordered_map numberCollsInBC; // Number of collisions mapped to the global BC index of all BCs std::unordered_map numberCellsInBC; // Number of cells mapped to the global BC index of all BCs to check whether EMCal was readout - for (auto bc : bcs) { + for (const auto& bc : bcs) { LOG(debug) << "Next BC"; // Convert aod::Calo to o2::emcal::Cell which can be used with the clusterizer. // In particular, we need to filter only EMCAL cells. @@ -393,10 +395,10 @@ struct EmcalCorrectionTask { std::vector cellsBC; std::vector cellIndicesBC; std::vector cellLabels; - for (auto& cell : cellsInBC) { + for (const auto& cell : cellsInBC) { mHistManager.fill(HIST("hContributors"), cell.mcParticle_as().size()); auto cellParticles = cell.mcParticle_as(); - for (auto& cellparticle : cellParticles) { + for (const auto& cellparticle : cellParticles) { mHistManager.fill(HIST("hMCParticleEnergy"), cellparticle.e()); } auto amplitude = cell.amplitude(); @@ -417,7 +419,7 @@ struct EmcalCorrectionTask { // TODO: Helpful for now, but should be removed. LOG(debug) << "Converted EMCAL cells"; - for (auto& cell : cellsBC) { + for (const auto& cell : cellsBC) { LOG(debug) << cell.getTower() << ": E: " << cell.getEnergy() << ", time: " << cell.getTimeStamp() << ", type: " << cell.getType(); } @@ -434,17 +436,17 @@ struct EmcalCorrectionTask { if (col.foundBCId() == bc.globalIndex()) { mHistManager.fill(HIST("hCollPerBC"), 1); mHistManager.fill(HIST("hCollisionType"), 1); - math_utils::Point3D vertex_pos = {col.posX(), col.posY(), col.posZ()}; + math_utils::Point3D vertexPos = {col.posX(), col.posY(), col.posZ()}; std::vector> clusterToTrackIndexMap; std::vector> trackToClusterIndexMap; - std::tuple>, std::vector>> IndexMapPair{clusterToTrackIndexMap, trackToClusterIndexMap}; + std::tuple>, std::vector>> indexMapPair{clusterToTrackIndexMap, trackToClusterIndexMap}; std::vector trackGlobalIndex; - doTrackMatching(col, tracks, IndexMapPair, vertex_pos, trackGlobalIndex); + doTrackMatching(col, tracks, indexMapPair, vertexPos, trackGlobalIndex); // Store the clusters in the table where a matching collision could // be identified. - FillClusterTable(col, vertex_pos, iClusterizer, cellIndicesBC, IndexMapPair, trackGlobalIndex); + fillClusterTable(col, vertexPos, iClusterizer, cellIndicesBC, indexMapPair, trackGlobalIndex); } } } else { // ambiguous @@ -457,7 +459,7 @@ struct EmcalCorrectionTask { hasCollision = true; mHistManager.fill(HIST("hCollisionType"), 2); } - FillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); + fillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); } LOG(debug) << "Cluster loop done for clusterizer " << iClusterizer; } // end of clusterizer loop @@ -467,7 +469,7 @@ struct EmcalCorrectionTask { // Loop through all collisions and fill emcalcollisionmatch with a boolean stating, whether the collision was ambiguous (not the only collision in its BC) for (const auto& collision : collisions) { - auto globalbcid = collision.foundBC_as().globalIndex(); + auto globalbcid = collision.foundBC_as().globalIndex(); auto foundColls = numberCollsInBC.find(globalbcid); auto foundCells = numberCellsInBC.find(globalbcid); if (foundColls != numberCollsInBC.end() && foundCells != numberCellsInBC.end()) { @@ -480,12 +482,12 @@ struct EmcalCorrectionTask { LOG(detail) << "Processed " << nBCsProcessed << " BCs with " << nCellsProcessed << " cells"; } PROCESS_SWITCH(EmcalCorrectionTask, processMCFull, "run full analysis with MC info", false); - void processStandalone(aod::BCs const& bcs, aod::Collisions const& collisions, filteredCells const& cells) + void processStandalone(aod::BCs const& bcs, aod::Collisions const& collisions, FilteredCells const& cells) { LOG(debug) << "Starting process standalone."; int nBCsProcessed = 0; int nCellsProcessed = 0; - for (auto bc : bcs) { + for (const auto& bc : bcs) { LOG(debug) << "Next BC"; // Convert aod::Calo to o2::emcal::Cell which can be used with the clusterizer. // In particular, we need to filter only EMCAL cells. @@ -504,7 +506,7 @@ struct EmcalCorrectionTask { countBC(collisionsInBC.size(), true); std::vector cellsBC; std::vector cellIndicesBC; - for (auto& cell : cellsInBC) { + for (const auto& cell : cellsInBC) { cellsBC.emplace_back(cell.cellNumber(), cell.amplitude(), cell.time() + getCellTimeShift(cell.cellNumber(), cell.amplitude(), o2::emcal::intToChannelType(cell.cellType())), @@ -518,7 +520,7 @@ struct EmcalCorrectionTask { // TODO: Helpful for now, but should be removed. LOG(debug) << "Converted EMCAL cells"; - for (auto& cell : cellsBC) { + for (const auto& cell : cellsBC) { LOG(debug) << cell.getTower() << ": E: " << cell.getEnergy() << ", time: " << cell.getTimeStamp() << ", type: " << cell.getType(); } @@ -535,11 +537,11 @@ struct EmcalCorrectionTask { for (const auto& col : collisionsInBC) { mHistManager.fill(HIST("hCollPerBC"), 1); mHistManager.fill(HIST("hCollisionType"), 1); - math_utils::Point3D vertex_pos = {col.posX(), col.posY(), col.posZ()}; + math_utils::Point3D vertexPos = {col.posX(), col.posY(), col.posZ()}; // Store the clusters in the table where a matching collision could // be identified. - FillClusterTable(col, vertex_pos, iClusterizer, cellIndicesBC); + fillClusterTable(col, vertexPos, iClusterizer, cellIndicesBC); } } else { // ambiguous // LOG(warning) << "No vertex found for event. Assuming (0,0,0)."; @@ -551,7 +553,7 @@ struct EmcalCorrectionTask { hasCollision = true; mHistManager.fill(HIST("hCollisionType"), 2); } - FillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); + fillAmbigousClusterTable(bc, iClusterizer, cellIndicesBC, hasCollision); } LOG(debug) << "Cluster loop done for clusterizer " << iClusterizer; @@ -599,7 +601,7 @@ struct EmcalCorrectionTask { } template - void FillClusterTable(Collision const& col, math_utils::Point3D const& vertex_pos, size_t iClusterizer, const gsl::span cellIndicesBC, std::optional>, std::vector>>> const& IndexMapPair = std::nullopt, std::optional> const& trackGlobalIndex = std::nullopt) + void fillClusterTable(Collision const& col, math_utils::Point3D const& vertexPos, size_t iClusterizer, const gsl::span cellIndicesBC, std::optional>, std::vector>>> const& indexMapPair = std::nullopt, std::optional> const& trackGlobalIndex = std::nullopt) { // we found a collision, put the clusters into the none ambiguous table clusters.reserve(mAnalysisClusters.size()); @@ -611,7 +613,7 @@ struct EmcalCorrectionTask { for (const auto& cluster : mAnalysisClusters) { // Determine the cluster eta, phi, correcting for the vertex position. auto pos = cluster.getGlobalPosition(); - pos = pos - vertex_pos; + pos = pos - vertexPos; // Normalize the vector and rescale by energy. pos *= (cluster.E() / std::sqrt(pos.Mag2())); @@ -651,11 +653,11 @@ struct EmcalCorrectionTask { mHistManager.fill(HIST("hClusterNLM"), cluster.getNExMax()); mHistManager.fill(HIST("hClusterTime"), cluster.getClusterTime()); mHistManager.fill(HIST("hClusterEtaPhi"), pos.Eta(), TVector2::Phi_0_2pi(pos.Phi())); - if (IndexMapPair && trackGlobalIndex) { - for (unsigned int iTrack = 0; iTrack < std::get<0>(*IndexMapPair)[iCluster].size(); iTrack++) { - if (std::get<0>(*IndexMapPair)[iCluster][iTrack] >= 0) { - LOG(debug) << "Found track " << (*trackGlobalIndex)[std::get<0>(*IndexMapPair)[iCluster][iTrack]] << " in cluster " << cluster.getID(); - matchedTracks(clusters.lastIndex(), (*trackGlobalIndex)[std::get<0>(*IndexMapPair)[iCluster][iTrack]]); + if (indexMapPair && trackGlobalIndex) { + for (unsigned int iTrack = 0; iTrack < std::get<0>(*indexMapPair)[iCluster].size(); iTrack++) { + if (std::get<0>(*indexMapPair)[iCluster][iTrack] >= 0) { + LOG(debug) << "Found track " << (*trackGlobalIndex)[std::get<0>(*indexMapPair)[iCluster][iTrack]] << " in cluster " << cluster.getID(); + matchedTracks(clusters.lastIndex(), (*trackGlobalIndex)[std::get<0>(*indexMapPair)[iCluster][iTrack]]); } } } @@ -664,7 +666,7 @@ struct EmcalCorrectionTask { } template - void FillAmbigousClusterTable(BC const& bc, size_t iClusterizer, const gsl::span cellIndicesBC, bool hasCollision) + void fillAmbigousClusterTable(BC const& bc, size_t iClusterizer, const gsl::span cellIndicesBC, bool hasCollision) { int cellindex = -1; clustersAmbiguous.reserve(mAnalysisClusters.size()); @@ -706,23 +708,23 @@ struct EmcalCorrectionTask { } template - void doTrackMatching(Collision const& col, myGlobTracks const& tracks, std::tuple>, std::vector>>& IndexMapPair, math_utils::Point3D& vertex_pos, std::vector& trackGlobalIndex) + void doTrackMatching(Collision const& col, MyGlobTracks const& tracks, std::tuple>, std::vector>>& indexMapPair, math_utils::Point3D& vertexPos, std::vector& trackGlobalIndex) { auto groupedTracks = tracks.sliceBy(perCollision, col.globalIndex()); - int NTracksInCol = groupedTracks.size(); + int nTracksInCol = groupedTracks.size(); std::vector trackPhi; std::vector trackEta; // reserve memory to reduce on the fly memory allocation - trackPhi.reserve(NTracksInCol); - trackEta.reserve(NTracksInCol); - trackGlobalIndex.reserve(NTracksInCol); - FillTrackInfo(groupedTracks, trackPhi, trackEta, trackGlobalIndex); + trackPhi.reserve(nTracksInCol); + trackEta.reserve(nTracksInCol); + trackGlobalIndex.reserve(nTracksInCol); + fillTrackInfo(groupedTracks, trackPhi, trackEta, trackGlobalIndex); - int NClusterInCol = mAnalysisClusters.size(); + int nClusterInCol = mAnalysisClusters.size(); std::vector clusterPhi; std::vector clusterEta; - clusterPhi.reserve(NClusterInCol); - clusterEta.reserve(NClusterInCol); + clusterPhi.reserve(nClusterInCol); + clusterEta.reserve(nClusterInCol); // TODO one loop that could in principle be combined with the other // loop to improve performance @@ -730,40 +732,40 @@ struct EmcalCorrectionTask { // Determine the cluster eta, phi, correcting for the vertex // position. auto pos = cluster.getGlobalPosition(); - pos = pos - vertex_pos; + pos = pos - vertexPos; // Normalize the vector and rescale by energy. pos *= (cluster.E() / std::sqrt(pos.Mag2())); clusterPhi.emplace_back(TVector2::Phi_0_2pi(pos.Phi())); clusterEta.emplace_back(pos.Eta()); } - IndexMapPair = + indexMapPair = jetutilities::MatchClustersAndTracks(clusterPhi, clusterEta, trackPhi, trackEta, maxMatchingDistance, 20); } template - void FillTrackInfo(Tracks const& tracks, std::vector& trackPhi, std::vector& trackEta, std::vector& trackGlobalIndex) + void fillTrackInfo(Tracks const& tracks, std::vector& trackPhi, std::vector& trackEta, std::vector& trackGlobalIndex) { - int NTrack = 0; - for (auto& track : tracks) { + int nTrack = 0; + for (const auto& track : tracks) { // TODO only consider tracks in current emcal/dcal acceptanc if (!track.isGlobalTrack()) { // only global tracks continue; } - NTrack++; + nTrack++; trackPhi.emplace_back(TVector2::Phi_0_2pi(track.trackPhiEmcal())); trackEta.emplace_back(track.trackEtaEmcal()); mHistManager.fill(HIST("hGlobalTrackEtaPhi"), track.trackEtaEmcal(), TVector2::Phi_0_2pi(track.trackPhiEmcal())); trackGlobalIndex.emplace_back(track.globalIndex()); } - mHistManager.fill(HIST("hGlobalTrackMult"), NTrack); + mHistManager.fill(HIST("hGlobalTrackMult"), nTrack); } - void countBC(int numberOfCollisions, bool hasEMCcells) + void countBC(int numberOfCollisions, bool hasEMCCells) { - int emcDataOffset = hasEMCcells ? 0 : 3; + int emcDataOffset = hasEMCCells ? 0 : 3; int collisionOffset = 2; switch (numberOfCollisions) { case 0: @@ -777,7 +779,7 @@ struct EmcalCorrectionTask { break; } mHistManager.fill(HIST("hBC"), 7); // All collisions - if (hasEMCcells) { + if (hasEMCCells) { mHistManager.fill(HIST("hBC"), 0); } mHistManager.fill(HIST("hBC"), 1 + emcDataOffset + collisionOffset); @@ -787,7 +789,7 @@ struct EmcalCorrectionTask { { // Cell QA // For convenience, use the clusterizer stored geometry to get the eta-phi - for (auto& cell : cellsBC) { + for (const auto& cell : cellsBC) { mHistManager.fill(HIST("hCellE"), cell.getEnergy()); if (cell.getLowGain()) mHistManager.fill(HIST("hLGCellTimeEnergy"), cell.getTimeStamp(), cell.getEnergy()); @@ -802,18 +804,18 @@ struct EmcalCorrectionTask { } } - float GetAbsCellScale(const int cellID) + float getAbsCellScale(const int cellID) { // Apply cell scale based on SM types (Full, Half (not used), EMC 1/3, DCal, DCal 1/3) // Same as in Run2 data if (applyCellAbsScale == 1) { int iSM = mClusterizers.at(0)->getGeometry()->GetSuperModuleNumber(cellID); - return vCellAbsScaleFactor.value[mClusterizers.at(0)->getGeometry()->GetSMType(iSM)]; + return cellAbsScaleFactors.value[mClusterizers.at(0)->getGeometry()->GetSMType(iSM)]; // Apply cell scale based on columns to accoutn for material of TRD structures } else if (applyCellAbsScale == 2) { auto res = mClusterizers.at(0)->getGeometry()->GlobalRowColFromIndex(cellID); - return vCellAbsScaleFactor.value[std::get<1>(res)]; + return cellAbsScaleFactors.value[std::get<1>(res)]; } else { return 1.f; } @@ -822,41 +824,50 @@ struct EmcalCorrectionTask { // Apply shift of the cell time in data and MC // In MC this has to be done to shift the cell time, which is not calibrated to 0 due to the flight time of the particles to the EMCal surface (~15ns) // In data this is done to correct for the time walk effect - float getCellTimeShift(const int16_t cellID, const float cellEnergy, const o2::emcal::ChannelType_t cellType) + float getCellTimeShift(const int16_t cellID, const float cellEnergy, const emcal::ChannelType_t cellType) { if (!applyCellTimeCorrection) { return 0.f; } float timeshift = 0.f; float timesmear = 0.f; - if (isMC) { + if (isMC) { // ---> MC // Shift the time to 0, as the TOF was simulated -> eta dependent shift (as larger eta values are further away from collision point) // Use distance between vertex and EMCal (at eta = 0) and distance on EMCal surface (cell size times column) to calculate distance to cell // 0.2 is cell size in m (0.06) divided by the speed of light in m/ns (0.3) - 47.5 is the "middle" of the EMCal (2*48 cells in one column) float timeCol = 0.2f * (geometry->GlobalCol(cellID) - 47.5f); // calculate time to get to specific column - timeshift = -sqrt(215.f + timeCol * timeCol); // 215 is 14.67ns^2 (time it takes to get the cell at eta = 0) + timeshift = -std::sqrt(215.f + timeCol * timeCol); // 215 is 14.67ns^2 (time it takes to get the cell at eta = 0) + // Also smear the time to account for the broader time resolution in data than in MC - timesmear = normalgaus(rdgen) * (1.6 + 9.5 * TMath::Exp(-3. * cellEnergy)); // Parameters extracted from LHC22o (pp), but also usable for other periods - } else { // data - if (cellEnergy < 0.3) { // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration - timeshift = 0.; - } else if (cellType == o2::emcal::ChannelType_t::HIGH_GAIN) { // High gain cells -> Low energies - if (cellEnergy < 4.) // Low energy regime - timeshift = 0.57284 + 0.82194 * TMath::Log(1.30651 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods - else // Medium energy regime - timeshift = -0.05858 + 1.50593 * TMath::Log(0.97591 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods - } else if (cellType == o2::emcal::ChannelType_t::LOW_GAIN) { // Low gain cells -> High energies - timeshift = -0.05858 + 1.50593 * TMath::Log(0.97591 * cellEnergy); // Parameters extracted from LHC22o (pp), will be updated by LHC24aj input + if (cellEnergy < 0.3) // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration + timesmear = 0.; // They will therefore not be smeared and only get their shift + else if (cellType == emcal::ChannelType_t::HIGH_GAIN) // High gain cells -> Low energies + timesmear = normalgaus(rdgen) * (1.6 + 9.5 * std::exp(-3. * cellEnergy)); // Parameters extracted from LHC24f3b & LHC22o (pp), but also usable for other periods + else if (cellType == emcal::ChannelType_t::LOW_GAIN) // Low gain cells -> High energies + timesmear = normalgaus(rdgen) * (5.0); // Parameters extracted from LHC24g4 & LHC24aj (pp), but also usable for other periods + + } else { // ---> Data + if (cellEnergy < 0.3) { // Cells with tless than 300 MeV cannot be the leading cell in the cluster, so their time does not require precise calibration + timeshift = 0.; // In data they will not be shifted (they are close to 0 anyways) + } else if (cellType == emcal::ChannelType_t::HIGH_GAIN) { // High gain cells -> Low energies + if (cellEnergy < 4.) // Low energy regime + timeshift = 0.8 * std::log(2.7 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods + else // Medium energy regime + timeshift = 1.5 * std::log(0.9 * cellEnergy); // Parameters extracted from LHC22o (pp), but also usable for other periods + } else if (cellType == emcal::ChannelType_t::LOW_GAIN) { // Low gain cells -> High energies + if (cellEnergy < 30.) // High energy regime + timeshift = 1.9 * std::log(0.09 * cellEnergy); // Parameters extracted from LHC24aj (pp), but also usable for other periods + else // Very high energy regime + timeshift = 1.9; // Parameters extracted from LHC24aj (pp), but also usable for other periods } + LOG(debug) << "Shift the cell time by " << timeshift << " + " << timesmear << " ns"; + return timeshift + timesmear; } - - LOG(debug) << "Shift the cell time by " << timeshift << " + " << timesmear << " ns"; - return timeshift + timesmear; - } + }; }; WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{ - adaptAnalysisTask(cfgc, TaskName{"emcal-correction-task"})}; + adaptAnalysisTask(cfgc)}; }