CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalSimHitsValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalSimHitsValidation.cc
3  *
4  * \author C.Rovelli
5  *
6 */
7 
14 
15 using namespace cms;
16 using namespace edm;
17 using namespace std;
18 
20  HepMCLabel(ps.getParameter<std::string>("moduleLabelMC")),
21  g4InfoLabel(ps.getParameter<std::string>("moduleLabelG4")),
22  EBHitsCollection(ps.getParameter<std::string>("EBHitsCollection")),
23  EEHitsCollection(ps.getParameter<std::string>("EEHitsCollection")),
24  ESHitsCollection(ps.getParameter<std::string>("ESHitsCollection")){
25 
26  // DQM ROOT output
27  outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "");
28 
29  if ( outputFile_.size() != 0 ) {
30  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will be saved to " << outputFile_.c_str();
31  } else {
32  edm::LogInfo("OutputInfo") << " Ecal SimHits Task histograms will NOT be saved";
33  }
34 
35  // verbosity switch
36  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
37 
38  // DQMServices
39  dbe_ = 0;
40 
41  // get hold of back-end interface
42  dbe_ = edm::Service<DQMStore>().operator->();
43  if ( dbe_ ) {
44  if ( verbose_ ) { dbe_->setVerbose(1); }
45  else { dbe_->setVerbose(0); }
46  }
47 
48  if ( dbe_ ) {
49  if ( verbose_ ) dbe_->showDirStructure();
50  }
51 
52  meGunEnergy_ = 0;
53  meGunEta_ = 0;
54  meGunPhi_ = 0;
58 
59  Char_t histo[200];
60 
61 
62  if ( dbe_ ) {
63  dbe_->setCurrentFolder("EcalHitsV/EcalSimHitsValidation");
64 
65  sprintf (histo, "EcalSimHitsValidation Gun Momentum" ) ;
66  meGunEnergy_ = dbe_->book1D(histo, histo, 100, 0., 1000.);
67 
68  sprintf (histo, "EcalSimHitsValidation Gun Eta" ) ;
69  meGunEta_ = dbe_->book1D(histo, histo, 700, -3.5, 3.5);
70 
71  sprintf (histo, "EcalSimHitsValidation Gun Phi" ) ;
72  meGunPhi_ = dbe_->book1D(histo, histo, 360, 0., 360.);
73 
74  sprintf (histo, "EcalSimHitsValidation Barrel fraction of energy" ) ;
75  meEBEnergyFraction_ = dbe_->book1D(histo, histo, 100 , 0. , 1.1);
76 
77  sprintf (histo, "EcalSimHitsValidation Endcap fraction of energy" ) ;
78  meEEEnergyFraction_ = dbe_->book1D(histo, histo, 100 , 0. , 1.1);
79 
80  sprintf (histo, "EcalSimHitsValidation Preshower fraction of energy" ) ;
81  meESEnergyFraction_ = dbe_->book1D(histo, histo, 60 , 0. , 0.001);
82  }
83 
84 }
85 
87 
88  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
89 
90 }
91 
93 
94 }
95 
97 
98 }
99 
101 
102  edm::LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
103 
104  std::vector<PCaloHit> theEBCaloHits;
105  std::vector<PCaloHit> theEECaloHits;
106  std::vector<PCaloHit> theESCaloHits;
107 
112 
113  e.getByLabel(HepMCLabel, MCEvt);
117 
118  for ( HepMC::GenEvent::particle_const_iterator p = MCEvt->GetEvent()->particles_begin();
119  p != MCEvt->GetEvent()->particles_end(); ++p ) {
120 
121  double htheta = (*p)->momentum().theta();
122  double heta = -99999.;
123  if( tan(htheta * 0.5) > 0 ) {
124  heta = -log(tan(htheta * 0.5));
125  }
126  double hphi = (*p)->momentum().phi();
127  hphi = (hphi>=0) ? hphi : hphi+2*M_PI;
128  hphi = hphi / M_PI * 180.;
129 
130  LogDebug("EventInfo") << "Particle gun type form MC = " << abs((*p)->pdg_id()) << "\n" << "Energy = "<< (*p)->momentum().e() << " Eta = " << heta << " Phi = " << hphi;
131 
132  if (meGunEnergy_) meGunEnergy_->Fill((*p)->momentum().e());
133  if (meGunEta_) meGunEta_ ->Fill(heta);
134  if (meGunPhi_) meGunPhi_ ->Fill(hphi);
135 
136  }
137 
138  double EBEnergy_ = 0.;
139  if ( EcalHitsEB.isValid() ) {
140  theEBCaloHits.insert(theEBCaloHits.end(), EcalHitsEB->begin(), EcalHitsEB->end());
141  for (std::vector<PCaloHit>::iterator isim = theEBCaloHits.begin();
142  isim != theEBCaloHits.end(); ++isim){
143  EBEnergy_ += isim->energy();
144  }
145  }
146 
147  double EEEnergy_ = 0.;
148  if ( EcalHitsEE.isValid() ) {
149  theEECaloHits.insert(theEECaloHits.end(), EcalHitsEE->begin(), EcalHitsEE->end());
150  for (std::vector<PCaloHit>::iterator isim = theEECaloHits.begin();
151  isim != theEECaloHits.end(); ++isim){
152  EEEnergy_ += isim->energy();
153  }
154  }
155 
156  double ESEnergy_ = 0.;
157  if ( EcalHitsES.isValid() ) {
158  theESCaloHits.insert(theESCaloHits.end(), EcalHitsES->begin(), EcalHitsES->end());
159  for (std::vector<PCaloHit>::iterator isim = theESCaloHits.begin();
160  isim != theESCaloHits.end(); ++isim){
161  ESEnergy_ += isim->energy();
162  }
163  }
164 
165  double etot = EBEnergy_ + EEEnergy_ + ESEnergy_ ;
166  double fracEB = 0.0;
167  double fracEE = 0.0;
168  double fracES = 0.0;
169 
170  if (etot>0.0) {
171  fracEB = EBEnergy_/etot;
172  fracEE = EEEnergy_/etot;
173  fracES = ESEnergy_/etot;
174  }
175 
177 
179 
181 }
182 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
MonitorElement * meEBEnergyFraction_
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
void Fill(long long x)
MonitorElement * meGunEnergy_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
bool isValid() const
Definition: HandleBase.h:76
EcalSimHitsValidation(const edm::ParameterSet &ps)
Constructor.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
#define M_PI
Definition: BFit3D.cc:3
MonitorElement * meEEEnergyFraction_
edm::EventID id() const
Definition: EventBase.h:56
MonitorElement * meESEnergyFraction_
~EcalSimHitsValidation()
Destructor.