CMS 3D CMS Logo

PhotonCoreProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
12 
13 
18 
19 
21  conf_(config)
22 
23 {
24 
25  // use onfiguration file to setup input/output collection names
27  consumes<reco::SuperClusterCollection>(conf_.getParameter<edm::InputTag>("scHybridBarrelProducer"));
29  consumes<reco::SuperClusterCollection>(conf_.getParameter<edm::InputTag>("scIslandEndcapProducer"));
31  consumes<reco::ConversionCollection>(conf_.getParameter<edm::InputTag>("conversionProducer"));
32  PhotonCoreCollection_ = conf_.getParameter<std::string>("photonCoreCollection");
34  consumes<reco::ElectronSeedCollection>(conf_.getParameter<edm::InputTag>("pixelSeedProducer"));
35  minSCEt_ = conf_.getParameter<double>("minSCEt");
36  risolveAmbiguity_ = conf_.getParameter<bool>("risolveConversionAmbiguity");
37 
38  // Register the product
39  produces< reco::PhotonCoreCollection >(PhotonCoreCollection_);
40 
41 }
42 
44 
45 
46 
47 
48 void PhotonCoreProducer::produce(edm::Event &theEvent, const edm::EventSetup& theEventSetup) {
49 
50 
51  using namespace edm;
52  // nEvt_++;
53 
54  reco::PhotonCoreCollection outputPhotonCoreCollection;
55  auto outputPhotonCoreCollection_p = std::make_unique<reco::PhotonCoreCollection>();
56 
57  // Get the Barrel Super Cluster collection
58  bool validBarrelSCHandle=true;
60  theEvent.getByToken(scHybridBarrelProducer_,scBarrelHandle);
61  if (!scBarrelHandle.isValid()) {
62  edm::LogError("PhotonCoreProducer")
63  << "Error! Can't get the scHybridBarrelProducer";
64  validBarrelSCHandle=false;
65  }
66 
67 
68  // Get the Endcap Super Cluster collection
69  bool validEndcapSCHandle=true;
71  theEvent.getByToken(scIslandEndcapProducer_,scEndcapHandle);
72  if (!scEndcapHandle.isValid()) {
73  edm::LogError("PhotonCoreProducer")
74  << "Error! Can't get the scIslandEndcapProducer";
75  validEndcapSCHandle=false;
76  }
77 
78 
80  validConversions_=true;
82  theEvent.getByToken(conversionProducer_, conversionHandle);
83  if (!conversionHandle.isValid()) {
84  //edm::LogError("PhotonCoreProducer") << "Error! Can't get the product "<< conversionProducer_.label() << "\n" ;
85  validConversions_=false;
86  }
87 
88 
89 
90 
91  // Get ElectronPixelSeeds
92  validPixelSeeds_=true;
95  theEvent.getByToken(pixelSeedProducer_, pixelSeedHandle);
96  if (!pixelSeedHandle.isValid()) {
97  validPixelSeeds_=false;
98  }
99  // if ( validPixelSeeds_) pixelSeeds = *(pixelSeedHandle.product());
100 
101 
102 
103  int iSC=0; // index in photon collection
104  // Loop over barrel and endcap SC collections and fill the photon collection
105  if ( validBarrelSCHandle) fillPhotonCollection(theEvent,
106  theEventSetup,
107  scBarrelHandle,
108  conversionHandle,
109  pixelSeedHandle,
110  outputPhotonCoreCollection,
111  iSC);
112  if ( validEndcapSCHandle) fillPhotonCollection(theEvent,
113  theEventSetup,
114  scEndcapHandle,
115  conversionHandle,
116  pixelSeedHandle,
117  outputPhotonCoreCollection,
118  iSC);
119 
120  // put the product in the event
121  edm::LogInfo("PhotonCoreProducer") << " Put in the event " << iSC << " Photon Candidates \n";
122  outputPhotonCoreCollection_p->assign(outputPhotonCoreCollection.begin(),outputPhotonCoreCollection.end());
123  theEvent.put(std::move(outputPhotonCoreCollection_p), PhotonCoreCollection_);
124 
125 }
126 
128  edm::EventSetup const & es,
131  const edm::Handle<reco::ElectronSeedCollection> & pixelSeedHandle,
132  reco::PhotonCoreCollection & outputPhotonCoreCollection, int& iSC) {
133 
134  for(unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
135 
136  // get SuperClusterRef
137  reco::SuperClusterRef scRef(reco::SuperClusterRef(scHandle, lSC));
138  iSC++;
139  //const reco::SuperCluster* pClus=&(*scRef);
140 
141  // SC energy preselection
142  if (scRef->energy()/cosh(scRef->eta()) <= minSCEt_) continue;
143 
144  reco::PhotonCore newCandidate(scRef);
145  newCandidate.setParentSuperCluster(scRef);
146  if ( validConversions_) {
147 
148  if ( risolveAmbiguity_ ) {
149  reco::ConversionRef bestRef=solveAmbiguity( conversionHandle , scRef);
150  if (bestRef.isNonnull() ) newCandidate.addConversion(bestRef);
151 
152  } else {
153 
154 
155  for( unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
156  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
157  if ( cpRef->caloCluster().empty()) continue;
158  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
159  if ( !cpRef->isConverted() ) continue;
160  newCandidate.addConversion(cpRef);
161 
162  }
163 
164  } // solve or not the ambiguity of many conversion candidates
165 
166  }
167 
168  if ( validPixelSeeds_) {
169  for( unsigned int icp = 0; icp < pixelSeedHandle->size(); icp++) {
170  reco::ElectronSeedRef cpRef(reco::ElectronSeedRef(pixelSeedHandle,icp));
171  if ( ! cpRef->isEcalDriven() ) continue;
172  if (!( scRef.id() == cpRef->caloCluster().id() && scRef.key() == cpRef->caloCluster().key() )) continue;
173  newCandidate.addElectronPixelSeed(cpRef);
174  }
175  }
176 
177  outputPhotonCoreCollection.push_back(newCandidate);
178 
179  }
180 
181 
182 }
183 
184 
185 
186 
188 
189 
190  std::multimap<reco::ConversionRef, double > convMap;
191  for ( unsigned int icp=0; icp< conversionHandle->size(); icp++) {
192 
193  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
194 
195  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
196  if ( !cpRef->isConverted() ) continue;
197  double like = cpRef->MVAout();
198  convMap.insert ( std::make_pair(cpRef,like) );
199 
200  }
201 
202 
203 
204  std::multimap<reco::ConversionRef, double >::iterator iMap;
205  double max_lh = -1.;
206  reco::ConversionRef bestRef;
207  // std::cout << " Pick up the best conv " << std::endl;
208  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
209  double like = iMap->second;
210  if (like > max_lh) {
211  max_lh = like;
212  bestRef=iMap->first;
213  }
214  }
215 
216  //std::cout << " Best conv like " << max_lh << std::endl;
217 
218  float ep=0;
219  if ( max_lh <0 ) {
220  // std::cout << " Candidates with only one track " << std::endl;
222  float epMin=999;
223 
224  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
225  reco::ConversionRef convRef=iMap->first;
226  // std::vector<reco::TrackRef> tracks = convRef->tracks();
227  const std::vector<edm::RefToBase<reco::Track> > tracks = convRef->tracks();
228  float px=tracks[0]->innerMomentum().x();
229  float py=tracks[0]->innerMomentum().y();
230  float pz=tracks[0]->innerMomentum().z();
231  float p=sqrt(px*px+py*py+pz*pz);
232  ep=fabs(1.-convRef->caloCluster()[0]->energy()/p);
233  // std::cout << " 1-E/P = " << ep << std::endl;
234  if ( ep<epMin) {
235  epMin=ep;
236  bestRef=iMap->first;
237  }
238  }
239  // std::cout << " Best conv 1-E/P " << ep << std::endl;
240 
241  }
242 
243 
244  return bestRef;
245 
246 
247 }
248 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void addConversion(const reco::ConversionRef &r)
add single ConversionRef to the vector of Refs
Definition: PhotonCore.h:54
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
edm::EDGetTokenT< reco::ConversionCollection > conversionProducer_
edm::ParameterSet conf_
edm::EDGetTokenT< reco::ElectronSeedCollection > pixelSeedProducer_
void fillPhotonCollection(edm::Event &evt, edm::EventSetup const &es, const edm::Handle< reco::SuperClusterCollection > &scHandle, const edm::Handle< reco::ConversionCollection > &conversionHandle, const edm::Handle< reco::ElectronSeedCollection > &pixelSeeds, reco::PhotonCoreCollection &outputCollection, int &iSC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Definition: config.py:1
key_type key() const
Accessor for product key.
Definition: Ref.h:263
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
reco::ConversionRef solveAmbiguity(const edm::Handle< reco::ConversionCollection > &conversionHandle, reco::SuperClusterRef &sc)
void setParentSuperCluster(const reco::SuperClusterRef &r)
set reference to PFlow SuperCluster
Definition: PhotonCore.h:52
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool isValid() const
Definition: HandleBase.h:74
PhotonCoreProducer(const edm::ParameterSet &ps)
edm::EDGetTokenT< reco::SuperClusterCollection > scHybridBarrelProducer_
~PhotonCoreProducer() override
void produce(edm::Event &evt, const edm::EventSetup &es) override
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
HLT enums.
edm::EDGetTokenT< reco::SuperClusterCollection > scIslandEndcapProducer_
std::string PhotonCoreCollection_
void addElectronPixelSeed(const reco::ElectronSeedRef &r)
set electron pixel seed ref
Definition: PhotonCore.h:58
def move(src, dest)
Definition: eostools.py:511