CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ME0ReDigiProducer.cc
Go to the documentation of this file.
8 
14 #include "CLHEP/Random/RandGaussQ.h"
15 #include "CLHEP/Random/RandFlat.h"
16 #include <sstream>
17 #include <string>
18 #include <map>
19 #include <vector>
20 
21 
23 {
24  produces<ME0DigiPreRecoCollection>();
25 
27  if (!rng.isAvailable()){
28  throw cms::Exception("Configuration")
29  << "ME0ReDigiProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
30  << "Add the service in the configuration file or remove the modules that require it.";
31  }
32  std::string collection_(ps.getParameter<std::string>("inputCollection"));
33 
34  token_ = consumes<ME0DigiPreRecoCollection>(edm::InputTag(collection_));
35  timeResolution_ = ps.getParameter<double>("timeResolution");
36  minBunch_ = ps.getParameter<int>("minBunch");
37  maxBunch_ = ps.getParameter<int>("maxBunch");
38  smearTiming_ = ps.getParameter<bool>("smearTiming");
39  discretizeTiming_ = ps.getParameter<bool>("discretizeTiming");
40  radialResolution_ = ps.getParameter<double>("radialResolution");
41  smearRadial_ = ps.getParameter<bool>("smearRadial");
42  oldXResolution_ = ps.getParameter<double>("oldXResolution");
43  oldYResolution_ = ps.getParameter<double>("oldYResolution");
44  newXResolution_ = ps.getParameter<double>("newXResolution");
45  newYResolution_ = ps.getParameter<double>("newYResolution");
46  discretizeX_ = ps.getParameter<bool>("discretizeX");
47  discretizeY_ = ps.getParameter<bool>("discretizeY");
48  reDigitizeOnlyMuons_ = ps.getParameter<bool>("reDigitizeOnlyMuons");
49  reDigitizeNeutronBkg_ = ps.getParameter<bool>("reDigitizeNeutronBkg");
50  rateFact_ = ps.getParameter<double>("rateFact");
51  instLumiDefault_ = ps.getParameter<double>("instLumiDefault");
52  instLumi_ = ps.getParameter<double>("instLumi");
53 }
54 
55 
57 {
58 }
59 
60 
61 void ME0ReDigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup)
62 {
63  // set geometry
65  eventSetup.get<MuonGeometryRecord>().get(hGeom);
66  geometry_= &*hGeom;
67 
68  LogDebug("ME0ReDigiProducer")
69  << "Extracting central TOFs:" << std::endl;
70  // get the central TOFs for the eta partitions
71  for(auto &roll: geometry_->etaPartitions()){
72  const ME0DetId detId(roll->id());
73  if (detId.chamber() != 1 or detId.region() != 1) continue;
74  const LocalPoint centralLP(0., 0., 0.);
75  const GlobalPoint centralGP(roll->toGlobal(centralLP));
76  const float centralTOF(centralGP.mag() / 29.98); //speed of light
77  centralTOF_.push_back(centralTOF);
78  LogDebug("ME0ReDigiProducer")
79  << "ME0DetId " << detId << " central TOF " << centralTOF << std::endl;
80  }
81  nPartitions_ = centralTOF_.size()/6;
82  LogDebug("ME0ReDigiProducer")<<" Number of partitions "<<nPartitions_<<std::endl;
83 }
84 
85 
87 {
89  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
90 
92  e.getByToken(token_, input_digis);
93 
94  std::unique_ptr<ME0DigiPreRecoCollection> output_digis(new ME0DigiPreRecoCollection());
95 
96  // build the clusters
97  buildDigis(*(input_digis.product()), *output_digis, engine);
98 
99  // store them in the event
100  e.put(std::move(output_digis));
101 }
102 
103 
105  ME0DigiPreRecoCollection & output_digis,
106  CLHEP::HepRandomEngine* engine)
107 {
108  /*
109  Starting form the incoming pseudo-digi, which has sigma_x=300um, sigma_t=sigma_R=0, do the following
110  1A. Smear time using sigma_t by 7 ns (native resolution of GEM)
111  1B. Correct the smeared time with the central arrival time for partition
112  1C. Apply discretization: if the smeared time is outside the BX window (-12.5ns;+12.5ns),
113  the hit should be assigned to the next (or previous) BX
114 
115  2A. Apply smearing in the radial direction (not in local Y!) sigma_R of 100 um
116  2B. Apply discretization in radial direction to see which eta partition it belongs to.
117  Assign the hit to have Y-position equal to the middle of the partition.
118 
119  3A. Apply smearing in x-direction (not required if we stick with sigma=300 um, which is what
120  is used in pseudo-digis) to obtain desired x-resolution sigma_x_desired:
121  - use gaussian smear with sigma_eff=sqrt(sigma_desired^2-300^2)
122  */
123 
124  for(auto &roll: geometry_->etaPartitions()){
125  const ME0DetId detId(roll->id());
126  //const uint32_t rawId(detId.rawId());
127  auto digis = input_digis.get(detId);
128  for (auto d = digis.first; d != digis.second; ++d) {
129  const ME0DigiPreReco me0Digi = *d;
130  edm::LogVerbatim("ME0ReDigiProducer")
131  << "Check detId " << detId << " digi " << me0Digi << std::endl;
132 
133  // selection
134  if (reDigitizeOnlyMuons_ and std::abs(me0Digi.pdgid()) != 13) continue;
135  if (!reDigitizeNeutronBkg_ and !me0Digi.prompt()) continue;
136 
137  // scale background hits for luminosity
138  if (!me0Digi.prompt())
139  if (CLHEP::RandFlat::shoot(engine) > instLumi_*1.0/(instLumiDefault_*rateFact_)) continue;
140 
141  edm::LogVerbatim("ME0ReDigiProducer")
142  << "\tPassed selection" << std::endl;
143 
144  // time resolution
145  float newTof(me0Digi.tof());
146  if (me0Digi.prompt() and smearTiming_) newTof += CLHEP::RandGaussQ::shoot(engine, 0, timeResolution_);
147 
148  // arrival time in ns
149  //const float t0(centralTOF_[ nPartitions_ * (detId.layer() -1) + detId.roll() - 1 ]);
150  int index = nPartitions_ * (detId.layer() -1) + detId.roll() - 1;
151  edm::LogVerbatim("ME0ReDigiProducer")
152  <<"size "<<centralTOF_.size()<<" nPartitions "<<nPartitions_<<" layer "<<detId.layer()<<" roll "<<detId.roll()<<" index "<<index<<std::endl;
153 
154  const float t0(centralTOF_[ index ]);
155  const float correctedNewTof(newTof - t0);
156 
157  edm::LogVerbatim("ME0ReDigiProducer")
158  <<" t0 "<< t0 << " originalTOF " << me0Digi.tof() << "\tnew TOF " << newTof << " corrected new TOF " << correctedNewTof << std::endl;
159 
160  // calculate the new time in ns
161  float newTime = correctedNewTof;
162  if (discretizeTiming_){
163  for (int iBunch = minBunch_ - 2; iBunch <= maxBunch_ + 2; ++iBunch){
164  if (-12.5 + iBunch*25 < newTime and newTime <= 12.5 + iBunch*25){
165  newTime = iBunch * 25;
166  break;
167  }
168  }
169  }
170 
171  edm::LogVerbatim("ME0ReDigiProducer")
172  << "\tBX " << newTime << std::endl;
173 
174  // calculate the position in global coordinates
175  const LocalPoint oldLP(me0Digi.x(), me0Digi.y(), 0);
176  const GlobalPoint oldGP(roll->toGlobal(oldLP));
177  const GlobalPoint centralGP(roll->toGlobal(LocalPoint(0.,0.,0.)));
178  const std::vector<float> parameters(roll->specs()->parameters());
179  const float height(parameters[2]); // G4 uses half-dimensions!
180 
181  // smear the new radial with gaussian
182  const float oldR(oldGP.perp());
183 
184  float newR = oldR;
185  if (me0Digi.prompt() and smearRadial_ and nPartitions_ > 1)
186  newR = CLHEP::RandGaussQ::shoot(engine, oldR, radialResolution_);
187 
188  // calculate the new position in local coordinates
189  const GlobalPoint radialSmearedGP(GlobalPoint::Cylindrical(newR, oldGP.phi(), oldGP.z()));
190  LocalPoint radialSmearedLP = roll->toLocal(radialSmearedGP);
191 
192  // new y position after smearing
193  const float targetYResolution(sqrt(newYResolution_*newYResolution_ - oldYResolution_ * oldYResolution_));
194  float newLPy = radialSmearedLP.y();
195  if (me0Digi.prompt())
196  newLPy = CLHEP::RandGaussQ::shoot(engine, radialSmearedLP.y(), targetYResolution);
197 
198  const ME0EtaPartition* newPart = roll;
199  LocalPoint newLP(radialSmearedLP.x(), newLPy, radialSmearedLP.z());
200  GlobalPoint newGP(newPart->toGlobal(newLP));
201 
202  // check if digi moves one up or down roll
203  int newRoll = detId.roll();
204  if (newLP.y() > height) --newRoll;
205  if (newLP.y() < -height) ++newRoll;
206 
207  if (newRoll != detId.roll()){
208  // check if new roll is possible
209  if (newRoll < ME0DetId::minRollId || newRoll > ME0DetId::maxRollId){
210  newRoll = detId.roll();
211  }
212  else {
213  // roll changed, get new ME0EtaPartition
214  newPart = geometry_->etaPartition(ME0DetId(detId.region(), detId.layer(), detId.chamber(), newRoll));
215  }
216 
217  // if new ME0EtaPartition fails or roll not changed
218  if (!newPart or newRoll == detId.roll()){
219  newPart = roll;
220  // set local y to edge of etaPartition
221  if (newLP.y() > height) newLP = LocalPoint(newLP.x(), height, newLP.z());
222  if (newLP.y() < -height) newLP = LocalPoint(newLP.x(), -height, newLP.z());
223  }
224  else {// new partiton, get new local point
225  newLP = newPart->toLocal(newGP);
226  }
227  }
228 
229  // smearing in X
230  double newXResolutionCor = correctSigmaU(roll, newLP.y());
231 
232  // new x position after smearing
233  const float targetXResolution(sqrt(newXResolutionCor*newXResolutionCor - oldXResolution_ * oldXResolution_));
234  float newLPx = newLP.x();
235  if (me0Digi.prompt())
236  newLPx = CLHEP::RandGaussQ::shoot(engine, newLP.x(), targetXResolution);
237 
238  // update local point after x smearing
239  newLP = LocalPoint(newLPx, newLP.y(), newLP.z());
240 
241  float newY(newLP.y());
242  // new hit has y coordinate in the center of the roll when using discretizeY
243  if (discretizeY_ and nPartitions_ > 1) newY = 0;
244  edm::LogVerbatim("ME0ReDigiProducer")
245  << "\tnew Y " << newY << std::endl;
246 
247  float newX(newLP.x());
248  edm::LogVerbatim("ME0ReDigiProducer")
249  << "\tnew X " << newX << std::endl;
250  // discretize the new X
251  if (discretizeX_){
252  int strip(newPart->strip(newLP));
253  float stripF(float(strip) - 0.5);
254  const LocalPoint newLP(newPart->centreOfStrip(stripF));
255  newX = newLP.x();
256  edm::LogVerbatim("ME0ReDigiProducer")
257  << "\t\tdiscretized X " << newX << std::endl;
258  }
259 
260  // make a new ME0DetId
261  ME0DigiPreReco out_digi(newX, newY, targetXResolution, targetYResolution, me0Digi.corr(), newTime, me0Digi.pdgid(), me0Digi.prompt());
262 
263  output_digis.insertDigi(newPart->id(), out_digi);
264  }
265  }
266 }
267 
269  const TrapezoidalStripTopology* top_(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
270  auto& parameters(roll->specs()->parameters());
271  double height(parameters[2]); // height = height from Center of Roll
272  double rollRadius = top_->radius(); // rollRadius = Radius at Center of Roll
273  double Rmax = rollRadius+height; // MaxRadius = Radius at top of Roll
274  double Rx = rollRadius+y; // y in [-height,+height]
275  double sigma_u_new = Rx/Rmax*newXResolution_;
276  return sigma_u_new;
277 }
#define LogDebug(id)
const ME0EtaPartitionSpecs * specs() const
T getParameter(std::string const &) const
void buildDigis(const ME0DigiPreRecoCollection &, ME0DigiPreRecoCollection &, CLHEP::HepRandomEngine *engine)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
float y() const
double correctSigmaU(const ME0EtaPartition *roll, double y)
static const int maxRollId
Definition: ME0DetId.h:96
edm::Service< edm::RandomNumberGenerator > rng
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
float tof() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
const ME0Specs & parameters() const
virtual ~ME0ReDigiProducer()
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
LocalPoint centreOfStrip(int strip) const
int pdgid() const
float strip(const LocalPoint &lp) const
const ME0EtaPartition * etaPartition(ME0DetId id) const
Return a etaPartition given its id.
Definition: ME0Geometry.cc:64
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const ME0Geometry * geometry_
int prompt() const
edm::EDGetTokenT< ME0DigiPreRecoCollection > token_
tuple d
Definition: ztail.py:151
MuonDigiCollection< ME0DetId, ME0DigiPreReco > ME0DigiPreRecoCollection
T sqrt(T t)
Definition: SSEVec.h:18
ME0DetId id() const
T z() const
Definition: PV3DBase.h:64
def move
Definition: eostools.py:510
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< ME0EtaPartition const * > & etaPartitions() const
Return a vector of all ME0 eta partitions.
Definition: ME0Geometry.cc:59
float x() const
T const * product() const
Definition: Handle.h:81
float corr() const
const T & get() const
Definition: EventSetup.h:56
std::vector< double > centralTOF_
const Topology & topology() const
ME0ReDigiProducer(const edm::ParameterSet &ps)
StreamID streamID() const
Definition: Event.h:81
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
const double Rmax[kNumberCalorimeter]
T x() const
Definition: PV3DBase.h:62
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: Run.h:42
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override