ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimRawNtupleWrapperAlg.cxx
Go to the documentation of this file.
6
7
8
9#include "TFile.h"
10#include "TTree.h"
11
12FPGATrackSimRawNtupleWrapperAlg::FPGATrackSimRawNtupleWrapperAlg (const std::string& name, ISvcLocator* pSvcLocator) :
13 AthAlgorithm(name, pSvcLocator)
14{}
15
16
18{
19
20 ATH_CHECK(m_hitInputTool.retrieve());
21 ATH_MSG_INFO ("Creating output file: " );
22 m_outfile = TFile::Open(m_outpath.value().c_str(),"recreate");
24
25 // create a TTree to store the truth tracks
26 m_trackstree = new TTree("truthtracks","Truth tracks");
27 // add the branch related to the truth tracks
28 m_trackstree->Branch("TruthTracks",&m_truth_tracks);
29
30 // create a TTree to store event information
31 m_evtinfo = new TTree("evtinfo","Events info");
32 m_evtinfo->Branch("RunNumber",&m_run_number,"RunNumber/I");
33 m_evtinfo->Branch("EventNumber",&m_event_number,"EventNumber/I");
34 m_evtinfo->Branch("LB",&m_LB,"LB/I");
35 m_evtinfo->Branch("BCID",&m_BCID,"BCID/I");
36 m_evtinfo->Branch("ExtendedLevel1ID",&m_extendedLevel1ID,"ExtendedLevel1ID/i");
37 m_evtinfo->Branch("Level1TriggerType",&m_level1TriggerType,"Level1TriggerType/i");
38 m_evtinfo->Branch("Level1TriggerInfo",&m_level1TriggerInfo);
39 m_evtinfo->Branch("AverageInteractionsPerCrossing",&m_averageInteractionsPerCrossing,"AverageInteractionsPerCrossing/F");
40 m_evtinfo->Branch("ActualInteractionsPerCrossing",&m_actualInteractionsPerCrossing,"ActualInteractionsPerCrossing/F");
41
42 // create and populate the TTree
43 m_hittree = new TTree("htthits","Raw hits for the FPGATrackSim simulation");
44 // prepare a branch for each tower
45 m_original_hits = new std::vector<FPGATrackSimHit>[m_ntowers];
46 for (unsigned int ireg=0;ireg!=m_ntowers;++ireg) { // towers loop
47 m_hittree->Branch(Form("RawHits%d.",ireg),&m_original_hits[ireg], 32000, 1);
48 } // end towers loop
49
50
51 if (m_getOffline) {
52
53 m_offline_locX = new std::vector<float>;
54 m_offline_locY = new std::vector<float>;
55 m_offline_isPixel = new std::vector<int>;
56 m_offline_isBarrel = new std::vector<int>;
57 m_offline_layer = new std::vector<int>;
58 m_offline_clustID = new std::vector<int>;
59 m_offline_trackNumber = new std::vector<int>;
60
61 m_offline_qoverpt = new std::vector<float>;
62 m_offline_eta = new std::vector<float>;
63 m_offline_phi = new std::vector<float>;
64 m_offline_d0 = new std::vector<float>;
65 m_offline_z0 = new std::vector<float>;
66
67 m_offline_barcode = new std::vector<int>;
68 m_offline_barcode_frac = new std::vector<float>;
69
70
71 m_offline_cluster_tree = new TTree("offline_cluster_tree","offline_cluster_tree");
72
73 m_offline_cluster_tree->Branch("offline_locX",&m_offline_locX);
74 m_offline_cluster_tree->Branch("offline_locY",&m_offline_locY);
75 m_offline_cluster_tree->Branch("offline_is_Pixel",&m_offline_isPixel);
76 m_offline_cluster_tree->Branch("offline_is_Barrel",&m_offline_isBarrel);
77 m_offline_cluster_tree->Branch("offline_layer",&m_offline_layer);
78 m_offline_cluster_tree->Branch("offline_clustID",&m_offline_clustID);
79 m_offline_cluster_tree->Branch("offline_trackNumber",&m_offline_trackNumber);
80
81 m_offline_cluster_tree->Branch("offline_qoverpt",&m_offline_qoverpt);
82 m_offline_cluster_tree->Branch("offline_eta",&m_offline_eta);
83 m_offline_cluster_tree->Branch("offline_phi",&m_offline_phi);
84 m_offline_cluster_tree->Branch("offline_d0",&m_offline_d0);
85 m_offline_cluster_tree->Branch("offline_z0",&m_offline_z0);
86
87 m_offline_cluster_tree->Branch("offline_barcode",&m_offline_barcode);
88 m_offline_cluster_tree->Branch("offline_barcode_frac",&m_offline_barcode_frac);
89 }
90
91 // eventually add some histograms for monitoring?
92 return StatusCode::SUCCESS;
93}
94
95
96
98 ATH_MSG_DEBUG ( "Start execute");
99 bool last=false;
100 ATH_CHECK (m_hitInputTool->readData(m_eventHeader, last));
101 if (last) return StatusCode::SUCCESS;
103
104
105 // reset the branches
106 for (unsigned int ireg=0;ireg!=m_ntowers;++ireg) {
107 m_original_hits[ireg].clear();
108 }
109
110 const FPGATrackSimEventInfo event=m_eventHeader->event();
111 m_run_number = event.runNumber(); // event's run number
112 m_event_number = event.eventNumber(); // event number
113 m_LB = event.LB();
114 m_BCID = event.BCID();
115 m_averageInteractionsPerCrossing = event.averageInteractionsPerCrossing();
116 m_actualInteractionsPerCrossing = event.actualInteractionsPerCrossing();
117 m_level1TriggerType = event.level1TriggerType();
118 m_level1TriggerInfo = event.level1TriggerInfo();
119 m_extendedLevel1ID = event.extendedLevel1ID();
120 m_evtinfo->Fill();
121
122 std::vector<FPGATrackSimHit> fulllist = m_eventHeader->hits();
123 ATH_MSG_VERBOSE("Going to run on "<< fulllist.size()<<" hits");
124
125 std::vector<FPGATrackSimHit>::const_iterator ihit = fulllist.begin();
126 std::vector<FPGATrackSimHit>::const_iterator ihitE = fulllist.end();
127 for (;ihit!=ihitE;++ihit) { // hit loop
128 const FPGATrackSimHit &currawhit = *ihit;
129 for (unsigned int ireg=0;ireg!=m_ntowers;++ireg) {
130 // if the equivalent hit is compatible with this tower the hit is saved
131 m_original_hits[ireg].push_back(currawhit);
132 }
133 }
134
135 m_hittree->Fill();
136
137 //truth tracks
138 m_truth_tracks.clear();
139 const std::vector<FPGATrackSimTruthTrack> &truthtracks = m_eventHeader->optional().getTruthTracks();
140 m_truth_tracks.insert(m_truth_tracks.end(),truthtracks.begin(),truthtracks.end());
141 // Write the tracks
142 m_trackstree->Fill();
143
144
145 if (m_getOffline) {
146
147 m_offline_locX->clear();
148 m_offline_locY->clear();
149 m_offline_isPixel->clear();
150 m_offline_isBarrel->clear();
151 m_offline_layer->clear();
152 m_offline_clustID->clear();
153 m_offline_trackNumber->clear();
154
155 m_offline_qoverpt->clear();
156 m_offline_eta->clear();
157 m_offline_phi->clear();
158 m_offline_d0->clear();
159 m_offline_z0->clear();
160
161 m_offline_barcode->clear();
162 m_offline_barcode_frac->clear();
163
164 const std::vector<FPGATrackSimOfflineTrack> &offlinetracks = m_eventHeader->optional().getOfflineTracks();
165
166 for (auto &offline_t: offlinetracks){
167
168 m_offline_qoverpt->push_back(offline_t.getQOverPt());
169 m_offline_eta->push_back(offline_t.getEta());
170 m_offline_phi->push_back(offline_t.getPhi());
171 m_offline_d0->push_back(offline_t.getD0());
172 m_offline_z0->push_back(offline_t.getZ0());
173 m_offline_barcode->push_back(offline_t.getBarcode());
174 m_offline_barcode_frac->push_back(offline_t.getBarcodeFrac());
175
176 for (auto &hit: offline_t.getOfflineHits()){
177 m_offline_isPixel->push_back(hit.isPixel());
178 m_offline_isBarrel->push_back(hit.isBarrel());
179 m_offline_clustID->push_back(hit.getClusterID());
180 m_offline_trackNumber->push_back(hit.getTrackNumber());
181 m_offline_layer->push_back(hit.getLayer());
182 m_offline_locX->push_back(hit.getLocX());
183 m_offline_locY->push_back(hit.getLocY());
184 }
185
186 }
187
189 }
190
191
192 return StatusCode::SUCCESS;
193}
194
195
197{
198 // close the output files, but check that it exists (for athenaMT)
199 if (m_outfile) {
200 m_outfile->Write();
201 m_outfile->Close();
202 }
203
204 return StatusCode::SUCCESS;
205}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
std::vector< FPGATrackSimTruthTrack > m_truth_tracks
FPGATrackSimRawNtupleWrapperAlg(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< IFPGATrackSimEventInputHeaderTool > m_hitInputTool
std::vector< FPGATrackSimHit > * m_original_hits
FPGATrackSimEventInputHeader * m_eventHeader
TTree * m_trackstree
TTree with general event information.