25 barrelEcalHits_token_ = consumes<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > >(pset.
getParameter<
edm::InputTag>(
"barrelEcalHits"));
26 endcapEcalHits_token_ = consumes<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > >(pset.
getParameter<
edm::InputTag>(
"endcapEcalHits"));
31 seleXtalMinEnergy_ = pset.
getParameter<
double> (
"seleXtalMinEnergy");
32 clusSeedThr_ = pset.
getParameter<
double> (
"clusSeedThr");
35 ParameterLogWeighted_ = pset.
getParameter<
bool> (
"ParameterLogWeighted");
36 ParameterX0_ = pset.
getParameter<
double> (
"ParameterX0");
37 ParameterT0_barl_ = pset.
getParameter<
double> (
"ParameterT0_barl");
38 ParameterW0_ = pset.
getParameter<
double> (
"ParameterW0");
40 selePtGammaOne_ = pset.
getParameter<
double> (
"selePtGammaOne");
41 selePtGammaTwo_ = pset.
getParameter<
double> (
"selePtGammaTwo");
42 seleS4S9GammaOne_ = pset.
getParameter<
double> (
"seleS4S9GammaOne");
43 seleS4S9GammaTwo_ = pset.
getParameter<
double> (
"seleS4S9GammaTwo");
46 selePi0BeltDR_ = pset.
getParameter<
double> (
"selePi0BeltDR");
47 selePi0BeltDeta_ = pset.
getParameter<
double> (
"selePi0BeltDeta");
48 seleMinvMaxPi0_ = pset.
getParameter<
double> (
"seleMinvMaxPi0");
49 seleMinvMinPi0_ = pset.
getParameter<
double> (
"seleMinvMinPi0");
61 currentFolder_.str(
"");
62 currentFolder_ <<
"Egamma/PiZeroAnalyzer/";
65 hMinvPi0EB_ = ibooker.
book1D(
"Pi0InvmassEB",
"Pi0 Invariant Mass in EB",100,0.,0.5);
68 hPt1Pi0EB_ = ibooker.
book1D(
"Pt1Pi0EB",
"Pt 1st most energetic Pi0 photon in EB",100,0.,20.);
71 hPt2Pi0EB_ = ibooker.
book1D(
"Pt2Pi0EB",
"Pt 2nd most energetic Pi0 photon in EB",100,0.,20.);
74 hPtPi0EB_ = ibooker.
book1D(
"PtPi0EB",
"Pi0 Pt in EB",100,0.,20.);
77 hIsoPi0EB_ = ibooker.
book1D(
"IsoPi0EB",
"Pi0 Iso in EB",50,0.,1.);
85 if (nEvt_% prescaleFactor_ )
return;
87 LogInfo(
"PiZeroAnalyzer") <<
"PiZeroAnalyzer Analyzing event number: " << e.
id() <<
" Global Counter " << nEvt_ <<
"\n";
90 bool validEcalRecHits=
true;
93 e.
getByToken(barrelEcalHits_token_, barrelHitHandle);
94 if (!barrelHitHandle.
isValid()) {
95 edm::LogError(
"PhotonProducer") <<
"Error! Can't get the product: barrelEcalHits_token_";
96 validEcalRecHits=
false;
100 e.
getByToken(endcapEcalHits_token_, endcapHitHandle);
102 if (!endcapHitHandle.
isValid()) {
103 edm::LogError(
"PhotonProducer") <<
"Error! Can't get the product: endcapEcalHits_token_";
104 validEcalRecHits=
false;
107 if (validEcalRecHits) makePizero(esup, barrelHitHandle, endcapHitHandle);
126 std::map<DetId, EcalRecHit> recHitsEB_map;
128 std::vector<EcalRecHit> seeds;
132 vector<EBDetId> usedXtals;
137 static const int MAXCLUS = 2000;
140 vector<float> etClus;
141 vector<float> etaClus;
142 vector<float> phiClus;
143 vector<EBDetId> max_hit;
144 vector< vector<EcalRecHit> > RecHitsCluster;
145 vector<float> s4s9Clus;
148 for(itb=rhEB->
begin(); itb!=rhEB->
end(); ++itb){
150 double energy = itb->energy();
151 if (energy > seleXtalMinEnergy_) {
152 std::pair<DetId, EcalRecHit> map_entry(itb->id(), *itb);
153 recHitsEB_map.insert(map_entry);
155 if (energy > clusSeedThr_) seeds.push_back(*itb);
158 sort(seeds.begin(), seeds.end(), [](
auto& x,
auto& y){
return (x.energy() > y.energy());});
159 for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
160 EBDetId seed_id = itseed->id();
161 std::vector<EBDetId>::const_iterator usedIds;
163 bool seedAlreadyUsed=
false;
164 for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
165 if(*usedIds==seed_id){
166 seedAlreadyUsed=
true;
171 if(seedAlreadyUsed)
continue;
173 std::vector<DetId> clus_v = topology_p->
getWindow(seed_id,clusEtaSize_,clusPhiSize_);
175 std::vector<std::pair<DetId, float> > clus_used;
177 vector<EcalRecHit> RecHitsInWindow;
179 double simple_energy = 0;
181 for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
184 bool HitAlreadyUsed=
false;
185 for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
191 if(HitAlreadyUsed)
continue;
192 if (recHitsEB_map.find(*det) != recHitsEB_map.end()){
194 std::map<DetId, EcalRecHit>::iterator aHit;
195 aHit = recHitsEB_map.find(*det);
196 usedXtals.push_back(*det);
197 RecHitsInWindow.push_back(aHit->second);
198 clus_used.push_back( std::pair<DetId, float>(*det, 1.) );
199 simple_energy = simple_energy + aHit->second.energy();
204 float theta_s = 2. * atan(
exp(-clus_pos.eta()));
205 float p0x_s = simple_energy *
sin(theta_s) *
cos(clus_pos.phi());
206 float p0y_s = simple_energy *
sin(theta_s) *
sin(clus_pos.phi());
208 float et_s =
sqrt( p0x_s*p0x_s + p0y_s*p0y_s);
212 eClus.push_back(simple_energy);
213 etClus.push_back(et_s);
214 etaClus.push_back(clus_pos.eta());
215 phiClus.push_back(clus_pos.phi());
216 max_hit.push_back(seed_id);
217 RecHitsCluster.push_back(RecHitsInWindow);
221 for(
int i=0;
i<4;
i++)s4s9_[
i]= itseed->energy();
222 for(
unsigned int j=0; j<RecHitsInWindow.size();j++){
224 if((((
EBDetId)RecHitsInWindow[j].
id()).ieta() == seed_id.
ieta()-1 && seed_id.
ieta()!=1 ) || ( seed_id.
ieta()==1 && (((
EBDetId)RecHitsInWindow[j].
id()).ieta() == seed_id.
ieta()-2))){
225 if(((
EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.
iphi()-1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()-1 ){
226 s4s9_[0]+=RecHitsInWindow[j].energy();
228 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()){
229 s4s9_[0]+=RecHitsInWindow[j].energy();
230 s4s9_[1]+=RecHitsInWindow[j].energy();
232 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()+1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()+1 ){
233 s4s9_[1]+=RecHitsInWindow[j].energy();
238 if(((
EBDetId)RecHitsInWindow[j].
id()).ieta() == seed_id.
ieta()){
239 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()-1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()-1 ){
240 s4s9_[0]+=RecHitsInWindow[j].energy();
241 s4s9_[3]+=RecHitsInWindow[j].energy();
243 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()+1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()+1 ){
244 s4s9_[1]+=RecHitsInWindow[j].energy();
245 s4s9_[2]+=RecHitsInWindow[j].energy();
249 if((((
EBDetId)RecHitsInWindow[j].
id()).ieta() == seed_id.
ieta()+1 && seed_id.
ieta()!=-1 ) || ( seed_id.
ieta()==-1 && (((
EBDetId)RecHitsInWindow[j].
id()).ieta() == seed_id.
ieta()+2))){
250 if(((
EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.
iphi()-1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()-1 ){
251 s4s9_[3]+=RecHitsInWindow[j].energy();
253 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()){
254 s4s9_[2]+=RecHitsInWindow[j].energy();
255 s4s9_[3]+=RecHitsInWindow[j].energy();
257 if(((
EBDetId)RecHitsInWindow[j].
id()).iphi() == seed_id.
iphi()+1 ||((
EBDetId)RecHitsInWindow[j].
id()).iphi()-360 == seed_id.
iphi()+1 ){
258 s4s9_[2]+=RecHitsInWindow[j].energy();
263 cout<<
" (EBDetId)RecHitsInWindow[j].id()).ieta() "<<((
EBDetId)RecHitsInWindow[j].
id()).ieta()<<
" seed_id.ieta() "<<seed_id.
ieta()<<endl;
264 cout<<
" Problem with S4 calculation "<<endl;
return;
269 s4s9Clus.push_back(*max_element( s4s9_,s4s9_+4)/simple_energy);
273 if (nClus == MAXCLUS)
return;
280 static const int MAXPI0S = 200;
283 vector<EBDetId> scXtals;
286 if (nClus <= 1)
return;
287 for(Int_t
i=0 ;
i<nClus ;
i++){
288 for(Int_t j=
i+1 ; j<nClus ; j++){
290 if( etClus[
i]>selePtGammaOne_ && etClus[j]>selePtGammaTwo_ && s4s9Clus[
i]>seleS4S9GammaOne_ && s4s9Clus[j]>seleS4S9GammaTwo_){
291 float theta_0 = 2. * atan(
exp(-etaClus[
i]));
292 float theta_1 = 2. * atan(
exp(-etaClus[j]));
294 float p0x = eClus[
i] *
sin(theta_0) *
cos(phiClus[i]);
295 float p1x = eClus[j] *
sin(theta_1) *
cos(phiClus[j]);
296 float p0y = eClus[
i] *
sin(theta_0) *
sin(phiClus[i]);
297 float p1y = eClus[j] *
sin(theta_1) *
sin(phiClus[j]);
298 float p0z = eClus[
i] *
cos(theta_0);
299 float p1z = eClus[j] *
cos(theta_1);
301 float pt_pi0 =
sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
303 if (pt_pi0 < selePtPi0_)
continue;
304 float m_inv =
sqrt ( (eClus[i] + eClus[j])*(eClus[i] + eClus[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
305 if ( (m_inv<seleMinvMaxPi0_) && (m_inv>seleMinvMinPi0_) ){
311 TVector3 pi0vect = TVector3((p0x+p1x), (p0y+p1y), (p0z+p1z));
312 for(Int_t
k=0 ;
k<nClus ;
k++){
313 if(
k==i ||
k==j)
continue;
314 TVector3 Clusvect = TVector3(eClus[
k] *
sin(2. * atan(
exp(-etaClus[
k]))) *
cos(phiClus[k]), eClus[k] *
sin(2. * atan(
exp(-etaClus[k]))) *
sin(phiClus[k]) , eClus[k] *
cos(2. * atan(
exp(-etaClus[k]))));
315 float dretaclpi0 = fabs(etaClus[k] - pi0vect.Eta());
316 float drclpi0 = Clusvect.DeltaR(pi0vect);
318 if((drclpi0<selePi0BeltDR_) && (dretaclpi0<selePi0BeltDeta_) ){
320 Iso = Iso + etClus[
k];
321 IsoClus.push_back(k);
326 if(Iso/pt_pi0<selePi0Iso_){
328 hMinvPi0EB_->Fill(m_inv);
329 hPt1Pi0EB_->Fill(etClus[i]);
330 hPt2Pi0EB_->Fill(etClus[j]);
331 hPtPi0EB_->Fill(pt_pi0);
332 hIsoPi0EB_->Fill(Iso/pt_pi0);
338 if(npi0_s == MAXPI0S)
return;
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
PiZeroAnalyzer(const edm::ParameterSet &)
void makePizero(const edm::EventSetup &es, const edm::Handle< EcalRecHitCollection > eb, const edm::Handle< EcalRecHitCollection > ee)
Sin< T >::type sin(const T &t)
std::vector< EcalRecHit >::const_iterator const_iterator
int iphi() const
get the crystal iphi
void setCurrentFolder(std::string const &fullpath)
Cos< T >::type cos(const T &t)
MonitorElement * book1D(Args &&...args)
int ieta() const
get the crystal ieta
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
const_iterator end() const
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
T const * product() const
XYZPointD XYZPoint
point in space with cartesian internal representation
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=0)
~PiZeroAnalyzer() override
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
const_iterator begin() const