CMS 3D CMS Logo

TestMixedSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TestMixedSource
4 // Class: TestMixedSource
5 //
13 //
14 // Original Author: Emilia Lubenova Becheva
15 // Created: Wed May 20 16:46:58 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
34 
39 
40 #include "TH1I.h"
41 #include "TFile.h"
42 
43 #include "TestMixedSource.h"
44 
45 #include <iostream>
46 #include <fstream>
47 
48 //
49 // constructors and destructor
50 //
51 namespace edm {
53  : fileName_(iConfig.getParameter<std::string>("fileName")),
54  minbunch_(iConfig.getParameter<int>("minBunch")),
55  maxbunch_(iConfig.getParameter<int>("maxBunch")) {
57  new TH1I("histoTrackSignal", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
59  new TH1I("histoTrackPileups", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
60 
61  // Vertex
62  histVertex_bunch_ = new TH1I("histoVertex", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
63 
64  // PCaloHit
66  new TH1I("histoPCaloHit", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
67 
68  // PSimHit
69  histPSimHit_bunchSignal_TrackerHitsTECHighTof_ = new TH1I("histoPSimHitTrackerHitsTECHighTofSignal",
70  "Bunchcrossings",
71  maxbunch_ - minbunch_ + 1,
72  minbunch_,
73  maxbunch_ + 1);
74  histPSimHit_bunchPileups_TrackerHitsTECHighTof_ = new TH1I("histoPSimHitTrackerHitsTECHighTofPileups",
75  "Bunchcrossings",
76  maxbunch_ - minbunch_ + 1,
77  minbunch_,
78  maxbunch_ + 1);
80  "histoPSimHitMuonCSCHitsSignal", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
82  "histoPSimHitMuonCSCHitsPileups", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
83 
84  int bsp = 25; //bunchspace
85  tofhist_ =
86  new TH1I("TrackerHit_Tof_bcr", "TrackerHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
87  tofhist_sig_ = new TH1I(
88  "SignalTrackerHit_Tof_bcr", "TrackerHit_ToF", 100, float(bsp * minbunch_), float(bsp * maxbunch_) + 50.);
89 
90  // HepMCProduct
92  new TH1I("histoHepMCProduct", "Bunchcrossings", maxbunch_ - minbunch_ + 1, minbunch_, maxbunch_ + 1);
93 
94  // Tokens
95 
96  edm::InputTag tag = edm::InputTag("mix", "g4SimHits");
97 
98  SimTrackToken_ = consumes<CrossingFrame<SimTrack>>(tag);
99  SimVertexToken_ = consumes<CrossingFrame<SimVertex>>(tag);
100 
101  tag = edm::InputTag("mix", "g4SimHitsTrackerHitsTECHighTof");
102  TrackerToken0_ = consumes<CrossingFrame<PSimHit>>(tag);
103 
104  tag = edm::InputTag("mix", "g4SimHitsEcalHitsEB");
105  CaloToken1_ = consumes<CrossingFrame<PCaloHit>>(tag);
106 
107  tag = edm::InputTag("mix", "g4SimHitsMuonCSCHits");
108  MuonToken_ = consumes<CrossingFrame<PSimHit>>(tag);
109 
110  tag = edm::InputTag("mix", "generatorSmeared");
111  HepMCToken_ = consumes<CrossingFrame<edm::HepMCProduct>>(tag);
112  }
113 
114  TestMixedSource::~TestMixedSource() { std::cout << " Destructor TestMixed" << std::endl; }
115 
116  //
117  // member functions
118  //
119 
120  // ------------ method called to for each event ------------
122  // test SimTracks
123  //----------------------
125  bool gotTracks = iEvent.getByToken(SimTrackToken_, cf_simtrack);
126  if (!gotTracks)
127  outputFile << " Could not read SimTracks!!!!"
128  << " Please, check if the object SimTracks has been declared in the"
129  << " MixingModule configuration file." << std::endl;
130 
131  if (gotTracks) {
132  outputFile << "\n=================== Starting SimTrack access ===================" << std::endl;
133 
134  std::unique_ptr<MixCollection<SimTrack>> col1(new MixCollection<SimTrack>(cf_simtrack.product()));
136  int count1 = 0;
137  std::cout << " \nWe got " << col1->sizeSignal() << " signal tracks and " << col1->sizePileup()
138  << " pileup tracks, total: " << col1->size() << std::endl;
139  for (cfi1 = col1->begin(); cfi1 != col1->end(); cfi1++) {
140  //std::cout << " BUNCH cfi1.bunch() = " << cfi1.bunch() << std::endl;
141  if (cfi1.getTrigger() == 0) {
142  histTrack_bunchPileups_->Fill(cfi1.bunch());
143  }
144 
145  if (cfi1.getTrigger() == 1) {
146  histTrack_bunchSignal_->Fill(cfi1.bunch());
147  }
148 
149  int a = count1 % 4;
150  if (a == 3) {
151  outputFile << " SimTrack " << count1 << " has genpart index " << cfi1->genpartIndex() << " vertex Index "
152  << cfi1->vertIndex() << " bunchcr " << cfi1.bunch() << " trigger " << cfi1.getTrigger()
153  << ", from EncodedEventId: " << cfi1->eventId().bunchCrossing() << " " << cfi1->eventId().event()
154  << std::endl;
155  }
156  count1++;
157  }
158  }
159 
160  // test SimVertices
161  //---------------------
163  bool gotSimVertex = iEvent.getByToken(SimVertexToken_, cf_simvtx);
164  if (!gotSimVertex)
165  outputFile << " Could not read Simvertices !!!!" << std::endl;
166  else {
167  outputFile << "\n=================== Starting SimVertex access ===================" << std::endl;
168  std::unique_ptr<MixCollection<SimVertex>> col2(new MixCollection<SimVertex>(cf_simvtx.product()));
170  int count2 = 0;
171  outputFile << " \nWe got " << col2->sizeSignal() << " signal vertices and " << col2->sizePileup()
172  << " pileup vertices, total: " << col2->size() << std::endl;
173  for (cfi2 = col2->begin(); cfi2 != col2->end(); cfi2++) {
174  histVertex_bunch_->Fill(cfi2.bunch());
175  int b = count2 % 4;
176  if (count2 == 0 || b == 3) {
177  //outputFile<<" SimVertex "<<count2<<" has parent index "<<cfi2->parentIndex()<<" bunchcr "<<cfi2.bunch()<<" trigger "<<cfi2.getTrigger()<<", from EncodedEventId: "<<cfi2->eventId().bunchCrossing() <<" "<<cfi2->eventId().event() <<std::endl;
178  }
179  //SimVertex myvtx=(*cfi2);
180  //outputFile<<"Same with op*: "<<count2<<" has parent index "<<myvtx.parentIndex()<<" bunchcr "<<cfi2.bunch()<<" trigger "<<cfi2.getTrigger()<<", from EncodedEventId: "<<myvtx.eventId().bunchCrossing() <<" "<<myvtx.eventId().event() <<std::endl;
181  count2++;
182  }
183  }
184 
185  //test HepMCProducts
186  //------------------------------------
188  bool gotHepMCP = iEvent.getByToken(HepMCToken_, cf_hepmc);
189  if (!gotHepMCP)
190  std::cout << " Could not read HepMCProducts!!!!" << std::endl;
191  else {
192  outputFile << "\n=================== Starting HepMCProduct access ===================" << std::endl;
193  std::unique_ptr<MixCollection<edm::HepMCProduct>> colhepmc(
194  new MixCollection<edm::HepMCProduct>(cf_hepmc.product()));
196 
197  int count3 = 0;
198  outputFile << " \nWe got " << colhepmc->sizeSignal() << " signal hepmc products and " << colhepmc->sizePileup()
199  << " pileup hepmcs, total: " << colhepmc->size() << std::endl;
200  for (cfihepmc = colhepmc->begin(); cfihepmc != colhepmc->end(); cfihepmc++) {
201  histHepMCProduct_bunch_->Fill(cfihepmc.bunch());
202  int c = count3 % 4;
203  if (count3 == 0 || c == 3) {
204  //outputFile<<" edm::HepMCProduct "<<count3<<" has event number "<<cfihepmc->GetEvent()->event_number()<<", "<< cfihepmc->GetEvent()->particles_size()<<" particles and "<<cfihepmc->GetEvent()->vertices_size()<<" vertices, bunchcr= "<<cfihepmc.bunch()<<" trigger= "<<cfihepmc.getTrigger() <<" sourcetype= "<<cfihepmc.getSourceType()<<std::endl;
205  }
206  HepMCProduct myprod = colhepmc->getObject(count3);
207  //outputFile<<"same with getObject:hepmc product "<<count3<<" has event number "<<myprod.GetEvent()->event_number()<<", "<<myprod.GetEvent()->particles_size()<<" particles and "<<myprod.GetEvent()->vertices_size()<<" vertices"<<std::endl;
208  count3++;
209  }
210  }
211 
212  // test CaloHits
213  //--------------------------
214  const std::string subdetcalo("g4SimHitsEcalHitsEB");
216  bool gotPCaloHit = iEvent.getByToken(CaloToken1_, cf_calo);
217  if (!gotPCaloHit)
218  outputFile << " Could not read CaloHits with label " << subdetcalo << "!!!!" << std::endl;
219  else {
220  outputFile << "\n\n=================== Starting CaloHit access, subdet " << subdetcalo
221  << " ===================" << std::endl;
222  std::unique_ptr<MixCollection<PCaloHit>> colcalo(new MixCollection<PCaloHit>(cf_calo.product()));
223  //outputFile<<*(colcalo.get())<<std::endl;
225  int count4 = 0;
226  for (cficalo = colcalo->begin(); cficalo != colcalo->end(); cficalo++) {
227  histPCaloHit_bunch_->Fill(cficalo.bunch());
228  int d = count4 % 4;
229  if (count4 == 0 || d == 3) {
230  //outputFile<<" CaloHit "<<count4<<" has tof "<<cficalo->time()<<" trackid "<<cficalo->geantTrackId() <<" bunchcr "<<cficalo.bunch()<<" trigger "<<cficalo.getTrigger()<<", from EncodedEventId: "<<cficalo->eventId().bunchCrossing()<<" " <<cficalo->eventId().event() <<std::endl;
231  }
232  count4++;
233  }
234  }
235 
236  // test PSimHit for one particular subdet
237  //---------------------------------------
238 
239  const std::string subdet("g4SimHitsTrackerHitsTECHighTof");
241  bool gotPSimHit = iEvent.getByToken(TrackerToken0_, cf_simhit);
242  if (!gotPSimHit)
243  outputFile << " Could not read SimHits with label " << subdet << "!!!!" << std::endl;
244  else {
245  outputFile << "\n\n=================== Starting SimHit access, subdet " << subdet
246  << " ===================" << std::endl;
247 
248  std::unique_ptr<MixCollection<PSimHit>> col(new MixCollection<PSimHit>(cf_simhit.product()));
249  //outputFile<<*(col.get())<<std::endl;
251  int count5 = 0;
252  for (cfi = col->begin(); cfi != col->end(); cfi++) {
253  // Signal
254  if (cfi.getTrigger() == 1) {
256  tofhist_sig_->Fill(cfi->timeOfFlight());
257  }
258 
259  // Pileups
260  if (cfi.getTrigger() == 0) {
262  std::cout << " cfi->timeOfFlight() = " << cfi->timeOfFlight() << std::endl;
263  tofhist_->Fill(cfi->timeOfFlight());
264  }
265 
266  int e = count5 % 4;
267  if (e == 3) {
268  outputFile << " Hit " << count5 << " has tof " << cfi->timeOfFlight() << " trackid " << cfi->trackId()
269  << " bunchcr " << cfi.bunch() << " trigger " << cfi.getTrigger()
270  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " " << cfi->eventId().event()
271  << " bcr from MixCol " << cfi.bunch() << std::endl;
272  }
273  count5++;
274  }
275  }
276 
277  const std::string subdet1("g4SimHitsMuonCSCHits");
279  bool gotPSimHit1 = iEvent.getByToken(MuonToken_, cf_simhit1);
280  if (!gotPSimHit1)
281  outputFile << " Could not read SimHits with label " << subdet1 << "!!!!" << std::endl;
282  else {
283  outputFile << "\n\n=================== Starting SimHit access, subdet " << subdet1
284  << " ===================" << std::endl;
285 
286  std::unique_ptr<MixCollection<PSimHit>> col(new MixCollection<PSimHit>(cf_simhit1.product()));
287  //outputFile<<*(col.get())<<std::endl;
289  int count5 = 0;
290  for (cfi = col->begin(); cfi != col->end(); cfi++) {
291  if (cfi.getTrigger() == 1)
293 
294  if (cfi.getTrigger() == 0)
296 
297  int e = count5 % 4;
298  if (e == 3) {
299  outputFile << " Hit " << count5 << " has tof " << cfi->timeOfFlight() << " trackid " << cfi->trackId()
300  << " bunchcr " << cfi.bunch() << " trigger " << cfi.getTrigger()
301  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " " << cfi->eventId().event()
302  << " bcr from MixCol " << cfi.bunch() << std::endl;
303  }
304  count5++;
305  }
306  }
307  }
308 
309  // ------------ method called once each job just before starting event loop ------------
311  outputFile.open("test.log");
312  if (!outputFile.is_open()) {
313  std::cout << "Unable to open file!" << std::endl;
314  }
315  }
316 
317  // ------------ method called once each job just after ending the event loop ------------
319  outputFile.close();
320 
321  char t[30];
322  sprintf(t, "%s", fileName_.c_str());
323  std::cout << " fileName = " << t << std::endl;
324  histFile_ = new TFile(t, "RECREATE");
325  histTrack_bunchPileups_->Write();
326  histTrack_bunchSignal_->Write();
327  histVertex_bunch_->Write();
328  histPCaloHit_bunch_->Write();
331  tofhist_sig_->Write();
332  tofhist_->Write();
335  histHepMCProduct_bunch_->Write();
336  histFile_->Write();
337  histFile_->Close();
338  }
339 } // namespace edm
edm::TestMixedSource::SimVertexToken_
edm::EDGetTokenT< CrossingFrame< SimVertex > > SimVertexToken_
Definition: TestMixedSource.h:86
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::TestMixedSource::fileName_
std::string fileName_
Definition: TestMixedSource.h:63
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::TestMixedSource::tofhist_
TH1I * tofhist_
Definition: TestMixedSource.h:73
CrossingFrame.h
cuy.col
col
Definition: cuy.py:1009
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::TestMixedSource::minbunch_
int minbunch_
Definition: TestMixedSource.h:65
edm::TestMixedSource::maxbunch_
int maxbunch_
Definition: TestMixedSource.h:66
edm::TestMixedSource::histFile_
TFile * histFile_
Definition: TestMixedSource.h:78
edm::TestMixedSource::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TestMixedSource.cc:121
edm::TestMixedSource::CaloToken1_
edm::EDGetTokenT< CrossingFrame< PCaloHit > > CaloToken1_
Definition: TestMixedSource.h:83
EDAnalyzer.h
edm::TestMixedSource::TestMixedSource
TestMixedSource(const edm::ParameterSet &)
Definition: TestMixedSource.cc:52
edm::Handle
Definition: AssociativeIterator.h:50
MixCollection::MixItr
Definition: MixCollection.h:61
TestMixedSource.h
MakerMacros.h
MixCollection::MixItr::bunch
int bunch() const
Definition: MixCollection.h:90
edm::TestMixedSource::HepMCToken_
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > HepMCToken_
Definition: TestMixedSource.h:87
PSimHit.h
edm::TestMixedSource::outputFile
std::ofstream outputFile
Definition: TestMixedSource.h:62
MixCollection.h
edm::TestMixedSource::histPSimHit_bunchPileups_MuonCSCHits_
TH1I * histPSimHit_bunchPileups_MuonCSCHits_
Definition: TestMixedSource.h:76
MixCollection
Definition: MixCollection.h:10
edm::TestMixedSource::histPSimHit_bunchSignal_MuonCSCHits_
TH1I * histPSimHit_bunchSignal_MuonCSCHits_
Definition: TestMixedSource.h:75
MixCollection::MixItr::getTrigger
bool getTrigger() const
Definition: MixCollection.h:97
edm::TestMixedSource::SimTrackToken_
edm::EDGetTokenT< CrossingFrame< SimTrack > > SimTrackToken_
Definition: TestMixedSource.h:85
b
double b
Definition: hdecay.h:118
edm::TestMixedSource::endJob
void endJob() override
Definition: TestMixedSource.cc:318
edm::TestMixedSource::tofhist_sig_
TH1I * tofhist_sig_
Definition: TestMixedSource.h:74
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
edm::TestMixedSource::histHepMCProduct_bunch_
TH1I * histHepMCProduct_bunch_
Definition: TestMixedSource.h:77
edm::TestMixedSource::histPSimHit_bunchPileups_TrackerHitsTECHighTof_
TH1I * histPSimHit_bunchPileups_TrackerHitsTECHighTof_
Definition: TestMixedSource.h:72
edm::TestMixedSource::beginJob
void beginJob() override
Definition: TestMixedSource.cc:310
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
edm::TestMixedSource::histTrack_bunchSignal_
TH1I * histTrack_bunchSignal_
Definition: TestMixedSource.h:68
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::TestMixedSource::TrackerToken0_
edm::EDGetTokenT< CrossingFrame< PSimHit > > TrackerToken0_
Definition: TestMixedSource.h:80
edm::TestMixedSource::histVertex_bunch_
TH1I * histVertex_bunch_
Definition: TestMixedSource.h:69
edm::TestMixedSource::histPSimHit_bunchSignal_TrackerHitsTECHighTof_
TH1I * histPSimHit_bunchSignal_TrackerHitsTECHighTof_
Definition: TestMixedSource.h:71
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::TestMixedSource::histTrack_bunchPileups_
TH1I * histTrack_bunchPileups_
Definition: TestMixedSource.h:67
PCaloHitContainer.h
edm::TestMixedSource::MuonToken_
edm::EDGetTokenT< CrossingFrame< PSimHit > > MuonToken_
Definition: TestMixedSource.h:81
edm::TestMixedSource::histPCaloHit_bunch_
TH1I * histPCaloHit_bunch_
Definition: TestMixedSource.h:70
edm::TestMixedSource::~TestMixedSource
~TestMixedSource() override
Definition: TestMixedSource.cc:114
ztail.d
d
Definition: ztail.py:151
edm::HepMCProduct
Definition: HepMCProduct.h:21
ParameterSet.h
HepMCProduct.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
SimVertexContainer.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37