CMS 3D CMS Logo

LowPtGsfElectronSCProducer.cc
Go to the documentation of this file.
17 #include <iostream>
18 
20 //
22  gsfPfRecTracks_{consumes<reco::GsfPFRecTrackCollection>( cfg.getParameter<edm::InputTag>("gsfPfRecTracks") )},
23  ecalClusters_{consumes<reco::PFClusterCollection>( cfg.getParameter<edm::InputTag>("ecalClusters") )},
24  dr2_{cfg.getParameter<double>("MaxDeltaR2")}
25 {
26  produces<reco::CaloClusterCollection>();
27  produces<reco::SuperClusterCollection>();
28  produces< edm::ValueMap<reco::SuperClusterRef> >();
29 }
30 
32 //
34 {}
35 
37 //
39 {
40 
41  // Input GsfPFRecTracks collection
43 
44  // Input EcalClusters collection
46 
47  // Output SuperClusters collection and getRefBeforePut
48  auto superClusters = std::make_unique<reco::SuperClusterCollection>( reco::SuperClusterCollection() );
49  superClusters->reserve(gsfPfRecTracks->size());
50  const reco::SuperClusterRefProd superClustersRefProd = event.getRefBeforePut<reco::SuperClusterCollection>();
51 
52  // Output ValueMap container of GsfPFRecTrackRef index to SuperClusterRef
53  std::vector<reco::SuperClusterRef> superClustersValueMap;
54 
55  // Output CaloClusters collection
56  auto caloClusters = std::make_unique<reco::CaloClusterCollection>( reco::CaloClusterCollection() );
57  caloClusters->reserve(ecalClusters.size());
58 
59  // Index[GSF track][trajectory point] for "best" CaloCluster
60  std::vector< std::vector<int> > cluster_idx;
61  cluster_idx.reserve( gsfPfRecTracks->size());
62 
63  // Index[GSF track][trajectory point] for "best" PFCluster
64  std::vector< std::vector<int> > pfcluster_idx;
65  pfcluster_idx.reserve( gsfPfRecTracks->size());
66 
67  // dr2min[GSF track][trajectory point] for "best" CaloCluster
68  std::vector< std::vector<float> > cluster_dr2min;
69  cluster_dr2min.reserve( gsfPfRecTracks->size());
70 
71  // Construct list of trajectory points from the GSF track and electron brems
72  std::vector< std::vector<const reco::PFTrajectoryPoint*> > points;
73  points.reserve( gsfPfRecTracks->size());
74  for ( auto const& trk: *gsfPfRecTracks) {
75  // Extrapolated track
76  std::vector<const reco::PFTrajectoryPoint*> traj;
77  traj.reserve(trk.PFRecBrem().size()+1);
78  traj.push_back( &trk.extrapolatedPoint(reco::PFTrajectoryPoint::LayerType::ECALShowerMax) );
79  // Extrapolated brem trajectories
80  for ( auto const& brem : trk.PFRecBrem() ) {
81  traj.push_back( &brem.extrapolatedPoint(reco::PFTrajectoryPoint::LayerType::ECALShowerMax) );
82  }
83  auto size = traj.size();
84  points.push_back(std::move(traj));
85  // Size containers
86  cluster_idx.emplace_back(size,-1);
87  pfcluster_idx.emplace_back(size,-1);
88  cluster_dr2min.emplace_back(size,1.e6);
89  }
90 
91  // For each cluster, find closest trajectory point ("global" arbitration at event level)
92  for ( size_t iclu = 0; iclu < ecalClusters.size(); ++iclu ) { // Cluster loop
93  std::pair<int,int> point = std::make_pair(-1,-1);
94  float dr2min = 1.e6;
95  for ( size_t ipoint = 0; ipoint < points.size(); ++ipoint ) { // GSF track loop
96  for ( size_t jpoint = 0; jpoint < points[ipoint].size(); ++jpoint ) { // Traj point loop
97  if ( points[ipoint][jpoint]->isValid() ) {
98  float dr2 = reco::deltaR2( ecalClusters[iclu], points[ipoint][jpoint]->positionREP() );
99  if ( dr2 < dr2min ) {
100  // Store nearest point to this cluster
101  dr2min = dr2;
102  point = std::make_pair(ipoint,jpoint);
103  }
104  }
105  }
106  }
107  if ( point.first >= 0 && point.second >= 0 && // if this cluster is matched to a point ...
108  dr2min < cluster_dr2min[point.first][point.second] ) { // ... and cluster is closest to the same point
109  // Copy CaloCluster to new collection
110  caloClusters->push_back(ecalClusters[iclu]);
111  // Store cluster index for creation of SC later
112  cluster_idx[point.first][point.second] = caloClusters->size()-1;
113  pfcluster_idx[point.first][point.second] = iclu;
114  cluster_dr2min[point.first][point.second] = dr2min;
115  }
116  }
117 
118  // Put CaloClusters in event and get orphan handle
119  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClustersH = event.put(std::move(caloClusters));
120 
121  // Loop through GSF tracks
122  for ( size_t itrk = 0; itrk < gsfPfRecTracks->size(); ++itrk ) {
123 
124  // Used to create SC
125  float energy = 0.;
126  float X = 0., Y = 0., Z = 0.;
129  std::vector<const reco::PFCluster*> barePtrs;
130 
131  // Find closest match in dr2 from points associated to given track
132  int index = -1;
133  float dr2 = 1.e6;
134  for ( size_t ipoint = 0; ipoint < cluster_idx[itrk].size(); ++ipoint ) {
135  if ( cluster_idx[itrk][ipoint] < 0 ) { continue; }
136  if ( cluster_dr2min[itrk][ipoint] < dr2 ) {
137  dr2 = cluster_dr2min[itrk][ipoint];
138  index = cluster_idx[itrk][ipoint];
139  }
140  }
141 
142  // For each track, loop through points and use associated cluster
143  for ( size_t ipoint = 0; ipoint < cluster_idx[itrk].size(); ++ipoint ) {
144  if ( cluster_idx[itrk][ipoint] < 0 ) { continue; }
145  reco::CaloClusterPtr clu(caloClustersH,cluster_idx[itrk][ipoint]);
146  if ( clu.isNull() ) { continue; }
147  if ( !( cluster_dr2min[itrk][ipoint] < dr2_ || // Require cluster to be closer than dr2_ ...
148  index == cluster_idx[itrk][ipoint] ) ) { continue; } // ... unless it is the closest one ...
149  if ( seed.isNull() ) { seed = clu; }
150  clusters.push_back(clu);
151  energy += clu->correctedEnergy();
152  X += clu->position().X() * clu->correctedEnergy();
153  Y += clu->position().Y() * clu->correctedEnergy();
154  Z += clu->position().Z() * clu->correctedEnergy();
155  auto index = pfcluster_idx[itrk][ipoint];
156  if(index < static_cast<decltype(index)>(ecalClusters.size())) {
157  barePtrs.push_back(&(ecalClusters[index]));
158  }
159  }
160  X /= energy;
161  Y /= energy;
162  Z /= energy;
163 
164  // Create SC
165  if ( seed.isNonnull() ) {
167  sc.setCorrectedEnergy(energy);
168  sc.setSeed(seed);
169  sc.setClusters(clusters);
170  PFClusterWidthAlgo pfwidth(barePtrs);
171  sc.setEtaWidth(pfwidth.pflowEtaWidth());
172  sc.setPhiWidth(pfwidth.pflowPhiWidth());
173  sc.rawEnergy(); // Cache the value of raw energy
174  superClusters->push_back(sc);
175 
176  // Populate ValueMap container
177  superClustersValueMap.push_back( reco::SuperClusterRef( superClustersRefProd, superClusters->size()-1 ) );
178  } else {
179  superClustersValueMap.push_back( reco::SuperClusterRef( superClustersRefProd.id() ) );
180  }
181 
182  } // GSF tracks
183 
184  // Put SuperClusters in event
185  event.put(std::move(superClusters));
186 
187  auto ptr = std::make_unique< edm::ValueMap<reco::SuperClusterRef> >( edm::ValueMap<reco::SuperClusterRef>() );
189  filler.insert(gsfPfRecTracks, superClustersValueMap.begin(), superClustersValueMap.end());
190  filler.fill();
191  event.put(std::move(ptr));
192 
193 }
194 
196 //
199  std::vector<int>& matched ) {
200  reco::PFClusterRef closest;
201  if ( point.isValid() ) {
202  float dr2min = dr2_;
203  for ( size_t ii = 0; ii < clusters->size(); ++ii ) {
204  if ( std::find( matched.begin(), matched.end(), ii ) == matched.end() ) {
205  float dr2 = reco::deltaR2( clusters->at(ii), point.positionREP() );
206  if ( dr2 < dr2min ) {
207  closest = reco::PFClusterRef( clusters, ii );
208  dr2min = dr2;
209  }
210  }
211  }
212  if ( dr2min < (dr2_ - 1.e-6) ) { matched.push_back( closest.index() ); }
213  }
214  return closest;
215 }
216 
218 //
220 {
222  desc.add<edm::InputTag>("gsfPfRecTracks",edm::InputTag("lowPtGsfElePfGsfTracks"));
223  desc.add<edm::InputTag>("ecalClusters",edm::InputTag("particleFlowClusterECAL"));
224  desc.add<edm::InputTag>("hcalClusters",edm::InputTag("particleFlowClusterHCAL"));
225  desc.add<double>("MaxDeltaR2",0.5);
226  descriptions.add("defaultLowPtGsfElectronSuperClusters",desc);
227 }
228 
230 //
const REPPoint & positionREP() const
trajectory position in (rho, eta, phi) base
size
Write out results.
T getParameter(std::string const &) const
const edm::EDGetTokenT< reco::PFClusterCollection > ecalClusters_
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
double pflowPhiWidth() const
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
#define X(str)
Definition: MuonsGrabber.cc:48
const edm::EDGetTokenT< reco::GsfPFRecTrackCollection > gsfPfRecTracks_
key_type index() const
Definition: Ref.h:266
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
Definition: SuperCluster.h:96
static void fillDescriptions(edm::ConfigurationDescriptions &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void setPhiWidth(double pw)
Definition: SuperCluster.h:62
double pflowEtaWidth() const
void setClusters(const CaloClusterPtrVector &clusters)
Definition: SuperCluster.h:99
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
void setEtaWidth(double ew)
Definition: SuperCluster.h:63
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
LowPtGsfElectronSCProducer(const edm::ParameterSet &)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:114
edm::Ref< PFClusterCollection > PFClusterRef
persistent reference to PFCluster objects
Definition: PFClusterFwd.h:15
bool isNull() const
Checks for null.
Definition: Ptr.h:164
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
reco::PFClusterRef closestCluster(const reco::PFTrajectoryPoint &point, const edm::Handle< reco::PFClusterCollection > &clusters, std::vector< int > &matched)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ii
Definition: cuy.py:590
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:137
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:47
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
bool isValid() const
is this point valid ?
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
auto makeValid(const U &iOtherHandleType) noexcept(false)
Definition: ValidHandle.h:59
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
Definition: event.py:1