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