CMS 3D CMS Logo

HGCalValidator.cc
Go to the documentation of this file.
2 
5 
6 using namespace std;
7 using namespace edm;
8 
10  label(pset.getParameter< std::vector<edm::InputTag> >("label")),
11  SaveGeneralInfo_(pset.getUntrackedParameter<bool>("SaveGeneralInfo")),
12  doCaloParticlePlots_(pset.getUntrackedParameter<bool>("doCaloParticlePlots")),
13  dolayerclustersPlots_(pset.getUntrackedParameter<bool>("dolayerclustersPlots")),
14  cummatbudinxo_(pset.getParameter<edm::FileInPath>("cummatbudinxo"))
15 {
16 
17  //In this way we can easily generalize to associations between other objects also.
18  const edm::InputTag& label_cp_effic_tag = pset.getParameter< edm::InputTag >("label_cp_effic");
19  const edm::InputTag& label_cp_fake_tag = pset.getParameter< edm::InputTag >("label_cp_fake");
20 
21  label_cp_effic = consumes<std::vector<CaloParticle> >(label_cp_effic_tag);
22  label_cp_fake = consumes<std::vector<CaloParticle> >(label_cp_fake_tag);
23 
24  simVertices_ = consumes<std::vector<SimVertex>>(pset.getParameter<edm::InputTag>("simVertices"));
25 
26  recHitsEE_ = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit", "HGCEERecHits"));
27  recHitsFH_ = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
28  recHitsBH_ = consumes<HGCRecHitCollection>(edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
29 
30  density_ = consumes<Density>(edm::InputTag("hgcalLayerClusters"));
31 
32  for (auto& itag : label) {
33  labelToken.push_back(consumes<reco::CaloClusterCollection>(itag));
34  }
35 
36  cpSelector = CaloParticleSelector(pset.getParameter<double>("ptMinCP"),
37  pset.getParameter<double>("ptMaxCP"),
38  pset.getParameter<double>("minRapidityCP"),
39  pset.getParameter<double>("maxRapidityCP"),
40  pset.getParameter<int>("minHitCP"),
41  pset.getParameter<double>("tipCP"),
42  pset.getParameter<double>("lipCP"),
43  pset.getParameter<bool>("signalOnlyCP"),
44  pset.getParameter<bool>("intimeOnlyCP"),
45  pset.getParameter<bool>("chargedOnlyCP"),
46  pset.getParameter<bool>("stableOnlyCP"),
47  pset.getParameter<std::vector<int> >("pdgIdCP"));
48 
49  tools_.reset(new hgcal::RecHitTools());
50 
51  particles_to_monitor_ = pset.getParameter<std::vector<int> >("pdgIdCP");
52  totallayers_to_monitor_ = pset.getParameter<int>("totallayers_to_monitor");
53  thicknesses_to_monitor_ = pset.getParameter<std::vector<int> >("thicknesses_to_monitor");
54 
55  //For the material budget file here
56  std::ifstream fmb(cummatbudinxo_.fullPath().c_str());
57  double thelay = 0.; double mbg = 0.;
58  for (unsigned ilayer = 1; ilayer <= totallayers_to_monitor_; ++ilayer) {
59  fmb >> thelay >> mbg;
60  cummatbudg.insert( std::pair<double, double>( thelay , mbg ) );
61  }
62 
63  fmb.close();
64 
65 
66 
67  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
68  histoProducerAlgo_ = std::make_unique<HGVHistoProducerAlgo>(psetForHistoProducerAlgo);
69 
70  dirName_ = pset.getParameter<std::string>("dirName");
71 
72 }
73 
74 
76 
77 
79 
80  if (SaveGeneralInfo_){
81  ibook.cd();
82  ibook.setCurrentFolder(dirName_ + "GeneralInfo");
83  histoProducerAlgo_->bookInfo(ibook, histograms.histoProducerAlgo);
84  }
85 
87  ibook.cd();
88 
89  for (auto const particle : particles_to_monitor_) {
90  ibook.setCurrentFolder(dirName_ + "SelectedCaloParticles/" + std::to_string(particle));
91  histoProducerAlgo_->bookCaloParticleHistos(ibook, histograms.histoProducerAlgo, particle);
92  }
93  ibook.cd();
95  }
96 
97  for (unsigned int www=0;www<label.size();www++){
98  ibook.cd();
99  InputTag algo = label[www];
100  string dirName=dirName_;
101  if (!algo.process().empty())
102  dirName+=algo.process()+"_";
103  LogDebug("HGCalValidator") << dirName << "\n";
104  if(!algo.label().empty())
105  dirName+=algo.label()+"_";
106  LogDebug("HGCalValidator") << dirName << "\n";
107  if(!algo.instance().empty())
108  dirName+=algo.instance()+"_";
109  LogDebug("HGCalValidator") << dirName << "\n";
110 
111  if (!dirName.empty()){dirName.resize(dirName.size() - 1);}
112 
113  LogDebug("HGCalValidator") << dirName << "\n";
114 
115  ibook.setCurrentFolder(dirName);
116 
117  //Booking histograms concerning with hgcal layer clusters
120  }
121 
122  }//end loop www
123 }
124 
126  std::vector<CaloParticle> const & cPeff,
127  std::vector<SimVertex> const & simVertices,
128  std::vector<size_t>& selected_cPeff) const {
129  selected_cPeff.reserve(cPeff.size());
130 
131  size_t j=0;
132  for (auto const caloParticle : cPeff) {
133  int id = caloParticle.pdgId();
134 
135  if(cpSelector(caloParticle,simVertices)) {
136  selected_cPeff.push_back(j);
138  histoProducerAlgo_->fill_caloparticle_histos(histograms.histoProducerAlgo,id,caloParticle,simVertices);
139  }
140  }
141  ++j;
142  }//end of loop over caloparticles
143 
144 }
145 
147  using namespace reco;
148 
149  LogDebug("HGCalValidator") << "\n====================================================" << "\n"
150  << "Analyzing new event" << "\n"
151  << "====================================================\n" << "\n";
152 
153  edm::Handle<std::vector<SimVertex>> simVerticesHandle;
154  event.getByToken(simVertices_, simVerticesHandle);
155  std::vector<SimVertex> const & simVertices = *simVerticesHandle;
156 
157  edm::Handle<std::vector<CaloParticle> > caloParticleHandle;
158  event.getByToken(label_cp_effic, caloParticleHandle);
159  std::vector<CaloParticle> const & caloParticles = *caloParticleHandle;
160 
161  tools_->getEventSetup(setup);
162  histoProducerAlgo_->setRecHitTools(tools_);
163 
164  edm::Handle<HGCRecHitCollection> recHitHandleEE;
165  event.getByToken(recHitsEE_, recHitHandleEE);
166  edm::Handle<HGCRecHitCollection> recHitHandleFH;
167  event.getByToken(recHitsFH_, recHitHandleFH);
168  edm::Handle<HGCRecHitCollection> recHitHandleBH;
169  event.getByToken(recHitsBH_, recHitHandleBH);
170 
171  std::map<DetId, const HGCRecHit* > hitMap;
172  fillHitMap(hitMap, *recHitHandleEE,*recHitHandleFH,*recHitHandleBH);
173 
174  //Some general info on layers etc.
175  if (SaveGeneralInfo_){
176  histoProducerAlgo_->fill_info_histos(histograms.histoProducerAlgo,totallayers_to_monitor_);
177  }
178 
179  // ##############################################
180  // fill caloparticles histograms
181  // ##############################################
182  LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n";
183  std::vector<size_t> selected_cPeff;
184  cpParametersAndSelection(histograms, caloParticles, simVertices, selected_cPeff);
185 
186  int w=0; //counter counting the number of sets of histograms
187  for (unsigned int www=0;www<label.size();www++, w++){ // need to increment w here, since there will be many continues in the loop body
188 
189  //get collections from the event
191  event.getByToken(labelToken[www],clusterHandle);
192  const reco::CaloClusterCollection &clusters = *clusterHandle;
193 
194  //Density
195  edm::Handle<Density> densityHandle;
196  event.getByToken( density_, densityHandle);
197  const Density &densities = *densityHandle;
198 
199  // ##############################################
200  // fill cluster histograms (LOOP OVER CLUSTERS)
201  // ##############################################
202  if(!dolayerclustersPlots_){continue;}
203 
204  histoProducerAlgo_->fill_generic_cluster_histos(histograms.histoProducerAlgo,
205  w,clusters,densities,caloParticles,
206  hitMap,
209 
210  for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) {
211  histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo,w,clusters[layerclusterIndex]);
212  }
213 
214  LogTrace("HGCalValidator") << "\n# of layer clusters with "
215  << label[www].process()<<":"
216  << label[www].label()<<":"
217  << label[www].instance()
218  << ": " << clusters.size() << "\n";
219 
220  } // End of for (unsigned int www=0;www<label.size();www++){
221 }
222 
223 void HGCalValidator::fillHitMap(std::map<DetId, const HGCRecHit *> & hitMap,
224  const HGCRecHitCollection & rechitsEE,
225  const HGCRecHitCollection & rechitsFH,
226  const HGCRecHitCollection & rechitsBH) const {
227  hitMap.clear();
228  for (const auto& hit : rechitsEE) {
229  hitMap.emplace(hit.detid(), &hit);
230  }
231 
232  for (const auto& hit : rechitsFH) {
233  hitMap.emplace(hit.detid(), &hit);
234  }
235 
236  for (const auto& hit : rechitsBH) {
237  hitMap.emplace(hit.detid(), &hit);
238  }
239 }
240 
#define LogDebug(id)
T getParameter(std::string const &) const
std::map< double, double > cummatbudg
const double w
Definition: UKUtility.cc:23
edm::EDGetTokenT< HGCRecHitCollection > recHitsBH_
std::unique_ptr< HGVHistoProducerAlgo > histoProducerAlgo_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
~HGCalValidator() override
Destructor.
CaloParticleSelector cpSelector
const bool doCaloParticlePlots_
unsigned totallayers_to_monitor_
std::vector< int > thicknesses_to_monitor_
std::vector< edm::InputTag > label
const bool SaveGeneralInfo_
edm::EDGetTokenT< Density > density_
char const * label
cc *****************************************************cc the common blocks pinput and cwdidth are for input parameters cc these parameters needed to be interfaced to other program common pinput fmb
Definition: inclcon.h:4
hgcal_clustering::Density Density
Definition: HGCalCLUEAlgo.h:29
std::string dirName_
void bookHistograms(DQMStore::ConcurrentBooker &, edm::Run const &, edm::EventSetup const &, Histograms &) const override
Method called to book the DQM histograms.
HGVHistoProducerAlgoHistograms histoProducerAlgo
edm::EDGetTokenT< std::vector< SimVertex > > simVertices_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_fake
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_effic
std::shared_ptr< hgcal::RecHitTools > tools_
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
void cpParametersAndSelection(const Histograms &histograms, std::vector< CaloParticle > const &cPeff, std::vector< SimVertex > const &simVertices, std::vector< size_t > &selected_cPeff) const
#define LogTrace(id)
HGCalValidator(const edm::ParameterSet &pset)
Constructor.
const edm::FileInPath cummatbudinxo_
const bool dolayerclustersPlots_
std::vector< edm::EDGetTokenT< reco::CaloClusterCollection > > labelToken
std::string const & label() const
Definition: InputTag.h:36
std::string const & process() const
Definition: InputTag.h:40
std::vector< int > particles_to_monitor_
fixed size matrix
HLT enums.
void dqmAnalyze(const edm::Event &, const edm::EventSetup &, const Histograms &) const override
Method called once per event.
edm::EDGetTokenT< HGCRecHitCollection > recHitsEE_
edm::EDGetTokenT< HGCRecHitCollection > recHitsFH_
std::string fullPath() const
Definition: FileInPath.cc:163
void fillHitMap(std::map< DetId, const HGCRecHit * > &, const HGCRecHitCollection &, const HGCRecHitCollection &, const HGCRecHitCollection &) const
std::string const & instance() const
Definition: InputTag.h:37
Definition: event.py:1
Definition: Run.h:45