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 //
14 //
15 
16 
18 
19 // system include files
20 #include <memory>
21 #include <utility>
22 
23 #include <string>
24 
25 // user include files
28 
31 
33 
34 #include "TFile.h"
37 
38 using namespace edm;
39 
41  filename_(iConfig.getParameter<std::string>("fileName")),
42  minbunch_(iConfig.getParameter<int>("minBunch")),maxbunch_(iConfig.getParameter<int>("maxBunch")), dbe_(0),
43  cfTrackToken_(consumes<CrossingFrame<SimTrack> > (
44  iConfig.getParameter<edm::InputTag>("cfTrackTag"))),
45  cfVertexToken_(consumes<CrossingFrame<SimTrack> >(
46  iConfig.getParameter<edm::InputTag>("cfVertexTag")))
47 {
48  std::string ecalsubdetb();
49  std::string ecalsubdete("g4SimHitsEcalHitsEE");
50  g4SimHits_EB_Token_ = consumes<CrossingFrame<PCaloHit> > (
51  edm::InputTag("mix", "g4SimHitsEcalHitsEB"));
52  g4SimHits_EE_Token_ = consumes<CrossingFrame<PCaloHit> > (
53  edm::InputTag("mix", "g4SimHitsEcalHitsEE"));
54 
55  std::cout << "Constructed GlobalTest, filename: "
56  << filename_ << " minbunch: "
57  << minbunch_ << ", maxbunch: "
58  << maxbunch_ << std::endl;
59 
60 }
61 
63 {
64 
65  // do anything here that needs to be done at desctruction time
66  // (e.g. close files, deallocate resources etc.)
67 }
68 
70  using namespace std;
71 
72  // get hold of back-end interface
75  dbe_->setCurrentFolder("MixingV/Mixing");
76  //book histos
77  std::string NrPileupEvts = "NrPileupEvts";
78  size_t NrPileupEvtsSize = NrPileupEvts.size() + 1;
79  std::string NrVertices = "NrVertices";
80  size_t NrVerticesSize = NrVertices.size() + 1;
81  std::string NrTracks = "NrTracks";
82  size_t NrTracksSize = NrTracks.size() + 1;
83  std::string TrackPartId = "TrackPartId";
84  size_t TrackPartIdSize = TrackPartId.size() + 1;
85  std::string CaloEnergyEB = "CaloEnergyEB";
86  size_t CaloEnergyEBSize = CaloEnergyEB.size() + 1;
87  std::string CaloEnergyEE = "CaloEnergyEE";
88  size_t CaloEnergyEESize = CaloEnergyEE.size() + 1;
89 
90  labels[0] = new char [NrPileupEvtsSize];
91  strncpy(labels[0], NrPileupEvts.c_str(), NrPileupEvtsSize);
92  labels[1] = new char [NrVerticesSize];
93  strncpy(labels[1], NrVertices.c_str(), NrVerticesSize);
94  labels[2] = new char [NrTracksSize];
95  strncpy(labels[2], NrTracks.c_str(), NrTracksSize);
96  labels[3] = new char [TrackPartIdSize];
97  strncpy(labels[3], TrackPartId.c_str(), TrackPartIdSize);
98  labels[4] = new char [CaloEnergyEBSize];
99  strncpy(labels[4], CaloEnergyEB.c_str(), CaloEnergyEBSize);
100  labels[5] = new char [CaloEnergyEESize];
101  strncpy(labels[5], CaloEnergyEE.c_str(), CaloEnergyEESize);
102 
103  //FIXME: test for max nr of histos
104  for (int i=minbunch_;i<=maxbunch_;++i) {
105  int ii=i-minbunch_;
106  char label[50];
107  sprintf(label,"%s_%d",labels[0],i);
108  nrPileupsH_[ii] = dbe_->book1D(label,label,100,0,100);
109  sprintf(label,"%s_%d",labels[1],i);
110  nrVerticesH_[ii] = dbe_->book1D(label,label,100,0,5000);
111  sprintf(label,"%s_%d",labels[2],i);
112  nrTracksH_[ii] = dbe_->book1D(label,label,100,0,10000);
113  sprintf(label,"%s_%d",labels[3],i);
114  trackPartIdH_[ii] = dbe_->book1D(label,label,100,0,100);
115  sprintf(label,"%s_%d",labels[4],i);
116  caloEnergyEBH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
117  sprintf(label,"%s_%d",labels[5],i);
118  caloEnergyEEH_ [ii] = dbe_->book1D(label,label,100,0.,1000.);
119  }
120 }
121 
122 
124  if (filename_.size() != 0 && dbe_ ) dbe_->save(filename_);
125 
126  for (int i = 0; i < 6; i++) delete[] labels[i];
127 }
128 
129 //
130 // member functions
131 //
132 
133 // ------------ method called to analyze the data ------------
134 void
136 {
137  using namespace edm;
138  using namespace std;
139 
140  // Get input
145  std::string ecalsubdetb("g4SimHitsEcalHitsEB");
146  std::string ecalsubdete("g4SimHitsEcalHitsEE");
147  iEvent.getByToken(cfTrackToken_, cf_track);
148  iEvent.getByToken(cfVertexToken_, cf_vertex);
149  iEvent.getByToken(g4SimHits_EB_Token_, cf_calohitB);
150  iEvent.getByToken(g4SimHits_EE_Token_, cf_calohitE);
151 
152  // number of events/bcr ??
153 
154  // number of tracks
155  for (int i=minbunch_;i<=maxbunch_;++i) {
156  nrTracksH_[i-minbunch_]->Fill(cf_track->getNrPileups(i));
157  }
158 
159  // number of vertices
160  for (int i=minbunch_;i<=maxbunch_;++i) {
161  nrVerticesH_[i-minbunch_]->Fill(cf_vertex->getNrPileups(i));
162  }
163 
164  // part id for each track
165  std::auto_ptr<MixCollection<SimTrack> > coltr(new MixCollection<SimTrack>(cf_track.product()));
167  for (cfitr=coltr->begin(); cfitr!=coltr->end();cfitr++) {
168  trackPartIdH_[cfitr.bunch()-minbunch_]->Fill(cfitr->type());
169  }
170 
171  // energy sum
172  double sumE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
173  std::auto_ptr<MixCollection<PCaloHit> > colecalb(new MixCollection<PCaloHit>(cf_calohitB.product()));
175  for (cfiecalb=colecalb->begin(); cfiecalb!=colecalb->end();cfiecalb++) {
176  sumE[cfiecalb.bunch()-minbunch_]+=cfiecalb->energy();
177  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
178  // else tofecalhist->Fill(cfiecal->time());
179  }
180  for (int i=minbunch_;i<=maxbunch_;++i) {
182  }
183  double sumEE[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
184  std::auto_ptr<MixCollection<PCaloHit> > colecale(new MixCollection<PCaloHit>(cf_calohitE.product()));
186  for (cfiecale=colecale->begin(); cfiecale!=colecale->end();cfiecale++) {
187  sumEE[cfiecale.bunch()-minbunch_]+=cfiecale->energy();
188  // if (cfiecal.getTrigger()) tofecalhist_sig->Fill(cfiecal->time());
189  // else tofecalhist->Fill(cfiecal->time());
190  }
191  for (int i=minbunch_;i<=maxbunch_;++i) {
193  }
194 }
195 
void endJob()
Definition: GlobalTest.cc:123
int i
Definition: DBlmapReader.cc:9
int maxbunch_
Definition: GlobalTest.h:59
DQMStore * dbe_
Definition: GlobalTest.h:70
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
MonitorElement * caloEnergyEEH_[nMaxH]
Definition: GlobalTest.h:68
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: GlobalTest.cc:135
char * labels[nrHistos]
Definition: GlobalTest.h:73
int minbunch_
Definition: GlobalTest.h:58
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_EE_Token_
Definition: GlobalTest.h:78
int ii
Definition: cuy.py:588
MonitorElement * trackPartIdH_[nMaxH]
Definition: GlobalTest.h:66
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfTrackToken_
Definition: GlobalTest.h:75
std::string filename_
Definition: GlobalTest.h:57
MonitorElement * caloEnergyEBH_[nMaxH]
Definition: GlobalTest.h:67
void Fill(long long x)
void beginJob()
Definition: GlobalTest.cc:69
int iEvent
Definition: GenABIO.cc:230
GlobalTest(const edm::ParameterSet &)
Definition: GlobalTest.cc:40
MonitorElement * nrPileupsH_[nMaxH]
Definition: GlobalTest.h:63
MonitorElement * nrTracksH_[nMaxH]
Definition: GlobalTest.h:65
edm::EDGetTokenT< CrossingFrame< SimTrack > > cfVertexToken_
Definition: GlobalTest.h:76
DQMStore * dbe_
MonitorElement * nrVerticesH_[nMaxH]
Definition: GlobalTest.h:64
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2490
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:3282
edm::EDGetTokenT< CrossingFrame< PCaloHit > > g4SimHits_EB_Token_
Definition: GlobalTest.h:77
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655