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_lcl(pset.getParameter<edm::InputTag>("label_lcl")),
11  label_mcl(pset.getParameter<std::vector<edm::InputTag>>("label_mcl")),
12  SaveGeneralInfo_(pset.getUntrackedParameter<bool>("SaveGeneralInfo")),
13  doCaloParticlePlots_(pset.getUntrackedParameter<bool>("doCaloParticlePlots")),
14  doCaloParticleSelection_(pset.getUntrackedParameter<bool>("doCaloParticleSelection")),
15  dolayerclustersPlots_(pset.getUntrackedParameter<bool>("dolayerclustersPlots")),
16  domulticlustersPlots_(pset.getUntrackedParameter<bool>("domulticlustersPlots")),
17  cummatbudinxo_(pset.getParameter<edm::FileInPath>("cummatbudinxo")) {
18  //In this way we can easily generalize to associations between other objects also.
19  const edm::InputTag& label_cp_effic_tag = pset.getParameter<edm::InputTag>("label_cp_effic");
20  const edm::InputTag& label_cp_fake_tag = pset.getParameter<edm::InputTag>("label_cp_fake");
21 
22  label_cp_effic = consumes<std::vector<CaloParticle>>(label_cp_effic_tag);
23  label_cp_fake = consumes<std::vector<CaloParticle>>(label_cp_fake_tag);
24 
25  simVertices_ = consumes<std::vector<SimVertex>>(pset.getParameter<edm::InputTag>("simVertices"));
26 
27  hitMap_ = consumes<std::unordered_map<DetId, const HGCRecHit*>>(edm::InputTag("hgcalRecHitMapProducer"));
28 
29  density_ = consumes<Density>(edm::InputTag("hgcalLayerClusters"));
30 
31  layerclusters_ = consumes<reco::CaloClusterCollection>(label_lcl);
32 
33  for (auto& itag : label_mcl) {
34  label_mclTokens.push_back(consumes<std::vector<reco::HGCalMultiCluster>>(itag));
35  }
36 
38  consumes<hgcal::LayerClusterToCaloParticleAssociator>(edm::InputTag("lcAssocByEnergyScoreProducer"));
39 
40  cpSelector = CaloParticleSelector(pset.getParameter<double>("ptMinCP"),
41  pset.getParameter<double>("ptMaxCP"),
42  pset.getParameter<double>("minRapidityCP"),
43  pset.getParameter<double>("maxRapidityCP"),
44  pset.getParameter<int>("minHitCP"),
45  pset.getParameter<int>("maxSimClustersCP"),
46  pset.getParameter<double>("tipCP"),
47  pset.getParameter<double>("lipCP"),
48  pset.getParameter<bool>("signalOnlyCP"),
49  pset.getParameter<bool>("intimeOnlyCP"),
50  pset.getParameter<bool>("chargedOnlyCP"),
51  pset.getParameter<bool>("stableOnlyCP"),
52  pset.getParameter<std::vector<int>>("pdgIdCP"));
53 
54  tools_.reset(new hgcal::RecHitTools());
55 
56  particles_to_monitor_ = pset.getParameter<std::vector<int>>("pdgIdCP");
57  totallayers_to_monitor_ = pset.getParameter<int>("totallayers_to_monitor");
58  thicknesses_to_monitor_ = pset.getParameter<std::vector<int>>("thicknesses_to_monitor");
59 
60  //For the material budget file here
61  std::ifstream fmb(cummatbudinxo_.fullPath().c_str());
62  double thelay = 0.;
63  double mbg = 0.;
64  for (unsigned ilayer = 1; ilayer <= totallayers_to_monitor_; ++ilayer) {
65  fmb >> thelay >> mbg;
66  cummatbudg.insert(std::pair<double, double>(thelay, mbg));
67  }
68 
69  fmb.close();
70 
71  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
72  histoProducerAlgo_ = std::make_unique<HGVHistoProducerAlgo>(psetForHistoProducerAlgo);
73 
74  dirName_ = pset.getParameter<std::string>("dirName");
75 }
76 
78 
80  edm::Run const&,
81  edm::EventSetup const& setup,
82  Histograms& histograms) const {
83  if (SaveGeneralInfo_) {
84  ibook.cd();
85  ibook.setCurrentFolder(dirName_ + "GeneralInfo");
86  histoProducerAlgo_->bookInfo(ibook, histograms.histoProducerAlgo);
87  }
88 
90  ibook.cd();
91 
92  for (auto const particle : particles_to_monitor_) {
93  ibook.setCurrentFolder(dirName_ + "SelectedCaloParticles/" + std::to_string(particle));
94  histoProducerAlgo_->bookCaloParticleHistos(ibook, histograms.histoProducerAlgo, particle);
95  }
96  ibook.cd();
98  }
99 
100  //Booking histograms concerning with hgcal layer clusters
101  if (dolayerclustersPlots_) {
102  ibook.cd();
103  ibook.setCurrentFolder(dirName_ + "hgcalLayerClusters");
104  histoProducerAlgo_->bookClusterHistos(ibook,
105  histograms.histoProducerAlgo,
109  }
110 
111  //Booking histograms for multiclusters
112  for (unsigned int www = 0; www < label_mcl.size(); www++) {
113  ibook.cd();
114  InputTag algo = label_mcl[www];
115  string dirName = dirName_;
116  if (!algo.process().empty())
117  dirName += algo.process() + "_";
118  LogDebug("HGCalValidator") << dirName << "\n";
119  if (!algo.label().empty())
120  dirName += algo.label() + "_";
121  LogDebug("HGCalValidator") << dirName << "\n";
122  if (!algo.instance().empty())
123  dirName += algo.instance() + "_";
124  LogDebug("HGCalValidator") << dirName << "\n";
125 
126  if (!dirName.empty()) {
127  dirName.resize(dirName.size() - 1);
128  }
129 
130  LogDebug("HGCalValidator") << dirName << "\n";
131 
132  ibook.setCurrentFolder(dirName);
133 
134  //Booking histograms concerning for hgcal multi clusters
135  if (domulticlustersPlots_) {
136  histoProducerAlgo_->bookMultiClusterHistos(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_);
137  }
138  } //end of booking multiclusters loop
139 }
140 
142  std::vector<CaloParticle> const& cPeff,
143  std::vector<SimVertex> const& simVertices,
144  std::vector<size_t>& selected_cPeff) const {
145  selected_cPeff.reserve(cPeff.size());
146 
147  size_t j = 0;
148  for (auto const& caloParticle : cPeff) {
149  int id = caloParticle.pdgId();
150 
152  selected_cPeff.push_back(j);
153  if (doCaloParticlePlots_) {
154  histoProducerAlgo_->fill_caloparticle_histos(histograms.histoProducerAlgo, id, caloParticle, simVertices);
155  }
156  }
157  ++j;
158  } //end of loop over caloparticles
159 }
160 
162  const edm::EventSetup& setup,
163  const Histograms& histograms) const {
164  using namespace reco;
165 
166  LogDebug("HGCalValidator") << "\n===================================================="
167  << "\n"
168  << "Analyzing new event"
169  << "\n"
170  << "====================================================\n"
171  << "\n";
172 
173  edm::Handle<std::vector<SimVertex>> simVerticesHandle;
174  event.getByToken(simVertices_, simVerticesHandle);
175  std::vector<SimVertex> const& simVertices = *simVerticesHandle;
176 
177  edm::Handle<std::vector<CaloParticle>> caloParticleHandle;
178  event.getByToken(label_cp_effic, caloParticleHandle);
179  std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;
180 
183  tools_->setGeometry(*geom);
184  histoProducerAlgo_->setRecHitTools(tools_);
185 
187  event.getByToken(LCAssocByEnergyScoreProducer_, LCAssocByEnergyScoreHandle);
188 
190  event.getByToken(hitMap_, hitMapHandle);
191  const std::unordered_map<DetId, const HGCRecHit*>* hitMap = &*hitMapHandle;
192 
193  //Some general info on layers etc.
194  if (SaveGeneralInfo_) {
195  histoProducerAlgo_->fill_info_histos(histograms.histoProducerAlgo, totallayers_to_monitor_);
196  }
197 
198  auto nCaloParticles = caloParticles.size();
199  std::vector<size_t> cPIndices;
200  //Consider CaloParticles coming from the hard scatterer
201  //excluding the PU contribution and save the indices.
202  for (unsigned int cpId = 0; cpId < nCaloParticles; ++cpId) {
203  if (caloParticles[cpId].g4Tracks()[0].eventId().event() != 0 or
204  caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing() != 0) {
205  LogDebug("HGCalValidator") << "Excluding CaloParticles from event: "
206  << caloParticles[cpId].g4Tracks()[0].eventId().event()
207  << " with BX: " << caloParticles[cpId].g4Tracks()[0].eventId().bunchCrossing()
208  << std::endl;
209  continue;
210  }
211  cPIndices.emplace_back(cpId);
212  }
213 
214  // ##############################################
215  // fill caloparticles histograms
216  // ##############################################
217  LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n";
218  std::vector<size_t> selected_cPeff;
220 
221  //get collections from the event
222  //Layer clusters
224  event.getByToken(layerclusters_, clusterHandle);
225  const reco::CaloClusterCollection& clusters = *clusterHandle;
226 
227  //Density
228  edm::Handle<Density> densityHandle;
229  event.getByToken(density_, densityHandle);
230  const Density& densities = *densityHandle;
231 
232  // ##############################################
233  // fill layercluster histograms
234  // ##############################################
235  int w = 0; //counter counting the number of sets of histograms
236  if (dolayerclustersPlots_) {
237  histoProducerAlgo_->fill_generic_cluster_histos(histograms.histoProducerAlgo,
238  w,
239  clusterHandle,
240  clusters,
241  densities,
242  caloParticleHandle,
244  cPIndices,
245  selected_cPeff,
246  *hitMap,
247  cummatbudg,
250  LCAssocByEnergyScoreHandle);
251 
252  for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) {
253  histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]);
254  }
255 
256  //General Info on hgcalLayerClusters
257  LogTrace("HGCalValidator") << "\n# of layer clusters with " << label_lcl.process() << ":" << label_lcl.label()
258  << ":" << label_lcl.instance() << ": " << clusters.size() << "\n";
259  }
260 
261  // ##############################################
262  // fill multicluster histograms
263  // ##############################################
264  for (unsigned int wml = 0; wml < label_mclTokens.size(); wml++) {
265  if (domulticlustersPlots_) {
267  event.getByToken(label_mclTokens[wml], multiClusterHandle);
268  const std::vector<reco::HGCalMultiCluster>& multiClusters = *multiClusterHandle;
269 
270  histoProducerAlgo_->fill_multi_cluster_histos(histograms.histoProducerAlgo,
271  wml,
272  multiClusters,
274  cPIndices,
275  selected_cPeff,
276  *hitMap,
278 
279  //General Info on multiclusters
280  LogTrace("HGCalValidator") << "\n# of multi clusters with " << label_mcl[wml].process() << ":"
281  << label_mcl[wml].label() << ":" << label_mcl[wml].instance() << ": "
282  << multiClusters.size() << "\n";
283  }
284  } //end of loop over multicluster input labels
285 }
HGCalValidator::dqmAnalyze
void dqmAnalyze(const edm::Event &, const edm::EventSetup &, const Histograms &) const override
Method called once per event.
Definition: HGCalValidator.cc:161
HGCalValidator::label_cp_effic
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_effic
Definition: HGCalValidator.h:72
HGCalValidator::cummatbudinxo_
const edm::FileInPath cummatbudinxo_
Definition: HGCalValidator.h:67
hgcal::RecHitTools
Definition: RecHitTools.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:393
MessageLogger.h
HGCalValidator::~HGCalValidator
~HGCalValidator() override
Destructor.
Definition: HGCalValidator.cc:77
HGCalValidator::cpParametersAndSelection
void cpParametersAndSelection(const Histograms &histograms, std::vector< CaloParticle > const &cPeff, std::vector< SimVertex > const &simVertices, std::vector< size_t > &selected_cPeff) const
Definition: HGCalValidator.cc:141
edm::InputTag::instance
std::string const & instance() const
Definition: InputTag.h:37
HGCalValidator::HGCalValidator
HGCalValidator(const edm::ParameterSet &pset)
Constructor.
Definition: HGCalValidator.cc:9
edm::Run
Definition: Run.h:45
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
edm::InputTag::process
std::string const & process() const
Definition: InputTag.h:40
HGCalValidator::dolayerclustersPlots_
const bool dolayerclustersPlots_
Definition: HGCalValidator.h:65
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
cmsdt::algo
algo
Definition: constants.h:164
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
HGCalValidator::cpSelector
CaloParticleSelector cpSelector
Definition: HGCalValidator.h:81
CaloParticleSelector
Definition: CaloParticleSelector.h:10
HGCalValidator::tools_
std::shared_ptr< hgcal::RecHitTools > tools_
Definition: HGCalValidator.h:82
w
const double w
Definition: UKUtility.cc:23
caloTruthCellsProducer_cfi.caloParticles
caloParticles
Definition: caloTruthCellsProducer_cfi.py:6
reco::CaloClusterCollection
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
Definition: CaloClusterFwd.h:19
HGCalValidator::label_cp_fake
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_fake
Definition: HGCalValidator.h:73
edm::ESHandle< CaloGeometry >
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HGCalValidator::label_mclTokens
std::vector< edm::EDGetTokenT< std::vector< reco::HGCalMultiCluster > > > label_mclTokens
Definition: HGCalValidator.h:71
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
HGCalValidator::totallayers_to_monitor_
unsigned totallayers_to_monitor_
Definition: HGCalValidator.h:85
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
HGCalValidator::simVertices_
edm::EDGetTokenT< std::vector< SimVertex > > simVertices_
Definition: HGCalValidator.h:74
HGCalValidator::thicknesses_to_monitor_
std::vector< int > thicknesses_to_monitor_
Definition: HGCalValidator.h:86
HGCalValidator::histoProducerAlgo_
std::unique_ptr< HGVHistoProducerAlgo > histoProducerAlgo_
Definition: HGCalValidator.h:78
HGCalValidator::doCaloParticleSelection_
const bool doCaloParticleSelection_
Definition: HGCalValidator.h:64
edmPickEvents.event
event
Definition: edmPickEvents.py:273
HGCalValidator::label_lcl
edm::InputTag label_lcl
Definition: HGCalValidator.h:60
HGCalValidator::LCAssocByEnergyScoreProducer_
edm::EDGetTokenT< hgcal::LayerClusterToCaloParticleAssociator > LCAssocByEnergyScoreProducer_
Definition: HGCalValidator.h:77
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
histograms
Definition: histograms.py:1
HGCalValidator::particles_to_monitor_
std::vector< int > particles_to_monitor_
Definition: HGCalValidator.h:84
get
#define get
HGCalValidator.h
HGCalValidator::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, Histograms &) const override
Method called to book the DQM histograms.
Definition: HGCalValidator.cc:79
HGCalValidator::label_mcl
std::vector< edm::InputTag > label_mcl
Definition: HGCalValidator.h:61
std
Definition: JetResolutionObject.h:76
HGCalValidator::domulticlustersPlots_
const bool domulticlustersPlots_
Definition: HGCalValidator.h:66
HGCalValidator::cummatbudg
std::map< double, double > cummatbudg
Definition: HGCalValidator.h:83
HGCalValidatorHistograms
Definition: HGCalValidator.h:34
HGCalValidator::SaveGeneralInfo_
const bool SaveGeneralInfo_
Definition: HGCalValidator.h:62
fmb
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
HGCalValidator::density_
edm::EDGetTokenT< Density > density_
Definition: HGCalValidator.h:76
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
HGCalValidator::dirName_
std::string dirName_
Definition: HGCalValidator.h:87
HGCalValidator_cfi.label_lcl
label_lcl
general settings ### selection of CP for evaluation of efficiency #
Definition: HGCalValidator_cfi.py:16
dqm::implementation::IBooker
Definition: DQMStore.h:43
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
HGCalValidator_cfi.simVertices
simVertices
Definition: HGCalValidator_cfi.py:43
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:153
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
HGCalValidator::layerclusters_
edm::EDGetTokenT< reco::CaloClusterCollection > layerclusters_
Definition: HGCalValidator.h:70
HGCalValidator::hitMap_
edm::EDGetTokenT< std::unordered_map< DetId, const HGCRecHit * > > hitMap_
Definition: HGCalValidator.h:75
edm::InputTag
Definition: InputTag.h:15
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
Density
hgcal_clustering::Density Density
Definition: HGCalImagingAlgo.h:29
HGCalValidator_cfi.label_mcl
label_mcl
Definition: HGCalValidator_cfi.py:17
HGCalValidator::doCaloParticlePlots_
const bool doCaloParticlePlots_
Definition: HGCalValidator.h:63