ATLAS Offline Software
Loading...
Searching...
No Matches
SurveyConstraintTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GaudiKernel/MsgStream.h"
8
13#include "TH1F.h"
14#include "GaudiKernel/SmartDataPtr.h"
15#include "GaudiKernel/NTuple.h"
16#include "GaudiKernel/INTupleSvc.h"
17#include <cmath>
18
20
22
23SurveyConstraintTestAlg::SurveyConstraintTestAlg(const std::string& name, ISvcLocator* pSvcLocator) :
24AthAlgorithm(name, pSvcLocator),
26 m_pixid{},
27 m_sctid{},
32 m_NLoop(1){
33
34// Part 2: Properties go here
35 declareProperty("NLoop" , m_NLoop);
36
37
38}
39
40// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
41
43
44 // Part 1: Get the messaging service, print where you are
45 ATH_MSG_DEBUG( "initialize()" );
46
47 // Get The ToolSvc
48 SmartIF<IToolSvc> toolSvc{Gaudi::svcLocator()->service("ToolSvc")};
49 ATH_CHECK(toolSvc.isValid());
50
51 // Get SurveyConstraint from ToolService
52 ATH_CHECK( toolSvc->retrieveTool("SurveyConstraint",m_SurvConstr));
53
54 // get ID helpers from detector store (relying on GeoModel to put them)
55 ATH_CHECK(detStore()->retrieve(m_pixid));
56 ATH_CHECK(detStore()->retrieve(m_sctid));
57 ATH_MSG_DEBUG( "got ID helpers from detector store (relying on GeoModel to put them)" );
58
59 // book histograms
62
63return StatusCode::SUCCESS;
64}
65
67 StatusCode sc;
68 // initialize AlignResults NTuple
69
70 NTupleFilePtr file1(ntupleSvc(), "/NTUPLES/FILE1");
71
72 NTuplePtr nt(ntupleSvc(), "/NTUPLES/FILE1/InitialAlignment");
73 if ( !nt ) { // Check if already booked
74 nt = ntupleSvc()->book("/NTUPLES/FILE1/InitialAlignment", CLID_ColumnWiseTuple, "InitialAlignment");
75 if ( nt ) {
76 ATH_MSG_INFO( "InitialAlignment ntuple booked." );
77
78 sc = nt->addItem("x" , m_AlignResults_x);
79 sc = nt->addItem("y" , m_AlignResults_y);
80 sc = nt->addItem("z" , m_AlignResults_z);
81 sc = nt->addItem("alpha" , m_AlignResults_alpha);
82 sc = nt->addItem("beta" , m_AlignResults_beta);
83 sc = nt->addItem("gamma" , m_AlignResults_gamma);
84 sc = nt->addItem("ID" , m_AlignResults_Identifier_ID);
85 sc = nt->addItem("PixelSCT" , m_AlignResults_Identifier_SCT);
86 sc = nt->addItem("BarrelEC" , m_AlignResults_Identifier_BarrelEC);
87 sc = nt->addItem("LayerDisc" , m_AlignResults_Identifier_LayerDisc);
88 sc = nt->addItem("Phi" , m_AlignResults_Identifier_Phi);
89 sc = nt->addItem("Eta" , m_AlignResults_Identifier_Eta);
90
91 } else { // did not manage to book the N tuple....
92 ATH_MSG_ERROR( "Failed to book InitialAlignment ntuple." );
93 }
94 }
95
97 int SCT,barrel_ec,layer_disk,phi,eta;
98 std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> > ModuleMap;
99 m_SurvConstr -> MMap(ModuleMap);
100 std::map<Identifier, SurveyConstraintModule*, std::less<Identifier> >::iterator it;
101 for (it = ModuleMap.begin(); it != ModuleMap.end(); ++it) {
102 const Identifier& ModuleID = (it->second)->moduleID();
103 SurveyConstraintModule* mut = ModuleMap[ModuleID];
104 if(mut->isPixel()){
105 SCT = 1;
106 barrel_ec = m_pixid->barrel_ec(ModuleID);
107 layer_disk = m_pixid->layer_disk(ModuleID);
108 phi = m_pixid->phi_module(ModuleID);
109 eta = m_pixid->eta_module(ModuleID);
110 } else {
111 if (m_sctid->side(ModuleID) != 0) continue;
112 SCT = 2;
113 barrel_ec = m_sctid->barrel_ec(ModuleID);
114 layer_disk = m_sctid->layer_disk(ModuleID);
115 phi = m_sctid->phi_module(ModuleID);
116 eta = m_sctid->eta_module(ModuleID);
117 }
118 Amg::VectorX Misalign = mut->DOCA_Vector();
119 m_AlignResults_x = Misalign[0];
120 m_AlignResults_y = Misalign[1];
121 m_AlignResults_z = Misalign[2];
122 m_AlignResults_alpha = Misalign[3];
123 m_AlignResults_beta = Misalign[4];
124 m_AlignResults_gamma = Misalign[5];
131
133
134 // Write out AlignResults ntuple
135 sc = ntupleSvc()->writeRecord("NTUPLES/FILE1/InitialAlignment");
136 if (sc.isFailure()) {
137 ATH_MSG_ERROR( "Could not write InitialAlignment ntuple." );
138 }
139
140 } // end of module loop
141 }
142
143// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
144
146
147// Part 1: Get the messaging service, print where you are
148ATH_MSG_INFO( "execute()" );
149
150 float multipl=1.E3;
151
152 Amg::VectorX dparams(6); // alignment parameters
153 double deltachisq = 0;
154 Amg::VectorX DOCA_Vector(6);
155 Amg::MatrixX DOCA_Matrix(6,6);
156
157 // Pix EC
158 bool NewDisk = true, NewSector = true;
159 int previous_disk = -1, previous_sector = -1;
160 for(int i=0;i!=m_NLoop;++i){
161 if(i!=0){m_SurvConstr -> finalize().ignore();m_SurvConstr -> setup_SurveyConstraintModules();}
162 for (PixelID::const_id_iterator wafer_it=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
163 const Identifier Pixel_ModuleID = *wafer_it;
164 if(std::abs(m_pixid->barrel_ec(Pixel_ModuleID)) == 2){
165 ATH_CHECK(m_SurvConstr -> computeConstraint(Pixel_ModuleID,
166 dparams,
167 deltachisq,
168 DOCA_Vector,
169 DOCA_Matrix));
170
171
172 if(previous_disk == m_pixid->layer_disk(Pixel_ModuleID) &&
173 previous_sector == m_SurvConstr->SectorNumber(m_pixid->phi_module(Pixel_ModuleID)))
174 NewSector=false;
175 else NewSector=true;
176 if(previous_disk == m_pixid->layer_disk(Pixel_ModuleID))
177 NewDisk=false;
178 else NewDisk=true;
179 if (NewDisk) for (unsigned int i=0;i!=6;++i) m_h_PixEC_Align_Disk[i] -> Fill(multipl*dparams[i]);
180 if (NewSector) for (unsigned int i=0;i!=6;++i) m_h_PixEC_Align_first[i] -> Fill(multipl*dparams[i]);
181 else for (unsigned int i=0;i!=6;++i) m_h_PixEC_Align[i] -> Fill(multipl*dparams[i]);
182 previous_disk = m_pixid->layer_disk(Pixel_ModuleID);
183 previous_sector = m_SurvConstr->SectorNumber(m_pixid->phi_module(Pixel_ModuleID));
184
185 ATH_MSG_DEBUG( "Pixel_ModuleID = " << Pixel_ModuleID);
186 ATH_MSG_DEBUG( "alignment parameters = (" << dparams[0] << "," << dparams[1] << "," << dparams[2] << "," << dparams[3] << "," << dparams[4] << "," << dparams[5] << ")");
187 ATH_MSG_DEBUG( "chi^2 = " << deltachisq);
188 ATH_MSG_DEBUG( "DOCA_Vector = (" << DOCA_Vector[0] << "," << DOCA_Vector[1] << "," << DOCA_Vector[2] << "," << DOCA_Vector[3] << "," << DOCA_Vector[4] << "," << DOCA_Vector[5] << ")");
189 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,0) << "," << DOCA_Matrix(2,0) << "," << DOCA_Matrix(3,0) << "," << DOCA_Matrix(4,0) << "," << DOCA_Matrix(5,0) << ")");
190 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,1) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,1) << "," << DOCA_Matrix(3,1) << "," << DOCA_Matrix(4,1) << "," << DOCA_Matrix(5,1) << ")");
191 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,2) << "," << DOCA_Matrix(3,2) << "," << DOCA_Matrix(4,4) << "," << DOCA_Matrix(5,5) << ")");
192 //break;
193 }
194 }
195 }
196
197 // Pix B
198 for (PixelID::const_id_iterator wafer_it=m_pixid->wafer_begin(); wafer_it!=m_pixid->wafer_end(); ++wafer_it) {
199 const Identifier Pixel_ModuleID = *wafer_it;
200 if(m_pixid->barrel_ec(Pixel_ModuleID) == 0){
201 ATH_CHECK(m_SurvConstr -> computeConstraint(Pixel_ModuleID,
202 dparams,
203 deltachisq,
204 DOCA_Vector,
205 DOCA_Matrix));
206 ATH_MSG_DEBUG( "Pixel Barrel ModuleID = " << Pixel_ModuleID);
207 ATH_MSG_DEBUG( "alignment parameters = (" << dparams[0] << "," << dparams[1] << "," << dparams[2] << "," << dparams[3] << "," << dparams[4] << "," << dparams[5] << ")");
208 ATH_MSG_DEBUG( "chi^2 = " << deltachisq);
209 ATH_MSG_DEBUG( "DOCA_Vector = (" << DOCA_Vector[0] << "," << DOCA_Vector[1] << "," << DOCA_Vector[2] << "," << DOCA_Vector[3] << "," << DOCA_Vector[4] << "," << DOCA_Vector[5] << ")");
210 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,0) << "," << DOCA_Matrix(2,0) << "," << DOCA_Matrix(3,0) << "," << DOCA_Matrix(4,0) << "," << DOCA_Matrix(5,0) << ")");
211 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,1) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,1) << "," << DOCA_Matrix(3,1) << "," << DOCA_Matrix(4,1) << "," << DOCA_Matrix(5,1) << ")");
212 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,2) << "," << DOCA_Matrix(3,2) << "," << DOCA_Matrix(4,4) << "," << DOCA_Matrix(5,5) << ")");
213 break;
214 }
215 }
216
217 // SCT EC
218
219 for (SCT_ID::const_id_iterator wafer_it=m_sctid->wafer_begin(); wafer_it!=m_sctid->wafer_end(); ++wafer_it) {
220 const Identifier SCT_ModuleID = *wafer_it;
221 if(std::abs(m_sctid->barrel_ec(SCT_ModuleID)) == 2){
222 ATH_CHECK(m_SurvConstr -> computeConstraint(SCT_ModuleID,
223 dparams,
224 deltachisq,
225 DOCA_Vector,
226 DOCA_Matrix));
227 ATH_MSG_DEBUG( "SCT_ModuleID = " << SCT_ModuleID);
228 ATH_MSG_DEBUG( "alignment parameters = (" << dparams[0] << "," << dparams[1] << "," << dparams[2] << "," << dparams[3] << "," << dparams[4] << "," << dparams[5] << ")");
229 ATH_MSG_DEBUG( "chi^2 = " << deltachisq);
230 ATH_MSG_DEBUG( "DOCA_Vector = (" << DOCA_Vector[0] << "," << DOCA_Vector[1] << "," << DOCA_Vector[2] << "," << DOCA_Vector[3] << "," << DOCA_Vector[4] << "," << DOCA_Vector[5] << ")");
231 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,0) << "," << DOCA_Matrix(2,0) << "," << DOCA_Matrix(3,0) << "," << DOCA_Matrix(4,0) << "," << DOCA_Matrix(5,0) << ")");
232 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,1) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,1) << "," << DOCA_Matrix(3,1) << "," << DOCA_Matrix(4,1) << "," << DOCA_Matrix(5,1) << ")");
233 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,2) << "," << DOCA_Matrix(3,2) << "," << DOCA_Matrix(4,4) << "," << DOCA_Matrix(5,5) << ")");
234 break;
235 }
236 }
237
238
239 // SCT B
240 for (SCT_ID::const_id_iterator wafer_it=m_sctid->wafer_begin(); wafer_it!=m_sctid->wafer_end(); ++wafer_it) {
241 const Identifier SCT_ModuleID = *wafer_it;
242 if(m_sctid->barrel_ec(SCT_ModuleID) == 0){
243 ATH_CHECK(m_SurvConstr -> computeConstraint(SCT_ModuleID,
244 dparams,
245 deltachisq,
246 DOCA_Vector,
247 DOCA_Matrix));
248 ATH_MSG_DEBUG( "SCT Barrel ModuleID = " << SCT_ModuleID);
249 ATH_MSG_DEBUG( "alignment parameters = (" << dparams[0] << "," << dparams[1] << "," << dparams[2] << "," << dparams[3] << "," << dparams[4] << "," << dparams[5] << ")");
250 ATH_MSG_DEBUG( "chi^2 = " << deltachisq);
251 ATH_MSG_DEBUG( "DOCA_Vector = (" << DOCA_Vector[0] << "," << DOCA_Vector[1] << "," << DOCA_Vector[2] << "," << DOCA_Vector[3] << "," << DOCA_Vector[4] << "," << DOCA_Vector[5] << ")");
252 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,0) << "," << DOCA_Matrix(2,0) << "," << DOCA_Matrix(3,0) << "," << DOCA_Matrix(4,0) << "," << DOCA_Matrix(5,0) << ")");
253 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,1) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,1) << "," << DOCA_Matrix(3,1) << "," << DOCA_Matrix(4,1) << "," << DOCA_Matrix(5,1) << ")");
254 ATH_MSG_DEBUG( "DOCA_Matrix = (" <<DOCA_Matrix(0,0) << "," << DOCA_Matrix(1,1) << "," << DOCA_Matrix(2,2) << "," << DOCA_Matrix(3,2) << "," << DOCA_Matrix(4,4) << "," << DOCA_Matrix(5,5) << ")");
255 break;
256 }
257 }
258
259 return StatusCode::SUCCESS;
260 }
261
262// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
263
265
266 // Part 1: Get the messaging service, print where you are
267 ATH_MSG_INFO( "finalize()" );
268
269 ATH_MSG_INFO( "mm = " << CLHEP::mm
270 << ", mrad = " << CLHEP::mrad
271 << ", micrometer = " << CLHEP::micrometer
272 << ", deg = " << CLHEP::deg);
273
274 return StatusCode::SUCCESS;
275}
276
278 ServiceHandle<ITHistSvc> histSvc ("THistSvc", "SurveyConstraintTestAlg");
279 ATH_CHECK( histSvc.retrieve() );
280
281 auto book = [&] (TH1*& h,
282 const char* name,
283 const char* title,
284 int nbins,
285 float xlo,
286 float xhi)
287 {
288 h = new TH1F (name, title, nbins, xlo, xhi);
289 const static std::string prefix = "/stat/MisAlign/";
290 return histSvc->regHist (prefix + name, h);
291 };
292
293 ATH_CHECK( book (m_h_PixEC_Align_Disk[0], "Misalignment Disk X [mu]", "Misalignment Disk X [mu]",100, -50.,50.) );
294 ATH_CHECK( book (m_h_PixEC_Align_Disk[1], "Misalignment Disk Y [mu]", "Misalignment Disk Y [mu]",100, -100.,100.) );
295 ATH_CHECK( book (m_h_PixEC_Align_Disk[2], "Misalignment Disk Z [mu]", "Misalignment Disk Z [mu]",100, -200.,200.) );
296 ATH_CHECK( book (m_h_PixEC_Align_Disk[3], "Misalignment Disk PhiX [mrad]", "Misalignment Disk PhiX [mrad]",100, -2.,2.) );
297 ATH_CHECK( book (m_h_PixEC_Align_Disk[4], "Misalignment Disk PhiY [mrad]", "Misalignment Disk PhiY [mrad]",100, -5.,5.) );
298 ATH_CHECK( book (m_h_PixEC_Align_Disk[5], "Misalignment Disk PhiZ [mrad]", "Misalignment Disk PhiZ [mrad]",100, -2.,2.) );
299
300 ATH_CHECK( book (m_h_PixEC_Align_first[0], "Misalignment first X [mu]", "Misalignment first X [mu]",100, -50.,50.) );
301 ATH_CHECK( book (m_h_PixEC_Align_first[1], "Misalignment first Y [mu]", "Misalignment first Y [mu]",100, -100.,100.) );
302 ATH_CHECK( book (m_h_PixEC_Align_first[2], "Misalignment first Z [mu]", "Misalignment first Z [mu]",100, -200.,200.) );
303 ATH_CHECK( book (m_h_PixEC_Align_first[3], "Misalignment first PhiX [mrad]", "Misalignment first PhiX [mrad]",100, -2.,2.) );
304 ATH_CHECK( book (m_h_PixEC_Align_first[4], "Misalignment first PhiY [mrad]", "Misalignment first PhiY [mrad]",100, -5.,5.) );
305 ATH_CHECK( book (m_h_PixEC_Align_first[5], "Misalignment first PhiZ [mrad]", "Misalignment first PhiZ [mrad]",100, -2.,2.) );
306
307 ATH_CHECK( book (m_h_PixEC_Align[0], "Misalignment X [mu]", "Misalignment X [mu]",100, -50.,50.) );
308 ATH_CHECK( book (m_h_PixEC_Align[1], "Misalignment Y [mu]", "Misalignment Y [mu]",100, -100.,100.) );
309 ATH_CHECK( book (m_h_PixEC_Align[2], "Misalignment Z [mu]", "Misalignment Z [mu]",100, -200.,200.) );
310 ATH_CHECK( book (m_h_PixEC_Align[3], "Misalignment PhiX [mrad]", "Misalignment PhiX [mrad]",100, -2.,2.) );
311 ATH_CHECK( book (m_h_PixEC_Align[4], "Misalignment PhiY [mrad]", "Misalignment PhiY [mrad]",100, -5.,5.) );
312 ATH_CHECK( book (m_h_PixEC_Align[5], "Misalignment PhiZ [mrad]", "Misalignment PhiZ [mrad]",100, -2.,2.) );
313
314 return StatusCode::SUCCESS;
315}
316 //__________________________________________________________________________
318
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
INTupleSvc * ntupleSvc()
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Header file for AthHistogramAlgorithm.
std::vector< Identifier >::const_iterator const_id_iterator
Definition PixelID.h:72
std::vector< Identifier >::const_iterator const_id_iterator
Definition SCT_ID.h:73
Amg::VectorX DOCA_Vector() const
NTuple::Item< long > m_AlignResults_Identifier_SCT
virtual StatusCode finalize() override
NTuple::Item< double > m_AlignResults_gamma
NTuple::Item< long > m_AlignResults_Identifier_ID
NTuple::Item< double > m_AlignResults_alpha
NTuple::Item< long > m_AlignResults_Identifier_LayerDisc
virtual StatusCode execute() override
NTuple::Item< long > m_AlignResults_Identifier_Eta
NTuple::Item< long > m_AlignResults_Identifier_BarrelEC
NTuple::Item< double > m_AlignResults_y
NTuple::Item< double > m_AlignResults_z
NTuple::Item< double > m_AlignResults_beta
NTuple::Item< long > m_AlignResults_Identifier_Phi
virtual StatusCode initialize() override
SurveyConstraintTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
NTuple::Item< double > m_AlignResults_x
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.