50 barrelRecHitCollectionToken_ = consumes<EcalRecHitCollection>(barrelRecHitCollection_);
52 endcapRecHitCollectionToken_ = consumes<EcalRecHitCollection>(endcapRecHitCollection_);
58 preshStripECut_ = ps.
getParameter<
double>(
"preshStripEnergyCut");
62 PhotonPi0DiscriminatorAssociationMap_ = ps.
getParameter<
string>(
"Pi0Association");
64 string debugString = ps.
getParameter<
string>(
"debugLevel");
66 if (debugString ==
"DEBUG") debugL_pi0 = pDEBUG;
67 else if (debugString ==
"INFO") debugL_pi0 = pINFO;
68 else debugL_pi0 = pERROR;
70 string tmpPath = ps.
getUntrackedParameter<
string>(
"pathToWeightFiles",
"RecoEcal/EgammaClusterProducers/data/");
74 produces< PhotonPi0DiscriminatorAssociationMap >(PhotonPi0DiscriminatorAssociationMap_);
83 delete presh_pi0_algo;
91 if ( debugL_pi0 <= pDEBUG )
92 cout <<
"\n PiZeroDiscriminatorProducer: ....... Event " << evt.
id() <<
" with Number = " << nEvt_+1
93 <<
" is analyzing ....... " << endl << endl;
97 evt.
getByToken(pPreshowerShapeClustersXToken_, pPreshowerShapeClustersX);
99 if ( debugL_pi0 <= pDEBUG ) {
100 cout <<
"\n PiZeroDiscriminatorProducer: pPreshowerShapeClustersX->size() = " << clustersX->size() << endl;
104 evt.
getByToken(pPreshowerShapeClustersYToken_, pPreshowerShapeClustersY);
106 if ( debugL_pi0 <= pDEBUG ) {
107 cout <<
"\n PiZeroDiscriminatorProducer: pPreshowerShapeClustersY->size() = " << clustersY->size() << endl;
111 evt.
getByToken( barrelRecHitCollectionToken_, pEBRecHits );
115 evt.
getByToken( endcapRecHitCollectionToken_, pEERecHits );
128 evt.
getByToken(correctedPhotonToken_, correctedPhotonHandle);
130 if ( debugL_pi0 <= pDEBUG ) {
131 cout <<
" PiZeroDiscriminatorProducer: Photon Collection size : " << corrPhoCollection.size() << endl;
136 for( PhotonCollection::const_iterator iPho = corrPhoCollection.begin(); iPho != corrPhoCollection.end(); iPho++) {
138 float Phot_En = iPho->energy();
139 float Phot_Et = Phot_En*
sin(2*atan(
exp(-iPho->eta())));
140 float Phot_eta = iPho->eta();
141 float Phot_phi = iPho->phi();
142 float Phot_R9 = iPho->r9();
144 if ( debugL_pi0 <= pDEBUG ) {
145 cout <<
" PiZeroDiscriminatorProducer: Photon index : " << iPho - corrPhoCollection.begin()
146 <<
" with Energy = " << Phot_En
147 <<
" Et = " << Phot_Et
148 <<
" ETA = " << Phot_eta
149 <<
" PHI = " << Phot_phi
150 <<
" R9 = " << Phot_R9 << endl;
154 float SC_En = it_super->energy();
155 float SC_Et = SC_En*
sin(2*atan(
exp(-it_super->eta())));
156 float SC_eta = it_super->eta();
157 float SC_phi = it_super->phi();
159 if ( debugL_pi0 <= pDEBUG ) {
160 cout <<
" PiZeroDiscriminatorProducer: superE = " << SC_En
161 <<
" superEt = " << SC_Et
162 <<
" superETA = " << SC_eta
163 <<
" superPHI = " << SC_phi << endl;
173 float nnoutput = -1.;
174 if(fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5) {
175 const GlobalPoint pointSC(it_super->x(),it_super->y(),it_super->z());
176 if ( debugL_pi0 <= pDEBUG )
cout <<
"SC centroind = " << pointSC << endl;
177 double SC_seed_energy = it_super->seed()->energy();
184 double SC_seed_Shape_E3x3 = EcalClusterTools::e3x3( *seed, eeRecHits, topology );
187 if ( debugL_pi0 <= pDEBUG ) {
188 cout <<
"PiZeroDiscriminatorProducer: ( SeedBC_energy, E1, E3x3, E5x5) = " 189 << SC_seed_energy <<
" " 190 << SC_seed_Shape_E1 <<
" " 191 << SC_seed_Shape_E3x3 <<
" " 192 << SC_seed_Shape_E5x5 << endl;
196 vector<float> vout_stripE1;
197 vector<float> vout_stripE2;
198 for(reco::PreshowerClusterShapeCollection::const_iterator esClus = clustersX->begin();
199 esClus !=clustersX->end(); esClus++) {
201 float dR =
sqrt((SC_eta-sc_ref->eta())*(SC_eta-sc_ref->eta()) +
202 (SC_phi-sc_ref->phi())*(SC_phi-sc_ref->phi()));
205 vout_stripE1 = esClus->getStripEnergies();
209 for(reco::PreshowerClusterShapeCollection::const_iterator esClus = clustersY->begin();
210 esClus !=clustersY->end(); esClus++) {
212 float dR =
sqrt((SC_eta-sc_ref->eta())*(SC_eta-sc_ref->eta()) +
213 (SC_phi-sc_ref->phi())*(SC_phi-sc_ref->phi()));
216 vout_stripE2 = esClus->getStripEnergies();
221 if(vout_stripE1.empty() || vout_stripE2.empty() ) {
222 if ( debugL_pi0 <= pDEBUG )
223 cout <<
" PiZeroDiscriminatorProducer: Attention!!!!! Not Valid ES NN input Variables Return NNout = -1" << endl;
224 Pi0Assocs_p->insert(
Ref<PhotonCollection>(correctedPhotonHandle,iPho - corrPhoCollection.begin()), nnoutput);
228 if ( debugL_pi0 <= pDEBUG ) {
229 cout <<
"PiZeroDiscriminatorProducer : vout_stripE1.size = " << vout_stripE1.size()
230 <<
" vout_stripE2.size = " << vout_stripE2.size() << endl;
231 cout <<
"PiZeroDiscriminatorProducer : ES_input_vector = " ;
232 for(
int k1=0;k1<11;k1++) {
233 cout << vout_stripE1[k1] <<
" " ;
235 for(
int k1=0;k1<11;k1++) {
236 cout << vout_stripE2[k1] <<
" " ;
241 bool valid_NNinput = presh_pi0_algo->calculateNNInputVariables(vout_stripE1, vout_stripE2,
242 SC_seed_Shape_E1, SC_seed_Shape_E3x3, SC_seed_Shape_E5x5, EScorr_);
245 if ( debugL_pi0 <= pDEBUG )
246 cout <<
" PiZeroDiscriminatorProducer: Attention!!!!! Not Valid ES NN input Variables Return NNout = -1" << endl;
247 Pi0Assocs_p->insert(
Ref<PhotonCollection>(correctedPhotonHandle,iPho - corrPhoCollection.begin()), nnoutput);
251 float* nn_input_var = presh_pi0_algo->get_input_vector();
253 if ( debugL_pi0 <= pDEBUG ) {
254 cout <<
" PiZeroDiscriminatorProducer: NN_ESEndcap_input_vector+Et+Eta+Phi+R9 = " ;
255 for(
int k1=0;k1<25;k1++) {
256 cout << nn_input_var[k1] <<
" " ;
258 cout << SC_Et <<
" " << SC_eta <<
" " << SC_phi <<
" " << Phot_R9 << endl;
261 nnoutput = presh_pi0_algo->GetNNOutput(SC_Et);
263 if ( debugL_pi0 <= pDEBUG ) {
264 cout <<
" PiZeroDiscriminatorProducer: Event : " << evt.
id()
265 <<
" SC id = " << iPho - corrPhoCollection.begin()
266 <<
" with Pt = " << SC_Et
267 <<
" eta = " << SC_eta
268 <<
" phi = " << SC_phi
269 <<
" contains: " << it_super->clustersSize() <<
" BCs " 270 <<
" has NNout = " << nnoutput << endl;
273 Pi0Assocs_p->insert(
Ref<PhotonCollection>(correctedPhotonHandle,iPho - corrPhoCollection.begin()), nnoutput);
275 }
else if((fabs(SC_eta) <= 1.4442) || (fabs(SC_eta) < 1.65 && fabs(SC_eta) >= 1.566) || fabs(SC_eta) >= 2.5) {
280 double SC_seed_Shape_E3x3 = EcalClusterTools::e3x3( *seed, ebRecHits, topology );
282 double SC_seed_Shape_E2 = EcalClusterTools::e2nd( *seed, ebRecHits );
284 std::vector<float> vCov = EcalClusterTools::covariances( *seed, ebRecHits , topology, geometry, w0_ );
286 double SC_seed_Shape_cEE = vCov[0];
287 double SC_seed_Shape_cEP = vCov[1];
288 double SC_seed_Shape_cPP = vCov[2];
290 double SC_seed_Shape_E2x2 = EcalClusterTools::e2x2( *seed, ebRecHits, topology );
291 double SC_seed_Shape_E3x2 = EcalClusterTools::e3x2( *seed, ebRecHits, topology );
293 double SC_seed_Shape_E3x2r = 0.0;
294 double SC_seed_Shape_ELeft = EcalClusterTools::eLeft( *seed, ebRecHits, topology );
295 double SC_seed_Shape_ERight = EcalClusterTools::eRight( *seed, ebRecHits, topology );
296 double SC_seed_Shape_ETop = EcalClusterTools::eTop( *seed, ebRecHits, topology );
297 double SC_seed_Shape_EBottom = EcalClusterTools::eBottom( *seed, ebRecHits, topology );
299 double DA = SC_seed_Shape_E2x2 - SC_seed_Shape_E2 - SC_seed_Shape_E1;
301 if(SC_seed_Shape_E2==SC_seed_Shape_ETop || SC_seed_Shape_E2==SC_seed_Shape_EBottom) {
302 if( SC_seed_Shape_ELeft > SC_seed_Shape_ERight ) {
303 SC_seed_Shape_E3x2r = (DA - SC_seed_Shape_ELeft)/(0.25+SC_seed_Shape_ELeft);
305 SC_seed_Shape_E3x2r = (DA - SC_seed_Shape_ERight)/(0.25+SC_seed_Shape_ERight);
308 }
else if(SC_seed_Shape_E2==SC_seed_Shape_ELeft || SC_seed_Shape_E2==SC_seed_Shape_ERight) {
310 if( SC_seed_Shape_ETop > SC_seed_Shape_EBottom ) {
311 SC_seed_Shape_E3x2r = (DA - SC_seed_Shape_ETop)/(0.25+SC_seed_Shape_ETop);
313 SC_seed_Shape_E3x2r = (DA - SC_seed_Shape_EBottom)/(0.25+SC_seed_Shape_EBottom);
318 double SC_seed_Shape_xcog = EcalClusterTools::eRight( *seed, ebRecHits, topology ) - EcalClusterTools::e2x5Left( *seed, ebRecHits, topology );
319 double SC_seed_Shape_ycog = EcalClusterTools::e2x5Top( *seed, ebRecHits, topology ) - EcalClusterTools::e2x5Bottom( *seed, ebRecHits, topology );
322 if ( debugL_pi0 <= pDEBUG ) {
323 cout <<
"PiZeroDiscriminatorProduce: lazyTool (E1,E3x3,E5x5,E2,cEE,cEP,cPP,E2x2,E3x2_E3x2r,Xcog,Ycog,E2x5Bottom,E2x5Top,Et,Eta,PhiR9) = ( " 324 << SC_seed_Shape_E1 <<
" " 325 << SC_seed_Shape_E3x3 <<
" " 326 << SC_seed_Shape_E5x5 <<
" " 327 << SC_seed_Shape_E2 <<
" " 328 << SC_seed_Shape_cEE <<
" " 329 << SC_seed_Shape_cEP <<
" " 330 << SC_seed_Shape_cPP <<
" " 331 << SC_seed_Shape_E2x2 <<
" " 332 << SC_seed_Shape_E3x2 <<
" " 333 << SC_seed_Shape_E3x2r <<
" " 334 << SC_seed_Shape_xcog <<
" " 335 << SC_seed_Shape_ycog <<
" " 336 << EcalClusterTools::e2x5Bottom( *seed, ebRecHits, topology ) <<
" " 337 << EcalClusterTools::e2x5Top( *seed, ebRecHits, topology ) <<
" " 341 << Phot_R9 <<
" )" << endl;
344 float SC_et = it_super->energy()*
sin(2*atan(
exp(-it_super->eta())));
346 presh_pi0_algo->calculateBarrelNNInputVariables(SC_et, SC_seed_Shape_E1, SC_seed_Shape_E3x3,
347 SC_seed_Shape_E5x5, SC_seed_Shape_E2,
348 SC_seed_Shape_cEE, SC_seed_Shape_cEP,
349 SC_seed_Shape_cPP, SC_seed_Shape_E2x2,
350 SC_seed_Shape_E3x2, SC_seed_Shape_E3x2r,
351 SC_seed_Shape_xcog, SC_seed_Shape_ycog);
353 float* nn_input_var = presh_pi0_algo->get_input_vector();
355 if ( debugL_pi0 <= pDEBUG ) {
356 cout <<
" PiZeroDiscriminatorProducer : NN_barrel_nonESEndcap_variables+Et+Eta+Phi+R9 = " ;
357 for(
int k3=0;k3<12;k3++) {
358 cout << nn_input_var[k3] <<
" " ;
360 cout << SC_Et <<
" " << SC_eta <<
" " << SC_phi <<
" " << Phot_R9 << endl;
364 nnoutput = presh_pi0_algo->GetBarrelNNOutput(SC_et);
367 if ( debugL_pi0 <= pDEBUG ) {
368 cout <<
"PiZeroDiscriminatorProducer : Event : " << evt.
id()
369 <<
" SC id = " << iPho - corrPhoCollection.begin()
370 <<
" with Pt = " << SC_Et
371 <<
" eta = " << SC_eta
372 <<
" phi = " << SC_phi
373 <<
" contains: " << it_super->clustersSize() <<
" BCs " 374 <<
" has NNout = " << nnoutput
378 Pi0Assocs_p->insert(
Ref<PhotonCollection>(correctedPhotonHandle,iPho - corrPhoCollection.begin()), nnoutput);
379 }
else { Pi0Assocs_p->insert(
Ref<PhotonCollection>(correctedPhotonHandle,iPho - corrPhoCollection.begin()), -1.);}
382 evt.
put(
std::move(Pi0Assocs_p),PhotonPi0DiscriminatorAssociationMap_);
383 if ( debugL_pi0 <= pDEBUG )
cout <<
"PiZeroDiscriminatorProducer: PhotonPi0DiscriminatorAssociationMap added to the event" << endl;
387 LogDebug(
"PiZeroDiscriminatorDebug") << ostr.str();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Sin< T >::type sin(const T &t)
edm::AssociationMap< edm::OneToValue< std::vector< reco::Photon >, float > > PhotonPi0DiscriminatorAssociationMap
~PiZeroDiscriminatorProducer() override
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
T const * product() const
void produce(edm::Event &evt, const edm::EventSetup &es) override
std::vector< Photon > PhotonCollection
collectin of Photon objects
PiZeroDiscriminatorProducer(const edm::ParameterSet &ps)
T const * product() const