CMS 3D CMS Logo

EcalDetailedTimeRecHitProducer.cc
Go to the documentation of this file.
1 
40 
41 #include "CLHEP/Units/GlobalPhysicalConstants.h"
42 #include "CLHEP/Units/GlobalSystemOfUnits.h"
43 
44 #include <cmath>
45 #include <iostream>
46 #include <memory>
47 #include <vector>
48 
50 public:
52  void produce(edm::Event& evt, const edm::EventSetup& es) override;
53 
54 private:
55  //Functions to correct the TOF from the EcalDigi which is not corrected for the vertex position
56  double deltaTimeOfFlight(GlobalPoint& vertex, const DetId& detId, int layer) const;
57 
59 
60  edm::EDGetTokenT<EBRecHitCollection> EBRecHitCollection_; // secondary name given to collection of EBrechits
61  edm::EDGetTokenT<EERecHitCollection> EERecHitCollection_; // secondary name given to collection of EErechits
62 
67 
70 
72  ebTimeDigiCollection_; // secondary name given to collection of EB uncalib rechits
74  eeTimeDigiCollection_; // secondary name given to collection of EE uncalib rechits
75 
77 
78  std::string EBDetailedTimeRecHitCollection_; // secondary name to be given to EB collection of hits
79  std::string EEDetailedTimeRecHitCollection_; // secondary name to be given to EE collection of hits
80 };
81 
83  EBRecHitCollection_ = consumes<EBRecHitCollection>(ps.getParameter<edm::InputTag>("EBRecHitCollection"));
84  EERecHitCollection_ = consumes<EERecHitCollection>(ps.getParameter<edm::InputTag>("EERecHitCollection"));
85 
86  ebTimeDigiCollection_ = consumes<EcalTimeDigiCollection>(ps.getParameter<edm::InputTag>("EBTimeDigiCollection"));
87  eeTimeDigiCollection_ = consumes<EcalTimeDigiCollection>(ps.getParameter<edm::InputTag>("EETimeDigiCollection"));
88 
89  caloGeometry_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
90 
91  EBDetailedTimeRecHitCollection_ = ps.getParameter<std::string>("EBDetailedTimeRecHitCollection");
92  EEDetailedTimeRecHitCollection_ = ps.getParameter<std::string>("EEDetailedTimeRecHitCollection");
93 
94  correctForVertexZPosition_ = ps.getParameter<bool>("correctForVertexZPosition");
95  useMCTruthVertex_ = ps.getParameter<bool>("useMCTruthVertex");
97  if (not useMCTruthVertex_) {
98  recoVertex_ = consumes<reco::VertexCollection>(ps.getParameter<edm::InputTag>("recoVertex"));
99  } else {
100  simVertex_ = consumes<edm::SimVertexContainer>(ps.getParameter<edm::InputTag>("simVertex"));
101  }
102  }
103 
104  ebTimeLayer_ = ps.getParameter<int>("EBTimeLayer");
105  eeTimeLayer_ = ps.getParameter<int>("EETimeLayer");
106 
107  produces<EBRecHitCollection>(EBDetailedTimeRecHitCollection_);
108  produces<EERecHitCollection>(EEDetailedTimeRecHitCollection_);
109 }
110 
112  using namespace edm;
113  using namespace reco;
114 
116 
117  m_geometry = hGeometry.product();
118 
119  Handle<EBRecHitCollection> pEBRecHits;
120  Handle<EERecHitCollection> pEERecHits;
121 
122  const EBRecHitCollection* EBRecHits = nullptr;
123  const EERecHitCollection* EERecHits = nullptr;
124 
125  evt.getByToken(EBRecHitCollection_, pEBRecHits);
126  if (pEBRecHits.isValid()) {
127  EBRecHits = pEBRecHits.product(); // get a ptr to the product
128 #ifdef DEBUG
129  LogDebug("EcalRecHitDebug") << "total # EB rechits to be re-calibrated: " << EBRecHits->size();
130 #endif
131  }
132 
133  evt.getByToken(EERecHitCollection_, pEERecHits);
134  if (pEERecHits.isValid()) {
135  EERecHits = pEERecHits.product(); // get a ptr to the product
136 #ifdef DEBUG
137  LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits to be re-calibrated: " << EERecHits->size();
138 #endif
139  }
140 
141  Handle<EcalTimeDigiCollection> pEBTimeDigis;
142  Handle<EcalTimeDigiCollection> pEETimeDigis;
143 
144  const EcalTimeDigiCollection* ebTimeDigis = nullptr;
145  const EcalTimeDigiCollection* eeTimeDigis = nullptr;
146 
147  evt.getByToken(ebTimeDigiCollection_, pEBTimeDigis);
148  //evt.getByToken( digiProducer_, pEBTimeDigis);
149  if (pEBTimeDigis.isValid()) {
150  ebTimeDigis = pEBTimeDigis.product(); // get a ptr to the produc
151  edm::LogInfo("EcalDetailedTimeRecHitInfo") << "total # ebTimeDigis: " << ebTimeDigis->size();
152  }
153 
154  evt.getByToken(eeTimeDigiCollection_, pEETimeDigis);
155  //evt.getByToken( digiProducer_, pEETimeDigis);
156  if (pEETimeDigis.isValid()) {
157  eeTimeDigis = pEETimeDigis.product(); // get a ptr to the product
158  edm::LogInfo("EcalDetailedTimeRecHitInfo") << "total # eeTimeDigis: " << eeTimeDigis->size();
159  }
160  // collection of rechits to put in the event
161  std::unique_ptr<EBRecHitCollection> EBDetailedTimeRecHits(new EBRecHitCollection);
162  std::unique_ptr<EERecHitCollection> EEDetailedTimeRecHits(new EERecHitCollection);
163 
164  std::unique_ptr<GlobalPoint> vertex;
165 
167  if (!useMCTruthVertex_) {
168  //Get the first reco vertex
169  // get primary vertices
170 
171  edm::Handle<VertexCollection> VertexHandle;
172  evt.getByToken(recoVertex_, VertexHandle);
173 
174  if (VertexHandle.isValid()) {
175  if (!(*VertexHandle).empty()) //at least 1 vertex
176  {
177  const reco::Vertex* myVertex = &(*VertexHandle)[0];
178  vertex = std::make_unique<GlobalPoint>(myVertex->x(), myVertex->y(), myVertex->z());
179  }
180  }
181 
182  } else {
183  edm::Handle<SimVertexContainer> VertexHandle;
184  evt.getByToken(simVertex_, VertexHandle);
185 
186  if (VertexHandle.isValid()) {
187  if (!(*VertexHandle).empty()) //at least 1 vertex
188  {
189  assert((*VertexHandle)[0].vertexId() == 0);
190  const SimVertex* myVertex = &(*VertexHandle)[0];
191  vertex = std::make_unique<GlobalPoint>(
192  myVertex->position().x(), myVertex->position().y(), myVertex->position().z());
193  }
194  }
195  }
196  }
197 
198  if (EBRecHits && ebTimeDigis) {
199  // loop over uncalibrated rechits to make calibrated ones
200  for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
201  EcalRecHit aHit((*it));
202  EcalTimeDigiCollection::const_iterator timeDigi = ebTimeDigis->find((*it).id());
203  if (timeDigi != ebTimeDigis->end()) {
204  if (timeDigi->sampleOfInterest() >= 0) {
205  float myTime = (*timeDigi)[timeDigi->sampleOfInterest()];
206  //Vertex corrected ToF
207  if (vertex) {
208  aHit.setTime(myTime + deltaTimeOfFlight(*vertex, (*it).id(), ebTimeLayer_));
209  } else
210  //Uncorrected ToF
211  aHit.setTime(myTime);
212  }
213  }
214  // leave standard time if no timeDigi is associated (e.g. noise recHits)
215  EBDetailedTimeRecHits->push_back(aHit);
216  }
217  }
218 
219  if (EERecHits && eeTimeDigis) {
220  // loop over uncalibrated rechits to make calibrated ones
221  for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
222  EcalRecHit aHit(*it);
223  EcalTimeDigiCollection::const_iterator timeDigi = eeTimeDigis->find((*it).id());
224  if (timeDigi != eeTimeDigis->end()) {
225  if (timeDigi->sampleOfInterest() >= 0) {
226  float myTime = (*timeDigi)[timeDigi->sampleOfInterest()];
227  //Vertex corrected ToF
228  if (vertex) {
229  aHit.setTime(myTime + deltaTimeOfFlight(*vertex, (*it).id(), eeTimeLayer_));
230  } else
231  //Uncorrected ToF
232  aHit.setTime(myTime);
233  }
234  }
235  EEDetailedTimeRecHits->push_back(aHit);
236  }
237  }
238  // put the collection of recunstructed hits in the event
239  LogInfo("EcalDetailedTimeRecHitInfo") << "total # EB rechits: " << EBDetailedTimeRecHits->size();
240  LogInfo("EcalDetailedTimeRecHitInfo") << "total # EE rechits: " << EEDetailedTimeRecHits->size();
241 
242  evt.put(std::move(EBDetailedTimeRecHits), EBDetailedTimeRecHitCollection_);
243  evt.put(std::move(EEDetailedTimeRecHits), EEDetailedTimeRecHitCollection_);
244 }
245 
247  auto cellGeometry(m_geometry->getGeometry(detId));
248  assert(nullptr != cellGeometry);
249  GlobalPoint layerPos =
250  cellGeometry->getPosition(double(layer) + 0.5); //depth in mm in the middle of the layer position
251  GlobalVector tofVector = layerPos - vertex;
252  return (layerPos.mag() * cm - tofVector.mag() * cm) / (float)c_light;
253 }
254 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
double z() const
z coordinate
Definition: Vertex.h:134
size_type size() const
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:21
edm::EDGetTokenT< EcalTimeDigiCollection > eeTimeDigiCollection_
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
assert(be >=bs)
edm::EDGetTokenT< EcalTimeDigiCollection > ebTimeDigiCollection_
void setTime(float time)
Definition: EcalRecHit.h:72
T const * product() const
Definition: ESHandle.h:86
double deltaTimeOfFlight(GlobalPoint &vertex, const DetId &detId, int layer) const
edm::EDGetTokenT< reco::VertexCollection > recoVertex_
T mag() const
Definition: PV3DBase.h:64
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
Definition: CaloGeometry.cc:60
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double x() const
x coordinate
Definition: Vertex.h:130
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double y() const
y coordinate
Definition: Vertex.h:132
const_iterator end() const
Log< level::Info, false > LogInfo
EcalDetailedTimeRecHitProducer(const edm::ParameterSet &ps)
Definition: DetId.h:17
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< EBRecHitCollection > EBRecHitCollection_
iterator find(key_type k)
fixed size matrix
HLT enums.
edm::EDGetTokenT< edm::SimVertexContainer > simVertex_
edm::EDGetTokenT< EERecHitCollection > EERecHitCollection_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometry_
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &evt, const edm::EventSetup &es) override
#define LogDebug(id)