CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ShallowGainCalibration.cc
Go to the documentation of this file.
2 
3 using namespace edm;
4 using namespace reco;
5 using namespace std;
6 
8  : tracks_token_(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("Tracks"))),
9  association_token_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
10  trackerGeometry_token_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
11  gain_token_(esConsumes<SiStripGain, SiStripGainRcd>()),
13  Suffix(iConfig.getParameter<std::string>("Suffix")),
14  Prefix(iConfig.getParameter<std::string>("Prefix")) {
15  produces<std::vector<int>>(Prefix + "trackindex" + Suffix);
16  produces<std::vector<unsigned int>>(Prefix + "rawid" + Suffix);
17  produces<std::vector<double>>(Prefix + "localdirx" + Suffix);
18  produces<std::vector<double>>(Prefix + "localdiry" + Suffix);
19  produces<std::vector<double>>(Prefix + "localdirz" + Suffix);
20  produces<std::vector<unsigned short>>(Prefix + "firststrip" + Suffix);
21  produces<std::vector<unsigned short>>(Prefix + "nstrips" + Suffix);
22  produces<std::vector<bool>>(Prefix + "saturation" + Suffix);
23  produces<std::vector<bool>>(Prefix + "overlapping" + Suffix);
24  produces<std::vector<bool>>(Prefix + "farfromedge" + Suffix);
25  produces<std::vector<unsigned int>>(Prefix + "charge" + Suffix);
26  produces<std::vector<double>>(Prefix + "path" + Suffix);
27 #ifdef ExtendedCALIBTree
28  produces<std::vector<double>>(Prefix + "chargeoverpath" + Suffix);
29 #endif
30  produces<std::vector<unsigned char>>(Prefix + "amplitude" + Suffix);
31  produces<std::vector<double>>(Prefix + "gainused" + Suffix);
32  produces<std::vector<double>>(Prefix + "gainusedTick" + Suffix);
33 }
34 
36  auto trackindex = std::make_unique<std::vector<int>>();
37  auto rawid = std::make_unique<std::vector<unsigned int>>();
38  auto localdirx = std::make_unique<std::vector<double>>();
39  auto localdiry = std::make_unique<std::vector<double>>();
40  auto localdirz = std::make_unique<std::vector<double>>();
41  auto firststrip = std::make_unique<std::vector<unsigned short>>();
42  auto nstrips = std::make_unique<std::vector<unsigned short>>();
43  auto saturation = std::make_unique<std::vector<bool>>();
44  auto overlapping = std::make_unique<std::vector<bool>>();
45  auto farfromedge = std::make_unique<std::vector<bool>>();
46  auto charge = std::make_unique<std::vector<unsigned int>>();
47  auto path = std::make_unique<std::vector<double>>();
48 #ifdef ExtendedCALIBTree
49  auto chargeoverpath = std::make_unique<std::vector<double>>();
50 #endif
51  auto amplitude = std::make_unique<std::vector<unsigned char>>();
52  auto gainused = std::make_unique<std::vector<double>>();
53  auto gainusedTick = std::make_unique<std::vector<double>>();
54 
58  iEvent.getByToken(tracks_token_, tracks);
60  iEvent.getByToken(association_token_, associations);
61 
63  association != associations->end();
64  association++) {
65  const Trajectory* traj = association->key.get();
66  const reco::Track* track = association->val.get();
67 
68  vector<TrajectoryMeasurement> measurements = traj->measurements();
69  for (vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin();
70  measurement_it != measurements.end();
71  measurement_it++) {
72  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
73  if (!trajState.isValid())
74  continue;
75 
76  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
77  const SiStripRecHit1D* sistripsimple1dhit = dynamic_cast<const SiStripRecHit1D*>(hit);
78  const SiStripRecHit2D* sistripsimplehit = dynamic_cast<const SiStripRecHit2D*>(hit);
79  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
80  const SiPixelRecHit* sipixelhit = dynamic_cast<const SiPixelRecHit*>(hit);
81 
82  const SiPixelCluster* PixelCluster = nullptr;
83  const SiStripCluster* StripCluster = nullptr;
84  uint32_t DetId = 0;
85 
86  for (unsigned int h = 0; h < 2; h++) {
87  if (!sistripmatchedhit && h == 1) {
88  continue;
89  } else if (sistripmatchedhit && h == 0) {
90  StripCluster = &sistripmatchedhit->monoCluster();
91  DetId = sistripmatchedhit->monoId();
92  } else if (sistripmatchedhit && h == 1) {
93  StripCluster = &sistripmatchedhit->stereoCluster();
94  ;
95  DetId = sistripmatchedhit->stereoId();
96  } else if (sistripsimplehit) {
97  StripCluster = (sistripsimplehit->cluster()).get();
98  DetId = sistripsimplehit->geographicalId().rawId();
99  } else if (sistripsimple1dhit) {
100  StripCluster = (sistripsimple1dhit->cluster()).get();
101  DetId = sistripsimple1dhit->geographicalId().rawId();
102  } else if (sipixelhit) {
103  PixelCluster = (sipixelhit->cluster()).get();
104  DetId = sipixelhit->geographicalId().rawId();
105  } else {
106  continue;
107  }
108 
109  LocalVector trackDirection = trajState.localDirection();
110  double cosine = trackDirection.z() / trackDirection.mag();
111  bool Saturation = false;
112  bool Overlapping = false;
113  unsigned int Charge = 0;
114  double Path = (10.0 * thickness(DetId)) / fabs(cosine);
115  double PrevGain = -1;
116  double PrevGainTick = -1;
117  int FirstStrip = 0;
118  int NStrips = 0;
119 
120  if (StripCluster) {
121  const auto& Ampls = StripCluster->amplitudes();
122  FirstStrip = StripCluster->firstStrip();
123  NStrips = Ampls.size();
124  int APVId = FirstStrip / 128;
125 
126  if (gainHandle.isValid()) {
127  PrevGain = gainHandle->getApvGain(APVId, gainHandle->getRange(DetId, 1), 1);
128  PrevGainTick = gainHandle->getApvGain(APVId, gainHandle->getRange(DetId, 0), 1);
129  }
130 
131  for (unsigned int a = 0; a < Ampls.size(); a++) {
132  Charge += Ampls[a];
133  if (Ampls[a] >= 254)
134  Saturation = true;
135  amplitude->push_back(Ampls[a]);
136  }
137 
138  if (FirstStrip == 0)
139  Overlapping = true;
140  if (FirstStrip == 128)
141  Overlapping = true;
142  if (FirstStrip == 256)
143  Overlapping = true;
144  if (FirstStrip == 384)
145  Overlapping = true;
146  if (FirstStrip == 512)
147  Overlapping = true;
148  if (FirstStrip == 640)
149  Overlapping = true;
150 
151  if (FirstStrip <= 127 && FirstStrip + Ampls.size() > 127)
152  Overlapping = true;
153  if (FirstStrip <= 255 && FirstStrip + Ampls.size() > 255)
154  Overlapping = true;
155  if (FirstStrip <= 383 && FirstStrip + Ampls.size() > 383)
156  Overlapping = true;
157  if (FirstStrip <= 511 && FirstStrip + Ampls.size() > 511)
158  Overlapping = true;
159  if (FirstStrip <= 639 && FirstStrip + Ampls.size() > 639)
160  Overlapping = true;
161 
162  if (FirstStrip + Ampls.size() == 127)
163  Overlapping = true;
164  if (FirstStrip + Ampls.size() == 255)
165  Overlapping = true;
166  if (FirstStrip + Ampls.size() == 383)
167  Overlapping = true;
168  if (FirstStrip + Ampls.size() == 511)
169  Overlapping = true;
170  if (FirstStrip + Ampls.size() == 639)
171  Overlapping = true;
172  if (FirstStrip + Ampls.size() == 767)
173  Overlapping = true;
174  } else if (PixelCluster) {
175  const auto& Ampls = PixelCluster->pixelADC();
176  int FirstRow = PixelCluster->minPixelRow();
177  int FirstCol = PixelCluster->minPixelCol();
178  FirstStrip = ((FirstRow / 80) << 3 | (FirstCol / 52)) * 128; //Hack to save the APVId
179  NStrips = 0;
180  Saturation = false;
181  Overlapping = false;
182 
183  for (unsigned int a = 0; a < Ampls.size(); a++) {
184  Charge += Ampls[a];
185  if (Ampls[a] >= 254)
186  Saturation = true;
187  }
188  }
189 #ifdef ExtendedCALIBTree
190  double ChargeOverPath = (double)Charge / Path;
191 #endif
192 
193  trackindex->push_back(shallow::findTrackIndex(tracks, track));
194  rawid->push_back(DetId);
195  localdirx->push_back(trackDirection.x());
196  localdiry->push_back(trackDirection.y());
197  localdirz->push_back(trackDirection.z());
198  firststrip->push_back(FirstStrip);
199  nstrips->push_back(NStrips);
200  saturation->push_back(Saturation);
201  overlapping->push_back(Overlapping);
202  farfromedge->push_back(StripCluster ? isFarFromBorder(&trajState, DetId, &iSetup) : true);
203  charge->push_back(Charge);
204  path->push_back(Path);
205 #ifdef ExtendedCALIBTree
206  chargeoverpath->push_back(ChargeOverPath);
207 #endif
208  gainused->push_back(PrevGain);
209  gainusedTick->push_back(PrevGainTick);
210  }
211  }
212  }
213 
214  iEvent.put(std::move(trackindex), Prefix + "trackindex" + Suffix);
215  iEvent.put(std::move(rawid), Prefix + "rawid" + Suffix);
216  iEvent.put(std::move(localdirx), Prefix + "localdirx" + Suffix);
217  iEvent.put(std::move(localdiry), Prefix + "localdiry" + Suffix);
218  iEvent.put(std::move(localdirz), Prefix + "localdirz" + Suffix);
219  iEvent.put(std::move(firststrip), Prefix + "firststrip" + Suffix);
220  iEvent.put(std::move(nstrips), Prefix + "nstrips" + Suffix);
221  iEvent.put(std::move(saturation), Prefix + "saturation" + Suffix);
222  iEvent.put(std::move(overlapping), Prefix + "overlapping" + Suffix);
223  iEvent.put(std::move(farfromedge), Prefix + "farfromedge" + Suffix);
224  iEvent.put(std::move(charge), Prefix + "charge" + Suffix);
225  iEvent.put(std::move(path), Prefix + "path" + Suffix);
226 #ifdef ExtendedCALIBTree
227  iEvent.put(std::move(chargeoverpath), Prefix + "chargeoverpath" + Suffix);
228 #endif
229  iEvent.put(std::move(amplitude), Prefix + "amplitude" + Suffix);
230  iEvent.put(std::move(gainused), Prefix + "gainused" + Suffix);
231  iEvent.put(std::move(gainusedTick), Prefix + "gainusedTick" + Suffix);
232 }
233 
235  const uint32_t detid,
236  const edm::EventSetup* iSetup) {
238 
239  LocalPoint HitLocalPos = trajState->localPosition();
240  LocalError HitLocalError = trajState->localError().positionError();
241 
242  const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
243  if (dynamic_cast<const StripGeomDetUnit*>(it) == nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) == nullptr) {
244  throw cms::Exception("Logic Error") << "\t\t this detID doesn't seem to belong to the Tracker";
245  }
246 
247  const BoundPlane plane = it->surface();
248  const TrapezoidalPlaneBounds* trapezoidalBounds(dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
249  const RectangularPlaneBounds* rectangularBounds(dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
250 
251  double DistFromBorder = 1.0;
252  double HalfLength = it->surface().bounds().length() / 2.0;
253 
254  if (trapezoidalBounds) {
255  std::array<const float, 4> const& parameters = (*trapezoidalBounds).parameters();
256  HalfLength = parameters[3];
257  } else if (rectangularBounds) {
258  HalfLength = it->surface().bounds().length() / 2.0;
259  } else {
260  return false;
261  }
262 
263  if (fabs(HitLocalPos.y()) + HitLocalError.yy() >= (HalfLength - DistFromBorder))
264  return false;
265 
266  return true;
267 }
268 
270  map<DetId, double>::iterator th = m_thicknessMap.find(id);
271  if (th != m_thicknessMap.end())
272  return (*th).second;
273  else {
274  double detThickness = 1.;
275  //compute thickness normalization
276  const GeomDetUnit* it = m_tracker->idToDetUnit(DetId(id));
277  bool isPixel = dynamic_cast<const PixelGeomDetUnit*>(it) != nullptr;
278  bool isStrip = dynamic_cast<const StripGeomDetUnit*>(it) != nullptr;
279  if (!isPixel && !isStrip) {
280  throw cms::Exception("Logic Error") << "\t\t this detID doesn't seem to belong to the Tracker";
281  } else {
282  detThickness = it->surface().bounds().thickness();
283  }
284 
285  m_thicknessMap[id] = detThickness; //computed value
286  return detThickness;
287  }
288 }
ClusterRef cluster() const
int minPixelCol() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
unsigned int stereoId() const
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_token_
virtual float length() const =0
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
uint16_t *__restrict__ id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
int findTrackIndex(const edm::Handle< edm::View< reco::Track > > &h, const reco::Track *t)
Definition: ShallowTools.cc:25
SiStripCluster const & monoCluster() const
LocalVector localDirection() const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometry_token_
SiStripCluster const & amplitudes() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::map< DetId, double > m_thicknessMap
T y() const
Definition: PV3DBase.h:60
const Bounds & bounds() const
Definition: Surface.h:87
auto const & tracks
cannot be loose
uint16_t firstStrip() const
ShallowGainCalibration(const edm::ParameterSet &)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeom_token_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
LocalError positionError() const
bool getData(T &iHolder) const
Definition: EventSetup.h:128
DataContainer const & measurements() const
Definition: Trajectory.h:178
int iEvent
Definition: GenABIO.cc:224
T mag() const
Definition: PV3DBase.h:64
int minPixelRow() const
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
float yy() const
Definition: LocalError.h:24
Definition: Path.h:41
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
ClusterRef cluster() const
const LocalTrajectoryError & localError() const
const edm::EDGetTokenT< TrajTrackAssociationCollection > association_token_
const std::vector< uint16_t > & pixelADC() const
Definition: DetId.h:17
const TrackerGeometry * m_tracker
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
bool isFarFromBorder(TrajectoryStateOnSurface *trajState, const uint32_t detid, const edm::EventSetup *iSetup)
SiStripCluster const & stereoCluster() const
Pixel cluster – collection of neighboring pixels above threshold.
double a
Definition: hdecay.h:119
bool isPixel(HitType hitType)
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gain_token_
unsigned int monoId() const
DetId geographicalId() const
void produce(edm::Event &, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
bool isValid() const
Definition: ESHandle.h:44
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Our base class.
Definition: SiPixelRecHit.h:23