Project
Loading...
Searching...
No Matches
MCEventHeader.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
13
15#include "FairRootManager.h"
16#include <TFile.h>
17#include <TTree.h>
18#include <iostream>
19
20namespace o2
21{
22namespace dataformats
23{
24
25/*****************************************************************/
26/*****************************************************************/
27
29{
32 FairMCEventHeader::Reset();
33
34 clearInfo();
35 mEmbeddingFileName.clear();
37}
38
39void MCEventHeader::extractFileFromKinematics(std::string_view kinefilename, std::string_view targetfilename)
40{
41 auto oldfile = TFile::Open(kinefilename.data());
42 auto kinetree = (TTree*)oldfile->Get("o2sim");
43 // deactivate all branches
44 kinetree->SetBranchStatus("*", 0);
45 // activate the header branch
46 kinetree->SetBranchStatus("MCEventHeader*", 1);
47 // create a new file + a clone of old tree header. Do not copy events
48 auto newfile = TFile::Open(targetfilename.data(), "RECREATE");
49 auto newtree = kinetree->CloneTree(0);
50 // here we copy the branches
51 newtree->CopyEntries(kinetree, kinetree->GetEntries());
52 newtree->SetEntries(kinetree->GetEntries());
53 // flush to disk
54 newtree->Write();
55 newfile->Close();
56 delete newfile;
57
58 // clean
59 if (oldfile) {
60 oldfile->Close();
61 delete oldfile;
62 }
63}
64
66{
67 // print some used parts from FairMCEventHeader
68 std::cout << "RunID " << fRunId << "\n";
69 std::cout << "EventID " << fEventId << "\n";
70 std::cout << "Vertex-X " << fX << "\n";
71 std::cout << "Vertex-Y " << fY << "\n";
72 std::cout << "Vertex-Z " << fZ << "\n";
73 std::cout << "Vertex-T " << fT << "\n";
74 std::cout << "Impact-B " << fB << "\n";
75 std::cout << "NPrim " << fNPrim << "\n";
76 // print meta-fields
77 printInfo();
78}
79
128/*****************************************************************/
129/*****************************************************************/
130
131} /* namespace dataformats */
132} /* namespace o2 */
133
ClassImp(o2::dataformats::MCEventHeader)
void printInfo() const
prints a summary of info keys/types attached to this header
static void extractFileFromKinematics(std::string_view kinefilename, std::string_view targetfilename)
create a standalone ROOT file/tree with only the MCHeader branch
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...