CMS 3D CMS Logo

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);
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 }
Vector3DBase< float, LocalTag >
EcalSCDynamicDPhiParametersESProducer_cfi.saturation
saturation
Definition: EcalSCDynamicDPhiParametersESProducer_cfi.py:14
genericTrackCandidates_cff.associations
associations
Definition: genericTrackCandidates_cff.py:45
SiPixelCluster::minPixelCol
int minPixelCol() const
Definition: SiPixelCluster.h:144
SiStripMatchedRecHit2D::monoId
unsigned int monoId() const
Definition: SiStripMatchedRecHit2D.h:29
SiStripGainRcd
Definition: SiStripDependentRecords.h:29
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
ShallowGainCalibration::association_token_
const edm::EDGetTokenT< TrajTrackAssociationCollection > association_token_
Definition: ShallowGainCalibration.h:57
SiStripRecHit2D::cluster
ClusterRef cluster() const
Definition: SiStripRecHit2D.h:22
ProducerES_cfi.HalfLength
HalfLength
Definition: ProducerES_cfi.py:87
CustomPhysics_cfi.amplitude
amplitude
Definition: CustomPhysics_cfi.py:12
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
ShallowGainCalibration.h
GeomDet
Definition: GeomDet.h:27
SiStripMatchedRecHit2D::stereoCluster
SiStripCluster const & stereoCluster() const
Definition: SiStripMatchedRecHit2D.h:40
LocalTrajectoryError::positionError
LocalError positionError() const
Definition: LocalTrajectoryError.h:81
ShallowGainCalibration::m_tracker
const TrackerGeometry * m_tracker
Definition: ShallowGainCalibration.h:70
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
SiStripGain
Definition: SiStripGain.h:44
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
SiPixelRecHit::cluster
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
ShallowGainCalibration::isFarFromBorder
bool isFarFromBorder(TrajectoryStateOnSurface *trajState, const uint32_t detid, const edm::EventSetup *iSetup)
Definition: ShallowGainCalibration.cc:234
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
Bounds::length
virtual float length() const =0
SiStripCluster::firstStrip
uint16_t firstStrip() const
Definition: SiStripCluster.h:46
TrackerGeometry::idToDetUnit
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: TrackerGeometry.cc:183
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
h
TrajectoryStateOnSurface::localDirection
LocalVector localDirection() const
Definition: TrajectoryStateOnSurface.h:76
SiStripGain::getRange
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
SiPixelCluster::minPixelRow
int minPixelRow() const
Definition: SiPixelCluster.h:142
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
ShallowGainCalibration::gain_token_
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gain_token_
Definition: ShallowGainCalibration.h:60
L1TCaloTriggerNtuples_cff.Prefix
Prefix
Definition: L1TCaloTriggerNtuples_cff.py:8
reco::Track
Definition: Track.h:27
edm::ESHandle< SiStripGain >
ShallowGainCalibration::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShallowGainCalibration.cc:35
Point3DBase< float, LocalTag >
SiPixelCluster::pixelADC
const std::vector< uint16_t > & pixelADC() const
Definition: SiPixelCluster.h:148
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripGain::getApvGain
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >::const_iterator
friend struct const_iterator
Definition: AssociationMap.h:274
edm::View
Definition: CaloClusterFwd.h:14
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
SiStripMatchedRecHit2D::stereoId
unsigned int stereoId() const
Definition: SiStripMatchedRecHit2D.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
fastTrackerRecHitType::isPixel
bool isPixel(HitType hitType)
Definition: FastTrackerRecHit.h:37
LocalError
Definition: LocalError.h:12
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >
edm::Path
Definition: Path.h:41
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
ShallowGainCalibration::thickness
double thickness(DetId id)
Definition: ShallowGainCalibration.cc:269
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
ShallowGainCalibration::tracks_token_
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_token_
Definition: ShallowGainCalibration.h:56
SiStripRecHit1D::cluster
ClusterRef cluster() const
Definition: SiStripRecHit1D.h:18
edm::EventSetup
Definition: EventSetup.h:58
ShallowGainCalibration::m_thicknessMap
std::map< DetId, double > m_thicknessMap
Definition: ShallowGainCalibration.h:71
SiStripRecHit1D
Definition: SiStripRecHit1D.h:8
SiStripCluster::amplitudes
SiStripCluster const & amplitudes() const
Definition: SiStripCluster.h:68
TrapezoidalPlaneBounds
Definition: TrapezoidalPlaneBounds.h:15
get
#define get
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
TrackingRecHit
Definition: TrackingRecHit.h:21
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
ShallowGainCalibration::trackerGeometry_token_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometry_token_
Definition: ShallowGainCalibration.h:59
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
RectangularPlaneBounds
Definition: RectangularPlaneBounds.h:12
ShallowGainCalibration::ShallowGainCalibration
ShallowGainCalibration(const edm::ParameterSet &)
Definition: ShallowGainCalibration.cc:7
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:44
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
Trajectory
Definition: Trajectory.h:38
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
DuplicateTrackType::Overlapping
SiStripMatchedRecHit2D::monoCluster
SiStripCluster const & monoCluster() const
Definition: SiStripMatchedRecHit2D.h:41
Exception
Definition: hltDiff.cc:245
BoundPlane
PixelTestBeamValidation_cfi.Charge
Charge
Definition: PixelTestBeamValidation_cfi.py:91
ShallowGainCalibration::tkGeom_token_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeom_token_
Definition: ShallowGainCalibration.h:61
ShallowGainCalibration::Prefix
std::string Prefix
Definition: ShallowGainCalibration.h:64
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ShallowGainCalibration::Suffix
std::string Suffix
Definition: ShallowGainCalibration.h:63
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
SiStripCluster
Definition: SiStripCluster.h:8
LocalError::yy
float yy() const
Definition: LocalError.h:24
edm::InputTag
Definition: InputTag.h:15
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
hit
Definition: SiStripHitEffFromCalibTree.cc:88
TrackerGeometry
Definition: TrackerGeometry.h:14
shallow::findTrackIndex
int findTrackIndex(const edm::Handle< edm::View< reco::Track > > &h, const reco::Track *t)
Definition: ShallowTools.cc:25