00001
00016 #include "DQMOffline/Trigger/interface/HLTMuonBPAG.h"
00017
00018
00019 #include "DataFormats/Math/interface/deltaR.h"
00020
00021 #include "FWCore/ServiceRegistry/interface/Service.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00025 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00026 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00027 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00028 #include "DataFormats/VertexReco/interface/Vertex.h"
00029 #include "DataFormats/Common/interface/TriggerResults.h"
00030
00031
00032
00033 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00034 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00035
00036 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00037
00038 #include "TPRegexp.h"
00039 #include <iostream>
00040
00041 using namespace std;
00042 using namespace edm;
00043 using namespace reco;
00044 using namespace trigger;
00045 using namespace l1extra;
00046
00047
00048
00049 typedef std::vector< edm::ParameterSet > Parameters;
00050 typedef std::vector<reco::Muon> MuonCollection;
00051
00052
00053
00054
00055
00056
00057
00059 HLTMuonBPAG::HLTMuonBPAG
00060 ( const ParameterSet& pset, string triggerName, vector<string> moduleNames,
00061 MuonSelectionStruct probeSelection,
00062 MuonSelectionStruct inputTagSelection, string customName,
00063 vector<string> validTriggers,
00064 const edm::Run & currentRun,
00065 const edm::EventSetup & currentEventSetup)
00066 : HLTMuonMatchAndPlot(pset, triggerName, moduleNames, probeSelection, customName, validTriggers, currentRun, currentEventSetup),
00067 tagSelection(inputTagSelection)
00068
00069 {
00070
00071
00072 LogTrace ("HLTMuonVal") << "\n\n Inside HLTMuonBPAG Constructor";
00073 LogTrace ("HLTMuonVal") << "The trigger name is " << triggerName
00074 << "and we've done all the other intitializations";
00075
00076 LogTrace ("HLTMuonVal") << "exiting constructor\n\n";
00077
00078 ALLKEY = "ALL";
00079
00080
00081 theMassParameters = pset.getUntrackedParameter< vector<double> >("MassParameters");
00082
00083 }
00084
00085
00086
00087 void HLTMuonBPAG::finish()
00088 {
00089
00090
00091
00092
00093
00094 HLTMuonMatchAndPlot::finish();
00095 }
00096
00097
00098
00099 void HLTMuonBPAG::analyze( const Event & iEvent )
00100 {
00101
00102 LogTrace ("HLTMuonVal") << "Inside of BPAG analyze method!"
00103 << "calling my match and plot module's analyze..."
00104 << endl;
00105
00106
00107
00108
00109
00110
00111
00112
00114
00115
00116
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 LogTrace ("HLTMuonVal") << "BPAG: calling subclass matching routine" << endl;
00130
00131
00132 selectAndMatchMuons(iEvent, recMatches, hltFakeCands);
00133
00134
00135 LogTrace ("HLTMuonVal") << "BPAG: returned from muon ana, now in BAPG module"
00136 << endl
00137 << " muon ana stored size probe muons = "
00138 << recMatches.size()
00139 << " tag muons size = "
00140 << tagRecMatches.size()
00141 << endl;
00142
00143
00144
00145
00146
00147 for (unsigned iTag = 0;
00148 iTag < tagRecMatches.size();
00149 iTag ++) {
00150
00151
00152
00153
00154 bool passedHLT = false;
00155
00156 LogTrace ("HLTMuonVal") << "CRASH: tagRecMatches[iTag].hltCands.size() = "
00157 << theHltCollectionLabels.size() << endl
00158 << "CRASH: theHltCollectionLabels.size() = "
00159 << theHltCollectionLabels.size()
00160 << endl;
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 if ( theHltCollectionLabels.size() <= tagRecMatches[iTag].hltCands.size()) {
00171 for ( size_t jCollLabel = 0; jCollLabel < theHltCollectionLabels.size(); jCollLabel++ ) {
00172 if ( tagRecMatches[iTag].hltCands[jCollLabel].pt() > 0 ) {
00173 passedHLT = true;
00174 }
00175 }
00176 }
00177
00178 LogTrace ("HLTMuonVal") << "===BPAG=== Did Tag # " << iTag << " pass the trigger? "
00179 << ((passedHLT) ? "YES" : "NO") << endl
00180 << " if no, then we will skip it as a tag..." << endl;
00181
00182 if (!passedHLT) continue;
00183
00184 for ( unsigned int iProbe = 0;
00185 iProbe < recMatches.size();
00186 iProbe++ ) {
00187
00188
00189 LogTrace ("HLTMuonVal") << "Probe = " << iProbe << endl
00190 << " Pt = " << endl
00191 << recMatches[iProbe].recCand->pt()
00192 << " eta = " << endl
00193 << recMatches[iProbe].recCand->eta()
00194 << " phi = " << endl
00195 << recMatches[iProbe].recCand->phi()
00196 << endl << endl
00197 << "Tag = " << iTag
00198 << " Pt = " << endl
00199 << tagRecMatches[iTag].recCand->pt()
00200 << " eta = " << endl
00201 << tagRecMatches[iTag].recCand->eta()
00202 << " phi = " << endl
00203 << tagRecMatches[iTag].recCand->phi()
00204 << endl;
00205
00206 if ( recMatches[iProbe].recCand->charge() * tagRecMatches[iTag].recCand->charge() > 0 ){
00207 LogTrace ("HLTMuonVal") << "Tag and Probe don't have opp charges, skipping to next probe"
00208 << endl;
00209
00210 continue;
00211 }
00212
00213 LorentzVector tagPlusProbe = (recMatches[iProbe].recCand->p4() + tagRecMatches[iTag].recCand->p4());
00214
00215 double invariantMass = tagPlusProbe.mass();
00216 double ptProbe = recMatches[iProbe].recCand->pt();
00217 double etaProbe = recMatches[iProbe].recCand->eta();
00218 double phiProbe = recMatches[iProbe].recCand->phi();
00219
00221
00222
00223
00225
00226 diMuonMassVsPt[ALLKEY]->Fill(ptProbe, invariantMass);
00227 diMuonMassVsEta[ALLKEY]->Fill(etaProbe, invariantMass);
00228 diMuonMassVsPhi[ALLKEY]->Fill(phiProbe, invariantMass);
00229
00230 diMuonMass[ALLKEY]->Fill(invariantMass);
00231
00233
00234
00235
00237
00238
00239 if ( (recMatches[iProbe].l1Cand.pt() > 0) && ((useFullDebugInformation) || (isL1Path)) ) {
00240 TString myLabel = calcHistoSuffix(theL1CollectionLabel);
00241
00242 diMuonMassVsPt[myLabel]->Fill(ptProbe, invariantMass);
00243 diMuonMassVsEta[myLabel]->Fill(etaProbe, invariantMass);
00244 diMuonMassVsPhi[myLabel]->Fill(phiProbe, invariantMass);
00245
00246 diMuonMass[myLabel]->Fill(invariantMass);
00247 }
00248
00250
00251
00252
00254
00255 LogTrace ("HLTMuonVal") << "The size of the HLT collection labels = " << theHltCollectionLabels.size()
00256 << ", and the size of recMatches[" << iProbe << "].hltCands = "
00257 << recMatches[iProbe].hltCands.size()
00258 << endl;
00259
00260 for ( size_t j = 0; j < theHltCollectionLabels.size(); j++ ) {
00261 if ( recMatches[iProbe].hltCands[j].pt() > 0 ) {
00262 TString myLabel = calcHistoSuffix (theHltCollectionLabels[j]);
00263
00264 LogTrace ("HLTMuonVal") << "filling plot ... Looking up the plot label " << myLabel
00265 << endl;
00266
00267
00268
00269
00270 if (diMuonMassVsPt.find(myLabel) != diMuonMassVsPt.end()){
00271 LogTrace ("HLTMuonVal") << "Found a plot corresponding to label = "
00272 << myLabel << endl;
00273
00274 diMuonMassVsPt[myLabel]->Fill(ptProbe, invariantMass);
00275
00276
00277 } else {
00278 LogTrace ("HLTMuonVal") << "Didn't find a plot corresponding to your label" << endl;
00279 }
00280
00281 if (diMuonMass.find(myLabel) != diMuonMass.end())
00282 diMuonMass[myLabel]->Fill(invariantMass);
00283
00284 if (diMuonMassVsEta.find(myLabel) != diMuonMassVsEta.end())
00285 diMuonMassVsEta[myLabel]->Fill(etaProbe, invariantMass);
00286
00287 if (diMuonMassVsPhi.find(myLabel) != diMuonMassVsPhi.end())
00288 diMuonMassVsPhi[myLabel]->Fill(phiProbe, invariantMass);
00289
00290 }
00291 }
00292
00293
00294
00295
00296 }
00297 }
00298
00299 LogTrace ("HLTMuonVal") << "-----End of BPAG plotter analyze method-----" << endl;
00300 }
00301
00302
00303
00304
00305 void HLTMuonBPAG::begin()
00306 {
00307
00308 TString myLabel, newFolder;
00309 vector<TH1F*> h;
00310
00311 LogTrace ("HLTMuonVal") << "Inside begin for BPAG analyzer" << endl;
00312
00313
00314
00315
00316
00317
00318
00319 if ( dbe_ ) {
00320 dbe_->cd();
00321 dbe_->setCurrentFolder("HLT/Muon");
00322
00323
00324
00325
00326 myLabel = theL1CollectionLabel;
00327 myLabel = myLabel(myLabel.Index("L1"),myLabel.Length());
00328 myLabel = myLabel(0,myLabel.Index("Filtered")+8);
00329
00330
00331
00332
00333 newFolder = "HLT/Muon/Distributions/" + theTriggerName + "/" + mySelection.customLabel;
00334
00335
00336
00337 dbe_->setCurrentFolder( newFolder.Data() );
00338
00339 vector<string> binLabels;
00340 binLabels.push_back( theL1CollectionLabel.c_str() );
00341 for ( size_t i = 0; i < theHltCollectionLabels.size(); i++ )
00342 binLabels.push_back( theHltCollectionLabels[i].c_str() );
00343
00344
00345
00346
00347 if (useOldLabels) {
00348 myLabel = theL1CollectionLabel;
00349 myLabel = myLabel(myLabel.Index("L1"),myLabel.Length());
00350 myLabel = myLabel(0,myLabel.Index("Filtered")+8);
00351 } else {
00352 myLabel = "L1Filtered";
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 int nPtBins = ((int) thePtParameters.size()) - 1;
00370 int nMassBins = (theMassParameters.size() > 0) ? ((int)theMassParameters[0]) : 50;
00371 double minMass = (theMassParameters.size() > 1) ? theMassParameters[1] : 0;
00372 double maxMass = (theMassParameters.size() > 2) ? theMassParameters[2] : 6;;
00373
00374 double ptBinLowEdges[100];
00375
00376 unsigned maxPtBin = (thePtParameters.size() > 100) ? thePtParameters.size() : 100;
00377
00378 for (unsigned i = 0; i < maxPtBin; i++)
00379 ptBinLowEdges[i] = thePtParameters[i];
00380
00381 vector<double> evenPtBins;
00382 evenPtBins.push_back(10);
00383 evenPtBins.push_back(0);
00384 evenPtBins.push_back(20);
00385
00386
00387
00388
00389
00390
00391 vector<double> massVsEtaBins;
00392 massVsEtaBins.push_back(theEtaParameters[0]);
00393 massVsEtaBins.push_back(theEtaParameters[1]);
00394 massVsEtaBins.push_back(theEtaParameters[2]);
00395 massVsEtaBins.push_back(nMassBins);
00396 massVsEtaBins.push_back(minMass);
00397 massVsEtaBins.push_back(maxMass);
00398
00399 vector<double> massVsPhiBins;
00400 massVsPhiBins.push_back(thePhiParameters[0]);
00401 massVsPhiBins.push_back(thePhiParameters[1]);
00402 massVsPhiBins.push_back(thePhiParameters[2]);
00403 massVsPhiBins.push_back(nMassBins);
00404 massVsPhiBins.push_back(minMass);
00405 massVsPhiBins.push_back(maxMass);
00406
00407
00408
00409 vector<double> massBins;
00410 massBins.push_back(nMassBins);
00411 massBins.push_back(minMass);
00412 massBins.push_back(maxMass);
00413
00415
00416
00417
00419
00420
00421
00422 diMuonMassVsPt[ALLKEY] = book2DVarBins("diMuonMassVsPt_All", "Mass Vs Probe Pt; Pt; Mass", nPtBins, ptBinLowEdges, nMassBins, minMass, maxMass);
00423 diMuonMassVsEta[ALLKEY] = bookIt("diMuonMassVsEta_All", "Mass Vs Probe Eta; #eta ; Mass", massVsEtaBins);
00424 diMuonMassVsPhi[ALLKEY] = bookIt("diMuonMassVsPhi_All", "Mass Vs Probe Phi", massVsPhiBins);
00425
00426 diMuonMass[ALLKEY] = bookIt("diMuonMass_All", "Mass of Dimuons; Mass", massBins);
00427
00428 probeMuonPt[ALLKEY] = bookIt("probeMuonPt_All", "Probe Muon PT; Probe Pt", evenPtBins);
00429
00430
00431 if (useFullDebugInformation || isL1Path) {
00432 diMuonMassVsPt[myLabel] = book2DVarBins("diMuonMassVsPt_" + myLabel, "Mass Vs Probe Pt; Pt; Mass", nPtBins, ptBinLowEdges, nMassBins, minMass, maxMass);
00433 diMuonMassVsEta[myLabel] = bookIt("diMuonMassVsEta_" + myLabel, "Mass Vs Probe Eta; #eta; Mass " + myLabel, massVsEtaBins);
00434 diMuonMassVsPhi[myLabel] = bookIt("diMuonMassVsPhi_" + myLabel, "Mass Vs Probe Phi; #phi; Mass " + myLabel, massVsPhiBins);
00435
00436 diMuonMass[myLabel] = bookIt("diMuonMass_" + myLabel, "Mass of Dimuons; mass " + myLabel, massBins);
00437 probeMuonPt[myLabel] = bookIt("probeMuonPt_" + myLabel, "Probe Muon PT; Pt" + myLabel, evenPtBins);
00438
00439 }
00440
00441
00443
00444
00445
00447
00448
00449
00450
00451 for ( unsigned int i = 0; i < theHltCollectionLabels.size(); i++ ) {
00452
00453 if (useOldLabels) {
00454 myLabel = theHltCollectionLabels[i];
00455 TString level = ( myLabel.Contains("L2") ) ? "L2" : "L3";
00456 myLabel = myLabel(myLabel.Index(level),myLabel.Length());
00457 myLabel = myLabel(0,myLabel.Index("Filtered")+8);
00458 } else {
00459 TString tempString = theHltCollectionLabels[i];
00460 TString level = ( tempString.Contains("L2") ) ? "L2" : "L3";
00461 myLabel = level + "Filtered";
00462 }
00463
00464
00465
00466 diMuonMassVsPt[myLabel] = book2DVarBins("diMuonMassVsPt_" + myLabel, "Mass Vs Probe Pt; Pt; Mass" + myLabel, nPtBins, ptBinLowEdges, nMassBins, minMass, maxMass);
00467 diMuonMassVsEta[myLabel] = bookIt("diMuonMassVsEta_" + myLabel, "Mass Vs Probe Eta; #eta; Mass " + myLabel, massVsEtaBins);
00468 diMuonMassVsPhi[myLabel] = bookIt("diMuonMassVsPhi_" + myLabel, "Mass Vs Probe Phi; #phi; Mass " + myLabel, massVsPhiBins);
00469
00470 diMuonMass[myLabel] = bookIt("diMuonMass_" + myLabel, "Mass of Dimuons; Mass " + myLabel, massBins);
00471 probeMuonPt[myLabel] = bookIt("probeMuonPt_" + myLabel, "Probe Muon PT; Pt "+ myLabel, evenPtBins);
00472
00473 }
00474
00475 map<TString, MonitorElement*>::const_iterator iPlot;
00476
00477 LogTrace ("HLTMuonVal") << "BPAG::begin dumping some plot names " << endl;
00478 for (iPlot = diMuonMassVsPt.begin();
00479 iPlot != diMuonMassVsPt.end();
00480 iPlot++){
00481
00482 LogTrace("HLTMuonVal") << "BPAG: PLOT Key = " << iPlot->first << endl;
00483 }
00484
00485
00486 }
00487
00488 }
00489
00491
00492
00493
00495
00496 bool HLTMuonBPAG::selectAndMatchMuons(const edm::Event & iEvent,
00497 std::vector<MatchStruct> & argRecMatches,
00498 std::vector< std::vector<HltFakeStruct> > & argHltFakeCands
00499 ) {
00500
00501
00502 argRecMatches.clear();
00503 tagRecMatches.clear();
00504
00505
00506 HLTMuonMatchAndPlot::selectAndMatchMuons(iEvent, argRecMatches, argHltFakeCands, mySelection);
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 string customName = "bpagTag";
00517
00518
00519 string trkCol = "innerTrack";
00520 std::vector<std::string> reqTrigs;
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 HLTMuonMatchAndPlot::selectAndMatchMuons(iEvent, tagRecMatches, tagHltFakeCands, tagSelection);
00532
00533
00534
00535
00536
00537 LogTrace ("HLTMuonVal") << "Printing tags and probes!!!"
00538 << "NTAGS = " << tagRecMatches.size() << endl
00539 << "NPROBES = " << argRecMatches.size() << endl
00540 << endl;
00541
00542
00543
00544 for (unsigned iProbe = 0;
00545 iProbe < argRecMatches.size();
00546 iProbe++) {
00547
00548 LogTrace ("HLTMuonVal") << "Probe # " << iProbe
00549 << " PT = " << argRecMatches[iProbe].recCand->pt()
00550 << " ETA = " << argRecMatches[iProbe].recCand->eta()
00551 << " PHI = " << argRecMatches[iProbe].recCand->phi()
00552 << endl;
00553
00554
00555 }
00556
00557 for (unsigned iTag = 0;
00558 iTag < tagRecMatches.size();
00559 iTag++) {
00560
00561 LogTrace ("HLTMuonVal") << "Tag # " << iTag
00562 << " PT = " << tagRecMatches[iTag].recCand->pt()
00563 << " ETA = " << tagRecMatches[iTag].recCand->eta()
00564 << " PHI = " << tagRecMatches[iTag].recCand->phi()
00565 << endl;
00566
00567
00568 }
00569
00570
00571
00572
00573 return true;
00574
00575 }
00576
00577
00579
00580
00581
00583
00584
00585
00586 MonitorElement* HLTMuonBPAG::book2DVarBins (TString name, TString title, int nBinsX, double * xBinLowEdges, int nBinsY, double yMin, double yMax) {
00587
00588 TH2F *tempHist = new TH2F(name, title, nBinsX, xBinLowEdges, nBinsY, yMin, yMax);
00589 tempHist->Sumw2();
00590 MonitorElement * returnedME = dbe_->book2D(name.Data(), tempHist);
00591 delete tempHist;
00592 return returnedME;
00593
00594 }