CMS 3D CMS Logo

DBremWatcher.cc
Go to the documentation of this file.
1 #include "DBremWatcher.h"
2 
12 #include "G4Region.hh"
13 #include "G4RegionStore.hh"
14 #include "G4LogicalVolumeStore.hh"
15 #include "G4ProductionCuts.hh"
16 #include "G4ProcessTable.hh"
17 #include "G4ProcessManager.hh"
18 #include "G4MuonMinus.hh"
20 #include "G4Track.hh"
21 #include "G4PhysicalConstants.hh"
22 #include "G4SystemOfUnits.hh"
23 #include "G4VProcess.hh"
24 #include "G4VParticleChange.hh"
26 #include <algorithm>
27 
29  edm::ParameterSet ps = p.getParameter<edm::ParameterSet>("DBremWatcher");
30  biasFactor = ps.getUntrackedParameter<double>("DBremBiasFactor", 1);
31  m_weight = 0;
32  foundbrem = false;
33  finaltraj = G4ThreeVector(0, 0, 0);
34  aPrimeTraj = G4ThreeVector(0, 0, 0);
35  VertexPos = G4ThreeVector(0, 0, 0);
36  f_energy = 0;
37  produces<float>("DBremEventWeight");
38  produces<float>("DBremLocationX");
39  produces<float>("DBremLocationY");
40  produces<float>("DBremLocationZ");
41  //produces<std::string>("DBremMaterial");
42  produces<float>("DBremAngle");
43  produces<float>("DBremInitialEnergy");
44  produces<float>("DBremFinalEnergy");
45  produces<float>("BiasFactor");
46  pdgs_ = ps.getUntrackedParameter<std::vector<int>>("PDGCodes");
47  edm::LogInfo("DBremWatcher") << "DBremWatcher:: Save Sim Track if PDG code "
48  << "is one from the list of " << pdgs_.size() << " items";
49  for (unsigned int k = 0; k < pdgs_.size(); ++k)
50  edm::LogInfo("DBremWatcher") << "[" << k << "] " << pdgs_[k];
51 }
52 
54 
56  G4Track* theTrack = (G4Track*)((*trk)());
57  TrackInformation* trkInfo = (TrackInformation*)(theTrack->GetUserInformation());
58  if (trkInfo) {
59  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
60  G4ThreeVector Vpos = theTrack->GetVertexPosition();
61  const G4VProcess* TrPro = theTrack->GetCreatorProcess();
62  if (TrPro != nullptr) {
63  if ((theTrack->GetCreatorProcess()->GetProcessName()) == "muDBrem") {
64  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) == pdgs_.end()) {
65  //Found the deflected muon track
66  trkInfo->storeTrack(true);
67  if (!theTrack->IsGoodForTracking()) {
68  theTrack->SetGoodForTrackingFlag(true);
69  }
70  f_energy = theTrack->GetTotalEnergy();
71  foundbrem = true;
72  finaltraj = theTrack->GetMomentum();
73  } else {
74  m_weight = theTrack->GetWeight();
75  }
76  }
77  }
78  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) != pdgs_.end()) {
79  //Found an A'
80  trkInfo->storeTrack(true);
81  VertexPos = Vpos;
82  aPrimeTraj = theTrack->GetMomentum();
83  LogDebug("DBremWatcher") << "Save SimTrack the Track " << theTrack->GetTrackID() << " Type "
84  << theTrack->GetDefinition()->GetParticleName() << " Momentum "
85  << theTrack->GetMomentum() / MeV << " MeV/c";
86  }
87  }
88 }
89 
91 
93  G4String pname = "muDBrem";
94  G4ProcessTable* ptable = G4ProcessTable::GetProcessTable();
95  G4bool state = true;
96  ptable->SetProcessActivation(pname, state);
97  foundbrem = false;
98 }
99 
101 
103  G4Track* theTrack = (G4Track*)((*trk)());
104  TrackInformation* trkInfo = (TrackInformation*)(theTrack->GetUserInformation());
105  const G4VProcess* TrPro = theTrack->GetCreatorProcess();
106  if (trkInfo && TrPro != nullptr) {
107  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
108 
109  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) == pdgs_.end() &&
110  (theTrack->GetCreatorProcess()->GetProcessName()) == "muDBrem") {
111  trkInfo->storeTrack(true);
112  }
113  }
114 }
115 
117  if (foundbrem) {
118  std::unique_ptr<float> weight = std::make_unique<float>(m_weight);
119  fEvent.put(std::move(weight), "DBremEventWeight");
120  std::unique_ptr<float> vtxposx = std::make_unique<float>(VertexPos.x());
121  std::unique_ptr<float> vtxposy = std::make_unique<float>(VertexPos.y());
122  std::unique_ptr<float> vtxposz = std::make_unique<float>(VertexPos.z());
123  fEvent.put(std::move(vtxposx), "DBremLocationX");
124  fEvent.put(std::move(vtxposy), "DBremLocationY");
125  fEvent.put(std::move(vtxposz), "DBremLocationZ");
126  std::unique_ptr<float> finalE = std::make_unique<float>(f_energy / GeV);
127  fEvent.put(std::move(finalE), "DBremFinalEnergy");
128  float deflectionAngle = -1;
129  float initialEnergy = sqrt(pow(finaltraj.x() + aPrimeTraj.x(), 2) + pow(finaltraj.y() + aPrimeTraj.y(), 2) +
130  pow(finaltraj.z() + aPrimeTraj.z(), 2) + pow(0.1056 * GeV, 2));
131  G4ThreeVector mother(
132  finaltraj.x() + aPrimeTraj.x(), finaltraj.y() + aPrimeTraj.y(), finaltraj.z() + aPrimeTraj.z());
133  deflectionAngle = mother.angle(finaltraj);
134  std::unique_ptr<float> dAngle = std::make_unique<float>(deflectionAngle);
135  std::unique_ptr<float> initialE = std::make_unique<float>(initialEnergy / GeV);
136  fEvent.put(std::move(dAngle), "DBremAngle");
137  fEvent.put(std::move(initialE), "DBremInitialEnergy");
138  std::unique_ptr<float> bias = std::make_unique<float>(biasFactor);
139  fEvent.put(std::move(bias), "BiasFactor");
140  } else {
141  std::unique_ptr<float> weight = std::make_unique<float>(0.);
142  fEvent.put(std::move(weight), "DBremEventWeight");
143  }
144 }
145 
147 
bool storeTrack() const
#define DEFINE_SIMWATCHER(type)
double biasFactor
Definition: DBremWatcher.h:37
DBremWatcher(edm::ParameterSet const &p)
Definition: DBremWatcher.cc:28
void produce(edm::Event &, const edm::EventSetup &) override
G4ThreeVector aPrimeTraj
Definition: DBremWatcher.h:39
Definition: weight.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
T getUntrackedParameter(std::string const &, T const &) const
G4ThreeVector VertexPos
Definition: DBremWatcher.h:41
float m_weight
Definition: DBremWatcher.h:36
T sqrt(T t)
Definition: SSEVec.h:19
G4ThreeVector finaltraj
Definition: DBremWatcher.h:40
Log< level::Info, false > LogInfo
Class providing the Dark Bremsstrahlung process class.
void update(const BeginOfTrack *trk) override
This routine will be called when the appropriate signal arrives.
Definition: DBremWatcher.cc:55
float f_energy
Definition: DBremWatcher.h:42
std::vector< int > pdgs_
Definition: DBremWatcher.h:34
~DBremWatcher() override
Definition: DBremWatcher.cc:53
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
#define LogDebug(id)