Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MMLoadVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9  AthMessaging(Athena::getMessageSvc(), "MMLoadVariables") {
10  m_detManager = detManager;
11  m_MmIdHelper = idhelper;
12 }
13 
15  const McEventCollection *truthContainer,
16  const TrackRecordCollection* trackRecordCollection,
17  const MmDigitContainer *nsw_MmDigitContainer,
18  std::map<std::pair<uint64_t,unsigned int>,std::vector<digitWrapper> >& entries,
19  std::map<std::pair<uint64_t,unsigned int>,std::vector<hitData_entry> >& Hits_Data_Set_Time,
20  std::map<std::pair<uint64_t,unsigned int>,evInf_entry>& Event_Info) const {
21  //*******Following MuonPRD code to access all the variables**********
22  std::vector<ROOT::Math::PtEtaPhiEVector> truthParticles, truthParticles_ent, truthParticles_pos;
23  std::vector<int> pdg;
24  std::vector<ROOT::Math::XYZVector> vertex;
25  float phiEntry_tmp = 0;
26  float phiPosition_tmp = 0;
27  float etaEntry_tmp = 0;
28  float etaPosition_tmp = 0;
29  int pdg_tmp = 0;
30  ROOT::Math::XYZVector vertex_tmp(0.,0.,0.);
31 
32  ROOT::Math::PtEtaPhiEVector thePart, theInfo;
33  auto MuEntry_Particle_n = (trackRecordCollection!=nullptr)?trackRecordCollection->size():0;
34  int j=0; // iteration of particle entries
35  if( truthContainer != nullptr ){
36  for(const auto it : *truthContainer) {
37  const HepMC::GenEvent *subEvent = it;
38  for(const auto& particle : *subEvent){
39  const HepMC::FourVector momentum = particle->momentum();
40  if( HepMC::generations(particle) < 1 && std::abs(particle->pdg_id())==13){
41  thePart.SetCoordinates(momentum.perp(),momentum.eta(),momentum.phi(),momentum.e());
42  if(trackRecordCollection!=nullptr){
43  for(const auto & mit : *trackRecordCollection ) {
44  const CLHEP::Hep3Vector mumomentum = mit.GetMomentum();
45  const CLHEP::Hep3Vector muposition = mit.GetPosition();
46  if(!trackRecordCollection->empty() && HepMC::barcode(particle) == mit.barcode()) { // FIXME barcode-based
47  pdg_tmp = particle->pdg_id();
48  phiEntry_tmp = mumomentum.getPhi();
49  etaEntry_tmp = mumomentum.getEta();
50  phiPosition_tmp = muposition.getPhi();
51  etaPosition_tmp = muposition.getEta();
52  }
53  }//muentry loop
54  } // trackRecordCollection is not null
55 #ifdef HEPMC3
56  vertex_tmp = subEvent->vertices().front()->position();
57 #else
58  int l=0;
59  for(const auto vit : subEvent->vertex_range())
60  {
61  if(l!=0){break;}//get first vertex of iteration, may want to change this
62  l++;
63  const HepMC::GenVertex *vertex1 = vit;
64  const HepMC::FourVector& position = vertex1->position();
65  vertex_tmp.SetXYZ(position.x(),position.y(),position.z());
66  }//end vertex loop
67 #endif
68  }
69  j++;
70 
71  if(thePart.Pt() > 0. && HepMC::generations(particle) < 1){
72  bool addIt = true;
73  for(unsigned int ipart=0; ipart < truthParticles.size(); ipart++){
74  if( std::abs(thePart.Pt()-truthParticles[ipart].Pt()) < 0.001 ||
75  std::abs(thePart.Eta()-truthParticles[ipart].Eta()) < 0.001 ||
76  std::abs(xAOD::P4Helpers::deltaPhi(thePart.Phi(), truthParticles[ipart].Phi())) < 0.001 ||
77  std::abs(thePart.E()-truthParticles[ipart].E()) < 0.001 ) addIt = false;
78  }
79  if(addIt){
80  truthParticles.push_back(thePart);
81  //new stuff
82  vertex.push_back(vertex_tmp);
83  pdg.push_back(pdg_tmp);
84  truthParticles_ent.push_back(ROOT::Math::PtEtaPhiEVector(momentum.perp(),etaEntry_tmp ,phiEntry_tmp ,momentum.e()));
85  truthParticles_pos.push_back(ROOT::Math::PtEtaPhiEVector(momentum.perp(),etaPosition_tmp,phiPosition_tmp,momentum.e()));
86  }
87  }
88 
89  } //end particle loop
90  } //end truth container loop (should be only 1 container per event)
91  } // if truth container is not null
92 
93  uint64_t event = ctx.eventID().event_number();
94  int TruthParticle_n = j;
95  unsigned int digit_particles = 0;
96  for(auto digitCollectionIter : *nsw_MmDigitContainer) {
97  // a digit collection is instanciated for each container, i.e. holds all digits of a multilayer
98  const MmDigitCollection* digitCollection = digitCollectionIter;
99  // loop on all digits inside a collection, i.e. multilayer
100  std::vector<digitWrapper> entries_tmp;
101 
102  for (const auto item:*digitCollection) {
103  // get specific digit and identify it
104  const MmDigit* digit = item;
105  Identifier id = digit->identify();
106  if (!m_MmIdHelper->is_mm(id)) continue;
107 
108  std::string stName = m_MmIdHelper->stationNameString(m_MmIdHelper->stationName(id));
112  int multiplet = m_MmIdHelper->multilayer(id);
113  int gas_gap = m_MmIdHelper->gasGap(id);
114  int channel = m_MmIdHelper->channel(id);
115 
117 
118  std::vector<float> time{digit->stripResponseTime()};
119  std::vector<float> charge{digit->stripResponseCharge()};
120  std::vector<int> stripPosition{channel};
121  std::vector<int> MMFE_VMM{channel};
122  std::vector<int> VMM{channel};
123 
124  bool isValid = false;
125  std::vector<double> localPosX;
126  std::vector<double> localPosY;
127  std::vector<double> globalPosX;
128  std::vector<double> globalPosY;
129  std::vector<double> globalPosZ;
130 
131  int nstrip = 0; //counter of the number of firing strips
132  for (const auto &i: stripPosition) {
133 
134  isValid = false; //reset
135  // take strip index form chip information
136  int cr_strip = i;
137  localPosX.push_back (0.);
138  localPosY.push_back (0.);
139  globalPosX.push_back(0.);
140  globalPosY.push_back(0.);
141  globalPosZ.push_back(0.);
142  ++nstrip;
143 
144  Identifier cr_id = m_MmIdHelper->channelID(stationName, stationEta, stationPhi, multiplet, gas_gap, cr_strip, isValid);
145  if (!isValid) {
146  ATH_MSG_WARNING("MicroMegas digitization: failed to create a valid ID for (chip response) strip n. " << cr_strip
147  << "; associated positions will be set to 0.0.");
148  } else {
149  // asking the detector element to get local position of strip
150  Amg::Vector2D cr_strip_pos(0., 0.);
151  if ( !rdoEl->stripPosition(cr_id,cr_strip_pos) ) {
152  ATH_MSG_WARNING("MicroMegas digitization: failed to associate a valid local position for (chip response) strip n. " << cr_strip
153  << "; associated positions will be set to 0.0.");
154  } else {
155  localPosX[nstrip-1] = cr_strip_pos.x();
156  localPosY[nstrip-1] = cr_strip_pos.y();
157  }
158 
159  // asking the detector element to transform this local to the global position
160  Amg::Vector3D cr_strip_gpos(0., 0., 0.);
161  rdoEl->surface(cr_id).localToGlobal(cr_strip_pos, Amg::Vector3D(0., 0., 0.), cr_strip_gpos);
162  globalPosX[nstrip-1] = cr_strip_gpos[0];
163  globalPosY[nstrip-1] = cr_strip_gpos[1];
164  globalPosZ[nstrip-1] = cr_strip_gpos[2];
165  }
166  }//end of strip position loop
167  if(globalPosY.empty()) continue;
168 
169  if (!time.empty()) entries_tmp.push_back(
170  digitWrapper(digit, stName, -1.,
171  ROOT::Math::XYZVector(-999, -999, -999),
172  ROOT::Math::XYZVector(localPosX[0], localPosY[0], -999),
173  ROOT::Math::XYZVector(globalPosX[0], globalPosY[0], globalPosZ[0] )
174  ) );
175  } //end iterator digit loop
176 
177  if (!entries_tmp.empty()) {
178  std::vector<std::string> stNames;
179  for(const auto &dW : entries_tmp) stNames.push_back(dW.stName);
180  if(std::all_of(stNames.begin(), stNames.end(), [&] (const std::string & name) { return name == stNames[0]; })) {
181  entries[std::make_pair(event,digit_particles)]=entries_tmp;
182  digit_particles++;
183  } else {
184  ATH_MSG_WARNING("Digits belonging to different stations, skipping items");
185  }
186  stNames.clear();
187  }
188  } // end digit container loop
189 
190  for(unsigned int i=0; i<truthParticles.size(); i++) {
191  evInf_entry particle_info(event, pdg[i],
192  truthParticles[i].E(), truthParticles[i].Pt(),
193  truthParticles[i].Eta(), truthParticles_pos[i].Eta(), truthParticles_ent[i].Eta(),
194  truthParticles[i].Phi(), truthParticles_pos[i].Phi(), truthParticles_ent[i].Phi(),
195  truthParticles[i].Theta(), truthParticles_pos[i].Theta(), truthParticles_ent[i].Theta(), truthParticles_ent[i].Theta()-truthParticles_pos[i].Theta(),
196  TruthParticle_n,MuEntry_Particle_n,vertex[i]);
197  Event_Info[std::make_pair(event,i)] = particle_info;
198  }
199 
200  //Loop over entries, which has digitization info for each event
201  unsigned int ient=0;
202  for (auto it=entries.begin(); it!=entries.end(); it++){
203 
204  /* Identifying the wedge from digits:
205  * now the digit is associated with the corresponding station, so lambda function can be exploited to check if they are all the same
206  */
207  double tru_phi = -999, tru_theta = -999;
208  std::pair<int, unsigned int> pair (event,ient);
209  auto tru_it = Event_Info.find(pair);
210  if (tru_it != Event_Info.end()) {
211  tru_phi = tru_it->second.phi_pos;
212  tru_theta = tru_it->second.theta_pos;
213  }
214 
215  std::string station = it->second[0].stName;
216  std::vector<hitData_entry> hit_info;
217  hit_info.reserve(it->second.size());
218 
219  //Now we need to loop on digits
220  for (const auto &dW : it->second) {
221  Identifier tmpID = dW.id();
222  int thisMultiplet = m_MmIdHelper->multilayer( tmpID );
223  int thisGasGap = m_MmIdHelper->gasGap( tmpID );
224  int thisTime = dW.digit->stripResponseTime();
225  int thisCharge = 2; //dW.digit->stripChargeForTrigger().at(0);
226  int thisStripPosition = m_MmIdHelper->channel(tmpID);
227  double thisLocalPosX = dW.strip_lpos.X();
228  int thisVMM = m_MmIdHelper->channel( tmpID);
229  int thisMMFE_VMM = thisVMM;
230  int thisStationEta = m_MmIdHelper->stationEta( tmpID );
231  int thisStationPhi = m_MmIdHelper->stationPhi( tmpID );
232  int thisPlane = (thisMultiplet-1)*4+thisGasGap-1;
233  int BC_id = std::ceil( thisTime / 25. );
234  ROOT::Math::XYZVector mazin_check(
235  dW.strip_gpos.X(),
236  dW.strip_gpos.Y(),
237  dW.strip_gpos.Z()
238  );
239 
240  hitData_entry hit_entry(event,
241  thisTime,
242  thisCharge,
243  thisVMM,
244  thisMMFE_VMM,
245  thisPlane,
246  thisStripPosition,
247  thisStationEta,
248  thisStationPhi,
249  thisMultiplet,
250  thisGasGap,
251  thisLocalPosX,
252  tru_theta,
253  tru_phi,
254  true,
255  BC_id,
256  mazin_check,
257  mazin_check);
258 
259  hit_info.push_back(hit_entry);
260  ATH_MSG_DEBUG("Done filling hit_info structure");
261  }//end digit wrapper loop
262 
263  Hits_Data_Set_Time[std::make_pair(event,ient)] = hit_info;
264  ient++;
265  }
266  return StatusCode::SUCCESS;
267 }
MmDigitContainer
Use IdentifiableContainer with MmDigitCollection.
Definition: MmDigitContainer.h:50
MmDigitCollection
Definition: MmDigitCollection.h:18
MuonGM::MMReadoutElement::stripPosition
virtual bool stripPosition(const Identifier &id, Amg::Vector2D &pos) const override final
strip position – local or global If the strip number is outside the range of valid strips,...
Definition: MMReadoutElement.h:207
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:161
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
MMLoadVariables.h
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
AtlasHitsVector
Definition: AtlasHitsVector.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:407
MmDigit
Definition: MmDigit.h:20
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
Phi
@ Phi
Definition: RPCdef.h:8
MMLoadVariables::getMMDigitsInfo
StatusCode getMMDigitsInfo(const EventContext &ctx, const McEventCollection *truthContainer, const TrackRecordCollection *trackRecordCollection, const MmDigitContainer *nsw_MmDigitContainer, std::map< std::pair< uint64_t, unsigned int >, std::vector< digitWrapper > > &entries, std::map< std::pair< uint64_t, unsigned int >, std::vector< hitData_entry > > &Hits_Data_Set_Time, std::map< std::pair< uint64_t, unsigned int >, evInf_entry > &Event_Info) const
Definition: MMLoadVariables.cxx:14
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:800
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:812
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
MMLoadVariables::MMLoadVariables
MMLoadVariables(const MuonGM::MuonDetectorManager *detManager, const MmIdHelper *idhelper)
Definition: MMLoadVariables.cxx:8
MuonGM::MuonClusterReadoutElement::surface
virtual const Trk::PlaneSurface & surface() const override
access to chamber surface (phi orientation), uses the first gas gap
Definition: MuonClusterReadoutElement.h:123
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MmIdHelper::multilayer
int multilayer(const Identifier &id) const
Definition: MmIdHelper.cxx:796
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MMLoadVariables::m_detManager
const MuonGM::MuonDetectorManager * m_detManager
MuonDetectorManager.
Definition: MMLoadVariables.h:44
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
evInf_entry
Definition: MMT_struct.h:59
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
MuonIdHelper::is_mm
bool is_mm(const Identifier &id) const
Definition: MuonIdHelper.cxx:797
MMLoadVariables::m_MmIdHelper
const MmIdHelper * m_MmIdHelper
MM offline Id helper.
Definition: MMLoadVariables.h:45
MuonIdHelper::stationPhi
int stationPhi(const Identifier &id) const
Definition: MuonIdHelper.cxx:810
MuonIdHelper::stationNameString
const std::string & stationNameString(const int &index) const
Definition: MuonIdHelper.cxx:854
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MagicNumbers.h
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
charge
double charge(const T &p)
Definition: AtlasPID.h:931
MuonIdHelper::stationEta
int stationEta(const Identifier &id) const
Definition: MuonIdHelper.cxx:805
item
Definition: ItemListSvc.h:43
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
MmIdHelper::channel
int channel(const Identifier &id) const override
Definition: MmIdHelper.cxx:800
MmIdHelper
Definition: MmIdHelper.h:54
MmIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: MmIdHelper.cxx:798
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:50
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonGM::MuonDetectorManager::getMMReadoutElement
const MMReadoutElement * getMMReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:255
MuonGM::MMReadoutElement
An MMReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station con...
Definition: MMReadoutElement.h:25
entries
double entries
Definition: listroot.cxx:49
hitData_entry
Definition: MMT_struct.h:70
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:159
Trk::PlaneSurface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const override final
Specified for PlaneSurface: LocalToGlobal method without dynamic memory allocation.
Definition: PlaneSurface.cxx:204
HepMC::generations
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
Definition: MagicNumbers.h:358
MmIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
Definition: MmIdHelper.cxx:736
Eta
@ Eta
Definition: RPCdef.h:8
digitWrapper
Definition: MMT_struct.h:83
Identifier
Definition: IdentifierFieldParser.cxx:14