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