CMS 3D CMS Logo

SimAnalyzerMinbias.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <vector>
8 #include <map>
9 
10 // user include files
22 
27 
33 
35 
36 #include "TFile.h"
37 #include "TTree.h"
38 
39 // class declaration
40 class SimAnalyzerMinbias : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
41 public:
42  explicit SimAnalyzerMinbias(const edm::ParameterSet&);
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44  void analyze(const edm::Event&, const edm::EventSetup&) override;
45  void beginJob() override;
46  void endJob() override;
47  void beginRun(const edm::Run& r, const edm::EventSetup& iSetup) override{};
48  void endRun(const edm::Run& r, const edm::EventSetup& iSetup) override{};
49 
50 private:
51  // ----------member data ---------------------------
53  double timeCut_;
54  TTree* myTree_;
55 
56  // Root tree members
59  struct myInfo {
61  myInfo() { theMB0 = theMB1 = theMB2 = theMB3 = theMB4 = 0; }
62  };
63  std::map<HcalDetId, myInfo> myMap_;
66 };
67 
68 // constructors and destructor
69 
71  usesResource(TFileService::kSharedResource);
72  timeCut_ = iConfig.getUntrackedParameter<double>("TimeCut", 500);
73 
74  // get token names of modules, producing object collections
75  tok_evt_ = consumes<edm::HepMCProduct>(edm::InputTag("generator"));
76  tok_hcal_ = consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "HcalHits"));
77 
78  edm::LogVerbatim("AnalyzerMB") << "Use Time cut of " << timeCut_ << " ns";
79 }
80 
83  desc.addUntracked<double>("TimeCut", 500);
84  descriptions.add("simAnalyzerMinbias", desc);
85 }
86 
88  myTree_ = fs_->make<TTree>("SimJet", "SimJet Tree");
89  myTree_->Branch("mydet", &mydet, "mydet/I");
90  myTree_->Branch("mysubd", &mysubd, "mysubd/I");
91  myTree_->Branch("cells", &cells, "cells");
92  myTree_->Branch("depth", &depth, "depth/I");
93  myTree_->Branch("ieta", &ieta, "ieta/I");
94  myTree_->Branch("iphi", &iphi, "iphi/I");
95  myTree_->Branch("mom0_MB", &mom0_MB, "mom0_MB/F");
96  myTree_->Branch("mom1_MB", &mom1_MB, "mom1_MB/F");
97  myTree_->Branch("mom2_MB", &mom2_MB, "mom2_MB/F");
98  myTree_->Branch("mom3_MB", &mom3_MB, "mom3_MB/F");
99  myTree_->Branch("mom4_MB", &mom4_MB, "mom4_MB/F");
100 
101  myMap_.clear();
102 }
103 
104 // EndJob
105 //
107  cells = 0;
108  for (std::map<HcalDetId, myInfo>::const_iterator itr = myMap_.begin(); itr != myMap_.end(); ++itr) {
109  mysubd = itr->first.subdet();
110  depth = itr->first.depth();
111  iphi = itr->first.iphi();
112  ieta = itr->first.ieta();
113  myInfo info = itr->second;
114  if (info.theMB0 > 0) {
115  mom0_MB = info.theMB0;
116  mom1_MB = info.theMB1;
117  mom2_MB = info.theMB2;
118  mom3_MB = info.theMB3;
119  mom4_MB = info.theMB4;
120  cells++;
121 
122  edm::LogVerbatim("AnalyzerMB") << " Result= " << mysubd << " " << ieta << " " << iphi << " mom0 " << mom0_MB
123  << " mom1 " << mom1_MB << " mom2 " << mom2_MB << " mom3 " << mom3_MB << " mom4 "
124  << mom4_MB;
125  myTree_->Fill();
126  }
127  }
128  edm::LogVerbatim("AnalyzerMB") << "cells " << cells;
129 }
130 
131 //
132 // member functions
133 //
134 
135 // ------------ method called to produce the data ------------
136 
138  edm::LogVerbatim("AnalyzerMB") << " Start SimAnalyzerMinbias::analyze " << iEvent.id().run() << ":"
139  << iEvent.id().event();
140 
142  iEvent.getByToken(tok_evt_, evtMC);
143  if (!evtMC.isValid()) {
144  edm::LogWarning("AnalyzerMB") << "no HepMCProduct found";
145  } else {
146  const HepMC::GenEvent* myGenEvent = evtMC->GetEvent();
147  edm::LogVerbatim("AnalyzerMB") << "Event with " << myGenEvent->particles_size() << " particles + "
148  << myGenEvent->vertices_size() << " vertices";
149  }
150 
152  iEvent.getByToken(tok_hcal_, hcalHits);
153  if (!hcalHits.isValid()) {
154  edm::LogWarning("AnalyzerMB") << "Error! can't get HcalHits product!";
155  return;
156  }
157 
158  const edm::PCaloHitContainer* HitHcal = hcalHits.product();
159  std::map<HcalDetId, double> hitMap;
160  for (std::vector<PCaloHit>::const_iterator hcalItr = HitHcal->begin(); hcalItr != HitHcal->end(); ++hcalItr) {
161  double time = hcalItr->time();
162  if (time < timeCut_) {
163  double energyhit = hcalItr->energy();
164  HcalDetId hid = HcalDetId(hcalItr->id());
165  std::map<HcalDetId, double>::iterator itr1 = hitMap.find(hid);
166  if (itr1 == hitMap.end()) {
167  hitMap[hid] = 0;
168  itr1 = hitMap.find(hid);
169  }
170  itr1->second += energyhit;
171  }
172  }
173  edm::LogVerbatim("AnalyzerMB") << "extract information of " << hitMap.size() << " towers from " << HitHcal->size()
174  << " hits";
175 
176  for (std::map<HcalDetId, double>::const_iterator hcalItr = hitMap.begin(); hcalItr != hitMap.end(); ++hcalItr) {
177  HcalDetId hid = hcalItr->first;
178  double energyhit = hcalItr->second;
179  std::map<HcalDetId, myInfo>::iterator itr1 = myMap_.find(hid);
180  if (itr1 == myMap_.end()) {
181  myInfo info;
182  myMap_[hid] = info;
183  itr1 = myMap_.find(hid);
184  }
185  itr1->second.theMB0++;
186  itr1->second.theMB1 += energyhit;
187  itr1->second.theMB2 += (energyhit * energyhit);
188  itr1->second.theMB3 += (energyhit * energyhit * energyhit);
189  itr1->second.theMB4 += (energyhit * energyhit * energyhit * energyhit);
190  edm::LogVerbatim("AnalyzerMB") << "ID " << hid << " with energy " << energyhit;
191  }
192 }
193 
194 //define this as a plug-in
ConfigurationDescriptions.h
L1GtTriggerMenu.h
HcalRespCorrsRcd.h
EDAnalyzer.h
SimAnalyzerMinbias
Definition: SimAnalyzerMinbias.cc:40
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SimAnalyzerMinbias::tok_hcal_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hcal_
Definition: SimAnalyzerMinbias.cc:65
EDProducer.h
SimAnalyzerMinbias::SimAnalyzerMinbias
SimAnalyzerMinbias(const edm::ParameterSet &)
Definition: SimAnalyzerMinbias.cc:70
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< edm::HepMCProduct >
L1GtTriggerMenuRcd.h
SimAnalyzerMinbias::mom2_MB
float mom2_MB
Definition: SimAnalyzerMinbias.cc:58
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SimAnalyzerMinbias::timeCut_
double timeCut_
Definition: SimAnalyzerMinbias.cc:53
protons_cff.time
time
Definition: protons_cff.py:39
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
SimAnalyzerMinbias::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SimAnalyzerMinbias.cc:137
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
SimAnalyzerMinbias::beginJob
void beginJob() override
Definition: SimAnalyzerMinbias.cc:87
edm::Handle< edm::HepMCProduct >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
SimAnalyzerMinbias::myMap_
std::map< HcalDetId, myInfo > myMap_
Definition: SimAnalyzerMinbias.cc:63
MakerMacros.h
SimAnalyzerMinbias::mom4_MB
float mom4_MB
Definition: SimAnalyzerMinbias.cc:58
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
SimAnalyzerMinbias::tok_evt_
edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
Definition: SimAnalyzerMinbias.cc:64
Service.h
SimAnalyzerMinbias::myInfo::theMB3
double theMB3
Definition: SimAnalyzerMinbias.cc:60
ParameterSetDescription.h
SimAnalyzerMinbias::myInfo::theMB4
double theMB4
Definition: SimAnalyzerMinbias.cc:60
SimAnalyzerMinbias::endJob
void endJob() override
Definition: SimAnalyzerMinbias.cc:106
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TFileService.h
SimAnalyzerMinbias::mom0_MB
float mom0_MB
Definition: SimAnalyzerMinbias.cc:58
SimAnalyzerMinbias::myInfo::theMB0
double theMB0
Definition: SimAnalyzerMinbias.cc:60
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
HcalDetId.h
HcalDetId
Definition: HcalDetId.h:12
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
SimAnalyzerMinbias::myInfo::theMB1
double theMB1
Definition: SimAnalyzerMinbias.cc:60
SimAnalyzerMinbias::mom1_MB
float mom1_MB
Definition: SimAnalyzerMinbias.cc:58
edm::EventSetup
Definition: EventSetup.h:58
HcalSubdetector.h
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
HcalRespCorrs.h
SimAnalyzerMinbias::myInfo
Definition: SimAnalyzerMinbias.cc:59
SimAnalyzerMinbias::mydet
int mydet
Definition: SimAnalyzerMinbias.cc:57
SimAnalyzerMinbias::myInfo::myInfo
myInfo()
Definition: SimAnalyzerMinbias.cc:61
SimAnalyzerMinbias::mom3_MB
float mom3_MB
Definition: SimAnalyzerMinbias.cc:58
SimAnalyzerMinbias::ieta
int ieta
Definition: SimAnalyzerMinbias.cc:57
alignCSCRings.r
r
Definition: alignCSCRings.py:93
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
SimAnalyzerMinbias::myInfo::theMB2
double theMB2
Definition: SimAnalyzerMinbias.cc:60
SimAnalyzerMinbias::iphi
int iphi
Definition: SimAnalyzerMinbias.cc:57
DetId.h
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
SimAnalyzerMinbias::mysubd
int mysubd
Definition: SimAnalyzerMinbias.cc:57
SimAnalyzerMinbias::myTree_
TTree * myTree_
Definition: SimAnalyzerMinbias.cc:54
edm::PCaloHitContainer
std::vector< PCaloHit > PCaloHitContainer
Definition: PCaloHitContainer.h:8
EventSetup.h
SimAnalyzerMinbias::beginRun
void beginRun(const edm::Run &r, const edm::EventSetup &iSetup) override
Definition: SimAnalyzerMinbias.cc:47
PCaloHitContainer.h
SimAnalyzerMinbias::cells
int cells
Definition: SimAnalyzerMinbias.cc:57
HcalDCCHeader.h
SimAnalyzerMinbias::fs_
edm::Service< TFileService > fs_
Definition: SimAnalyzerMinbias.cc:48
ParameterSet.h
HepMCProduct.h
SimAnalyzerMinbias::endRun
void endRun(const edm::Run &r, const edm::EventSetup &iSetup) override
Definition: SimAnalyzerMinbias.cc:48
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
SimAnalyzerMinbias::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SimAnalyzerMinbias.cc:81
edm::InputTag
Definition: InputTag.h:15
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
SimAnalyzerMinbias::depth
int depth
Definition: SimAnalyzerMinbias.cc:57