ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "GaudiKernel/MsgStream.h"
12#include <iostream>
13#include <TTree.h>
14
15namespace ClusterSeg {
16
18 init();
19 tree.Branch("nclusters",&nclusters,"nclusters/I");
20 tree.Branch("x",&x,"x[nclusters]/D");
21 tree.Branch("y",&y,"y[nclusters]/D");
22 tree.Branch("z",&z,"z[nclusters]/D");
23 tree.Branch("isPhi",&isPhi,"isPhi[nclusters]/O");
24 tree.Branch("techIndex",&tIndex,"techIndex[nclusters]/I");
25 tree.Branch("phiIndex",&pIndex,"phiIndex[nclusters]/I");
26 tree.Branch("isMatch",&isMatch,"isMatch[nclusters]/O");
27 tree.Branch("barcode",&barcode,"barcode[nclusters]/I");
28 tree.Branch("ntracks",&ntracks,"ntracks/I");
29 tree.Branch("chi2",&chi2,"chi2[ntracks]/D");
30 tree.Branch("ntracksT",&ntracksT,"ntracksT/I");
31 tree.Branch("chi2T",&chi2T,"chi2T[ntracksT]/D");
32 tree.Branch("nMDT",&nMDT,"nMDT/I");
33 tree.Branch("residual",&residual,"residual[nMDT]/D");
34 tree.Branch("nMDTT",&nMDTT,"nMDTT/I");
35 tree.Branch("residualT",&residualT,"residualT[nMDTT]/D");
36 }
37
39 tree.SetBranchAddress("nclusters",&nclusters);
40 tree.SetBranchAddress("x",&x);
41 tree.SetBranchAddress("y",&y);
42 tree.SetBranchAddress("z",&z);
43 tree.SetBranchAddress("isPhi",&isPhi);
44 tree.SetBranchAddress("techIndex",&tIndex);
45 tree.SetBranchAddress("phiIndex",&pIndex);
46 tree.SetBranchAddress("isMatch",&isMatch);
47 tree.SetBranchAddress("barcode",&barcode);
48 }
49
50 void ClusterNtuple::fill( const std::vector<Cluster*>& clusters) {
51 for(const auto& it: clusters) fill(*it);
52 }
53
54 void ClusterNtuple::fill( const Cluster& cluster ){
55 if( nclusters >= CLUSTERSIZE ) return;
56 x[nclusters] = cluster.m_x;
57 y[nclusters] = cluster.m_y;
58 z[nclusters] = cluster.m_z;
59 isPhi[nclusters] = cluster.m_isPhi;
60 tIndex[nclusters] = (int)cluster.m_tIndex;
61 pIndex[nclusters] = (int)cluster.m_pIndex;
62 isMatch[nclusters] = cluster.m_isMatch;
63 barcode[nclusters] = cluster.m_barcode;
64 ++nclusters;
65 }
66
67 void ClusterNtuple::fill(const double& theVal,FillType theFillType) {
68 if (theFillType == FillType::chi2){
69 if( ntracks >= CLUSTERSIZE ) return;
70 chi2[ntracks] = theVal;
71 ++ntracks;
72 }
73
74 if (theFillType == FillType::chi2T){
75 if( ntracksT >= CLUSTERSIZE ) return;
76 chi2T[ntracksT] = theVal;
77 ++ntracksT;
78 }
79
80 if (theFillType == FillType::residual){
81 if( ntracks >= CLUSTERSIZE ) return;
82 residual[nMDT] = theVal;
83 ++nMDT;
84 }
85
86 if (theFillType == FillType::residualT){
87 if( ntracksT >= CLUSTERSIZE ) return;
88 residualT[nMDTT] = theVal;
89 ++nMDTT;
90 }
91
92 }
93
95 nclusters = 0;
96 ntracks = 0;
97 ntracksT = 0;
98 nMDT = 0;
99 nMDTT = 0;
100 }
101
102 bool ClusterNtuple::read( std::vector<Cluster*>& clusters) {
103 if( nclusters == 0 ) {
104 MsgStream log(Athena::getMessageSvc(),"ClusterNtuple::read");
105 if(log.level()<=MSG::DEBUG) log << MSG::DEBUG << " ntuple not initialized for reading " << endmsg;
106 return false;
107 }
108
109 for( int i=0;i<nclusters;++i){
110 Cluster* cluster = new Cluster(x[i],y[i],z[i],isPhi[i],tIndex[i],pIndex[i],isMatch[i],barcode[i]);
111 clusters.push_back(cluster);
112 }
113
114 return true;
115 }
116
117 void ClusterNtuple::clean( std::vector<Cluster*>& clusters) {
118 for(auto& it: clusters) delete it;
119 }
120
122 nclusters = 0;
123 ntracks = 0;
124 ntracksT = 0;
125 nMDT = 0;
126 nMDTT = 0;
127 }
128
129}
#define endmsg
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
int tIndex[CLUSTERSIZE]
int pIndex[CLUSTERSIZE]
static void clean(std::vector< Cluster * > &clusters)
double chi2[CLUSTERSIZE]
double x[CLUSTERSIZE]
int barcode[CLUSTERSIZE]
double chi2T[CLUSTERSIZE]
void initForWrite(TTree &tree)
bool isPhi[CLUSTERSIZE]
double residual[CLUSTERSIZE]
void fill(const double &fillVal, FillType theFillType)
void initForRead(TTree &tree)
double z[CLUSTERSIZE]
static const int CLUSTERSIZE
bool read(std::vector< Cluster * > &clusters)
double residualT[CLUSTERSIZE]
double y[CLUSTERSIZE]
bool isMatch[CLUSTERSIZE]
TChain * tree