ATLAS Offline Software
Loading...
Searching...
No Matches
PixelPrepDataToxAOD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PixelPrepDataToxAOD.cxx
7// Implementation file for class PixelPrepDataToxAOD
9
10#include "PixelPrepDataToxAOD.h"
11
13
17
18#include "Identifier/Identifier.h"
21#include "PixelConditionsData/ChargeCalibParameters.h" //for LegacyFitParameters
22
23
28#include "InDetSimEvent/SiHit.h"
31
32#include "CLHEP/Geometry/Point3D.h"
33
34#include <numbers>
35#include <map>
36
37#define AUXDATA(OBJ, TYP, NAME) \
38 static const SG::AuxElement::Accessor<TYP> acc_##NAME (#NAME); acc_##NAME(*(OBJ))
39
40namespace {
41 unsigned int makeKey(short phi, char eta, char layer) {
42 return phi | (eta << 16) | (layer << 24);
43 }
44 using std::numbers::pi;
45}
46
48//
49// Constructor with parameters:
50//
52PixelPrepDataToxAOD::PixelPrepDataToxAOD(const std::string &name, ISvcLocator *pSvcLocator) :
53 AthAlgorithm(name,pSvcLocator),
54 m_PixelHelper(nullptr),
57 m_need_sihits{false}
58{
59 // --- Steering and configuration flags
60
61 declareProperty("UseTruthInfo", m_useTruthInfo=false);
62 declareProperty("UseSiHitsGeometryMatching", m_useSiHitsGeometryMatching=true);
63 declareProperty("WriteSDOs", m_writeSDOs = false);
64 declareProperty("WriteSiHits", m_writeSiHits = false);
65 declareProperty("WriteNNinformation", m_writeNNinformation = true);
66 declareProperty("WriteRDOinformation", m_writeRDOinformation = true);
67 declareProperty("WriteExtendedPRDinformation", m_writeExtendedPRDinformation = false);
68
69 // --- Configuration keys
70 declareProperty("SiClusterContainer", m_clustercontainer_key = "PixelClusters");
71 declareProperty("MC_SDOs", m_SDOcontainer_key = "PixelSDO_Map");
72 declareProperty("MC_Hits", m_sihitContainer_key = "PixelHits");
73 declareProperty("PRD_MultiTruth", m_multiTruth_key = "PRD_MultiTruthPixel");
74
75}
76
78//
79// Initialize method:
80//
83{
84 ATH_CHECK( detStore()->retrieve(m_PixelHelper, "PixelID") );
85
86 //make sure we don't write what we don't have
87 if (not m_useTruthInfo) {
88 m_writeSDOs = false;
89 m_writeSiHits = false;
90 }
91
92 ATH_CHECK(m_pixelReadout.retrieve());
94
95 ATH_CHECK(m_condDCSStateKey.initialize());
96 ATH_CHECK(m_condDCSStatusKey.initialize());
97 ATH_CHECK(m_readKeyTemp.initialize());
98 ATH_CHECK(m_readKeyHV.initialize());
99
100 ATH_CHECK(m_pixelSummary.retrieve(DisableTool{!m_writeRDOinformation} ));
101
102 ATH_CHECK(m_lorentzAngleTool.retrieve());
103
104 ATH_CHECK(m_clustercontainer_key.initialize());
110
111 ATH_CHECK(m_write_xaod_key.initialize());
112 ATH_CHECK(m_write_offsets.initialize());
113
115
116 return StatusCode::SUCCESS;
117}
118
120//
121// Execute method:
122//
124StatusCode PixelPrepDataToxAOD::execute(const EventContext& ctx)
125{
126 //Mandatory. Require if the algorithm is scheduled.
128
129 if ( !PixelClusterContainer.isValid() )
130 {
131 ATH_MSG_ERROR("Failed to retrieve PixelClusterContainer with key" << PixelClusterContainer.key() );
132 return StatusCode::FAILURE;
133 }
134
135 const PRD_MultiTruthCollection* prdmtColl(nullptr);
136 const xAODTruthParticleLinkVector *truth_particle_links{nullptr};
137 if (m_useTruthInfo) {
139 if (prdmtCollHandle.isValid()) {
140 prdmtColl = &*prdmtCollHandle;
141 }
142 if (!m_truthParticleLinks.empty()) {
144 if (truthParticleLinksHandle.isValid()) {
145 truth_particle_links = truthParticleLinksHandle.cptr();
146 }
147 }
148 }
149
150 const InDetSimDataCollection* sdoCollection(nullptr);
151 if (m_writeSDOs) {
153 if (sdoCollectionHandle.isValid()) {
154 sdoCollection = &*sdoCollectionHandle;
155 } else if (m_firstEventWarnings) {
156 ATH_MSG_WARNING("SDO information requested, but SDO collection not available!");
157 }
158 }
159
161 bool foundSplitProbContainer = false;
162 if (!m_clusterSplitProbContainer.key().empty()) {
164 if (!splitProbContainer.isValid()) {
165 ATH_MSG_FATAL("Failed to get cluster splitting probability container " << m_clusterSplitProbContainer);
166 }
167 foundSplitProbContainer = true;
168 }
169
170 std::vector<std::vector<const SiHit*>> siHits(m_PixelHelper->wafer_hash_max());
171 if (m_need_sihits) {
172 SG::ReadHandle<SiHitCollection> siHitCollectionHandle(m_sihitContainer_key, ctx);
173 if (siHitCollectionHandle.isValid()) {
174 for (const SiHit& siHit: *siHitCollectionHandle) {
175 // Check if it is a Pixel hit
176 if (!siHit.isPixel()) continue;
177
178 Identifier wafer_id(m_PixelHelper->wafer_id(siHit.getBarrelEndcap(),
179 siHit.getLayerDisk(),
180 siHit.getPhiModule(),
181 siHit.getEtaModule()));
182 IdentifierHash wafer_hash(m_PixelHelper->wafer_hash(wafer_id));
183 if (wafer_hash>=m_PixelHelper->wafer_hash_max()) continue;
184 siHits[wafer_hash].push_back(&siHit);
185 }
186 } else if (m_firstEventWarnings) {
187 ATH_MSG_WARNING("SiHit information requested, but SiHit collection not available!");
188 }
189 }
190
191 const PixelChargeCalibCondData *calibData=nullptr;
194 if (!calibData_handle.isValid()) {
195 ATH_MSG_FATAL("Failed to get PixelChargeCalibCondData with key " << m_chargeDataKey);
196 }
197 calibData=calibData_handle.cptr();
198 }
199
200 // Create the xAOD container and its auxiliary store:
202 ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
203 std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
204
206 ATH_CHECK(offsets.record(std::make_unique<std::vector<unsigned int>>(m_PixelHelper->wafer_hash_max(), 0)));
207
208 unsigned int have_truth_link=0u;
209 unsigned int missing_truth_particle=0u;
210 unsigned int missing_parent_particle=0u;
211 // Loop over the container
212 unsigned int counter(0);
213
217
218 std::unordered_map< unsigned int , std::vector<unsigned int> > cluster_map;
219 for( const auto clusterCollection : * PixelClusterContainer ){
220
221 //Fill Offset container
222 (*offsets)[clusterCollection->identifyHash()] = counter;
223
224 // skip empty collections
225 if( clusterCollection->empty() ) continue;
226
227 // loop over collection and convert to xAOD
228 for( const InDet::PixelCluster* prd : *clusterCollection ){
229 ++counter;
230
231 Identifier clusterId = prd->identify();
232 if ( !clusterId.is_valid() ) {
233 ATH_MSG_WARNING("Pixel cluster identifier is not valid");
234 }
235
236 // create and add xAOD object
238 unsigned int cluster_idx = xaod->size();
239 xaod->push_back(xprd);
240
241 //Set Identifier
242 xprd->setIdentifier( clusterId.get_compact() );
243
244 //Set Global Position
245 Amg::Vector3D gpos = prd->globalPosition();
246 xprd->setGlobalPosition(gpos.x(),gpos.y(),gpos.z());
247
248 //Set Local Position
249 const Amg::Vector2D& locpos = prd->localPosition();
250
251 // Set local error matrix
252 xprd->setLocalPosition( locpos.x(), locpos.y() );
253
254 const Amg::MatrixX& localCov = prd->localCovariance();
255 if(localCov.size() == 1){
256 xprd->setLocalPositionError( localCov(0,0), 0., 0. );
257 } else if(localCov.size() == 4){
258 xprd->setLocalPositionError( localCov(0,0), localCov(1,1), localCov(0,1) );
259 } else {
260 xprd->setLocalPositionError(0.,0.,0.);
261 }
262
263 // Set vector of hit identifiers
264 std::vector< uint64_t > rdoIdentifierList;
265 rdoIdentifierList.reserve(prd->rdoList().size());
266 int rowmin=9999; int rowmax=-9999;
267 int colmin=9999; int colmax=-9999;
268 for( const auto &hitIdentifier : prd->rdoList() ){
269 rdoIdentifierList.push_back( hitIdentifier.get_compact() );
270 //May want to addinformation about the individual hits here
271 int row = m_PixelHelper->phi_index(hitIdentifier);
272 int col = m_PixelHelper->eta_index(hitIdentifier);
273 if(rowmin > row) rowmin = row;
274 if(rowmax < row) rowmax = row;
275 if(colmin > col) colmin = col;
276 if(colmax < col) colmax = col;
277 }
278 xprd->setRdoIdentifierList(rdoIdentifierList);
279
280 //Add pixel cluster properties
281 AUXDATA(xprd,int,bec) = m_PixelHelper->barrel_ec(clusterId) ;
282 char the_layer = m_PixelHelper->layer_disk(clusterId) ;
283 char the_eta = m_PixelHelper->eta_module(clusterId) ;
284 short the_phi = m_PixelHelper->phi_module(clusterId) ;
285 AUXDATA(xprd,int,layer) = the_layer ;
286 AUXDATA(xprd,int,phi_module) = the_phi ;
287 AUXDATA(xprd,int,eta_module) = the_eta ;
288 AUXDATA(xprd,int,eta_pixel_index) = m_PixelHelper->eta_index(clusterId);
289 AUXDATA(xprd,int,phi_pixel_index) = m_PixelHelper->phi_index(clusterId);
290
291 cluster_map[ makeKey(the_phi, the_eta, the_layer)].push_back(cluster_idx);
292
293 const InDet::SiWidth cw = prd->width();
294 AUXDATA(xprd,int,sizePhi) = (int)cw.colRow()[0];
295 AUXDATA(xprd,int,sizeZ) = (int)cw.colRow()[1];
296 AUXDATA(xprd,int,nRDO) = (int)prd->rdoList().size();
297
298 AUXDATA(xprd,float,charge) = prd->totalCharge();
299 AUXDATA(xprd,int,ToT) = prd->totalToT();
300 AUXDATA(xprd,int,LVL1A) = prd->LVL1A();
301
302 AUXDATA(xprd,char,isFake) = (char)prd->isFake();
303 AUXDATA(xprd,char,gangedPixel) = (char)prd->gangedPixel();
305 splitProb = foundSplitProbContainer ? splitProbContainer->splitProbability(prd) : Trk::ClusterSplitProbabilityContainer::getNoSplitProbability();
306 AUXDATA(xprd,char,isSplit) = static_cast<char>(splitProb.isSplit());
307 AUXDATA(xprd,float,splitProbability1) = splitProb.splitProbability1();
308 AUXDATA(xprd,float,splitProbability2) = splitProb.splitProbability2();
309
310 // Need to add something to Add the NN splitting information
311 if(m_writeNNinformation) addNNInformation( xprd, prd, 7, 7);
312
313 // Add information for each contributing hit
315 IdentifierHash moduleHash = clusterCollection->identifyHash();
316 AUXDATA(xprd,int,hasBSError) = (int)m_pixelSummary->hasBSError(moduleHash, ctx);
317 AUXDATA(xprd,int,DCSState) = dcsState->getModuleStatus(moduleHash);
318
319 float deplVoltage = 0.0;
320 AUXDATA(xprd,float,BiasVoltage) = dcsHV->getBiasVoltage(moduleHash);
321 AUXDATA(xprd,float,Temperature) = dcsTemp->getTemperature(moduleHash);
322 AUXDATA(xprd,float,DepletionVoltage) = deplVoltage;
323
324 AUXDATA(xprd,float,LorentzShift) = (float)m_lorentzAngleTool->getLorentzShift(moduleHash,ctx);
325
326 assert (calibData);
327 addRdoInformation(xprd, prd, calibData);
328 }
329
330
331 // Add the Detector element ID -- not sure if needed as we have the informations above
332 const InDetDD::SiDetectorElement* de = prd->detectorElement();
333 uint64_t detElementId(0);
334 if(de){
335 Identifier detId = de->identify();
336 if ( detId.is_valid() ) {
337 detElementId = detId.get_compact();
338 }
339 }
340 AUXDATA(xprd,uint64_t,detectorElementID) = detElementId;
341
343 AUXDATA(xprd,int,waferID) = m_PixelHelper->wafer_hash(de->identify());
344
345 const InDetDD::PixelModuleDesign* design = static_cast<const InDetDD::PixelModuleDesign*>(&de->design());
346 InDetDD::SiLocalPosition pos1 = design->positionFromColumnRow(colmin,rowmin);
347 InDetDD::SiLocalPosition pos2 = design->positionFromColumnRow(colmax,rowmin);
348 InDetDD::SiLocalPosition pos3 = design->positionFromColumnRow(colmin,rowmax);
349 InDetDD::SiLocalPosition pos4 = design->positionFromColumnRow(colmax,rowmax);
350 InDetDD::SiLocalPosition centroid = 0.25*(pos1+pos2+pos3+pos4);
351
352 AUXDATA(xprd,float,centroid_xphi) = centroid.xPhi();
353 AUXDATA(xprd,float,centroid_xeta) = centroid.xEta();
354
355 AUXDATA(xprd,float,omegax) = prd->omegax();
356 AUXDATA(xprd,float,omegay) = prd->omegay();
357 }
358
359 // Use the MultiTruth Collection to get a list of all true particle contributing to the cluster
360 if (prdmtColl) {
361 auto range{prdmtColl->equal_range(clusterId)};
362 if (truth_particle_links) {
363 std::vector<unsigned int> tp_indices;
364 for (auto i{range.first}; i!=range.second; ++i) {
365 ElementLink<xAOD::TruthParticleContainer> a_truth_particle_link = truth_particle_links->find(i->second);
366 if (a_truth_particle_link) {
367 const xAOD::TruthParticle *truth_particle = *a_truth_particle_link;
368 if (truth_particle) {
369 ++have_truth_link;
370 tp_indices.push_back(static_cast<int>(truth_particle->index()));
371 }
372 else {
373 ++missing_parent_particle;
374 }
375 }
376 else {
377 tp_indices.push_back(std::numeric_limits<unsigned int>::max());
378 ++missing_truth_particle;
379 }
380 }
381 // @TODO provide possibility to move tp_indices to its final destination
382 AUXDATA(xprd,std::vector<unsigned int>, truth_index) = std::move(tp_indices);
383 }
384 std::vector<int> uniqueIDs;
385 for (auto i = range.first; i != range.second; ++i) {
386 uniqueIDs.push_back( HepMC::uniqueID(i->second) );
387 }
388 AUXDATA(xprd,std::vector<int>, truth_barcode) = std::move(uniqueIDs); // TODO rename variable to be consistent?
389 }
390
391 std::vector< std::vector< int > > sdo_tracks;
392 // Use the SDO Collection to get a list of all true particle contributing to the cluster per readout element
393 // Also get the energy deposited by each true particle per readout element
394 if (sdoCollection) {
395 sdo_tracks = addSDOInformation(xprd, prd, *sdoCollection);
396 }
397
398 // Now Get the most detailed truth from the SiHits
399 // Note that this could get really slow if there are a lot of hits and clusters
400 if (m_need_sihits) {
401 const std::vector<SiHit> matched_hits = findAllHitsCompatibleWithCluster(prd, &siHits[prd->detectorElement()->identifyHash()], sdo_tracks);
402 if (m_writeSiHits) {
403 addSiHitInformation(xprd, prd, matched_hits);
404 }
405
407 addNNTruthInfo(xprd, prd, matched_hits);
408 }
409 }
410 }
411 }
412
413 for ( auto clusItr = xaod->begin(); clusItr != xaod->end(); ++clusItr ) {
414 AUXDATA(*clusItr,char,broken) = false;
415 }
416 m_haveTruthLink += have_truth_link;
417 m_missingTruthParticle += missing_truth_particle;
418 m_missingParentParticle += missing_parent_particle;
419
420 static const SG::AuxElement::Accessor<int> acc_layer ("layer");
421 static const SG::AuxElement::Accessor<int> acc_phi_module ("phi_module");
422 static const SG::AuxElement::Accessor<int> acc_eta_module ("eta_module");
423 static const SG::AuxElement::Accessor<std::vector<int> > acc_sihit_barcode ("sihit_barcode"); // TODO rename variable to be consistent?
424 for ( auto clusItr = xaod->begin(); clusItr != xaod->end(); ++clusItr)
425 {
426 auto pixelCluster = *clusItr;
427 int layer = acc_layer(*pixelCluster);
428 std::vector<int> uniqueIDs = acc_sihit_barcode(*pixelCluster); // TODO rename variable to be consistent?
429
430 const std::vector< unsigned int> &cluster_idx_list = cluster_map.at( makeKey(acc_phi_module(*pixelCluster), acc_eta_module(*pixelCluster), acc_layer(*pixelCluster) ));
431 for (unsigned int cluster_idx : cluster_idx_list) {
432 auto pixelCluster2 = xaod->at(cluster_idx);
433 if ( acc_layer(*pixelCluster2) != layer )
434 continue;
435 if ( acc_eta_module(*pixelCluster) != acc_eta_module(*pixelCluster2) )
436 continue;
437 if ( acc_phi_module(*pixelCluster) != acc_phi_module(*pixelCluster2) )
438 continue;
439
440 std::vector<int> uniqueIDs2 = acc_sihit_barcode(*pixelCluster2); // TODO rename variable to be consistent?
441
442 for ( auto uid : uniqueIDs ) {
443 if (std::find(uniqueIDs2.begin(), uniqueIDs2.end(), uid ) == uniqueIDs2.end()) continue;
444 static const SG::AuxElement::Accessor<char> acc_broken ("broken");
445 acc_broken(*pixelCluster) = true;
446 acc_broken(*pixelCluster2) = true;
447 break;
448 }
449 }
450 }
451
452 ATH_MSG_DEBUG( " recorded PixelPrepData objects: size " << xaod->size() );
453
454 m_firstEventWarnings = false;
455
456 return StatusCode::SUCCESS;
457}
458
459
461 const InDet::PixelCluster* prd,
462 const InDetSimDataCollection& sdoCollection ) const
463{
464 std::vector<int> sdo_word;
465 std::vector< std::vector< int > > sdo_depositsUniqueID;
466 std::vector< std::vector< float > > sdo_depositsEnergy;
467 // find hit
468 for( const auto &hitIdentifier : prd->rdoList() ){
469 auto pos = sdoCollection.find(hitIdentifier);
470 if( pos == sdoCollection.end() ) continue;
471 sdo_word.push_back( pos->second.word() ) ;
472 std::vector<int> sdoDepUID(pos->second.getdeposits().size(), HepMC::INVALID_PARTICLE_ID);
473 std::vector<float> sdoDepEnergy(pos->second.getdeposits().size());
474 unsigned int nDepos{0};
475 for (auto& deposit: pos->second.getdeposits()) {
476 if (deposit.first) sdoDepUID[nDepos] = HepMC::uniqueID(deposit.first);
477 ATH_MSG_DEBUG(" SDO Energy Deposit " << deposit.second ) ;
478 sdoDepEnergy[nDepos] = deposit.second;
479 nDepos++;
480 }
481 sdo_depositsUniqueID.push_back( std::move(sdoDepUID) );
482 sdo_depositsEnergy.push_back( std::move(sdoDepEnergy) );
483 }
484 AUXDATA(xprd,std::vector<int>,sdo_words) = std::move(sdo_word);
485 AUXDATA(xprd,std::vector< std::vector<int> >,sdo_depositsBarcode) = sdo_depositsUniqueID; // TODO rename variable to be consistent?
486 AUXDATA(xprd,std::vector< std::vector<float> >,sdo_depositsEnergy) = std::move(sdo_depositsEnergy);
487
488 return sdo_depositsUniqueID;
489}
490
491
492
494 const InDet::PixelCluster* prd,
495 const std::vector<SiHit> & matchingHits ) const
496{
497
498 int numHits = matchingHits.size();
499
500 std::vector<float> sihit_energyDeposit(numHits,0);
501 std::vector<float> sihit_meanTime(numHits,0);
502 std::vector<int> sihit_uniqueID(numHits,HepMC::UNDEFINED_ID);
503 std::vector<int> sihit_pdgid(numHits,0);
504
505 std::vector<float> sihit_startPosX(numHits,0);
506 std::vector<float> sihit_startPosY(numHits,0);
507 std::vector<float> sihit_startPosZ(numHits,0);
508
509 std::vector<float> sihit_endPosX(numHits,0);
510 std::vector<float> sihit_endPosY(numHits,0);
511 std::vector<float> sihit_endPosZ(numHits,0);
512
513 int hitNumber(0);
515 if(de){
516 for ( const auto& sihit : matchingHits ) {
517 sihit_energyDeposit[hitNumber] = sihit.energyLoss() ;
518 sihit_meanTime[hitNumber] = sihit.meanTime() ;
519 const HepMcParticleLink& HMPL = sihit.particleLink();
520 sihit_uniqueID[hitNumber] = HepMC::uniqueID(HMPL) ;
521 if(HMPL.isValid()){
522 sihit_pdgid[hitNumber] = HMPL->pdg_id();
523 }
524
525 // Convert Simulation frame into reco frame
526 const HepGeom::Point3D<double>& startPos=sihit.localStartPosition();
527
528 Amg::Vector2D pos= de->hitLocalToLocal( startPos.z(), startPos.y() );
529 sihit_startPosX[hitNumber] = pos[0];
530 sihit_startPosY[hitNumber] = pos[1];
531 sihit_startPosZ[hitNumber] = startPos.x();
532
533
534 const HepGeom::Point3D<double>& endPos=sihit.localEndPosition();
535 pos= de->hitLocalToLocal( endPos.z(), endPos.y() );
536 sihit_endPosX[hitNumber] = pos[0];
537 sihit_endPosY[hitNumber] = pos[1];
538 sihit_endPosZ[hitNumber] = endPos.x();
539 ++hitNumber;
540 }
541 }
542
543 AUXDATA(xprd,std::vector<float>,sihit_energyDeposit) = std::move(sihit_energyDeposit);
544 AUXDATA(xprd,std::vector<float>,sihit_meanTime) = std::move(sihit_meanTime);
545 AUXDATA(xprd,std::vector<int>,sihit_barcode) = std::move(sihit_uniqueID); // TODO rename variable to be consistent?
546 AUXDATA(xprd,std::vector<int>,sihit_pdgid) = std::move(sihit_pdgid);
547
548 AUXDATA(xprd,std::vector<float>,sihit_startPosX) = std::move(sihit_startPosX);
549 AUXDATA(xprd,std::vector<float>,sihit_startPosY) = std::move(sihit_startPosY);
550 AUXDATA(xprd,std::vector<float>,sihit_startPosZ) = std::move(sihit_startPosZ);
551
552 AUXDATA(xprd,std::vector<float>,sihit_endPosX) = std::move(sihit_endPosX);
553 AUXDATA(xprd,std::vector<float>,sihit_endPosY) = std::move(sihit_endPosY);
554 AUXDATA(xprd,std::vector<float>,sihit_endPosZ) = std::move(sihit_endPosZ);
555
556
557}
558
559
560
561
562
563
565 const std::vector<const SiHit*>* sihits,
566 std::vector< std::vector< int > > & trkUIDs ) const
567{
568 ATH_MSG_VERBOSE( "Got " << sihits->size() << " SiHits to look through" );
569 std::vector<SiHit> matchingHits;
570
571 // Check if we have detector element -- needed to find the local position of the SiHits
573 if(!de)
574 return matchingHits;
575
576 std::vector<const SiHit* > multiMatchingHits;
577
578 for ( const SiHit* siHit : *sihits) {
579 // Now we have all hits in the module that match lets check to see if they match the cluster
580 // Must be within +/- 1 hits of any hit in the cluster to be included
581
583 {
584 HepGeom::Point3D<double> averagePosition = siHit->localStartPosition() + siHit->localEndPosition();
585 averagePosition *= 0.5;
586 Amg::Vector2D pos = de->hitLocalToLocal( averagePosition.z(), averagePosition.y() );
587 InDetDD::SiCellId diode = de->cellIdOfPosition(pos);
588
589 for( const auto &hitIdentifier : prd->rdoList() ){
590 ATH_MSG_DEBUG("Truth Phi " << diode.phiIndex() << " Cluster Phi " << m_PixelHelper->phi_index( hitIdentifier ) );
591 ATH_MSG_DEBUG("Truth Eta " << diode.etaIndex() << " Cluster Eta " << m_PixelHelper->eta_index( hitIdentifier ) );
592 if( abs( int(diode.etaIndex()) - m_PixelHelper->eta_index( hitIdentifier ) ) <=1
593 && abs( int(diode.phiIndex()) - m_PixelHelper->phi_index( hitIdentifier ) ) <=1 )
594 {
595 multiMatchingHits.push_back(siHit);
596 break;
597 }
598 }
599 }
600 else
601 {
602 auto uid = HepMC::uniqueID(siHit->particleLink());
603 for ( const auto& uniqueIDSDOColl : trkUIDs ) {
604 if (std::find(uniqueIDSDOColl.begin(),uniqueIDSDOColl.end(),uid) == uniqueIDSDOColl.end() ) continue;
605 multiMatchingHits.push_back(siHit);
606 break;
607 }
608 }
609 }
610 //Now we will now make 1 SiHit for each true particle if the SiHits "touch" other
611 std::vector<const SiHit* >::iterator siHitIter = multiMatchingHits.begin();
612 std::vector<const SiHit* >::iterator siHitIter2 = multiMatchingHits.begin();
613 ATH_MSG_DEBUG( "Found " << multiMatchingHits.size() << " SiHit " );
614 for ( ; siHitIter != multiMatchingHits.end(); ++siHitIter) {
615 const SiHit* lowestXPos = *siHitIter;
616 const SiHit* highestXPos = *siHitIter;
617
618
619 // We will merge these hits
620 std::vector<const SiHit* > ajoiningHits;
621 ajoiningHits.push_back( *siHitIter );
622
623 siHitIter2 = siHitIter+1;
624 while ( siHitIter2 != multiMatchingHits.end() ) {
625 // Need to come from the same truth particle
626
627 if( !HepMC::is_same_particle((*siHitIter)->particleLink(),(*siHitIter2)->particleLink()) ){
628 ++siHitIter2;
629 continue;
630 }
631
632 // Check to see if the SiHits are compatible with each other.
633 if (std::abs((highestXPos->localEndPosition().x()-(*siHitIter2)->localStartPosition().x()))<0.00005 &&
634 std::abs((highestXPos->localEndPosition().y()-(*siHitIter2)->localStartPosition().y()))<0.00005 &&
635 std::abs((highestXPos->localEndPosition().z()-(*siHitIter2)->localStartPosition().z()))<0.00005 )
636 {
637 highestXPos = *siHitIter2;
638 ajoiningHits.push_back( *siHitIter2 );
639 // Dont use hit more than once
640 // @TODO could invalidate siHitIter
641 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
642 }else if (std::abs((lowestXPos->localStartPosition().x()-(*siHitIter2)->localEndPosition().x()))<0.00005 &&
643 std::abs((lowestXPos->localStartPosition().y()-(*siHitIter2)->localEndPosition().y()))<0.00005 &&
644 std::abs((lowestXPos->localStartPosition().z()-(*siHitIter2)->localEndPosition().z()))<0.00005)
645 {
646 lowestXPos = *siHitIter2;
647 ajoiningHits.push_back( *siHitIter2 );
648 // Dont use hit more than once
649 // @TODO could invalidate siHitIter
650 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
651 } else {
652 ++siHitIter2;
653 }
654 }
655
656 if( ajoiningHits.size() == 0){
657 ATH_MSG_WARNING("This should really never happen");
658 continue;
659 }else if(ajoiningHits.size() == 1){
660 // Copy Si Hit ready to return
661 matchingHits.push_back( *ajoiningHits[0] );
662 continue;
663 } else {
664 // Build new SiHit and merge information together.
665 ATH_MSG_DEBUG("Merging " << ajoiningHits.size() << " SiHits together." );
666
667
668 float energyDep(0);
669 float time(0);
670 for( const auto& siHit : ajoiningHits){
671 energyDep += siHit->energyLoss();
672 time += siHit->meanTime();
673 }
674 time /= (float)ajoiningHits.size();
675
676 matchingHits.emplace_back(lowestXPos->localStartPosition(),
677 highestXPos->localEndPosition(),
678 energyDep,
679 time,
680 (*siHitIter)->particleLink(),
681 0, // 0 for pixel 1 for Pixel
682 (*siHitIter)->getBarrelEndcap(),
683 (*siHitIter)->getLayerDisk(),
684 (*siHitIter)->getEtaModule(),
685 (*siHitIter)->getPhiModule(),
686 (*siHitIter)->getSide() );
687 ATH_MSG_DEBUG("Finished Merging " << ajoiningHits.size() << " SiHits together." );
688
689 }
690 }
691
692
693 return matchingHits;
694
695}
696
698 const InDet::PixelCluster* pixelCluster,
699 const PixelChargeCalibCondData *calibData) const
700{
701 ATH_MSG_VERBOSE( " Starting creating input from cluster " );
702
703
704 const std::vector<Identifier>& rdos = pixelCluster->rdoList();
705
706 const std::vector<float> &chList = pixelCluster->chargeList();
707 const std::vector<int> &totList = pixelCluster->totList();
708
709 // std::vector<int> rowList;
710 // std::vector<int> colList;
711 std::vector<int> etaIndexList;
712 std::vector<int> phiIndexList;
713 std::vector<float> CTerm;
714 std::vector<float> ATerm;
715 std::vector<float> ETerm;
716
717 ATH_MSG_VERBOSE( "Number of RDOs: " << rdos.size() );
718
719 //Itererate over all elements hits in the cluster and fill the charge and tot matricies
720 std::vector<Identifier>::const_iterator rdosBegin = rdos.begin();
721 std::vector<Identifier>::const_iterator rdosEnd = rdos.end();
722
723 ATH_MSG_VERBOSE(" Putting together the n. " << rdos.size() << " rdos into a matrix.");
724
725 phiIndexList.reserve( rdos.size());
726 etaIndexList.reserve( rdos.size());
727 CTerm.reserve( rdos.size());
728 ATerm.reserve( rdos.size());
729 ETerm.reserve( rdos.size());
730 for (; rdosBegin!= rdosEnd; ++rdosBegin)
731 {
732 Identifier rId = *rdosBegin;
733 phiIndexList.push_back( m_PixelHelper->phi_index(rId) );
734 etaIndexList.push_back( m_PixelHelper->eta_index(rId) );
735
736 // charge calibration parameters
737 Identifier moduleID = m_PixelHelper->wafer_id(rId);
738 IdentifierHash moduleHash = m_PixelHelper->wafer_hash(moduleID); // wafer hash
739 unsigned int FE = m_pixelReadout->getFE(rId, moduleID);
740 InDetDD::PixelDiodeType type = m_pixelReadout->getDiodeType(rId);
741 if (type == InDetDD::PixelDiodeType::NONE) continue;
742 const auto & parameters = calibData->getLegacyFitParameters(type, moduleHash, FE);
743 CTerm.emplace_back(parameters.C);
744 ATerm.emplace_back(parameters.A);
745 ETerm.emplace_back(parameters.E);
746
747 }//end iteration on rdos
748
749
750 AUXDATA(xprd, std::vector<int>,rdo_phi_pixel_index) = std::move(phiIndexList);
751 AUXDATA(xprd, std::vector<int>,rdo_eta_pixel_index) = std::move(etaIndexList);
752 AUXDATA(xprd, std::vector<float>,rdo_charge) = chList;
753 AUXDATA(xprd, std::vector<int>,rdo_tot) = totList;
754
755 AUXDATA(xprd, std::vector<float>,rdo_Cterm) = std::move(CTerm);
756 AUXDATA(xprd, std::vector<float>,rdo_Aterm) = std::move(ATerm);
757 AUXDATA(xprd, std::vector<float>,rdo_Eterm) = std::move(ETerm);
758
759}
760
761
763 const InDet::PixelCluster* pixelCluster,
764 const unsigned int sizeX, const unsigned int sizeY ) const
765{
766 ATH_MSG_VERBOSE( " Starting creating input from cluster " );
767
768 const InDetDD::SiDetectorElement* de = pixelCluster->detectorElement();
769 if (de==nullptr) {
770 ATH_MSG_ERROR("Could not get detector element");
771 return;
772 }
773
774
775 const InDetDD::PixelModuleDesign* design(dynamic_cast<const InDetDD::PixelModuleDesign*>(&de->design()));
776 if (not design) {
777 ATH_MSG_WARNING("PixelModuleDesign was not retrieved in function 'addNNInformation'");
778 return;
779 }
780 const std::vector<Identifier>& rdos = pixelCluster->rdoList();
781
782 const std::vector<float>& chList = pixelCluster->chargeList();
783 const std::vector<int>& totList = pixelCluster->totList();
784
785 ATH_MSG_VERBOSE( "Number of RDOs: " << rdos.size() );
786 ATH_MSG_VERBOSE( "Number of charges: " << chList.size() );
787 ATH_MSG_VERBOSE( "Number of TOT: " << totList.size() );
788
789
790 //Calculate the centre of the cluster
791 int phiPixelIndexMin, phiPixelIndexMax, etaPixelIndexMin, etaPixelIndexMax;
792 InDetDD::SiCellId cellIdWeightedPosition= getCellIdWeightedPosition( pixelCluster, &phiPixelIndexMin, &phiPixelIndexMax, &etaPixelIndexMin, &etaPixelIndexMax);
793
794 if (!cellIdWeightedPosition.isValid())
795 {
796 ATH_MSG_WARNING( "Weighted position is on invalid CellID." );
797 }
798
799 int etaPixelIndexWeightedPosition=cellIdWeightedPosition.etaIndex();
800 int phiPixelIndexWeightedPosition=cellIdWeightedPosition.phiIndex();
801
802
803 ATH_MSG_DEBUG(" weighted pos phiPixelIndex: " << phiPixelIndexWeightedPosition << " etaPixelIndex: " << etaPixelIndexWeightedPosition );
804
805 // SiLocalPosition PixelModuleDesign::positionFromColumnRow(const int column, const int row) const;
806 //
807 // Given row and column index of diode, returns position of diode center
808 // ALTERNATIVE/PREFERED way is to use localPositionOfCell(const SiCellId & cellId) or
809 // rawLocalPositionOfCell method in SiDetectorElement.
810 // DEPRECATED (but used in numerous places)
811 //
812 // Comment by Hide (referring the original comment in the code) : 2015-02-04
813 // I automatically replaced column to etaPixelIndex and row to phiPixelIndex here. It was bofore:
814 // InDetDD::SiLocalPosition siLocalPosition( design->positionFromColumnRow(columnWeightedPosition,rowWeightedPosition) );
815 //
816 // Then I assume the argument of column/row in this function is in offline manner, not the real hardware column/row.
817 //
818 InDetDD::SiLocalPosition w = design->positionFromColumnRow(etaPixelIndexWeightedPosition,phiPixelIndexWeightedPosition);
819
820
821 double localEtaPixelIndexWeightedPosition = w.xEta();
822 double localPhiPixelIndexWeightedPosition = w.xPhi();
823
824 int centralIndexX=(sizeX-1)/2;
825 int centralIndexY=(sizeY-1)/2;
826
827
828
829 // Check to see if the cluster is too big for the NN
830
831 if (abs(phiPixelIndexWeightedPosition-phiPixelIndexMin)>centralIndexX ||
832 abs(phiPixelIndexWeightedPosition-phiPixelIndexMax)>centralIndexX)
833 {
834 ATH_MSG_DEBUG(" Cluster too large phiPixelIndexMin " << phiPixelIndexMin << " phiPixelIndexMax " << phiPixelIndexMax << " centralX " << centralIndexX);
835 //return;
836 }
837
838 if (abs(etaPixelIndexWeightedPosition-etaPixelIndexMin)>centralIndexY ||
839 abs(etaPixelIndexWeightedPosition-etaPixelIndexMax)>centralIndexY)
840 {
841 ATH_MSG_DEBUG(" Cluster too large etaPixelIndexMin" << etaPixelIndexMin << " etaPixelIndexMax " << etaPixelIndexMax << " centralY " << centralIndexY);
842 //return;
843 }
844
845 std::vector< std::vector<float> > matrixOfToT (sizeX, std::vector<float>(sizeY,0) );
846 std::vector< std::vector<float> > matrixOfCharge(sizeX, std::vector<float>(sizeY,0));
847 // Seed with the module's nominal pitch (from the design), as in
848 // NnClusterizationFactory::createInput; correct for ITk (25x100 / 50x50 um)
849 // where the old literal 0.4 (eta) seed and the >0.1 fill guard were both wrong.
850 std::vector<float> vectorOfPitchesY(sizeY, design->etaPitch());
851 std::vector<float> vectorOfPitchesX(sizeX, design->phiPitch());
852
853
854 //Itererate over all elements hits in the cluster and fill the charge and tot matrices
855 std::vector<Identifier>::const_iterator rdosBegin = rdos.begin();
856 std::vector<Identifier>::const_iterator rdosEnd = rdos.end();
857 auto charge = chList.begin();
858 auto tot = totList.begin();
859
860 ATH_MSG_VERBOSE(" Putting together the n. " << rdos.size() << " rdos into a matrix.");
861
862 for (; rdosBegin!= rdosEnd; ++rdosBegin)
863 {
864
865 Identifier rId = *rdosBegin;
866 int absphiPixelIndex = m_PixelHelper->phi_index(rId)-phiPixelIndexWeightedPosition + centralIndexX;
867 int absetaPixelIndex = m_PixelHelper->eta_index(rId)-etaPixelIndexWeightedPosition + centralIndexY;
868 if (charge != chList.end()){
869 ATH_MSG_VERBOSE( " Phi Index: " << m_PixelHelper->phi_index(rId) << " absphiPixelIndex: " << absphiPixelIndex << " eta Idx: " << m_PixelHelper->eta_index(rId) << " absetaPixelIndex: " << absetaPixelIndex << " charge " << *charge );
870 }
871 if (absphiPixelIndex <0 || absphiPixelIndex >= (int)sizeX)
872 {
873 ATH_MSG_DEBUG(" problem with index: " << absphiPixelIndex << " min: " << 0 << " max: " << sizeX);
874 continue;
875 }
876
877 if (absetaPixelIndex <0 || absetaPixelIndex >= (int)sizeY)
878 {
879 ATH_MSG_DEBUG(" problem with index: " << absetaPixelIndex << " min: " << 0 << " max: " << sizeY);
880 continue;
881 }
882
883 InDetDD::SiCellId cellId = de->cellIdFromIdentifier(*rdosBegin);
884 InDetDD::SiDiodesParameters diodeParameters = design->parameters(cellId);
885 float pitchY = diodeParameters.width().xEta();
886 float pitchX = diodeParameters.width().xPhi();
887
888 if ( (not totList.empty()) && tot != totList.end()) {
889 matrixOfToT[absphiPixelIndex][absetaPixelIndex] =*tot;
890 ++tot;
891 } else matrixOfToT[absphiPixelIndex][absetaPixelIndex] = -1;
892
893 if ( (not chList.empty()) && charge != chList.end()){
894 matrixOfCharge[absphiPixelIndex][absetaPixelIndex]=*charge;
895 ++charge;
896 } else matrixOfCharge[absphiPixelIndex][absetaPixelIndex] = -1;
897
898 // Store the real per-cell pitch, built the same way as
899 // NnClusterizationFactory::createInput so the dumped training inputs match
900 // the runtime inference inputs.
901 vectorOfPitchesY[absetaPixelIndex]=pitchY;
902 vectorOfPitchesX[absphiPixelIndex]=pitchX;
903 }//end iteration on rdos
904
905
906 ATH_MSG_VERBOSE( " End RDO LOOP " );
907
908 // Using the centre of the module and beam spot calculate
909 // the incidence angles of the tracks
910 const Amg::Vector2D& prdLocPos = pixelCluster->localPosition();
911 InDetDD::SiLocalPosition centroid(prdLocPos);
912
913 Amg::Vector3D globalPos = de->globalPosition(centroid);
914 Amg::Vector3D trackDir = globalPos; // - beamSpotPosition;
915 trackDir.normalize();
916
917 Amg::Vector3D module_normal = de->normal();
918 Amg::Vector3D module_phiax = de->phiAxis();
919 Amg::Vector3D module_etaax = de->etaAxis();
920
921 // Calculate the phi incidence angle
922 float trkphicomp = trackDir.dot(module_phiax);
923 float trketacomp = trackDir.dot(module_etaax);
924 float trknormcomp = trackDir.dot(module_normal);
925 double bowphi = atan2(trkphicomp,trknormcomp);
926 double boweta = atan2(trketacomp,trknormcomp);
927 double tanl = m_lorentzAngleTool->getTanLorentzAngle(de->identifyHash(),Gaudi::Hive::currentContext());
928 if(bowphi > pi/2) bowphi -= pi;
929 if(bowphi < -pi/2) bowphi += pi;
930 int readoutside = design->readoutSide();
931 double angle = atan(tan(bowphi)-readoutside*tanl);
932
933
934 // Calculate the theta incidence angle
935 ATH_MSG_VERBOSE( " Angle theta bef corr: " << boweta );
936 if (boweta>pi/2.) boweta-=pi;
937 if (boweta<-pi/2.) boweta+=pi;
938
939
940 ATH_MSG_VERBOSE(" Angle phi: " << angle << " theta: " << boweta );
941 ATH_MSG_VERBOSE(" PhiPixelIndexWeightedPosition: " << phiPixelIndexWeightedPosition << " EtaPixelIndexWeightedPosition: " << etaPixelIndexWeightedPosition );
942
943 // store the matrixOfToT in a vector
944 std::vector<float> vectorOfCharge(sizeX*sizeY,0);
945 std::vector<float> vectorOfToT(sizeX*sizeY,0);
946 int counter(0);
947 for (unsigned int u=0;u<sizeX;u++)
948 {
949 for (unsigned int s=0;s<sizeY;s++)
950 {
951 vectorOfToT[counter] = matrixOfToT[u][s];
952 vectorOfCharge[counter] = matrixOfCharge[u][s];
953 ++counter;
954 }
955 }
956
957 ATH_MSG_VERBOSE( "matrixOfToT converted in a std::vector<float> " );
958
959 ATH_MSG_VERBOSE( "... and saved " );
960 // Add information to xAOD
961 AUXDATA(xprd, int, NN_sizeX) = sizeX;
962 AUXDATA(xprd, int, NN_sizeY) = sizeY;
963
964 AUXDATA(xprd, float, NN_phiBS) = angle;
965 AUXDATA(xprd, float, NN_thetaBS) = boweta;
966
967 AUXDATA(xprd, std::vector<float>, NN_matrixOfToT) = std::move(vectorOfToT);
968 AUXDATA(xprd, std::vector<float>, NN_matrixOfCharge) = std::move(vectorOfCharge);
969 AUXDATA(xprd, std::vector<float>, NN_vectorOfPitchesY) = std::move(vectorOfPitchesY);
970 AUXDATA(xprd, std::vector<float>, NN_vectorOfPitchesX) = std::move(vectorOfPitchesX);
971
972
973 AUXDATA(xprd, int, NN_etaPixelIndexWeightedPosition) = etaPixelIndexWeightedPosition;
974 AUXDATA(xprd, int, NN_phiPixelIndexWeightedPosition) = phiPixelIndexWeightedPosition;
975
976 AUXDATA(xprd, float, NN_localEtaPixelIndexWeightedPosition) = localEtaPixelIndexWeightedPosition;
977 AUXDATA(xprd, float, NN_localPhiPixelIndexWeightedPosition) = localPhiPixelIndexWeightedPosition;
978
979 ATH_MSG_VERBOSE( "NN training Written" );
980}
981
983 const InDet::PixelCluster* pixelCluster,
984 const std::vector<SiHit> & matchingHits ) const
985{
986
987
988 unsigned int numberOfSiHits = matchingHits.size();
989
990 std::vector<float> positionsX(numberOfSiHits,0);
991 std::vector<float> positionsY(numberOfSiHits,0);
992
993 std::vector<float> positions_indexX(numberOfSiHits,0);
994 std::vector<float> positions_indexY(numberOfSiHits,0);
995
996 std::vector<float> theta(numberOfSiHits,0);
997 std::vector<float> phi(numberOfSiHits,0);
998
999 std::vector<int> uniqueID(numberOfSiHits,HepMC::UNDEFINED_ID);
1000 std::vector<int> pdgid(numberOfSiHits,0);
1001 std::vector<float> chargeDep(numberOfSiHits,0);
1002 std::vector<float> truep(numberOfSiHits,0);
1003
1004 std::vector<float> pathlengthX(numberOfSiHits,0);
1005 std::vector<float> pathlengthY(numberOfSiHits,0);
1006 std::vector<float> pathlengthZ(numberOfSiHits,0);
1007
1008 std::vector<int> motherUniqueID(numberOfSiHits,HepMC::UNDEFINED_ID);
1009 std::vector<int> motherPdgid(numberOfSiHits,0);
1010
1011
1012
1013 // Check if we have detector element -- needed to find the local position of the SiHits
1014 const InDetDD::SiDetectorElement* de = pixelCluster->detectorElement();
1015 if(!de)
1016 return;
1017
1018 InDetDD::SiCellId cellIdWeightedPosition = getCellIdWeightedPosition( pixelCluster );
1019
1020 const InDetDD::PixelModuleDesign* design(dynamic_cast<const InDetDD::PixelModuleDesign*>(&de->design()));
1021 if (not design) {
1022 ATH_MSG_WARNING("PixelModuleDesign was not retrieved in function 'addNNTruthInfo'");
1023 return;
1024 }
1025 // lorentz shift correction
1026 double shift = m_lorentzAngleTool->getLorentzShift(de->identifyHash(),Gaudi::Hive::currentContext());
1027 unsigned hitNumber(0);
1028 for( const auto& siHit : matchingHits ){
1029
1030 HepGeom::Point3D<double> averagePosition = (siHit.localStartPosition() + siHit.localEndPosition()) * 0.5;
1031
1032 ATH_MSG_VERBOSE("Truth Part X: " << averagePosition.y() << " shift " << shift << " Y: " << averagePosition.z() );
1033
1034 // position lorentz shift corrected
1035 float YposC = averagePosition.y()-shift;
1036
1037 if (std::abs(YposC)>design->width()/2 &&
1038 std::abs(averagePosition.y())<design->width()/2)
1039 {
1040 if (YposC>design->width()/2)
1041 {
1042 YposC=design->width()/2-1e-6;
1043 } else if (YposC<-design->width()/2)
1044 {
1045 YposC=-design->width()/2+1e-6;
1046 }
1047 }
1048
1049 positionsX[hitNumber] = YposC;
1050 positionsY[hitNumber] = averagePosition.z();
1051
1052 HepGeom::Point3D<double> deltaPosition = siHit.localEndPosition() - siHit.localStartPosition();
1053
1054 pathlengthX[hitNumber] = deltaPosition.y();
1055 pathlengthY[hitNumber] = deltaPosition.z();
1056 pathlengthZ[hitNumber] = deltaPosition.x();
1057
1058
1059 // Here we convert the hit position to the right frame
1060 Amg::Vector2D siLocalTruthPosition = de->hitLocalToLocal(averagePosition.z(), YposC);
1061 InDetDD::SiCellId cellIdOfTruthPosition = design->cellIdOfPosition(siLocalTruthPosition);
1062
1063
1064// InDetDD::SiLocalPosition siLocalTruthPosition(averagePosition.z(),YposC ) ;
1065// InDetDD::SiCellId cellIdOfTruthPosition =design->cellIdOfPosition(siLocalTruthPosition);
1066
1067 int truthEtaIndex = cellIdOfTruthPosition.etaIndex();
1068 int truthPhiIndex = cellIdOfTruthPosition.phiIndex();
1069
1070 InDetDD::SiDiodesParameters diodeParameters = design->parameters(cellIdOfTruthPosition);
1071 double pitchY = diodeParameters.width().xEta();
1072 double pitchX = diodeParameters.width().xPhi();
1073
1074 // pixel center
1075 // SiLocalPosition PixelModuleDesign::positionFromColumnRow(const int column, const int row) const;
1076 //
1077 // Given row and column index of diode, returns position of diode center
1078 // ALTERNATIVE/PREFERED way is to use localPositionOfCell(const SiCellId & cellId) or
1079 // rawLocalPositionOfCell method in SiDetectorElement.
1080 // DEPRECATED (but used in numerous places)
1081 //
1082 // Comment by Hide (referring the original comment in the code) : 2015-02-04
1083 // I automatically replaced column to etaPixelIndex and row to phiPixelIndex here. It was bofore:
1084 // InDetDD::SiLocalPosition siLocalPosition( design->positionFromColumnRow(truthColumn,truthRow) );
1085 //
1086 // Then I assume the argument of column/row in this function is in offline manner, not the real hardware column/row.
1087 //
1088 InDetDD::SiLocalPosition siLocalPositionCenter(design->positionFromColumnRow(truthEtaIndex,truthPhiIndex));
1089 double pixelCenterY = siLocalPositionCenter.xEta();
1090 double pixelCenterX = siLocalPositionCenter.xPhi();
1091
1092
1093 // truth index
1094// double truthIndexY = truthEtaIndex + (averagePosition.z() - pixelCenterY)/pitchY;
1095// double truthIndexX = truthPhiIndex + (YposC - pixelCenterX)/pitchX;
1096 double truthIndexY = truthEtaIndex + (siLocalTruthPosition[Trk::distEta] - pixelCenterY)/pitchY;
1097 double truthIndexX = truthPhiIndex + (siLocalTruthPosition[Trk::distPhi] - pixelCenterX)/pitchX;
1098
1099
1100 positions_indexX[hitNumber] = truthIndexX - cellIdWeightedPosition.phiIndex();
1101 positions_indexY[hitNumber] = truthIndexY - cellIdWeightedPosition.etaIndex();
1102
1103 HepGeom::Point3D<double> diffPositions = (siHit.localEndPosition() - siHit.localStartPosition());
1104 double bowphi = std::atan2( diffPositions.y(), diffPositions.x() );
1105
1106
1107 //Truth Track incident angle theta
1108 theta[hitNumber] = std::atan2(diffPositions.z() ,diffPositions.x());
1109 //Truth track incident angle phi -- correct for lorentz angle
1110 float tanlorentz = m_lorentzAngleTool->getTanLorentzAngle(de->identifyHash(),Gaudi::Hive::currentContext());
1111
1112 int readoutside = design->readoutSide();
1113 phi[hitNumber] = std::atan(std::tan(bowphi)-readoutside*tanlorentz);
1114 const HepMcParticleLink& HMPL = siHit.particleLink();
1115 if (HMPL.isValid()){
1116 uniqueID[hitNumber] = HepMC::uniqueID(HMPL);
1117 const auto particle = HMPL.cptr();
1118 pdgid[hitNumber] = particle->pdg_id();
1119 HepMC::FourVector mom=particle->momentum();
1120 truep[hitNumber] = std::sqrt(mom.x()*mom.x()+mom.y()*mom.y()+mom.z()*mom.z());
1121 const auto vertex = particle->production_vertex();
1122//AV Please note that taking the first particle as a mother is ambiguous.
1123 if ( vertex && !vertex->particles_in().empty()){
1124 const auto& mother_of_particle=vertex->particles_in().front();
1125 motherUniqueID[hitNumber] = HepMC::uniqueID(mother_of_particle);
1126 motherPdgid[hitNumber] = mother_of_particle->pdg_id();
1127 }
1128 }
1129 chargeDep[hitNumber] = siHit.energyLoss() ;
1130
1131 ++hitNumber;
1132 }
1133
1134
1135 AUXDATA(xprd, std::vector<float>, NN_positionsX) = std::move(positionsX);
1136 AUXDATA(xprd, std::vector<float>, NN_positionsY) = std::move(positionsY);
1137
1138 AUXDATA(xprd, std::vector<float>, NN_positions_indexX) = std::move(positions_indexX);
1139 AUXDATA(xprd, std::vector<float>, NN_positions_indexY) = std::move(positions_indexY);
1140
1141 AUXDATA(xprd, std::vector<float>, NN_theta) = std::move(theta);
1142 AUXDATA(xprd, std::vector<float>, NN_phi) = std::move(phi);
1143
1144 AUXDATA(xprd, std::vector<int>, NN_barcode) = std::move(uniqueID); // TODO Rename variable to be consistent?
1145 AUXDATA(xprd, std::vector<int>, NN_pdgid) = std::move(pdgid);
1146 AUXDATA(xprd, std::vector<float>, NN_energyDep) = std::move(chargeDep);
1147 AUXDATA(xprd, std::vector<float>, NN_trueP) = std::move(truep);
1148
1149 AUXDATA(xprd, std::vector<int>, NN_motherBarcode) = std::move(motherUniqueID); // TODO Rename variable to be consistent?
1150 AUXDATA(xprd, std::vector<int>, NN_motherPdgid) = std::move(motherPdgid);
1151
1152
1153
1154 AUXDATA(xprd, std::vector<float>, NN_pathlengthX) = std::move(pathlengthX);
1155 AUXDATA(xprd, std::vector<float>, NN_pathlengthY) = std::move(pathlengthY);
1156 AUXDATA(xprd, std::vector<float>, NN_pathlengthZ) = std::move(pathlengthZ);
1157
1158
1159}
1160
1161
1162
1163
1165 int *rphiPixelIndexMin,
1166 int *rphiPixelIndexMax,
1167 int *retaPixelIndexMin,
1168 int *retaPixelIndexMax ) const
1169{
1170
1171 const InDetDD::SiDetectorElement* de = pixelCluster->detectorElement();
1172 if (de==nullptr) {
1173 ATH_MSG_ERROR("Could not get detector element");
1174 return {};
1175 }
1176
1177 const InDetDD::PixelModuleDesign* design(dynamic_cast<const InDetDD::PixelModuleDesign*>(&de->design()));
1178 if (not design) {
1179 ATH_MSG_WARNING("PixelModuleDesign was not retrieved in function 'getCellIdWeightedPosition'");
1180 return {};
1181 }
1182 const std::vector<Identifier>& rdos = pixelCluster->rdoList();
1183
1184 ATH_MSG_VERBOSE( "Number of RDOs: " << rdos.size() );
1185 const std::vector<float>& chList = pixelCluster->chargeList();
1186
1187 ATH_MSG_VERBOSE( "Number of charges: " << chList.size() );
1188 std::vector<Identifier>::const_iterator rdosBegin = rdos.begin();
1189 std::vector<Identifier>::const_iterator rdosEnd = rdos.end();
1190
1191 auto charge = chList.begin();
1192
1193 InDetDD::SiLocalPosition sumOfWeightedPositions(0,0,0);
1194 double sumOfCharge=0;
1195
1196 int phiPixelIndexMin = 99999;
1197 int phiPixelIndexMax = -99999;
1198 int etaPixelIndexMin = 99999;
1199 int etaPixelIndexMax = -99999;
1200
1201 for (; rdosBegin!= rdosEnd; ++rdosBegin, ++charge)
1202 {
1203
1204 Identifier rId = *rdosBegin;
1205 int phiPixelIndex = m_PixelHelper->phi_index(rId);
1206 int etaPixelIndex = m_PixelHelper->eta_index(rId);
1207
1208 ATH_MSG_VERBOSE(" Adding pixel phiPixelIndex: " << phiPixelIndex << " etaPixelIndex: " << etaPixelIndex << " charge: " << *charge );
1209
1210 // SiLocalPosition PixelModuleDesign::positionFromColumnRow(const int column, const int row) const;
1211 //
1212 // Given row and column index of diode, returns position of diode center
1213 // ALTERNATIVE/PREFERED way is to use localPositionOfCell(const SiCellId & cellId) or
1214 // rawLocalPositionOfCell method in SiDetectorElement.
1215 // DEPRECATED (but used in numerous places)
1216 //
1217 // Comment by Hide (referring the original comment in the code): 2015-02-04
1218 // I automatically replaced column to etaPixelIndex and row to phiPixelIndex here. It was bofore:
1219 // InDetDD::SiLocalPosition siLocalPosition( design->positionFromColumnRow(column,row) );
1220 //
1221 // Then I assume the argument of column/row in this function is in offline manner, not the real hardware column/row.
1222 //
1223 InDetDD::SiLocalPosition siLocalPosition( design->positionFromColumnRow(etaPixelIndex,phiPixelIndex) );
1224 ATH_MSG_VERBOSE ( "Local Position: Row = " << siLocalPosition.xRow() << ", Col = " << siLocalPosition.xColumn() );
1225
1226 sumOfWeightedPositions += (*charge)*siLocalPosition;
1227 sumOfCharge += (*charge);
1228
1229 if (phiPixelIndex < phiPixelIndexMin)
1230 phiPixelIndexMin = phiPixelIndex;
1231
1232 if (phiPixelIndex > phiPixelIndexMax)
1233 phiPixelIndexMax = phiPixelIndex;
1234
1235 if (etaPixelIndex < etaPixelIndexMin)
1236 etaPixelIndexMin = etaPixelIndex;
1237
1238 if (etaPixelIndex > etaPixelIndexMax)
1239 etaPixelIndexMax = etaPixelIndex;
1240
1241 }
1242 sumOfWeightedPositions /= sumOfCharge;
1243
1244 ATH_MSG_VERBOSE ( "Wighted position: Row = " << sumOfWeightedPositions.xRow() << ", Col = " << sumOfWeightedPositions.xColumn() );
1245
1246 if(rphiPixelIndexMin) *rphiPixelIndexMin = phiPixelIndexMin;
1247 if(rphiPixelIndexMax) *rphiPixelIndexMax = phiPixelIndexMax;
1248 if(retaPixelIndexMin) *retaPixelIndexMin = etaPixelIndexMin;
1249 if(retaPixelIndexMax) *retaPixelIndexMax = etaPixelIndexMax;
1250
1251 //what you want to know is simple:
1252 //just the phiPixelIndex and etaPixelIndex of this average position!
1253
1254 InDetDD::SiCellId cellIdWeightedPosition=design->cellIdOfPosition(sumOfWeightedPositions);
1255
1256
1257 return cellIdWeightedPosition;
1258
1259}
1260
1261
1262
1264//
1265// Finalize method:
1266//
1269{
1270 if (m_useTruthInfo && !m_truthParticleLinks.empty()) {
1271 ATH_MSG_INFO("Missing truth particles " << m_missingTruthParticle << " missing parent: " << m_missingParentParticle
1272 << " have " << m_haveTruthLink);
1273 }
1274 return StatusCode::SUCCESS;
1275}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
Structs for holding charge calibration parameterisation and data.
This is an Identifier helper class for the Pixel subdetector.
#define AUXDATA(OBJ, TYP, NAME)
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
const double width
#define pi
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
This is a "hash" representation of an Identifier.
bool is_valid() const
Check if id is in a valid state.
value_type get_compact() const
Get the compact id.
int readoutSide() const
ReadoutSide.
Class used to describe the design of a module (diode segmentation and readout scheme).
virtual SiDiodesParameters parameters(const SiCellId &cellId) const
readout or diode id -> position, size
SiLocalPosition positionFromColumnRow(const int column, const int row) const
Given row and column index of a diode, return position of diode center ALTERNATIVE/PREFERED way is to...
virtual SiCellId cellIdOfPosition(const SiLocalPosition &localPos) const
position -> id
virtual double width() const
Method to calculate average width of a module.
virtual double etaPitch() const
Pitch in eta direction.
virtual double phiPitch() const
Pitch in phi direction.
Identifier for the strip or pixel cell.
Definition SiCellId.h:29
int phiIndex() const
Get phi index. Equivalent to strip().
Definition SiCellId.h:122
bool isValid() const
Test if its in a valid state.
Definition SiCellId.h:136
int etaIndex() const
Get eta index.
Definition SiCellId.h:114
Class to hold geometrical description of a silicon detector element.
virtual SiCellId cellIdFromIdentifier(const Identifier &identifier) const override final
SiCellId from Identifier.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
Class to handle the position of the centre and the width of a diode or a cluster of diodes Version 1....
const SiLocalPosition & width() const
width of the diodes:
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
double xColumn() const
positions for Pixel:
double xEta() const
position along eta direction:
SiCellId cellIdOfPosition(const Amg::Vector2D &localPos) const
As in previous method but returns SiCellId.
virtual const Amg::Vector3D & normal() const override final
Get reconstruction local normal axes in global frame.
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
virtual Identifier identify() const override final
identifier of this detector element (inline)
Amg::Vector2D hitLocalToLocal(double xEta, double xPhi) const
Simulation/Hit local frame to reconstruction local frame.
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
const Amg::Vector2D & colRow() const
Definition SiWidth.h:115
A PRD is mapped onto all contributing particles.
PixelChargeCalib::LegacyFitParameters getLegacyFitParameters(InDetDD::PixelDiodeType type, unsigned int moduleHash, unsigned int FE) const
void addNNInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::PixelCluster *pixelCluster, const unsigned int SizeX, const unsigned int SizeY) const
SG::WriteHandleKey< std::vector< unsigned int > > m_write_offsets
void addRdoInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::PixelCluster *pixelCluster, const PixelChargeCalibCondData *calibData) const
std::atomic< unsigned int > m_missingTruthParticle
const PixelID * m_PixelHelper
SG::ReadCondHandleKey< PixelDCSHVData > m_readKeyHV
SG::ReadHandleKey< SiHitCollection > m_sihitContainer_key
SG::ReadCondHandleKey< PixelChargeCalibCondData > m_chargeDataKey
void addSiHitInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::PixelCluster *prd, const std::vector< SiHit > &matchingHits) const
SG::ReadHandleKey< Trk::ClusterSplitProbabilityContainer > m_clusterSplitProbContainer
virtual StatusCode execute(const EventContext &ctx)
Execute method.
PixelPrepDataToxAOD(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< SiHit > findAllHitsCompatibleWithCluster(const InDet::PixelCluster *prd, const std::vector< const SiHit * > *sihits, std::vector< std::vector< int > > &trkBCs) const
ToolHandle< IInDetConditionsTool > m_pixelSummary
SG::ReadHandleKey< xAODTruthParticleLinkVector > m_truthParticleLinks
SG::ReadCondHandleKey< PixelDCSTempData > m_readKeyTemp
InDetDD::SiCellId getCellIdWeightedPosition(const InDet::PixelCluster *pixelCluster, int *rrowMin=0, int *rrowMax=0, int *rcolMin=0, int *rcolMax=0) const
SG::ReadHandleKey< InDetSimDataCollection > m_SDOcontainer_key
SG::ReadCondHandleKey< PixelDCSStatusData > m_condDCSStatusKey
std::atomic< unsigned int > m_missingParentParticle
void addNNTruthInfo(xAOD::TrackMeasurementValidation *xprd, const InDet::PixelCluster *prd, const std::vector< SiHit > &matchingHits) const
virtual StatusCode finalize()
SG::ReadHandleKey< InDet::PixelClusterContainer > m_clustercontainer_key
SG::ReadHandleKey< PRD_MultiTruthCollection > m_multiTruth_key
SG::ReadCondHandleKey< PixelDCSStateData > m_condDCSStateKey
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
ToolHandle< ISiLorentzAngleTool > m_lorentzAngleTool
ServiceHandle< InDetDD::IPixelReadoutManager > m_pixelReadout
std::vector< std::vector< int > > addSDOInformation(xAOD::TrackMeasurementValidation *xprd, const InDet::PixelCluster *prd, const InDetSimDataCollection &sdoCollection) const
virtual StatusCode initialize()
std::atomic< unsigned int > m_haveTruthLink
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Definition SiHit.h:19
HepGeom::Point3D< double > localStartPosition() const
Definition SiHit.cxx:146
HepGeom::Point3D< double > localEndPosition() const
Definition SiHit.cxx:153
static const ProbabilityInfo & getNoSplitProbability()
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
ElementLink< xAOD::TruthParticleContainer > find(const HepMcParticleLink &hepMCLink) const
void setRdoIdentifierList(const std::vector< uint64_t > &rdoIdentifierList)
Sets the list of RDO identifiers.
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
void setLocalPosition(float localX, float localY)
Sets the local position.
void setIdentifier(uint64_t identifier)
Sets the identifier.
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr int INVALID_PARTICLE_ID
HepMC3::FourVector FourVector
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
@ distEta
readout for silicon
Definition ParamDefs.h:51
@ distPhi
Definition ParamDefs.h:50
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.