ATLAS Offline Software
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
8 #include "xAODForward/AFPSiHit.h"
9 #include "xAODForward/AFPTrack.h"
13 
14 //STL
15 #include <memory> //for unique_ptr
16 
17 //ROOT
18 #include "TFile.h"
19 #include "TH1I.h"
20 
21 AFP_PixelHistoFiller::AFP_PixelHistoFiller(const std::string& name, ISvcLocator* pSvcLocator) :
22  AthAlgorithm(name, pSvcLocator)
23 {
24 }
25 
26 
28 {
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 
88 {
89  const EventContext& ctx = Gaudi::Hive::currentContext();
90 
91  // get event info
93  if (!eventInfo.isValid())
94  {
95  ATH_MSG_WARNING("cannot get eventInfo");
96  return StatusCode::SUCCESS;
97  }
98  else ATH_MSG_DEBUG("successfully got eventInfo");
99 
100  // make sure all the histograms are defined
101  int current_lb=eventInfo->lumiBlock();
102 
103  if(static_cast<int>(m_pixelHits[0][0].size())-1<current_lb/m_LBRangeLength)
104  {
105  for(int st=0;st<m_nStations;++st)
106  {
107  for(int la=0;la<m_nLayers;++la)
108  {
109  for(int add=static_cast<int>(m_pixelHits[st][la].size());add<=current_lb/m_LBRangeLength;++add)
110  {
111  TH2F p_hist(Form("pixel_hits_lb_%d_%d_station_%d_layer_%d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
112  Form("pixel hits, lb %d-%d, station %d, layer %d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
113  m_nPixelsX,0.5,m_nPixelsX+0.5, m_nPixelsY,0.5,m_nPixelsY+1);
114 
115  m_pixelHits[st][la].push_back(p_hist);
116 
117  TH2F c_hist(Form("pixel_clusters_lb_%d_%d_station_%d_layer_%d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
118  Form("pixel_clusters, lb %d-%d, station %d, layer %d", add*m_LBRangeLength,(add+1)*m_LBRangeLength-1,st,la),
119  400,-20, 20, 400, -20, 20);
120 
121  m_pixelCluster[st][la].push_back(c_hist);
122 
123 
124  }
125 
126  }
127  }
128  }
129 
130  int lb_index=current_lb/m_LBRangeLength;
131 
132  // Get containers:
133 
135  if (!afpHitContainer.isValid())
136  {
137  ATH_MSG_WARNING("cannot get AFPSiHitContainer");
138  return StatusCode::SUCCESS;
139  }
140  else ATH_MSG_DEBUG("successfully got AFPSiHitContainer");
141 
143  if(!afpTrackContainer.isValid()){
144  ATH_MSG_WARNING("cannot get AFPTrackContainer");
145  return StatusCode::SUCCESS;
146  }else{
147  ATH_MSG_DEBUG("successfully got AFPTrackContainer");
148  }
149 
150 
151 // Fill histograms:
152 // Pixel hit histograms:
153 
154  for (const xAOD::AFPSiHit* hit : *afpHitContainer)
155  {
156  int st=hit->stationID();
157  int la=hit->pixelLayerID();
158 
159  if(st<0 || m_nStations<=st)
160  {
161  ATH_MSG_INFO("stationID = " <<st<<", but expected values are from 0 to "<<m_nStations-1 );
162  continue;
163  }
164  if(la<0 || m_nLayers<=la)
165  {
166  ATH_MSG_INFO("pixelLayerID = " <<la<<", but expected values are from 0 to "<<m_nLayers-1 );
167  continue;
168  }
169 
170  m_pixelHits[st][la].at(lb_index).Fill(hit->pixelRowIDChip(),hit->pixelColIDChip());
171  }
172 
173 // Histograms for local alignment:
174 
175  // determining numbers for good track selection
176 
177  int nTrks[m_nStations]={0};
178  int nClusterHits[m_nStations]={0};
179  int nClusterHistPerPlane[m_nStations][m_nLayers]={{0}};
180 
181  for(const xAOD::AFPTrack* track: *afpTrackContainer){
182  nTrks[track->stationID()]++;
183  for(const auto& cluster : track->clusters()){
184  nClusterHits[(*cluster)->stationID()]++;
185  nClusterHistPerPlane[(*cluster)->stationID()][(*cluster)->pixelLayerID()]++;
186  }
187  }
188 
189  // looping over tracks
190 
191  for(const xAOD::AFPTrack* track: *afpTrackContainer){
192 
193  if(nTrks[track->stationID()] != 1) continue; //exactly 1 track per station
194 
195  for (const auto& cluster : track->clusters())
196  {
197  int st=(*cluster)->stationID();
198  int la=(*cluster)->pixelLayerID();
199 
200 
201 
202  if(st<0 || m_nStations<=st)
203  {
204  ATH_MSG_INFO("stationID = " <<st<<", but expected values are from 0 to "<<m_nStations-1 );
205  continue;
206  }
207 
208  if(la<0 || m_nLayers<=la)
209  {
210  ATH_MSG_INFO("pixelLayerID = " <<la<<", but expected values are from 0 to "<<m_nLayers-1 );
211  continue;
212  }
213 
214  if(nClusterHits[st]<3 || nClusterHits[st]>4) continue; // 3 or 4 cluster hits per track
215  if(nClusterHistPerPlane[st][la]>1) continue; // 1 cluster hit per plane
216 
217  m_pixelCluster[st][la].at(lb_index).Fill((*cluster)->xLocal(),(*cluster)->yLocal());
218 
219  double dx = 1e3*(track->xLocal() + (*cluster)->zLocal()*track->xSlope() - (*cluster)->xLocal());
220  double dy = 1e3*(track->yLocal() + (*cluster)->zLocal()*track->ySlope() - (*cluster)->yLocal());
221 
222  m_lb_yCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->yLocal(), dy);
223  m_lb_xCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->xLocal(), dx);
224  m_lb_sxTrack_xDistSiTrackCluster[st][la].Fill(current_lb, track->xSlope(), dx);
225  m_lb_syTrack_yDistSiTrackCluster[st][la].Fill(current_lb, track->ySlope(), dy);
226  m_lb_syTrack_xDistSiTrackCluster[st][la].Fill(current_lb, track->ySlope(), dx);
227  m_lb_sxTrack_yDistSiTrackCluster[st][la].Fill(current_lb, track->xSlope(), dy);
228 
229  m_lb_xDistSiTrackCluster[st][la].Fill(current_lb, dx);
230  m_lb_yDistSiTrackCluster[st][la].Fill(current_lb, dy);
231 
232  m_lb_xCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->xLocal(), dy);
233  m_lb_yCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->yLocal(), dx);
234  m_lb_zCluster_xDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->zLocal(), dx);
235  m_lb_zCluster_yDistSiTrackCluster[st][la].Fill(current_lb, (*cluster)->zLocal(), dy);
236 
237  }
238 
239  }
240 
241  return StatusCode::SUCCESS;
242 }
243 
244 
246 {
247  std::unique_ptr<TFile> output_file(new TFile("AFP_PixelHistoFiller.root","recreate"));
248 
249  TH1I lb("LBRangeLength","LBRangeLength",2,0,2);
250  lb.Fill(0.5);
251  lb.Fill(1.5,m_LBRangeLength);
252  lb.Write();
253 
254  for(int st=0;st<m_nStations;++st)
255  {
256  for(int la=0;la<m_nLayers;++la)
257  {
258  m_lb_xDistSiTrackCluster[st][la].Write();
259  m_lb_yDistSiTrackCluster[st][la].Write();
260  m_lb_xCluster_yDistSiTrackCluster[st][la].Write();
261  m_lb_yCluster_xDistSiTrackCluster[st][la].Write();
262  m_lb_zCluster_xDistSiTrackCluster[st][la].Write();
263  m_lb_zCluster_yDistSiTrackCluster[st][la].Write();
264  m_lb_yCluster_yDistSiTrackCluster[st][la].Write();
265  m_lb_xCluster_xDistSiTrackCluster[st][la].Write();
266  m_lb_sxTrack_xDistSiTrackCluster[st][la].Write();
267  m_lb_syTrack_yDistSiTrackCluster[st][la].Write();
268  m_lb_syTrack_xDistSiTrackCluster[st][la].Write();
269  m_lb_sxTrack_yDistSiTrackCluster[st][la].Write();
270 
271  for(TH2F& p_hist: m_pixelHits[st][la])
272  {
273  p_hist.Write();
274  }
275  for(TH2F& c_hist: m_pixelCluster[st][la]){
276  c_hist.Write();
277  }
278 
279  }
280  }
281 
282  output_file->Close();
283 
284  return StatusCode::SUCCESS;
285 }
286 
AFP_PixelHistoFiller::m_lb_sxTrack_xDistSiTrackCluster
TProfile2D m_lb_sxTrack_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:55
AFP_PixelHistoFiller::execute
virtual StatusCode execute() override
Definition: AFP_PixelHistoFiller.cxx:87
AFPSiHitsCluster.h
xAOD::AFPTrack_v2
Class representing a track reconstructed in AFP.
Definition: AFPTrack_v2.h:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
AFP_constants.h
xAOD::AFPSiHit_v2
Class representing a hit in silicon detector.
Definition: AFPSiHit_v2.h:30
AFP_PixelHistoFiller::m_pixelHits
std::vector< TH2F > m_pixelHits[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:43
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
AFP_PixelHistoFiller::m_lb_syTrack_yDistSiTrackCluster
TProfile2D m_lb_syTrack_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:56
AFP_PixelHistoFiller::initialize
virtual StatusCode initialize() override
Definition: AFP_PixelHistoFiller.cxx:27
AFP_PixelHistoFiller::m_lb_zCluster_xDistSiTrackCluster
TProfile2D m_lb_zCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:50
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AFP_PixelHistoFiller::m_afpHitContainerKey
SG::ReadHandleKey< xAOD::AFPSiHitContainer > m_afpHitContainerKey
Definition: AFP_PixelHistoFiller.h:63
AFP_PixelHistoFiller::finalize
virtual StatusCode finalize() override
Definition: AFP_PixelHistoFiller.cxx:245
AFP_PixelHistoFiller::m_nPixelsY
int m_nPixelsY
Definition: AFP_PixelHistoFiller.h:41
AFP_PixelHistoFiller::m_lb_syTrack_xDistSiTrackCluster
TProfile2D m_lb_syTrack_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:57
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
AFP_PixelHistoFiller::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: AFP_PixelHistoFiller.h:62
mergePhysValFiles.output_file
output_file
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:27
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AFP_PixelHistoFiller::m_lb_sxTrack_yDistSiTrackCluster
TProfile2D m_lb_sxTrack_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:58
AFPSiHitsClusterContainer.h
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AFP_PixelHistoFiller::m_lb_xDistSiTrackCluster
TProfile m_lb_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:46
AFPSiHit.h
AFP_PixelHistoFiller::m_lb_xCluster_yDistSiTrackCluster
TProfile2D m_lb_xCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:48
AFP_CONSTANTS::SiT_Pixel_amount_x
static constexpr double SiT_Pixel_amount_x
Definition: AFP_constants.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AFP_PixelHistoFiller::m_nPixelsX
int m_nPixelsX
Definition: AFP_PixelHistoFiller.h:40
AFP_PixelHistoFiller::m_lb_zCluster_yDistSiTrackCluster
TProfile2D m_lb_zCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:51
AFP_PixelHistoFiller::m_lb_yCluster_xDistSiTrackCluster
TProfile2D m_lb_yCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:49
AFP_PixelHistoFiller::m_afpTrackContainerKey
SG::ReadHandleKey< xAOD::AFPTrackContainer > m_afpTrackContainerKey
Definition: AFP_PixelHistoFiller.h:64
AFP_PixelHistoFiller::m_pixelCluster
std::vector< TH2F > m_pixelCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:44
AFP_PixelHistoFiller::m_LBRangeLength
Gaudi::Property< int > m_LBRangeLength
Definition: AFP_PixelHistoFiller.h:60
AFPTrack.h
AFP_PixelHistoFiller::m_lb_yDistSiTrackCluster
TProfile m_lb_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:47
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
AFP_PixelHistoFiller::m_lb_yCluster_yDistSiTrackCluster
TProfile2D m_lb_yCluster_yDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:53
AFP_PixelHistoFiller::m_nLayers
static const int m_nLayers
Definition: AFP_PixelHistoFiller.h:39
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
AFP_PixelHistoFiller::m_lb_xCluster_xDistSiTrackCluster
TProfile2D m_lb_xCluster_xDistSiTrackCluster[m_nStations][m_nLayers]
Definition: AFP_PixelHistoFiller.h:54
AFP_CONSTANTS::SiT_Pixel_amount_y
static constexpr double SiT_Pixel_amount_y
Definition: AFP_constants.h:57
AFP_PixelHistoFiller::AFP_PixelHistoFiller
AFP_PixelHistoFiller(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AFP_PixelHistoFiller.cxx:21
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
AFP_PixelHistoFiller.h
AFP_PixelHistoFiller::m_nStations
static const int m_nStations
Definition: AFP_PixelHistoFiller.h:38