test
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  instLumi_ = ps.getParameter<double>("instLumi");
51 }
52 
53 
55 {
56 }
57 
58 
59 void ME0ReDigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup)
60 {
61  // set geometry
63  eventSetup.get<MuonGeometryRecord>().get(hGeom);
64  geometry_= &*hGeom;
65 
66  LogDebug("ME0ReDigiProducer")
67  << "Extracting central TOFs:" << std::endl;
68  // get the central TOFs for the eta partitions
69  for(auto &roll: geometry_->etaPartitions()){
70  const ME0DetId detId(roll->id());
71  if (detId.chamber() != 1 or detId.region() != 1) continue;
72  const LocalPoint centralLP(0., 0., 0.);
73  const GlobalPoint centralGP(roll->toGlobal(centralLP));
74  const float centralTOF(centralGP.mag() / 29.98); //speed of light
75  centralTOF_.push_back(centralTOF);
76  LogDebug("ME0ReDigiProducer")
77  << "ME0DetId " << detId << " central TOF " << centralTOF << std::endl;
78  }
79  nPartitions_ = centralTOF_.size()/6;
80 }
81 
82 
84 {
86  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
87 
89  e.getByToken(token_, input_digis);
90 
91  std::unique_ptr<ME0DigiPreRecoCollection> output_digis(new ME0DigiPreRecoCollection());
92 
93  // build the clusters
94  buildDigis(*(input_digis.product()), *output_digis, engine);
95 
96  // store them in the event
97  e.put(std::move(output_digis));
98 }
99 
100 
102  ME0DigiPreRecoCollection & output_digis,
103  CLHEP::HepRandomEngine* engine)
104 {
105  /*
106  Starting form the incoming pseudo-digi, which has sigma_x=300um, sigma_t=sigma_R=0, do the following
107  1A. Smear time using sigma_t by 7 ns (native resolution of GEM)
108  1B. Correct the smeared time with the central arrival time for partition
109  1C. Apply discretization: if the smeared time is outside the BX window (-12.5ns;+12.5ns),
110  the hit should be assigned to the next (or previous) BX
111 
112  2A. Apply smearing in the radial direction (not in local Y!) sigma_R of 100 um
113  2B. Apply discretization in radial direction to see which eta partition it belongs to.
114  Assign the hit to have Y-position equal to the middle of the partition.
115 
116  3A. Apply smearing in x-direction (not required if we stick with sigma=300 um, which is what
117  is used in pseudo-digis) to obtain desired x-resolution sigma_x_desired:
118  - use gaussian smear with sigma_eff=sqrt(sigma_desired^2-300^2)
119  */
120 
121  for(auto &roll: geometry_->etaPartitions()){
122  const ME0DetId detId(roll->id());
123  //const uint32_t rawId(detId.rawId());
124  auto digis = input_digis.get(detId);
125  for (auto d = digis.first; d != digis.second; ++d) {
126  const ME0DigiPreReco me0Digi = *d;
127  edm::LogVerbatim("ME0ReDigiProducer")
128  << "Check detId " << detId << " digi " << me0Digi << std::endl;
129 
130  // selection
131  if (reDigitizeOnlyMuons_ and std::abs(me0Digi.pdgid()) != 13) continue;
132  if (!reDigitizeNeutronBkg_ and !me0Digi.prompt()) continue;
133 
134  // scale background hits for luminosity
135  if (!me0Digi.prompt())
136  if (CLHEP::RandFlat::shoot(engine) > instLumi_*1.0/5) continue;
137 
138  edm::LogVerbatim("ME0ReDigiProducer")
139  << "\tPassed selection" << std::endl;
140 
141  // time resolution
142  float newTof(me0Digi.tof());
143  if (me0Digi.prompt() and smearTiming_) newTof += CLHEP::RandGaussQ::shoot(engine, 0, timeResolution_);
144 
145  // arrival time in ns
146  //const float t0(centralTOF_[ nPartitions_ * (detId.layer() -1) + detId.roll() - 1 ]);
147  int index = nPartitions_ * (detId.layer() -1) + detId.roll() - 1;
148  if(detId.roll() == 0) index = nPartitions_ * (detId.layer() -1) + detId.roll();
149  edm::LogVerbatim("ME0ReDigiProducer")
150  <<"size "<<centralTOF_.size()<<" nPartitions "<<nPartitions_<<" layer "<<detId.layer()<<" roll "<<detId.roll()<<" index "<<index<<std::endl;
151 
152  const float t0(centralTOF_[ index ]);
153  const float correctedNewTof(newTof - t0);
154 
155  edm::LogVerbatim("ME0ReDigiProducer")
156  <<" t0 "<< t0 << " originalTOF " << me0Digi.tof() << "\tnew TOF " << newTof << " corrected new TOF " << correctedNewTof << std::endl;
157 
158  // calculate the new time in ns
159  float newTime = correctedNewTof;
160  if (discretizeTiming_){
161  for (int iBunch = minBunch_ - 2; iBunch <= maxBunch_ + 2; ++iBunch){
162  if (-12.5 + iBunch*25 < newTime and newTime <= 12.5 + iBunch*25){
163  newTime = iBunch * 25;
164  break;
165  }
166  }
167  }
168 
169  edm::LogVerbatim("ME0ReDigiProducer")
170  << "\tBX " << newTime << std::endl;
171 
172  // calculate the position in global coordinates
173  const LocalPoint oldLP(me0Digi.x(), me0Digi.y(), 0);
174  const GlobalPoint oldGP(roll->toGlobal(oldLP));
175  const GlobalPoint centralGP(roll->toGlobal(LocalPoint(0.,0.,0.)));
176  const std::vector<float> parameters(roll->specs()->parameters());
177  const float height(parameters[2]); // G4 uses half-dimensions!
178 
179  // smear the new radial with gaussian
180  const float oldR(oldGP.perp());
181 
182  float newR = oldR;
183  if (me0Digi.prompt() and smearRadial_ and detId.roll() > 0)
184  newR = CLHEP::RandGaussQ::shoot(engine, oldR, radialResolution_);
185 
186  // calculate the new position in local coordinates
187  const GlobalPoint radialSmearedGP(GlobalPoint::Cylindrical(newR, oldGP.phi(), oldGP.z()));
188  LocalPoint radialSmearedLP = roll->toLocal(radialSmearedGP);
189 
190  // new y position after smearing
191  const float targetYResolution(sqrt(newYResolution_*newYResolution_ - oldYResolution_ * oldYResolution_));
192  float newLPy = radialSmearedLP.y();
193  if (me0Digi.prompt())
194  newLPy = CLHEP::RandGaussQ::shoot(engine, radialSmearedLP.y(), targetYResolution);
195 
196  const ME0EtaPartition* newPart = roll;
197  LocalPoint newLP(radialSmearedLP.x(), newLPy, radialSmearedLP.z());
198  GlobalPoint newGP(newPart->toGlobal(newLP));
199 
200  // check if digi moves one up or down roll
201  int newRoll = detId.roll();
202  if (newLP.y() > height) --newRoll;
203  if (newLP.y() < -height) ++newRoll;
204 
205  if (newRoll != detId.roll()){
206  // check if new roll is possible
207  if (newRoll < ME0DetId::minRollId || newRoll > ME0DetId::maxRollId){
208  newRoll = detId.roll();
209  }
210  else {
211  // roll changed, get new ME0EtaPartition
212  newPart = geometry_->etaPartition(ME0DetId(detId.region(), detId.layer(), detId.chamber(), newRoll));
213  }
214 
215  // if new ME0EtaPartition fails or roll not changed
216  if (!newPart or newRoll == detId.roll()){
217  newPart = roll;
218  // set local y to edge of etaPartition
219  if (newLP.y() > height) newLP = LocalPoint(newLP.x(), height, newLP.z());
220  if (newLP.y() < -height) newLP = LocalPoint(newLP.x(), -height, newLP.z());
221  }
222  else {// new partiton, get new local point
223  newLP = newPart->toLocal(newGP);
224  }
225  }
226 
227  // smearing in X
228  double newXResolutionCor = correctSigmaU(roll, newLP.y());
229 
230  // new x position after smearing
231  const float targetXResolution(sqrt(newXResolutionCor*newXResolutionCor - oldXResolution_ * oldXResolution_));
232  float newLPx = newLP.x();
233  if (me0Digi.prompt())
234  newLPx = CLHEP::RandGaussQ::shoot(engine, newLP.x(), targetXResolution);
235 
236  // update local point after x smearing
237  newLP = LocalPoint(newLPx, newLP.y(), newLP.z());
238 
239  float newY(newLP.y());
240  // new hit has y coordinate in the center of the roll when using discretizeY
241  if (discretizeY_ and detId.roll() > 0) newY = 0;
242  edm::LogVerbatim("ME0ReDigiProducer")
243  << "\tnew Y " << newY << std::endl;
244 
245  float newX(newLP.x());
246  edm::LogVerbatim("ME0ReDigiProducer")
247  << "\tnew X " << newX << std::endl;
248  // discretize the new X
249  if (discretizeX_){
250  int strip(newPart->strip(newLP));
251  float stripF(float(strip) - 0.5);
252  const LocalPoint newLP(newPart->centreOfStrip(stripF));
253  newX = newLP.x();
254  edm::LogVerbatim("ME0ReDigiProducer")
255  << "\t\tdiscretized X " << newX << std::endl;
256  }
257 
258  // make a new ME0DetId
259  ME0DigiPreReco out_digi(newX, newY, targetXResolution, targetYResolution, me0Digi.corr(), newTime, me0Digi.pdgid(), me0Digi.prompt());
260 
261  output_digis.insertDigi(newPart->id(), out_digi);
262  }
263  }
264 }
265 
267  const TrapezoidalStripTopology* top_(dynamic_cast<const TrapezoidalStripTopology*>(&(roll->topology())));
268  auto& parameters(roll->specs()->parameters());
269  double height(parameters[2]); // height = height from Center of Roll
270  double rollRadius = top_->radius(); // rollRadius = Radius at Center of Roll
271  double Rmax = rollRadius+height; // MaxRadius = Radius at top of Roll
272  double Rx = rollRadius+y; // y in [-height,+height]
273  double sigma_u_new = Rx/Rmax*newXResolution_;
274  return sigma_u_new;
275 }
#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_
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
bool prompt() const
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