Project
Loading...
Searching...
No Matches
ClusterizerTask.cxx
Go to the documentation of this file.
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
14
15#include <iostream>
16#include <vector>
17#include <algorithm>
18#include <iterator>
19#include <gsl/span>
20#include <fairlogger/Logger.h> // for LOG
21#include "FairRootManager.h" // for FairRootManager
24
25#include <TFile.h>
26
27//ClassImp(o2::emcal::ClusterizerTask);
28
29using namespace o2::emcal;
30
31//_____________________________________________________________________
32template <class InputType>
33ClusterizerTask<InputType>::ClusterizerTask(ClusterizerParameters* parameters) : mClusterizer(parameters->getTimeCut(), parameters->getTimeMin(), parameters->getTimeMax(), parameters->getGradientCut(), parameters->getDoEnergyGradientCut(), parameters->getThresholdSeedEnergy(), parameters->getThresholdCellEnergy())
34{
35}
36
37//_____________________________________________________________________
40template <class InputType>
42{
43 // Initialize cell/digit reader
44 if (!mInputReader) {
45 mInputReader = std::make_unique<DigitReader<InputType>>();
46 }
47
48 // Get default geometry object if not yet set
49 if (!mGeometry) {
50 mGeometry = Geometry::GetInstanceFromRunNumber(223409); // NOTE: Hardcoded for run II run
51 }
52 if (!mGeometry) {
53 LOG(error) << "Failure accessing geometry";
54 }
55
56 // Set geometry object in clusterizer
57 if (!mClusterizer.getGeometry()) {
58 mClusterizer.setGeometry(mGeometry);
59 }
60 if (!mClusterizer.getGeometry()) {
61 LOG(error) << "Could not set geometry in clusterizer";
62 }
63
64 mClustersArray = new std::vector<o2::emcal::Cluster>();
65 mClustersInputIndices = new std::vector<o2::emcal::ClusterIndex>();
66 mClusterTriggerRecordsClusters = new std::vector<o2::emcal::TriggerRecord>();
67 mClusterTriggerRecordsIndices = new std::vector<o2::emcal::TriggerRecord>();
68}
69
70//_____________________________________________________________________
71template <class InputType>
72void ClusterizerTask<InputType>::process(const std::string inputFileName, const std::string outputFileName)
73{
74 LOG(debug) << "Running clusterization on new event";
75
76 // Create reader, initilize clusterizer geometry
77 init();
78
79 // Load output file
80 std::unique_ptr<TFile> outFile(TFile::Open(outputFileName.data(), "recreate"));
81 if (!outFile || outFile->IsZombie()) {
82 LOG(fatal) << "Failed to open output file " << outputFileName;
83 }
84
85 // Create output tree
86 std::unique_ptr<TTree> outTree = std::make_unique<TTree>("o2sim", "EMCAL clusters");
87 outTree->Branch("EMCALCluster", &mClustersArray);
88 outTree->Branch("EMCALClusterInputIndex", &mClustersInputIndices);
89 outTree->Branch("EMCALClusterTRGR", &mClusterTriggerRecordsClusters);
90 outTree->Branch("EMCIndicesTRGR", &mClusterTriggerRecordsIndices);
91
92 mClustersArray->clear();
93 mClustersInputIndices->clear();
94 mClusterTriggerRecordsClusters->clear();
95 mClusterTriggerRecordsIndices->clear();
96
97 // Loop over entries of the input tree
98 mInputReader->openInput(inputFileName);
99 while (mInputReader->readNextEntry()) {
100
101 auto InputVector = mInputReader->getInputArray();
102
103 int currentStartClusters = mClustersArray->size();
104 int currentStartIndices = mClustersInputIndices->size();
105
106 for (auto iTrgRcrd = mInputReader->getTriggerArray()->begin(); iTrgRcrd != mInputReader->getTriggerArray()->end(); ++iTrgRcrd) {
107
108 mClusterizer.findClusters(gsl::span<const InputType>(InputVector->data() + iTrgRcrd->getFirstEntry(), iTrgRcrd->getNumberOfObjects())); // Find clusters on cells/digits given in reader::mInputArray (pass by ref)
109
110 // Get found clusters + cell/digit indices for output
111 auto clusterstmp = mClusterizer.getFoundClusters();
112 auto clusterIndecestmp = mClusterizer.getFoundClustersInputIndices();
113 std::copy(clusterstmp->begin(), clusterstmp->end(), std::back_inserter(*mClustersArray));
114 std::copy(clusterIndecestmp->begin(), clusterIndecestmp->end(), std::back_inserter(*mClustersInputIndices));
115
116 mClusterTriggerRecordsClusters->emplace_back(iTrgRcrd->getBCData(), currentStartClusters, clusterstmp->size());
117 mClusterTriggerRecordsIndices->emplace_back(iTrgRcrd->getBCData(), currentStartIndices, clusterIndecestmp->size());
118
119 currentStartClusters = mClustersArray->size();
120 currentStartIndices = mClustersInputIndices->size();
121 }
122 outTree->Fill();
123 }
124
125 // Write, close, and destroy tree/file
126 outTree->Write();
127 outTree.reset(); // here we reset the unique ptr, not the tree!
128 outFile->Close();
129}
130
Definition of the EMCAL clusterizer task.
std::ostringstream debug
Contains all parameters to set up the clusterizer.
Stand-alone task running EMCAL clusterization.
void init()
Init function Inititializes the cell/digit reader & geometry in cluster finder.
ClusterizerTask(ClusterizerParameters *parameters)
void process(const std::string inputFileName, const std::string outputFileName)
static Geometry * GetInstanceFromRunNumber(Int_t runNumber, const std::string_view="", const std::string_view mcname="TGeant3", const std::string_view mctitle="")
Instanciate geometry depending on the run number. Mostly used in analysis and MC anchors.
Definition Geometry.cxx:219
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"