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