CMS 3D CMS Logo

ConversionSeedFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ConversionSeedFilter
4 // Class: ConversionSeedFilter
5 //
13 //
14 // Original Author: Giuseppe Cerati & Domenico Giordano
15 // Created: Thu Mar 11 10:48:48 CET 2010
16 //
17 //
18 
19 #include <memory>
40 
42 public:
43  explicit ConversionSeedFilter(const edm::ParameterSet&);
44  ~ConversionSeedFilter() override;
45 
46 private:
47  void produce(edm::Event&, const edm::EventSetup&) override;
48  bool isCompatible(double *vars1, double* vars2);
49  void getKine(const TrajectoryStateOnSurface& tsos, double *vars);
50  void SearchAmongSeeds(const TrajectorySeedCollection* pInPos,const TrajectorySeedCollection* pInNeg, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl1, std::vector<bool>& idxPosColl2);
51  void SearchAmongTracks(const TrajectorySeedCollection* pInSeed,const reco::TrackCollection* pInTk, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl);
52  void SearchAmongTrajectories(const TrajectorySeedCollection* pInSeed,const Trajectory* InTj, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl);
53 
57 
62 
65  uint32_t maxInputSeeds;
66  bool takeAll;
67 };
68 
70  //inputCollTkPos(cfg.getParameter<edm::InputTag>("tkCollectionPos")),
71  inputCollSeedPos(consumes<TrajectorySeedCollection>(cfg.getParameter<edm::InputTag>("seedCollectionPos"))),
72  //inputCollTkNeg(cfg.getParameter<edm::InputTag>("tkCollectionNeg")),
73  inputCollSeedNeg(consumes<TrajectorySeedCollection>(cfg.getParameter<edm::InputTag>("seedCollectionNeg"))),
74  inputTrajectory(consumes<TrajTrackAssociationCollection>(cfg.getParameter<edm::InputTag>("inputTrajectory"))),
75  deltaPhiCut(cfg.getParameter<double>("deltaPhiCut")),
76  deltaCotThetaCut(cfg.getParameter<double>("deltaCotThetaCut")),
77  deltaRCut(cfg.getParameter<double>("deltaRCut")),
78  deltaZCut(cfg.getParameter<double>("deltaZCut")),
79  maxInputSeeds(cfg.getParameter<uint32_t>("maxInputSeeds")),
80  takeAll(cfg.getParameter<bool>("takeAll"))
81 {
82  produces<TrajectorySeedCollection>();
83 }
84 
85 
87 
88 
90  using namespace edm;
91  using namespace std;
94 
95  // Handle<reco::TrackCollection> pInTkPos; iEvent.getByLabel(inputCollTkPos,pInTkPos);
96  // Handle<reco::TrackCollection> pInTkNeg; iEvent.getByLabel(inputCollTkNeg,pInTkNeg);
97 
98  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociations; iEvent.getByToken(inputTrajectory,trajTrackAssociations);
99 
100  iSetup.get<TrackerDigiGeometryRecord>().get(theG);
101  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
102 
103  auto result = std::make_unique<TrajectorySeedCollection>();
104 
105  TrajectorySeedCollection selectedColl;
106 
107  if(takeAll){
108  result->insert(result->end(),pInPos->begin(),pInPos->end());
109  result->insert(result->end(),pInNeg->begin(),pInNeg->end());
110  }else{
111  edm::LogInfo("ConversionSeedFilter") << "takeAll " << takeAll ;
112  if (pInPos->size()<maxInputSeeds && pInNeg->size()<maxInputSeeds) {
113 
114  std::vector<bool> idxPosColl1(pInPos->size(),false);
115  std::vector<bool> idxPosColl2(pInNeg->size(),false);
116  selectedColl.reserve(pInPos->size());
117 
118  edm::LogInfo("ConversionSeedFilter") << "New Event \t Pos " << pInPos->size() << " \t Neg " << pInNeg->size() << std::endl;
119 
120  SearchAmongSeeds(pInPos.product(),pInNeg.product(),selectedColl,idxPosColl1,idxPosColl2);
121  //SearchAmongTracks(pInPos.product(),pInTkNeg.product(),selectedColl,idxPosColl1);
122  //SearchAmongTracks(pInNeg.product(),pInTkPos.product(),selectedColl,idxPosColl2);
123 
124  if(trajTrackAssociations.isValid()){
125  edm::LogInfo("ConversionSeedFilter") << "Reconstructed tracks " << trajTrackAssociations->size() << std::endl;
126  for( TrajTrackAssociationCollection::const_iterator association = trajTrackAssociations->begin();
127  association != trajTrackAssociations->end(); association++) {
128  const Trajectory* traj = association->key.get();
129  const reco::Track* track = association->val.get();
130 
131  //edm::LogInfo("ConversionSeedFilter") << "Traj charge " << track->charge() << std::endl;
132 
133  if(track->charge()<0){SearchAmongTrajectories(pInPos.product(),traj,selectedColl,idxPosColl1);}
134  else {SearchAmongTrajectories(pInNeg.product(),traj,selectedColl,idxPosColl2);}
135 
136  }
137  }
138  }
139  result->insert(result->end(),selectedColl.begin(),selectedColl.end());
140  }
141 
142 
143  edm::LogInfo("ConversionSeedFilter") << "\nNew Event : result size " << result->size()<< std::endl;
144 
145  iEvent.put(std::move(result));
146 
147 }
148 
149 
151 SearchAmongSeeds(const TrajectorySeedCollection* pInPos,const TrajectorySeedCollection* pInNeg, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl1, std::vector<bool>& idxPosColl2){
152 
153  for (TrajectorySeedCollection::const_iterator iS1=pInPos->begin(); iS1!=pInPos->end(); ++iS1){
154  bool pushed1 = false;
155 
156  double vars1[4];
157  getKine(getTSOS(*iS1),vars1);
158 
159  for (TrajectorySeedCollection::const_iterator iS2=pInNeg->begin(); iS2!=pInNeg->end(); ++iS2){
160 
161  double vars2[4];
162  getKine(getTSOS(*iS2),vars2);
163 
164  if(isCompatible(vars1,vars2)){
165  edm::LogInfo("ConversionSeedFilter") << "[SearchAmongSeeds] match in pos " << iS1-pInPos->begin() << " " << iS2-pInNeg->begin() << std::endl;
166  if (!pushed1) {
167  idxPosColl1[iS1-pInPos->begin()]=true;
168  selectedColl.push_back(*iS1);
169  pushed1 = true;
170  }
171  if(!idxPosColl2[iS2-pInNeg->begin()]){
172  selectedColl.push_back(*iS2);
173  idxPosColl2[iS2-pInNeg->begin()]=true;
174  }
175  }
176  }
177  }
178 }
179 
181 SearchAmongTracks(const TrajectorySeedCollection* pInSeed,const reco::TrackCollection* pInTk, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl){
182 
183  for (TrajectorySeedCollection::const_iterator iS1=pInSeed->begin(); iS1!=pInSeed->end(); ++iS1){
184 
185  if(idxPosColl[iS1-pInSeed->begin()])
186  continue;
187 
188  double vars1[4];
189  getKine(getTSOS(*iS1),vars1);
190 
191  for (reco::TrackCollection::const_iterator iS2=pInTk->begin(); iS2!=pInTk->end(); ++iS2){
192 
193  double vars2[4];
194  getKine(getTSOS(*iS2),vars2);
195 
196  if(isCompatible(vars1,vars2)){
197  edm::LogInfo("ConversionSeedFilter") << "[SearchAmongTracks] match in pos " << iS1-pInSeed->begin() << std::endl;
198  idxPosColl[iS1-pInSeed->begin()]=true;
199  selectedColl.push_back(*iS1);
200  continue;
201  }
202  }
203  }
204 }
205 
207 SearchAmongTrajectories(const TrajectorySeedCollection* pInSeed,const Trajectory* InTj, TrajectorySeedCollection& selectedColl, std::vector<bool>& idxPosColl){
208 
209  for (TrajectorySeedCollection::const_iterator iS1=pInSeed->begin(); iS1!=pInSeed->end(); ++iS1){
210 
211  if(idxPosColl[iS1-pInSeed->begin()])
212  continue;
213 
214  double vars1[4];
215  getKine(getTSOS(*iS1),vars1);
216 
217  double vars2[4];
218  getKine(getTSOS(*InTj,*iS1),vars2);
219 
220  if(isCompatible(vars1,vars2)){
221  edm::LogInfo("ConversionSeedFilter") << "[SearchAmongTrajectories] match seed in pos " << iS1-pInSeed->begin() << " of " << pInSeed->size() << " seed charge " << iS1->startingState().parameters().charge()<<std::endl;
222  idxPosColl[iS1-pInSeed->begin()]=true;
223  selectedColl.push_back(*iS1);
224  }
225  }
226 }
227 
230 
232  DetId detId(state.detId());
234 }
235 
237 getTSOS(const reco::Track& tk){
239 }
240 
242 getTSOS(const Trajectory& tj, const TrajectorySeed& ts){
243 
245  DetId detId(state.detId());
246  GlobalPoint p = theG->idToDet(detId)->surface().toGlobal(state.parameters().position());
247  return tj.closestMeasurement(p).updatedState();
248 }
249 
251 isCompatible(double *vars1, double* vars2){
252 
253  double deltaPhi = fabs(reco::deltaPhi(vars1[0],vars2[0]) );
254  double deltaCotTheta = fabs( vars1[1]-vars2[1] );
255  double deltaR = fabs( vars1[2]-vars2[2] );
256  double deltaZ = fabs( vars1[3]-vars2[3] );
257  /*
258  std::cout << "\nnewCheck" << std::endl;
259  if(deltaPhi>deltaPhiCut) std::cout << "\nko deltaphi" << deltaPhi;
260  if(deltaCotTheta>deltaCotThetaCut ) std::cout << "\nko deltaCt " << deltaCotTheta;
261  if(deltaR>deltaRCut ) std::cout << "\nko deltaR " << deltaR;
262  if(deltaZ>deltaZCut ) std::cout << "\nko deltaZ " << deltaZ;
263  if(deltaPhi<deltaPhiCut && deltaCotTheta<deltaCotThetaCut && deltaR<deltaRCut && deltaZ<deltaZCut) std::cout << "\nok :)\n";
264  */
265  return deltaPhi<deltaPhiCut && deltaCotTheta<deltaCotThetaCut && deltaR<deltaRCut && deltaZ<deltaZCut;
266 
267 }
268 
270 getKine(const TrajectoryStateOnSurface& tsos, double *vars){
271 
272  vars[0] = tsos.globalMomentum().phi(); //phi
273  vars[1] = 2/tan(tsos.globalMomentum().theta()); //cotTheta
274  vars[2] = tsos.globalPosition().perp(); //R
275  vars[3] = tsos.globalPosition().z(); //Z
276 }
277 
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
void getKine(const TrajectoryStateOnSurface &tsos, double *vars)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
T perp() const
Definition: PV3DBase.h:72
const_iterator end() const
last iterator over the map (read only)
edm::EDGetTokenT< TrajectorySeedCollection > inputCollSeedNeg
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
LocalPoint position() const
Local x and y position coordinates.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
GlobalPoint globalPosition() const
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
Definition: Trajectory.cc:256
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
edm::EDGetTokenT< TrajectorySeedCollection > inputCollSeedPos
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
edm::EDGetTokenT< TrajTrackAssociationCollection > inputTrajectory
void SearchAmongSeeds(const TrajectorySeedCollection *pInPos, const TrajectorySeedCollection *pInNeg, TrajectorySeedCollection &selectedColl, std::vector< bool > &idxPosColl1, std::vector< bool > &idxPosColl2)
TrajectoryStateOnSurface getTSOS(const TrajectorySeed &ts)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TrajectorySeed > TrajectorySeedCollection
T z() const
Definition: PV3DBase.h:64
void SearchAmongTrajectories(const TrajectorySeedCollection *pInSeed, const Trajectory *InTj, TrajectorySeedCollection &selectedColl, std::vector< bool > &idxPosColl)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
unsigned int detId() const
bool isValid() const
Definition: HandleBase.h:74
ConversionSeedFilter(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
edm::ESHandle< MagneticField > theMF
bool isCompatible(double *vars1, double *vars2)
Definition: DetId.h:18
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
size_type size() const
map size
T const * product() const
Definition: Handle.h:74
HLT enums.
GlobalVector globalMomentum() const
T get() const
Definition: EventSetup.h:71
const TrackerGeomDet * idToDet(DetId) const override
void SearchAmongTracks(const TrajectorySeedCollection *pInSeed, const reco::TrackCollection *pInTk, TrajectorySeedCollection &selectedColl, std::vector< bool > &idxPosColl)
int charge() const
track electric charge
Definition: TrackBase.h:606
TrajectoryStateOnSurface const & updatedState() const
const_iterator begin() const
first iterator over the map (read only)
vars
Definition: DeepTauId.cc:77
edm::ESHandle< TrackerGeometry > theG
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
const LocalTrajectoryParameters & parameters() const
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)