1- #include < memory>
21#include " ShallowGainCalibration.h"
32
43using namespace edm ;
@@ -8,8 +7,9 @@ using namespace std;
87ShallowGainCalibration::ShallowGainCalibration (const edm::ParameterSet& iConfig)
98 : tracks_token_(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>(" Tracks" ))),
109 association_token_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>(" Tracks" ))),
11- geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
12- gainToken_(esConsumes<SiStripGain, SiStripGainRcd>()),
10+ trackerGeometry_token_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
11+ gain_token_(esConsumes<SiStripGain, SiStripGainRcd>()),
12+ tkGeom_token_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
1313 Suffix(iConfig.getParameter<std::string>(" Suffix" )),
1414 Prefix(iConfig.getParameter<std::string>(" Prefix" )) {
1515 produces<std::vector<int >>(Prefix + " trackindex" + Suffix);
@@ -32,7 +32,7 @@ ShallowGainCalibration::ShallowGainCalibration(const edm::ParameterSet& iConfig)
3232 produces<std::vector<double >>(Prefix + " gainusedTick" + Suffix);
3333}
3434
35- void ShallowGainCalibration::produce (edm::StreamID, edm:: Event& iEvent, const edm::EventSetup& iSetup) const {
35+ void ShallowGainCalibration::produce (edm::Event& iEvent, const edm::EventSetup& iSetup) {
3636 auto trackindex = std::make_unique<std::vector<int >>();
3737 auto rawid = std::make_unique<std::vector<unsigned int >>();
3838 auto localdirx = std::make_unique<std::vector<double >>();
@@ -52,14 +52,13 @@ void ShallowGainCalibration::produce(edm::StreamID, edm::Event& iEvent, const ed
5252 auto gainused = std::make_unique<std::vector<double >>();
5353 auto gainusedTick = std::make_unique<std::vector<double >>();
5454
55- edm::ESHandle<SiStripGain> gainHandle = iSetup.getHandle (gainToken_);
55+ m_tracker = &iSetup.getData (trackerGeometry_token_);
56+ edm::ESHandle<SiStripGain> gainHandle = iSetup.getHandle (gain_token_);
5657 edm::Handle<edm::View<reco::Track>> tracks;
5758 iEvent.getByToken (tracks_token_, tracks);
5859 edm::Handle<TrajTrackAssociationCollection> associations;
5960 iEvent.getByToken (association_token_, associations);
6061
61- auto bundle = *runCache (iEvent.getRun ().index ());
62-
6362 for (TrajTrackAssociationCollection::const_iterator association = associations->begin ();
6463 association != associations->end ();
6564 association++) {
@@ -112,8 +111,7 @@ void ShallowGainCalibration::produce(edm::StreamID, edm::Event& iEvent, const ed
112111 bool Saturation = false ;
113112 bool Overlapping = false ;
114113 unsigned int Charge = 0 ;
115- auto thicknessMap = bundle.getThicknessMap ();
116- double Path = (10.0 * thicknessMap[DetId]) / fabs (cosine);
114+ double Path = (10.0 * thickness (DetId)) / fabs (cosine);
117115 double PrevGain = -1 ;
118116 double PrevGainTick = -1 ;
119117 int FirstStrip = 0 ;
@@ -201,7 +199,7 @@ void ShallowGainCalibration::produce(edm::StreamID, edm::Event& iEvent, const ed
201199 nstrips->push_back (NStrips);
202200 saturation->push_back (Saturation);
203201 overlapping->push_back (Overlapping);
204- farfromedge->push_back (StripCluster ? isFarFromBorder (&trajState, DetId, bundle. getTrackerGeometry () ) : true );
202+ farfromedge->push_back (StripCluster ? isFarFromBorder (&trajState, DetId, &iSetup ) : true );
205203 charge->push_back (Charge);
206204 path->push_back (Path);
207205#ifdef ExtendedCALIBTree
@@ -235,7 +233,9 @@ void ShallowGainCalibration::produce(edm::StreamID, edm::Event& iEvent, const ed
235233
236234bool ShallowGainCalibration::isFarFromBorder (TrajectoryStateOnSurface* trajState,
237235 const uint32_t detid,
238- const TrackerGeometry* tkGeom) const {
236+ const edm::EventSetup* iSetup) {
237+ edm::ESHandle<TrackerGeometry> tkGeom = iSetup->getHandle (tkGeom_token_);
238+
239239 LocalPoint HitLocalPos = trajState->localPosition ();
240240 LocalError HitLocalError = trajState->localError ().positionError ();
241241
@@ -266,26 +266,23 @@ bool ShallowGainCalibration::isFarFromBorder(TrajectoryStateOnSurface* trajState
266266 return true ;
267267}
268268
269- std::shared_ptr<shallowGainCalibration::bundle> ShallowGainCalibration::globalBeginRun (
270- edm::Run const & iRun, edm::EventSetup const & iSetup) const {
271- edm::ESHandle<TrackerGeometry> theTrackerGeometry = iSetup.getHandle (geomToken_);
272- auto bundle = std::make_shared<shallowGainCalibration::bundle>(theTrackerGeometry.product ());
273-
274- for (const auto & it : theTrackerGeometry->detUnits ()) {
269+ double ShallowGainCalibration::thickness (DetId id) {
270+ map<DetId, double >::iterator th = m_thicknessMap.find (id);
271+ if (th != m_thicknessMap.end ())
272+ return (*th).second ;
273+ else {
275274 double detThickness = 1 .;
276- auto id = (it-> geographicalId ()). rawId ();
277-
275+ // compute thickness normalization
276+ const GeomDetUnit* it = m_tracker-> idToDetUnit ( DetId (id));
278277 bool isPixel = dynamic_cast <const PixelGeomDetUnit*>(it) != nullptr ;
279278 bool isStrip = dynamic_cast <const StripGeomDetUnit*>(it) != nullptr ;
280-
281279 if (!isPixel && !isStrip) {
282280 throw cms::Exception (" Logic Error" ) << " \t\t this detID doesn't seem to belong to the Tracker" ;
283281 } else {
284282 detThickness = it->surface ().bounds ().thickness ();
285283 }
286- bundle.get ()->updateMap (id, detThickness);
284+
285+ m_thicknessMap[id] = detThickness; // computed value
286+ return detThickness;
287287 }
288- return bundle;
289288}
290-
291- void ShallowGainCalibration::globalEndRun (edm::Run const &, edm::EventSetup const &) const {}
0 commit comments