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 {
27 bool isBPIXFED(unsigned int fed) {return fed< 32;}
28 bool isFPIXFED(unsigned int fed) {return fed>=32;}
29 bool isBPIXModule(unsigned int id) {return DetId(id).subdetId() == PixelSubdetector::PixelBarrel;}
30 bool isFPIXModule(unsigned int id) {return DetId(id).subdetId() == PixelSubdetector::PixelEndcap;}
31 
32 inline std::ostream& operator<<(std::ostream& s, const PixelUnpackingRegions::Module& m)
33 {
34  s<< (isBPIXModule(m.id) ? "BPIX " : "FPIX ") <<m.id<<" "<<m.fed<<" "<<m.phi<<" "<<m.x<<" "<<m.y<<" "<<m.z<<" "<<sqrt(std::pow(m.x,2)+std::pow(m.y,2));
35  return s;
36 }
37 }
38 
39 
40 
42 {
43  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("Regions");
44  beamSpotTag_ = regPSet.getParameter<edm::InputTag>("beamSpot");
45  inputs_ = regPSet.getParameter<std::vector<edm::InputTag> >("inputs");
46  dPhi_ = regPSet.getParameter<std::vector<double> >("deltaPhi");
47  maxZ_ = regPSet.getParameter<std::vector<double> >("maxZ");
48 
49  tBeamSpot = iC.consumes<reco::BeamSpot>(beamSpotTag_);
50  for (unsigned int t=0; t<inputs_.size(); t++ ) tCandidateView.push_back(iC.consumes< reco::CandidateView >(inputs_[t]));
51 
52  if (inputs_.size() != dPhi_.size() || dPhi_.size() != maxZ_.size() )
53  {
54  edm::LogError("PixelUnpackingRegions")<<"Not the same size of config parameters vectors!\n"
55  <<" inputs "<<inputs_.size()<<" deltaPhi "<<dPhi_.size() <<" maxZ "<< maxZ_.size();
56  }
57 }
58 
59 
61 {
62  feds_.clear();
63  modules_.clear();
64  nreg_ = 0;
65 
66  initialize(es);
67 
69  e.getByToken(tBeamSpot, beamSpot);
70  beamSpot_ = beamSpot->position();
71  //beamSpot_ = math::XYZPoint(0.,0.,0.);
72 
73  size_t ninputs = inputs_.size();
74  for(size_t input = 0; input < ninputs; ++input)
75  {
78 
79  size_t n = h->size();
80  for(size_t i = 0; i < n; ++i )
81  {
82  const reco::Candidate & c = (*h)[i];
83 
84  // different input collections can have different dPhi and maxZ
86  addRegion(r);
87  }
88  }
89 }
90 
91 
93 {
94  // initialize cabling map or update it if necessary
95  // and re-cache modules information
97  {
99  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
100  cabling_ = cablingMap->cablingTree();
101 
103  // get the TrackerGeom
104  es.get<TrackerDigiGeometryRecord>().get( geom );
105 
106  phiBPIX_.clear();
107  phiFPIXp_.clear();
108  phiFPIXm_.clear();
109 
110  phiBPIX_.reserve(1024);
111  phiFPIXp_.reserve(512);
112  phiFPIXm_.reserve(512);
113 
114  auto it = geom->dets().begin();
115  for ( ; it != geom->dets().end(); ++it)
116  {
117  int subdet = (*it)->geographicalId().subdetId();
118  if (! (subdet == PixelSubdetector::PixelBarrel ||
119  subdet == PixelSubdetector::PixelEndcap) ) continue;
120 
121  Module m;
122 
123  m.x = (*it)->position().x();
124  m.y = (*it)->position().y();
125  m.z = (*it)->position().z();
126 
127  m.phi = normalizedPhi( (*it)->position().phi() ); // ensure [-pi,+pi]
128 
129  m.id = (*it)->geographicalId().rawId();
130  const std::vector<sipixelobjects::CablingPathToDetUnit> path2det = cabling_->pathToDetUnit(m.id);
131 
132  m.fed = path2det[0].fed;
133  assert(m.fed<40);
134 
135  if (subdet == PixelSubdetector::PixelBarrel)
136  {
137  phiBPIX_.push_back(m);
138  }
139  else if (subdet == PixelSubdetector::PixelEndcap)
140  {
141  if (m.z > 0.) phiFPIXp_.push_back(m);
142  else phiFPIXm_.push_back(m);
143  }
144  }
145 
146  // pre-sort by phi
147  std::sort(phiBPIX_.begin(), phiBPIX_.end());
148  std::sort(phiFPIXp_.begin(), phiFPIXp_.end());
149  std::sort(phiFPIXm_.begin(), phiFPIXm_.end());
150  }
151 }
152 
153 
155 {
156  ++nreg_;
157 
158  float phi = normalizedPhi(r.v.phi()); // ensure [-pi,+pi]
159 
160  Module lo(phi - r.dPhi);
161  Module hi(phi + r.dPhi);
162 
163  addRegionLocal(r, phiBPIX_, lo, hi);
164  if (r.v.eta() > 1.)
165  {
166  addRegionLocal(r, phiFPIXp_, lo, hi);
167  }
168  if (r.v.eta() < -1.)
169  {
170  addRegionLocal(r, phiFPIXm_, lo, hi);
171  }
172 }
173 
174 
175 void PixelUnpackingRegions::addRegionLocal(Region &r, std::vector<Module> &container,const Module& _lo,const Module& _hi)
176 {
177  Module lo = _lo;
178  Module hi = _hi;
179  Module pi_m(-M_PI);
180  Module pi_p( M_PI);
181 
182  std::vector<Module>::const_iterator a, b;
183 
184  if (lo.phi >= -M_PI && hi.phi <= M_PI) // interval doesn't cross the +-pi overlap
185  {
186  a = lower_bound(container.begin(), container.end(), lo);
187  b = upper_bound(container.begin(), container.end(), hi);
188  gatherFromRange(r, a, b);
189  }
190  else // interval is torn by the +-pi overlap
191  {
192  if (hi.phi > M_PI) hi.phi -= 2.*M_PI;
193  a = lower_bound(container.begin(), container.end(), pi_m);
194  b = upper_bound(container.begin(), container.end(), hi);
195  gatherFromRange(r, a, b);
196 
197  if (lo.phi < -M_PI) lo.phi += 2.*M_PI;
198  a = lower_bound(container.begin(), container.end(), lo);
199  b = upper_bound(container.begin(), container.end(), pi_p);
200  gatherFromRange(r, a, b);
201  }
202 }
203 
204 
205 void PixelUnpackingRegions::gatherFromRange(Region &r, std::vector<Module>::const_iterator a, std::vector<Module>::const_iterator b)
206 {
207  for(; a != b; ++a)
208  {
209  // projection in r's direction onto beam's z
210  float zmodule = a->z - ( (a->x - beamSpot_.x())*r.cosphi + (a->y - beamSpot_.y())*r.sinphi ) * r.atantheta;
211 
212  // do not include modules that project too far in z
213  if ( std::abs(zmodule) > r.maxZ ) continue;
214 
215  feds_.insert(a->fed);
216  modules_.insert(a->id);
217  }
218 }
219 
220 
221 bool PixelUnpackingRegions::mayUnpackFED(unsigned int fed_n) const
222 {
223  if (feds_.count(fed_n)) return true;
224  return false;
225 }
226 
228 {
229  return std::count_if(feds_.begin(), feds_.end(), isBPIXFED );
230 }
231 
233 {
234  return std::count_if(feds_.begin(), feds_.end(), isFPIXFED );
235 }
236 
237 
238 bool PixelUnpackingRegions::mayUnpackModule(unsigned int id) const
239 {
240  if (modules_.count(id)) return true;
241  return false;
242 }
243 
245 {
246  return std::count_if(modules_.begin(), modules_.end(), isBPIXModule );
247 }
248 
250 {
251  return std::count_if(modules_.begin(), modules_.end(), isFPIXModule );
252 }
T getParameter(std::string const &) const
bool mayUnpackModule(unsigned int id) const
check whether a module has to be unpacked
int i
Definition: DBlmapReader.cc:9
void addRegionLocal(Region &r, std::vector< Module > &container, const Module &lo, const Module &hi)
unsigned int nForwardFEDs() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< edm::EDGetTokenT< reco::CandidateView > > tCandidateView
void gatherFromRange(Region &r, std::vector< Module >::const_iterator, std::vector< Module >::const_iterator)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
PixelUnpackingRegions(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
static std::string const input
Definition: EdmProvDump.cc:44
std::vector< Module > phiFPIXm_
std::unique_ptr< SiPixelFedCablingTree > cabling_
virtual Vector momentum() const =0
spatial momentum vector
edm::ESWatcher< SiPixelFedCablingMapRcd > watcherSiPixelFedCablingMap_
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int nBarrelModules() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define M_PI
tuple conf
Definition: dbtoconf.py:185
void run(const edm::Event &e, const edm::EventSetup &es)
has to be run during each event
Definition: DetId.h:18
std::vector< edm::InputTag > inputs_
std::vector< Module > phiFPIXp_
const T & get() const
Definition: EventSetup.h:55
double b
Definition: hdecay.h:120
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:58
unsigned int nForwardModules() const
double a
Definition: hdecay.h:121
unsigned int nBarrelFEDs() const
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
std::vector< double > maxZ_
std::vector< Module > phiBPIX_
double normalizedPhi(double phi)
Definition: normalizedPhi.cc:5
edm::EDGetTokenT< reco::BeamSpot > tBeamSpot
std::set< unsigned int > feds_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::set< unsigned int > modules_
Definition: DDAxes.h:10