ATLAS Offline Software
MMLoadVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
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<int,unsigned int>,std::vector<digitWrapper> >& entries,
19  std::map<std::pair<int,unsigned int>,std::vector<hitData_entry> >& Hits_Data_Set_Time,
20  std::map<std::pair<int,unsigned int>,evInf_entry>& Event_Info,
21  histogramDigitVariables &histDigVars) const {
22  //*******Following MuonPRD code to access all the variables**********
23  std::vector<ROOT::Math::PtEtaPhiEVector> truthParticles, truthParticles_ent, truthParticles_pos;
24  std::vector<int> pdg;
25  std::vector<ROOT::Math::XYZVector> vertex;
26  float phiEntry_tmp = 0;
27  float phiPosition_tmp = 0;
28  float etaEntry_tmp = 0;
29  float etaPosition_tmp = 0;
30  int pdg_tmp = 0;
31  ROOT::Math::XYZVector vertex_tmp(0.,0.,0.);
32 
33  ROOT::Math::PtEtaPhiEVector thePart, theInfo;
34  auto MuEntry_Particle_n = (trackRecordCollection!=nullptr)?trackRecordCollection->size():0;
35  int j=0; // iteration of particle entries
36  if( truthContainer != nullptr ){
37  for(const auto it : *truthContainer) {
38  const HepMC::GenEvent *subEvent = it;
39  for(const auto& particle : *subEvent){
40  const HepMC::FourVector momentum = particle->momentum();
41  if( HepMC::generations(particle) < 1 && std::abs(particle->pdg_id())==13){
42  thePart.SetCoordinates(momentum.perp(),momentum.eta(),momentum.phi(),momentum.e());
43  if(trackRecordCollection!=nullptr){
44  for(const auto & mit : *trackRecordCollection ) {
45  const CLHEP::Hep3Vector mumomentum = mit.GetMomentum();
46  const CLHEP::Hep3Vector muposition = mit.GetPosition();
47  if(!trackRecordCollection->empty() && HepMC::barcode(particle) == mit.barcode()) { // FIXME barcode-based
48  pdg_tmp = particle->pdg_id();
49  phiEntry_tmp = mumomentum.getPhi();
50  etaEntry_tmp = mumomentum.getEta();
51  phiPosition_tmp = muposition.getPhi();
52  etaPosition_tmp = muposition.getEta();
53  }
54  }//muentry loop
55  } // trackRecordCollection is not null
56 #ifdef HEPMC3
57  vertex_tmp = subEvent->vertices().front()->position();
58 #else
59  int l=0;
60  for(const auto vit : subEvent->vertex_range())
61  {
62  if(l!=0){break;}//get first vertex of iteration, may want to change this
63  l++;
64  const HepMC::GenVertex *vertex1 = vit;
65  const HepMC::FourVector& position = vertex1->position();
66  vertex_tmp.SetXYZ(position.x(),position.y(),position.z());
67  }//end vertex loop
68 #endif
69  }
70  j++;
71 
72  if(thePart.Pt() > 0. && HepMC::generations(particle) < 1){
73  bool addIt = true;
74  for(unsigned int ipart=0; ipart < truthParticles.size(); ipart++){
75  if( std::abs(thePart.Pt()-truthParticles[ipart].Pt()) < 0.001 ||
76  std::abs(thePart.Eta()-truthParticles[ipart].Eta()) < 0.001 ||
77  std::abs(xAOD::P4Helpers::deltaPhi(thePart.Phi(), truthParticles[ipart].Phi())) < 0.001 ||
78  std::abs(thePart.E()-truthParticles[ipart].E()) < 0.001 ) addIt = false;
79  }
80  if(addIt){
81  truthParticles.push_back(thePart);
82  //new stuff
83  vertex.push_back(vertex_tmp);
84  pdg.push_back(pdg_tmp);
85  truthParticles_ent.push_back(ROOT::Math::PtEtaPhiEVector(momentum.perp(),etaEntry_tmp ,phiEntry_tmp ,momentum.e()));
86  truthParticles_pos.push_back(ROOT::Math::PtEtaPhiEVector(momentum.perp(),etaPosition_tmp,phiPosition_tmp,momentum.e()));
87  }
88  }
89 
90  } //end particle loop
91  } //end truth container loop (should be only 1 container per event)
92  } // if truth container is not null
93 
94  int event = ctx.eventID().event_number();
95  int TruthParticle_n = j;
96  unsigned int digit_particles = 0;
97  for(auto digitCollectionIter : *nsw_MmDigitContainer) {
98  // a digit collection is instanciated for each container, i.e. holds all digits of a multilayer
99  const MmDigitCollection* digitCollection = digitCollectionIter;
100  // loop on all digits inside a collection, i.e. multilayer
101  std::vector<digitWrapper> entries_tmp;
102 
103  for (const auto item:*digitCollection) {
104  // get specific digit and identify it
105  const MmDigit* digit = item;
106  Identifier id = digit->identify();
107  if (!m_MmIdHelper->is_mm(id)) continue;
108 
109  std::string stName = m_MmIdHelper->stationNameString(m_MmIdHelper->stationName(id));
113  int multiplet = m_MmIdHelper->multilayer(id);
114  int gas_gap = m_MmIdHelper->gasGap(id);
115  int channel = m_MmIdHelper->channel(id);
116 
118 
119  std::vector<float> time{digit->stripResponseTime()};
120  std::vector<float> charge{digit->stripResponseCharge()};
121  std::vector<int> stripPosition{channel};
122  std::vector<int> MMFE_VMM{channel};
123  std::vector<int> VMM{channel};
124 
125  bool isValid = false;
126  histDigVars.NSWMM_dig_stationName.push_back(stName);
127  histDigVars.NSWMM_dig_stationEta.push_back(stationEta);
128  histDigVars.NSWMM_dig_stationPhi.push_back(stationPhi);
129  histDigVars.NSWMM_dig_multiplet.push_back(multiplet);
130  histDigVars.NSWMM_dig_gas_gap.push_back(gas_gap);
131  histDigVars.NSWMM_dig_channel.push_back(channel);
132 
133  std::vector<double> localPosX;
134  std::vector<double> localPosY;
135  std::vector<double> globalPosX;
136  std::vector<double> globalPosY;
137  std::vector<double> globalPosZ;
138 
139  int nstrip = 0; //counter of the number of firing strips
140  for (const auto &i: stripPosition) {
141 
142  isValid = false; //reset
143  // take strip index form chip information
144  int cr_strip = i;
145  localPosX.push_back (0.);
146  localPosY.push_back (0.);
147  globalPosX.push_back(0.);
148  globalPosY.push_back(0.);
149  globalPosZ.push_back(0.);
150  ++nstrip;
151 
152  Identifier cr_id = m_MmIdHelper->channelID(stationName, stationEta, stationPhi, multiplet, gas_gap, cr_strip, isValid);
153  if (!isValid) {
154  ATH_MSG_WARNING("MicroMegas digitization: failed to create a valid ID for (chip response) strip n. " << cr_strip
155  << "; associated positions will be set to 0.0.");
156  } else {
157  // asking the detector element to get local position of strip
158  Amg::Vector2D cr_strip_pos(0., 0.);
159  if ( !rdoEl->stripPosition(cr_id,cr_strip_pos) ) {
160  ATH_MSG_WARNING("MicroMegas digitization: failed to associate a valid local position for (chip response) strip n. " << cr_strip
161  << "; associated positions will be set to 0.0.");
162  } else {
163  localPosX[nstrip-1] = cr_strip_pos.x();
164  localPosY[nstrip-1] = cr_strip_pos.y();
165  }
166 
167  // asking the detector element to transform this local to the global position
168  Amg::Vector3D cr_strip_gpos(0., 0., 0.);
169  rdoEl->surface(cr_id).localToGlobal(cr_strip_pos, Amg::Vector3D(0., 0., 0.), cr_strip_gpos);
170  globalPosX[nstrip-1] = cr_strip_gpos[0];
171  globalPosY[nstrip-1] = cr_strip_gpos[1];
172  globalPosZ[nstrip-1] = cr_strip_gpos[2];
173  }
174  }//end of strip position loop
175 
176  //NTUPLE FILL DIGITS
177  histDigVars.NSWMM_dig_time.push_back(time);
178  histDigVars.NSWMM_dig_charge.push_back(charge);
179  histDigVars.NSWMM_dig_stripPosition.push_back(stripPosition);
180  histDigVars.NSWMM_dig_stripLposX.push_back(localPosX);
181  histDigVars.NSWMM_dig_stripLposY.push_back(localPosY);
182  histDigVars.NSWMM_dig_stripGposX.push_back(globalPosX);
183  histDigVars.NSWMM_dig_stripGposY.push_back(globalPosY);
184  histDigVars.NSWMM_dig_stripGposZ.push_back(globalPosZ);
185  if(globalPosY.empty()) continue;
186 
187  if (!time.empty()) entries_tmp.push_back(
188  digitWrapper(digit, stName, -1.,
189  ROOT::Math::XYZVector(-999, -999, -999),
190  ROOT::Math::XYZVector(localPosX[0], localPosY[0], -999),
191  ROOT::Math::XYZVector(globalPosX[0], globalPosY[0], globalPosZ[0] )
192  ) );
193  } //end iterator digit loop
194 
195  if (!entries_tmp.empty()) {
196  std::vector<std::string> stNames;
197  for(const auto &dW : entries_tmp) stNames.push_back(dW.stName);
198  if(std::all_of(stNames.begin(), stNames.end(), [&] (const std::string & name) { return name == stNames[0]; })) {
199  entries[std::make_pair(event,digit_particles)]=entries_tmp;
200  digit_particles++;
201  } else {
202  ATH_MSG_WARNING("Digits belonging to different stations, skipping items");
203  }
204  stNames.clear();
205  }
206  } // end digit container loop
207 
208  for(unsigned int i=0; i<truthParticles.size(); i++) {
209  evInf_entry particle_info(event, pdg[i],
210  truthParticles[i].E(), truthParticles[i].Pt(),
211  truthParticles[i].Eta(), truthParticles_pos[i].Eta(), truthParticles_ent[i].Eta(),
212  truthParticles[i].Phi(), truthParticles_pos[i].Phi(), truthParticles_ent[i].Phi(),
213  truthParticles[i].Theta(), truthParticles_pos[i].Theta(), truthParticles_ent[i].Theta(), truthParticles_ent[i].Theta()-truthParticles_pos[i].Theta(),
214  TruthParticle_n,MuEntry_Particle_n,vertex[i]);
215  Event_Info[std::make_pair(event,i)] = particle_info;
216  }
217 
218  //Loop over entries, which has digitization info for each event
219  unsigned int ient=0;
220  for (auto it=entries.begin(); it!=entries.end(); it++){
221 
222  /* Identifying the wedge from digits:
223  * now the digit is associated with the corresponding station, so lambda function can be exploited to check if they are all the same
224  */
225  double tru_phi = -999, tru_theta = -999;
226  std::pair<int, unsigned int> pair (event,ient);
227  auto tru_it = Event_Info.find(pair);
228  if (tru_it != Event_Info.end()) {
229  tru_phi = tru_it->second.phi_pos;
230  tru_theta = tru_it->second.theta_pos;
231  }
232 
233  std::string station = it->second[0].stName;
234  std::vector<hitData_entry> hit_info;
235  hit_info.reserve(it->second.size());
236 
237  //Now we need to loop on digits
238  for (const auto &dW : it->second) {
239  Identifier tmpID = dW.id();
240  int thisMultiplet = m_MmIdHelper->multilayer( tmpID );
241  int thisGasGap = m_MmIdHelper->gasGap( tmpID );
242  int thisTime = dW.digit->stripResponseTime();
243  int thisCharge = 2; //dW.digit->stripChargeForTrigger().at(0);
244  int thisStripPosition = m_MmIdHelper->channel(tmpID);
245  double thisLocalPosX = dW.strip_lpos.X();
246  int thisVMM = m_MmIdHelper->channel( tmpID);
247  int thisMMFE_VMM = thisVMM;
248  int thisStationEta = m_MmIdHelper->stationEta( tmpID );
249  int thisStationPhi = m_MmIdHelper->stationPhi( tmpID );
250  int thisPlane = (thisMultiplet-1)*4+thisGasGap-1;
251  int BC_id = std::ceil( thisTime / 25. );
252  ROOT::Math::XYZVector mazin_check(
253  dW.strip_gpos.X(),
254  dW.strip_gpos.Y(),
255  dW.strip_gpos.Z()
256  );
257 
258  hitData_entry hit_entry(event,
259  thisTime,
260  thisCharge,
261  thisVMM,
262  thisMMFE_VMM,
263  thisPlane,
264  thisStripPosition,
265  thisStationEta,
266  thisStationPhi,
267  thisMultiplet,
268  thisGasGap,
269  thisLocalPosX,
270  tru_theta,
271  tru_phi,
272  true,
273  BC_id,
274  mazin_check,
275  mazin_check);
276 
277  hit_info.push_back(hit_entry);
278  ATH_MSG_DEBUG("Done filling hit_info structure");
279  }//end digit wrapper loop
280 
281  Hits_Data_Set_Time[std::make_pair(event,ient)] = hit_info;
282  ient++;
283  }
284  return StatusCode::SUCCESS;
285 }
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:158
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
histogramDigitVariables::NSWMM_dig_stripLposY
std::vector< std::vector< double > > NSWMM_dig_stripLposY
Definition: MMLoadVariables.h:42
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
histogramDigitVariables::NSWMM_dig_channel
std::vector< int > NSWMM_dig_channel
Definition: MMLoadVariables.h:36
AtlasHitsVector
Definition: AtlasHitsVector.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:396
histogramDigitVariables::NSWMM_dig_multiplet
std::vector< int > NSWMM_dig_multiplet
Definition: MMLoadVariables.h:34
histogramDigitVariables::NSWMM_dig_stripGposX
std::vector< std::vector< double > > NSWMM_dig_stripGposX
Definition: MMLoadVariables.h:43
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
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:800
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:225
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
histogramDigitVariables::NSWMM_dig_stripGposY
std::vector< std::vector< double > > NSWMM_dig_stripGposY
Definition: MMLoadVariables.h:44
histogramDigitVariables::NSWMM_dig_stationEta
std::vector< int > NSWMM_dig_stationEta
Definition: MMLoadVariables.h:32
MmIdHelper::multilayer
int multilayer(const Identifier &id) const
Definition: MmIdHelper.cxx:796
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
histogramDigitVariables::NSWMM_dig_stripPosition
std::vector< std::vector< int > > NSWMM_dig_stripPosition
Definition: MMLoadVariables.h:40
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:64
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
evInf_entry
Definition: MMT_struct.h:59
histogramDigitVariables::NSWMM_dig_stationName
std::vector< std::string > NSWMM_dig_stationName
Definition: MMLoadVariables.h:31
histogramDigitVariables::NSWMM_dig_stationPhi
std::vector< int > NSWMM_dig_stationPhi
Definition: MMLoadVariables.h:33
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:65
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:221
MagicNumbers.h
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
charge
double charge(const T &p)
Definition: AtlasPID.h:538
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
histogramDigitVariables::NSWMM_dig_gas_gap
std::vector< int > NSWMM_dig_gas_gap
Definition: MMLoadVariables.h:35
histogramDigitVariables
Definition: MMLoadVariables.h:30
histogramDigitVariables::NSWMM_dig_stripGposZ
std::vector< std::vector< double > > NSWMM_dig_stripGposZ
Definition: MMLoadVariables.h:45
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
histogramDigitVariables::NSWMM_dig_stripLposX
std::vector< std::vector< double > > NSWMM_dig_stripLposX
Definition: MMLoadVariables.h:41
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:69
histogramDigitVariables::NSWMM_dig_charge
std::vector< std::vector< float > > NSWMM_dig_charge
Definition: MMLoadVariables.h:39
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
histogramDigitVariables::NSWMM_dig_time
std::vector< std::vector< float > > NSWMM_dig_time
Definition: MMLoadVariables.h:38
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:156
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:345
MmIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
Definition: MmIdHelper.cxx:736
MMLoadVariables::getMMDigitsInfo
StatusCode getMMDigitsInfo(const EventContext &ctx, const McEventCollection *truthContainer, const TrackRecordCollection *trackRecordCollection, const MmDigitContainer *nsw_MmDigitContainer, std::map< std::pair< int, unsigned int >, std::vector< digitWrapper > > &entries, std::map< std::pair< int, unsigned int >, std::vector< hitData_entry > > &Hits_Data_Set_Time, std::map< std::pair< int, unsigned int >, evInf_entry > &Event_Info, histogramDigitVariables &histDigVars) const
Definition: MMLoadVariables.cxx:14
Eta
@ Eta
Definition: RPCdef.h:8
digitWrapper
Definition: MMT_struct.h:82
Identifier
Definition: IdentifierFieldParser.cxx:14