test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConversionProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ConversionProducer
4 // Class: ConversionProducer
5 //
13 //
14 // Original Authors: Hongliang Liu
15 // Created: Thu Mar 13 17:40:48 CDT 2008
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <map>
23 
24 
30 
35 
38 
39 
41 
44 
48 
51 
58 
59 
60 //Kinematic constraint vertex fitter
70 
71 
72 
74  theVertexFinder_(0)
75 
76 {
77  algoName_ = iConfig.getParameter<std::string>( "AlgorithmName" );
78 
79  src_ =
80  consumes<edm::View<reco::ConversionTrack> >(iConfig.getParameter<edm::InputTag>("src"));
81 
82  maxNumOfTrackInPU_ = iConfig.getParameter<int>("maxNumOfTrackInPU");
83  maxTrackRho_ = iConfig.getParameter<double>("maxTrackRho");
84  maxTrackZ_ = iConfig.getParameter<double>("maxTrackZ");
85 
86  allowTrackBC_ = iConfig.getParameter<bool>("AllowTrackBC");
87  allowD0_ = iConfig.getParameter<bool>("AllowD0");
88  allowDeltaPhi_ = iConfig.getParameter<bool>("AllowDeltaPhi");
89  allowDeltaCot_ = iConfig.getParameter<bool>("AllowDeltaCot");
90  allowMinApproach_ = iConfig.getParameter<bool>("AllowMinApproach");
91  allowOppCharge_ = iConfig.getParameter<bool>("AllowOppCharge");
92 
93  allowVertex_ = iConfig.getParameter<bool>("AllowVertex");
94 
95  bypassPreselGsf_ = iConfig.getParameter<bool>("bypassPreselGsf");
96  bypassPreselEcal_ = iConfig.getParameter<bool>("bypassPreselEcal");
97  bypassPreselEcalEcal_ = iConfig.getParameter<bool>("bypassPreselEcalEcal");
98 
99  deltaEta_ = iConfig.getParameter<double>("deltaEta");
100 
101  halfWayEta_ = iConfig.getParameter<double>("HalfwayEta");//open angle to search track matches with BC
102 
103  d0Cut_ = iConfig.getParameter<double>("d0");
104 
105  usePvtx_ = iConfig.getParameter<bool>("UsePvtx");//if use primary vertices
106 
107  vertexProducer_ =
108  consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexProducer"));
109 
110 
111  //Track-cluster matching eta and phi cuts
112  dEtaTkBC_ = iConfig.getParameter<double>("dEtaTrackBC");//TODO research on cut endcap/barrel
113  dPhiTkBC_ = iConfig.getParameter<double>("dPhiTrackBC");
114 
116  consumes<edm::View<reco::CaloCluster> >(iConfig.getParameter<edm::InputTag>("bcBarrelCollection"));
118  consumes<edm::View<reco::CaloCluster> >(iConfig.getParameter<edm::InputTag>("bcEndcapCollection"));
119 
121  consumes<edm::View<reco::CaloCluster> >(iConfig.getParameter<edm::InputTag>("scBarrelProducer"));
123  consumes<edm::View<reco::CaloCluster> >(iConfig.getParameter<edm::InputTag>("scEndcapProducer"));
124 
125  energyBC_ = iConfig.getParameter<double>("EnergyBC");//BC energy threshold
126  energyTotalBC_ = iConfig.getParameter<double>("EnergyTotalBC");//BC energy threshold
127  minSCEt_ = iConfig.getParameter<double>("minSCEt");//super cluster energy threshold
128  dEtacutForSCmatching_ = iConfig.getParameter<double>("dEtacutForSCmatching");// dEta between conversion momentum direction and SC position
129  dPhicutForSCmatching_ = iConfig.getParameter<double>("dPhicutForSCmatching");// dPhi between conversion momentum direction and SC position
130 
131 
132 
133 
134  //Track cuts on left right track: at least one leg reaches ECAL
135  //Left track: must exist, must reach Ecal and match BC, so loose cut on Chi2 and tight on hits
136  //Right track: not necessary to exist (if allowSingleLeg_), not necessary to reach ECAL or match BC, so tight cut on Chi2 and loose on hits
137  maxChi2Left_ = iConfig.getParameter<double>("MaxChi2Left");
138  maxChi2Right_ = iConfig.getParameter<double>("MaxChi2Right");
139  minHitsLeft_ = iConfig.getParameter<int>("MinHitsLeft");
140  minHitsRight_ = iConfig.getParameter<int>("MinHitsRight");
141 
142  //Track Open angle cut on delta cot(theta) and delta phi
143  deltaCotTheta_ = iConfig.getParameter<double>("DeltaCotTheta");
144  deltaPhi_ = iConfig.getParameter<double>("DeltaPhi");
145  minApproachLow_ = iConfig.getParameter<double>("MinApproachLow");
146  minApproachHigh_ = iConfig.getParameter<double>("MinApproachHigh");
147 
148 
149  // if allow single track collection, by default False
150  allowSingleLeg_ = iConfig.getParameter<bool>("AllowSingleLeg");
151  rightBC_ = iConfig.getParameter<bool>("AllowRightBC");
152 
153  //track inner position dz cut, need RECO
154  dzCut_ = iConfig.getParameter<double>("dz");
155  //track analytical cross cut
156  r_cut = iConfig.getParameter<double>("rCut");
157  vtxChi2_ = iConfig.getParameter<double>("vtxChi2");
158 
159 
160  theVertexFinder_ = new ConversionVertexFinder ( iConfig );
161 
162  thettbuilder_ = 0;
163 
164  //output
165  ConvertedPhotonCollection_ = iConfig.getParameter<std::string>("convertedPhotonCollection");
166 
167  produces< reco::ConversionCollection >(ConvertedPhotonCollection_);
168 
169 }
170 
171 
173 {
174 
175  // do anything here that needs to be done at desctruction time
176  // (e.g. close files, deallocate resources etc.)
177  delete theVertexFinder_;
178 }
179 
180 
181 // ------------ method called to produce the data ------------
182 void
184 {
185  using namespace edm;
186 
187  reco::ConversionCollection outputConvPhotonCollection;
188  std::auto_ptr<reco::ConversionCollection> outputConvPhotonCollection_p(new reco::ConversionCollection);
189 
190  //std::cout << " ConversionProducer::produce " << std::endl;
191  //Read multiple track input collections
192 
193  edm::Handle<edm::View<reco::ConversionTrack> > trackCollectionHandle;
194  iEvent.getByToken(src_,trackCollectionHandle);
195 
196  //build map of ConversionTracks ordered in eta
197  std::multimap<float, edm::Ptr<reco::ConversionTrack> > convTrackMap;
198  for (edm::PtrVector<reco::ConversionTrack>::const_iterator tk_ref = trackCollectionHandle->ptrVector().begin(); tk_ref != trackCollectionHandle->ptrVector().end(); ++tk_ref ){
199  convTrackMap.insert(std::make_pair((*tk_ref)->track()->eta(),*tk_ref));
200  }
201 
204  if (usePvtx_){
205  iEvent.getByToken(vertexProducer_, vertexHandle);
206  if (!vertexHandle.isValid()) {
207  edm::LogError("ConversionProducer")
208  << "Error! Can't get the product primary Vertex Collection "<< "\n";
209  usePvtx_ = false;
210  }
211  if (usePvtx_)
212  vertexCollection = *(vertexHandle.product());
213  }
214 
215  edm::ESHandle<TransientTrackBuilder> hTransientTrackBuilder;
216  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",hTransientTrackBuilder);
217  thettbuilder_ = hTransientTrackBuilder.product();
218 
219  reco::Vertex the_pvtx;
220  //because the priamry vertex is sorted by quality, the first one is the best
221  if (!vertexCollection.empty())
222  the_pvtx = *(vertexCollection.begin());
223 
224  if (trackCollectionHandle->size()> maxNumOfTrackInPU_){
225  iEvent.put( outputConvPhotonCollection_p, ConvertedPhotonCollection_);
226  return;
227  }
228 
229 
230  // build Super and Basic cluster geometry map to search in eta bounds for clusters
231  std::multimap<double, reco::CaloClusterPtr> basicClusterPtrs;
232  std::multimap<double, reco::CaloClusterPtr> superClusterPtrs;
233 
234 
235  buildSuperAndBasicClusterGeoMap(iEvent,basicClusterPtrs,superClusterPtrs);
236 
237  buildCollection( iEvent, iSetup, convTrackMap, superClusterPtrs, basicClusterPtrs, the_pvtx, outputConvPhotonCollection);//allow empty basicClusterPtrs
238 
239  outputConvPhotonCollection_p->assign(outputConvPhotonCollection.begin(), outputConvPhotonCollection.end());
240  iEvent.put( outputConvPhotonCollection_p, ConvertedPhotonCollection_);
241 
242 }
243 
244 
246  std::multimap<double, reco::CaloClusterPtr>& basicClusterPtrs,
247  std::multimap<double, reco::CaloClusterPtr>& superClusterPtrs){
248 
249  // Get the Super Cluster collection in the Barrel
251  iEvent.getByToken(scBarrelProducer_,scBarrelHandle);
252  if (!scBarrelHandle.isValid()) {
253  edm::LogError("ConvertedPhotonProducer")
254  << "Error! Can't get the barrel superclusters!";
255  }
256 
257  // Get the Super Cluster collection in the Endcap
259  iEvent.getByToken(scEndcapProducer_,scEndcapHandle);
260  if (!scEndcapHandle.isValid()) {
261  edm::LogError("ConvertedPhotonProducer")
262  << "Error! Can't get the endcap superclusters!";
263  }
264 
265 
267  edm::Handle<edm::View<reco::CaloCluster> > bcEndcapHandle;//TODO check cluster type if BasicCluster or PFCluster
268 
269  iEvent.getByToken( bcBarrelCollection_, bcBarrelHandle);
270  if (!bcBarrelHandle.isValid()) {
271  edm::LogError("ConvertedPhotonProducer")
272  << "Error! Can't get the barrel basic clusters!";
273  }
274 
275  iEvent.getByToken( bcEndcapCollection_, bcEndcapHandle);
276  if (! bcEndcapHandle.isValid()) {
277  edm::LogError("ConvertedPhotonProducer")
278  << "Error! Can't get the endcap basic clusters!";
279  }
280 
281  edm::Handle<edm::View<reco::CaloCluster> > bcHandle = bcBarrelHandle;
282  edm::Handle<edm::View<reco::CaloCluster> > scHandle = scBarrelHandle;
283 
284  if ( bcHandle.isValid() ) {
285  for (unsigned jj = 0; jj < 2; ++jj ){
286  for (unsigned ii = 0; ii < bcHandle->size(); ++ii ) {
287  if (bcHandle->ptrAt(ii)->energy()>energyBC_)
288  basicClusterPtrs.insert(std::make_pair(bcHandle->ptrAt(ii)->position().eta(), bcHandle->ptrAt(ii)));
289  }
290  bcHandle = bcEndcapHandle;
291  }
292  }
293 
294 
295  if ( scHandle.isValid() ) {
296  for (unsigned jj = 0; jj < 2; ++jj ){
297  for (unsigned ii = 0; ii < scHandle->size(); ++ii ) {
298  if (scHandle->ptrAt(ii)->energy()>minSCEt_)
299  superClusterPtrs.insert(std::make_pair(scHandle->ptrAt(ii)->position().eta(), scHandle->ptrAt(ii)));
300  }
301  scHandle = scEndcapHandle;
302  }
303  }
304 
305 
306 }
307 
308 
310  const std::multimap<float, edm::Ptr<reco::ConversionTrack> >& allTracks,
311  const std::multimap<double, reco::CaloClusterPtr>& superClusterPtrs,
312  const std::multimap<double, reco::CaloClusterPtr>& basicClusterPtrs,
313  const reco::Vertex& the_pvtx,
314  reco::ConversionCollection & outputConvPhotonCollection){
315 
316 
317  edm::ESHandle<TrackerGeometry> trackerGeomHandle;
318  edm::ESHandle<MagneticField> magFieldHandle;
319  iSetup.get<TrackerDigiGeometryRecord>().get( trackerGeomHandle );
320  iSetup.get<IdealMagneticFieldRecord>().get( magFieldHandle );
321 
322  const TrackerGeometry* trackerGeom = trackerGeomHandle.product();
323  const MagneticField* magField = magFieldHandle.product();
324 
325 // std::vector<math::XYZPointF> trackImpactPosition;
326 // trackImpactPosition.reserve(allTracks.size());//track impact position at ECAL
327 // std::vector<bool> trackValidECAL;//Does this track reach ECAL basic cluster (reach ECAL && match with BC)
328 // trackValidECAL.assign(allTracks.size(), false);
329 //
330 // std::vector<reco::CaloClusterPtr> trackMatchedBC;
331 // reco::CaloClusterPtr empty_bc;
332 // trackMatchedBC.assign(allTracks.size(), empty_bc);//TODO find a better way to avoid copy constructor
333 //
334 // std::vector<int> bcHandleId;//the associated BC handle id, -1 invalid, 0 barrel 1 endcap
335 // bcHandleId.assign(allTracks.size(), -1);
336 
337  // not used std::multimap<double, int> trackInnerEta;//Track innermost state Eta map to TrackRef index, to be used in track pair sorting
338 
339  std::map<edm::Ptr<reco::ConversionTrack>, math::XYZPointF> trackImpactPosition;
340  std::map<edm::Ptr<reco::ConversionTrack>, reco::CaloClusterPtr> trackMatchedBC;
341 
342  ConversionHitChecker hitChecker;
343 
344 
345  //2 propagate all tracks into ECAL, record its eta and phi
346 
347  for (std::multimap<float, edm::Ptr<reco::ConversionTrack> >::const_iterator tk_ref = allTracks.begin(); tk_ref != allTracks.end(); ++tk_ref ){
348  const reco::Track* tk = tk_ref->second->trackRef().get() ;
349 
350 
351  //check impact position then match with BC
352  math::XYZPointF ew;
353  if ( getTrackImpactPosition(tk, trackerGeom, magField, ew) ){
354  trackImpactPosition[tk_ref->second] = ew;
355 
356  reco::CaloClusterPtr closest_bc;//the closest matching BC to track
357 
358  if ( getMatchedBC(basicClusterPtrs, ew, closest_bc) ){
359  trackMatchedBC[tk_ref->second] = closest_bc;
360  }
361  }
362  }
363 
364 
365 
366  //3. pair up tracks:
367  //TODO it is k-Closest pair of point problem
368  //std::cout << " allTracks.size() " << allTracks.size() << std::endl;
369  for(std::multimap<float, edm::Ptr<reco::ConversionTrack> >::const_iterator ll = allTracks.begin(); ll != allTracks.end(); ++ll ) {
370  bool track1HighPurity=true;
371  //std::cout << " Loop on allTracks " << std::endl;
372  const edm::RefToBase<reco::Track> & left = ll->second->trackRef();
373 
374 
375  //TODO: This is a workaround, should be fixed with a proper function in the TTBuilder
376  //(Note that the TrackRef and GsfTrackRef versions of the constructor are needed
377  // to properly get refit tracks in the output vertex)
378  reco::TransientTrack ttk_l;
379  if (dynamic_cast<const reco::GsfTrack*>(left.get())) {
380  ttk_l = thettbuilder_->build(left.castTo<reco::GsfTrackRef>());
381  }
382  else {
383  ttk_l = thettbuilder_->build(left.castTo<reco::TrackRef>());
384  }
385 
387  // if ((allowTrackBC_ && !trackValidECAL[ll-allTracks.begin()]) )//this Left leg should have valid BC
388  // continue;
389 
390 
391  if (the_pvtx.isValid()){
392  if (!(trackD0Cut(left, the_pvtx))) track1HighPurity=false;
393  } else {
394  if (!(trackD0Cut(left))) track1HighPurity=false;
395  }
396 
397  std::vector<int> right_candidates;//store all right legs passed the cut (theta/approach and ref pair)
398  std::vector<double> right_candidate_theta, right_candidate_approach;
399  std::vector<std::pair<bool, reco::Vertex> > vertex_candidates;
400 
401  //inner loop only over tracks between eta and eta + deltaEta of the first track
402  float etasearch = ll->first + deltaEta_;
403  std::multimap<float, edm::Ptr<reco::ConversionTrack> >::const_iterator rr = ll;
404  ++rr;
405  for (; rr != allTracks.lower_bound(etasearch); ++rr ) {
406  bool track2HighPurity = true;
407  bool highPurityPair = true;
408 
409  const edm::RefToBase<reco::Track> & right = rr->second->trackRef();
410 
411 
412  //TODO: This is a workaround, should be fixed with a proper function in the TTBuilder
413  reco::TransientTrack ttk_r;
414  if (dynamic_cast<const reco::GsfTrack*>(right.get())) {
415  ttk_r = thettbuilder_->build(right.castTo<reco::GsfTrackRef>());
416  }
417  else {
418  ttk_r = thettbuilder_->build(right.castTo<reco::TrackRef>());
419  }
420  //std::cout << " This track is " << right->algoName() << std::endl;
421 
422 
423  //all vertexing preselection should go here
424 
425  //check for opposite charge
426  if ( allowOppCharge_ && (left->charge()*right->charge() > 0) )
427  continue; //same sign, reject pair
428 
430  //if ( (allowTrackBC_ && !trackValidECAL[rr-allTracks.begin()] && rightBC_) )// if right track matches ECAL
431  // continue;
432 
433 
434  double approachDist = -999.;
435  //apply preselection to track pair, overriding preselection for gsf+X or ecalseeded+X pairs if so configured
436  bool preselected = preselectTrackPair(ttk_l,ttk_r, approachDist);
437  preselected = preselected || (bypassPreselGsf_ && (left->algo()==29 || right->algo()==29));
438  preselected = preselected || (bypassPreselEcal_ && (left->algo()==15 || right->algo()==15 || left->algo()==16 || right->algo()==16));
439  preselected = preselected || (bypassPreselEcalEcal_ && (left->algo()==15 || left->algo()==16) && (right->algo()==15 || right->algo()==16));
440 
441  if (!preselected) {
442  continue;
443  }
444 
445  //do the actual vertex fit
446  reco::Vertex theConversionVertex;//by default it is invalid
447  bool goodVertex = checkVertex(ttk_l, ttk_r, magField, theConversionVertex);
448 
449  //bail as early as possible in case the fit didn't return a good vertex
450  if (!goodVertex) {
451  continue;
452  }
453 
454 
455 
456  //track pair pass the quality cut
457  if ( !( (trackQualityFilter(left, true) && trackQualityFilter(right, false))
458  || (trackQualityFilter(left, false) && trackQualityFilter(right, true)) ) ) {
459  highPurityPair=false;
460  }
461 
462  if (the_pvtx.isValid()){
463  if (!(trackD0Cut(right, the_pvtx))) track2HighPurity=false;
464  } else {
465  if (!(trackD0Cut(right))) track2HighPurity=false;
466  }
467 
468 
469  //if all cuts passed, go ahead to make conversion candidates
470  std::vector<edm::RefToBase<reco::Track> > trackPairRef;
471  trackPairRef.push_back(left);//left track
472  trackPairRef.push_back(right);//right track
473 
474  std::vector<math::XYZVectorF> trackPin;
475  std::vector<math::XYZVectorF> trackPout;
476  std::vector<math::XYZPointF> trackInnPos;
477  std::vector<uint8_t> nHitsBeforeVtx;
478  std::vector<Measurement1DFloat> dlClosestHitToVtx;
479 
480  if (left->extra().isNonnull() && right->extra().isNonnull()){//only available on TrackExtra
481  trackInnPos.push_back( toFConverterP(left->innerPosition()));
482  trackInnPos.push_back( toFConverterP(right->innerPosition()));
483  trackPin.push_back(toFConverterV(left->innerMomentum()));
484  trackPin.push_back(toFConverterV(right->innerMomentum()));
485  trackPout.push_back(toFConverterV(left->outerMomentum()));
486  trackPout.push_back(toFConverterV(right->outerMomentum()));
487  }
488 
489  if (ll->second->trajRef().isNonnull() && rr->second->trajRef().isNonnull()) {
490  std::pair<uint8_t,Measurement1DFloat> leftWrongHits = hitChecker.nHitsBeforeVtx(*ll->second->trajRef().get(),theConversionVertex);
491  std::pair<uint8_t,Measurement1DFloat> rightWrongHits = hitChecker.nHitsBeforeVtx(*rr->second->trajRef().get(),theConversionVertex);
492  nHitsBeforeVtx.push_back(leftWrongHits.first);
493  nHitsBeforeVtx.push_back(rightWrongHits.first);
494  dlClosestHitToVtx.push_back(leftWrongHits.second);
495  dlClosestHitToVtx.push_back(rightWrongHits.second);
496  }
497 
498  uint8_t nSharedHits = hitChecker.nSharedHits(*left.get(),*right.get());
499 
500 
501  //if using kinematic fit, check with chi2 post cut
502  if (theConversionVertex.isValid()){
503  const float chi2Prob = ChiSquaredProbability(theConversionVertex.chi2(), theConversionVertex.ndof());
504  if (chi2Prob<vtxChi2_) highPurityPair=false;
505  }
506 
507  //std::cout << " highPurityPair after vertex cut " << highPurityPair << std::endl;
508  std::vector<math::XYZPointF> trkPositionAtEcal;
509  std::vector<reco::CaloClusterPtr> matchingBC;
510 
511  if (allowTrackBC_){//TODO find out the BC ptrs if not doing matching, otherwise, leave it empty
512  //const int lbc_handle = bcHandleId[ll-allTracks.begin()],
513  // rbc_handle = bcHandleId[rr-allTracks.begin()];
514 
515  std::map<edm::Ptr<reco::ConversionTrack>, math::XYZPointF>::const_iterator trackImpactPositionLeft = trackImpactPosition.find(ll->second);
516  std::map<edm::Ptr<reco::ConversionTrack>, math::XYZPointF>::const_iterator trackImpactPositionRight = trackImpactPosition.find(rr->second);
517  std::map<edm::Ptr<reco::ConversionTrack>, reco::CaloClusterPtr>::const_iterator trackMatchedBCLeft = trackMatchedBC.find(ll->second);
518  std::map<edm::Ptr<reco::ConversionTrack>, reco::CaloClusterPtr>::const_iterator trackMatchedBCRight = trackMatchedBC.find(rr->second);
519 
520  if (trackImpactPositionLeft!=trackImpactPosition.end()) {
521  trkPositionAtEcal.push_back(trackImpactPositionLeft->second);//left track
522  }
523  else {
524  trkPositionAtEcal.push_back(math::XYZPointF());//left track
525  }
526  if (trackImpactPositionRight!=trackImpactPosition.end()) {//second track ECAL position may be invalid
527  trkPositionAtEcal.push_back(trackImpactPositionRight->second);
528  }
529 
530  double total_e_bc = 0.;
531  if (trackMatchedBCLeft!=trackMatchedBC.end()) {
532  matchingBC.push_back(trackMatchedBCLeft->second);//left track
533  total_e_bc += trackMatchedBCLeft->second->energy();
534  }
535  else {
536  matchingBC.push_back( reco::CaloClusterPtr() );//left track
537  }
538  if (trackMatchedBCRight!=trackMatchedBC.end()) {//second track ECAL position may be invalid
539  matchingBC.push_back(trackMatchedBCRight->second);
540  total_e_bc += trackMatchedBCRight->second->energy();
541  }
542 
543  if (total_e_bc<energyTotalBC_) {
544  highPurityPair = false;
545  }
546 
547 
548  }
549  //signature cuts, then check if vertex, then post-selection cuts
550  highPurityPair = highPurityPair && track1HighPurity && track2HighPurity && goodVertex && checkPhi(left, right, trackerGeom, magField, theConversionVertex) ;
551 
552 
554  /*
555  for ( std::vector<edm::RefToBase<reco::Track> >::iterator iTk=trackPairRef.begin(); iTk!=trackPairRef.end(); iTk++) {
556  math::XYZPointF impPos;
557  if ( getTrackImpactPosition(*iTk, trackerGeom, magField, impPos) ) {
558 
559  }
560 
561  }
562  */
563 
564  const float minAppDist = approachDist;
566  float dummy=0;
568  reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, nHitsBeforeVtx, dlClosestHitToVtx, nSharedHits, dummy, algo );
569  // Fill in scPtrVec with the macthing SC
570  if ( matchingSC ( superClusterPtrs, newCandidate, scPtrVec) )
571  newCandidate.setMatchingSuperCluster( scPtrVec);
572 
573  //std::cout << " ConversionProducer scPtrVec.size " << scPtrVec.size() << std::endl;
574 
575  newCandidate.setQuality(reco::Conversion::highPurity, highPurityPair);
576  bool generalTracksOnly = ll->second->isTrackerOnly() && rr->second->isTrackerOnly() && !dynamic_cast<const reco::GsfTrack*>(ll->second->trackRef().get()) && !dynamic_cast<const reco::GsfTrack*>(rr->second->trackRef().get());
577  bool arbitratedEcalSeeded = ll->second->isArbitratedEcalSeeded() && rr->second->isArbitratedEcalSeeded();
578  bool arbitratedMerged = ll->second->isArbitratedMerged() && rr->second->isArbitratedMerged();
579  bool arbitratedMergedEcalGeneral = ll->second->isArbitratedMergedEcalGeneral() && rr->second->isArbitratedMergedEcalGeneral();
580 
581  newCandidate.setQuality(reco::Conversion::generalTracksOnly, generalTracksOnly);
582  newCandidate.setQuality(reco::Conversion::arbitratedEcalSeeded, arbitratedEcalSeeded);
583  newCandidate.setQuality(reco::Conversion::arbitratedMerged, arbitratedMerged);
584  newCandidate.setQuality(reco::Conversion::arbitratedMergedEcalGeneral, arbitratedMergedEcalGeneral);
585 
586  outputConvPhotonCollection.push_back(newCandidate);
587 
588  }
589 
590  }
591 
592 
593 
594 
595 
596 
597 }
598 
599 
600 
601 
602 
603 //
604 // member functions
605 //
606 
608  bool pass = true;
609  if (isLeft){
610  pass = (ref->normalizedChi2() < maxChi2Left_ && ref->found() >= minHitsLeft_);
611  } else {
612  pass = (ref->normalizedChi2() < maxChi2Right_ && ref->found() >= minHitsRight_);
613  }
614 
615  return pass;
616 }
617 
619  //NOTE if not allow d0 cut, always true
620  return ((!allowD0_) || !(ref->d0()*ref->charge()/ref->d0Error()<d0Cut_));
621 }
622 
624  //
625  return ((!allowD0_) || !(-ref->dxy(the_pvtx.position())*ref->charge()/ref->dxyError()<d0Cut_));
626 }
627 
628 
630  const TrackerGeometry* trackerGeom, const MagneticField* magField,
631  math::XYZPointF& ew){
632 
633  PropagatorWithMaterial propag( alongMomentum, 0.000511, magField );
634 
636  new BoundCylinder(129.f, GlobalPoint(0.,0.,0.), TkRotation<float>(),
637  new SimpleCylinderBounds( 129, 129, -320.5, 320.5 ) ) );
638  const float epsilon = 0.001;
639  Surface::RotationType rot; // unit rotation matrix
640  const float barrelRadius = 129.f;
641  const float barrelHalfLength = 270.9f;
642  const float endcapRadius = 171.1f;
643  const float endcapZ = 320.5f;
644  ReferenceCountingPointer<BoundCylinder> theBarrel_(new BoundCylinder(barrelRadius, Surface::PositionType(0,0,0), rot,
645  new SimpleCylinderBounds( barrelRadius-epsilon, barrelRadius+epsilon,
646 -barrelHalfLength, barrelHalfLength)));
647  ReferenceCountingPointer<BoundDisk> theNegativeEtaEndcap_(
648  new BoundDisk( Surface::PositionType( 0, 0, -endcapZ), rot,
649  new SimpleDiskBounds( 0, endcapRadius, -epsilon, epsilon)));
650  ReferenceCountingPointer<BoundDisk> thePositiveEtaEndcap_(
651  new BoundDisk( Surface::PositionType( 0, 0, endcapZ), rot,
652  new SimpleDiskBounds( 0, endcapRadius, -epsilon, epsilon)));
653 
654  //const TrajectoryStateOnSurface myTSOS = trajectoryStateTransform::innerStateOnSurface(*(*ref), *trackerGeom, magField);
655  const TrajectoryStateOnSurface myTSOS = trajectoryStateTransform::outerStateOnSurface(*tk_ref, *trackerGeom, magField);
656  TrajectoryStateOnSurface stateAtECAL;
657  stateAtECAL = propag.propagate(myTSOS, *theBarrel_);
658  if (!stateAtECAL.isValid() || ( stateAtECAL.isValid() && fabs(stateAtECAL.globalPosition().eta() ) >1.479f ) ) {
659  //endcap propagator
660  if (myTSOS.globalPosition().z() > 0.) {
661  stateAtECAL = propag.propagate(myTSOS, *thePositiveEtaEndcap_);
662  } else {
663  stateAtECAL = propag.propagate(myTSOS, *theNegativeEtaEndcap_);
664  }
665  }
666  if (stateAtECAL.isValid()){
667  ew = stateAtECAL.globalPosition();
668  return true;
669  }
670  else
671  return false;
672 }
673 
674 
675 
676 
677 bool ConversionProducer::matchingSC(const std::multimap<double, reco::CaloClusterPtr>& scMap,
678  reco::Conversion& aConv,
679  // reco::CaloClusterPtr& mSC){
681 
682  // double dRMin=999.;
683  double detaMin=999.;
684  double dphiMin=999.;
686  for (std::multimap<double, reco::CaloClusterPtr>::const_iterator scItr = scMap.begin(); scItr != scMap.end(); scItr++) {
687  const reco::CaloClusterPtr& sc = scItr->second;
688  const double delta_phi = reco::deltaPhi( aConv.refittedPairMomentum().phi(), sc->phi());
689  double sceta = sc->eta();
690  double conveta = etaTransformation(aConv.refittedPairMomentum().eta(), aConv.zOfPrimaryVertexFromTracks() );
691  const double delta_eta = fabs(conveta - sceta);
692  if ( fabs(delta_eta) < fabs(detaMin) && fabs(delta_phi) < fabs(dphiMin) ) {
693  detaMin= fabs(delta_eta);
694  dphiMin= fabs(delta_phi);
695  match=sc;
696  }
697  }
698 
699  if ( fabs(detaMin) < dEtacutForSCmatching_ && fabs(dphiMin) < dPhicutForSCmatching_ ) {
700  mSC.push_back(match);
701  return true;
702  } else
703  return false;
704 }
705 
706 bool ConversionProducer::getMatchedBC(const std::multimap<double, reco::CaloClusterPtr>& bcMap,
707  const math::XYZPointF& trackImpactPosition,
708  reco::CaloClusterPtr& closestBC){
709  const double track_eta = trackImpactPosition.eta();
710  const double track_phi = trackImpactPosition.phi();
711 
712  double min_eta = 999., min_phi = 999.;
713  reco::CaloClusterPtr closest_bc;
714  for (std::multimap<double, reco::CaloClusterPtr>::const_iterator bc = bcMap.lower_bound(track_eta - halfWayEta_);
715  bc != bcMap.upper_bound(track_eta + halfWayEta_); ++bc){//use eta map to select possible BC collection then loop in
716  const reco::CaloClusterPtr& ebc = bc->second;
717  const double delta_eta = track_eta-(ebc->position().eta());
718  const double delta_phi = reco::deltaPhi(track_phi, (ebc->position().phi()));
719  if (fabs(delta_eta)<dEtaTkBC_ && fabs(delta_phi)<dPhiTkBC_){
720  if (fabs(min_eta)>fabs(delta_eta) && fabs(min_phi)>fabs(delta_phi)){//take the closest to track BC
721  min_eta = delta_eta;
722  min_phi = delta_phi;
723  closest_bc = bc->second;
724  //TODO check if min_eta>delta_eta but min_phi<delta_phi
725  }
726  }
727  }
728 
729  if (min_eta < 999.){
730  closestBC = closest_bc;
731  return true;
732  } else
733  return false;
734 }
735 
736 
737 
738 
739 
740 
741 //check track open angle of phi at vertex
743  const TrackerGeometry* trackerGeom, const MagneticField* magField,
744  const reco::Vertex& vtx){
745  if (!allowDeltaPhi_)
746  return true;
747  //if track has innermost momentum, check with innermost phi
748  //if track also has valid vertex, propagate to vertex then calculate phi there
749  //if track has no innermost momentum, just return true, because track->phi() makes no sense
750  if (tk_l->extra().isNonnull() && tk_r->extra().isNonnull()){
751  double iphi1 = tk_l->innerMomentum().phi(), iphi2 = tk_r->innerMomentum().phi();
752  if (vtx.isValid()){
753  PropagatorWithMaterial propag( anyDirection, 0.000511, magField );
754 
755  double recoPhoR = vtx.position().Rho();
758  new SimpleCylinderBounds( recoPhoR-0.001, recoPhoR+0.001,
759  -fabs(vtx.position().z()), fabs(vtx.position().z()))));
761  new BoundDisk( Surface::PositionType( 0, 0, vtx.position().z()), rot,
762  new SimpleDiskBounds( 0, recoPhoR, -0.001, 0.001)));
763 
764  const TrajectoryStateOnSurface myTSOS1 = trajectoryStateTransform::innerStateOnSurface(*tk_l, *trackerGeom, magField);
765  const TrajectoryStateOnSurface myTSOS2 = trajectoryStateTransform::innerStateOnSurface(*tk_r, *trackerGeom, magField);
766  TrajectoryStateOnSurface stateAtVtx1, stateAtVtx2;
767  stateAtVtx1 = propag.propagate(myTSOS1, *theBarrel_);
768  if (!stateAtVtx1.isValid() ) {
769  stateAtVtx1 = propag.propagate(myTSOS1, *theDisk_);
770  }
771  if (stateAtVtx1.isValid()){
772  iphi1 = stateAtVtx1.globalDirection().phi();
773  }
774  stateAtVtx2 = propag.propagate(myTSOS2, *theBarrel_);
775  if (!stateAtVtx2.isValid() ) {
776  stateAtVtx2 = propag.propagate(myTSOS2, *theDisk_);
777  }
778  if (stateAtVtx2.isValid()){
779  iphi2 = stateAtVtx2.globalDirection().phi();
780  }
781  }
782  const double dPhi = reco::deltaPhi(iphi1, iphi2);
783  return (fabs(dPhi) < deltaPhi_);
784  } else {
785  return true;
786  }
787 }
788 
790  double& appDist) {
791 
792 
793  double dCotTheta = 1./tan(ttk_l.track().innerMomentum().theta()) - 1./tan(ttk_r.track().innerMomentum().theta());
794  if (allowDeltaCot_ && (std::abs(dCotTheta) > deltaCotTheta_)) {
795  return false;
796  }
797 
798  //non-conversion hypothesis, reject prompt track pairs
799  ClosestApproachInRPhi closest;
801  if (!closest.status()) {
802  return false;
803  }
804 
805  if (closest.crossingPoint().perp() < r_cut) {
806  return false;
807  }
808 
809 
810  //compute tangent point btw tracks (conversion hypothesis)
811  TangentApproachInRPhi tangent;
813  if (!tangent.status()) {
814  return false;
815  }
816 
817  GlobalPoint tangentPoint = tangent.crossingPoint();
818  double rho = tangentPoint.perp();
819 
820  //reject candidates well outside of tracker bounds
821  if (rho > maxTrackRho_) {
822  return false;
823  }
824 
825  if (std::abs(tangentPoint.z()) > maxTrackZ_) {
826  return false;
827  }
828 
829  std::pair<GlobalTrajectoryParameters,GlobalTrajectoryParameters> trajs = tangent.trajectoryParameters();
830 
831  //very large separation in z, no hope
832  if (std::abs(trajs.first.position().z() - trajs.second.position().z()) > dzCut_) {
833  return false;
834  }
835 
836 
837  float minApproach = tangent.perpdist();
838  appDist = minApproach;
839 
840  if (allowMinApproach_ && (minApproach < minApproachLow_ || minApproach > minApproachHigh_) ) {
841  return false;
842  }
843 
844  return true;
845 
846 
847 }
848 
851 
852  const reco::CaloClusterPtr& bc_l = ll.second;//can be null, so check isNonnull()
853  const reco::CaloClusterPtr& bc_r = rr.second;
854 
855  //The cuts should be ordered by considering if takes time and if cuts off many fakes
856  if (allowTrackBC_){
857  //check energy of BC
858  double total_e_bc = 0;
859  if (bc_l.isNonnull()) total_e_bc += bc_l->energy();
860  if (rightBC_)
861  if (bc_r.isNonnull())
862  total_e_bc += bc_r->energy();
863 
864  if (total_e_bc < energyTotalBC_) return false;
865  }
866 
867  return true;
868 }
869 
870 
871 
872 //because reco::vertex uses track ref, so have to keep them
874  const MagneticField* magField,
875  reco::Vertex& the_vertex){
876  bool found = false;
877 
878  std::vector<reco::TransientTrack> pair;
879  pair.push_back(ttk_l);
880  pair.push_back(ttk_r);
881 
882  found = theVertexFinder_->run(pair, the_vertex);
883 
884 
885 
886  return found;
887 }
888 
889 
890 
891 double ConversionProducer::etaTransformation( float EtaParticle , float Zvertex) {
892 
893  //---Definitions
894  const float PI = 3.1415927;
895 
896  //---Definitions for ECAL
897  const float R_ECAL = 136.5;
898  const float Z_Endcap = 328.0;
899  const float etaBarrelEndcap = 1.479;
900 
901  //---ETA correction
902 
903  float Theta = 0.0 ;
904  float ZEcal = R_ECAL*sinh(EtaParticle)+Zvertex;
905 
906  if(ZEcal != 0.0) Theta = atan(R_ECAL/ZEcal);
907  if(Theta<0.0) Theta = Theta+PI ;
908  double ETA = - log(tan(0.5*Theta));
909 
910  if( fabs(ETA) > etaBarrelEndcap )
911  {
912  float Zend = Z_Endcap ;
913  if(EtaParticle<0.0 ) Zend = -Zend ;
914  float Zlen = Zend - Zvertex ;
915  float RR = Zlen/sinh(EtaParticle);
916  Theta = atan(RR/Zend);
917  if(Theta<0.0) Theta = Theta+PI ;
918  ETA = - log(tan(0.5*Theta));
919  }
920  //---Return the result
921  return ETA;
922  //---end
923 }
924 
T getParameter(std::string const &) const
unsigned int maxNumOfTrackInPU_
ConversionVertexFinder * theVertexFinder_
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
double d0Error() const
error on d0
Definition: TrackBase.h:209
edm::EDGetTokenT< reco::VertexCollection > vertexProducer_
double delta_eta(double eta1, double eta2)
Definition: AnglesUtil.h:98
TransientVertex run(const std::vector< reco::TransientTrack > &pair)
T perp() const
Definition: PV3DBase.h:72
static float barrelHalfLength()
double d0() const
dxy parameter in perigee convention (d0 = - dxy)
Definition: TrackBase.h:121
bool getTrackImpactPosition(const reco::Track *tk_ref, const TrackerGeometry *trackerGeom, const MagneticField *magField, math::XYZPointF &ew)
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:97
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field)
std::pair< GlobalTrajectoryParameters, GlobalTrajectoryParameters > trajectoryParameters() const
#define PI
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:109
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
double dxyError() const
error on dxy
Definition: TrackBase.h:207
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:138
std::pair< uint8_t, Measurement1DFloat > nHitsBeforeVtx(const Trajectory &traj, const reco::Vertex &vtx, double sigmaTolerance=3.0) const
const TransientTrackBuilder * thettbuilder_
void setQuality(ConversionQuality q, bool b)
Definition: Conversion.h:247
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:60
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void buildCollection(edm::Event &iEvent, const edm::EventSetup &iSetup, const std::multimap< float, edm::Ptr< reco::ConversionTrack > > &allTracks, const std::multimap< double, reco::CaloClusterPtr > &superClusterPtrs, const std::multimap< double, reco::CaloClusterPtr > &basicClusterPtrs, const reco::Vertex &the_pvtx, reco::ConversionCollection &outputConvPhotonCollection)
reco::TransientTrack build(const reco::Track *p) const
double zOfPrimaryVertexFromTracks(const math::XYZPoint &myBeamSpot=math::XYZPoint()) const
Definition: Conversion.h:145
Cylinder BoundCylinder
Definition: BoundCylinder.h:17
static ConversionAlgorithm algoByName(const std::string &name)
Definition: Conversion.cc:163
void buildSuperAndBasicClusterGeoMap(const edm::Event &, std::multimap< double, reco::CaloClusterPtr > &basicClusterPtrs, std::multimap< double, reco::CaloClusterPtr > &superClusterPtrs)
GlobalPoint globalPosition() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
int ii
Definition: cuy.py:588
const Point & position() const
position
Definition: Vertex.h:106
tuple vertexCollection
math::XYZVectorF refittedPairMomentum() const
Conversion tracks momentum from the tracks refitted with vertex constraint.
Definition: Conversion.cc:248
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
TrajectoryStateOnSurface innermostMeasurementState() const
bool matchingSC(const std::multimap< double, reco::CaloClusterPtr > &scMap, reco::Conversion &conv, reco::CaloClusterPtrVector &mSC)
virtual GlobalPoint crossingPoint() const
virtual GlobalPoint crossingPoint() const
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
TrackAlgorithm algo() const
Definition: TrackBase.h:330
static float endcapRadius()
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
#define ETA
int iEvent
Definition: GenABIO.cc:230
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
math::XYZVectorF toFConverterV(const math::XYZVector &val)
T z() const
Definition: PV3DBase.h:64
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double chi2() const
chi-squares
Definition: Vertex.h:95
double f[11][100]
float ChiSquaredProbability(double chiSquared, double nrDOF)
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scEndcapProducer_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcBarrelCollection_
bool isValid() const
Definition: HandleBase.h:76
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcEndcapCollection_
uint8_t nSharedHits(const reco::Track &trk1, const reco::Track &trk2) const
bool getMatchedBC(const std::multimap< double, reco::CaloClusterPtr > &bcMap, const math::XYZPointF &trackImpactPosition, reco::CaloClusterPtr &closestBC)
double ndof() const
Definition: Vertex.h:102
double delta_phi(double ph11, double phi2)
Definition: AnglesUtil.h:91
static float endcapZ()
bool checkTrackPair(const std::pair< edm::RefToBase< reco::Track >, reco::CaloClusterPtr > &ll, const std::pair< edm::RefToBase< reco::Track >, reco::CaloClusterPtr > &rr)
bool trackQualityFilter(const edm::RefToBase< reco::Track > &ref, bool isLeft)
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
virtual bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb)
const Track & track() const
bool trackD0Cut(const edm::RefToBase< reco::Track > &ref)
const T & get() const
Definition: EventSetup.h:55
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:241
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field)
T const * product() const
Definition: ESHandle.h:62
std::string ConvertedPhotonCollection_
Disk BoundDisk
Definition: BoundDisk.h:62
static const float etaBarrelEndcap
static const float Z_Endcap
T eta() const
Definition: PV3DBase.h:76
edm::EDGetTokenT< edm::View< reco::ConversionTrack > > src_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scBarrelProducer_
virtual bool status() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:45
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:100
static const float R_ECAL
double etaTransformation(float EtaParticle, float Zvertex)
int charge() const
track electric charge
Definition: TrackBase.h:111
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
math::XYZPointF toFConverterP(const math::XYZPoint &val)
const double epsilon
virtual void produce(edm::Event &, const edm::EventSetup &)
bool preselectTrackPair(const reco::TransientTrack &ttk_l, const reco::TransientTrack &ttk_r, double &appDist)
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:119
virtual bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb)
value_type const * get() const
Definition: RefToBase.h:212
void setMatchingSuperCluster(const reco::CaloClusterPtrVector &sc)
Definition: Conversion.h:173
bool checkPhi(const edm::RefToBase< reco::Track > &tk_l, const edm::RefToBase< reco::Track > &tk_r, const TrackerGeometry *trackerGeom, const MagneticField *magField, const reco::Vertex &the_vertex)
virtual bool status() const
static float barrelRadius()
GlobalVector globalDirection() const
ConversionProducer(const edm::ParameterSet &)
bool checkVertex(const reco::TransientTrack &ttk_l, const reco::TransientTrack &ttk_r, const MagneticField *magField, reco::Vertex &the_vertex)