CMS 3D CMS Logo

GlobalTrackingRegionWithVerticesProducer.h
Go to the documentation of this file.
1 #ifndef RecoTracker_TkTrackingRegions_GlobalTrackingRegionWithVerticesProducer_H
2 #define RecoTracker_TkTrackingRegions_GlobalTrackingRegionWithVerticesProducer_H
3 
17 
19 {
20 public:
21 
24  {
25  edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
26 
27  thePtMin = regionPSet.getParameter<double>("ptMin");
28  theOriginRadius = regionPSet.getParameter<double>("originRadius");
29  theNSigmaZ = regionPSet.getParameter<double>("nSigmaZ");
30  token_beamSpot = iC.consumes<reco::BeamSpot>(regionPSet.getParameter<edm::InputTag>("beamSpot"));
31  thePrecise = regionPSet.getParameter<bool>("precise");
32  theUseMS = regionPSet.getParameter<bool>("useMultipleScattering");
33 
34  theSigmaZVertex = regionPSet.getParameter<double>("sigmaZVertex");
35  theFixedError = regionPSet.getParameter<double>("fixedError");
36 
37  theMaxNVertices = regionPSet.getParameter<int>("maxNVertices");
38 
39  theUseFoundVertices = regionPSet.getParameter<bool>("useFoundVertices");
40  theUseFakeVertices = regionPSet.getParameter<bool>("useFakeVertices");
41  theUseFixedError = regionPSet.getParameter<bool>("useFixedError");
42  token_vertex = iC.consumes<reco::VertexCollection>(regionPSet.getParameter<edm::InputTag>("VertexCollection"));
43 
44  //information for Heavy ion region scaling
45  theOriginRScaling = regionPSet.getParameter<bool>("originRScaling4BigEvts");
46  thePtMinScaling = regionPSet.getParameter<bool>("ptMinScaling4BigEvts");
47  theHalfLengthScaling = regionPSet.getParameter<bool>("halfLengthScaling4BigEvts");
48  theMinOriginR = regionPSet.getParameter<double>("minOriginR");
49  theMaxPtMin = regionPSet.getParameter<double>("maxPtMin");
50  theMinHalfLength = regionPSet.getParameter<double>("minHalfLength");
51  theScalingStart = regionPSet.getParameter<double>("scalingStartNPix");
52  theScalingEnd = regionPSet.getParameter<double>("scalingEndNPix");
53  edm::InputTag pixelClustersForScaling = regionPSet.getParameter< edm::InputTag >("pixelClustersForScaling");
54  if(theOriginRScaling || thePtMinScaling || theHalfLengthScaling) token_pc = iC.consumes<edmNew::DetSetVector<SiPixelCluster> >(pixelClustersForScaling);
55  }
56 
58 
59  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
61 
62  desc.add<bool>("precise", true);
63  desc.add<bool>("useMultipleScattering", false);
64  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
65  desc.add<bool>("useFixedError", true);
66  desc.add<double>("originRadius", 0.2);
67  desc.add<double>("sigmaZVertex", 3.0);
68  desc.add<double>("fixedError", 0.2);
69  desc.add<edm::InputTag>("VertexCollection", edm::InputTag("firstStepPrimaryVertices"));
70  desc.add<double>("ptMin", 0.9);
71  desc.add<bool>("useFoundVertices", true);
72  desc.add<bool>("useFakeVertices", false);
73  desc.add<int>("maxNVertices", -1)->setComment("-1 for all vertices");
74  desc.add<double>("nSigmaZ", 4.0);
75  desc.add<edm::InputTag>("pixelClustersForScaling",edm::InputTag("siPixelClusters"));
76  desc.add<bool>("originRScaling4BigEvts",false);
77  desc.add<bool>("ptMinScaling4BigEvts",false);
78  desc.add<bool>("halfLengthScaling4BigEvts",false);
79  desc.add<double>("minOriginR",0);
80  desc.add<double>("maxPtMin",1000);
81  desc.add<double>("minHalfLength",0);
82  desc.add<double>("scalingStartNPix",0.0);
83  desc.add<double>("scalingEndNPix",1.0);
84 
85  // Only for backwards-compatibility
87  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
88 
89  descriptions.add("globalTrackingRegionWithVertices", descRegion);
90  }
91 
92  std::vector<std::unique_ptr<TrackingRegion> > regions
93  (const edm::Event& ev, const edm::EventSetup&) const override
94  {
95  std::vector<std::unique_ptr<TrackingRegion> > result;
96 
97  GlobalPoint theOrigin;
99  ev.getByToken( token_beamSpot, bsHandle);
100  double bsSigmaZ;
101  if(bsHandle.isValid()) {
102  const reco::BeamSpot & bs = *bsHandle;
103  bsSigmaZ = theNSigmaZ*bs.sigmaZ();
104  theOrigin = GlobalPoint(bs.x0(), bs.y0(), bs.z0());
105  }else{
106  throw cms::Exception("Seeding") << "ERROR: input beamSpot is not valid in GlobalTrackingRegionWithVertices";
107  }
108 
110  {
112  ev.getByToken(token_vertex,vertexCollection);
113 
116  if(doScaling) ev.getByToken(token_pc, pixelClusterDSV);
117 
118  for(reco::VertexCollection::const_iterator iV=vertexCollection->begin(); iV != vertexCollection->end() ; iV++) {
119  if (!iV->isValid()) continue;
120  if (iV->isFake() && !(theUseFakeVertices && theUseFixedError)) continue;
121  GlobalPoint theOrigin_ = GlobalPoint(iV->x(),iV->y(),iV->z());
122 
123  //scaling origin radius, half length, min pt for high-occupancy HI events to keep timing reasonable
124  if(doScaling){
125  //Use the unscaled radius unless one of the two conditions below is met
126  double scaledOriginRadius = theOriginRadius;
127  double scaledHalfLength = theFixedError;
128  double scaledPtMin = thePtMin;
129 
130  //calculate nPixels (adapted from TkSeedGenerator/src/ClusterChecker.cc)
131  double nPix = 0;
132 
133  const edmNew::DetSetVector<SiPixelCluster> & input = *pixelClusterDSV;
134  nPix = input.dataSize();
135 
136  //first condition is for high occupancy, second makes sure we won't divide by zero or a negative number
137  if((nPix > theScalingEnd) || ((theScalingEnd-theScalingStart) <= 0)){
138  if(theOriginRScaling) scaledOriginRadius = theMinOriginR; // sets parameters to minimum value from PSet
139  if(theHalfLengthScaling) scaledHalfLength = theMinHalfLength;
140  if(thePtMinScaling) scaledPtMin = theMaxPtMin;
141  }
142  //second condition - scale radius linearly by Npix in the region from ScalingStart to ScalingEnd
143  else if((nPix <= theScalingEnd) && (nPix > theScalingStart)){
144  float slopeFactor = (nPix-theScalingStart)/(theScalingEnd-theScalingStart);
145  if(theOriginRScaling) scaledOriginRadius = theOriginRadius - (theOriginRadius-theMinOriginR)*slopeFactor;
146  if(theHalfLengthScaling) scaledHalfLength = theFixedError - (theFixedError-theMinHalfLength)*slopeFactor;
147  if(thePtMinScaling) scaledPtMin = thePtMin - (thePtMin-theMaxPtMin)*slopeFactor;
148  }
149  //if region has 0 size, return 'result' empty, otherwise make a tracking region
150  if(scaledOriginRadius!=0 && scaledHalfLength !=0){
151  result.push_back( std::make_unique<GlobalTrackingRegion>( scaledPtMin, theOrigin_, scaledOriginRadius, scaledHalfLength, thePrecise,theUseMS));
152  }
153  }//end of region scaling code, pp behavior below
154 
155  else{
156  double theOriginHalfLength_ = (theUseFixedError ? theFixedError : (iV->zError())*theSigmaZVertex);
157  result.push_back( std::make_unique<GlobalTrackingRegion>(thePtMin, theOrigin_, theOriginRadius, theOriginHalfLength_, thePrecise, theUseMS) );
158  if(theMaxNVertices >= 0 && result.size() >= static_cast<unsigned>(theMaxNVertices)) break;
159  }
160  }
161 
162  if (result.empty() && !(theOriginRScaling || thePtMinScaling || theHalfLengthScaling)) {
163  result.push_back( std::make_unique<GlobalTrackingRegion>(thePtMin, theOrigin, theOriginRadius, bsSigmaZ, thePrecise, theUseMS) );
164  }
165  }
166  else
167  {
168  result.push_back(
169  std::make_unique<GlobalTrackingRegion>(thePtMin, theOrigin, theOriginRadius, bsSigmaZ, thePrecise, theUseMS) );
170  }
171 
172  return result;
173  }
174 
175 private:
176  double thePtMin;
178  double theNSigmaZ;
180 
185  bool theUseMS;
186 
192 
193  //HI-related variables
198  double theMaxPtMin;
203 
204 };
205 
206 #endif
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double z0() const
z coordinate
Definition: BeamSpot.h:68
size_type dataSize() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::EDGetTokenT< reco::VertexCollection > token_vertex
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > token_pc
static std::string const input
Definition: EdmProvDump.cc:45
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
void add(std::string const &label, ParameterSetDescription const &psetDescription)
GlobalTrackingRegionWithVerticesProducer(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
double y0() const
y coordinate
Definition: BeamSpot.h:66
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &ev, const edm::EventSetup &) const override
double x0() const
x coordinate
Definition: BeamSpot.h:64