CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: GlobalTest.cc,v 1.11 2012/10/10 14:39:02 wdd Exp $
14 //
15 //
16 
17 
18 // system include files
19 #include <memory>
20 #include <utility>
21 
22 #include <string>
23 
24 // user include files
27 
30 
32 
36 
39 
41 #include "TFile.h"
44 
45 using namespace edm;
46 
48 filename_(iConfig.getParameter<std::string>("fileName")),
49 minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")), dbe_(0),
50 cfTrackTag_(iConfig.getParameter<edm::InputTag>("cfTrackTag")),
51 cfVertexTag_(iConfig.getParameter<edm::InputTag>("cfVertexTag"))
52 {
53  std::cout << "Constructed GlobalTest, filename: "<<filename_<<" minbunch: "<<minbunch_<<", maxbunch: "<<maxbunch_<<std::endl;
54 
55 }
56 
58 {
59 
60  // do anything here that needs to be done at desctruction time
61  // (e.g. close files, deallocate resources etc.)
62 }
63 
65  using namespace std;
66 
67  // get hold of back-end interface
70  dbe_->setCurrentFolder("MixingV/Mixing");
71  //book histos
72  std::string NrPileupEvts = "NrPileupEvts";
73  size_t NrPileupEvtsSize = NrPileupEvts.size() + 1;
74  std::string NrVertices = "NrVertices";
75  size_t NrVerticesSize = NrVertices.size() + 1;
76  std::string NrTracks = "NrTracks";
77  size_t NrTracksSize = NrTracks.size() + 1;
78  std::string TrackPartId = "TrackPartId";
79  size_t TrackPartIdSize = TrackPartId.size() + 1;
80  std::string CaloEnergyEB = "CaloEnergyEB";
81  size_t CaloEnergyEBSize = CaloEnergyEB.size() + 1;
82  std::string CaloEnergyEE = "CaloEnergyEE";
83  size_t CaloEnergyEESize = CaloEnergyEE.size() + 1;
84 
85  labels[0] = new char [NrPileupEvtsSize];
86  strncpy(labels[0], NrPileupEvts.c_str(), NrPileupEvtsSize);
87  labels[1] = new char [NrVerticesSize];
88  strncpy(labels[1], NrVertices.c_str(), NrVerticesSize);
89  labels[2] = new char [NrTracksSize];
90  strncpy(labels[2], NrTracks.c_str(), NrTracksSize);
91  labels[3] = new char [TrackPartIdSize];
92  strncpy(labels[3], TrackPartId.c_str(), TrackPartIdSize);
93  labels[4] = new char [CaloEnergyEBSize];
94  strncpy(labels[4], CaloEnergyEB.c_str(), CaloEnergyEBSize);
95  labels[5] = new char [CaloEnergyEESize];
96  strncpy(labels[5], CaloEnergyEE.c_str(), CaloEnergyEESize);
97 
98  //FIXME: test for max nr of histos
99  for (int i=minbunch_;i<=maxbunch_;++i) {
100  int ii=i-minbunch_;
101  char label[50];
102  sprintf(label,"%s_%d",labels[0],i);
103  nrPileupsH_[ii] = dbe_->book1D(label,label,100,0,100);
104  sprintf(label,"%s_%d",labels[1],i);
105  nrVerticesH_[ii] = dbe_->book1D(label,label,100,0,5000);
106  sprintf(label,"%s_%d",labels[2],i);
107  nrTracksH_[ii] = dbe_->book1D(label,label,100,0,10000);
108  sprintf(label,"%s_%d",labels[3],i);
109  trackPartIdH_[ii] = dbe_->book1D(label,label,100,0,100);
110  sprintf(label,"%s_%d",labels[4],i);
111  caloEnergyEBH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
112  sprintf(label,"%s_%d",labels[5],i);
113  caloEnergyEEH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
114  }
115 }
116 
117 
119  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
120 
121  for (int i = 0; i < 6; i++) delete[] labels[i];
122 }
123 
124 //
125 // member functions
126 //
127 
128 // ------------ method called to analyze the data ------------
129 void
131 {
132  using namespace edm;
133  using namespace std;
134 
135 // Get input
140  std::string ecalsubdetb("g4SimHitsEcalHitsEB");
141  std::string ecalsubdete("g4SimHitsEcalHitsEE");
142  iEvent.getByLabel(cfTrackTag_, cf_track);
143  iEvent.getByLabel(cfVertexTag_, cf_vertex);
144  iEvent.getByLabel("mix",ecalsubdetb,cf_calohitB);
145  iEvent.getByLabel("mix",ecalsubdete,cf_calohitE);
146 
147  // number of events/bcr ??
148 
149  // number of tracks
150  for (int i=minbunch_;i<=maxbunch_;++i) {
151  nrTracksH_[i-minbunch_]->Fill(cf_track->getNrPileups(i));
152  }
153 
154  // number of vertices
155  for (int i=minbunch_;i<=maxbunch_;++i) {
156  nrVerticesH_[i-minbunch_]->Fill(cf_vertex->getNrPileups(i));
157  }
158 
159  // part id for each track
160  std::auto_ptr<MixCollection<SimTrack> > coltr(new MixCollection<SimTrack>(cf_track.product()));
162  for (cfitr=coltr->begin(); cfitr!=coltr->end();cfitr++) {
163  trackPartIdH_[cfitr.bunch()-minbunch_]->Fill(cfitr->type());
164  }
165 
166  // energy sum
167  double sumE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
168  std::auto_ptr<MixCollection<PCaloHit> > colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
170  for (cfiecalb=colecalb->begin(); cfiecalb!=colecalb->end();cfiecalb++) {
171  sumE[cfiecalb.bunch()-minbunch_]+=cfiecalb->energy();
172  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
173  // else tofecalhist->Fill(cfiecal->time());
174  }
175  for (int i=minbunch_;i<=maxbunch_;++i) {
177  }
178  double sumEE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
179  std::auto_ptr<MixCollection<PCaloHit> > colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
181  for (cfiecale=colecale->begin(); cfiecale!=colecale->end();cfiecale++) {
182  sumEE[cfiecale.bunch()-minbunch_]+=cfiecale->energy();
183  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
184  // else tofecalhist->Fill(cfiecal->time());
185  }
186  for (int i=minbunch_;i<=maxbunch_;++i) {
188  }
189 }
190 
void endJob()
Definition: GlobalTest.cc:118
int i
Definition: DBlmapReader.cc:9
int maxbunch_
Definition: GlobalTest.h:53
DQMStore * dbe_
Definition: GlobalTest.h:64
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
MonitorElement * caloEnergyEEH_[nMaxH]
Definition: GlobalTest.h:62
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: GlobalTest.cc:130
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:2118
char * labels[nrHistos]
Definition: GlobalTest.h:67
int minbunch_
Definition: GlobalTest.h:52
int ii
Definition: cuy.py:588
MonitorElement * trackPartIdH_[nMaxH]
Definition: GlobalTest.h:60
std::string filename_
Definition: GlobalTest.h:51
MonitorElement * caloEnergyEBH_[nMaxH]
Definition: GlobalTest.h:61
void Fill(long long x)
void beginJob()
Definition: GlobalTest.cc:64
int iEvent
Definition: GenABIO.cc:243
GlobalTest(const edm::ParameterSet &)
Definition: GlobalTest.cc:47
MonitorElement * nrPileupsH_[nMaxH]
Definition: GlobalTest.h:57
MonitorElement * nrTracksH_[nMaxH]
Definition: GlobalTest.h:59
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
DQMStore * dbe_
MonitorElement * nrVerticesH_[nMaxH]
Definition: GlobalTest.h:58
edm::InputTag cfVertexTag_
Definition: GlobalTest.h:70
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:2766
edm::InputTag cfTrackTag_
Definition: GlobalTest.h:69
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434