CMS 3D CMS Logo

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