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
edm::StreamID
Definition: StreamID.h:30
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
mps_fire.i
i
Definition: mps_fire.py:428
CTPPSRecHitProducer::fTrk2XOffset
double fTrk2XOffset
Definition: CTPPSRecHitProducer.cc:85
CTPPSRecHitProducer::beginStream
void beginStream(edm::StreamID) override
Definition: CTPPSRecHitProducer.cc:259
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
CTPPSRecHitProducer::fTrackerInsertion
double fTrackerInsertion
Definition: CTPPSRecHitProducer.cc:85
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
CrossingFrame.h
CTPPSRecHitProducer::fToFPitchX
double fToFPitchX
Definition: CTPPSRecHitProducer.cc:88
PSimHitContainer.h
CTPPSRecHitProducer::fTrackerWidth
double fTrackerWidth
Definition: CTPPSRecHitProducer.cc:85
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
EDProducer.h
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
PPSUnitConversion.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CTPPSRecHitProducer::fBeamXRMS_Trk1
double fBeamXRMS_Trk1
Definition: CTPPSRecHitProducer.cc:85
um_to_mm
static const double um_to_mm
Definition: PPSUnitConversion.h:11
edm::Handle
Definition: AssociativeIterator.h:50
CTPPSRecHitProducer::fToFCellWidth
std::vector< double > fToFCellWidth
Definition: CTPPSRecHitProducer.cc:87
CTPPSToFDetector
Definition: CTPPSToFDetector.h:8
MixCollection::MixItr
Definition: MixCollection.h:62
CTPPSRecHitProducer::fTimeSigma
double fTimeSigma
Definition: CTPPSRecHitProducer.cc:90
CTPPSRecHitProducer::endStream
void endStream() override
Definition: CTPPSRecHitProducer.cc:262
CTPPSRecHitProducer::fHitSigmaZ
double fHitSigmaZ
Definition: CTPPSRecHitProducer.cc:86
CTPPSFastRecHitContainer.h
CTPPSRecHitProducer::fTrackerHeight
double fTrackerHeight
Definition: CTPPSRecHitProducer.cc:85
MakerMacros.h
CTPPSRecHitProducer::fTrk1XOffset
double fTrk1XOffset
Definition: CTPPSRecHitProducer.cc:85
PSimHit.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CTPPSFastRecHit::setTof
void setTof(float tof)
Definition: CTPPSFastRecHit.h:42
MixCollection.h
MixCollection
Definition: MixCollection.h:11
Service.h
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
CTPPSRecHitProducer::fHitSigmaX
double fHitSigmaX
Definition: CTPPSRecHitProducer.cc:86
CTPPSRecHitProducer::fToFCellHeight
double fToFCellHeight
Definition: CTPPSRecHitProducer.cc:88
Point3DBase< float, LocalTag >
EDGetToken.h
CTPPSRecHitProducer::fHitSigmaY
double fHitSigmaY
Definition: CTPPSRecHitProducer.cc:86
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSFastRecHit::setLocal3DPoint
void setLocal3DPoint(const Local3DPoint &entry)
Definition: CTPPSFastRecHit.h:44
CTPPSFastRecHit::setCellId
void setCellId(unsigned int cellId)
Definition: CTPPSFastRecHit.h:48
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CTPPSRecHitProducer::fBeamXRMS_Trk2
double fBeamXRMS_Trk2
Definition: CTPPSRecHitProducer.cc:85
CTPPSToFDetector::get_CellCenter
bool get_CellCenter(int cell_id, double &x, double &y)
Definition: CTPPSToFDetector.cc:107
CTPPSRecHitProducer::~CTPPSRecHitProducer
~CTPPSRecHitProducer() override
Definition: CTPPSRecHitProducer.cc:132
CTPPSRecHitProducer::cf_token
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
Definition: CTPPSRecHitProducer.cc:83
CTPPSRecHitProducer::fBeamXRMS_ToF
double fBeamXRMS_ToF
Definition: CTPPSRecHitProducer.cc:90
edm::Service< edm::RandomNumberGenerator >
iEvent
int iEvent
Definition: GenABIO.cc:224
CTPPSFastRecHit::setDetUnitId
void setDetUnitId(unsigned int detId)
Definition: CTPPSFastRecHit.h:46
edm::stream::EDProducer
Definition: EDProducer.h:38
CTPPSRecHitProducer::fToFPitchY
double fToFPitchY
Definition: CTPPSRecHitProducer.cc:88
edm::EventSetup
Definition: EventSetup.h:57
CTPPSToFDetector::findCellId
int findCellId(double x, double y)
Definition: CTPPSToFDetector.cc:83
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
CTPPSRecHitProducer::fToFXOffset
double fToFXOffset
Definition: CTPPSRecHitProducer.cc:90
LocalPoint.h
CTPPSToFDetector.h
CTPPSRecHitProducer::fToFInsertion
double fToFInsertion
Definition: CTPPSRecHitProducer.cc:90
Exception
Definition: hltDiff.cc:246
CTPPSRecHitProducer::fToFNCellY
int fToFNCellY
Definition: CTPPSRecHitProducer.cc:89
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CTPPSRecHitProducer::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: CTPPSRecHitProducer.cc:78
Exception.h
CTPPSRecHitProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CTPPSRecHitProducer.cc:134
ConsumesCollector.h
ParameterSet.h
PSimHit
Definition: PSimHit.h:15
edm::Event
Definition: Event.h:73
LocalVector.h
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
CTPPSFastRecHit
Definition: CTPPSFastRecHit.h:9
StreamID.h
CTPPSRecHitProducer::fToFNCellX
int fToFNCellX
Definition: CTPPSRecHitProducer.cc:89
CTPPSRecHitProducer::CTPPSRecHitProducer
CTPPSRecHitProducer(const edm::ParameterSet &)
Definition: CTPPSRecHitProducer.cc:93
edm::CTPPSFastRecHitContainer
std::vector< CTPPSFastRecHit > CTPPSFastRecHitContainer
Definition: CTPPSFastRecHitContainer.h:13
Local3DPoint
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
CTPPSRecHitProducer
Definition: CTPPSRecHitProducer.cc:67