CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTMonPhotonSource.cc
Go to the documentation of this file.
5 
16 
17 
27 
28 using namespace edm;
29 
30 
32 {
33 
34  LogDebug("HLTMonPhotonSource") << "constructor...." ;
35 
36  logFile_.open("HLTMonPhotonSource.log");
37 
38  dbe = NULL;
39  if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
40  dbe = Service < DQMStore > ().operator->();
41  dbe->setVerbose(0);
42  }
43 
44  //std::cout<<"supposed to be message about output file \n\n\n\n";
45 
46  outputFile_ =
47  iConfig.getUntrackedParameter < std::string > ("outputFile", "");
48  if (outputFile_.size() != 0) {
49  edm::LogInfo("HLTMonPhotonSource") << "Photon Trigger Monitoring histograms will be saved to " <<
50 outputFile_ ;
51  // std::cout<< "Photon Trigger Monitoring histograms will be saved to " << outputFile_ ;
52  }
53  else {
54 
55  //std::cout<<"output filename not read in, setting as: PhotonDQM.root\n\n";
56  outputFile_ = "PhotonDQM.root";
57  }
58 
59  bool disable =
60  iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
61  if (disable) {
62 std::cout<<"output disabled?\n\n\n";
63  outputFile_ = "";
64  }
65 
66  dirname_="HLT/HLTMonPhoton/"+iConfig.getParameter<std::string>("@module_label");
67 
68  if (dbe != NULL) {
69  dbe->setCurrentFolder(dirname_);
70  }
71 
72 //std::cout<<"finished setting up directories\n\n";
73 
74  //plotting paramters
75  thePtMin = iConfig.getUntrackedParameter<double>("PtMin",0.);
76  thePtMax = iConfig.getUntrackedParameter<double>("PtMax",1000.);
77  theNbins = iConfig.getUntrackedParameter<unsigned int>("Nbins",40);
78 
79  //info for each filter-step
80  reqNum = iConfig.getParameter<unsigned int>("reqNum");
81  std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
82 
83  for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++){
84  theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
85  theHLTOutputTypes.push_back(filterconf->getParameter<unsigned int>("theHLTOutputTypes"));
86  std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
87  assert(bounds.size() == 2);
88  plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
89  isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
90  assert(isoNames.back().size()>0);
91  if (isoNames.back().at(0).label()=="none")
92  plotiso.push_back(false);
93  else{
94  plotiso.push_back(true);
95  }
96  }
97 
98 //std::cout<<"finished setup\n\n";
99 
100 }
101 
102 
104 {
105 
106  // do anything here that needs to be done at desctruction time
107  // (e.g. close files, deallocate resources etc.)
108 
109 }
110 
111 
112 //
113 // member functions
114 //
115 
116 // ------------ method called to for each event ------------
117 void
119 {
120  using namespace edm;
121  using namespace trigger;
122  nev_++;
123 // LogDebug("HLTMonPhotonSource")<< "HLTMonPhotonSource: analyze...." ;
124  edm::LogInfo("HLTMonPhotonSource")<< "HLTMonPhotonSource: analyze...." ;
125 
126 
128  iEvent.getByLabel("hltTriggerSummaryRAW",triggerObj);
129  if(!triggerObj.isValid()) {
130  edm::LogWarning("HLTMonPhotonSource") << "RAW-type HLT results not found, skipping event";
131  return;
132  }
133 
134  maxEt = 0.;
135  eta = 999.;
136  phi = 999.;
137 
138  //testing:
139  sigmaetaeta=0.;
140 
141  for(unsigned int n=0; n < theHLTCollectionLabels.size() ; n++) { //loop over filter modules
142 //std::cout<<"\n\n\n HLT codes:\n\n";
143 //std::cout<<theHLTOutputTypes[n]<<"\t";
144 
145  switch(theHLTOutputTypes[n]){
146  case 82: // non-iso L1
147  fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
148  case 83: // iso L1
149  fillHistos<l1extra::L1EmParticleCollection>(triggerObj,iEvent,n);break;
150  case 91: //photon
151  fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
152  case 92: //electron
153  fillHistos<reco::ElectronCollection>(triggerObj,iEvent,n);break;
154  case 100: // TriggerCluster
155  fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,iEvent,n);break;
156  default: throw(cms::Exception("Release Validation Error")<< "HLT output type not implemented: theHLTOutputTypes[n]" );
157  }
158  }
159 }
160 
161 template <class T> void HLTMonPhotonSource::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent ,unsigned int n){
162 
163  std::vector<edm::Ref<T> > recoecalcands;
164 
165 //std::cout<<"next step should be analyze\n\n";
166 
167 //std::cout<<"filterIndex result: "<<triggerObj->filterIndex(theHLTCollectionLabels[n])<<std::endl;
168 
169  if (!( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if available
170 
171  // std::cout<<theHLTCollectionLabels[n]<<" "<<n<<std::endl;
172 
173  //std::cout<<"analyzing recoecalcands\n\n";
174 
175  // retrieve saved filter objects
176  triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
177  //Danger: special case, L1 non-isolated
178  // needs to be merged with L1 iso
179  if(theHLTOutputTypes[n]==82){
180  std::vector<edm::Ref<T> > isocands;
181  triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),83,isocands);
182  if(isocands.size()>0)
183  for(unsigned int i=0; i < isocands.size(); i++)
184  recoecalcands.push_back(isocands[i]);
185  }
186 
187 
188 
189  //get the parameters of the candidate with highest et
190  if(n == 0 && recoecalcands.size()!=0){
191  for (unsigned int i=0; i<recoecalcands.size(); i++) {
192  if(recoecalcands[i]->et() > maxEt){
193  maxEt = recoecalcands[i]->et();
194  eta = recoecalcands[i]->eta();
195  phi = recoecalcands[i]->phi();
196 
197  if ( theHLTOutputTypes[n]==100){
198  // std::cout<<recoecalcands[i]->superCluster()->seed()->sigmaEtaEta()<<std::endl;
199  }
200  }
201  }
202  }
203 
204 
205  //fill filter objects into histos
206  if (recoecalcands.size()!=0){
207  if(recoecalcands.size() >= reqNum){
208  eventCounter->Fill(n+0.5);
209  ethist[n]->Fill(maxEt);
210  phihist[n]->Fill(phi);
211  etahist[n]->Fill(eta);
212 
213  //std::cout<<"Et, eta, phi: "<<maxEt<<" "<<eta<<" "<<phi<<"\n\n\n";
214 
215  for (unsigned int i=0; i<recoecalcands.size(); i++) {
216  //plot isolation variables before the isolation filter has been applied
217  if(n+1 < theHLTCollectionLabels.size()){ // can't plot beyond last
218  if(plotiso[n+1]){
219  for(unsigned int j = 0 ; j < isoNames[n+1].size() ;j++ ){
221  iEvent.getByLabel(isoNames[n+1].at(j).label(),depMap);
222  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
223  if(mapi!=depMap->end()){ // found candidate in isolation map!
224  histiso[n+1]->Fill(mapi->val);
225  etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
226  phihistiso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
227  ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
228  break; // to avoid multiple filling we only look until we found the candidate once.
229  }
230  }
231  }
232  }
233  }
234  }
235  }
236  }
237 }
238 // ------------ method called once each job just before starting event loop ------------
239 void
241 {
242  nev_ = 0;
243  DQMStore *dbe = 0;
244  dbe = Service < DQMStore > ().operator->();
245 
246  if (dbe) {
247  dbe->setCurrentFolder(dirname_);
248  dbe->rmdir(dirname_);
249  }
250 
251 
252  if (dbe) {
253  dbe->setCurrentFolder(dirname_);
254 
255  std::string histoname;
256  MonitorElement* tmphisto;
257 
258  eventCounter = dbe->book1D("Evts Passing Filters","Evts Passing Filters",5,0,5);
259  eventCounter->setBinLabel(1,"SinglePhotonEtFilter");
260  eventCounter->setBinLabel(2,"SinglePhotonEcalIsolFilter");
261  eventCounter->setBinLabel(3,"SinglePhotonHcalIsolFilter");
262  eventCounter->setBinLabel(4,"SinglePhotonTrackIsolFilter");
263  /*
264  eventCounter->setBinLabel(5,"HLTIsoSinglePhotonEt10EtFilter");
265  eventCounter->setBinLabel(6,"HLTIsoSinglePhotonEt10EcalIsolFilter");
266  eventCounter->setBinLabel(7,"HLTIsoSinglePhotonEt10HcalIsolFilter");
267  eventCounter->setBinLabel(8,"HLTIsoSinglePhotonEt10TrackIsolFilter");
268  eventCounter->setBinLabel(9,"HLTIsoSinglePhotonEt15EtFilter");
269  eventCounter->setBinLabel(10,"HLTIsoSinglePhotonEt15EcalIsolFilter");
270  eventCounter->setBinLabel(11,"HLTIsoSinglePhotonEt15HcalIsolFilter");
271  eventCounter->setBinLabel(12,"HLTIsoSinglePhotonEt15TrackIsolFilter");
272  eventCounter->setBinLabel(13,"HLTIsoSinglePhotonEt20EtFilter");
273  eventCounter->setBinLabel(14,"HLTIsoSinglePhotonEt20EcalIsolFilter");
274  eventCounter->setBinLabel(15,"HLTIsoSinglePhotonEt20HcalIsolFilter");
275  eventCounter->setBinLabel(16,"HLTIsoSinglePhotonEt20TrackIsolFilter");
276  eventCounter->setBinLabel(17,"HLTIsoSinglePhotonEt25EtFilter");
277  eventCounter->setBinLabel(18,"HLTIsoSinglePhotonEt25EcalIsolFilter");
278  eventCounter->setBinLabel(19,"HLTIsoSinglePhotonEt25HcalIsolFilter");
279  eventCounter->setBinLabel(20,"HLTIsoSinglePhotonEt25TrackIsolFilter");
280  eventCounter->setBinLabel(21,"HLTNonIsoSinglePhotonEtFilter");
281  eventCounter->setBinLabel(22,"HLTNonIsoSinglePhotonEcalIsolFilter");
282  eventCounter->setBinLabel(23,"HLTNonIsoSinglePhotonHcalIsolFilter");
283  eventCounter->setBinLabel(24,"HLTNonIsoSinglePhotonTrackIsolFilter");
284  eventCounter->setBinLabel(25,"HLTNonIsoSinglePhotonEt15EtFilter");
285  eventCounter->setBinLabel(26,"HLTNonIsoSinglePhotonEt15EcalIsolFilter");
286  eventCounter->setBinLabel(27,"HLTNonIsoSinglePhotonEt15HcalIsolFilter");
287  eventCounter->setBinLabel(28,"HLTNonIsoSinglePhotonEt15TrackIsolFilter");
288  eventCounter->setBinLabel(29,"HLTNonIsoSinglePhotonEt25EtFilter");
289  eventCounter->setBinLabel(30,"HLTNonIsoSinglePhotonEt25EcalIsolFilter");
290  eventCounter->setBinLabel(31,"HLTNonIsoSinglePhotonEt25HcalIsolFilter");
291  eventCounter->setBinLabel(32,"HLTNonIsoSinglePhotonEt25TrackIsolFilter");
292  */
293 
294 
295  for(unsigned int i = 0; i< theHLTCollectionLabels.size() ; i++){
296  histoname = theHLTCollectionLabels[i].label()+" Et Dist";
297  tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax);
298  ethist.push_back(tmphisto);
299 
300  histoname = theHLTCollectionLabels[i].label()+" Eta Dist";
301  tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7);
302  etahist.push_back(tmphisto);
303 
304  histoname = theHLTCollectionLabels[i].label()+" Phi Dist";
305  tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2);
306  phihist.push_back(tmphisto);
307 
308  if(plotiso[i]){
309  histoname = theHLTCollectionLabels[i].label()+" Isolation Variable";
310  tmphisto = dbe->book1D(histoname.c_str(),histoname.c_str(),theNbins,plotBounds[i].first,plotBounds[i].second);
311  }
312  else{
313  tmphisto = NULL;
314  }
315  histiso.push_back(tmphisto);
316 
317  if(plotiso[i]){
318  histoname = theHLTCollectionLabels[i].label()+" Isolation vs Eta";
319  tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-2.7,2.7,theNbins,plotBounds[i].first,plotBounds[i].second);
320  }
321  else{
322  tmphisto = NULL;
323  }
324  etahistiso.push_back(tmphisto);
325 
326  if(plotiso[i]){
327  histoname = theHLTCollectionLabels[i].label()+" Isolation vs Phi";
328  tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,-3.2,3.2,theNbins,plotBounds[i].first,plotBounds[i].second);
329  }
330  else{
331  tmphisto = NULL;
332  }
333  phihistiso.push_back(tmphisto);
334 
335  if(plotiso[i]){
336  histoname = theHLTCollectionLabels[i].label()+" Isolation vs Et";
337  tmphisto = dbe->book2D(histoname.c_str(),histoname.c_str(),theNbins,thePtMin,thePtMax,theNbins,plotBounds[i].first,plotBounds[i].second);
338  }
339  else{
340  tmphisto = NULL;
341  }
342  ethistiso.push_back(tmphisto);
343  }
344  } // end "if(dbe)"
345 }
346 
347 // ------------ method called once each job just after ending the event loop ------------
348 void
350 
351 
352 // std::cout << "HLTMonPhotonSource: end job...." << std::endl;
353  LogInfo("HLTMonPhotonSource") << "analyzed " << nev_ << " events";
354 
355  if (outputFile_.size() != 0 && dbe)
356  dbe->save(outputFile_);
357 
358  //std::cout<<"outputfile size: " <<outputFile_.size();
359 
360 //don't do this, you'll break root
361 
362 //std::cout<<"saving file\n\n";
363 //dbe->save(outputFile_);
364 
365  return;
366 }
367 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
HLTMonPhotonSource(const edm::ParameterSet &)
#define NULL
Definition: scimark2.h:8
DEFINE_FWK_MODULE(HiMixingModule)
T eta() const
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
int iEvent
Definition: GenABIO.cc:243
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple cout
Definition: gather_cfg.py:121
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
void fillHistos(edm::Handle< trigger::TriggerEventWithRefs > &, const edm::Event &, unsigned int)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
list at
Definition: asciidump.py:428
Definition: DDAxes.h:10