CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedFilter.cc
Go to the documentation of this file.
1 // Package: EgammaElectronAlgos
2 // Class: SeedFilter.
3 
6 
7 
10 
14 #include <vector>
15 
17 
22 
24 
26 
28 
31 
32 using namespace std;
33 using namespace reco;
34 
36  const SeedFilter::Tokens& tokens,
38  {
39  edm::LogInfo("EtaPhiRegionSeedFactory") << "Enter the EtaPhiRegionSeedFactory";
40  edm::ParameterSet regionPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
41 
42  ptmin_ = regionPSet.getParameter<double>("ptMin");
43  originradius_ = regionPSet.getParameter<double>("originRadius");
44  halflength_ = regionPSet.getParameter<double>("originHalfLength");
45  deltaEta_ = regionPSet.getParameter<double>("deltaEtaRegion");
46  deltaPhi_ = regionPSet.getParameter<double>("deltaPhiRegion");
47  useZvertex_ = regionPSet.getParameter<bool>("useZInVertex");
48  vertexSrc_ = tokens.token_vtx;
49 
50  // setup orderedhits setup (in order to tell seed generator to use pairs/triplets, which layers)
51  edm::ParameterSet hitsfactoryPSet = conf.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet");
52  std::string hitsfactoryName = hitsfactoryPSet.getParameter<std::string>("ComponentName");
53 
54  // HIT FACTORY MODE (JRV)
55  // -1 = look for existing hit collections for both pixels and strips
56  // 0 = look for pixel hit collections and build strip hits on demand (regional unpacking)
57  // 1 = build both pixel and strip hits on demand (regional unpacking)
58  //
59  // FIXME: when next time altering the configuration of this class,
60  // please consider changing the type of useOnDemandTracker to a
61  // string corresponding to the UseMeasurementTracker enumeration
62  int tmp = hitsfactoryPSet.getUntrackedParameter<int>("useOnDemandTracker");
63  if(tmp < -1 || tmp > 1)
64  throw cms::Exception("Configuration") << "SeedFilter: useOnDemandTracker must be -1, 0, or 1; got " << tmp;
66 
67  // get orderd hits generator from factory
68  OrderedHitsGenerator* hitsGenerator = OrderedHitsGeneratorFactory::get()->create(hitsfactoryName, hitsfactoryPSet, iC);
69 
70  // start seed generator
71  edm::ParameterSet seedCreatorPSet = conf.getParameter<edm::ParameterSet>("SeedCreatorPSet");
72  std::string seedCreatorType = seedCreatorPSet.getParameter<std::string>("ComponentName");
73 
74  combinatorialSeedGenerator = new SeedGeneratorFromRegionHits(hitsGenerator,0,
75  SeedCreatorFactory::get()->create(seedCreatorType, seedCreatorPSet)
76  );
77  beamSpotTag_ = tokens.token_bs; ;
79  measurementTrackerToken_ = iC.consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("measurementTrackerEvent"));
80  }
81  }
82 
84  delete combinatorialSeedGenerator;
85 }
86 
88 
89  setup.get<IdealMagneticFieldRecord>().get(theMagField);
90  std::auto_ptr<TrajectorySeedCollection> seedColl(new TrajectorySeedCollection());
91 
92  GlobalPoint vtxPos;
93  double deltaZVertex;
94 
95  //edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
96  //e.getByType(recoBeamSpotHandle);
97 
98  // gets its position
99  //const reco::BeamSpot::Point& BSPosition = recoBeamSpotHandle->position();
100  //vtxPos = GlobalPoint(BSPosition.x(), BSPosition.y(), BSPosition.z());
101  //double sigmaZ = recoBeamSpotHandle->sigmaZ();
102  //double sigmaZ0Error = recoBeamSpotHandle->sigmaZ0Error();
103  //double sq=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
104  //deltaZVertex = 3*sq; //halflength_;
105 
106  // get the primary vertex (if any)
109  if (e.getByToken(vertexSrc_, h_vertices)) {
110  vertices = *(h_vertices.product());
111  } else {
112  LogDebug("SeedFilter") << "SeedFilter::seeds"
113  << "No vertex collection found: using beam-spot";
114  }
115 
116  if (!vertices.empty() && useZvertex_) {
117  vtxPos = GlobalPoint(vertices.front().x(), vertices.front().y(), vertices.front().z());
118  deltaZVertex = halflength_;
119 
120  } else {
121  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
122  //e.getByType(recoBeamSpotHandle);
123  e.getByToken(beamSpotTag_,recoBeamSpotHandle);
124  // gets its position
125  const reco::BeamSpot::Point& BSPosition = recoBeamSpotHandle->position();
126  double sigmaZ = recoBeamSpotHandle->sigmaZ();
127  double sigmaZ0Error = recoBeamSpotHandle->sigmaZ0Error();
128  double sq=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
129  vtxPos = GlobalPoint(BSPosition.x(), BSPosition.y(), BSPosition.z());
130  deltaZVertex = 3*sq;
131  }
132 
134  if(!measurementTrackerToken_.isUninitialized()) {
136  e.getByToken(measurementTrackerToken_, hmte);
137  measurementTracker = hmte.product();
138  }
139 
140  //seeds selection
141  float energy = scRef->energy();
142 
143  const GlobalPoint clusterPos(scRef->position().x(), scRef->position().y(), scRef->position().z());
144 
145  //===============================================
146  // EtaPhiRegion and seeds for electron hypothesis
147  //===============================================
148 
149  TrackCharge aCharge = -1 ;
150  FreeTrajectoryState fts = FTSFromVertexToPointFactory::get(*theMagField, clusterPos, vtxPos, energy, aCharge);
151 
152  RectangularEtaPhiTrackingRegion etaphiRegionMinus(fts.momentum(),
153  vtxPos,
154  ptmin_,
155  originradius_,
156  deltaZVertex,
157  // deltaEta_,
158  // deltaPhi_,-1);
161  ,hitsfactoryMode_,
162  true, /*default in header*/
164  );
165  combinatorialSeedGenerator->run(*seedColl, etaphiRegionMinus, e, setup);
166 
167  for (unsigned int i = 0; i<seedColl->size(); ++i)
168  output->push_back((*seedColl)[i]);
169 
170  seedColl->clear();
171 
172  //===============================================
173  // EtaPhiRegion and seeds for positron hypothesis
174  //===============================================
175 
176  TrackCharge aChargep = 1 ;
177  fts = FTSFromVertexToPointFactory::get(*theMagField, clusterPos, vtxPos, energy, aChargep);
178 
179  RectangularEtaPhiTrackingRegion etaphiRegionPlus(fts.momentum(),
180  vtxPos,
181  ptmin_,
182  originradius_,
183  deltaZVertex,
184  // deltaEta_,
185  // deltaPhi_,-1);
188  ,hitsfactoryMode_
189  ,true, /*default in header*/
191  );
192 
193  combinatorialSeedGenerator->run(*seedColl, etaphiRegionPlus, e, setup);
194 
195  for (unsigned int i = 0; i<seedColl->size(); ++i){
196  TrajectorySeed::range r = (*seedColl)[i].recHits();
197  // first Hit
198  TrajectorySeed::const_iterator it = r.first;
199  const TrackingRecHit* a1 = &(*it);
200  // now second Hit
201  it++;
202  const TrackingRecHit* a2 = &(*it);
203  // check if the seed is already in the collection
204  bool isInCollection = false;
205  for(unsigned int j=0; j<output->size(); ++j) {
206  TrajectorySeed::range r = (*seedColl)[i].recHits();
207  // first Hit
208  TrajectorySeed::const_iterator it = r.first;
209  const TrackingRecHit* b1 = &(*it);
210  // now second Hit
211  it++;
212  const TrackingRecHit* b2 = &(*it);
213  if ((b1->sharesInput(a1, TrackingRecHit::all)) && (b2->sharesInput(a2, TrackingRecHit::all))) {
214  isInCollection = true;
215  break;
216  }
217  }
218  if (!isInCollection)
219  output->push_back((*seedColl)[i]);
220  }
221 
222  seedColl->clear();
223 }
224 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static FreeTrajectoryState get(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
SeedFilter(const edm::ParameterSet &conf, const Tokens &tokens, edm::ConsumesCollector &iC)
Definition: SeedFilter.cc:35
void seeds(edm::Event &, const edm::EventSetup &, const reco::SuperClusterRef &, TrajectorySeedCollection *)
Definition: SeedFilter.cc:87
int TrackCharge
Definition: TrackCharge.h:4
std::vector< TrajectorySeed > TrajectorySeedCollection
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:48
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
GlobalVector momentum() const
tuple conf
Definition: dbtoconf.py:185
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
edm::EDGetTokenT< reco::BeamSpot > token_bs
Definition: SeedFilter.h:37
static UseMeasurementTracker intToUseMeasurementTracker(int value)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
SurfaceDeformation * create(int type, const std::vector< double > &params)
TkTrackingRegionsMargin< float > Margin
T get(const Candidate &c)
Definition: component.h:55
edm::EDGetTokenT< std::vector< reco::Vertex > > token_vtx
Definition: SeedFilter.h:36