CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  std::auto_ptr< reco::PhotonCoreCollection > outputPhotonCoreCollection_p(new 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;
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,
109  pixelSeedHandle,
110  outputPhotonCoreCollection,
111  iSC);
112  if ( validEndcapSCHandle) fillPhotonCollection(theEvent,
113  theEventSetup,
114  scEndcapHandle,
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( 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 
135 
136  reco::ElectronSeedCollection::const_iterator pixelSeedItr;
137  for(unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
138 
139  // get SuperClusterRef
140  reco::SuperClusterRef scRef(reco::SuperClusterRef(scHandle, lSC));
141  iSC++;
142  //const reco::SuperCluster* pClus=&(*scRef);
143 
144  // SC energy preselection
145  if (scRef->energy()/cosh(scRef->eta()) <= minSCEt_) continue;
146 
147  reco::PhotonCore newCandidate(scRef);
148  if ( validConversions_) {
149 
150  if ( risolveAmbiguity_ ) {
151  reco::ConversionRef bestRef=solveAmbiguity( conversionHandle , scRef);
152  if (bestRef.isNonnull() ) newCandidate.addConversion(bestRef);
153 
154  } else {
155 
156 
157  for( unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
158  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
159  if ( !cpRef->caloCluster().size()) continue;
160  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
161  if ( !cpRef->isConverted() ) continue;
162  newCandidate.addConversion(cpRef);
163 
164  }
165 
166  } // solve or not the ambiguity of many conversion candidates
167 
168  }
169 
170  if ( validPixelSeeds_) {
171  for( unsigned int icp = 0; icp < pixelSeedHandle->size(); icp++) {
172  reco::ElectronSeedRef cpRef(reco::ElectronSeedRef(pixelSeedHandle,icp));
173  if ( ! cpRef->isEcalDriven() ) continue;
174  if (!( scRef.id() == cpRef->caloCluster().id() && scRef.key() == cpRef->caloCluster().key() )) continue;
175  newCandidate.addElectronPixelSeed(cpRef);
176  }
177  }
178 
179  outputPhotonCoreCollection.push_back(newCandidate);
180 
181  }
182 
183 
184 }
185 
186 
187 
188 
190 
191 
192  std::multimap<reco::ConversionRef, double > convMap;
193  for ( unsigned int icp=0; icp< conversionHandle->size(); icp++) {
194 
195  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
196 
197  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
198  if ( !cpRef->isConverted() ) continue;
199  double like = cpRef->MVAout();
200  convMap.insert ( std::make_pair(cpRef,like) );
201 
202  }
203 
204 
205 
206  std::multimap<reco::ConversionRef, double >::iterator iMap;
207  double max_lh = -1.;
208  reco::ConversionRef bestRef;
209  // std::cout << " Pick up the best conv " << std::endl;
210  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
211  double like = iMap->second;
212  if (like > max_lh) {
213  max_lh = like;
214  bestRef=iMap->first;
215  }
216  }
217 
218  //std::cout << " Best conv like " << max_lh << std::endl;
219 
220  float ep=0;
221  if ( max_lh <0 ) {
222  // std::cout << " Candidates with only one track " << std::endl;
224  float epMin=999;
225 
226  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
227  reco::ConversionRef convRef=iMap->first;
228  // std::vector<reco::TrackRef> tracks = convRef->tracks();
229  const std::vector<edm::RefToBase<reco::Track> > tracks = convRef->tracks();
230  float px=tracks[0]->innerMomentum().x();
231  float py=tracks[0]->innerMomentum().y();
232  float pz=tracks[0]->innerMomentum().z();
233  float p=sqrt(px*px+py*py+pz*pz);
234  ep=fabs(1.-convRef->caloCluster()[0]->energy()/p);
235  // std::cout << " 1-E/P = " << ep << std::endl;
236  if ( ep<epMin) {
237  epMin=ep;
238  bestRef=iMap->first;
239  }
240  }
241  // std::cout << " Best conv 1-E/P " << ep << std::endl;
242 
243  }
244 
245 
246  return bestRef;
247 
248 
249 }
250 
T getParameter(std::string const &) const
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
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:252
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:464
key_type key() const
Accessor for product key.
Definition: Ref.h:264
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
reco::ConversionRef solveAmbiguity(const edm::Handle< reco::ConversionCollection > &conversionHandle, reco::SuperClusterRef &sc)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
PhotonCoreProducer(const edm::ParameterSet &ps)
edm::EDGetTokenT< reco::SuperClusterCollection > scHybridBarrelProducer_
tuple tracks
Definition: testEve_cfg.py:39
std::vector< PhotonCore > PhotonCoreCollection
collectin of PhotonCore objects
Definition: PhotonCoreFwd.h:9
edm::EDGetTokenT< reco::SuperClusterCollection > scIslandEndcapProducer_
std::string PhotonCoreCollection_
void addElectronPixelSeed(const reco::ElectronSeedRef &r)
set electron pixel seed ref
Definition: PhotonCore.h:58