ATLAS Offline Software
Loading...
Searching...
No Matches
AFP_PixelHistoFiller.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//local object includes
13
14//STL
15#include <memory> //for unique_ptr
16
17//ROOT
18#include "TFile.h"
19#include "TH1I.h"
20
21AFP_PixelHistoFiller::AFP_PixelHistoFiller(const std::string& name, ISvcLocator* pSvcLocator) :
22 AthAlgorithm(name, pSvcLocator)
23{
24}
25
26
28{
29 ATH_CHECK( m_eventInfoKey.initialize() );
30 ATH_CHECK( m_afpHitContainerKey.initialize() );
31 ATH_CHECK( m_afpTrackContainerKey.initialize() );
32
35
36 for(int st=0;st<m_nStations;++st)
37 {
38 for(int la=0;la<m_nLayers;++la)
39 {
40 m_pixelHits[st][la].clear();
41 m_pixelCluster[st][la].clear();
42
43
44 TProfile lb_dx(Form("lb_dx_station_%d_layer_%d", st,la), Form("lb_dx, station %d, layer %d", st,la), 100, 0, 1000);
45 m_lb_xDistSiTrackCluster[st][la] = lb_dx;
46
47 TProfile lb_dy(Form("lb_dy_station_%d_layer_%d", st,la), Form("lb_dy, station %d, layer %d", st,la), 100, 0, 1000);
48 m_lb_yDistSiTrackCluster[st][la] = lb_dy;
49
50 TProfile2D lb_yc_dy(Form("lb_yCluster_dy_station_%d_layer_%d", st,la), Form("lb_yCluster_dy, station %d, layer %d", st,la), 100, 0, 1000, 40, -20., 20.);
51 m_lb_yCluster_yDistSiTrackCluster[st][la] = lb_yc_dy;
52
53 TProfile2D lb_xc_dx(Form("lb_xCluster_dx_station_%d_layer_%d", st,la), Form("lb_xCluster_dx, station %d, layer %d", st,la), 100, 0, 1000, 40, -20., 20.);
54 m_lb_xCluster_xDistSiTrackCluster[st][la] = lb_xc_dx;
55
56 TProfile2D lb_xC_dy(Form("lb_xCluster_dy_station_%d_layer_%d", st, la), Form("lb_xCluster_dy, station %d, layer %d", st, la), 100, 0, 1000, 40, -20, 20);
57 m_lb_xCluster_yDistSiTrackCluster[st][la] = lb_xC_dy;
58
59 TProfile2D lb_yC_dx(Form("lb_yCluster_dx_station_%d_layer_%d", st, la), Form("lb_yCluster_dx, station %d, layer %d", st, la), 100, 0, 1000, 40, -20, 20);
60 m_lb_yCluster_xDistSiTrackCluster[st][la] = lb_yC_dx;
61
62 TProfile2D lb_zC_dx(Form("lb_zCluster_dx_station_%d_layer_%d", st, la), Form("lb_zCluster_dx, station %d, layer %d", st, la), 100, 0, 1000, 100, 9*la - 3, 9*(la+1));
63 m_lb_zCluster_xDistSiTrackCluster[st][la] = lb_zC_dx;
64
65 TProfile2D lb_zC_dy(Form("lb_zCluster_dy_station_%d_layer_%d", st, la), Form("lb_zCluster_dy, station %d, layer %d", st, la), 100, 0, 1000, 100, 9*la - 3, 9*(la+1));
66 m_lb_zCluster_yDistSiTrackCluster[st][la] = lb_zC_dy;
67
68 TProfile2D lb_sx_dx(Form("lb_xSlopeTrack_dx_station_%d_layer_%d",st,la), Form("xSlopeTrack_dx, station %d, layer %d", st,la), 100, 0, 1000, 100, -1., 1.);
69 m_lb_sxTrack_xDistSiTrackCluster[st][la] = lb_sx_dx;
70
71 TProfile2D lb_sy_dy(Form("lb_ySlopeTrack_dy_station_%d_layer_%d", st,la), Form("lb_ySlopeTrack_dy, station %d, layer %d", st,la), 100, 0, 1000, 100, -1., 1.);
72 m_lb_syTrack_yDistSiTrackCluster[st][la] = lb_sy_dy;
73
74 TProfile2D lb_sy_dx(Form("lb_ySlopeTrack_dx_station_%d_layer_%d", st,la), Form("lb_ySlopeTrack_dx, station %d, layer %d", st,la), 100, 0, 1000, 100, -1., 1.);
75 m_lb_syTrack_xDistSiTrackCluster[st][la] = lb_sy_dx;
76
77 TProfile2D lb_sx_dy(Form("lb_xSlopeTrack_dy_station_%d_layer_%d", st,la), Form("lb_xSlopeTrack_dy, station %d, layer %d", st,la), 100, 0, 1000, 100, -1., 1.);
78 m_lb_sxTrack_yDistSiTrackCluster[st][la] = lb_sx_dy;
79
80 }
81 }
82
83 return StatusCode::SUCCESS;
84}
85
86
87StatusCode AFP_PixelHistoFiller::execute(const EventContext& ctx)
88{
89
90 // get event info
92 if (!eventInfo.isValid())
93 {
94 ATH_MSG_WARNING("cannot get eventInfo");
95 return StatusCode::SUCCESS;
96 }
97 else ATH_MSG_DEBUG("successfully got eventInfo");
98
99 // make sure all the histograms are defined
100 int current_lb=eventInfo->lumiBlock();
101
102 if(static_cast<int>(m_pixelHits[0][0].size())-1<current_lb/m_LBRangeLength)
103 {
104 for(int st=0;st<m_nStations;++st)
105 {
106 for(int la=0;la<m_nLayers;++la)
107 {
108 for(int add=static_cast<int>(m_pixelHits[st][la].size());add<=current_lb/m_LBRangeLength;++add)
109 {
110 TH2F p_hist(Form("pixel_hits_lb_%d_%d_station_%d_layer_%d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
111 Form("pixel hits, lb %d-%d, station %d, layer %d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
113
114 m_pixelHits[st][la].push_back(p_hist);
115
116 TH2F c_hist(Form("pixel_clusters_lb_%d_%d_station_%d_layer_%d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
117 Form("pixel_clusters, lb %d-%d, station %d, layer %d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
118 400,-20, 20, 400, -20, 20);
119
120 m_pixelCluster[st][la].push_back(c_hist);
121
122
123 }
124
125 }
126 }
127 }
128
129 int lb_index=current_lb/m_LBRangeLength;
130
131 // Get containers:
132
134 if (!afpHitContainer.isValid())
135 {
136 ATH_MSG_WARNING("cannot get AFPSiHitContainer");
137 return StatusCode::SUCCESS;
138 }
139 else ATH_MSG_DEBUG("successfully got AFPSiHitContainer");
140
142 if(!afpTrackContainer.isValid()){
143 ATH_MSG_WARNING("cannot get AFPTrackContainer");
144 return StatusCode::SUCCESS;
145 }else{
146 ATH_MSG_DEBUG("successfully got AFPTrackContainer");
147 }
148
149
150// Fill histograms:
151// Pixel hit histograms:
152
153 for (const xAOD::AFPSiHit* hit : *afpHitContainer)
154 {
155 int st=hit->stationID();
156 int la=hit->pixelLayerID();
157
158 if(st<0 || m_nStations<=st)
159 {
160 ATH_MSG_INFO("stationID = " <<st<<", but expected values are from 0 to "<<m_nStations-1 );
161 continue;
162 }
163 if(la<0 || m_nLayers<=la)
164 {
165 ATH_MSG_INFO("pixelLayerID = " <<la<<", but expected values are from 0 to "<<m_nLayers-1 );
166 continue;
167 }
168
169 m_pixelHits[st][la].at(lb_index).Fill(hit->pixelRowIDChip(),hit->pixelColIDChip());
170 }
171
172// Histograms for local alignment:
173
174 // determining numbers for good track selection
175
176 int nTrks[m_nStations]={0};
177 int nClusterHits[m_nStations]={0};
178 int nClusterHistPerPlane[m_nStations][m_nLayers]={{0}};
179
180 for(const xAOD::AFPTrack* track: *afpTrackContainer){
181 nTrks[track->stationID()]++;
182 for(const auto& cluster : track->clusters()){
183 nClusterHits[(*cluster)->stationID()]++;
184 nClusterHistPerPlane[(*cluster)->stationID()][(*cluster)->pixelLayerID()]++;
185 }
186 }
187
188 // looping over tracks
189
190 for(const xAOD::AFPTrack* track: *afpTrackContainer){
191
192 if(nTrks[track->stationID()] != 1) continue; //exactly 1 track per station
193
194 for (const auto& cluster : track->clusters())
195 {
196 int st=(*cluster)->stationID();
197 int la=(*cluster)->pixelLayerID();
198
199
200
201 if(st<0 || m_nStations<=st)
202 {
203 ATH_MSG_INFO("stationID = " <<st<<", but expected values are from 0 to "<<m_nStations-1 );
204 continue;
205 }
206
207 if(la<0 || m_nLayers<=la)
208 {
209 ATH_MSG_INFO("pixelLayerID = " <<la<<", but expected values are from 0 to "<<m_nLayers-1 );
210 continue;
211 }
212
213 if(nClusterHits[st]<3 || nClusterHits[st]>4) continue; // 3 or 4 cluster hits per track
214 if(nClusterHistPerPlane[st][la]>1) continue; // 1 cluster hit per plane
215
216 m_pixelCluster[st][la].at(lb_index).Fill((*cluster)->xLocal(),(*cluster)->yLocal());
217
218 double dx = 1e3*(track->xLocal() + (*cluster)->zLocal()*track->xSlope() - (*cluster)->xLocal());
219 double dy = 1e3*(track->yLocal() + (*cluster)->zLocal()*track->ySlope() - (*cluster)->yLocal());
220
221 m_lb_yCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->yLocal(), dy);
222 m_lb_xCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->xLocal(), dx);
223 m_lb_sxTrack_xDistSiTrackCluster[st][la].Fill(current_lb, track->xSlope(), dx);
224 m_lb_syTrack_yDistSiTrackCluster[st][la].Fill(current_lb, track->ySlope(), dy);
225 m_lb_syTrack_xDistSiTrackCluster[st][la].Fill(current_lb, track->ySlope(), dx);
226 m_lb_sxTrack_yDistSiTrackCluster[st][la].Fill(current_lb, track->xSlope(), dy);
227
228 m_lb_xDistSiTrackCluster[st][la].Fill(current_lb, dx);
229 m_lb_yDistSiTrackCluster[st][la].Fill(current_lb, dy);
230
231 m_lb_xCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->xLocal(), dy);
232 m_lb_yCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->yLocal(), dx);
233 m_lb_zCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->zLocal(), dx);
234 m_lb_zCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->zLocal(), dy);
235
236 }
237
238 }
239
240 return StatusCode::SUCCESS;
241}
242
243
245{
246 std::unique_ptr<TFile> output_file(new TFile("AFP_PixelHistoFiller.root","recreate"));
247
248 TH1I lb("LBRangeLength","LBRangeLength",2,0,2);
249 lb.Fill(0.5);
250 lb.Fill(1.5,m_LBRangeLength);
251 lb.Write();
252
253 for(int st=0;st<m_nStations;++st)
254 {
255 for(int la=0;la<m_nLayers;++la)
256 {
257 m_lb_xDistSiTrackCluster[st][la].Write();
258 m_lb_yDistSiTrackCluster[st][la].Write();
259 m_lb_xCluster_yDistSiTrackCluster[st][la].Write();
260 m_lb_yCluster_xDistSiTrackCluster[st][la].Write();
261 m_lb_zCluster_xDistSiTrackCluster[st][la].Write();
262 m_lb_zCluster_yDistSiTrackCluster[st][la].Write();
263 m_lb_yCluster_yDistSiTrackCluster[st][la].Write();
264 m_lb_xCluster_xDistSiTrackCluster[st][la].Write();
265 m_lb_sxTrack_xDistSiTrackCluster[st][la].Write();
266 m_lb_syTrack_yDistSiTrackCluster[st][la].Write();
267 m_lb_syTrack_xDistSiTrackCluster[st][la].Write();
268 m_lb_sxTrack_yDistSiTrackCluster[st][la].Write();
269
270 for(TH2F& p_hist: m_pixelHits[st][la])
271 {
272 p_hist.Write();
273 }
274 for(TH2F& c_hist: m_pixelCluster[st][la]){
275 c_hist.Write();
276 }
277
278 }
279 }
280
281 output_file->Close();
282
283 return StatusCode::SUCCESS;
284}
285
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
size_t size() const
Number of registered mappings.
Gaudi::Property< int > m_LBRangeLength
TProfile2D m_lb_zCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
virtual StatusCode initialize() override
virtual StatusCode finalize() override
TProfile2D m_lb_sxTrack_xDistSiTrackCluster[m_nStations][m_nLayers]
SG::ReadHandleKey< xAOD::AFPTrackContainer > m_afpTrackContainerKey
std::vector< TH2F > m_pixelCluster[m_nStations][m_nLayers]
TProfile2D m_lb_yCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
TProfile2D m_lb_xCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
static const int m_nStations
TProfile2D m_lb_yCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
SG::ReadHandleKey< xAOD::AFPSiHitContainer > m_afpHitContainerKey
TProfile m_lb_xDistSiTrackCluster[m_nStations][m_nLayers]
TProfile2D m_lb_xCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
TProfile2D m_lb_sxTrack_yDistSiTrackCluster[m_nStations][m_nLayers]
TProfile2D m_lb_syTrack_xDistSiTrackCluster[m_nStations][m_nLayers]
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
AFP_PixelHistoFiller(const std::string &name, ISvcLocator *pSvcLocator)
TProfile2D m_lb_zCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
TProfile2D m_lb_syTrack_yDistSiTrackCluster[m_nStations][m_nLayers]
TProfile m_lb_yDistSiTrackCluster[m_nStations][m_nLayers]
std::vector< TH2F > m_pixelHits[m_nStations][m_nLayers]
virtual StatusCode execute()
Execute method without EventContext (deprecated).
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual bool isValid() override final
Can the handle be successfully dereferenced?
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
int lb
Definition globals.cxx:23
AFPSiHit_v2 AFPSiHit
Definition AFPSiHit.h:12
AFPTrack_v2 AFPTrack
Definition AFPTrack.h:12
static constexpr double SiT_Pixel_amount_y
static constexpr double SiT_Pixel_amount_x