CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: TestSuite.cc,v 1.12 2009/12/21 14:46:56 ebecheva Exp $
14 //
15 //
16 
17 
18 // system include files
19 #include <memory>
20 #include <utility>
21 
22 // user include files
23 
27 
32 
34 
35 #include "TFile.h"
38 
39 using namespace edm;
40 
41 TestSuite::TestSuite(const edm::ParameterSet& iConfig): filename_(iConfig.getParameter<std::string>("fileName")), bunchcr_(iConfig.getParameter<int>("BunchNr")), minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")), dbe_(0)
42 {
43  std::cout << "Constructed testSuite , bunchcr "<<bunchcr_<<" filename: "<<filename_<<std::endl;
44 
45 }
46 
47 
49 {
50 
51  // do anything here that needs to be done at desctruction time
52  // (e.g. close files, deallocate resources etc.)
53 }
54 
56 
57  // get hold of back-end interface
60  dbe_->setCurrentFolder("MixingV/Mixing");
61 }
62 
64  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
65 }
66 
67 
68 
69 // ------------ method called to analyze the data ------------
70 void
72 {
73  using namespace edm;
74 
75 // Get input
79  edm::Handle<CrossingFrame<PCaloHit> > cf_calohitEcal;
80  edm::Handle<CrossingFrame<PCaloHit> > cf_calohitHcal;
81  std::string subdetTracker("g4SimHitsTrackerHitsTECLowTof");
82  std::string ecalsubdet("g4SimHitsEcalHitsEB");
83  std::string hcalsubdet("g4SimHitsHcalHits");
84  iEvent.getByType(cf_track);
85  iEvent.getByType(cf_vertex);
86  iEvent.getByLabel("mix",subdetTracker,cf_simhit);
87  iEvent.getByLabel("mix",ecalsubdet,cf_calohitEcal);
88  iEvent.getByLabel("mix",hcalsubdet,cf_calohitHcal);
89 
90 // use MixCollection and its iterator
91 // Please note that bunch() and getTrigger() are methods of the iterator itself
92 // while operator-> points to the templated objects!!!!
93 
94 //track histo
95  char histotracks[30],sighistotracks[30],histotracksindsig[30],histotracksind[30];
96  sprintf(histotracks,"Tracks_bcr_%d",bunchcr_);
97  sprintf(sighistotracks,"SignalTracks_bcr_%d",bunchcr_);
98  sprintf(histotracksind,"VtxPointers_%d",bunchcr_);
99  sprintf(histotracksindsig,"VtxPointers_signal_%d",bunchcr_);
100  MonitorElement * trhist = dbe_->book1D(histotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
101  MonitorElement * trhistsig = dbe_->book1D(sighistotracks,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
102  MonitorElement * trindhist = dbe_->book1D(histotracksind,"Track to Vertex indices",100,0,500);
103  MonitorElement * trindhistsig = dbe_->book1D(histotracksindsig,"Signal Track to Vertex indices",100,0,500);
104  std::auto_ptr<MixCollection<SimTrack> > col1(new MixCollection<SimTrack>(cf_track.product()));
106  for (cfi1=col1->begin(); cfi1!=col1->end();cfi1++) {
107  if (cfi1.getTrigger()==0) {
108  trhist->Fill(cfi1.bunch());
109  trindhist->Fill(cfi1->vertIndex());
110  } else {
111  trindhistsig->Fill(cfi1->vertIndex());
112  trhistsig->Fill(cfi1.bunch());
113  }
114  }
115 
116 
117 //vertex histo
118  char histovertices[30], sighistovertices[30],histovertexindices[30],histovertexindicessig[30];
119  sprintf(histovertices,"Vertices_bcr_%d",bunchcr_);
120  sprintf(sighistovertices,"SignalVertices_bcr_%d",bunchcr_);
121  sprintf(histovertexindices,"TrackPointers_%d",bunchcr_);
122  sprintf(histovertexindicessig,"TrackPointers_signal_%d",bunchcr_);
123  MonitorElement * vtxhist = dbe_->book1D(histovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
124  MonitorElement * vtxhistsig = dbe_->book1D(sighistovertices,"Bunchcrossings",maxbunch_-minbunch_+1,minbunch_,maxbunch_+1);
125  MonitorElement * vtxindhist = dbe_->book1D(histovertexindices,"Vertex to Track Indices",100,0,300);
126  MonitorElement * vtxindhistsig = dbe_->book1D(histovertexindicessig,"Signal Vertex to Track Indices",100,0,300);
127  std::auto_ptr<MixCollection<SimVertex> > col2(new MixCollection<SimVertex>(cf_vertex.product()));
129  for (cfi2=col2->begin(); cfi2!=col2->end();cfi2++) {
130  if (cfi2.getTrigger()==0) {
131  vtxhist->Fill(cfi2.bunch());
132  if (!cfi2->noParent()) vtxindhist->Fill(cfi2->parentIndex());
133  } else {
134  vtxhistsig->Fill(cfi2.bunch());
135  if (!cfi2->noParent()) vtxindhistsig->Fill(cfi2->parentIndex());
136  }
137  }
138 
139  //tracker
140  int bsp=cf_simhit->getBunchSpace();
141  char tof[30];
142 
143  sprintf(tof,"TrackerHit_Tof_bcr_%d",bunchcr_);
144  MonitorElement * tofhist = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
145  sprintf(tof,"SignalTrackerHit_Tof_bcr_%d",bunchcr_);
146  MonitorElement * tofhist_sig = dbe_->book1D(tof,"TrackerHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
147  std::auto_ptr<MixCollection<PSimHit> > colsh(new MixCollection<PSimHit>(cf_simhit.product()));
149  for (cfish=colsh->begin(); cfish!=colsh->end();cfish++) {
150  if (cfish.getTrigger()) {
151  tofhist_sig->Fill(cfish->timeOfFlight());
152  }
153  else {
154  tofhist->Fill(cfish->timeOfFlight());
155  }
156  }
157 
158  //Ecal
159  sprintf(tof,"EcalEBHit_Tof_bcr_%d",bunchcr_);
160  MonitorElement * tofecalhist = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
161  sprintf(tof,"SignalEcalEBHit_Tof_bcr_%d",bunchcr_);
162  MonitorElement * tofecalhist_sig = dbe_->book1D(tof,"EcalEBHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
163  // std::string ecalsubdet("EcalHitsEB");
164  std::auto_ptr<MixCollection<PCaloHit> > colecal(new MixCollection<PCaloHit>(cf_calohitEcal.product()));
166  for (cfiecal=colecal->begin(); cfiecal!=colecal->end();cfiecal++) {
167  if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
168  else tofecalhist->Fill(cfiecal->time());
169  }
170 
171  // Hcal
172  sprintf(tof,"HcalHit_Tof_bcr_%d",bunchcr_);
173  MonitorElement * tofhcalhist = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
174  sprintf(tof,"SignalHcalHit_Tof_bcr_%d",bunchcr_);
175  MonitorElement * tofhcalhist_sig = dbe_->book1D(tof,"HcalHit_ToF",100,float(bsp*minbunch_),float(bsp*maxbunch_)+50.);
176  // std::string hcalsubdet("HcalHits");
177  std::auto_ptr<MixCollection<PCaloHit> > colhcal(new MixCollection<PCaloHit>(cf_calohitHcal.product()));
179 
180  for (cfihcal=colhcal->begin(); cfihcal!=colhcal->end();cfihcal++) {
181  if (cfihcal.getTrigger()) tofhcalhist_sig->Fill(cfihcal->time());
182  else tofhcalhist->Fill(cfihcal->time());
183  }
184 }
185 
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: TestSuite.cc:71
virtual void endJob()
Definition: TestSuite.cc:63
int maxbunch_
Definition: TestSuite.h:51
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
~TestSuite()
Definition: TestSuite.cc:48
TestSuite(const edm::ParameterSet &)
Definition: TestSuite.cc:41
int minbunch_
Definition: TestSuite.h:50
int iEvent
Definition: GenABIO.cc:243
DQMStore * dbe_
Definition: TestSuite.h:52
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
DQMStore * dbe_
std::string filename_
Definition: TestSuite.h:48
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:2761
virtual void beginJob()
Definition: TestSuite.cc:55
int bunchcr_
Definition: TestSuite.h:49
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429