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 // $Id: PixelUnpackingRegions.cc,v 1.3 2012/03/19 06:58:18 khotilov Exp $
3 //
5 
10 
14 
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 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  if (inputs_.size() != dPhi_.size() || dPhi_.size() != maxZ_.size() )
50  {
51  edm::LogError("PixelUnpackingRegions")<<"Not the same size of config parameters vectors!\n"
52  <<" inputs "<<inputs_.size()<<" deltaPhi "<<dPhi_.size() <<" maxZ "<< maxZ_.size();
53  }
54 }
55 
56 
58 {
59  feds_.clear();
60  modules_.clear();
61  nreg_ = 0;
62 
63  initialize(es);
64 
66  e.getByLabel(beamSpotTag_, beamSpot);
67  beamSpot_ = beamSpot->position();
68  //beamSpot_ = math::XYZPoint(0.,0.,0.);
69 
70  size_t ninputs = inputs_.size();
71  for(size_t input = 0; input < ninputs; ++input)
72  {
74  e.getByLabel(inputs_[input], h);
75 
76  size_t n = h->size();
77  for(size_t i = 0; i < n; ++i )
78  {
79  const reco::Candidate & c = (*h)[i];
80 
81  // different input collections can have different dPhi and maxZ
83  addRegion(r);
84  }
85  }
86 }
87 
88 
90 {
91  // initialize cabling map or update it if necessary
92  // and re-cache modules information
94  {
96  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
97  cabling_.reset((SiPixelFedCabling*)cablingMap->cablingTree());
98 
100  // get the TrackerGeom
101  es.get<TrackerDigiGeometryRecord>().get( geom );
102 
103  phiBPIX_.clear();
104  phiFPIXp_.clear();
105  phiFPIXm_.clear();
106 
107  phiBPIX_.reserve(1024);
108  phiFPIXp_.reserve(512);
109  phiFPIXm_.reserve(512);
110 
111  std::vector<GeomDet*>::const_iterator it = geom->dets().begin();
112  for ( ; it != geom->dets().end(); ++it)
113  {
114  int subdet = (*it)->geographicalId().subdetId();
115  if (! (subdet == PixelSubdetector::PixelBarrel ||
116  subdet == PixelSubdetector::PixelEndcap) ) continue;
117 
118  Module m;
119 
120  m.x = (*it)->position().x();
121  m.y = (*it)->position().y();
122  m.z = (*it)->position().z();
123 
124  m.phi = normalizedPhi( (*it)->position().phi() ); // ensure [-pi,+pi]
125 
126  m.id = (*it)->geographicalId().rawId();
127  const std::vector<sipixelobjects::CablingPathToDetUnit> path2det = cabling_->pathToDetUnit(m.id);
128 
129  m.fed = path2det[0].fed;
130  assert(m.fed<40);
131 
132  if (subdet == PixelSubdetector::PixelBarrel)
133  {
134  phiBPIX_.push_back(m);
135  }
136  else if (subdet == PixelSubdetector::PixelEndcap)
137  {
138  if (m.z > 0.) phiFPIXp_.push_back(m);
139  else phiFPIXm_.push_back(m);
140  }
141  }
142 
143  // pre-sort by phi
144  std::sort(phiBPIX_.begin(), phiBPIX_.end());
145  std::sort(phiFPIXp_.begin(), phiFPIXp_.end());
146  std::sort(phiFPIXm_.begin(), phiFPIXm_.end());
147  }
148 }
149 
150 
152 {
153  ++nreg_;
154 
155  float phi = normalizedPhi(r.v.phi()); // ensure [-pi,+pi]
156 
157  Module lo(phi - r.dPhi);
158  Module hi(phi + r.dPhi);
159 
160  addRegionLocal(r, phiBPIX_, lo, hi);
161  if (r.v.eta() > 1.)
162  {
163  addRegionLocal(r, phiFPIXp_, lo, hi);
164  }
165  if (r.v.eta() < -1.)
166  {
167  addRegionLocal(r, phiFPIXm_, lo, hi);
168  }
169 }
170 
171 
172 void PixelUnpackingRegions::addRegionLocal(Region &r, std::vector<Module> &container, Module lo, Module hi)
173 {
174  Module pi_m(-M_PI);
175  Module pi_p( M_PI);
176 
177  std::vector<Module>::const_iterator a, b;
178 
179  if (lo.phi >= -M_PI && hi.phi <= M_PI) // interval doesn't cross the +-pi overlap
180  {
181  a = lower_bound(container.begin(), container.end(), lo);
182  b = upper_bound(container.begin(), container.end(), hi);
183  gatherFromRange(r, a, b);
184  }
185  else // interval is torn by the +-pi overlap
186  {
187  if (hi.phi > M_PI) hi.phi -= 2.*M_PI;
188  a = lower_bound(container.begin(), container.end(), pi_m);
189  b = upper_bound(container.begin(), container.end(), hi);
190  gatherFromRange(r, a, b);
191 
192  if (lo.phi < -M_PI) lo.phi += 2.*M_PI;
193  a = lower_bound(container.begin(), container.end(), lo);
194  b = upper_bound(container.begin(), container.end(), pi_p);
195  gatherFromRange(r, a, b);
196  }
197 }
198 
199 
200 void PixelUnpackingRegions::gatherFromRange(Region &r, std::vector<Module>::const_iterator a, std::vector<Module>::const_iterator b)
201 {
202  for(; a != b; ++a)
203  {
204  // projection in r's direction onto beam's z
205  float zmodule = a->z - ( (a->x - beamSpot_.x())*r.cosphi + (a->y - beamSpot_.y())*r.sinphi ) * r.atantheta;
206 
207  // do not include modules that project too far in z
208  if ( std::abs(zmodule) > r.maxZ ) continue;
209 
210  feds_.insert(a->fed);
211  modules_.insert(a->id);
212  }
213 }
214 
215 
216 bool PixelUnpackingRegions::mayUnpackFED(unsigned int fed_n) const
217 {
218  if (feds_.count(fed_n)) return true;
219  return false;
220 }
221 
223 {
224  return std::count_if(feds_.begin(), feds_.end(), isBPIXFED );
225 }
226 
228 {
229  return std::count_if(feds_.begin(), feds_.end(), isFPIXFED );
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
int i
Definition: DBlmapReader.cc:9
unsigned int nForwardFEDs() const
#define abs(x)
Definition: mlp_lapack.h:159
void gatherFromRange(Region &r, std::vector< Module >::const_iterator, std::vector< Module >::const_iterator)
boost::scoped_ptr< SiPixelFedCabling > cabling_
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
std::vector< Module > phiFPIXm_
PixelUnpackingRegions(const edm::ParameterSet &)
virtual Vector momentum() const =0
spatial momentum vector
edm::ESWatcher< SiPixelFedCablingMapRcd > watcherSiPixelFedCablingMap_
T sqrt(T t)
Definition: SSEVec.h:48
unsigned int nBarrelModules() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
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:20
#define M_PI
Definition: BFit3D.cc:3
void addRegionLocal(Region &r, std::vector< Module > &container, Module lo, Module hi)
std::vector< edm::InputTag > inputs_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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:59
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
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