CMS 3D CMS Logo

GlobalTest.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: GlobalTest
4 //
10 //
11 // Original Author: Ursula Berthon
12 // Created: Fri Sep 23 11:38:38 CEST 2005
13 //
14 //
15 
17 
18 // system include files
19 #include <memory>
20 #include <utility>
21 
22 #include <string>
23 
24 // user include files
27 
30 
32 
34 #include "TFile.h"
35 
36 using namespace edm;
37 
39  : filename_(iConfig.getParameter<std::string>("fileName")),
40  minbunch_(iConfig.getParameter<int>("minBunch")),
41  maxbunch_(iConfig.getParameter<int>("maxBunch")),
42  cfTrackToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfTrackTag"))),
43  cfVertexToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfVertexTag"))) {
44  std::string ecalsubdetb("");
45  std::string ecalsubdete("g4SimHitsEcalHitsEE");
46  g4SimHits_EB_Token_ = consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsEcalHitsEB"));
47  g4SimHits_EE_Token_ = consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsEcalHitsEE"));
48 
49  std::cout << "Constructed GlobalTest, filename: " << filename_ << " minbunch: " << minbunch_
50  << ", maxbunch: " << maxbunch_ << std::endl;
51 }
52 
54  for (int i = 0; i < 6; i++)
55  delete[] labels[i];
56 }
57 
59  using namespace std;
60 
61  ibooker.setCurrentFolder("MixingV/Mixing");
62  // book histos
63  std::string NrPileupEvts = "NrPileupEvts";
64  size_t NrPileupEvtsSize = NrPileupEvts.size() + 1;
65  std::string NrVertices = "NrVertices";
66  size_t NrVerticesSize = NrVertices.size() + 1;
67  std::string NrTracks = "NrTracks";
68  size_t NrTracksSize = NrTracks.size() + 1;
69  std::string TrackPartId = "TrackPartId";
70  size_t TrackPartIdSize = TrackPartId.size() + 1;
71  std::string CaloEnergyEB = "CaloEnergyEB";
72  size_t CaloEnergyEBSize = CaloEnergyEB.size() + 1;
73  std::string CaloEnergyEE = "CaloEnergyEE";
74  size_t CaloEnergyEESize = CaloEnergyEE.size() + 1;
75 
76  labels[0] = new char[NrPileupEvtsSize];
77  strncpy(labels[0], NrPileupEvts.c_str(), NrPileupEvtsSize);
78  labels[1] = new char[NrVerticesSize];
79  strncpy(labels[1], NrVertices.c_str(), NrVerticesSize);
80  labels[2] = new char[NrTracksSize];
81  strncpy(labels[2], NrTracks.c_str(), NrTracksSize);
82  labels[3] = new char[TrackPartIdSize];
83  strncpy(labels[3], TrackPartId.c_str(), TrackPartIdSize);
84  labels[4] = new char[CaloEnergyEBSize];
85  strncpy(labels[4], CaloEnergyEB.c_str(), CaloEnergyEBSize);
86  labels[5] = new char[CaloEnergyEESize];
87  strncpy(labels[5], CaloEnergyEE.c_str(), CaloEnergyEESize);
88 
89  // FIXME: test for max nr of histos
90  for (int i = minbunch_; i <= maxbunch_; ++i) {
91  int ii = i - minbunch_;
92  char label[50];
93  sprintf(label, "%s_%d", labels[0], i);
94  nrPileupsH_[ii] = ibooker.book1D(label, label, 100, 0, 100);
95  sprintf(label, "%s_%d", labels[1], i);
96  nrVerticesH_[ii] = ibooker.book1D(label, label, 100, 0, 5000);
97  sprintf(label, "%s_%d", labels[2], i);
98  nrTracksH_[ii] = ibooker.book1D(label, label, 100, 0, 10000);
99  sprintf(label, "%s_%d", labels[3], i);
100  trackPartIdH_[ii] = ibooker.book1D(label, label, 100, 0, 100);
101  sprintf(label, "%s_%d", labels[4], i);
102  caloEnergyEBH_[ii] = ibooker.book1D(label, label, 100, 0., 1000.);
103  sprintf(label, "%s_%d", labels[5], i);
104  caloEnergyEEH_[ii] = ibooker.book1D(label, label, 100, 0., 1000.);
105  }
106 }
107 
108 //
109 // member functions
110 //
111 
112 // ------------ method called to analyze the data ------------
114  using namespace edm;
115  using namespace std;
116 
117  // Get input
122  std::string ecalsubdetb("g4SimHitsEcalHitsEB");
123  std::string ecalsubdete("g4SimHitsEcalHitsEE");
124  iEvent.getByToken(cfTrackToken_, cf_track);
125  iEvent.getByToken(cfVertexToken_, cf_vertex);
126  iEvent.getByToken(g4SimHits_EB_Token_, cf_calohitB);
127  iEvent.getByToken(g4SimHits_EE_Token_, cf_calohitE);
128 
129  // number of events/bcr ??
130 
131  // number of tracks
132  for (int i = minbunch_; i <= maxbunch_; ++i) {
133  nrTracksH_[i - minbunch_]->Fill(cf_track->getNrPileups(i));
134  }
135 
136  // number of vertices
137  for (int i = minbunch_; i <= maxbunch_; ++i) {
138  nrVerticesH_[i - minbunch_]->Fill(cf_vertex->getNrPileups(i));
139  }
140 
141  // part id for each track
142  std::unique_ptr<MixCollection<SimTrack>> coltr(new MixCollection<SimTrack>(cf_track.product()));
144  for (cfitr = coltr->begin(); cfitr != coltr->end(); cfitr++) {
145  trackPartIdH_[cfitr.bunch() - minbunch_]->Fill(cfitr->type());
146  }
147 
148  // energy sum
149  double sumE[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
150  std::unique_ptr<MixCollection<PCaloHit>> colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
152  for (cfiecalb = colecalb->begin(); cfiecalb != colecalb->end(); cfiecalb++) {
153  sumE[cfiecalb.bunch() - minbunch_] += cfiecalb->energy();
154  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
155  // else tofecalhist->Fill(cfiecal->time());
156  }
157  for (int i = minbunch_; i <= maxbunch_; ++i) {
158  caloEnergyEBH_[i - minbunch_]->Fill(sumE[i - minbunch_]);
159  }
160  double sumEE[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
161  std::unique_ptr<MixCollection<PCaloHit>> colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
163  for (cfiecale = colecale->begin(); cfiecale != colecale->end(); cfiecale++) {
164  sumEE[cfiecale.bunch() - minbunch_] += cfiecale->energy();
165  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
166  // else tofecalhist->Fill(cfiecal->time());
167  }
168  for (int i = minbunch_; i <= maxbunch_; ++i) {
169  caloEnergyEEH_[i - minbunch_]->Fill(sumEE[i - minbunch_]);
170  }
171 }
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
int maxbunch_
Definition: GlobalTest.h:54
MonitorElement * caloEnergyEEH_[nMaxH]
Definition: GlobalTest.h:63
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
char * labels[nrHistos]
Definition: GlobalTest.h:66
int minbunch_
Definition: GlobalTest.h:53
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_EE_Token_
Definition: GlobalTest.h:71
MonitorElement * trackPartIdH_[nMaxH]
Definition: GlobalTest.h:61
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfTrackToken_
Definition: GlobalTest.h:68
std::string filename_
Definition: GlobalTest.h:52
MonitorElement * caloEnergyEBH_[nMaxH]
Definition: GlobalTest.h:62
void Fill(long long x)
char const * label
int iEvent
Definition: GenABIO.cc:224
GlobalTest(const edm::ParameterSet &)
Definition: GlobalTest.cc:38
~GlobalTest() override
Definition: GlobalTest.cc:53
MonitorElement * nrPileupsH_[nMaxH]
Definition: GlobalTest.h:58
MonitorElement * nrTracksH_[nMaxH]
Definition: GlobalTest.h:60
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfVertexToken_
Definition: GlobalTest.h:69
ii
Definition: cuy.py:590
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: GlobalTest.cc:58
T const * product() const
Definition: Handle.h:69
MonitorElement * nrVerticesH_[nMaxH]
Definition: GlobalTest.h:59
HLT enums.
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_EB_Token_
Definition: GlobalTest.h:70
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: GlobalTest.cc:113
Definition: Run.h:45