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