CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelUnpackingRegions.cc
Go to the documentation of this file.
1 //
2 //
4 
9 
13 
20 
21 #include <algorithm>
22 #include <iterator>
23 
24 // local convenience functions
25 namespace {
26  bool isBPIXModule(unsigned int id) { return DetId(id).subdetId() == PixelSubdetector::PixelBarrel; }
27  bool isFPIXModule(unsigned int id) { return DetId(id).subdetId() == PixelSubdetector::PixelEndcap; }
28 } // namespace
29 
31  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("Regions");
32  beamSpotTag_ = regPSet.getParameter<edm::InputTag>("beamSpot");
33  inputs_ = regPSet.getParameter<std::vector<edm::InputTag> >("inputs");
34  dPhi_ = regPSet.getParameter<std::vector<double> >("deltaPhi");
35  maxZ_ = regPSet.getParameter<std::vector<double> >("maxZ");
36 
37  tBeamSpot = iC.consumes<reco::BeamSpot>(beamSpotTag_);
38  for (unsigned int t = 0; t < inputs_.size(); t++)
39  tCandidateView.push_back(iC.consumes<reco::CandidateView>(inputs_[t]));
40 
41  if (inputs_.size() != dPhi_.size() || dPhi_.size() != maxZ_.size()) {
42  edm::LogError("PixelUnpackingRegions")
43  << "Not the same size of config parameters vectors!\n"
44  << " inputs " << inputs_.size() << " deltaPhi " << dPhi_.size() << " maxZ " << maxZ_.size();
45  }
46 }
47 
49  feds_.clear();
50  modules_.clear();
51  nreg_ = 0;
52 
53  initialize(es);
54 
56  e.getByToken(tBeamSpot, beamSpot);
57  beamSpot_ = beamSpot->position();
58  //beamSpot_ = math::XYZPoint(0.,0.,0.);
59 
60  size_t ninputs = inputs_.size();
61  for (size_t input = 0; input < ninputs; ++input) {
64 
65  size_t n = h->size();
66  for (size_t i = 0; i < n; ++i) {
67  const reco::Candidate& c = (*h)[i];
68 
69  // different input collections can have different dPhi and maxZ
71  addRegion(r);
72  }
73  }
74 }
75 
77  // initialize cabling map or update it if necessary
78  // and re-cache modules information
81  es.get<SiPixelFedCablingMapRcd>().get(cablingMap);
82  cabling_ = cablingMap->cablingTree();
83 
85  // get the TrackerGeom
86  es.get<TrackerDigiGeometryRecord>().get(geom);
87 
88  // switch on the phase1
89  unsigned int fedMin = FEDNumbering::MINSiPixelFEDID; // phase0
90  unsigned int fedMax = FEDNumbering::MAXSiPixelFEDID;
92  fedMin = FEDNumbering::MINSiPixeluTCAFEDID; // phase1
94  }
95 
96  phiBPIX_.clear();
97  phiFPIXp_.clear();
98  phiFPIXm_.clear();
99 
100  phiBPIX_.reserve(1024);
101  phiFPIXp_.reserve(512);
102  phiFPIXm_.reserve(512);
103 
104  auto it = geom->dets().begin();
105  for (; it != geom->dets().end(); ++it) {
106  int subdet = (*it)->geographicalId().subdetId();
107  if (!(subdet == PixelSubdetector::PixelBarrel || subdet == PixelSubdetector::PixelEndcap))
108  continue;
109 
110  Module m;
111 
112  m.x = (*it)->position().x();
113  m.y = (*it)->position().y();
114  m.z = (*it)->position().z();
115 
116  m.phi = (*it)->position().phi();
117 
118  m.id = (*it)->geographicalId().rawId();
119  const std::vector<sipixelobjects::CablingPathToDetUnit> path2det = cabling_->pathToDetUnit(m.id);
120 
121  m.fed = path2det[0].fed;
122  assert((m.fed <= fedMax) && (m.fed >= fedMin));
123 
124  if (subdet == PixelSubdetector::PixelBarrel) {
125  phiBPIX_.push_back(m);
126  } else if (subdet == PixelSubdetector::PixelEndcap) {
127  if (m.z > 0.)
128  phiFPIXp_.push_back(m);
129  else
130  phiFPIXm_.push_back(m);
131  }
132  }
133 
134  // pre-sort by phi
135  std::sort(phiBPIX_.begin(), phiBPIX_.end());
136  std::sort(phiFPIXp_.begin(), phiFPIXp_.end());
137  std::sort(phiFPIXm_.begin(), phiFPIXm_.end());
138  }
139 }
140 
142  ++nreg_;
143 
144  float phi = r.v.phi();
145 
146  Module lo(phi - r.dPhi);
147  Module hi(phi + r.dPhi);
148 
149  addRegionLocal(r, phiBPIX_, lo, hi);
150  if (r.v.eta() > 1.) {
151  addRegionLocal(r, phiFPIXp_, lo, hi);
152  }
153  if (r.v.eta() < -1.) {
154  addRegionLocal(r, phiFPIXm_, lo, hi);
155  }
156 }
157 
159  std::vector<Module>& container,
160  const Module& _lo,
161  const Module& _hi) {
162  Module lo = _lo;
163  Module hi = _hi;
164  Module pi_m(-M_PI);
165  Module pi_p(M_PI);
166 
167  std::vector<Module>::const_iterator a, b;
168 
169  if (lo.phi >= -M_PI && hi.phi <= M_PI) // interval doesn't cross the +-pi overlap
170  {
171  a = lower_bound(container.begin(), container.end(), lo);
172  b = upper_bound(container.begin(), container.end(), hi);
173  gatherFromRange(r, a, b);
174  } else // interval is torn by the +-pi overlap
175  {
176  if (hi.phi > M_PI)
177  hi.phi -= 2. * M_PI;
178  a = lower_bound(container.begin(), container.end(), pi_m);
179  b = upper_bound(container.begin(), container.end(), hi);
180  gatherFromRange(r, a, b);
181 
182  if (lo.phi < -M_PI)
183  lo.phi += 2. * M_PI;
184  a = lower_bound(container.begin(), container.end(), lo);
185  b = upper_bound(container.begin(), container.end(), pi_p);
186  gatherFromRange(r, a, b);
187  }
188 }
189 
191  std::vector<Module>::const_iterator a,
192  std::vector<Module>::const_iterator b) {
193  for (; a != b; ++a) {
194  // projection in r's direction onto beam's z
195  float zmodule = a->z - ((a->x - beamSpot_.x()) * r.cosphi + (a->y - beamSpot_.y()) * r.sinphi) * r.atantheta;
196 
197  // do not include modules that project too far in z
198  if (std::abs(zmodule) > r.maxZ)
199  continue;
200 
201  feds_.insert(a->fed);
202  modules_.insert(a->id);
203  }
204 }
205 
206 bool PixelUnpackingRegions::mayUnpackFED(unsigned int fed_n) const {
207  if (feds_.count(fed_n))
208  return true;
209  return false;
210 }
211 
212 bool PixelUnpackingRegions::mayUnpackModule(unsigned int id) const {
213  if (modules_.count(id))
214  return true;
215  return false;
216 }
217 
219  return std::count_if(modules_.begin(), modules_.end(), isBPIXModule);
220 }
221 
223  return std::count_if(modules_.begin(), modules_.end(), isFPIXModule);
224 }
T getParameter(std::string const &) const
bool mayUnpackModule(unsigned int id) const
check whether a module has to be unpacked
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void addRegionLocal(Region &r, std::vector< Module > &container, const Module &lo, const Module &hi)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< edm::EDGetTokenT< reco::CandidateView > > tCandidateView
size_type size() const
void gatherFromRange(Region &r, std::vector< Module >::const_iterator, std::vector< Module >::const_iterator)
PixelUnpackingRegions(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
static std::string const input
Definition: EdmProvDump.cc:48
std::vector< Module > phiFPIXm_
bool isThere(GeomDetEnumerators::SubDetector subdet) const
std::unique_ptr< SiPixelFedCablingTree > cabling_
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
edm::ESWatcher< SiPixelFedCablingMapRcd > watcherSiPixelFedCablingMap_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int nBarrelModules() const
#define M_PI
void run(const edm::Event &e, const edm::EventSetup &es)
has to be run during each event
Definition: DetId.h:17
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
std::vector< edm::InputTag > inputs_
std::vector< Module > phiFPIXp_
double b
Definition: hdecay.h:118
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
virtual Vector momentum() const =0
spatial momentum vector
unsigned int nForwardModules() const
double a
Definition: hdecay.h:119
T get() const
Definition: EventSetup.h:73
bool mayUnpackFED(unsigned int fed_n) const
check whether a FED has to be unpacked
std::vector< double > dPhi_
void initialize(const edm::EventSetup &es)
run by the run method: (re)initialize the cabling data when it&#39;s necessary
const Point & position() const
position
Definition: BeamSpot.h:59
std::vector< double > maxZ_
std::vector< Module > phiBPIX_
edm::EDGetTokenT< reco::BeamSpot > tBeamSpot
std::set< unsigned int > feds_
std::set< unsigned int > modules_