CMS 3D CMS Logo

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