CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQMOffline/Trigger/src/HLTMuonMatchAndPlot.cc

Go to the documentation of this file.
00001 
00015 #include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h"
00016 
00017 #include "DataFormats/Math/interface/deltaR.h"
00018 
00019 #include "FWCore/Framework/interface/Run.h"
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 
00022 #include "FWCore/ServiceRegistry/interface/Service.h"
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
00026 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00027 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00028 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00029 #include "DataFormats/VertexReco/interface/Vertex.h"
00030 #include "DataFormats/Common/interface/TriggerResults.h"
00031 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00032 
00033 // For storing calorimeter isolation info in the ntuple
00034 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00035 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00036 
00037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00038 
00039 #include "TPRegexp.h"
00040 #include <iostream>
00041 
00042 using namespace std;
00043 using namespace edm;
00044 using namespace reco;
00045 using namespace trigger;
00046 using namespace l1extra;
00047 
00048 typedef std::vector< edm::ParameterSet > Parameters;
00049 typedef std::vector<reco::Muon> MuonCollection;
00050 
00051 const int numCones     = 3;
00052 const int numMinPtCuts = 1;
00053 double coneSizes[] = { 0.20, 0.24, 0.30 };
00054 double minPtCuts[] = { 0. };
00055 
00056 const int HLTMuonMatchAndPlot::POS_CHARGE;
00057 const int HLTMuonMatchAndPlot::NEG_CHARGE;
00058 
00060 HLTMuonMatchAndPlot::HLTMuonMatchAndPlot
00061 ( const ParameterSet& pset, string triggerName, vector<string> moduleNames,
00062   MuonSelectionStruct inputSelection, string customName,
00063   vector<string> validTriggers, edm::Run const& currentRun, edm::EventSetup const& currentEventSetup )
00064   :  mySelection(inputSelection), selectedValidTriggers(validTriggers)
00065 {
00066 
00067 
00068   LogTrace ("HLTMuonVal") << "\n\n Inside HLTMuonMatchAndPlot Constructor";
00069   LogTrace ("HLTMuonVal") << "The trigger name is " << triggerName
00070                           << " and the module names are listed";
00071 
00072   for (vector<string>::iterator iMod = moduleNames.begin();
00073        iMod != moduleNames.end(); iMod++){
00074     LogTrace ("HLTMuonVal") << (*iMod);
00075   }
00076     
00077   
00078   theHltProcessName  = pset.getParameter<string>("HltProcessName");
00079 
00080   LogTrace ("HLTMuonVal") << "HLTMuonMatchAndPlot: Constructor: Initializing HLTConfigProvider with HLT process name: " << theHltProcessName << endl;
00081 
00082   
00083   HLTConfigProvider hltConfig;
00084   bool hltConfigChanged;
00085   bool hltConfigInitSuccess = hltConfig.init(currentRun, currentEventSetup, theHltProcessName, hltConfigChanged);
00086 
00087   theNumberOfObjects = ( TString(triggerName).Contains("Double") ) ? 2 : 1;
00088   theTriggerName     = triggerName;
00089     
00090   useAod         = true;
00091 
00092   requireL1SeedForHLTPaths = pset.getUntrackedParameter<bool>("RequireRecoToMatchL1Seed", false);
00093 
00094   matchType = pset.getUntrackedParameter<string>("matchType");
00095 
00096   // JMS Added a method to make standalone histogram output
00097   createStandAloneHistos = pset.getUntrackedParameter<bool>("createStandAloneHistos");
00098   histoFileName = pset.getUntrackedParameter<string> ("histoFileName");
00099 
00100   theHltCollectionLabels.clear();
00101 
00102   // make these config file inputs eventually
00103   useOldLabels = false;
00104   useFullDebugInformation = false;
00105 
00106   if (useFullDebugInformation) {
00107     // if you're filling all plots
00108     // then you'll have (All, L1, HLT)
00109     HLT_PLOT_OFFSET = 2;
00110   } else {
00111     // if you're only filling
00112     // the plots for one trigger
00113     // then have (All, HLT)
00114     HLT_PLOT_OFFSET = 1;
00115   }
00116 
00117   isL1Path = false;
00118   isL2Path = false;
00119   isL3Path = true;
00120 
00121   if (TString(triggerName).Contains("L1")) {
00122     isL1Path = true;
00123     isL3Path = false;
00124   }
00125 
00126   if (TString(triggerName).Contains("L2")) {
00127     isL2Path = true;
00128     isL3Path = false;
00129   }
00130   if (TString(triggerName).Contains("L3")) {
00131     isL3Path = true;
00132     isL3Path = false;
00133   }
00134 
00135     
00136   
00137   LogTrace ("HLTMuonVal") << "Parsing Module names... useOldLabels? "
00138                           << useOldLabels
00139                           << ",  useFullDebugInformation? "
00140                           << useFullDebugInformation
00141                           << endl;
00142                           
00143   
00144   TPRegexp l1Regexp("L1.*Filtered");
00145   TPRegexp l2Regexp("L2.*Filtered");
00146 
00147   string theLastHltFilter = "";
00148 
00149   theL1SeedModuleForHLTPath = "" ;
00150 
00151 
00152   for ( size_t i = 0; i < moduleNames.size(); i++ ) {
00153     string module = moduleNames[i];
00154 
00155     if (hltConfigInitSuccess) {
00156       LogTrace ("HLTMuonVal") << "Considering Module named    "
00157                               << module
00158                               << "      which has type =    "
00159                               << hltConfig.moduleType(module);
00160 
00161       if ( hltConfig.moduleType(module) == "HLTLevel1GTSeed" ) {
00162         LogTrace ("HLTMuonVal") << "Module = " << module
00163                                 <<  " is a HLTLevel1GTSeed!!"
00164                                 << endl
00165                                 << "Storing it as L1Seed"
00166                                 << endl;
00167         theL1SeedModuleForHLTPath = module;
00168       }
00169     }
00170 
00171     
00172     if ( TString(module).Contains(l1Regexp) ) {
00173       // this will be used to look up info
00174       // in the AOD information
00175       theL1CollectionLabel = module;
00176       LogTrace ("HLTMuonVal") << "... module is L1 collection";
00177 
00178       
00179     } else if ( TString(module).Contains(l2Regexp) ) {
00180       // this is a l2 module, only consider it if the trigger
00181       // is an L2 passthrough or if we want to use debug trigger info
00182 
00183       if (useFullDebugInformation) {
00184         theHltCollectionLabels.push_back(module);
00185         LogTrace ("HLTMuonVal") << "... module added to HLT collection list";
00186       } else if (isL2Path) {
00187         LogTrace ("HLTMuonVal") << "... module saved for later";
00188         theLastHltFilter = module;
00189       }
00190 
00191       
00192     } else if (TString(module).Contains("Filtered") ) {
00193       // must be L3 filtered here
00194       // potential to have Pre vs Iso filtered
00195       // In AOD, I think there is only information
00196       // for the *final* filter
00197 
00198       if (useFullDebugInformation) {
00199         LogTrace ("HLTMuonVal") << "... module added to HLT collection list" << endl;
00200         theHltCollectionLabels.push_back(module);        
00201       } else if (isL3Path) {
00202         LogTrace ("HLTMuonVal") << "... module saved for later" << endl;
00203         theLastHltFilter = module;
00204       }      
00205 
00206     }
00207   }
00208 
00209   if (!useFullDebugInformation && theLastHltFilter != "" ) {
00210     
00211     LogTrace("HLTMuonVal") << "\nAfter running over labels, we find hlt label coll size = "
00212                            << theHltCollectionLabels.size() << endl
00213                            << "\n\nwill only use the final hlt label = "
00214                            << theLastHltFilter << endl;
00215 
00216     theHltCollectionLabels.push_back (theLastHltFilter);
00217   }
00218   
00219 
00220   numHltLabels   = theHltCollectionLabels.size();
00221   isIsolatedPath = ( numHltLabels == 4 ) ? true : false;
00222 
00223   // -- Right now the new way is to hard-code it
00224   // -- this uses the most generic kind of muon
00225   // -- selectors will handle other cuts
00226   //theRecoLabel = "muons";
00227 
00228   RecoMuonInputTag =  pset.getParameter<edm::InputTag>("RecoMuonInputTag");  
00229   BeamSpotInputTag = pset.getParameter<edm::InputTag>("BeamSpotInputTag");
00230   HltRawInputTag  = pset.getParameter<edm::InputTag>("HltRawInputTag");
00231   HltAodInputTag = pset.getParameter<edm::InputTag>("HltAodInputTag");
00232   
00233   TriggerResultLabel = pset.getParameter<edm::InputTag>("TriggerResultLabel");  
00234   
00235   //useMuonFromGenerator = false; // = ( theGenLabel  == "" ) ? false : true;
00236   useMuonFromReco      = true; // = ( theRecoLabel == "" ) ? false : true;
00237 
00238   //define default parameters so that you don't crash
00239 
00240   vector <double> etaDefault;
00241   etaDefault.push_back(15);
00242   etaDefault.push_back(-2.1);
00243   etaDefault.push_back(2.1);
00244 
00245   theEtaParameters   = pset.getUntrackedParameter< vector<double> >("EtaParameters", etaDefault);
00246   
00247   vector <double> phiDefault;
00248   phiDefault.push_back(15);
00249   phiDefault.push_back(-3.2);
00250   phiDefault.push_back(3.2);
00251 
00252   thePhiParameters   = pset.getUntrackedParameter< vector<double> >("PhiParameters", phiDefault);
00253 
00254   // leave this vector of size 0
00255   vector <double> ptDefault;
00256 
00257   //  pt parameters are a different story
00258   //  it's a vector of doubles but it unpacked
00259   //  as bin low edges
00260   thePtParameters    = pset.getUntrackedParameter< vector<double> >("PtParameters", ptDefault);
00261 
00262   
00263   vector <double> resDefault;
00264   resDefault.push_back(10);
00265   resDefault.push_back(-0.1);
00266   resDefault.push_back(0.1);
00267   theResParameters = pset.getUntrackedParameter < vector<double> >("ResParameters", resDefault);  
00268 
00269   vector <double> d0Default;
00270   d0Default.push_back(10);
00271   d0Default.push_back(-2.0);
00272   d0Default.push_back(2.0);
00273 
00274   theD0Parameters = pset.getUntrackedParameter <vector<double> > ("D0Parameters", d0Default);
00275 
00276   vector <double> z0Default;
00277   z0Default.push_back(10);
00278   z0Default.push_back(-25);
00279   z0Default.push_back(25);
00280 
00281   theZ0Parameters = pset.getUntrackedParameter < vector<double> > ("Z0Parameters", z0Default);
00282 
00283   
00284   
00285   int numPtBinEdge = 0;
00286   if ( thePtParameters.size() > 100) {
00287     LogInfo ("HLTMuonVal") << "Warning!!! You specified a list of pt bin edges that is > 100 bins"
00288                            << "This is too many bins!! Truncating the list!!! " << endl;
00289     numPtBinEdge = 100;
00290   } else if (thePtParameters.size() < 1) {
00291 
00292     numPtBinEdge = 5;
00293     numBinsInPtHisto = numPtBinEdge - 1;
00294     ptBins[0] = 0;
00295     ptBins[1] = 20;
00296     ptBins[2] = 50;
00297     ptBins[3] = 100;
00298     ptBins[4] = 150;
00299     
00300   } else {
00301     numPtBinEdge = thePtParameters.size();
00302     // the number of bins in the histo is one
00303     // less than the number of edges
00304     numBinsInPtHisto = numPtBinEdge - 1;
00305   
00306     for (int iBin = 0; iBin < numPtBinEdge; iBin++){
00307       ptBins[iBin] = (float) thePtParameters[iBin];
00308       //LogTrace ("HLTMuonVal") << the 
00309     }
00310 
00311   }
00312 
00313 
00314   
00315   // Duplicate the pt parameters for some 2D histos
00316 //   for(int i =0; i < 2; i++){
00317 //     for (std::vector<double>::const_iterator iNum = theMaxPtParameters.begin();
00318 //          iNum != theMaxPtParameters.end();
00319 //          iNum++){
00320       
00321 //       // if this is the # of bins, then
00322 //       // halve the number of bins.
00323 //       if (iNum == theMaxPtParameters.begin()){
00324 //         theMaxPtParameters2d.push_back(floor((*iNum)/2));
00325 //       } else {
00326 //         theMaxPtParameters2d.push_back((*iNum));
00327 //       }
00328 //     }
00329 //   }
00330 
00331 //   // Duplicate the eta parameters for some 2D histos
00332 //   for(int i =0; i < 2; i++){
00333 //     for (std::vector<double>::const_iterator iNum = theEtaParameters.begin();
00334 //          iNum != theEtaParameters.end();
00335 //          iNum++){
00336 //       // if this is the nBins param, halve it
00337 //       if (iNum ==  theEtaParameters.begin()){
00338 //         theEtaParameters2d.push_back(floor((*iNum)/2));      
00339 //       } else {
00340 //         theEtaParameters2d.push_back(*iNum);                   
00341 //       }
00342       
00343 //       // also fill the eta/phi plot parameters
00344 //       // but don't worry about doubleing bins
00345 //       // if (i < 1){
00346 //       //         if (iNum ==  theEtaParameters.begin()){
00347 //       //           thePhiEtaParameters2d.push_back(floor((*iNum)/2));      
00348 //       //         } else {
00349 //       //           thePhiEtaParameters2d.push_back(*iNum);      
00350       
00351 //       //         } 
00352       
00353 //       //       }
00354 //     }
00355 //   }
00356 
00357 //   // Duplicate the pt parameters for some 2D histos
00358 //   for(int i =0; i < 2; i++){
00359 //     for (std::vector<double>::const_iterator iNum = thePhiParameters.begin();
00360 //          iNum != thePhiParameters.end();
00361 //          iNum++){
00362 
00363 //       if (iNum == thePhiParameters.begin()) {
00364 //         thePhiParameters2d.push_back(floor((*iNum)/2));
00365 //       } else {
00366 //         thePhiParameters2d.push_back(*iNum);
00367 //       }
00368 
00369 //       //       if (i < 1){
00370       
00371 //       //         // if (iNum ==  theEtaParameters.begin()){
00372 //       //         //           thePhiEtaParameters2d.push_back(floor((*iNum)/2));      
00373 //       //         //         } else {
00374 //       //         //           thePhiEtaParameters2d.push_back(*iNum);      
00375       
00376 //       //         //         } 
00377       
00378 //       //       }
00379 //     }
00380 //   }
00381 
00382 
00383 
00384   //=======================================
00385 
00386 
00387 
00388   theL1DrCut     = pset.getUntrackedParameter<double>("L1DrCut", 0.4);
00389   theL2DrCut     = pset.getUntrackedParameter<double>("L2DrCut", 0.1);
00390   theL3DrCut     = pset.getUntrackedParameter<double>("L3DrCut", 0.05);
00391 
00392   
00393   //==========================================
00394   // Hard-coded parameters
00395   // Make modifibly from script later
00396   //==========================================
00397 
00398 
00399   // put in the phi parameters
00400   thePhiEtaParameters2d.push_back(10);
00401   thePhiEtaParameters2d.push_back(-2.2);
00402   thePhiEtaParameters2d.push_back(2.2);
00403 
00404   thePhiEtaParameters2d.push_back(10);
00405   thePhiEtaParameters2d.push_back(-3.15);
00406   thePhiEtaParameters2d.push_back(3.15);
00407   
00408   
00409   // theD0Parameters.push_back(25);
00410   // theD0Parameters.push_back(-50.0);
00411   // theD0Parameters.push_back(50.0);
00412   
00413   //   theZ0Parameters.push_back(25);
00414   //   theZ0Parameters.push_back(-100);
00415   //   theZ0Parameters.push_back(100);
00416 
00417   theChargeParameters.push_back(3);
00418   theChargeParameters.push_back(-1.5);
00419   theChargeParameters.push_back(1.5);
00420 
00421   theDRParameters.push_back(10);
00422   theDRParameters.push_back(0.0);
00423   theDRParameters.push_back(theL2DrCut);
00424 
00425   theChargeFlipParameters.push_back(2);
00426   theChargeFlipParameters.push_back(-1.0);
00427   theChargeFlipParameters.push_back(1.0);
00428   theChargeFlipParameters.push_back(2);
00429   theChargeFlipParameters.push_back(-1.0);
00430   theChargeFlipParameters.push_back(1.0);
00431 
00432   theIsolationParameters.push_back(10);
00433   theIsolationParameters.push_back(0.0);
00434   theIsolationParameters.push_back(1.0);
00435 
00436   thePhiParameters0Pi.push_back(10);
00437   thePhiParameters0Pi.push_back(0);
00438   thePhiParameters0Pi.push_back(3.2);
00439 
00440   // theDeltaPhiVsPhiParameters.push_back(50);
00441   //   theDeltaPhiVsPhiParameters.push_back(-3.15);
00442   //   theDeltaPhiVsPhiParameters.push_back(3.15);
00443   //   theDeltaPhiVsPhiParameters.push_back(50);
00444   //   theDeltaPhiVsPhiParameters.push_back(0);
00445   //   theDeltaPhiVsPhiParameters.push_back(3.2);
00446 
00447 //   theDeltaPhiVsZ0Parameters.push_back(theZ0Parameters[0]);
00448 //   theDeltaPhiVsZ0Parameters.push_back(theZ0Parameters[1]);
00449 //   theDeltaPhiVsZ0Parameters.push_back(theZ0Parameters[2]);
00450 //   theDeltaPhiVsZ0Parameters.push_back(50);
00451 //   theDeltaPhiVsZ0Parameters.push_back(0);
00452 //   theDeltaPhiVsZ0Parameters.push_back(3.2);
00453 
00454 //   theDeltaPhiVsD0Parameters.push_back(theD0Parameters[0]);
00455 //   theDeltaPhiVsD0Parameters.push_back(theD0Parameters[1]);
00456 //   theDeltaPhiVsD0Parameters.push_back(theD0Parameters[2]);
00457 //   theDeltaPhiVsD0Parameters.push_back(50);
00458 //   theDeltaPhiVsD0Parameters.push_back(0);
00459 //   theDeltaPhiVsD0Parameters.push_back(3.2);
00460       
00461   
00462 
00463   
00464   dbe_ = 0 ;
00465   if ( pset.getUntrackedParameter<bool>("DQMStore", false) ) {
00466     dbe_ = Service<DQMStore>().operator->();
00467     dbe_->setVerbose(0);
00468   }
00469 
00470   if (!dbe_) {
00471 
00472     LogInfo ("HLTMuonVal") << "===WARNING=== Couldn't find DQMStore..." 
00473                            << "Won't be able to book ME's..."
00474                            << "The rest of the run will probably not be useful..."
00475                            << endl;
00476 
00477   }
00478 
00479   eventNumber = 0;
00480 
00481   LogTrace ("HLTMuonVal") << "exiting constructor\n\n";
00482 
00483 }
00484 
00485 
00486 
00487 void HLTMuonMatchAndPlot::endRun (const edm::Run& r, const edm::EventSetup& c)
00488 {
00489 
00490   LogTrace ("HLTMuonVal") << "\n\nInside HLTMuonMatchAndPlot endRun()";
00491 
00492   // loop over all the histograms we booked, and handle the overflow bins
00493 
00494   // do this at end run, since you want to be sure you did it before you
00495   // saved your ME's.
00496   
00497   vector<MonitorElement*>::iterator iMonitorEl;
00498   
00499   for ( iMonitorEl = booked1DMonitorElements.begin();
00500         iMonitorEl != booked1DMonitorElements.end();
00501         iMonitorEl++ ) {
00502 
00503     moveOverflow((*iMonitorEl));
00504 
00505   }
00506   
00507 
00508 }
00509 
00510 
00511 void HLTMuonMatchAndPlot::finish()
00512 {
00513 
00514   LogTrace ("HLTMuonVal") << "\n\nInside HLTMuonMatchAndPlot finish()" << endl;
00515 
00516   if (createStandAloneHistos && histoFileName != "") {
00517     dbe_->save(histoFileName);
00518   }
00519   
00520 }
00521 
00522 
00523 void HLTMuonMatchAndPlot::analyze( const Event & iEvent )
00524 {
00525 
00526   LogTrace( "HLTMuonVal" ) << "\n\nIn analyze for trigger path " << 
00527     theTriggerName << ", Event:" << eventNumber <<"\n\n\n";
00528 
00529   
00530   // Call the selection method with the default selection
00531   bool validSelection = selectAndMatchMuons (iEvent, recMatches, hltFakeCands, mySelection);
00532   if (validSelection) fillPlots (recMatches, hltFakeCands);
00533 
00534   eventNumber++;
00535   
00536 }// end analyze
00537 
00538 bool HLTMuonMatchAndPlot::selectAndMatchMuons (const Event & iEvent, vector<MatchStruct> & myRecMatches,
00539                                                std::vector< std::vector<HltFakeStruct> > & myHltFakeCands
00540                                                ){
00541 
00542   LogTrace ("HLTMuonVal") << "\n\nInside selectAndMatchMuons, called with no selection argument"
00543                           << endl
00544                           << "Calling function using mySelection"
00545                           << endl;
00546 
00547   return selectAndMatchMuons (iEvent, myRecMatches, myHltFakeCands, mySelection);
00548 
00549 }
00550 
00551 
00552 bool HLTMuonMatchAndPlot::selectAndMatchMuons (const Event & iEvent, vector<MatchStruct> & myRecMatches,
00553                                                std::vector< std::vector<HltFakeStruct> > & myHltFakeCands,
00554                                                MuonSelectionStruct muonSelection){
00555 
00556   // clear the matches from the last event
00557   myRecMatches.clear();
00558 
00559   // a fake hlt cand is an hlt object not matched to a
00560   // reco object
00561   //  std::vector< std::vector<HltFakeStruct> > myHltFakeCands(numHltLabels);
00562 
00563   myHltFakeCands.clear();
00564   for (unsigned iLabel = 0; iLabel < numHltLabels; iLabel++){
00565 
00566     std::vector<HltFakeStruct> tempFake;
00567     
00568     myHltFakeCands.push_back(tempFake);
00569     
00570   }
00571 
00572   
00573 
00574   // Update event numbers
00575   // meNumberOfEvents->Fill(eventNumber);
00576 
00577 
00578   //------------------------------------------
00579   //    Trigger Requirement
00580   //    
00581   //------------------------------------------
00582 
00583   LogTrace("HLTMuonVal") << "Checking trigger result for "
00584                          << "trigger information stored in the following block "
00585                          << TriggerResultLabel;
00586 
00587   bool passedRequiredTrigger = applyTriggerSelection ( muonSelection, iEvent);
00588 
00589   if (!passedRequiredTrigger) {
00590     LogTrace ("HLTMuonVal") << "You didn't pass the required trigger"
00591                             << "skipping event"
00592                             << endl;
00593     return false;
00594   }
00595 
00597   // Get all generated and reconstructed muons and create structs to hold  
00598   // matches to trigger candidates 
00599 
00600   double genMuonPt = -1;
00601   double recMuonPt = -1;
00602 
00603 
00604   LogTrace ("HLTMuonVal") << "\n\nStarting to look for gen muons\n\n";
00605                           
00606   
00607   //std::vector<MatchStruct> genMatches;
00608   
00609 
00610   LogTrace ("HLTMuonVal") << "\n\n\n\nDone getting gen, now getting reco\n\n\n";
00611   
00612 
00613   
00614   //std::vector<MatchStruct> highPtMatches;
00615   
00616   //reco::BeamSpot  beamSpot;
00617   foundBeamSpot = false;
00618   
00619   if ( useMuonFromReco ) {
00620     //Handle<reco::TrackCollection> muTracks;
00621     Handle<MuonCollection> muTracks;
00622     iEvent.getByLabel(RecoMuonInputTag, muTracks);    
00623     //reco::TrackCollection::const_iterator muon;
00624     MuonCollection::const_iterator muon;
00625     if  ( muTracks.failedToGet() ) {
00626       LogWarning("HLTMuonVal") << "WARNING: failed to get the RECO Muon collection named " << RecoMuonInputTag
00627                                << "\nYou have tracks to compare to... ignoring RECO muons"
00628                                << " for the rest of this job";
00629       useMuonFromReco = false;
00630     } else {
00631 
00632       LogTrace ("HLTMuonVal") << "Beginning loop over reco muons" << endl;
00633       
00634       for ( muon = muTracks->begin(); muon != muTracks->end(); ++muon ) {
00635         
00636         // this applies cuts that can
00637         // go towards the muon collection
00638 
00639         LogTrace ("HLTMuonVal") << "... Applying selection" << endl;
00640         if ( muonSelection.recoMuonSelector((*muon)) ) {
00641 
00642           // now apply cuts to the tracks.
00643           LogTrace ("HLTMuonVal") << "Passed selection!" << endl;
00644           
00645           if ( applyTrackSelection( muonSelection, (*muon) ) ){
00646 
00647             
00648           
00649             float pt  = muon->pt();
00650             float eta = muon->eta();
00651             MatchStruct newMatchStruct;
00652             newMatchStruct.recCand = &*muon;
00653             myRecMatches.push_back(newMatchStruct);
00654 
00655             LogTrace ("HLTMuonVal") << "\n\nFound a muon track in " << muonSelection.customLabel
00656                                     << " with pt = " << pt
00657                                     << ", eta = " << eta;
00658             // Take out this eta cut, but still check to see if
00659             // it is a new maximum pt
00660             //if ( pt > recMuonPt  && fabs(eta) < theMaxEtaCut)
00661             if (pt > recMuonPt )
00662               recMuonPt = pt;
00663             
00664           }
00665         }
00666       }
00667     }
00668 
00669     // This loop checks to see that we successfully stored our cands
00670     LogTrace ("HLTMuonVal") << "Print out all rec cands for " << muonSelection.customLabel
00671                             << endl;
00672     
00673     for (unsigned iMatch = 0; iMatch < myRecMatches.size(); iMatch++) {
00674       LogTrace ("HLTMuonVal") << "Cand #" << iMatch << "   ";
00675       LogTrace ("HLTMuonVal") << "Pt = " << myRecMatches[iMatch].recCand->pt()
00676                               << endl;
00677     }
00678 
00679     edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00680     iEvent.getByLabel(BeamSpotInputTag,recoBeamSpotHandle);
00681     if (!recoBeamSpotHandle.failedToGet()) {
00682       
00683       beamSpot = *recoBeamSpotHandle;
00684       foundBeamSpot = true;
00685 
00686       LogTrace ("HLTMuonVal") << "\n\n\nSUCESS finding beamspot\n\n\n" << endl;
00687       
00688     } else {
00689       LogWarning ("HLTMuonVal") << "FAILED to get the beamspot for this event";
00690     }
00691     
00692 
00693   } 
00694   
00695   LogTrace("HLTMuonVal") << "\n\n\n\ngenMuonPt: " << genMuonPt << ", "  
00696                          << "recMuonPt: " << recMuonPt
00697                          << "\nCustom name = " << muonSelection.customLabel << endl
00698                          << "\nNow preparing to get trigger objects" 
00699                          << "\n\n\n\n";
00700 
00702   // Get the L1 and HLT trigger collections
00703 
00704   edm::Handle<trigger::TriggerEventWithRefs> rawTriggerEvent;
00705   edm::Handle<trigger::TriggerEvent>         aodTriggerEvent;
00706   vector<TriggerObject>                      l1Particles;
00707   vector<TriggerObject>                      l1RawParticles;
00708   vector<TriggerObject>                      l1Seeds;
00709   //--  HLTParticles [0] is a vector of L2 matches
00710   //--  HLTParticles [1] is a vector of L1 matches
00711 
00712   // HLT particles are just 4 vectors
00713   vector< vector<TriggerObject> >            hltParticles(numHltLabels);
00714 
00715   // HLT cands are references to trigger objects
00716   vector< vector<RecoChargedCandidateRef> >  hltCands(numHltLabels);
00717 
00718   // L1 Cands are references to trigger objects
00719   vector<L1MuonParticleRef> l1Cands;
00720   
00721   InputTag collectionTag;
00722   //size_t   filterIndex;
00723 
00724 
00725   // Try to get the triggerSummaryRAW branch for
00726   // this event. If it's there, great, keep using it.
00727   // but if it isn't there, skip over it silently
00728 
00729 //   LogTrace ("HLTMuonVal") << "Trying to get RAW information\n\n";
00730                           
00731 //   iEvent.getByLabel( HltRawInputTag, rawTriggerEvent );
00732   
00733 //   if ( rawTriggerEvent.isValid() ) { 
00734 //     LogTrace("HLTMuonVal") << "\n\nRAW trigger summary found! "
00735 //                            << "\n\nUsing RAW information";
00736     
00737 //     collectionTag = InputTag( theL1CollectionLabel, "", theHltProcessName );
00738 //     filterIndex   = rawTriggerEvent->filterIndex(collectionTag);
00739 
00740 
00741 //     if ( filterIndex < rawTriggerEvent->size() ) {
00742 //       rawTriggerEvent->getObjects( filterIndex, TriggerL1Mu, l1Cands );
00743 //       LogTrace ("HLTMuonVal") << "Found l1 raw cands for filter = " << filterIndex ;                              
00744         
00745 //     } else {
00746 //       LogTrace("HLTMuonVal") << "No L1 Collection with label " 
00747 //                                 << collectionTag;
00748 //     }
00749     
00750 //     //for ( size_t i = 0; i < l1Cands.size(); i++ ) 
00751 //     //  l1Cands.push_back( l1Cands[i]->p4() );
00752 //     LogTrace ("HLTMuonVal") << "Looking for information from  hltFilters";
00753                             
00754 //     for ( size_t i = 0; i < numHltLabels; i++ ) {
00755 
00756 //       collectionTag = InputTag( theHltCollectionLabels[i], 
00757 //                                 "", theHltProcessName );
00758 //       filterIndex   = rawTriggerEvent->filterIndex(collectionTag);
00759 
00760 //       LogTrace ("HLTMuonVal") << "Looking for candidates for filter "
00761 //                               << theHltCollectionLabels[i]
00762 //                               << ", index = "
00763 //                               << filterIndex;
00764       
00765 //       if ( filterIndex < rawTriggerEvent->size() )
00766 //         rawTriggerEvent->getObjects( filterIndex, TriggerMuon, hltCands[i]);
00767 //       else LogTrace("HLTMuonVal") << "No HLT Collection with label " 
00768 //                                   << collectionTag;
00769 
00770 //       // JMS -- do we ever store this raw info in the MatchStruct?
00771       
00772 
00773 //       // don't copy the hltCands into particles
00774 //       // for ( size_t j = 0; j < hltCands[i].size(); j++ )
00775 //       // hltParticles[i].push_back( hltCands[i][j]->p4() );
00776 
00777 //     } // End loop over theHltCollectionLabels
00778 //   }  else {
00779 //     LogTrace ("HLTMuonVal") << "\n\nCouldn't find any RAW information for this event";
00780                             
00781 //   } // Done processing RAW summary information
00782     
00783 
00784 
00788   // if ( useAod ) {
00789 
00790     LogTrace ("HLTMuonVal") << "\n\n\nLooking for AOD branch named "
00791                             << "hltTriggerSummaryAOD\n\n\n";
00792                             
00793     iEvent.getByLabel(HltAodInputTag, aodTriggerEvent);
00794     if ( !aodTriggerEvent.isValid() ) { 
00795       LogInfo("HLTMuonVal") << "No AOD trigger summary found! Returning..."; 
00796       return false; 
00797     }
00798 
00799     LogTrace ("HLTMuonVal") << "\n\n\nFound a branch! Getting objects\n\n\n";
00800 
00801 
00802     // This gets you all of the stored trigger objects in the AOD block
00803     // could be muons, met, etc
00804     const TriggerObjectCollection objects = aodTriggerEvent->getObjects();
00805 
00806     LogTrace ("HLTMuonVal") << "\n\n\nFound a collection with size "
00807                             << objects.size() << "\n\n\n";
00808 
00809     if (objects.size() < 1) {
00810       LogTrace ("HLTMuonVal")
00811         << "You found the collection, but doesn't have any entries";
00812 
00813       return false;
00814     }
00815 
00816     // The AOD block has many collections, and you need to
00817     // parse which one you want. There are fancy lookup functions
00818     // to give you the number of the collection you want.
00819     // I think this is related to the trigger bits for each
00820     // event not being constant... so kinda like triger
00821     
00822     collectionTag = InputTag( theL1CollectionLabel, "", theHltProcessName );
00823 
00824     LogTrace ("HLTMuonVal") << "Trigger Name is " << theTriggerName;
00825     
00826     LogTrace ("HLTMuonVal") << "\n\n L1Collection tag is "
00827                             << collectionTag << endl
00828                             << " and size filters is "
00829                             << aodTriggerEvent->sizeFilters()
00830                             << "Looking up L1 information in trigSummaryAod";
00831 
00832     // this function call fills l1 particles with your matching trigger objects
00833     getAodTriggerObjectsForModule ( collectionTag, aodTriggerEvent, objects, l1Particles, muonSelection);
00834     
00835     int indexHltColl = 0;
00836     vector<string>::const_iterator iHltColl;
00837     for (iHltColl = theHltCollectionLabels.begin();
00838          iHltColl != theHltCollectionLabels.end();
00839          iHltColl++ ){
00840       collectionTag = InputTag((*iHltColl) , "", 
00841                                theHltProcessName );
00842 
00843       // this function call filles hltParticles with your hlt matches.
00844       getAodTriggerObjectsForModule ( collectionTag, aodTriggerEvent, objects, hltParticles[indexHltColl] , muonSelection);
00845       
00846 
00847       indexHltColl++;
00848     }
00849 
00850 
00851     // more very verbose debug
00852     // trying to restructure code 
00853     LogTrace ("HLTMuonVal") << "At the end of parsing the L2/L3 filters, you have found "
00854                             << "L2 = " <<  ((hltParticles.size() > 0) ? hltParticles[0].size() : 0)
00855                             << "L3 = " <<  ((hltParticles.size() > 1) ? hltParticles[1].size() : 0)
00856                             << endl;
00857 
00859     //
00860     //  Look up the L1 seeds
00861     //
00863     
00864     collectionTag = InputTag( theL1SeedModuleForHLTPath, "", theHltProcessName );
00865 
00866     LogTrace ("HLTMuonVal") << "\n\n L1Seed colelction tag is "
00867                             << collectionTag << endl
00868                             << " and size filters is "
00869                             << aodTriggerEvent->sizeFilters()
00870                             << "Looking up L1 Seed information in trigSummaryAod";
00871 
00872     // this function call fills l1 particles with your matching trigger objects
00873     getAodTriggerObjectsForModule ( collectionTag, aodTriggerEvent, objects, l1Seeds, muonSelection);
00874     
00875     LogTrace ("HLTMuonVal") << "At the end of parsing the L1 filter, you have found "
00876                             <<  l1Particles.size() << " objects: ";
00877   
00878 
00880   // Initialize MatchStructs
00881 
00882   LorentzVector nullLorentzVector( 0., 0., 0., -999. );
00883 
00884   // trigger object id, pt
00885   TriggerObject nullTriggerObject (-9999, -9e10, -20, 0, 0);
00886   
00887   //L1MuonParticleRef nullL1Ref(L1MuonParticle(-1, nullLorentzVector));
00888 
00889 
00890 
00891   for ( size_t i = 0; i < myRecMatches.size(); i++ ) {
00892     myRecMatches[i].l1Cand = nullTriggerObject;
00893     myRecMatches[i].l1Seed = nullTriggerObject;
00894     myRecMatches[i].hltCands. assign( numHltLabels, nullTriggerObject );
00895     //myRecMatches[i].hltTracks.assign( numHltLabels, false );
00896     // new! raw matches too
00897     myRecMatches[i].hltRawCands.assign(numHltLabels, nullLorentzVector);
00898     myRecMatches[i].l1RawCand = nullLorentzVector;
00899   }
00900 
00901 
00902 
00903 
00904   
00906   // Loop through L1 candidates, matching to gen/reco muons 
00907 
00908   numL1Cands = 0;
00909 
00910   
00911   for ( size_t i = 0; i < l1Particles.size(); i++ ) {
00912 
00913     TriggerObject l1Cand = l1Particles[i];
00914     double eta           = l1Cand.eta();
00915     double phi           = l1Cand.phi();
00916     // L1 pt is taken from a lookup table
00917     // double ptLUT      = l1Cand->pt();  
00918 
00919     double maxDeltaR = theL1DrCut;
00920     numL1Cands++;
00921 
00922 
00923     if ( useMuonFromReco ){
00924       int match = findRecMatch( eta, phi, maxDeltaR, myRecMatches );
00925       if ( match != -1 && myRecMatches[match].l1Cand.pt() < 0 ) {
00926         myRecMatches[match].l1Cand = l1Cand;
00927         LogTrace ("HLTMuonVal") << "Found a rec match to L1 particle (aod)  "
00928                                 << " rec pt = " << myRecMatches[match].recCand->pt()
00929                                 << ",  l1 pt  = " << myRecMatches[match].l1Cand.pt(); 
00930       } else {
00931         //hNumOrphansRec->getTH1F()->AddBinContent( 1 );
00932       }
00933     }
00934 
00935   } // End loop over l1Particles
00936 
00937   
00938   //========================================
00939   // Loop over L1 seeds and store matches
00940   //========================================
00941   
00942   for ( size_t i = 0; i < l1Seeds.size(); i++ ) {
00943 
00944     TriggerObject l1Cand = l1Seeds[i];
00945     double eta           = l1Cand.eta();
00946     double phi           = l1Cand.phi();
00947     // L1 pt is taken from a lookup table
00948     // double ptLUT      = l1Cand->pt();  
00949 
00950     double maxDeltaR = theL1DrCut;
00951     //numL1Cands++;
00952 
00953 
00954     if ( useMuonFromReco ){
00955       int match = findRecMatch( eta, phi, maxDeltaR, myRecMatches );
00956       if ( match != -1 && myRecMatches[match].l1Seed.pt() < 0 ) {
00957         myRecMatches[match].l1Seed = l1Cand;
00958         LogTrace ("HLTMuonVal") << "Found a rec match to L1 particle (aod)  "
00959                                 << " rec pt = " << myRecMatches[match].recCand->pt()
00960                                 << ",  l1 pt  = " << myRecMatches[match].l1Seed.pt(); 
00961       } else {
00962         //hNumOrphansRec->getTH1F()->AddBinContent( 1 );
00963       }
00964     }
00965 
00966   } // End loop over l1Seeds
00967 
00968   
00969 
00971   //   Loop over the L1 Candidates (RAW information)
00972   //   and look for matches
00974   
00975   for ( size_t i = 0; i < l1Cands.size(); i++ ) {
00976 
00977     LorentzVector l1Cand = l1Cands[i]->p4();
00978     
00979     double eta           = l1Cand.eta();
00980     double phi           = l1Cand.phi();
00981     // L1 pt is taken from a lookup table
00982     // double ptLUT      = l1Cand.pt();  
00983 
00984     double maxDeltaR = theL1DrCut;
00985     //numL1Cands++;
00986 
00987 
00988     if ( useMuonFromReco ){
00989       int match = findRecMatch( eta, phi, maxDeltaR, myRecMatches );
00990       if ( match != -1 && myRecMatches[match].l1RawCand.energy() < 0 ) {
00991         myRecMatches[match].l1RawCand = l1Cand;
00992         LogTrace ("HLTMuonVal") << "Found an L1 match to a RAW object";
00993       } else {
00994         //hNumOrphansRec->getTH1F()->AddBinContent( 1 );
00995       }
00996     }
00997 
00998   } // End loop over L1 Candidates (RAW)
00999 
01000 
01001   
01002   LogTrace("HLTMuonVal") << "Number of L1 Cands: " << numL1Cands;
01003 
01005   // Loop through HLT candidates, matching to gen/reco muons
01006 
01007   vector<unsigned int> numHltCands( numHltLabels, 0) ;
01008 
01009   LogTrace ("HLTMuonVal") << "Looking for HLT matches for numHltLabels = "
01010                           << numHltLabels;
01011   
01012   for ( size_t i = 0; i < numHltLabels; i++ ) { 
01013 
01014     int triggerLevel      = ( i < ( numHltLabels / 2 ) ) ? 2 : 3;
01015     double maxDeltaR      = ( triggerLevel == 2 ) ? theL2DrCut : theL3DrCut;
01016 
01017     LogTrace ("HLTMuonVal") << "Looking at 4-vectors  for " << theHltCollectionLabels[i];
01018     
01019     for ( size_t candNum = 0; candNum < hltParticles[i].size(); candNum++ ) {
01020 
01021       TriggerObject hltCand = hltParticles[i][candNum];
01022       double eta            = hltCand.eta();
01023       double phi            = hltCand.phi();
01024 
01025       numHltCands[i]++;
01026 
01027 
01028       if ( useMuonFromReco ){
01029 
01030         HltFakeStruct tempFakeCand; 
01031         tempFakeCand.myHltCand  = hltCand;
01032 
01033         int match  = findRecMatch( eta, phi, maxDeltaR, myRecMatches );
01034 
01035         // if match doesn't return error (-1)
01036         // and if this candidate spot isn't filled
01037         if ( match != -1 && myRecMatches[match].hltCands[i].pt() < 0 ) {
01038           myRecMatches[match].hltCands[i] = hltCand;
01039 
01040           LogTrace ("HLTMuonVal") << "Found a HLT cand match!   "
01041                                   << " rec pt = " << myRecMatches[match].recCand->pt()
01042                                   << ",   hlt pt = " << myRecMatches[match].hltCands[i].pt();
01043 
01044           // since this matched, it's not a fake, so
01045           // record it as "not a fake"
01046           tempFakeCand.isAFake = false;
01047 
01048           
01049           // if match *did* return -1, then this is a fake  hlt candidate
01050           // it is fake because it isn't matched to a reco muon
01051           // 2009-03-24 oops, found a bug here, used to be != -1
01052           // fixed 
01053         } else if (match == -1){
01054           tempFakeCand.isAFake = true;
01055           //hNumOrphansRec->getTH1F()->AddBinContent( i + 2 );
01056         }
01057 
01058         // add this cand 
01059         myHltFakeCands[i].push_back(tempFakeCand);
01060         LogTrace ("HLTMuonVal") << "\n\nWas this a fake hlt cand? "
01061                               << tempFakeCand.isAFake;
01062 
01063       }
01064 
01065                               
01066       
01067       LogTrace("HLTMuonVal") << "Number of HLT Cands: " << numHltCands[i];
01068 
01069     } // End loop over HLT particles
01070 
01071     
01072     LogTrace ("HLTMuonVal") << "Looking at RAW Candidates for "
01073                             << theHltCollectionLabels[i];
01074 
01075     
01076     for ( size_t candNum = 0; candNum < hltCands[i].size(); candNum++ ) {
01077 
01078       LorentzVector hltCand = hltCands[i][candNum]->p4();
01079       double eta            = hltCand.eta();
01080       double phi            = hltCand.phi();
01081 
01082       numHltCands[i]++;
01083 
01084 
01085       if ( useMuonFromReco ){
01086 
01087         //HltFakeStruct tempFakeCand; 
01088         //tempFakeCand.myHltCand  = hltCand;
01089 
01090         int match  = findRecMatch( eta, phi, maxDeltaR, myRecMatches );
01091 
01092         // if match doesn't return error (-1)
01093         // and if this candidate spot isn't filled
01094         if ( match != -1 && myRecMatches[match].hltCands[i].pt() < 0 ) {
01095           myRecMatches[match].hltRawCands[i] = hltCand;
01096           LogTrace ("HLTMuonVal") << "Found a RAW hlt match to reco";
01097         }
01098 
01099         //else if (match == -1){
01100           //tempFakeCand.isAFake = true;
01101           //hNumOrphansRec->getTH1F()->AddBinContent( i + 2 );
01102           //}
01103 
01104         // add this cand 
01105         //myHltFakeCands[i].push_back(tempFakeCand);
01106         //LogTrace ("HLTMuonVal") << "\n\nWas this a fake hlt cand? "
01107         //                      << tempFakeCand.isAFake;
01108 
01109       }
01110 
01111                               
01112       
01113       //LogTrace("HLTMuonVal") << "Number of HLT Cands: " << numHltCands[i];
01114 
01115     } // End loop over HLT RAW information
01116 
01117 
01118   } // End loop over HLT labels
01119 
01120 
01121   // if you reach this point, then the code was
01122   // successful
01123 
01124   return true;
01125   
01126 }// end select and match muons
01127 
01128 
01129 void HLTMuonMatchAndPlot::fillPlots (vector<MatchStruct> & myRecMatches,
01130                                      std::vector< std::vector<HltFakeStruct> > & myHltFakeCands) {
01131 
01132 
01133   if (!dbe_) {
01134 
01135     LogTrace ("HLTMuonVal")
01136       << "===Warning=== You've tried to call fill plots, "
01137       << "but no DQMStore object exists... refusing to fill plots"
01138       << endl;
01139 
01140     return;
01141 
01142   }
01143 
01144   int numRecMatches = myRecMatches.size();
01145 
01146   
01147 
01148   //double recMuonPt = -1;
01149   
01150   //=======================
01151   // DoubleMu Triggers
01152   // ----------------------
01153   // If you're using a double mu trigger
01154   // Check to see if you found at least two reco muons
01155   // If you haven't, then skip this event!
01156   //========================
01157 
01158   if ((theNumberOfObjects == 2) && (myRecMatches.size() < 2)) return;
01159   
01161   // Fill histograms
01162   
01164   //
01165   //               RECO Matching
01166   //
01168 
01169   double maxMatchPtRec = -10.0;
01170   //std::vector <double> allRecPts;
01171   //std::vector <bool> matchedToHLT;
01172   
01173   // Look at each rec & hlt cand
01174 
01175   for ( size_t i = 0; i < myRecMatches.size(); i++ ) {
01176 
01177     LogTrace("HLTMuonVal") << "Reco Candidate loop:"
01178                            << "looking at cand " << i
01179                            << " out of " << myRecMatches.size()
01180                            << endl;
01181 
01182 
01183     if ((isL3Path || isL2Path) && requireL1SeedForHLTPaths) {
01184 
01185       LogTrace ("HLTMuonVal") << "Checking to see if your RECO muon matched to an L1 seed"
01186                               << endl;
01187 
01188       if (myRecMatches[i].l1Seed.pt() < 0) {
01189         LogTrace ("HLTMuonVal") << "No match to L1 seed, skipping this RECO muon" << endl;
01190         continue;
01191       }
01192     }
01193 
01194     
01195 
01196     double pt  = myRecMatches[i].recCand->pt();
01197     double eta = myRecMatches[i].recCand->eta();
01198     double phi = myRecMatches[i].recCand->phi();
01199     int recPdgId = myRecMatches[i].recCand->pdgId();
01200 
01201     LogTrace ("HLTMuonVal") << "trying to get a global track for this muon" << endl;
01202 
01203     // old way - breaks if no global track
01204     //TrackRef theMuoGlobalTrack = myRecMatches[i].recCand->globalTrack();
01205 
01206     TrackRef theMuonTrack = getCandTrackRef (mySelection, (*myRecMatches[i].recCand));
01207     
01208     double d0 = -9e20;
01209     double z0 = -9e20;
01210     int charge = -99999;
01211     int plottedCharge = -99999;
01212 
01213     double d0beam = -9e20;
01214     double z0beam = -9e20;
01215     
01216     if (theMuonTrack.isNonnull() ) {
01217       d0 = theMuonTrack->d0();
01218       z0 = theMuonTrack->dz();
01219       // comment:
01220       // does the charge function return the
01221       // same value as the abs(pdgId) ?    
01222       charge = theMuonTrack->charge(); 
01223       plottedCharge = getCharge (recPdgId);
01224       
01225     
01226       if (foundBeamSpot) {
01227         d0beam = theMuonTrack->dxy(beamSpot.position());
01228         z0beam = theMuonTrack->dz(beamSpot.position());
01229         
01230         hBeamSpotZ0Rec[0]->Fill(beamSpot.z0());
01231       }
01232 
01233 
01234     } else {
01235       LogTrace ("HLTMuonVal") << "... oops! that wasn't a global muon" << endl;
01236     }
01237     
01238     
01239     // For now, take out the cuts on the pt/eta,
01240     // We'll get the total efficiency and worry about
01241     // the hlt matching later.    
01242     //    if ( pt > theMinPtCut &&  fabs(eta) < theMaxEtaCut ) {
01243     
01244     //hNumObjects->getTH1()->AddBinContent(2);
01245 
01246     // fill the "all" histograms for basic muon
01247     // parameters
01248     hPassEtaRec[0]->Fill(eta);
01249     hPassPhiRec[0]->Fill(phi);
01250     hPassPtRec[0]->Fill(pt);
01251     hPhiVsEtaRec[0]->Fill(eta,phi);
01252     hPassD0Rec[0]->Fill(d0);
01253     hPassD0BeamRec[0]->Fill(d0beam);
01254     hPassZ0Rec[0]->Fill(z0);
01255     hPassZ0BeamRec[0]->Fill(z0beam);
01256     hPassCharge[0]->Fill(charge);
01257     
01258     MuonIsolation thisIso = myRecMatches[i].recCand->isolationR03();
01259     double emEnergy = thisIso.emEt;
01260     double hadEnergy = thisIso.hadEt;
01261     double myMuonIso = (emEnergy + hadEnergy) / pt;
01262 
01263     hIsolationRec[0]->Fill(myMuonIso);
01264     
01265     if (numRecMatches == 1) {
01266       hPassPtRecExactlyOne[0]->Fill(pt);
01267     }
01268     
01269 
01270     // if you found an L1 match, fill this histo
01271     // check for L1 match using pt, not energy
01272     if ( (myRecMatches[i].l1Cand.pt() > 0) && ((useFullDebugInformation) || (isL1Path)) ) {
01273       hPassEtaRec[1]->Fill(eta);
01274       hPassPhiRec[1]->Fill(phi);
01275       hPassPtRec[1]->Fill(pt);
01276       hPhiVsEtaRec[1]->Fill(eta,phi);
01277       hPassD0Rec[1]->Fill(d0);
01278       hPassD0BeamRec[1]->Fill(d0beam);
01279       hPassZ0Rec[1]->Fill(z0);
01280       hPassZ0BeamRec[1]->Fill(z0beam);
01281       hPassCharge[1]->Fill(charge);
01282       hIsolationRec[1]->Fill(myMuonIso);
01283 
01284       double l1eta = myRecMatches[i].l1Cand.eta();
01285       double l1phi = myRecMatches[i].l1Cand.phi();
01286       double l1pt  = myRecMatches[i].l1Cand.energy();
01287 
01288       // Get the charges in terms of charge constants
01289       // this reduces bins in histogram.
01290       int l1plottedCharge = getCharge (myRecMatches[i].l1Cand.id());
01291       LogTrace ("HLTMuonVal") << "The pdg id is (L1)   "
01292                               << myRecMatches[i].l1Cand.id()
01293                               << "  and the L1 plotted charge is "
01294                               << l1plottedCharge;
01295       
01296       
01297       double deltaR = reco::deltaR (l1eta, l1phi, eta, phi);
01298 
01299       double deltaPhi = reco::deltaPhi (l1phi, phi);
01300       
01301       // These are matched histos
01302       // so they have no "all" histos
01303       //
01304       
01305       hDeltaRMatched[0]->Fill(deltaR);
01306       hPassMatchPtRec[0]->Fill(pt);
01307       //hPtMatchVsPtRec[0]->Fill(l1pt, pt);
01308       //hEtaMatchVsEtaRec[0]->Fill(l1eta, eta);
01309       //hPhiMatchVsPhiRec[0]->Fill(l1phi, phi);
01310       hMatchedDeltaPhi[0]->Fill(deltaPhi);
01311       //hDeltaPhiVsPhi[0]->Fill(phi, deltaPhi);
01312       //hDeltaPhiVsZ0[0]->Fill(z0, deltaPhi);
01313       //hDeltaPhiVsD0[0]->Fill(d0, deltaPhi);
01314       // Resolution histos must have hlt matches
01315       
01316       hResoPtAodRec[0]->Fill((pt - l1pt)/pt);
01317       hResoEtaAodRec[0]->Fill((eta - l1eta)/fabs(eta));
01318       hResoPhiAodRec[0]->Fill((phi - l1phi)/fabs(phi));
01319         
01320       
01321       hChargeFlipMatched[0]->Fill(l1plottedCharge, plottedCharge);
01322       
01323       if (numRecMatches == 1) {
01324         hPassExaclyOneMuonMaxPtRec[1]->Fill(pt);
01325         hPassPtRecExactlyOne[1]->Fill(pt);
01326       }
01327     }
01328     
01329     //  bool foundAllPreviousCands = true;
01330     //  Look through the hltCands and see what's going on
01331     //
01332 
01333     
01334     for ( size_t j = 0; j < myRecMatches[i].hltCands.size(); j++ ) {
01335       if ( myRecMatches[i].hltCands[j].pt() > 0 ) {
01336         double hltCand_pt = myRecMatches[i].hltCands[j].pt();
01337         double hltCand_eta = myRecMatches[i].hltCands[j].eta();
01338         double hltCand_phi = myRecMatches[i].hltCands[j].phi();
01339         int hltCand_plottedCharge = getCharge(myRecMatches[i].hltCands[j].id());
01340 
01341         // store this rec muon pt, not hlt cand pt
01342         if (theHltCollectionLabels.size() > j) {
01343           TString tempString = theHltCollectionLabels[j];
01344           if (tempString.Contains("L3")) {
01345             
01346             maxMatchPtRec = (pt > maxMatchPtRec)? pt : maxMatchPtRec;
01347           }
01348         }
01349 
01350         // these are histos where you have
01351         // all + L1 (= displaced two indices)
01352         // Which means your HLT histos are
01353         // at index j+HLT_PLOT_OFFSET 
01354         hPassEtaRec[j+HLT_PLOT_OFFSET]->Fill(eta);
01355         hPassPhiRec[j+HLT_PLOT_OFFSET]->Fill(phi);
01356         hPassPtRec[j+HLT_PLOT_OFFSET]->Fill(pt);
01357         hPhiVsEtaRec[j+HLT_PLOT_OFFSET]->Fill(eta,phi);
01358         hPassD0Rec[j+HLT_PLOT_OFFSET]->Fill(d0);
01359         hPassD0BeamRec[j+HLT_PLOT_OFFSET]->Fill(d0beam);
01360         hPassZ0Rec[j+HLT_PLOT_OFFSET]->Fill(z0);
01361         hPassZ0BeamRec[j+HLT_PLOT_OFFSET]->Fill(z0beam);
01362         hPassCharge[j+HLT_PLOT_OFFSET]->Fill(charge);
01363         hIsolationRec[j+HLT_PLOT_OFFSET]->Fill(myMuonIso);
01364         
01365         
01366         // Histograms with Match in the name only have HLT
01367         // matches possible
01368         // so there are no "all" histograms
01369         // so offset = 1 b/c of L1 histos
01370 
01371         double deltaR = reco::deltaR (hltCand_eta, hltCand_phi,
01372                                         eta, phi);
01373 
01374         double deltaPhi = reco::deltaPhi (hltCand_phi, phi);
01375 
01376         hDeltaRMatched[j+HLT_PLOT_OFFSET-1]->Fill(deltaR);
01377         hPassMatchPtRec[j+HLT_PLOT_OFFSET-1]->Fill(pt);
01378         //hPtMatchVsPtRec[j+HLT_PLOT_OFFSET-1]->Fill(hltCand_pt, pt);
01379         //hEtaMatchVsEtaRec[j+HLT_PLOT_OFFSET-1]->Fill(hltCand_eta, eta);
01380         //hPhiMatchVsPhiRec[j+HLT_PLOT_OFFSET-1]->Fill(hltCand_phi, phi);
01381         hMatchedDeltaPhi[j+HLT_PLOT_OFFSET-1]->Fill(deltaPhi);
01382         //hDeltaPhiVsPhi[j+HLT_PLOT_OFFSET-1]->Fill(phi, deltaPhi);
01383         //hDeltaPhiVsZ0[j+HLT_PLOT_OFFSET-1]->Fill(z0, deltaPhi);
01384         //hDeltaPhiVsD0[j+HLT_PLOT_OFFSET-1]->Fill(d0, deltaPhi);
01385         
01386 
01387         LogTrace ("HLTMuonVal") << "The pdg id is (hlt [" << j << "]) "
01388                                 << myRecMatches[i].hltCands[j].id()
01389                                 << "  and the plotted charge is "
01390                                 << hltCand_plottedCharge
01391                                 << ", w/ rec  charge "
01392                                 << charge
01393                                 << ", and plotted charge "
01394                                 << plottedCharge
01395                                 << "\n                "
01396                                 << "and rec pdg id = "
01397                                 << recPdgId;
01398         
01399 
01400         
01401         hChargeFlipMatched[j+HLT_PLOT_OFFSET-1]->Fill( hltCand_plottedCharge, plottedCharge);
01402 
01403         
01404         // Resolution histos must have hlt matches
01405 
01406         hResoPtAodRec[j+HLT_PLOT_OFFSET-1]->Fill((pt - hltCand_pt)/pt);
01407         hResoEtaAodRec[j+HLT_PLOT_OFFSET-1]->Fill((eta - hltCand_eta)/fabs(eta));
01408         hResoPhiAodRec[j+HLT_PLOT_OFFSET-1]->Fill((phi - hltCand_phi)/fabs(phi));
01409         
01410         if (numRecMatches == 1 && (myRecMatches[i].hltCands.size()== 1)) {
01411           hPassExaclyOneMuonMaxPtRec[j+HLT_PLOT_OFFSET]->Fill(pt);
01412           hPassPtRecExactlyOne[j+HLT_PLOT_OFFSET]->Fill(pt);
01413         }
01414       } // end if found hlt match      
01415     }
01416 
01418     //         Fill some RAW histograms
01420     if (useFullDebugInformation) {
01421       LogTrace ("HLTMuonVal")  << "\n.... now Filling Raw Histos";
01422       if ( myRecMatches[i].l1RawCand.energy() > 0 ) {
01423       
01424         // you've found a L1 raw candidate
01425         rawMatchHltCandPt[1]->Fill(pt);
01426         rawMatchHltCandEta[1]->Fill(eta);
01427         rawMatchHltCandPhi[1]->Fill(phi);      
01428       }
01429 
01430       LogTrace ("HLTMuonVal") << "There are " << myRecMatches[i].hltCands.size()
01431                               << " hltRaw candidates that could match, starting loop"
01432                               << endl;
01433     
01434       for ( size_t j = 0; j < myRecMatches[i].hltCands.size(); j++ ) {
01435         if ( myRecMatches[i].hltCands[j].pt() > 0 ) {
01436           rawMatchHltCandPt[j+HLT_PLOT_OFFSET]->Fill(pt);
01437           rawMatchHltCandEta[j+HLT_PLOT_OFFSET]->Fill(eta);
01438           rawMatchHltCandPhi[j+HLT_PLOT_OFFSET]->Fill(phi);   
01439         }
01440       }
01441 
01442     }
01443   } // end RECO matching
01444 
01446   //
01447   //  HLT fakes cands
01448   // 
01450 
01451   LogTrace ("HLTMuonVal")  << "\n.... now looping over fake cands";
01452   for (unsigned int  iHltModule = 0;  iHltModule < numHltLabels; iHltModule++) {
01453     for(size_t iCand = 0; iCand < myHltFakeCands[iHltModule].size() ; iCand ++){
01454       LogTrace ("HLTMuonVal") << "Label number : " << iHltModule
01455                               << "(max = " << numHltLabels << ")\n"
01456                               << "Candidate number: " << iCand
01457                               << "(max = " <<  myHltFakeCands[iHltModule].size()
01458                               << " )\n";
01459         
01460                               
01461       TriggerObject candVect = myHltFakeCands[iHltModule][iCand].myHltCand;
01462       bool candIsFake = myHltFakeCands[iHltModule][iCand].isAFake;
01463       
01464       allHltCandPt[iHltModule]->Fill(candVect.pt());
01465       allHltCandEta[iHltModule]->Fill(candVect.eta());
01466       allHltCandPhi[iHltModule]->Fill(candVect.phi());
01467 
01468       if (candIsFake) {
01469         fakeHltCandPt[iHltModule]->Fill(candVect.pt());
01470         fakeHltCandEta[iHltModule]->Fill(candVect.eta());
01471         fakeHltCandPhi[iHltModule]->Fill(candVect.phi());
01472         //fakeHltCandEtaPhi[iHltModule]->Fill(candVect.eta(), candVect.phi());
01473 
01474         // JMS extra hack - print out run,event so you can look
01475         // in event display
01476         // int myRun = iEvent.id().run();
01477         //         int myEvent = iEvent.id().event();
01478         
01479 
01480         //         cout << endl << "FAKE! run = " << myRun << ", event = "
01481         //              << myEvent << ", pt = " << candVect.pt() << ", eta = "
01482         //              << candVect.eta() << "phi, " << candVect.phi() << endl << endl;
01483         
01484       }
01485       
01486     }
01487     
01488   }
01489   
01490 
01491   LogTrace ("HLTMuonVal") << "There are " << myRecMatches.size()
01492                           << "  RECO muons in this event"
01493                           << endl;
01494     
01495   LogTrace ("HLTMuonVal") << "The max pt found by looking at candiates is   "
01496                           << maxMatchPtRec
01497     //<< "\n and the max found while storing reco was "
01498     //<< recMuonPt
01499                           << endl;
01500   
01502   //
01503   //  Fill MAX PT plot
01504   //
01506 
01507 
01508   // genMuonPt and maxMatchPtRec are the max values
01509   // fill these hists with the max reconstructed Pt  
01510   //if ( genMuonPt > 0 ) hPassMaxPtGen[0]->Fill( genMuonPt );
01511   if ( maxMatchPtRec > 0 ) hPassMaxPtRec[0]->Fill( maxMatchPtRec );
01512 
01513   // there will be one hlt match for each
01514   // trigger module label
01515   // int numHltMatches = myRecMatches[i].hltCands.size();
01516 
01517   if (numRecMatches == 1) {
01518     if (maxMatchPtRec >0) hPassExaclyOneMuonMaxPtRec[0]->Fill(maxMatchPtRec);
01519   }
01520 
01521   // Fill these if there are any L1 candidates
01522   if (useFullDebugInformation || isL1Path) {
01523     if ( numL1Cands >= theNumberOfObjects ) {
01524       //if ( genMuonPt > 0 ) hPassMaxPtGen[1]->Fill( genMuonPt );
01525       if ( maxMatchPtRec > 0 ) hPassMaxPtRec[1]->Fill( maxMatchPtRec );
01526       if (numRecMatches == 1 && numL1Cands == 1) {
01527         if (maxMatchPtRec >0) hPassExaclyOneMuonMaxPtRec[1]->Fill(maxMatchPtRec);
01528       }
01529     }
01530   }
01531 
01532 
01533   
01534   for ( size_t i = 0; i < numHltLabels; i++ ) {
01535     // this will only fill up if L3
01536     // I don't think it's correct to fill
01537     // all the labels with this
01538     if (maxMatchPtRec > 0) hPassMaxPtRec[i+HLT_PLOT_OFFSET]->Fill(maxMatchPtRec);
01539 
01540   }
01541 
01542 
01543   
01544 
01545 } // end fillPlots: Done filling histograms
01546 
01547 
01548 
01549 const reco::Candidate* HLTMuonMatchAndPlot::
01550 findMother( const reco::Candidate* p ) 
01551 {
01552   const reco::Candidate* mother = p->mother();
01553   if ( mother ) {
01554     if ( mother->pdgId() == p->pdgId() ) return findMother(mother);
01555     else return mother;
01556   }
01557   else return 0;
01558 }
01559 
01560 
01562 //
01563 //      You should not use findGenMatch b/c it references sim info
01565 
01566 int HLTMuonMatchAndPlot::findGenMatch
01567 ( double eta, double phi, double maxDeltaR, vector<MatchStruct> matches )
01568 {
01569   double bestDeltaR = maxDeltaR;
01570   int bestMatch = -1;
01571   for ( size_t i = 0; i < matches.size(); i++ ) {
01572     // double dR = reco::deltaR( eta, phi, 
01573     //                          matches[i].genCand->eta(), 
01574     //                          matches[i].genCand->phi() );
01575 
01576     
01577     double dR = 10;
01578     
01579     if ( dR  < bestDeltaR ) {
01580       bestMatch  =  i;
01581       bestDeltaR = dR;
01582     }
01583   }
01584   return bestMatch;
01585 }
01586 
01587 
01588 
01589 int HLTMuonMatchAndPlot::findRecMatch
01590 ( double eta, double phi,  double maxDeltaR, vector<MatchStruct> matches)
01591 {
01592   double bestDeltaR = maxDeltaR;
01593   int bestMatch = -1;
01594 
01595   // Case for delta R matching
01596   // the != cosmic case is for default handling.
01597   if (matchType != "cosmic" || matchType == "dr"  ) {
01598     for ( size_t i = 0; i < matches.size(); i++ ) {
01599       double dR = reco::deltaR( eta, phi, 
01600                                   matches[i].recCand->eta(), 
01601                                   matches[i].recCand->phi() );
01602       if ( dR  < bestDeltaR ) {
01603         bestMatch  =  i;
01604         bestDeltaR = dR;
01605       }
01606     }
01607     return bestMatch;
01608   }
01609 
01610   if (matchType == "cosmic") {
01611 
01612     //   Comsic trigger matching
01613     //   Just require the the muon
01614     //   will be in the same half of the detector
01615     //   ignore the eta information
01616     //   but we will look for the minmum delta phi
01617     //   with the muon in that region of the detector
01618     
01619     double bestDphi = 100.0;
01620     for ( size_t i = 0; i < matches.size(); i++ ) {
01621 
01622       double recCandPhi = matches[i].recCand->phi();
01623 
01624       
01625       if (recCandPhi < 0 && phi < 0) {
01626         if ( reco::deltaPhi(phi, recCandPhi) < bestDphi) {
01627           bestDphi = reco::deltaPhi(phi, recCandPhi);
01628           bestMatch = i;          
01629         }
01630       }
01631 
01632      
01633       if (recCandPhi > 0 && phi > 0) {
01634         
01635         if ( reco::deltaPhi(phi, recCandPhi) < bestDphi) {
01636           bestDphi = reco::deltaPhi(phi, recCandPhi);
01637           bestMatch = i;          
01638         }         
01639           
01640       }        
01641       
01642     }
01643     return bestMatch;
01644   }
01645 
01646   // If you get here, then you've improperly set
01647   // your matching
01648 
01649   LogWarning ("HLTMuonVal") << "WARNING: You have improperly set matchType" << endl
01650                          << "valid choices are 'dr' and 'cosmic', " <<endl
01651                          << "but you provided    " << matchType << endl;
01652   
01653   return bestMatch;
01654   
01655 }
01656 
01657 
01658 bool HLTMuonMatchAndPlot::applyTrackSelection (MuonSelectionStruct mySelection, Muon candMuon) {
01659 
01660   LogTrace ("HLTMuonVal") << "Applying track selection to your muon"
01661                           << endl;
01662   // get the track 
01663   // you should have specified the track using the collection names
01664   TrackRef theMuonTrack = getCandTrackRef (mySelection, candMuon);
01665 
01666   bool passedSelection = false;
01667   
01668   if ( theMuonTrack.isNonnull() ) {
01669      double d0 = theMuonTrack->d0();
01670      double z0 = theMuonTrack->dz();
01671 
01672 
01673      LogTrace ("HLTMuonVal") << "d0 = " << d0
01674                              << ", d0 cut = " << mySelection.d0cut << endl
01675                              << "z0 = " << z0
01676                              << ", z0 cut = " << mySelection.z0cut << endl;
01677                              
01678                              
01679      
01680      if (fabs(d0) < mySelection.d0cut &&
01681          fabs(z0) < mySelection.z0cut ) {
01682        passedSelection = true;
01683      }
01684   } else {
01685     LogTrace ("HLTMuonVal") << "This event didn't have a valid track of type "
01686                             << mySelection.trackCollection;            
01687   }
01688 
01689   return passedSelection;
01690   
01691 }
01692 
01693 bool HLTMuonMatchAndPlot::applyTriggerSelection(MuonSelectionStruct mySelection, const Event & event) {
01694 
01695   bool passedAnyTrigger = false;
01696   //  Look and your event selection criteria
01697   //  if you have a vector of size zero
01698   //  or if you have a vector with just an empty string
01699   //  then you should just skip this selection and return true
01700 
01701   LogTrace ("HLTMuonVal") << "Checking to see if you have non-empty triggers to match"
01702                           << endl;
01703   
01704   if (mySelection.requiredTriggers.size() < 1)
01705     return true;
01706 
01707   vector<string>::const_iterator iTargetTrig;
01708 
01709   bool everythingIsEmpty = true;
01710   for ( iTargetTrig = mySelection.requiredTriggers.begin();
01711         iTargetTrig != mySelection.requiredTriggers.end();
01712         iTargetTrig ++ ) {
01713 
01714     if ( (*iTargetTrig) != "" ) {
01715       everythingIsEmpty = false;
01716     }
01717     
01718   }
01719 
01720   if (everythingIsEmpty) {
01721     LogTrace ("HLTMuonVal") << "Only empty triggers, skipping match";
01722     return true;
01723   }
01724 
01725   //  At this point, you have a true trigger requirement
01726   //  You need to check the trigger results
01727   //  0. Get the trigger resutls 
01728   //  1. Loop over list of target triggers 
01729   //  2. See if the target is valid according to HLTConfig
01730   //  3. If it is, check to see that it fired
01731   //
01732   //  Potential optimization - store the trigger index
01733   //  rather than doing the match for each event
01734 
01735 
01736   // Get the trigger results
01737   
01738   Handle<TriggerResults> trigRes;
01739   event.getByLabel(TriggerResultLabel, trigRes);
01740   if (!trigRes.isValid()){
01741     edm::InputTag triggerResultsLabelFU(TriggerResultLabel.label(),TriggerResultLabel.instance(), "FU");
01742     event.getByLabel(triggerResultsLabelFU,trigRes);
01743     if(!trigRes.isValid()) {
01744       LogTrace("HLTMuonVal")<< "Trigger Results WARNING: No trigger Results in event info, but you wanted to check a trigger";
01745       // Do nothing, and 
01746       //TrigResultsIn=false;
01747 
01748       return false;
01749     }
01750   }
01751   unsigned size = trigRes->size();
01752 
01753   unsigned int Ntp = 0;
01754   
01755   LogTrace("HLTMuonVal")<< "Ntp=" << Ntp <<" Size of trigger results="<<size;
01756 
01757 
01758   // loop over the list of target triggers  
01759   
01760   map<string,bool> firedTrigger;
01761   
01762   for ( iTargetTrig = mySelection.requiredTriggers.begin();
01763         iTargetTrig != mySelection.requiredTriggers.end();
01764         iTargetTrig++ ) {
01765 
01766     std::string targetName = (*iTargetTrig);
01767 
01768     LogTrace("HLTMuonVal") << "Looking to see if " << targetName << " has fired... ";
01769 
01770     firedTrigger[targetName] = false;
01771     vector<string>::const_iterator iValidTrig;
01772     unsigned int trigIndex = 0;
01773     for ( iValidTrig = selectedValidTriggers.begin();
01774           iValidTrig != selectedValidTriggers.end();
01775           iValidTrig ++) {
01776 
01777       if ( targetName == (*iValidTrig)){
01778         
01779         LogTrace ("HLTMuonVal") << "Trigger " << targetName
01780                                 << " was part of the hlt configuration at index"
01781                                 << trigIndex
01782                                 << endl;
01783         
01784         firedTrigger[targetName] =  trigRes->accept(trigIndex);
01785 
01786         LogTrace ("HLTMuonVal") << "Did the trigger fire?      "
01787                                 << ((firedTrigger[targetName]) ? "PASSED" : "FAILED")
01788                                 << endl;
01789         
01790       }
01791 
01792       trigIndex++;
01793     } // end loop over valid triggers
01794   }// end loop over target triggers
01795     
01796 
01797   map<string,bool>::const_iterator iResult;
01798 
01799   passedAnyTrigger = false;
01800 
01801   LogTrace ("HLTMuonVal") << "OR-ing trigger results together" <<endl;
01802 
01803   
01804   for (iResult = firedTrigger.begin();
01805        iResult != firedTrigger.end();
01806        iResult ++) {
01807 
01808     passedAnyTrigger = passedAnyTrigger || iResult->second;
01809     
01810   }
01811 
01812   LogTrace ("HLTMuonVal") << "Returning " << passedAnyTrigger;
01813 
01814   return passedAnyTrigger;
01815   
01816 }
01817 
01818 
01819 
01820 TrackRef HLTMuonMatchAndPlot::getCandTrackRef (MuonSelectionStruct mySelection, Muon candMuon) {
01821 
01822   string trackCollection = mySelection.trackCollection;
01823   TrackRef theTrack;
01824 
01825   LogTrace ("HLTMuonVal") << "Getting the track reference for coll "
01826                           << trackCollection
01827                           << endl;
01828 
01829   LogTrace ("HLTMuonVal") << "Muon information" << endl
01830                           << "pt = " << candMuon.pt()
01831                           << ", phi = " << candMuon.phi()
01832                           << ", eta = " << candMuon.eta()
01833                           << ", global muon? = " << candMuon.isGlobalMuon()
01834                           << ", standalone muon = " << candMuon.isStandAloneMuon()
01835                           << ", tracker muon = " << candMuon.isTrackerMuon()
01836                           << endl;
01837   
01838   if (trackCollection == "innerTrack") {
01839     LogTrace ("HLTMuonVal") << "----> GET " << trackCollection;
01840 
01841     if ( candMuon.isTrackerMuon() ) {
01842       theTrack = candMuon.innerTrack();
01843     }
01844     
01845   } else if ( trackCollection == "outerTrack" ) {
01846     
01847     LogTrace ("HLTMuonVal") << "----> GET " << trackCollection;
01848 
01849     if ( candMuon.isStandAloneMuon() ) {
01850       theTrack = candMuon.outerTrack();
01851     }
01852     
01853   } else if ( trackCollection == "globalTrack") {
01854 
01855     LogTrace ("HLTMuonVal") << "----> GET " << trackCollection;
01856     if (candMuon.isGlobalMuon()) {
01857       theTrack = candMuon.globalTrack();
01858     }
01859   }
01860 
01861   if (theTrack.isNonnull()) {
01862     LogTrace ("HLTMuonVal") << "Found the desired track";
01863   } else {
01864     LogTrace ("HLTMuonVal") << "No track for this candidate";
01865   }
01866   
01867   return theTrack;
01868 }
01869 
01870 
01871 void HLTMuonMatchAndPlot::begin() 
01872 {
01873   LogTrace ("HLTMuonVal") << "\n\nInside HLTMuonMatchAndPlot begin()";
01874 
01875   TString myLabel, newFolder;
01876   vector<TH1F*> h;
01877 
01878   if ( dbe_ ) {
01879     dbe_->cd();
01880     dbe_->setCurrentFolder("HLT/Muon");
01881 
01882     // JMS I think this is trimming all L1 names to
01883     // to be L1Filtered
01884     // Update this so that it really is just L1Filtered
01885     // new trigger names ruin string trimming
01886 
01887     if (useOldLabels) { 
01888       myLabel = theL1CollectionLabel;
01889       myLabel = myLabel(myLabel.Index("L1"),myLabel.Length());
01890       myLabel = myLabel(0,myLabel.Index("Filtered")+8);
01891     } else {
01892       myLabel = "L1Filtered";
01893     }
01894     // JMS Old way of doing things
01895     //newFolder = "HLT/Muon/Distributions/" + theTriggerName;
01896     newFolder = "HLT/Muon/Distributions/" + theTriggerName + "/" + mySelection.customLabel;
01897 
01898     
01899     
01900     dbe_->setCurrentFolder( newFolder.Data() );
01901 
01902     //meNumberOfEvents            = dbe_->bookInt("NumberOfEvents");
01903     //MonitorElement *meMinPtCut  = dbe_->bookFloat("MinPtCut"    );
01904     //MonitorElement *meMaxEtaCut = dbe_->bookFloat("MaxEtaCut"   );
01905     //meMinPtCut ->Fill(theMinPtCut );
01906     //meMaxEtaCut->Fill(theMaxEtaCut);
01907     
01908     vector<string> binLabels;
01909     binLabels.push_back( theL1CollectionLabel.c_str() );
01910     for ( size_t i = 0; i < theHltCollectionLabels.size(); i++ )
01911       binLabels.push_back( theHltCollectionLabels[i].c_str() );
01912 
01913     //hNumObjects = dbe_->book1D( "numObjects", "Number of Objects", 7, 0, 7 );
01914     //hNumObjects->setBinLabel( 1, "Gen" );
01915     //hNumObjects->setBinLabel( 2, "Reco" );
01916     //for ( size_t i = 0; i < binLabels.size(); i++ )
01917     //hNumObjects->setBinLabel( i + 3, binLabels[i].c_str() );
01918     //hNumObjects->getTH1()->LabelsDeflate("X");
01919 
01920 
01921     if ( useMuonFromReco ){
01922 
01923       //hNumOrphansRec = dbe_->book1D( "recNumOrphans", "Number of Orphans;;Number of Objects Not Matched to a Reconstructed #mu", 5, 0, 5 );
01924       //       for ( size_t i = 0; i < binLabels.size(); i++ )
01925       //         hNumOrphansRec->setBinLabel( i + 1, binLabels[i].c_str() );
01926       //hNumOrphansRec->getTH1()->LabelsDeflate("X");
01927 
01928 
01929       
01930       
01931       // 0 = MaxPt_All
01932       hPassMaxPtRec.push_back( bookIt( "recPassMaxPt_All", "pt of Leading Reco Muon" ,  numBinsInPtHisto, ptBins) );
01933       // 1 = MaxPt if matched to L1 Trigger
01934       if (useFullDebugInformation || isL1Path) hPassMaxPtRec.push_back( bookIt( "recPassMaxPt_" + myLabel, "pt of Leading Reco Muon, if matched to " + myLabel,  numBinsInPtHisto, ptBins) );
01935 
01936       hPassEtaRec.push_back( bookIt( "recPassEta_All", "#eta of Reco Muons", theEtaParameters) );
01937       if (useFullDebugInformation || isL1Path) hPassEtaRec.push_back( bookIt( "recPassEta_" + myLabel, "#eta of Reco Muons matched to " + myLabel, theEtaParameters) );
01938       
01939       hPassPhiRec.push_back( bookIt( "recPassPhi_All", "#phi of Reco Muons", thePhiParameters) );
01940       if (useFullDebugInformation || isL1Path) hPassPhiRec.push_back( bookIt( "recPassPhi_" + myLabel, "#phi of Reco Muons matched to " + myLabel, thePhiParameters) );
01941       
01942 
01943       
01944       hPassPtRec.push_back( bookIt( "recPassPt_All", "Pt of  Reco Muon" , numBinsInPtHisto, ptBins) );
01945       if (useFullDebugInformation || isL1Path) hPassPtRec.push_back( bookIt( "recPassPt_" + myLabel, "pt  Reco Muon, if matched to " + myLabel,  numBinsInPtHisto, ptBins) );
01946       
01947       hPassPtRecExactlyOne.push_back( bookIt( "recPassPtExactlyOne_All", "pt of Leading Reco Muon (==1 muon)" ,  numBinsInPtHisto, ptBins) );
01948       if (useFullDebugInformation || isL1Path) hPassPtRecExactlyOne.push_back( bookIt( "recPassPtExactlyOne_" + myLabel, "pt of Leading Reco Muon (==1 muon), if matched to " + myLabel,  numBinsInPtHisto, ptBins) );
01949       
01950       hPassExaclyOneMuonMaxPtRec.push_back( bookIt("recPassExactlyOneMuonMaxPt_All", "pt of Leading Reco Muon in events with exactly one muon" ,  numBinsInPtHisto, ptBins) );
01951       if (useFullDebugInformation || isL1Path) hPassExaclyOneMuonMaxPtRec.push_back( bookIt("recPassExactlyOneMuonMaxPt_" + myLabel, "pt of Leading Reco Muon in events with exactly one muon match to " + myLabel ,  numBinsInPtHisto, ptBins) );
01952 
01953       hPassD0Rec.push_back( bookIt("recPassD0_All", "Track 2-D impact parameter wrt (0,0,0)(d0) ALL", theD0Parameters));
01954       if (useFullDebugInformation || isL1Path) hPassD0Rec.push_back( bookIt("recPassD0_" + myLabel, "Track 2-D impact parameter (0,0,0)(d0) " + myLabel, theD0Parameters));
01955       hPassD0BeamRec.push_back( bookIt("recPassD0Beam_All", "Track 2-D impact parameter wrt (beam)(d0) ALL", theD0Parameters));
01956       if (useFullDebugInformation || isL1Path) hPassD0BeamRec.push_back( bookIt("recPassD0Beam_" + myLabel, "Track 2-D impact parameter (beam)(d0) " + myLabel, theD0Parameters));
01957       
01958       hPassZ0Rec.push_back( bookIt("recPassZ0_All", "Track Z0 wrt (0,0,0) ALL", theZ0Parameters));
01959       if (useFullDebugInformation || isL1Path) hPassZ0Rec.push_back( bookIt("recPassZ0_" + myLabel, "Track Z0 (0,0,0) " + myLabel, theZ0Parameters));      
01960       hPassZ0BeamRec.push_back( bookIt("recPassZ0Beam_All", "Track Z0 wrt (beam) ALL", theZ0Parameters));
01961       if (useFullDebugInformation || isL1Path) hPassZ0BeamRec.push_back( bookIt("recPassZ0Beam_" + myLabel, "Track Z0 (beam) " + myLabel, theZ0Parameters));
01962 
01963       hPassCharge.push_back( bookIt("recPassCharge_All", "Track Charge  ALL", theChargeParameters));
01964       if (useFullDebugInformation || isL1Path) hPassCharge.push_back( bookIt("recPassCharge_" + myLabel, "Track Charge  " + myLabel, theChargeParameters));
01965 
01966       hIsolationRec.push_back ( bookIt("recPassIsolation_ALL", "Muon Isolation cone 0.3", theIsolationParameters));
01967       if (useFullDebugInformation || isL1Path) hIsolationRec.push_back ( bookIt("recPassIsolation_" + myLabel, "Muon Isolation cone 0.3  " + myLabel, theIsolationParameters)); 
01968 
01969         // beamspot filled only once
01970       hBeamSpotZ0Rec.push_back ( bookIt("recBeamSpotZ0_All", "Z0 of beamspot for this event", theZ0Parameters));
01971 
01972       
01973 
01974       // =======================================================
01975       // these hisotgrams requite a match, and so will only have
01976       // L1,L2,L3 histograms and no "all" histogram
01977       // =======================================================
01978       
01979       // hDeltaRMatched.push_back ( bookIt("recDeltaRMatched_All" , "#Delta R between matched HLTCand", theDRParameters));
01980       if (useFullDebugInformation || isL1Path) hDeltaRMatched.push_back ( bookIt("recDeltaRMatched_" + myLabel, "#Delta R between matched HLTCand", theDRParameters));
01981 
01982       // hChargeFlipMatched.push_back ( bookIt("recChargeFlipMatched_All" , "Charge Flip from hlt to RECO;HLT;Reco", theChargeFlipParameters)); 
01983       if (useFullDebugInformation || isL1Path) hChargeFlipMatched.push_back ( bookIt("recChargeFlipMatched_" + myLabel, "Charge Flip from hlt to RECO;HLT Charge (-,+);Reco (-,+)", theChargeFlipParameters)); 
01984 
01985       if (useFullDebugInformation || isL1Path) hPassMatchPtRec.push_back( bookIt( "recPassMatchPt_" + myLabel, "Pt of Reco Muon that is matched to Trigger Muon " + myLabel, numBinsInPtHisto, ptBins) );
01986       //hPtMatchVsPtRec.push_back (bookIt("recPtVsMatchPt" + myLabel, "Reco Pt vs Matched HLT Muon Pt" + myLabel ,  theMaxPtParameters2d) );
01987       //hEtaMatchVsEtaRec.push_back( bookIt( "recEtaVsMatchEta_" + myLabel, "Reco #eta vs HLT #eta  " + myLabel, theEtaParameters2d) );
01988       //hPhiMatchVsPhiRec.push_back( bookIt( "recPhiVsMatchPhi_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, thePhiParameters2d) );
01989       
01990       if (useFullDebugInformation || isL1Path) hResoPtAodRec.push_back ( bookIt ("recResoPt_" + myLabel, "TrigSumAOD to RECO P_T resolution", theResParameters));
01991       if (useFullDebugInformation || isL1Path) hResoEtaAodRec.push_back ( bookIt ("recResoEta_" + myLabel, "TrigSumAOD to RECO #eta resolution", theResParameters));
01992       if (useFullDebugInformation || isL1Path) hResoPhiAodRec.push_back ( bookIt ("recResoPhi_" + myLabel, "TrigSumAOD to RECO #phi resolution", theResParameters));
01993 
01994       // Cosmic debugging histos
01995       if (useFullDebugInformation || isL1Path) hMatchedDeltaPhi.push_back ( bookIt( "recDeltaPhiMatched_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, thePhiParameters0Pi) );
01996       //hDeltaPhiVsPhi.push_back(bookIt( "recDeltaPhiVsPhi_" + myLabel, "#Delta #phi (reco,hlt) vs HLT #phi  " + myLabel, theDeltaPhiVsPhiParameters) );
01997       //hDeltaPhiVsZ0.push_back(bookIt( "recDeltaPhiVsZ0_" + myLabel, "#Delta #phi (reco, hlt) vs HLT z0  " + myLabel, theDeltaPhiVsZ0Parameters) );
01998       //hDeltaPhiVsD0.push_back(bookIt( "recDeltaPhiVsD0_" + myLabel, "#Delta #phi (reco, hlt) vs HLT d0 " + myLabel, theDeltaPhiVsD0Parameters) );
01999       
02001       //  RAW Histograms 
02003 
02004       if (useFullDebugInformation) {
02005         rawMatchHltCandPt.push_back( bookIt( "rawPassPt_All", "Pt of  Reco Muon" ,  numBinsInPtHisto, ptBins) );
02006         rawMatchHltCandPt.push_back( bookIt( "rawPassPt_" + myLabel, "pt  Reco Muon, if matched to " + myLabel,  numBinsInPtHisto, ptBins) );
02007       
02008         rawMatchHltCandEta.push_back( bookIt( "rawPassEta_All", "#eta of Reco Muons", theEtaParameters) );
02009         rawMatchHltCandEta.push_back( bookIt( "rawPassEta_" + myLabel, "#eta of Reco Muons matched to " + myLabel, theEtaParameters) );
02010       
02011         rawMatchHltCandPhi.push_back( bookIt( "rawPassPhi_All", "#phi of Reco Muons", thePhiParameters) );
02012         rawMatchHltCandPhi.push_back( bookIt( "rawPassPhi_" + myLabel, "#phi of Reco Muons matched to " + myLabel, thePhiParameters) );
02013       }
02014       
02015       //=================================
02016       //          2-D Histograms
02017       //=================================
02018       
02019       hPhiVsEtaRec.push_back ( bookIt ("recPhiVsRecEta_All", "Reco #phi vs Reco #eta  ", thePhiEtaParameters2d));
02020       if (useFullDebugInformation || isL1Path) hPhiVsEtaRec.push_back ( bookIt ("recPhiVsRecEta_" + myLabel, "Reco #phi vs Reco #eta  " +myLabel, thePhiEtaParameters2d));
02021 
02022     }
02023 
02024     // we won't enter this loop if we don't have an hlt label
02025     // we won't have an hlt label is this is a l1 path
02026     for ( unsigned int i = 0; i < theHltCollectionLabels.size(); i++ ) {
02027 
02028       if (useOldLabels) {
02029         myLabel = theHltCollectionLabels[i];
02030         TString level = ( myLabel.Contains("L2") ) ? "L2" : "L3";
02031         myLabel = myLabel(myLabel.Index(level),myLabel.Length());
02032         myLabel = myLabel(0,myLabel.Index("Filtered")+8);
02033       } else {
02034         TString tempString = theHltCollectionLabels[i];
02035         TString level = ( tempString.Contains("L2") ) ? "L2" : "L3";
02036         myLabel = level + "Filtered";
02037       }
02038       
02039       if ( useMuonFromReco ) {
02040 
02041         // These histos have All, L1, L2, L3
02042         hPassMaxPtRec.push_back( bookIt( "recPassMaxPt_" + myLabel, "pt of Leading Reco Muon, if matched to " + myLabel, numBinsInPtHisto, ptBins) );     
02043         hPassEtaRec.push_back( bookIt( "recPassEta_" + myLabel, "#eta of Reco Muons matched to " + myLabel, theEtaParameters) );
02044         hPassPhiRec.push_back( bookIt( "recPassPhi_" + myLabel, "#phi of Reco Muons matched to " + myLabel, thePhiParameters) );                
02045 
02046         hPassPtRec.push_back ( bookIt( "recPassPt_" + myLabel, "Pt of  Reco Muon, if matched to " + myLabel, numBinsInPtHisto, ptBins) );
02047         hPassPtRecExactlyOne.push_back (bookIt( "recPassPtExactlyOne__" + myLabel, "pt of Leading Reco Muon (==1 muon), if matched to " + myLabel, numBinsInPtHisto, ptBins) );
02048 
02049         hPassExaclyOneMuonMaxPtRec.push_back( bookIt("recPassExactlyOneMuonMaxPt_" + myLabel, "pt of Leading Reco Muon in events with exactly one muon match to " + myLabel ,  numBinsInPtHisto, ptBins) );        
02050         hPhiVsEtaRec.push_back ( bookIt ("recPhiVsRecEta_" + myLabel, "Reco #phi vs Reco #eta  " +myLabel, thePhiEtaParameters2d));
02051 
02052          
02053         hPassD0Rec.push_back( bookIt("recPassD0_" + myLabel, "Track 2-D impact parameter (Z0) " + myLabel, theD0Parameters));
02054         hPassD0BeamRec.push_back( bookIt("recPassD0Beam_" + myLabel, "Track 2-D impact parameter (beam)(d0) " + myLabel, theD0Parameters));
02055         hPassZ0Rec.push_back( bookIt("recPassZ0_" + myLabel, "Track Z0 " + myLabel, theZ0Parameters));
02056         hPassZ0BeamRec.push_back( bookIt("recPassZ0Beam_" + myLabel, "Track Z0 (0,0,0) " + myLabel, theZ0Parameters));
02057         hPassCharge.push_back( bookIt("recPassCharge_" + myLabel, "Track Charge  " + myLabel, theChargeParameters));
02058 
02059         hIsolationRec.push_back ( bookIt("recPassIsolation_" + myLabel, "Muon Isolation cone 0.3  " + myLabel, theIsolationParameters)); 
02060         
02061         // Match histos only have numHltLabels indices
02062         hPassMatchPtRec.push_back( bookIt( "recPassMatchPt_" + myLabel, "Pt of Reco Muon that is matched to Trigger Muon " + myLabel, numBinsInPtHisto, ptBins) );
02063 
02064         //hPtMatchVsPtRec.push_back (bookIt("recPtVsMatchPt" + myLabel, "Reco Pt vs Matched HLT Muon Pt" + myLabel ,  theMaxPtParameters2d) );
02065         //hEtaMatchVsEtaRec.push_back( bookIt( "recEtaVsMatchEta_" + myLabel, "Reco #eta vs HLT #eta  " + myLabel, theEtaParameters2d) );
02066         //hPhiMatchVsPhiRec.push_back( bookIt( "recPhiVsMatchPhi_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, thePhiParameters2d) );
02067 
02068         hResoPtAodRec.push_back ( bookIt ("recResoPt_" + myLabel, "TrigSumAOD to RECO P_T resolution", theResParameters));
02069         hResoEtaAodRec.push_back ( bookIt ("recResoEta_" + myLabel, "TrigSumAOD to RECO #eta resolution", theResParameters));
02070         hResoPhiAodRec.push_back ( bookIt ("recResoPhi_" + myLabel, "TrigSumAOD to RECO #phi resolution", theResParameters));
02071 
02072         hDeltaRMatched.push_back ( bookIt("recDeltaRMatched_" + myLabel, "#Delta R between matched HLTCand", theDRParameters));
02073         hChargeFlipMatched.push_back ( bookIt("recChargeFlipMatched_" + myLabel, "Charge Flip from hlt to RECO;HLT (-,+);Reco (-,+)", theChargeFlipParameters)); 
02074 
02075         // cosmic plots
02076 
02077         hMatchedDeltaPhi.push_back ( bookIt( "recDeltaPhiMatched_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, thePhiParameters0Pi) );  
02078         //hDeltaPhiVsPhi.push_back(bookIt( "recDeltaPhiVsPhi_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, theDeltaPhiVsPhiParameters) );
02079         //hDeltaPhiVsZ0.push_back(bookIt( "recDeltaPhiVsZ0_" + myLabel, "Reco #phi vs HLT #phi  " + myLabel, theDeltaPhiVsZ0Parameters) );
02080         //hDeltaPhiVsD0.push_back(bookIt( "recDeltaPhiVsD0_" + myLabel, "#Delta #phi (reco, hlt) vs HLT d0 " + myLabel, theDeltaPhiVsD0Parameters) );
02081 
02082         // these candidates are indexed by the number
02083         // of hlt labels
02084         allHltCandPt.push_back( bookIt("allHltCandPt_" + myLabel, "Pt of all HLT Muon Cands, for HLT " + myLabel, numBinsInPtHisto, ptBins));     
02085         allHltCandEta.push_back( bookIt("allHltCandEta_" + myLabel, "Eta of all HLT Muon Cands, for HLT " + myLabel, theEtaParameters));         
02086         allHltCandPhi.push_back( bookIt("allHltCandPhi_" + myLabel, "Phi of all HLT Muon Cands, for HLT " + myLabel, thePhiParameters));    
02087 
02088         fakeHltCandPt.push_back( bookIt("fakeHltCandPt_" + myLabel, "Pt of fake HLT Muon Cands, for HLT " + myLabel, numBinsInPtHisto, ptBins));     
02089         fakeHltCandEta.push_back( bookIt("fakeHltCandEta_" + myLabel, "Eta of fake HLT Muon Cands, for HLT " + myLabel, theEtaParameters));         
02090         fakeHltCandPhi.push_back( bookIt("fakeHltCandPhi_" + myLabel, "Phi of fake HLT Muon Cands, for HLT " + myLabel, thePhiParameters));    
02091                 
02092         //fakeHltCandEtaPhi.push_back(bookIt("fakeHltCandPhiVsEta_" + myLabel, " AOD #phi vs  #eta for fake HLT Muon Cands, for HLT  " +myLabel, thePhiEtaParameters2d));
02093 
02094         // raw histograms
02095 
02096         if (useFullDebugInformation) {
02097           rawMatchHltCandPt.push_back( bookIt( "rawPassPt_" + myLabel, "pt  Reco Muon, if matched to " + myLabel,  numBinsInPtHisto, ptBins) );
02098           rawMatchHltCandEta.push_back( bookIt( "rawPassEta_" + myLabel, "#eta of Reco Muons matched to " + myLabel, theEtaParameters) );
02099           rawMatchHltCandPhi.push_back( bookIt( "rawPassPhi_" + myLabel, "#phi of Reco Muons matched to " + myLabel, thePhiParameters) );
02100         }
02101       }
02102 
02103     }
02104   }
02105 
02106 }
02107 
02108 
02109 
02110 MonitorElement* HLTMuonMatchAndPlot::bookIt
02111 ( TString name, TString title, vector<double> parameters )
02112 {
02113   LogTrace("HLTMuonVal") << "Directory " << dbe_->pwd() << " Name " << 
02114                             name << " Title:" << title;
02115   int nBins  = (int)parameters[0];
02116   double min = parameters[1];
02117   double max = parameters[2];
02118 
02119   // this is the 1D hist case
02120   if (parameters.size() == 3) {
02121     TH1F *h = new TH1F( name, title, nBins, min, max );
02122     h->Sumw2();
02123     MonitorElement * returnedME = dbe_->book1D( name.Data(), h );
02124     delete h;
02125     booked1DMonitorElements.push_back(returnedME);
02126     return returnedME;
02127 
02128     // this is the case for a 2D hist
02129   } else if (parameters.size() == 6) {
02130 
02131     int nBins2  = (int)parameters[3];
02132     double min2 = parameters[4];
02133     double max2 = parameters[5];
02134 
02135     TH2F *h = new TH2F (name, title, nBins, min, max, nBins2, min2, max2);
02136     h->Sumw2();
02137     MonitorElement * returnedME = dbe_->book2D (name.Data(), h);
02138     delete h;    
02139     return returnedME;
02140 
02141   } else {
02142     LogInfo ("HLTMuonVal") << "Directory" << dbe_->pwd() << " Name "
02143                             << name << " had an invalid number of paramters";
02144     return 0;
02145   }
02146   
02147 }
02148 
02149 MonitorElement* HLTMuonMatchAndPlot::bookIt
02150 ( TString name, TString title, int nbins, float * xBinLowEdges )
02151 {
02152   LogTrace("HLTMuonVal") << "Directory " << dbe_->pwd() << " Name " << 
02153                             name << " Title:" << title;
02154 
02155   TH1F *tempHist = new TH1F(name, title, nbins, xBinLowEdges);
02156   tempHist->Sumw2();
02157   MonitorElement * returnedME = dbe_->book1D(name.Data(), tempHist);
02158   delete tempHist;
02159 
02160   booked1DMonitorElements.push_back(returnedME);
02161   return returnedME;
02162   
02163 }
02164 
02165 
02166 
02167 
02168 int HLTMuonMatchAndPlot::getCharge (int pdgId) {
02169 
02170   int resultCharge =  (pdgId > 0) ? POS_CHARGE : NEG_CHARGE;
02171   
02172   return resultCharge;
02173   
02174 }
02175 
02176 TString HLTMuonMatchAndPlot::calcHistoSuffix (string moduleName) {
02177 
02178   TString level = "L3";
02179   TString myLabel = moduleName; // the return value
02180 
02181   
02182   if ( myLabel.Contains("L1") ) {
02183     level = "L1";
02184   } else if (myLabel.Contains("L2")) {
02185     level = "L2";
02186   } else if (myLabel.Contains("L3")) {
02187     level = "L3";
02188   }
02189 
02190   if (useOldLabels) {
02191     myLabel = myLabel(myLabel.Index(level),myLabel.Length());
02192     myLabel = myLabel(0,myLabel.Index("Filtered")+8);
02193     
02194   } else {
02195     myLabel = level + "Filtered";
02196   }
02197 
02198   return myLabel;
02199   
02200 }
02201 
02202 void HLTMuonMatchAndPlot::moveOverflow (MonitorElement * myElement) {
02203 
02204   LogTrace ("HLTMuonVal") << "MOVEOVERFLOW" << endl;
02205 
02206   
02207   // This will handle an arbitrary dimension first/last bin
02208   // but you should think about how you will interpret this for
02209   // 2D/3D histos
02210   // Actually, this can't handle abitrary dimensions.
02211   int maxBin = myElement->getNbinsX();
02212 
02213   double originalEntries = myElement->getEntries();
02214   
02215   LogTrace ("HLTMuonVal") << "==MOVEOVERFLOW==  "
02216                                 << "maxBin = " << maxBin
02217                                 << ", calling underflow"
02218                                 << endl;
02219   
02220   myElement->setBinContent(1, myElement->getBinContent(0) + myElement->getBinContent(1));
02221 
02222   LogTrace ("HLTMuonVal") << "reseting underflow to zero" << endl;
02223   myElement->setBinContent(0,0.0);
02224   LogTrace ("HLTMuonVal") << "calling overflow" << endl;
02225   myElement->setBinContent(maxBin,myElement->getBinContent(maxBin) + myElement->getBinContent(maxBin+1));
02226   LogTrace ("HLTMuonVal") << "seting overflow to zero" << endl;
02227   myElement->setBinContent(maxBin+1,0.0);
02228 
02229   myElement->setEntries(originalEntries);
02230 
02231 }
02232 
02233 
02234 void HLTMuonMatchAndPlot::getAodTriggerObjectsForModule (edm::InputTag collectionTag,
02235                                                          edm::Handle<trigger::TriggerEvent> aodTriggerEvent,
02236                                                          trigger::TriggerObjectCollection trigObjs,
02237                                                          std::vector<TriggerObject> & foundObjects,
02238                                                          MuonSelectionStruct muonSelection) {
02239 
02240 
02241   //LogTrace ("HLTMuonVal") << "Getting trigger muons for module label = " << collectionTag << endl;
02242   
02243   size_t filterIndex   = aodTriggerEvent->filterIndex( collectionTag );
02244     
02245   LogTrace ("HLTMuonVal") << "\n\n filterIndex is "
02246                           << filterIndex;
02247     
02248   if ( filterIndex < aodTriggerEvent->sizeFilters() ) {
02249     const Keys &keys = aodTriggerEvent->filterKeys( filterIndex );
02250 
02251     LogTrace ("HLTMuonVal") << "\n\nGot keys";
02252     LogTrace ("HLTMuonVal") << "Key size is " << keys.size();
02253                               
02254     // The keys are apparently pointers into the trigger
02255     // trigObjs collections
02256     // Use the key's to look up the particles for the
02257     // filter module that you're using 
02258       
02259     for ( size_t j = 0; j < keys.size(); j++ ){
02260       TriggerObject foundObject = trigObjs[keys[j]];
02261 
02262       // This is the trigger object. Apply your filter to it!
02263       LogTrace ("HLTMuonVal") << "Testing to see if object in key passes selection"
02264                               << endl ;
02265         
02266       if (muonSelection.hltMuonSelector(foundObject)){
02267         
02268         LogTrace ("HLTMuonVal") << "OBJECT FOUND!!! - Storing a trigger object with id = "              
02269                                 << foundObject.id() 
02270                                 << ", eta = " << foundObject.eta()
02271                                 << ", pt = " << foundObject.pt()
02272                                 << ", custom name = " << muonSelection.customLabel
02273                                 << "\n\n" << endl;
02274         //l1Particles.push_back( trigObjs[keys[j]].particle().p4() );
02275         foundObjects.push_back( foundObject );
02276       }
02277     }
02278   }
02279 
02280   
02281   
02282 }