CMS 3D CMS Logo

DBremWatcher.cc
Go to the documentation of this file.
3 
11 
13 
18 
19 #include "G4Region.hh"
20 #include "G4RegionStore.hh"
21 #include "G4LogicalVolumeStore.hh"
22 #include "G4ProcessTable.hh"
23 #include "G4MuonMinus.hh"
24 #include "G4Track.hh"
25 #include "G4PhysicalConstants.hh"
26 #include "G4SystemOfUnits.hh"
27 #include "G4VProcess.hh"
28 
29 #include "G4ThreeVector.hh"
30 #include <vector>
31 
32 class DBremWatcher : public SimProducer,
33  public Observer<const BeginOfTrack*>,
34  public Observer<const BeginOfEvent*>,
35  public Observer<const BeginOfRun*>,
36  public Observer<const EndOfEvent*>,
37  public Observer<const EndOfTrack*> {
38 public:
40  ~DBremWatcher() override = default;
41  void update(const BeginOfTrack* trk) override;
42  void update(const BeginOfEvent* event) override;
43  void update(const EndOfEvent* event) override;
44  void update(const BeginOfRun* run) override;
45  void update(const EndOfTrack* trk) override;
46  void produce(edm::Event&, const edm::EventSetup&) override;
47 
48 private:
49  std::vector<int> pdgs_;
50  int MotherId;
51  float m_weight;
52  double biasFactor;
53  bool foundbrem;
54  G4ThreeVector aPrimeTraj;
55  G4ThreeVector finaltraj;
56  G4ThreeVector VertexPos;
57  double f_energy;
58 };
59 
61  edm::ParameterSet ps = p.getParameter<edm::ParameterSet>("DBremWatcher");
62  biasFactor = ps.getUntrackedParameter<double>("DBremBiasFactor", 1);
63  m_weight = 0;
64  foundbrem = false;
65  finaltraj = G4ThreeVector(0, 0, 0);
66  aPrimeTraj = G4ThreeVector(0, 0, 0);
67  VertexPos = G4ThreeVector(0, 0, 0);
68  f_energy = 0;
69  produces<float>("DBremEventWeight");
70  produces<float>("DBremLocationX");
71  produces<float>("DBremLocationY");
72  produces<float>("DBremLocationZ");
73  produces<float>("DBremAngle");
74  produces<float>("DBremInitialEnergy");
75  produces<float>("DBremFinalEnergy");
76  produces<float>("BiasFactor");
77  pdgs_ = ps.getUntrackedParameter<std::vector<int>>("PDGCodes");
78  edm::LogVerbatim("DBremWatcher") << "DBremWatcher:: Save Sim Track if PDG code "
79  << "is one from the list of " << pdgs_.size() << " items";
80  for (unsigned int k = 0; k < pdgs_.size(); ++k)
81  edm::LogVerbatim("DBremWatcher") << "[" << k << "] " << pdgs_[k];
82 }
83 
85  G4Track* theTrack = (G4Track*)((*trk)());
86  TrackInformation* trkInfo = (TrackInformation*)(theTrack->GetUserInformation());
87  if (trkInfo) {
88  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
89  G4ThreeVector Vpos = theTrack->GetVertexPosition();
90  const G4VProcess* TrPro = theTrack->GetCreatorProcess();
91  if (TrPro != nullptr) {
92  if ((theTrack->GetCreatorProcess()->GetProcessName()) == "muDBrem") {
93  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) == pdgs_.end()) {
94  //Found the deflected muon track
95  trkInfo->storeTrack();
96  if (!theTrack->IsGoodForTracking()) {
97  theTrack->SetGoodForTrackingFlag(true);
98  }
99  f_energy = theTrack->GetTotalEnergy();
100  foundbrem = true;
101  finaltraj = theTrack->GetMomentum();
102  } else {
103  m_weight = theTrack->GetWeight();
104  }
105  }
106  }
107  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) != pdgs_.end()) {
108  //Found an A'
109  trkInfo->setStoreTrack();
110  VertexPos = Vpos;
111  aPrimeTraj = theTrack->GetMomentum();
112  LogDebug("DBremWatcher") << "Save SimTrack the Track " << theTrack->GetTrackID() << " Type "
113  << theTrack->GetDefinition()->GetParticleName() << " Momentum "
114  << theTrack->GetMomentum() / MeV << " MeV/c";
115  }
116  }
117 }
118 
120 
122  G4String pname = "muDBrem";
123  G4ProcessTable* ptable = G4ProcessTable::GetProcessTable();
124  G4bool state = true;
125  ptable->SetProcessActivation(pname, state);
126  foundbrem = false;
127 }
128 
130 
132  G4Track* theTrack = (G4Track*)((*trk)());
133  TrackInformation* trkInfo = (TrackInformation*)(theTrack->GetUserInformation());
134  const G4VProcess* TrPro = theTrack->GetCreatorProcess();
135  if (trkInfo && TrPro != nullptr) {
136  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
137 
138  if (std::find(pdgs_.begin(), pdgs_.end(), pdg) == pdgs_.end() &&
139  (theTrack->GetCreatorProcess()->GetProcessName()) == "muDBrem") {
140  trkInfo->setStoreTrack();
141  }
142  }
143 }
144 
146  if (foundbrem) {
147  std::unique_ptr<float> weight = std::make_unique<float>(m_weight);
148  fEvent.put(std::move(weight), "DBremEventWeight");
149  std::unique_ptr<float> vtxposx = std::make_unique<float>(VertexPos.x());
150  std::unique_ptr<float> vtxposy = std::make_unique<float>(VertexPos.y());
151  std::unique_ptr<float> vtxposz = std::make_unique<float>(VertexPos.z());
152  fEvent.put(std::move(vtxposx), "DBremLocationX");
153  fEvent.put(std::move(vtxposy), "DBremLocationY");
154  fEvent.put(std::move(vtxposz), "DBremLocationZ");
155  std::unique_ptr<float> finalE = std::make_unique<float>(f_energy / GeV);
156  fEvent.put(std::move(finalE), "DBremFinalEnergy");
157  float deflectionAngle = -1;
158  float initialEnergy = sqrt(pow(finaltraj.x() + aPrimeTraj.x(), 2) + pow(finaltraj.y() + aPrimeTraj.y(), 2) +
159  pow(finaltraj.z() + aPrimeTraj.z(), 2) + pow(0.1056 * CLHEP::GeV, 2));
160  G4ThreeVector mother(
161  finaltraj.x() + aPrimeTraj.x(), finaltraj.y() + aPrimeTraj.y(), finaltraj.z() + aPrimeTraj.z());
162  deflectionAngle = mother.angle(finaltraj);
163  std::unique_ptr<float> dAngle = std::make_unique<float>(deflectionAngle);
164  std::unique_ptr<float> initialE = std::make_unique<float>(initialEnergy / CLHEP::GeV);
165  fEvent.put(std::move(dAngle), "DBremAngle");
166  fEvent.put(std::move(initialE), "DBremInitialEnergy");
167  std::unique_ptr<float> bias = std::make_unique<float>(biasFactor);
168  fEvent.put(std::move(bias), "BiasFactor");
169  } else {
170  std::unique_ptr<float> weight = std::make_unique<float>(0.);
171  fEvent.put(std::move(weight), "DBremEventWeight");
172  }
173 }
174 
bool storeTrack() const
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
void setStoreTrack()
can only be set to true, cannot be reset to false!
double biasFactor
Definition: DBremWatcher.cc:52
double f_energy
Definition: DBremWatcher.cc:57
DBremWatcher(edm::ParameterSet const &p)
Definition: DBremWatcher.cc:60
void produce(edm::Event &, const edm::EventSetup &) override
G4ThreeVector aPrimeTraj
Definition: DBremWatcher.cc:54
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.cc:56
T sqrt(T t)
Definition: SSEVec.h:19
G4ThreeVector finaltraj
Definition: DBremWatcher.cc:55
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:84
~DBremWatcher() override=default
std::vector< int > pdgs_
Definition: DBremWatcher.cc:49
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)