CMS 3D CMS Logo

CTPPSRecHitProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastSimulation/CTPPSRecHitProducer
4 // Class: CTPPSRecHitProducer
5 //
13 //
14 // Original Author: Dilson De Jesus Damiao
15 // Created: Mon, 19 Sep 2016 18:10:30 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
32 #include <cmath>
33 
34 #include <CLHEP/Random/RandGauss.h>
38 
43 #include <vector>
45 
49 
52 #include <iostream>
53 
54 #include <string>
55 
56 //Mixing Collection and CF info
59 #include "HepMC/GenEvent.h"
60 
61 //
62 // class declaration
63 //
64 class TRandom3;
65 class CTPPSToFDetector;
66 
68 public:
69  explicit CTPPSRecHitProducer(const edm::ParameterSet&);
70  ~CTPPSRecHitProducer() override;
71 
72 private:
73  void beginStream(edm::StreamID) override;
74  void produce(edm::Event&, const edm::EventSetup&) override;
75  void endStream() override;
76 
77  // ----------member data ---------------------------
78  typedef std::vector<PSimHit> PSimHitContainer;
79 
80  // std::string mix_;
81  // std::string collection_for_XF;
82 
84 
87  std::vector<double> fToFCellWidth;
91 };
92 
94  produces<edm::CTPPSFastRecHitContainer>("CTPPSFastRecHits");
95 
96  //Name of Collection use for create the XF
97  std::string mix_ = iConfig.getParameter<std::string>("mixLabel");
98  std::string collection_for_XF = iConfig.getParameter<std::string>("InputCollection");
99  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_for_XF));
100 
101  // Read the detector parameters
102  fTrackerWidth = iConfig.getParameter<double>("TrackerWidth");
103  fTrackerHeight = iConfig.getParameter<double>("TrackerHeight");
104  fTrackerInsertion = iConfig.getParameter<double>("TrackerInsertion");
105  fBeamXRMS_Trk1 = iConfig.getParameter<double>("BeamXRMS_Trk1");
106  fBeamXRMS_Trk2 = iConfig.getParameter<double>("BeamXRMS_Trk2");
107  fTrk1XOffset = iConfig.getParameter<double>("Trk1XOffset");
108  fTrk2XOffset = iConfig.getParameter<double>("Trk2XOffset");
109  fHitSigmaX = iConfig.getParameter<double>("HitSigmaX");
110  fHitSigmaY = iConfig.getParameter<double>("HitSigmaY");
111  fHitSigmaZ = iConfig.getParameter<double>("HitSigmaZ");
112  fToFCellWidth = iConfig.getUntrackedParameter<std::vector<double> >("ToFCellWidth");
113  fToFCellHeight = iConfig.getParameter<double>("ToFCellHeight");
114  fToFPitchX = iConfig.getParameter<double>("ToFPitchX");
115  fToFPitchY = iConfig.getParameter<double>("ToFPitchY");
116  fToFNCellX = iConfig.getParameter<int>("ToFNCellX");
117  fToFNCellY = iConfig.getParameter<int>("ToFNCellY");
118  fToFInsertion = iConfig.getParameter<double>("ToFInsertion");
119  fBeamXRMS_ToF = iConfig.getParameter<double>("BeamXRMS_ToF");
120  fToFXOffset = iConfig.getParameter<double>("ToFXOffset");
121  fTimeSigma = iConfig.getParameter<double>("TimeSigma");
122 
124  if (!rng.isAvailable()) {
125  throw cms::Exception("Configuration")
126  << "CTPPSRecHitProducer requires the RandomNumberGeneratorService\n"
127  "which is not present in the configuration file. You must add the service\n"
128  "in the configuration file or remove the modules that require it.";
129  }
130 }
131 
133 
135  using namespace edm;
136 
138  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
139  if (engine->name() != "TRandom3") {
140  throw cms::Exception("Configuration") << "The TRandom3 engine type must be used with CTPPSRecHitProducer, Random "
141  "Number Generator Service not correctly configured!";
142  }
143 
144  //Mix the PSimHits for pileup
146  iEvent.getByToken(cf_token, xFrame);
147 
148  std::unique_ptr<MixCollection<PSimHit> > simHits(new MixCollection<PSimHit>(xFrame.product()));
149 
150  std::vector<CTPPSFastRecHit> theCTPPSFastRecHit;
151 
152  for (MixCollection<PSimHit>::MixItr ihit = simHits->begin(); ihit != simHits->end(); ihit++)
153 
154  {
155  const PSimHit* simHit = &(*ihit);
156  unsigned int detlayerId = simHit->detUnitId();
157  // DetId layer codification for PSimHit
158  // 2014314496 -> Tracker1 zPositive
159  // 2014838784 -> Tracker2 zPositive
160  // 2046820352 -> Timing zPositive
161  // 2031091712 -> Tracker1 zNegative
162  // 2031616000 -> Tracker2 zNegative
163  // 2063597568 -> Timing zNegative
164  bool outside = false;
165 
166  //Make Tracker RecHits by smearing the SimHits positions and applying fiducial cuts
167  CTPPSFastRecHit rechit; // (const Local3DPoint& entry, unsigned int detId, float tof, unsigned int cellId)
168  if (detlayerId == 2014314496 || detlayerId == 2031091712) {
169  // Apply position smearing
170  float x_trk1 = simHit->entryPoint().x() + CLHEP::RandGauss::shoot(engine, 0, fHitSigmaX * um_to_mm);
171  float y_trk1 = simHit->entryPoint().y() + CLHEP::RandGauss::shoot(engine, 0, fHitSigmaY * um_to_mm);
172  float z_trk1 = simHit->entryPoint().z();
173 
174  // Apply fiducial cuts
175  double pos_trk1 = fTrackerInsertion * fBeamXRMS_Trk1 + fTrk1XOffset;
176  if (x_trk1 > 0 || fabs(x_trk1) < pos_trk1 || fabs(x_trk1) > (fTrackerWidth + pos_trk1) ||
177  fabs(y_trk1) > fTrackerHeight / 2.)
178  outside = true;
179 
180  float tof = 0.0;
181  unsigned int cellId = 1;
182  Local3DPoint xyzzy = Local3DPoint(x_trk1, y_trk1, z_trk1);
183  if (!outside) {
184  rechit.setLocal3DPoint(xyzzy);
185  rechit.setTof(tof);
186  rechit.setDetUnitId(detlayerId);
187  rechit.setCellId(cellId);
188  theCTPPSFastRecHit.push_back(rechit);
189  }
190  }
191  if (detlayerId == 2014838784 || detlayerId == 2031616000) {
192  // Apply position smearing
193  double x_trk2 = simHit->entryPoint().x() + CLHEP::RandGauss::shoot(engine, 0, fHitSigmaX * um_to_mm);
194  double y_trk2 = simHit->entryPoint().y() + CLHEP::RandGauss::shoot(engine, 0, fHitSigmaY * um_to_mm);
195  double z_trk2 = simHit->entryPoint().z();
196  // Apply fiducial cuts
197  double pos_trk2 = fTrackerInsertion * fBeamXRMS_Trk2 + fTrk2XOffset;
198  if (x_trk2 > 0 || fabs(x_trk2) < pos_trk2 || fabs(x_trk2) > (fTrackerWidth + pos_trk2) ||
199  fabs(y_trk2) > fTrackerHeight / 2.)
200  outside = true;
201 
202  float tof = 0.0;
203  unsigned int cellId = 2;
204  Local3DPoint xyzzy = Local3DPoint(x_trk2, y_trk2, z_trk2);
205  if (!outside) {
206  rechit.setLocal3DPoint(xyzzy);
207  rechit.setTof(tof);
208  rechit.setDetUnitId(detlayerId);
209  rechit.setCellId(cellId);
210  theCTPPSFastRecHit.push_back(rechit);
211  }
212  }
213  //Make Timing RecHits by smearing the SimHits time of flight and checking the cell of the hit
214  //The RecHit position is the centre of the cell
215  if (detlayerId == 2046820352 || detlayerId == 2063597568) {
216  float t = simHit->tof();
217  unsigned int cellId = 0;
218  float tof = CLHEP::RandGauss::shoot(engine, t, fTimeSigma);
219  double x_tof = simHit->entryPoint().x();
220  double y_tof = simHit->entryPoint().y();
221 
222  double pos_tof = fToFInsertion * fBeamXRMS_ToF + fToFXOffset;
223 
224  std::vector<double> vToFCellWidth;
225  vToFCellWidth.reserve(8);
226  for (int i = 0; i < 8; i++) {
227  vToFCellWidth.push_back(fToFCellWidth[i]);
228  }
229  CTPPSToFDetector* ToFDet = new CTPPSToFDetector(
230  fToFNCellX, fToFNCellY, vToFCellWidth, fToFCellHeight, fToFPitchX, fToFPitchY, pos_tof, fTimeSigma);
231  cellId = ToFDet->findCellId(x_tof, y_tof);
232  if (cellId > 0) {
233  double xc_tof = 0., yc_tof = 0.;
234  ToFDet->get_CellCenter(cellId, xc_tof, yc_tof);
235  Local3DPoint xyzzy = Local3DPoint(xc_tof, yc_tof, simHit->entryPoint().z());
236  rechit.setLocal3DPoint(xyzzy);
237  rechit.setTof(tof);
238  rechit.setDetUnitId(detlayerId);
239  rechit.setCellId(cellId);
240  theCTPPSFastRecHit.push_back(rechit);
241  }
242  }
243  }
244 
245  std::unique_ptr<CTPPSFastRecHitContainer> output_recHits(new edm::CTPPSFastRecHitContainer);
246  output_recHits->reserve(simHits->size());
247 
248  int n = 0;
249  for (std::vector<CTPPSFastRecHit>::const_iterator i = theCTPPSFastRecHit.begin(); i != theCTPPSFastRecHit.end();
250  i++) {
251  output_recHits->push_back(*i);
252  n += 1;
253  }
254 
255  iEvent.put(std::move(output_recHits), "CTPPSFastRecHits");
256 }
257 
258 // ------------ method called once each stream before processing any runs, lumis or events ------------
260 
261 // ------------ method called once each stream after processing all runs, lumis and events ------------
263 
264 //define this as a plug-in
bool get_CellCenter(int cell_id, double &x, double &y)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
int findCellId(double x, double y)
std::vector< PSimHit > PSimHitContainer
std::vector< CTPPSFastRecHit > CTPPSFastRecHitContainer
T const * product() const
Definition: Handle.h:70
void setTof(float tof)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void produce(edm::Event &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void setCellId(unsigned int cellId)
CTPPSRecHitProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setDetUnitId(unsigned int detId)
static const double um_to_mm
void beginStream(edm::StreamID) override
std::vector< double > fToFCellWidth
HLT enums.
void setLocal3DPoint(const Local3DPoint &entry)
def move(src, dest)
Definition: eostools.py:511
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9