Project
Loading...
Searching...
No Matches
TrivialVertexer.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 <limits>
16
17#include "TFile.h"
18#include "TTree.h"
19
20#include "FairMCEventHeader.h"
21#include <fairlogger/Logger.h>
22
27
28using namespace o2::itsmft;
29using namespace o2::its;
30
32
34
36{
37 if (mHeader)
38 delete mHeader;
39 if (mTree)
40 delete mTree;
41 if (mFile)
42 delete mFile;
43}
44
45Bool_t TrivialVertexer::openInputFile(const Char_t* fname)
46{
47 mFile = TFile::Open(fname, "old");
48 if (!mFile) {
49 LOG(error) << "TrivialVertexer::openInputFile() : "
50 << "Cannot open the input file !";
51 return kFALSE;
52 }
53 mTree = (TTree*)mFile->Get("o2sim");
54 if (!mTree) {
55 LOG(error) << "TrivialVertexer::openInputFile() : "
56 << "Cannot get the input tree !";
57 return kFALSE;
58 }
59 Int_t rc = mTree->SetBranchAddress("MCEventHeader.", &mHeader);
60 if (rc != 0) {
61 LOG(error) << "TrivialVertexer::openInputFile() : "
62 << "Cannot get the input branch ! rc=" << rc;
63 return kFALSE;
64 }
65 return kTRUE;
66}
67
68void TrivialVertexer::process(const std::vector<CompCluster>& clusters, std::vector<std::array<Double_t, 3>>& vertices)
69{
70 if (mClsLabels == nullptr) {
71 LOG(info) << "TrivialVertexer::process() : "
72 << "No cluster labels available ! Running with a default MC vertex...";
73 vertices.emplace_back(std::array<Double_t, 3>{0., 0., 0.});
74 return;
75 }
76
77 if (mTree == nullptr) {
78 LOG(info) << "TrivialVertexer::process() : "
79 << "No MC information available ! Running with a default MC vertex...";
80 vertices.emplace_back(std::array<Double_t, 3>{0., 0., 0.});
81 return;
82 }
83
84 Int_t lastEventID = 0;
85 Int_t firstEventID = std::numeric_limits<Int_t>::max();
86
87 // Find the first and last MC event within this TF
88 for (Int_t i = 0; i < clusters.size(); ++i) {
89 auto mclab = (mClsLabels->getLabels(i))[0];
90 if (mclab.getTrackID() == -1)
91 continue; // noise
92 auto id = mclab.getEventID();
93 if (id < firstEventID)
94 firstEventID = id;
95 if (id > lastEventID)
96 lastEventID = id;
97 }
98
99 for (Int_t mcEv = firstEventID; mcEv <= lastEventID; ++mcEv) {
100 mTree->GetEvent(mcEv);
101 Double_t vx = mHeader->GetX();
102 Double_t vy = mHeader->GetY();
103 Double_t vz = mHeader->GetZ();
104 vertices.emplace_back(std::array<Double_t, 3>{vx, vy, vz});
105 LOG(info) << "TrivialVertexer::process() : "
106 << "MC event #" << mcEv << " with vertex (" << vx << ',' << vy << ',' << vz << ')';
107 }
108}
Definition of the ITSMFT compact cluster.
int32_t i
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the ITS trivial vertex finder.
gsl::span< TruthElement > getLabels(uint32_t dataindex)
void process(const std::vector< Cluster > &clusters, std::vector< std::array< Double_t, 3 > > &vertices)
Bool_t openInputFile(const Char_t *)
GLuint id
Definition glcorearb.h:650
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters