CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PiZeroAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 //
3 
5 
6 
7 //#define TWOPI 6.283185308
8 //
9 
23 using namespace std;
24 
25 
27 {
28 
29  fName_ = pset.getUntrackedParameter<std::string>("Name");
30  verbosity_ = pset.getUntrackedParameter<int>("Verbosity");
31 
32  prescaleFactor_ = pset.getUntrackedParameter<int>("prescaleFactor",1);
33 
34 
35 
36  barrelEcalHits_ = pset.getParameter<edm::InputTag>("barrelEcalHits");
37  endcapEcalHits_ = pset.getParameter<edm::InputTag>("endcapEcalHits");
38 
39 
40  standAlone_ = pset.getParameter<bool>("standAlone");
41 
42 
43 
44 
45 
46  // parameters for Pizero finding
47  seleXtalMinEnergy_ = pset.getParameter<double> ("seleXtalMinEnergy");
48  clusSeedThr_ = pset.getParameter<double> ("clusSeedThr");
49  clusEtaSize_ = pset.getParameter<int> ("clusEtaSize");
50  clusPhiSize_ = pset.getParameter<int> ("clusPhiSize");
51  ParameterLogWeighted_ = pset.getParameter<bool> ("ParameterLogWeighted");
52  ParameterX0_ = pset.getParameter<double> ("ParameterX0");
53  ParameterT0_barl_ = pset.getParameter<double> ("ParameterT0_barl");
54  ParameterW0_ = pset.getParameter<double> ("ParameterW0");
55 
56  selePtGammaOne_ = pset.getParameter<double> ("selePtGammaOne");
57  selePtGammaTwo_ = pset.getParameter<double> ("selePtGammaTwo");
58  seleS4S9GammaOne_ = pset.getParameter<double> ("seleS4S9GammaOne");
59  seleS4S9GammaTwo_ = pset.getParameter<double> ("seleS4S9GammaTwo");
60  selePtPi0_ = pset.getParameter<double> ("selePtPi0");
61  selePi0Iso_ = pset.getParameter<double> ("selePi0Iso");
62  selePi0BeltDR_ = pset.getParameter<double> ("selePi0BeltDR");
63  selePi0BeltDeta_ = pset.getParameter<double> ("selePi0BeltDeta");
64  seleMinvMaxPi0_ = pset.getParameter<double> ("seleMinvMaxPi0");
65  seleMinvMinPi0_ = pset.getParameter<double> ("seleMinvMinPi0");
66 
67  parameters_ = pset;
68 
69 
70 }
71 
72 
73 
75 
76 
77 
78 
79 }
80 
81 
83 {
84 
85 
86  nEvt_=0;
87  nEntry_=0;
88 
89  dbe_ = 0;
91 
92 
93 
94  if (dbe_) {
95  if (verbosity_ > 0 ) {
96  dbe_->setVerbose(1);
97  } else {
98  dbe_->setVerbose(0);
99  }
100  }
101  if (dbe_) {
102  if (verbosity_ > 0 ) dbe_->showDirStructure();
103  }
104 
105 
106 
107 
108  //booking all histograms
109 
110  if (dbe_) {
111 
112  currentFolder_.str("");
113  currentFolder_ << "Egamma/PiZeroAnalyzer/";
114  dbe_->setCurrentFolder(currentFolder_.str());
115 
116 
117 
118 
119  hMinvPi0EB_ = dbe_->book1D("Pi0InvmassEB","Pi0 Invariant Mass in EB",100,0.,0.5);
120  hMinvPi0EB_->setAxisTitle("Inv Mass [GeV] ",1);
121 
122  hPt1Pi0EB_ = dbe_->book1D("Pt1Pi0EB","Pt 1st most energetic Pi0 photon in EB",100,0.,20.);
123  hPt1Pi0EB_->setAxisTitle("1st photon Pt [GeV] ",1);
124 
125  hPt2Pi0EB_ = dbe_->book1D("Pt2Pi0EB","Pt 2nd most energetic Pi0 photon in EB",100,0.,20.);
126  hPt2Pi0EB_->setAxisTitle("2nd photon Pt [GeV] ",1);
127 
128  hPtPi0EB_ = dbe_->book1D("PtPi0EB","Pi0 Pt in EB",100,0.,20.);
129  hPtPi0EB_->setAxisTitle("Pi0 Pt [GeV] ",1);
130 
131  hIsoPi0EB_ = dbe_->book1D("IsoPi0EB","Pi0 Iso in EB",50,0.,1.);
132  hIsoPi0EB_->setAxisTitle("Pi0 Iso",1);
133 
134 
135  }
136 
137 }
138 
139 
140 
141 
142 
143 
145 {
146 
147  using namespace edm;
148 
149  if (nEvt_% prescaleFactor_ ) return;
150  nEvt_++;
151  LogInfo("PiZeroAnalyzer") << "PiZeroAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
152 
153 
154  // Get EcalRecHits
155  bool validEcalRecHits=true;
156  Handle<EcalRecHitCollection> barrelHitHandle;
157  EcalRecHitCollection barrelRecHits;
158  e.getByLabel(barrelEcalHits_, barrelHitHandle);
159  if (!barrelHitHandle.isValid()) {
160  edm::LogError("PhotonProducer") << "Error! Can't get the product "<<barrelEcalHits_.label();
161  validEcalRecHits=false;
162  }
163 
164  Handle<EcalRecHitCollection> endcapHitHandle;
165  e.getByLabel(endcapEcalHits_, endcapHitHandle);
166  EcalRecHitCollection endcapRecHits;
167  if (!endcapHitHandle.isValid()) {
168  edm::LogError("PhotonProducer") << "Error! Can't get the product "<<endcapEcalHits_.label();
169  validEcalRecHits=false;
170  }
171 
172  if (validEcalRecHits) makePizero(esup, barrelHitHandle, endcapHitHandle);
173 
174 
175 
176 }
177 
179 
180  const EcalRecHitCollection *hitCollection_p = rhEB.product();
181 
182  edm::ESHandle<CaloGeometry> geoHandle;
183  es.get<CaloGeometryRecord>().get(geoHandle);
184 
185  edm::ESHandle<CaloTopology> theCaloTopology;
186  es.get<CaloTopologyRecord>().get(theCaloTopology);
187 
188 
189  const CaloSubdetectorGeometry *geometry_p;
190  const CaloSubdetectorTopology *topology_p;
191  const CaloSubdetectorGeometry *geometryES_p;
192  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
193  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
194 
195  // Parameters for the position calculation:
196  edm::ParameterSet posCalcParameters =
197  parameters_.getParameter<edm::ParameterSet>("posCalcParameters");
198  PositionCalc posCalculator_ = PositionCalc(posCalcParameters);
199  //
200  std::map<DetId, EcalRecHit> recHitsEB_map;
201  //
202  std::vector<EcalRecHit> seeds;
203 
204  seeds.clear();
205  //
206  vector<EBDetId> usedXtals;
207  usedXtals.clear();
208  //
210  //
211  static const int MAXCLUS = 2000;
212  int nClus=0;
213  vector<float> eClus;
214  vector<float> etClus;
215  vector<float> etaClus;
216  vector<float> phiClus;
217  vector<EBDetId> max_hit;
218  vector< vector<EcalRecHit> > RecHitsCluster;
219  vector<float> s4s9Clus;
220 
221  // find cluster seeds in EB
222  for(itb=rhEB->begin(); itb!=rhEB->end(); ++itb){
223  EBDetId id(itb->id());
224  double energy = itb->energy();
225  if (energy > seleXtalMinEnergy_) {
226  std::pair<DetId, EcalRecHit> map_entry(itb->id(), *itb);
227  recHitsEB_map.insert(map_entry);
228  }
229  if (energy > clusSeedThr_) seeds.push_back(*itb);
230  } // Eb rechits
231 
232  sort(seeds.begin(), seeds.end(), ecalRecHitLess());
233  for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
234  EBDetId seed_id = itseed->id();
235  std::vector<EBDetId>::const_iterator usedIds;
236 
237  bool seedAlreadyUsed=false;
238  for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
239  if(*usedIds==seed_id){
240  seedAlreadyUsed=true;
241  //cout<< " Seed with energy "<<itseed->energy()<<" was used !"<<endl;
242  break;
243  }
244  }
245  if(seedAlreadyUsed)continue;
246  topology_p = theCaloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
247  std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
248  //std::vector<DetId> clus_used;
249  std::vector<std::pair<DetId, float> > clus_used;
250 
251  vector<EcalRecHit> RecHitsInWindow;
252 
253  double simple_energy = 0;
254 
255  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
256  EBDetId EBdet = *det;
257  // cout<<" det "<< EBdet<<" ieta "<<EBdet.ieta()<<" iphi "<<EBdet.iphi()<<endl;
258  bool HitAlreadyUsed=false;
259  for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
260  if(*usedIds==*det){
261  HitAlreadyUsed=true;
262  break;
263  }
264  }
265  if(HitAlreadyUsed)continue;
266  if (recHitsEB_map.find(*det) != recHitsEB_map.end()){
267  // cout<<" Used det "<< EBdet<<endl;
268  std::map<DetId, EcalRecHit>::iterator aHit;
269  aHit = recHitsEB_map.find(*det);
270  usedXtals.push_back(*det);
271  RecHitsInWindow.push_back(aHit->second);
272  clus_used.push_back( std::pair<DetId, float>(*det, 1.) );
273  simple_energy = simple_energy + aHit->second.energy();
274  }
275  }
276 
277  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hitCollection_p,geometry_p,geometryES_p);
278  float theta_s = 2. * atan(exp(-clus_pos.eta()));
279  float p0x_s = simple_energy * sin(theta_s) * cos(clus_pos.phi());
280  float p0y_s = simple_energy * sin(theta_s) * sin(clus_pos.phi());
281  // float p0z_s = simple_energy * cos(theta_s);
282  float et_s = sqrt( p0x_s*p0x_s + p0y_s*p0y_s);
283 
284  //cout << " Simple Clustering: E,Et,px,py,pz: "<<simple_energy<<" "<<et_s<<" "<<p0x_s<<" "<<p0y_s<<" "<<endl;
285 
286  eClus.push_back(simple_energy);
287  etClus.push_back(et_s);
288  etaClus.push_back(clus_pos.eta());
289  phiClus.push_back(clus_pos.phi());
290  max_hit.push_back(seed_id);
291  RecHitsCluster.push_back(RecHitsInWindow);
292  //Compute S4/S9 variable
293  //We are not sure to have 9 RecHits so need to check eta and phi:
294  float s4s9_[4];
295  for(int i=0;i<4;i++)s4s9_[i]= itseed->energy();
296  for(unsigned int j=0; j<RecHitsInWindow.size();j++){
297  //cout << " Simple cluster rh, ieta, iphi : "<<((EBDetId)RecHitsInWindow[j].id()).ieta()<<" "<<((EBDetId)RecHitsInWindow[j].id()).iphi()<<endl;
298  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))){
299  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()-1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()-1 ){
300  s4s9_[0]+=RecHitsInWindow[j].energy();
301  }else{
302  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()){
303  s4s9_[0]+=RecHitsInWindow[j].energy();
304  s4s9_[1]+=RecHitsInWindow[j].energy();
305  }else{
306  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()+1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()+1 ){
307  s4s9_[1]+=RecHitsInWindow[j].energy();
308  }
309  }
310  }
311  }else{
312  if(((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta()){
313  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()-1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()-1 ){
314  s4s9_[0]+=RecHitsInWindow[j].energy();
315  s4s9_[3]+=RecHitsInWindow[j].energy();
316  }else{
317  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()+1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()+1 ){
318  s4s9_[1]+=RecHitsInWindow[j].energy();
319  s4s9_[2]+=RecHitsInWindow[j].energy();
320  }
321  }
322  }else{
323  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))){
324  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()-1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()-1 ){
325  s4s9_[3]+=RecHitsInWindow[j].energy();
326  }else{
327  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()){
328  s4s9_[2]+=RecHitsInWindow[j].energy();
329  s4s9_[3]+=RecHitsInWindow[j].energy();
330  }else{
331  if(((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()+1 ||((EBDetId)RecHitsInWindow[j].id()).iphi()-360 == seed_id.iphi()+1 ){
332  s4s9_[2]+=RecHitsInWindow[j].energy();
333  }
334  }
335  }
336  }else{
337  cout<<" (EBDetId)RecHitsInWindow[j].id()).ieta() "<<((EBDetId)RecHitsInWindow[j].id()).ieta()<<" seed_id.ieta() "<<seed_id.ieta()<<endl;
338  cout<<" Problem with S4 calculation "<<endl;return;
339  }
340  }
341  }
342  }
343  s4s9Clus.push_back(*max_element( s4s9_,s4s9_+4)/simple_energy);
344  // cout<<" s4s9Clus[0] "<<s4s9_[0]/simple_energy<<" s4s9Clus[1] "<<s4s9_[1]/simple_energy<<" s4s9Clus[2] "<<s4s9_[2]/simple_energy<<" s4s9Clus[3] "<<s4s9_[3]/simple_energy<<endl;
345  // cout<<" Max "<<*max_element( s4s9_,s4s9_+4)/simple_energy<<endl;
346  nClus++;
347  if (nClus == MAXCLUS) return;
348  } // End loop over seed clusters
349 
350  // cout<< " Pi0 clusters: "<<nClus<<endl;
351 
352  // Selection, based on Simple clustering
353  //pi0 candidates
354  static const int MAXPI0S = 200;
355  int npi0_s=0;
356 
357  vector<EBDetId> scXtals;
358  scXtals.clear();
359 
360  if (nClus <= 1) return;
361  for(Int_t i=0 ; i<nClus ; i++){
362  for(Int_t j=i+1 ; j<nClus ; j++){
363  // cout<<" i "<<i<<" etClus[i] "<<etClus[i]<<" j "<<j<<" etClus[j] "<<etClus[j]<<endl;
364  if( etClus[i]>selePtGammaOne_ && etClus[j]>selePtGammaTwo_ && s4s9Clus[i]>seleS4S9GammaOne_ && s4s9Clus[j]>seleS4S9GammaTwo_){
365  float theta_0 = 2. * atan(exp(-etaClus[i]));
366  float theta_1 = 2. * atan(exp(-etaClus[j]));
367 
368  float p0x = eClus[i] * sin(theta_0) * cos(phiClus[i]);
369  float p1x = eClus[j] * sin(theta_1) * cos(phiClus[j]);
370  float p0y = eClus[i] * sin(theta_0) * sin(phiClus[i]);
371  float p1y = eClus[j] * sin(theta_1) * sin(phiClus[j]);
372  float p0z = eClus[i] * cos(theta_0);
373  float p1z = eClus[j] * cos(theta_1);
374 
375  float pt_pi0 = sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
376  // cout<<" pt_pi0 "<<pt_pi0<<endl;
377  if (pt_pi0 < selePtPi0_)continue;
378  float m_inv = sqrt ( (eClus[i] + eClus[j])*(eClus[i] + eClus[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
379  if ( (m_inv<seleMinvMaxPi0_) && (m_inv>seleMinvMinPi0_) ){
380 
381  //New Loop on cluster to measure isolation:
382  vector<int> IsoClus;
383  IsoClus.clear();
384  float Iso = 0;
385  TVector3 pi0vect = TVector3((p0x+p1x), (p0y+p1y), (p0z+p1z));
386  for(Int_t k=0 ; k<nClus ; k++){
387  if(k==i || k==j)continue;
388  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]))));
389  float dretaclpi0 = fabs(etaClus[k] - pi0vect.Eta());
390  float drclpi0 = Clusvect.DeltaR(pi0vect);
391 
392  if((drclpi0<selePi0BeltDR_) && (dretaclpi0<selePi0BeltDeta_) ){
393 
394  Iso = Iso + etClus[k];
395  IsoClus.push_back(k);
396  }
397  }
398 
399 
400  if(Iso/pt_pi0<selePi0Iso_){
401 
402  hMinvPi0EB_->Fill(m_inv);
403  hPt1Pi0EB_->Fill(etClus[i]);
404  hPt2Pi0EB_->Fill(etClus[j]);
405  hPtPi0EB_->Fill(pt_pi0);
406  hIsoPi0EB_->Fill(Iso/pt_pi0);
407 
408 
409  npi0_s++;
410  }
411 
412  if(npi0_s == MAXPI0S) return;
413  }
414  }
415  }
416  }
417 
418 }
419 
420 
421 
423 {
424 
425 
426 
427  bool outputMEsInRootFile = parameters_.getParameter<bool>("OutputMEsInRootFile");
428  std::string outputFileName = parameters_.getParameter<std::string>("OutputFileName");
429  if(outputMEsInRootFile){
430  dbe_->save(outputFileName);
431  }
432 
433  edm::LogInfo("PiZeroAnalyzer") << "Analyzed " << nEvt_ << "\n";
434  return ;
435 }
436 
437 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
PiZeroAnalyzer(const edm::ParameterSet &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1883
void makePizero(const edm::EventSetup &es, const edm::Handle< EcalRecHitCollection > eb, const edm::Handle< EcalRecHitCollection > ee)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< T >::const_iterator const_iterator
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
return((rh^lh)&mask)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:46
T sqrt(T t)
Definition: SSEVec.h:28
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
tuple pset
Definition: CrabTask.py:85
void setVerbose(unsigned level)
Definition: DQMStore.cc:201
int ieta() const
get the crystal ieta
Definition: EBDetId.h:44
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
DQMStore * dbe_
virtual void endJob()
int k[5][pyjets_maxn]
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:74
edm::EventID id() const
Definition: EventBase.h:56
virtual ~PiZeroAnalyzer()
tuple cout
Definition: gather_cfg.py:41
void showDirStructure(void) const
Definition: DQMStore.cc:2539
virtual void beginJob()
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237