CMS 3D CMS Logo

TestSuite.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: TestSuite
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 // user include files
23 
25 #include "TFile.h"
26 
27 using namespace edm;
28 
30  : filename_(iConfig.getParameter<std::string>("fileName")),
31  bunchcr_(iConfig.getParameter<int>("BunchNr")),
32  minbunch_(iConfig.getParameter<int>("minBunch")),
33  maxbunch_(iConfig.getParameter<int>("maxBunch")),
34  dbe_(nullptr),
35  cfTrackToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfTrackTag"))),
36  cfVertexToken_(consumes<CrossingFrame<SimTrack>>(iConfig.getParameter<edm::InputTag>("cfVertexTag"))),
37  g4SimHits_Token_(consumes<CrossingFrame<PSimHit>>(edm::InputTag("mix", "g4SimHitsTrackerHitsTECLowTof"))),
38  g4SimHits_Ecal_Token_(consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsEcalHitsEB"))),
39  g4SimHits_HCal_Token_(consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsHcalHits"))) {
40  std::cout << "Constructed testSuite , bunchcr " << bunchcr_ << " filename: " << filename_ << std::endl;
41 }
42 
44  // do anything here that needs to be done at desctruction time
45  // (e.g. close files, deallocate resources etc.)
46 }
47 
49  // get hold of back-end interface
51  dbe_->setCurrentFolder("MixingV/Mixing");
52 }
53 
55  if (!filename_.empty() && dbe_)
57 }
58 
59 // ------------ method called to analyze the data ------------
60 void TestSuite::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
61  using namespace edm;
62 
63  // Get input
69  std::string subdetTracker("g4SimHitsTrackerHitsTECLowTof");
70  std::string ecalsubdet("g4SimHitsEcalHitsEB");
71  std::string hcalsubdet("g4SimHitsHcalHits");
72  iEvent.getByToken(cfTrackToken_, cf_track);
73  iEvent.getByToken(cfVertexToken_, cf_vertex);
74  iEvent.getByToken(g4SimHits_Token_, cf_simhit);
75  iEvent.getByToken(g4SimHits_Ecal_Token_, cf_calohitEcal);
76  iEvent.getByToken(g4SimHits_HCal_Token_, cf_calohitHcal);
77 
78  // use MixCollection and its iterator
79  // Please note that bunch() and getTrigger() are methods of the iterator
80  // itself while operator-> points to the templated objects!!!!
81 
82  // track histo
83  char histotracks[30], sighistotracks[30], histotracksindsig[30], histotracksind[30];
84  sprintf(histotracks, "Tracks_bcr_%d", bunchcr_);
85  sprintf(sighistotracks, "SignalTracks_bcr_%d", bunchcr_);
86  sprintf(histotracksind, "VtxPointers_%d", bunchcr_);
87  sprintf(histotracksindsig, "VtxPointers_signal_%d", bunchcr_);
88  MonitorElement *trhist =
89  dbe_->book1D(histotracks, "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
90  MonitorElement *trhistsig =
91  dbe_->book1D(sighistotracks, "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
92  MonitorElement *trindhist = dbe_->book1D(histotracksind, "Track to Vertex indices", 100, 0, 500);
93  MonitorElement *trindhistsig = dbe_->book1D(histotracksindsig, "Signal Track to Vertex indices", 100, 0, 500);
94  std::unique_ptr<MixCollection<SimTrack>> col1(new MixCollection<SimTrack>(cf_track.product()));
96  for (cfi1 = col1->begin(); cfi1 != col1->end(); cfi1++) {
97  if (cfi1.getTrigger() == 0) {
98  trhist->Fill(cfi1.bunch());
99  trindhist->Fill(cfi1->vertIndex());
100  } else {
101  trindhistsig->Fill(cfi1->vertIndex());
102  trhistsig->Fill(cfi1.bunch());
103  }
104  }
105 
106  // vertex histo
107  char histovertices[30], sighistovertices[30], histovertexindices[30], histovertexindicessig[30];
108  sprintf(histovertices, "Vertices_bcr_%d", bunchcr_);
109  sprintf(sighistovertices, "SignalVertices_bcr_%d", bunchcr_);
110  sprintf(histovertexindices, "TrackPointers_%d", bunchcr_);
111  sprintf(histovertexindicessig, "TrackPointers_signal_%d", bunchcr_);
112  MonitorElement *vtxhist =
113  dbe_->book1D(histovertices, "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
114  MonitorElement *vtxhistsig =
115  dbe_->book1D(sighistovertices, "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
116  MonitorElement *vtxindhist = dbe_->book1D(histovertexindices, "Vertex to Track Indices", 100, 0, 300);
117  MonitorElement *vtxindhistsig = dbe_->book1D(histovertexindicessig, "Signal Vertex to Track Indices", 100, 0, 300);
118  std::unique_ptr<MixCollection<SimVertex>> col2(new MixCollection<SimVertex>(cf_vertex.product()));
120  for (cfi2 = col2->begin(); cfi2 != col2->end(); cfi2++) {
121  if (cfi2.getTrigger() == 0) {
122  vtxhist->Fill(cfi2.bunch());
123  if (!cfi2->noParent())
124  vtxindhist->Fill(cfi2->parentIndex());
125  } else {
126  vtxhistsig->Fill(cfi2.bunch());
127  if (!cfi2->noParent())
128  vtxindhistsig->Fill(cfi2->parentIndex());
129  }
130  }
131 
132  // tracker
133  int bsp = cf_simhit->getBunchSpace();
134  char tof[30];
135 
136  sprintf(tof, "TrackerHit_Tof_bcr_%d", bunchcr_);
137  MonitorElement *tofhist =
138  dbe_->book1D(tof, "TrackerHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
139  sprintf(tof, "SignalTrackerHit_Tof_bcr_%d", bunchcr_);
140  MonitorElement *tofhist_sig =
141  dbe_->book1D(tof, "TrackerHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
142  std::unique_ptr<MixCollection<PSimHit>> colsh(new MixCollection<PSimHit>(cf_simhit.product()));
144  for (cfish = colsh->begin(); cfish != colsh->end(); cfish++) {
145  if (cfish.getTrigger()) {
146  tofhist_sig->Fill(cfish->timeOfFlight());
147  } else {
148  tofhist->Fill(cfish->timeOfFlight());
149  }
150  }
151 
152  // Ecal
153  sprintf(tof, "EcalEBHit_Tof_bcr_%d", bunchcr_);
154  MonitorElement *tofecalhist =
155  dbe_->book1D(tof, "EcalEBHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
156  sprintf(tof, "SignalEcalEBHit_Tof_bcr_%d", bunchcr_);
157  MonitorElement *tofecalhist_sig =
158  dbe_->book1D(tof, "EcalEBHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
159  // std::string ecalsubdet("EcalHitsEB");
160  std::unique_ptr<MixCollection<PCaloHit>> colecal(new MixCollection<PCaloHit>(cf_calohitEcal.product()));
162  for (cfiecal = colecal->begin(); cfiecal != colecal->end(); cfiecal++) {
163  if (cfiecal.getTrigger())
164  tofecalhist_sig->Fill(cfiecal->time());
165  else
166  tofecalhist->Fill(cfiecal->time());
167  }
168 
169  // Hcal
170  sprintf(tof, "HcalHit_Tof_bcr_%d", bunchcr_);
171  MonitorElement *tofhcalhist =
172  dbe_->book1D(tof, "HcalHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
173  sprintf(tof, "SignalHcalHit_Tof_bcr_%d", bunchcr_);
174  MonitorElement *tofhcalhist_sig =
175  dbe_->book1D(tof, "HcalHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
176  // std::string hcalsubdet("HcalHits");
177  std::unique_ptr<MixCollection<PCaloHit>> colhcal(new MixCollection<PCaloHit>(cf_calohitHcal.product()));
179 
180  for (cfihcal = colhcal->begin(); cfihcal != colhcal->end(); cfihcal++) {
181  if (cfihcal.getTrigger())
182  tofhcalhist_sig->Fill(cfihcal->time());
183  else
184  tofhcalhist->Fill(cfihcal->time());
185  }
186 }
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfVertexToken_
Definition: TestSuite.h:65
void beginJob() override
Definition: TestSuite.cc:48
int maxbunch_
Definition: TestSuite.h:61
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:647
T const * product() const
Definition: Handle.h:70
TestSuite(const edm::ParameterSet &)
Definition: TestSuite.cc:29
void Fill(long long x)
int minbunch_
Definition: TestSuite.h:60
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfTrackToken_
Definition: TestSuite.h:64
DQMStore * dbe_
Definition: TestSuite.h:62
~TestSuite() override
Definition: TestSuite.cc:43
void endJob() override
Definition: TestSuite.cc:54
edm::EDGetTokenT< CrossingFrame< PSimHit > > g4SimHits_Token_
Definition: TestSuite.h:66
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_HCal_Token_
Definition: TestSuite.h:68
std::string filename_
Definition: TestSuite.h:58
bool getTrigger() const
Definition: MixCollection.h:97
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:824
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TestSuite.cc:60
HLT enums.
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_Ecal_Token_
Definition: TestSuite.h:67
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
int bunchcr_
Definition: TestSuite.h:59