CMS 3D CMS Logo

XtalDedxAnalysis.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 #include <vector>
5 
6 // user include files
9 
13 
18 
20 
23 
30 
31 #include <TH1F.h>
32 #include <TH1I.h>
33 
34 //#define EDM_ML_DEBUG
35 
36 class XtalDedxAnalysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
37 public:
38  explicit XtalDedxAnalysis(const edm::ParameterSet &);
39  ~XtalDedxAnalysis() override {}
40 
41  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
42 
43 protected:
44  void beginJob() override {}
45  void analyze(const edm::Event &, const edm::EventSetup &) override;
46  void endJob() override {}
47 
48  void analyzeHits(std::vector<PCaloHit> &,
51 
52 private:
55 
59 
60  TH1F *meNHit_[4], *meE1T0_[4], *meE9T0_[4], *meE1T1_[4], *meE9T1_[4];
61  TH1I *mType_;
62 };
63 
65  usesResource(TFileService::kSharedResource);
66  caloHitSource_ = ps.getParameter<edm::InputTag>("caloHitSource");
67  simTkLabel_ = ps.getParameter<std::string>("moduleLabelTk");
68  double energyMax = ps.getParameter<double>("energyMax");
69  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Source " << caloHitSource_ << " Track Label "
70  << simTkLabel_ << " Energy Max " << energyMax;
71  // register for data access
72  tok_calo_ = consumes<edm::PCaloHitContainer>(caloHitSource_);
73  tok_tk_ = consumes<edm::SimTrackContainer>(edm::InputTag(simTkLabel_));
74  tok_vtx_ = consumes<edm::SimVertexContainer>(edm::InputTag(simTkLabel_));
75 
76  // Book histograms
78 
79  if (!tfile.isAvailable())
80  throw cms::Exception("BadConfig") << "TFileService unavailable: "
81  << "please add it to config file";
82  // Histograms for Hits
83  std::string types[4] = {"total", "by dE/dx", "by delta-ray", "by bremms"};
84  char name[20], title[80];
85  for (int i = 0; i < 4; i++) {
86  sprintf(name, "Hits%d", i);
87  sprintf(title, "Number of hits (%s)", types[i].c_str());
88  meNHit_[i] = tfile->make<TH1F>(name, title, 5000, 0., 5000.);
89  meNHit_[i]->GetXaxis()->SetTitle(title);
90  meNHit_[i]->GetYaxis()->SetTitle("Events");
91  sprintf(name, "E1T0%d", i);
92  sprintf(title, "E1 (Loss %s) in GeV", types[i].c_str());
93  meE1T0_[i] = tfile->make<TH1F>(name, title, 5000, 0, energyMax);
94  meE1T0_[i]->GetXaxis()->SetTitle(title);
95  meE1T0_[i]->GetYaxis()->SetTitle("Events");
96  sprintf(name, "E9T0%d", i);
97  sprintf(title, "E9 (Loss %s) in GeV", types[i].c_str());
98  meE9T0_[i] = tfile->make<TH1F>(name, title, 5000, 0, energyMax);
99  meE9T0_[i]->GetXaxis()->SetTitle(title);
100  meE9T0_[i]->GetYaxis()->SetTitle("Events");
101  sprintf(name, "E1T1%d", i);
102  sprintf(title, "E1 (Loss %s with t < 400 ns) in GeV", types[i].c_str());
103  meE1T1_[i] = tfile->make<TH1F>(name, title, 5000, 0, energyMax);
104  meE1T1_[i]->GetXaxis()->SetTitle(title);
105  meE1T1_[i]->GetYaxis()->SetTitle("Events");
106  sprintf(name, "E9T1%d", i);
107  sprintf(title, "E9 (Loss %s with t < 400 ns) in GeV", types[i].c_str());
108  meE9T1_[i] = tfile->make<TH1F>(name, title, 5000, 0, energyMax);
109  meE9T1_[i]->GetXaxis()->SetTitle(title);
110  meE9T1_[i]->GetYaxis()->SetTitle("Events");
111  }
112  sprintf(name, "PDGType");
113  sprintf(title, "PDG ID of first level secondary");
114  mType_ = tfile->make<TH1I>(name, title, 5000, -2500, 2500);
115  mType_->GetXaxis()->SetTitle(title);
116  mType_->GetYaxis()->SetTitle("Tracks");
117 }
118 
121  desc.add<edm::InputTag>("caloHitSource", edm::InputTag("g4SimHits", "EcalHitsEB"));
122  desc.add<std::string>("moduleLabelTk", "g4SimHits");
123  desc.add<double>("energyMax", 2.0);
124  descriptions.add("xtalDedxAnalysis", desc);
125 }
126 
128 #ifdef EDM_ML_DEBUG
129  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Run = " << e.id().run() << " Event = " << e.id().event();
130 #endif
131  std::vector<PCaloHit> caloHits;
133  e.getByToken(tok_calo_, pCaloHits);
134 
135  std::vector<SimTrack> theSimTracks;
137  e.getByToken(tok_tk_, simTk);
138 
139  std::vector<SimVertex> theSimVertex;
141  e.getByToken(tok_vtx_, simVtx);
142 
143  if (pCaloHits.isValid()) {
144  caloHits.insert(caloHits.end(), pCaloHits->begin(), pCaloHits->end());
145 #ifdef EDM_ML_DEBUG
146  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis: Hit buffer " << caloHits.size();
147 #endif
148  analyzeHits(caloHits, simTk, simVtx);
149  }
150 }
151 
152 void XtalDedxAnalysis::analyzeHits(std::vector<PCaloHit> &hits,
155  edm::SimTrackContainer::const_iterator simTrkItr;
156  int nHit = hits.size();
157  double e10[4], e90[4], e11[4], e91[4], hit[4];
158  for (int i = 0; i < 4; i++)
159  e10[i] = e90[i] = e11[i] = e91[i] = hit[i] = 0;
160  for (int i = 0; i < nHit; i++) {
161  double energy = hits[i].energy();
162  double time = hits[i].time();
163  unsigned int id_ = hits[i].id();
164  int trackID = hits[i].geantTrackId();
165  int type = 1;
166  for (simTrkItr = SimTk->begin(); simTrkItr != SimTk->end(); simTrkItr++) {
167  if (trackID == (int)(simTrkItr->trackId())) {
168  int thePID = simTrkItr->type();
169  if (thePID == 11)
170  type = 2;
171  else if (thePID != -13 && thePID != 13)
172  type = 3;
173  break;
174  }
175  }
176  hit[0]++;
177  hit[type]++;
178  e90[0] += energy;
179  e90[type] += energy;
180  if (time < 400) {
181  e91[0] += energy;
182  e91[type] += energy;
183  }
184  if (id_ == 22) {
185  e10[0] += energy;
186  e10[type] += energy;
187  if (time < 400) {
188  e11[0] += energy;
189  e11[type] += energy;
190  }
191  }
192 #ifdef EDM_ML_DEBUG
193  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis:Hit[" << i << "] ID " << id_ << " E " << energy
194  << " time " << time << " track " << trackID << " type " << type;
195 #endif
196  }
197  for (int i = 0; i < 4; i++) {
198 #ifdef EDM_ML_DEBUG
199  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis:Type(" << i << ") Hit " << hit[i] << " E10 " << e10[i]
200  << " E11 " << e11[i] << " E90 " << e90[i] << " E91 " << e91[i];
201 #endif
202  meNHit_[i]->Fill(hit[i]);
203  meE1T0_[i]->Fill(e10[i]);
204  meE9T0_[i]->Fill(e90[i]);
205  meE1T1_[i]->Fill(e11[i]);
206  meE9T1_[i]->Fill(e91[i]);
207  }
208 
209  // Type of the secondary (coming directly from a generator level track)
210  int nvtx = 0, ntrk = 0, k1 = 0;
211  edm::SimVertexContainer::const_iterator simVtxItr;
212  for (simTrkItr = SimTk->begin(); simTrkItr != SimTk->end(); simTrkItr++)
213  ntrk++;
214  for (simVtxItr = SimVtx->begin(); simVtxItr != SimVtx->end(); simVtxItr++)
215  nvtx++;
216 #ifdef EDM_ML_DEBUG
217  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis: " << ntrk << " tracks and " << nvtx << " vertices";
218 #endif
219  for (simTrkItr = SimTk->begin(); simTrkItr != SimTk->end(); simTrkItr++, ++k1) {
220 #ifdef EDM_ML_DEBUG
221  edm::LogVerbatim("CherenkovAnalysis") << "Track " << k1 << " PDGId " << simTrkItr->type() << " Vertex ID "
222  << simTrkItr->vertIndex() << " Generator " << simTrkItr->noGenpart();
223 #endif
224  if (simTrkItr->noGenpart()) { // This is a secondary
225  int vertIndex = simTrkItr->vertIndex(); // Vertex index of origin
226  if (vertIndex >= 0 && vertIndex < nvtx) {
227  simVtxItr = SimVtx->begin();
228  for (int iv = 0; iv < vertIndex; iv++)
229  simVtxItr++;
230  int parent = simVtxItr->parentIndex(), k2 = 0;
231  for (edm::SimTrackContainer::const_iterator trkItr = SimTk->begin(); trkItr != SimTk->end(); trkItr++, ++k2) {
232 #ifdef EDM_ML_DEBUG
233  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Track " << k2 << " ID " << trkItr->trackId()
234  << " (" << parent << ") Generator " << trkItr->noGenpart();
235 #endif
236  if ((int)trkItr->trackId() == parent) { // Parent track
237  if (!trkItr->noGenpart()) { // Generator level
238 #ifdef EDM_ML_DEBUG
239  edm::LogVerbatim("CherenkovAnalysis") << "XtalDedxAnalysis::Track found with ID " << simTrkItr->type();
240 #endif
241  mType_->Fill(simTrkItr->type());
242  }
243  break;
244  }
245  }
246  }
247  }
248  }
249 }
250 
251 // define this as a plug-in
ConfigurationDescriptions.h
XtalDedxAnalysis::caloHitSource_
edm::InputTag caloHitSource_
Definition: XtalDedxAnalysis.cc:53
XtalDedxAnalysis::tok_calo_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_
Definition: XtalDedxAnalysis.cc:56
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::EDGetTokenT< edm::PCaloHitContainer >
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
XtalDedxAnalysis::meE1T0_
TH1F * meE1T0_[4]
Definition: XtalDedxAnalysis.cc:60
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
protons_cff.time
time
Definition: protons_cff.py:35
XtalDedxAnalysis::simTkLabel_
std::string simTkLabel_
Definition: XtalDedxAnalysis.cc:54
XtalDedxAnalysis::~XtalDedxAnalysis
~XtalDedxAnalysis() override
Definition: XtalDedxAnalysis.cc:39
XtalDedxAnalysis::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: XtalDedxAnalysis.cc:119
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
XtalDedxAnalysis::meNHit_
TH1F * meNHit_[4]
Definition: XtalDedxAnalysis.cc:60
edm::Handle< edm::SimTrackContainer >
XtalDedxAnalysis::analyzeHits
void analyzeHits(std::vector< PCaloHit > &, edm::Handle< edm::SimTrackContainer > &, edm::Handle< edm::SimVertexContainer > &)
Definition: XtalDedxAnalysis.cc:152
MakerMacros.h
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
Service.h
SimVertex.h
tfile
Definition: tfile.py:1
XtalDedxAnalysis::meE9T0_
TH1F * meE9T0_[4]
Definition: XtalDedxAnalysis.cc:60
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
XtalDedxAnalysis::endJob
void endJob() override
Definition: XtalDedxAnalysis.cc:46
TFileService.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
XtalDedxAnalysis::meE9T1_
TH1F * meE9T1_[4]
Definition: XtalDedxAnalysis.cc:60
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
PCaloHit.h
XtalDedxAnalysis::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: XtalDedxAnalysis.cc:127
edm::Service< TFileService >
edm::EventSetup
Definition: EventSetup.h:58
XtalDedxAnalysis::tok_vtx_
edm::EDGetTokenT< edm::SimVertexContainer > tok_vtx_
Definition: XtalDedxAnalysis.cc:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
XtalDedxAnalysis
Definition: XtalDedxAnalysis.cc:36
InputTag.h
compare.tfile
tfile
Definition: compare.py:324
types
types
Definition: AlignPCLThresholds_PayloadInspector.cc:30
XtalDedxAnalysis::beginJob
void beginJob() override
Definition: XtalDedxAnalysis.cc:44
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
PCaloHitContainer.h
cms::Exception
Definition: Exception.h:70
XtalDedxAnalysis::XtalDedxAnalysis
XtalDedxAnalysis(const edm::ParameterSet &)
Definition: XtalDedxAnalysis.cc:64
XtalDedxAnalysis::mType_
TH1I * mType_
Definition: XtalDedxAnalysis.cc:61
SimTrack.h
ParameterSet.h
XtalDedxAnalysis::meE1T1_
TH1F * meE1T1_[4]
Definition: XtalDedxAnalysis.cc:60
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
XtalDedxAnalysis::tok_tk_
edm::EDGetTokenT< edm::SimTrackContainer > tok_tk_
Definition: XtalDedxAnalysis.cc:57
class-composition.parent
parent
Definition: class-composition.py:98
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
SimVertexContainer.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37