CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/Physics/src/QcdUeDQM.cc

Go to the documentation of this file.
00001 
00002 /*
00003     This is the DQM code for UE physics plots
00004     11/12/2009 Sunil Bansal
00005 */
00006 #include "DQM/Physics/src/QcdUeDQM.h"
00007 #include "DataFormats/Common/interface/TriggerResults.h"
00008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00009 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00010 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00011 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00012 #include "DataFormats/VertexReco/interface/Vertex.h"
00013 #include "DQMServices/Core/interface/DQMStore.h"
00014 #include "DQMServices/Core/interface/MonitorElement.h"
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00022 #include "CommonTools/RecoAlgos/src/TrackToRefCandidate.h"
00023 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00024 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00025 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00027 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" 
00028 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00029 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfo.h"
00030 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfoTrackAssociation.h"
00031 #include "DataFormats/TrackReco/interface/Track.h"
00032 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00033 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00034 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00035 #include "DataFormats/Math/interface/deltaPhi.h"
00036 #include <TString.h>
00037 #include <TMath.h>
00038 #include <TH1F.h>
00039 #include <TH2F.h>
00040 #include <TH3F.h>
00041 #include <TProfile.h>
00042 using namespace std;
00043 using namespace edm;
00044 
00045 #define CP(level) \
00046   if (level>=verbose_)
00047 
00048 struct deleter {
00049   void operator()(TH3F *&h) { delete h; h=0;}
00050 };
00051 
00052 
00053 //--------------------------------------------------------------------------------------------------
00054 QcdUeDQM::QcdUeDQM(const ParameterSet &parameters) :
00055   hltResName_(parameters.getUntrackedParameter<string>("hltTrgResults")),
00056   verbose_(parameters.getUntrackedParameter<int>("verbose",3)),
00057   tgeo_(0),
00058   theDbe_(0),
00059   repSumMap_(0),
00060   repSummary_(0),
00061   h2TrigCorr_(0),
00062   ptMin_(parameters.getParameter<double>("ptMin")),
00063   minRapidity_(parameters.getParameter<double>("minRapidity")),
00064   maxRapidity_(parameters.getParameter<double>("maxRapidity")),
00065   tip_(parameters.getParameter<double>("tip")),
00066   lip_(parameters.getParameter<double>("lip")),
00067   diffvtxbs_(parameters.getParameter<double>("diffvtxbs")),
00068   ptErr_pt_(parameters.getParameter<double>("ptErr_pt")),
00069   vtxntk_(parameters.getParameter<double>("vtxntk")),
00070   minHit_(parameters.getParameter<int>("minHit")),
00071   pxlLayerMinCut_(parameters.getParameter<double>("pxlLayerMinCut")),
00072   requirePIX1_(parameters.getParameter<bool>("requirePIX1")),
00073   min3DHit_(parameters.getParameter<int>("min3DHit")),
00074   maxChi2_(parameters.getParameter<double>("maxChi2")),
00075   bsuse_(parameters.getParameter<bool>("bsuse")),
00076   allowTriplets_(parameters.getParameter<bool>("allowTriplets")),
00077   bsPos_(parameters.getParameter<double>("bsPos")),
00078   caloJetLabel_(parameters.getUntrackedParameter<edm::InputTag>("caloJetTag")),
00079   chargedJetLabel_(parameters.getUntrackedParameter<edm::InputTag>("chargedJetTag")),
00080   trackLabel_(parameters.getUntrackedParameter<edm::InputTag>("trackTag")),
00081   vtxLabel_(parameters.getUntrackedParameter<edm::InputTag>("vtxTag")),
00082   bsLabel_(parameters.getParameter<edm::InputTag>("beamSpotTag")) 
00083 {
00084   // Constructor.
00085   std::vector<std::string> quality = parameters.getParameter<std::vector<std::string> >("quality");
00086   for (unsigned int j=0;j<quality.size();j++) quality_.push_back(reco::TrackBase::qualityByName(quality[j])); 
00087   std::vector<std::string> algorithm = parameters.getParameter<std::vector<std::string> >("algorithm");
00088   for (unsigned int j=0;j<algorithm.size();j++) algorithm_.push_back(reco::TrackBase::algoByName(algorithm[j])); 
00089 
00090   if (parameters.exists("hltTrgNames"))
00091     hltTrgNames_ = parameters.getUntrackedParameter<vector<string> >("hltTrgNames");
00092 
00093   if (parameters.exists("hltProcNames"))
00094      hltProcNames_ = parameters.getUntrackedParameter<vector<string> >("hltProcNames");
00095   else {
00096     //     hltProcNames_.push_back("FU");
00097      hltProcNames_.push_back("HLT");
00098   }
00099 
00100   isHltConfigSuccessful_ = false; // init
00101  
00102 }
00103 
00104 //--------------------------------------------------------------------------------------------------
00105 QcdUeDQM::~QcdUeDQM()
00106 {
00107   // Destructor.
00108 
00109 
00110 }
00111 
00112 //--------------------------------------------------------------------------------------------------
00113 void QcdUeDQM::analyze(const Event &iEvent, const EventSetup &iSetup) 
00114 {
00115   if( ! isHltConfigSuccessful_ ) return;
00116 
00117   // Analyze the given event.
00118    
00119    edm::Handle<reco::BeamSpot> beamSpot;
00120    bool ValidBS_ = iEvent.getByLabel(bsLabel_,beamSpot);
00121    if(!ValidBS_)return;
00122 
00123    edm::Handle<reco::TrackCollection>tracks ;
00124    bool ValidTrack_ = iEvent.getByLabel(trackLabel_,tracks);
00125    if(!ValidTrack_)return;
00126 
00127    //edm::Handle<reco::CandidateView> trkJets;
00128    //bool ValidTrackJet_ = iEvent.getByLabel (chargedJetLabel_,trkJets);
00129    //if(!ValidTrackJet_)return;
00130 
00131    edm::Handle< reco::TrackJetCollection > trkJets ;
00132    bool ValidTrackJet_ =  iEvent.getByLabel(chargedJetLabel_,trkJets );
00133    if(!ValidTrackJet_)return;
00134 
00135    
00136    edm::Handle<reco::CaloJetCollection> calJets;
00137    bool ValidCaloJet_ = iEvent.getByLabel (caloJetLabel_,calJets);
00138    if(!ValidCaloJet_)return;
00139  
00140    edm::Handle< reco::VertexCollection > vertexColl;
00141    bool ValidVtxColl_ = iEvent.getByLabel (vtxLabel_, vertexColl);
00142    if(!ValidVtxColl_)return;
00143 
00144    reco::TrackCollection tracks_sort = *tracks;
00145    std::sort(tracks_sort.begin(), tracks_sort.end(), PtSorter()); 
00146 
00147   // get tracker geometry
00148 /*  ESHandle<TrackerGeometry> trackerHandle;
00149   iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00150   tgeo_ = trackerHandle.product();
00151   if (!tgeo_)return;
00152 */
00153   selected_.clear(); 
00154   fillHltBits(iEvent,iSetup);
00155   // select good tracks
00156   if(fillVtxPlots(beamSpot.product(),vertexColl))
00157   {
00158   fill1D(hNevts_,1);
00159   for(reco::TrackCollection::const_iterator Trk = tracks_sort.begin(); Trk != tracks_sort.end(); ++Trk)
00160    {
00161     
00162    if ( trackSelection(*Trk,beamSpot.product(),vtx1,vertexColl->size()) ) selected_.push_back( & * Trk );   
00163    }
00164  
00165       
00166     fillpTMaxRelated(selected_);
00167     fillChargedJetSpectra(trkJets);  
00168 //    fillCaloJetSpectra(calJets);
00169     fillUE_with_MaxpTtrack(selected_);
00170     if(trkJets->size() > 0)fillUE_with_ChargedJets(selected_,trkJets); 
00171    // if(calJets->size()>0)fillUE_with_CaloJets(selected_,calJets);
00172   
00173  }
00174 
00175 }
00176 
00177 //--------------------------------------------------------------------------------------------------
00178 void QcdUeDQM::beginJob() 
00179 {
00180   // Begin job and setup the DQM store.
00181 
00182   theDbe_ = Service<DQMStore>().operator->();
00183   if (!theDbe_)return;
00184   
00185   //  theDbe_->setCurrentFolder("Physics/QcdUe");
00186   
00187 }
00188 
00189 //--------------------------------------------------------------------------------------------------
00190 void QcdUeDQM::beginLuminosityBlock(const LuminosityBlock &l, 
00191                                        const EventSetup &iSetup)
00192 {
00193   if( ! isHltConfigSuccessful_ ) return;
00194 
00195   // At the moment, nothing needed to be done.
00196 }
00197 
00198 //--------------------------------------------------------------------------------------------------
00199 void QcdUeDQM::beginRun(const Run &run, const EventSetup &iSetup)
00200 {
00201 
00202  // indicating change of HLT cfg at run boundries
00203  // for HLTConfigProvider::init()
00204  bool isHltCfgChange = false;
00205  isHltConfigSuccessful_ = false; // init
00206 
00207  string teststr;
00208  for(size_t i=0; i<hltProcNames_.size(); ++i) {
00209    if (i>0) 
00210      teststr += ", ";
00211    teststr += hltProcNames_.at(i);
00212    if ( hltConfig.init( run, iSetup, hltProcNames_.at(i), isHltCfgChange ) ) {
00213      isHltConfigSuccessful_ = true;
00214      hltUsedResName_ = hltResName_;
00215      if (hltResName_.find(':')==string::npos)
00216        hltUsedResName_ += "::";
00217      else 
00218        hltUsedResName_ += ":";
00219      hltUsedResName_ += hltProcNames_.at(i);
00220      break;
00221    }
00222  }
00223  
00224  if ( ! isHltConfigSuccessful_ )return;
00225 
00226   // setup "Any" bit
00227   hltTrgBits_.clear();
00228   hltTrgBits_.push_back(-1);
00229   hltTrgDeci_.clear();
00230   hltTrgDeci_.push_back(true);
00231   hltTrgUsedNames_.clear();
00232   hltTrgUsedNames_.push_back("Any");
00233 
00234   // figure out relation of trigger name to trigger bit and store used trigger names/bits
00235   for(size_t i=0;i<hltTrgNames_.size();++i) {
00236     const string &n1(hltTrgNames_.at(i));
00237     //unsigned int hlt_prescale = hltConfig.prescaleValue(iSetup, n1);
00238     //cout<<"trigger=="<<n1<<"presc=="<<hlt_prescale<<endl;
00239     bool found = 0;
00240     for(size_t j=0;j<hltConfig.size();++j) {
00241       const string &n2(hltConfig.triggerName(j));
00242       if (n2==n1) {
00243         hltTrgBits_.push_back(j);
00244         hltTrgUsedNames_.push_back(n1);
00245         hltTrgDeci_.push_back(false);
00246         found = 1;
00247         break;
00248       }
00249     }      
00250     if (!found) {
00251       CP(2) cout<<"Could not find trigger bit"<<endl ;
00252     }
00253   }
00254  
00255   // book monitoring histograms
00256   createHistos();
00257   isHltConfigSuccessful_ = true;
00258 
00259 }
00260 
00261 //--------------------------------------------------------------------------------------------------
00262 void QcdUeDQM::book1D(std::vector<MonitorElement*> &mes, 
00263                          const std::string &name, const std::string &title, 
00264                          int nx, double x1, double x2, bool sumw2, bool sbox)
00265 {
00266   // Book 1D histos.
00267 
00268   for(size_t i=0;i<hltTrgUsedNames_.size();++i) {
00269     std::string folderName = "Physics/QcdUe/" + hltTrgUsedNames_.at(i);
00270     theDbe_->setCurrentFolder(folderName);
00271     MonitorElement *e = theDbe_->book1D(Form("%s_%s",name.c_str(),hltTrgUsedNames_.at(i).c_str()),
00272                                         Form("%s: %s",hltTrgUsedNames_.at(i).c_str(), title.c_str()), 
00273                                         nx, x1, x2);
00274     TH1 *h1 = e->getTH1();
00275     if (sumw2) {
00276       if( 0 == h1->GetSumw2N() ) { // protect against re-summing (would cause exception)
00277         h1->Sumw2();
00278       }
00279     }
00280     h1->SetStats(sbox);
00281     mes.push_back(e);
00282   }
00283 }
00284 
00285 //--------------------------------------------------------------------------------------------------
00286 void QcdUeDQM::book2D(std::vector<MonitorElement*> &mes, 
00287                          const std::string &name, const std::string &title, 
00288                          int nx, double x1, double x2, int ny, double y1, double y2, 
00289                          bool sumw2, bool sbox)
00290 {
00291   // Book 2D histos.
00292 
00293   for(size_t i=0;i<hltTrgUsedNames_.size();++i) {
00294     std::string folderName = "Physics/QcdUe/" + hltTrgUsedNames_.at(i);
00295     theDbe_->setCurrentFolder(folderName);
00296     MonitorElement *e = theDbe_->book2D(Form("%s_%s",name.c_str(),hltTrgUsedNames_.at(i).c_str()),
00297                                         Form("%s: %s",hltTrgUsedNames_.at(i).c_str(), title.c_str()), 
00298                                         nx, x1, x2, ny, y1, y2);
00299     TH1 *h1 = e->getTH1();
00300     if (sumw2) {
00301       if( 0 == h1->GetSumw2N() ) { // protect against re-summing (would cause exception)
00302         h1->Sumw2();
00303       }
00304     }
00305     h1->SetStats(sbox);
00306     mes.push_back(e);
00307   }
00308 }
00309 
00310 //--------------------------------------------------------------------------------------------------
00311 void QcdUeDQM::bookProfile(std::vector<MonitorElement*> &mes, 
00312                          const std::string &name, const std::string &title, 
00313                          int nx, double x1, double x2,  double y1, double y2, 
00314                          bool sumw2, bool sbox)
00315 {
00316   // Book Profile histos.
00317 
00318   for(size_t i=0;i<hltTrgUsedNames_.size();++i) {
00319     std::string folderName = "Physics/QcdUe/" + hltTrgUsedNames_.at(i);
00320     theDbe_->setCurrentFolder(folderName);
00321     MonitorElement *e = theDbe_->bookProfile(Form("%s_%s",name.c_str(),hltTrgUsedNames_.at(i).c_str()),
00322                                         Form("%s: %s",hltTrgUsedNames_.at(i).c_str(), title.c_str()), 
00323                                         nx, x1, x2, y1, y2," ");
00324     mes.push_back(e);
00325   }
00326 }
00327 //--------------------------------------------------------------------------------------------------
00328 void QcdUeDQM::createHistos()
00329 {
00330   // Book histograms if needed.
00331 
00332 
00333 /*  if (1) {
00334     theDbe_->setCurrentFolder("Physics/EventInfo/");
00335     repSumMap_  = theDbe_->book2D("reportSummaryMap","reportSummaryMap",1,0,1,1,0,1);
00336     repSummary_ = theDbe_->bookFloat("reportSummary");
00337   }
00338   */ 
00339    theDbe_->setCurrentFolder("Physics/QcdUe");
00340 
00341   if (1) {
00342     const int Nx = hltTrgUsedNames_.size();
00343     const double x1 = -0.5;
00344     const double x2 = Nx-0.5;
00345     h2TrigCorr_ = theDbe_->book2D("h2TriCorr","Trigger bit x vs y;y&&!x;x&&y",Nx,x1,x2,Nx,x1,x2);
00346     for(size_t i=1;i<=hltTrgUsedNames_.size();++i) {
00347       h2TrigCorr_->setBinLabel(i,hltTrgUsedNames_.at(i-1),1);
00348       h2TrigCorr_->setBinLabel(i,hltTrgUsedNames_.at(i-1),2);
00349     }
00350     TH1 *h = h2TrigCorr_->getTH1();
00351     if (h)
00352       h->SetStats(0);
00353   }
00354   book1D(hNevts_,"hNevts","number of events",2,0,2);
00355   book1D(hNtrackerLayer_,"hNtrackerLayer","number of tracker layers;multiplicity",20,-0.5,19.5 );
00356   book1D(hNtrackerPixelLayer_,"hNtrackerPixelLayer","number of pixel layers;multiplicity",10,-0.5,9.5 );
00357   book1D(hNtrackerStripPixelLayer_,"hNtrackerStripPixelLayer","number of strip + pixel layers;multiplicity",30,-0.5,39.5 );
00358   book1D(hRatioPtErrorPt_,"hRatioPtErrorPt","ratio of pT error and track pT",25,0.,5.);
00359   book1D(hTrkPt_,"hTrkPt","pT of all tracks",50,0.,50.);
00360   book1D(hTrkEta_,"hTrkEta","eta of all tracks",40,-4.,4.);
00361   book1D(hTrkPhi_,"hTrkPhi","phi of all tracks",40,-4.,4.);
00362   book1D(hRatioDxySigmaDxyBS_,"hRatioDxySigmaDxyBS","ratio of transverse impact parameter and its significance wrt beam spot",60,-10.,10);
00363   book1D(hRatioDxySigmaDxyPV_,"hRatioDxySigmaDxyPV","ratio of transverse impact parameter and its significance wrt PV",60,-10.,10);
00364   book1D(hRatioDzSigmaDzBS_,"hRatioDzSigmaDzBS","ratio of longitudinal impact parameter and its significance wrt beam spot",80,-20.,20);
00365   book1D(hRatioDzSigmaDzPV_,"hRatioDzSigmaDzPV","ratio of longitudinal impact parameter and its significance wrt PV",80,-20.,20);
00366   book1D(hTrkChi2_,"hTrkChi2","track chi2",30,0.,30);
00367   book1D(hTrkNdof_,"hTrkNdof","track NDOF",100,0,100);
00368 
00369   book1D(hNgoodTrk_,"hNgoodTrk","number of good tracks",50,-0.5,49.5);
00370 
00371   book1D(hGoodTrkPt500_,"hGoodTrkPt500","pT of all good tracks with pT > 500 MeV",50,0.,50.);
00372   book1D(hGoodTrkEta500_,"hGoodTrkEta500","eta of all good tracks pT > 500 MeV",40,-4.,4.);
00373   book1D(hGoodTrkPhi500_,"hGoodTrkPhi500","phi of all good tracks pT > 500 MeV",40,-4.,4.);
00374 
00375   book1D(hGoodTrkPt900_,"hGoodTrkPt900","pT of all good tracks with pT > 900 MeV",50,0.,50.);
00376   book1D(hGoodTrkEta900_,"hGoodTrkEta900","eta of all good tracks pT > 900 MeV",40,-4.,4.);
00377   book1D(hGoodTrkPhi900_,"hGoodTrkPhi900","phi of all good tracks pT > 900 MeV",40,-4.,4.);
00378 
00379   book1D(hNvertices_,"hNvertices","number of vertices",5,-0.5,4.5);
00380   book1D(hVertex_z_,"hVertex_z","z position of vertex; z[cm]",200,-50,50);
00381   book1D(hVertex_y_,"hVertex_y","y position of vertex; y[cm]",100,-5,5);
00382   book1D(hVertex_x_,"hVertex_x","x position of vertex; x[cm]",100,-5,5);
00383   book1D(hVertex_ndof_,"hVertex_ndof","ndof of vertex",100,0,100);
00384   book1D(hVertex_rho_,"hVertex_rho","rho of vertex",100,0,5);
00385   book1D(hVertex_z_bs_,"hVertex_z_bs","z position of vertex from beamspot; z[cm]",200,-50,50);
00386 
00387   book1D(hBeamSpot_z_,"hBeamSpot_z","z position of beamspot; z[cm]",100,-20,20);
00388   book1D(hBeamSpot_y_,"hBeamSpot_y","y position of beamspot; y[cm]",50,-10,10);
00389   book1D(hBeamSpot_x_,"hBeamSpot_x","x position of beamspot; x[cm]",50,-10,10);
00390 
00391 
00392   if (1) {
00393     const int Nx = 25;
00394     const double x1 = 0.0;
00395     const double x2 = 50.0;
00396     book1D(hLeadingTrack_pTSpectrum_,"hLeadingTrack_pTSpectrum","pT spectrum of leading track;pT(GeV/c)",Nx,x1,x2);
00397 //    book1D(hLeadingCaloJet_pTSpectrum_,"hLeadingCalo_pTSpectrum","pT spectrum of leading calo jet;pT(GeV/c)",Nx,x1,x2);
00398     book1D(hLeadingChargedJet_pTSpectrum_,"hLeadingChargedJet_pTSpectrum","pT spectrum of leading track jet;pT(GeV/c)",Nx,x1,x2);
00399     
00400   }
00401   
00402   if (1) {
00403     const int Nx = 24;
00404     const double x1 = -4.;
00405     const double x2 =  4.;
00406     book1D(hLeadingTrack_phiSpectrum_,"hLeadingTrack_phiSpectrum","#phi spectrum of leading track;#phi",Nx,x1,x2);
00407   //  book1D(hLeadingCaloJet_phiSpectrum_,"hLeadingCaloJet_phiSpectrum","#phi spectrum of leading calo jet;#phi",Nx,x1,x2);
00408     book1D(hLeadingChargedJet_phiSpectrum_,"hLeadingChargedJet_phiSpectrum","#phi spectrum of leading track jet;#phi",Nx,x1,x2);
00409 
00410   }
00411   
00412   if (1) {
00413     const int Nx = 24;
00414     const double x1 = -4.;
00415     const double x2 =  4.;
00416     book1D(hLeadingTrack_etaSpectrum_,"hLeadingTrack_etaSpectrum","#eta spectrum of leading track;#eta",Nx,x1,x2);
00417     //book1D(hLeadingCaloJet_etaSpectrum_,"hLeadingCaloJet_etaSpectrum","#eta spectrum of leading calo jet;#eta",Nx,x1,x2);
00418     book1D(hLeadingChargedJet_etaSpectrum_,"hLeadingChargedJet_etaSpectrum","#eta spectrum of leading track jet;#eta",Nx,x1,x2);
00419 
00420   }
00421 
00422 
00423 if (1) {
00424     const int Nx = 75;
00425     const double x1 = 0.0;
00426     const double x2 = 75.0;
00427     const double y1 = 0.;
00428     const double y2 = 10.;
00429     bookProfile(hdNdEtadPhi_pTMax_Toward500_,"hdNdEtadPhi_pTMax_Toward500", 
00430                  "Average number of tracks (pT > 500 MeV) in toward region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00431     bookProfile(hdNdEtadPhi_pTMax_Transverse500_,"hdNdEtadPhi_pTMax_Transverse500", 
00432                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00433     bookProfile(hdNdEtadPhi_pTMax_Away500_,"hdNdEtadPhi_pTMax_Away500", 
00434                  "Average number of tracks (pT > 500 MeV) in away region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00435  /*
00436     bookProfile(hdNdEtadPhi_caloJet_Toward500_,"hdNdEtadPhi_caloJet_Toward500", 
00437                  "Average number of tracks (pT > 500 MeV) in toward region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00438     bookProfile(hdNdEtadPhi_caloJet_Transverse500_,"hdNdEtadPhi_caloJet_Transverse500", 
00439                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00440     bookProfile(hdNdEtadPhi_caloJet_Away500_,"hdNdEtadPhi_caloJet_Away500", 
00441                  "Average number of tracks (pT > 500 MeV) in away region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);   
00442   */
00443 
00444     bookProfile(hdNdEtadPhi_trackJet_Toward500_,"hdNdEtadPhi_trackJet_Toward500", 
00445                  "Average number of tracks (pT > 500 MeV) in toward region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2);
00446     bookProfile(hdNdEtadPhi_trackJet_Transverse500_,"hdNdEtadPhi_trackJet_Transverse500", 
00447                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00448     bookProfile(hdNdEtadPhi_trackJet_Away500_,"hdNdEtadPhi_trackJet_Away500", 
00449                  "Average number of tracks (pT > 500 MeV) in away region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00450 
00451 
00452  
00453     bookProfile(hpTSumdEtadPhi_pTMax_Toward500_,"hpTSumdEtadPhi_pTMax_Toward500", 
00454                  "Average number of tracks (pT > 500 MeV) in toward region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00455     bookProfile(hpTSumdEtadPhi_pTMax_Transverse500_,"hpTSumdEtadPhi_pTMax_Transverse500", 
00456                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00457     bookProfile(hpTSumdEtadPhi_pTMax_Away500_,"hpTSumdEtadPhi_pTMax_Away500", 
00458                  "Average number of tracks (pT > 500 MeV) in away region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00459 /* 
00460     bookProfile(hpTSumdEtadPhi_caloJet_Toward500_,"hpTSumdEtadPhi_caloJet_Toward500", 
00461                  "Average number of tracks (pT > 500 MeV) in toward region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00462     bookProfile(hpTSumdEtadPhi_caloJet_Transverse500_,"hpTSumdEtadPhi_caloJet_Transverse500", 
00463                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00464     bookProfile(hpTSumdEtadPhi_caloJet_Away500_,"hpTSumdEtadPhi_caloJet_Away500", 
00465                  "Average number of tracks (pT > 500 MeV) in away region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);   
00466 */
00467   
00468     bookProfile(hpTSumdEtadPhi_trackJet_Toward500_,"hpTSumdEtadPhi_trackJet_Toward500", 
00469                  "Average number of tracks (pT > 500 MeV) in toward region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00470     bookProfile(hpTSumdEtadPhi_trackJet_Transverse500_,"hpTSumdEtadPhi_trackJet_Transverse500", 
00471                  "Average number of tracks (pT > 500 MeV) in transverse region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00472     bookProfile(hpTSumdEtadPhi_trackJet_Away500_,"hpTSumdEtadPhi_trackJet_Away500", 
00473                  "Average number of tracks (pT > 500 MeV) in away region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00474 
00475    
00476    bookProfile(hdNdEtadPhi_pTMax_Toward900_,"hdNdEtadPhi_pTMax_Toward900",
00477                  "Average number of tracks (pT > 900 MeV) in toward region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00478     bookProfile(hdNdEtadPhi_pTMax_Transverse900_,"hdNdEtadPhi_pTMax_Transverse900",
00479                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00480     bookProfile(hdNdEtadPhi_pTMax_Away900_,"hdNdEtadPhi_pTMax_Away900",
00481                  "Average number of tracks (pT > 900 MeV) in away region vs leading track pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00482 /*
00483     bookProfile(hdNdEtadPhi_caloJet_Toward900_,"hdNdEtadPhi_caloJet_Toward900",
00484                  "Average number of tracks (pT > 900 MeV) in toward region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00485     bookProfile(hdNdEtadPhi_caloJet_Transverse900_,"hdNdEtadPhi_caloJet_Transverse900",
00486                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00487     bookProfile(hdNdEtadPhi_caloJet_Away900_,"hdNdEtadPhi_caloJet_Away900",
00488                  "Average number of tracks (pT > 900 MeV) in away region vs leading calo jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00489 */
00490 
00491     bookProfile(hdNdEtadPhi_trackJet_Toward900_,"hdNdEtadPhi_trackJet_Toward900",
00492                  "Average number of tracks (pT > 900 MeV) in toward region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2);
00493     bookProfile(hdNdEtadPhi_trackJet_Transverse900_,"hdNdEtadPhi_trackJet_Transverse900",
00494                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00495     bookProfile(hdNdEtadPhi_trackJet_Away900_,"hdNdEtadPhi_trackJet_Away900",
00496                  "Average number of tracks (pT > 900 MeV) in away region vs leading track jet pT;pT(GeV/c);dN/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00497 
00498 
00499 
00500     bookProfile(hpTSumdEtadPhi_pTMax_Toward900_,"hpTSumdEtadPhi_pTMax_Toward900",
00501                  "Average number of tracks (pT > 900 MeV) in toward region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00502     bookProfile(hpTSumdEtadPhi_pTMax_Transverse900_,"hpTSumdEtadPhi_pTMax_Transverse900",
00503                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00504     bookProfile(hpTSumdEtadPhi_pTMax_Away900_,"hpTSumdEtadPhi_pTMax_Away900",
00505                  "Average number of tracks (pT > 900 MeV) in away region vs leading track pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00506 /*
00507     bookProfile(hpTSumdEtadPhi_caloJet_Toward900_,"hpTSumdEtadPhi_caloJet_Toward900",
00508                  "Average number of tracks (pT > 900 MeV) in toward region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00509     bookProfile(hpTSumdEtadPhi_caloJet_Transverse900_,"hpTSumdEtadPhi_caloJet_Transverse900",
00510                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00511     bookProfile(hpTSumdEtadPhi_caloJet_Away900_,"hpTSumdEtadPhi_caloJet_Away900",
00512                  "Average number of tracks (pT > 900 MeV) in away region vs leading calo jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00513 */
00514     bookProfile(hpTSumdEtadPhi_trackJet_Toward900_,"hpTSumdEtadPhi_trackJet_Toward900",
00515                  "Average number of tracks (pT > 900 MeV) in toward region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00516     bookProfile(hpTSumdEtadPhi_trackJet_Transverse900_,"hpTSumdEtadPhi_trackJet_Transverse900",
00517                  "Average number of tracks (pT > 900 MeV) in transverse region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00518     bookProfile(hpTSumdEtadPhi_trackJet_Away900_,"hpTSumdEtadPhi_trackJet_Away900",
00519                  "Average number of tracks (pT > 900 MeV) in away region vs leading track jet pT;pT(GeV/c);dpTSum/d#eta d#phi",Nx,x1,x2,y1,y2,0,0);
00520  
00521    
00522   }
00523 
00524 if (1) {
00525     const int Nx = 20;
00526     const double x1 = 0.0;
00527     const double x2 = 20.0;
00528 
00529         book1D(hChargedJetMulti_,"hChargedJetMulti","Charged jet multiplicity;multiplicities",Nx,x1,x2);
00530         //book1D(hCaloJetMulti_,"hCaloJetMulti","Calo jet multiplicity;multiplicities",Nx,x1,x2);
00531 
00532   }
00533 
00534 
00535 if (1) {
00536     const int Nx = 60;
00537     const double x1 = -180.0;
00538     const double x2 = 180.0;
00539 
00540         book1D(hdPhi_maxpTTrack_tracks_,"hdPhi_maxpTTrack_tracks","delta phi between leading tracks and other tracks;#Delta#phi(leading track-track)",Nx,x1,x2);
00541 //        book1D(hdPhi_caloJet_tracks_,"hdPhi_caloJet_tracks","delta phi between leading calo jet  and tracks;#Delta#phi(leading calo jet-track)",Nx,x1,x2);
00542         book1D(hdPhi_chargedJet_tracks_,"hdPhi_chargedJet_tracks","delta phi between leading charged jet  and tracks;#Delta#phi(leading charged jet-track)",Nx,x1,x2);
00543 
00544 }
00545             
00546 
00547 }
00548 
00549 //--------------------------------------------------------------------------------------------------
00550 void QcdUeDQM::endJob(void) 
00551 {
00552 }
00553 
00554 //--------------------------------------------------------------------------------------------------
00555 
00556 void QcdUeDQM::endLuminosityBlock(const LuminosityBlock &l, 
00557                                      const EventSetup &iSetup)
00558 {
00559   if( ! isHltConfigSuccessful_ ) return;
00560 
00561   // Update various histograms.
00562 
00563   //repSummary_->Fill(1.);
00564  // repSumMap_->Fill(0.5,0.5,1.);
00565 
00566 }
00567 
00568 //--------------------------------------------------------------------------------------------------
00569 
00570 void QcdUeDQM::endRun(const Run &, const EventSetup &)
00571 {
00572   if( ! isHltConfigSuccessful_ ) return;
00573 
00574   // End run, cleanup. TODO: can this be called several times in DQM???
00575 
00576 }
00577 
00578 //--------------------------------------------------------------------------------------------------
00579 void QcdUeDQM::fill1D(std::vector<TH1F*> &hs, double val, double w)
00580 {
00581   // Loop over histograms and fill if trigger has fired.
00582 
00583   for(size_t i=0;i<hs.size();++i) {
00584     if (!hltTrgDeci_.at(i))
00585       continue;
00586     hs.at(i)->Fill(val,w);
00587   }
00588 }
00589 
00590 //--------------------------------------------------------------------------------------------------
00591 void QcdUeDQM::fill1D(std::vector<MonitorElement*> &mes, double val, double w)
00592 {
00593   // Loop over histograms and fill if trigger has fired.
00594 
00595   for(size_t i=0;i<mes.size();++i) {
00596     if (!hltTrgDeci_.at(i))
00597       continue;
00598     mes.at(i)->Fill(val,w);
00599   }
00600 }
00601 
00602 //--------------------------------------------------------------------------------------------------
00603 void QcdUeDQM::setLabel1D(std::vector<MonitorElement*> &mes)
00604 {
00605   // Loop over histograms and fill if trigger has fired.
00606   string cut[5] = {"Nevt","vtx!=bmspt","Zvtx<10cm","pT>1GeV","trackFromVtx"};
00607   for(size_t i=0;i<mes.size();++i) {
00608     if (!hltTrgDeci_.at(i))
00609       continue;
00610     for(size_t j = 1;j < 6;j++)mes.at(i)->setBinLabel(j,cut[j-1],1);
00611   }
00612 }
00613 
00614 //--------------------------------------------------------------------------------------------------
00615 void QcdUeDQM::fill2D(std::vector<TH2F*> &hs, double valx, double valy, double w)
00616 {
00617   // Loop over histograms and fill if trigger has fired.
00618 
00619   for(size_t i=0;i<hs.size();++i) {
00620     if (!hltTrgDeci_.at(i))
00621       continue;
00622     hs.at(i)->Fill(valx, valy ,w);
00623   }
00624 }
00625 
00626 //--------------------------------------------------------------------------------------------------
00627 void QcdUeDQM::fill2D(std::vector<MonitorElement*> &mes, double valx, double valy, double w)
00628 {
00629   // Loop over histograms and fill if trigger has fired.
00630 
00631   for(size_t i=0;i<mes.size();++i) {
00632     if (!hltTrgDeci_.at(i))
00633       continue;
00634     mes.at(i)->Fill(valx, valy ,w);
00635   }
00636 }
00637 //--------------------------------------------------------------------------------------------------
00638 void QcdUeDQM::fillProfile(std::vector<TProfile*> &hs, double valx, double valy, double w)
00639 {
00640   // Loop over histograms and fill if trigger has fired.
00641 
00642   for(size_t i=0;i<hs.size();++i) {
00643     if (!hltTrgDeci_.at(i))
00644       continue;
00645     hs.at(i)->Fill(valx, valy ,w);
00646   }
00647 }
00648 
00649 //--------------------------------------------------------------------------------------------------
00650 void QcdUeDQM::fillProfile(std::vector<MonitorElement*> &mes, double valx, double valy, double w)
00651 {
00652   // Loop over histograms and fill if trigger has fired.
00653 
00654   for(size_t i=0;i<mes.size();++i) {
00655     if (!hltTrgDeci_.at(i))
00656       continue;
00657    const double y = valy*w; 
00658     mes.at(i)->Fill(valx, y);
00659   }
00660 }
00661 
00662 //--------------------------------------------------------------------------------------------------
00663 bool QcdUeDQM::trackSelection(const reco::Track &trk, const reco::BeamSpot* bs, const reco::Vertex& vtx, int sizevtx )
00664 {
00665 //-------------Fill basic histograms---------
00666 
00667 
00668 //-------------------------------------------
00669 
00670  bool goodTrk = false;
00671 
00672  if(sizevtx!=1) return 0;    //selection events with only a vertex
00673 
00674  //Fill basic information of all the tracks
00675   fill1D(hNtrackerLayer_,trk.hitPattern().trackerLayersWithMeasurement());
00676   fill1D(hNtrackerPixelLayer_,trk.hitPattern().pixelLayersWithMeasurement());
00677   fill1D(hNtrackerStripPixelLayer_,(trk.hitPattern().pixelLayersWithMeasurement() +  trk.hitPattern().numberOfValidStripLayersWithMonoAndStereo()));
00678   fill1D(hRatioPtErrorPt_,(trk.ptError()/trk.pt()));
00679   fill1D(hTrkPt_,trk.pt());
00680   fill1D(hTrkEta_,trk.eta());  
00681   fill1D(hTrkPhi_,trk.phi());
00682   fill1D(hRatioDxySigmaDxyBS_,(trk.dxy(bs->position())/trk.dxyError()));
00683   fill1D(hRatioDxySigmaDxyPV_,(trk.dxy(vtx.position())/trk.dxyError()));
00684   fill1D(hRatioDzSigmaDzBS_,(trk.dz(bs->position())/trk.dzError()));
00685   fill1D(hRatioDzSigmaDzPV_,(trk.dz(vtx.position())/trk.dzError()));
00686   fill1D(hTrkChi2_,trk.normalizedChi2());
00687   fill1D(hTrkNdof_,trk.ndof());   
00688 
00689   fill1D(hBeamSpot_x_,bs->x0());
00690   fill1D(hBeamSpot_y_,bs->y0()); 
00691   fill1D(hBeamSpot_z_,bs->z0());
00692  
00693  //number of layers
00694  bool layerMinCutbool=false;
00695     if (trk.hitPattern().trackerLayersWithMeasurement() >= minHit_ ||
00696                 (trk.hitPattern().trackerLayersWithMeasurement()==3 && trk.hitPattern().pixelLayersWithMeasurement()==3 && allowTriplets_))
00697       layerMinCutbool=true;
00698 
00699 
00700   //number of pixel layers
00701  bool pxlLayerMinCutbool=false;
00702     if (trk.hitPattern().pixelLayersWithMeasurement() >=pxlLayerMinCut_) pxlLayerMinCutbool=true;
00703 
00704 
00705  // cut on the hits in pixel layers
00706  bool hasPIX1 = false;
00707     if (requirePIX1_) {
00708       const reco::HitPattern& p = trk.hitPattern();
00709       for (int i=0; i<p.numberOfHits(); i++) {
00710         uint32_t hit = p.getHitPattern(i);
00711         if (p.validHitFilter(hit) && p.pixelHitFilter(hit) && p.getLayer(hit)==1) hasPIX1 = true;
00712       }
00713     }else hasPIX1 = true;
00714  
00715  // cut on the pT error
00716  bool ptErrorbool=false; 
00717     if (trk.ptError()/trk.pt() < ptErr_pt_ || 
00718         (trk.hitPattern().trackerLayersWithMeasurement()==3 && trk.hitPattern().pixelLayersWithMeasurement()==3 && allowTriplets_)) ptErrorbool=true; 
00719  // quality cut
00720  bool quality_ok = true;  
00721  if (quality_.size()!=0) {
00722       quality_ok = false;
00723       for (unsigned int i = 0; i<quality_.size();++i) {
00724         if (trk.quality(quality_[i])){
00725           quality_ok = true;
00726           break;
00727         }
00728       }
00729     }
00730  //-----
00731  bool algo_ok = true;
00732     if (algorithm_.size()!=0) {
00733       if (std::find(algorithm_.begin(),algorithm_.end(),trk.algo())==algorithm_.end()) algo_ok = false;
00734     }
00735  
00736 
00737  if(bsuse_==1)
00738       {
00739     if(hasPIX1 &&  pxlLayerMinCutbool && layerMinCutbool &&  (trk.hitPattern().pixelLayersWithMeasurement() +  trk.hitPattern().numberOfValidStripLayersWithMonoAndStereo()) >= min3DHit_ && ptErrorbool && fabs(trk.pt()) >= ptMin_ &&  trk.eta() >= minRapidity_ && trk.eta() <= maxRapidity_ &&  fabs(trk.dxy(bs->position())/trk.dxyError()) < tip_ &&  fabs(trk.dz(bs->position())/trk.dzError()) < lip_  &&  trk.normalizedChi2()<=maxChi2_ &&  quality_ok &&  algo_ok)goodTrk=true ;
00740       }
00741 
00742     if(bsuse_==0)
00743      {
00744        if(hasPIX1 &&  pxlLayerMinCutbool &&  layerMinCutbool &&  (trk.hitPattern().pixelLayersWithMeasurement() +  trk.hitPattern().numberOfValidStripLayersWithMonoAndStereo())  >= min3DHit_ && ptErrorbool && fabs(trk.pt()) >= ptMin_ && trk.eta() >= minRapidity_ && trk.eta() <= maxRapidity_ && fabs(trk.dxy(vtx.position())/trk.dxyError()) < tip_ && fabs(trk.dz(vtx.position())/trk.dzError()) < lip_  && trk.normalizedChi2()<=maxChi2_ && quality_ok &&  algo_ok)goodTrk=true;
00745      
00746      }
00747 
00748   return goodTrk;
00749 
00750  }
00751 
00752 
00753 //--------------------------------------------------------------------------------------------------
00754 bool  QcdUeDQM::fillVtxPlots( const reco::BeamSpot* bs, const edm::Handle< reco::VertexCollection > vtxColl)
00755 {
00756   const reco::VertexCollection theVertices = *(vtxColl.product());
00757   bool goodVtx = false;
00758   fill1D(hNvertices_,theVertices.size()); 
00759     for (reco::VertexCollection::const_iterator vertexIt = theVertices.begin(); vertexIt != theVertices.end(); ++vertexIt) 
00760       {
00761         fill1D(hVertex_z_,vertexIt->z());
00762         fill1D(hVertex_y_,vertexIt->y());
00763         fill1D(hVertex_x_,vertexIt->x());
00764         fill1D(hVertex_ndof_,vertexIt->ndof());
00765         fill1D(hVertex_rho_,vertexIt->position().rho()); 
00766         fill1D(hVertex_z_bs_,(vertexIt->z() -bs->z0()));
00767 
00768         if(fabs(vertexIt->z() -bs->z0()) < diffvtxbs_  && vertexIt->ndof() >= 4 && vertexIt->position().rho()<= 2.0)
00769          {
00770          goodVtx = true;
00771          vtx1=(*vertexIt);
00772          
00773          break;
00774          }
00775       } // Loop over vertcies
00776    return goodVtx;
00777 }
00778 //--------------------------------------------------------------------------------------------------
00779 void QcdUeDQM::fillpTMaxRelated(const std::vector<const reco::Track *> &track)
00780  {
00781    fill1D(hNgoodTrk_,track.size());
00782    if(track.size()>0)
00783    {
00784    fill1D(hLeadingTrack_pTSpectrum_,track[0]->pt());
00785    fill1D(hLeadingTrack_phiSpectrum_,track[0]->phi());
00786    fill1D(hLeadingTrack_etaSpectrum_,track[0]->eta());
00787    }
00788      for(size_t i = 0; i < track.size(); i++)
00789        {
00790         fill1D(hGoodTrkPt500_,track[i]->pt());
00791         fill1D(hGoodTrkEta500_,track[i]->eta());
00792         fill1D(hGoodTrkPhi500_,track[i]->phi());
00793         if(track[i]->pt() > 0.9)
00794         {
00795         fill1D(hGoodTrkPt900_,track[i]->pt());
00796         fill1D(hGoodTrkEta900_,track[i]->eta());
00797         fill1D(hGoodTrkPhi900_,track[i]->phi());
00798         }
00799         }
00800                      
00801  }
00802 
00803 
00804 void QcdUeDQM::fillChargedJetSpectra(const edm::Handle<reco::TrackJetCollection> trackJets)
00805 {
00806   fill1D(hChargedJetMulti_,trackJets->size());
00807   for( reco::TrackJetCollection::const_iterator f  = trackJets->begin();  f != trackJets->end(); f++) 
00808     {
00809       if(f != trackJets->begin())continue;
00810       fill1D(hLeadingChargedJet_pTSpectrum_,f->pt());
00811       fill1D(hLeadingChargedJet_etaSpectrum_,f->eta());
00812       fill1D(hLeadingChargedJet_phiSpectrum_,f->phi());
00813     } 
00814         
00815 }
00816 
00817 /*
00818 void QcdUeDQM::fillCaloJetSpectra(const edm::Handle<reco::CaloJetCollection> caloJets)
00819 {
00820   fill1D(hCaloJetMulti_,caloJets->size());
00821    for( reco::CaloJetCollection::const_iterator f  = caloJets->begin();  f != caloJets->end(); f++)
00822      {
00823        if(f != caloJets->begin())continue;
00824        fill1D(hLeadingCaloJet_pTSpectrum_,f->pt()); 
00825        fill1D(hLeadingCaloJet_etaSpectrum_,f->eta());
00826        fill1D(hLeadingCaloJet_phiSpectrum_,f->phi());
00827      }
00828    
00829 }
00830 
00831 
00832 */
00833 
00834 
00835 /*
00836  weight for transverse/toward/away region = 0.12
00837  
00838 
00839 */
00840 
00841 void QcdUeDQM::fillUE_with_MaxpTtrack(const std::vector<const reco::Track*>  &track)
00842 {
00843 double w = 0.119;          
00844 //double w = 1.;
00845 double nTrk500_TransReg = 0;
00846 double nTrk500_AwayReg = 0;
00847 double nTrk500_TowardReg = 0;
00848  
00849 double pTSum500_TransReg = 0;
00850 double pTSum500_AwayReg = 0;
00851 double pTSum500_TowardReg = 0;
00852 
00853 
00854 double nTrk900_TransReg = 0;
00855 double nTrk900_AwayReg = 0;
00856 double nTrk900_TowardReg = 0;
00857 
00858 double pTSum900_TransReg = 0;
00859 double pTSum900_AwayReg = 0;
00860 double pTSum900_TowardReg = 0;
00861    if(track.size() > 0) 
00862     {
00863      if(track[0]->pt() > 1.)
00864          {
00865             for(size_t i = 1; i < track.size();i++)
00866                  {
00867                         
00868                        double dphi = (180./PI)*(deltaPhi(track[0]->phi(),track[i]->phi()));
00869                        fill1D(hdPhi_maxpTTrack_tracks_,dphi);
00870                        if(fabs(dphi)>60. && fabs(dphi)<120.)
00871                          {
00872                                pTSum500_TransReg =  pTSum500_TransReg + track[i]->pt();     
00873                                nTrk500_TransReg++;
00874                                if(track[i]->pt() > 0.9)
00875                                {
00876                                pTSum900_TransReg =  pTSum900_TransReg + track[i]->pt();
00877                                nTrk900_TransReg++;
00878                                }
00879                          }            
00880                         
00881                        if(fabs(dphi)>120. && fabs(dphi)<180.)
00882                          {
00883                                pTSum500_AwayReg =  pTSum500_AwayReg + track[i]->pt();   
00884                                nTrk500_AwayReg++;
00885                                 if(track[i]->pt() > 0.9)
00886                                 {
00887                                 pTSum900_AwayReg =  pTSum900_AwayReg + track[i]->pt();
00888                                 nTrk900_AwayReg++;
00889 
00890                                 } 
00891                          } 
00892                        
00893                        if(fabs(dphi)<60.)
00894                          {
00895                                pTSum500_TowardReg =  pTSum500_TowardReg + track[i]->pt();
00896                                nTrk500_TowardReg++;
00897                                if(track[i]->pt() > 0.9)
00898                                {
00899                                pTSum900_TowardReg =  pTSum900_TowardReg + track[i]->pt();
00900                                nTrk900_TowardReg++;
00901                                } 
00902                          }           
00903                      } // track loop 
00904                  }// leading track
00905              // non empty collection
00906                fillProfile(hdNdEtadPhi_pTMax_Toward500_, track[0]->pt(),nTrk500_TowardReg,w);
00907                fillProfile(hdNdEtadPhi_pTMax_Transverse500_, track[0]->pt(),nTrk500_TransReg,w);
00908                fillProfile(hdNdEtadPhi_pTMax_Away500_, track[0]->pt(),nTrk500_AwayReg,w);
00909 
00910                fillProfile(hpTSumdEtadPhi_pTMax_Toward500_,track[0]->pt() ,pTSum500_TowardReg,w);
00911                fillProfile(hpTSumdEtadPhi_pTMax_Transverse500_,track[0]->pt(),pTSum500_TransReg,w);
00912                fillProfile(hpTSumdEtadPhi_pTMax_Away500_, track[0]->pt(),pTSum500_AwayReg,w);
00913 
00914                fillProfile(hdNdEtadPhi_pTMax_Toward900_, track[0]->pt(),nTrk900_TowardReg,w);
00915                fillProfile(hdNdEtadPhi_pTMax_Transverse900_, track[0]->pt(),nTrk900_TransReg,w);
00916                fillProfile(hdNdEtadPhi_pTMax_Away900_, track[0]->pt(),nTrk900_AwayReg,w);
00917 
00918                fillProfile(hpTSumdEtadPhi_pTMax_Toward900_,track[0]->pt() ,pTSum900_TowardReg,w);
00919                fillProfile(hpTSumdEtadPhi_pTMax_Transverse900_,track[0]->pt(),pTSum900_TransReg,w);
00920                fillProfile(hpTSumdEtadPhi_pTMax_Away900_, track[0]->pt(),pTSum900_AwayReg,w);
00921      }
00922 }
00923 
00924 void QcdUeDQM::fillUE_with_ChargedJets(const std::vector<const reco::Track *>  &track, const edm::Handle<reco::TrackJetCollection> &trackJets)
00925 {
00926 double w = 0.119;
00927 double nTrk500_TransReg = 0;
00928 double nTrk500_AwayReg = 0;
00929 double nTrk500_TowardReg = 0;
00930   
00931 double pTSum500_TransReg = 0;
00932 double pTSum500_AwayReg = 0;
00933 double pTSum500_TowardReg = 0;
00934 
00935 
00936 double nTrk900_TransReg = 0;
00937 double nTrk900_AwayReg = 0;
00938 double nTrk900_TowardReg = 0;
00939 
00940 double pTSum900_TransReg = 0;
00941 double pTSum900_AwayReg = 0;
00942 double pTSum900_TowardReg = 0;
00943 
00944    if(!(trackJets->empty()) && (trackJets->begin())->pt() > 1.)
00945          {
00946          double jetPhi = (trackJets->begin())->phi();
00947            for(size_t i = 0; i < track.size();i++)
00948                    {
00949                          double dphi = (180./PI)*(deltaPhi(jetPhi,track[i]->phi()));
00950                          fill1D(hdPhi_chargedJet_tracks_,dphi);
00951                          if(fabs(dphi)>60. && fabs(dphi)<120.)
00952                            {
00953                                  pTSum500_TransReg =  pTSum500_TransReg + track[i]->pt();
00954                                  nTrk500_TransReg++;
00955                                  if(track[i]->pt() > 0.9)
00956                                  {
00957                                  pTSum900_TransReg =  pTSum900_TransReg + track[i]->pt();
00958                                  nTrk900_TransReg++;
00959                                  }
00960                            }
00961                         
00962                          if(fabs(dphi)>120. && fabs(dphi)<180.)
00963                            {
00964                                  pTSum500_AwayReg =  pTSum500_AwayReg + track[i]->pt();
00965                                  nTrk500_AwayReg++;
00966                                   if(track[i]->pt() > 0.9)
00967                                  {
00968                                  pTSum900_AwayReg =  pTSum900_AwayReg + track[i]->pt();
00969                                  nTrk900_AwayReg++;
00970                                  }
00971                            }
00972                          if(fabs(dphi)<60.)
00973                            {
00974                                  pTSum500_TowardReg =  pTSum500_TowardReg + track[i]->pt();
00975                                  nTrk500_TowardReg++;
00976                                   if(track[i]->pt() > 0.9)
00977                                  {
00978                                  pTSum900_TowardReg =  pTSum900_TowardReg + track[i]->pt();
00979                                  nTrk900_TowardReg++;
00980                                  } 
00981                            }
00982                        }// tracks loop 
00983 
00984                    }// leading track jet
00985                  
00986                  fillProfile(hdNdEtadPhi_trackJet_Toward500_, (trackJets->begin())->pt(),nTrk500_TowardReg,w);
00987                  fillProfile(hdNdEtadPhi_trackJet_Transverse500_, (trackJets->begin())->pt(),nTrk500_TransReg,w);
00988                  fillProfile(hdNdEtadPhi_trackJet_Away500_, (trackJets->begin())->pt(),nTrk500_AwayReg,w);
00989                  
00990                  fillProfile(hpTSumdEtadPhi_trackJet_Toward500_, (trackJets->begin())->pt(),pTSum500_TowardReg,w);
00991                  fillProfile(hpTSumdEtadPhi_trackJet_Transverse500_, (trackJets->begin())->pt(),pTSum500_TransReg,w);
00992                  fillProfile(hpTSumdEtadPhi_trackJet_Away500_, (trackJets->begin())->pt(),pTSum500_AwayReg,w);
00993 
00994                  fillProfile(hdNdEtadPhi_trackJet_Toward900_, (trackJets->begin())->pt(),nTrk900_TowardReg,w);
00995                  fillProfile(hdNdEtadPhi_trackJet_Transverse900_, (trackJets->begin())->pt(),nTrk900_TransReg,w);
00996                  fillProfile(hdNdEtadPhi_trackJet_Away900_, (trackJets->begin())->pt(),nTrk900_AwayReg,w);
00997 
00998                  fillProfile(hpTSumdEtadPhi_trackJet_Toward900_, (trackJets->begin())->pt(),pTSum900_TowardReg,w);
00999                  fillProfile(hpTSumdEtadPhi_trackJet_Transverse900_, (trackJets->begin())->pt(),pTSum900_TransReg,w);
01000                  fillProfile(hpTSumdEtadPhi_trackJet_Away900_, (trackJets->begin())->pt(),pTSum900_AwayReg,w);  
01001 }
01002 
01003 /*
01004 void QcdUeDQM:: fillUE_with_CaloJets(const std::vector<const reco::Track *>  &track, const edm::Handle<reco::CaloJetCollection> &caloJets)
01005 {
01006 double w = 0.119;
01007 double nTrk500_TransReg = 0;
01008 double nTrk500_AwayReg = 0;
01009 double nTrk500_TowardReg = 0;
01010                  
01011 double pTSum500_TransReg = 0;
01012 double pTSum500_AwayReg = 0;
01013 double pTSum500_TowardReg = 0;
01014 
01015 double nTrk900_TransReg = 0;
01016 double nTrk900_AwayReg = 0;
01017 double nTrk900_TowardReg = 0;
01018 
01019 double pTSum900_TransReg = 0;
01020 double pTSum900_AwayReg = 0;
01021 double pTSum900_TowardReg = 0;
01022     if(!(caloJets->empty()) && (caloJets->begin())->pt() > 1.)
01023           {
01024             double jetPhi = (caloJets->begin())->phi();
01025              for(size_t i = 0; i < track.size();i++)
01026                    {
01027                          double dphi = (180./PI)*(deltaPhi(jetPhi,track[i]->phi()));
01028                          fill1D(hdPhi_caloJet_tracks_,dphi);
01029                          if(fabs(dphi)>60. && fabs(dphi)<120.)
01030                            {
01031                                  pTSum500_TransReg =  pTSum500_TransReg + track[i]->pt();
01032                                  nTrk500_TransReg++;
01033                                  if(track[i]->pt() > 0.9)
01034                                  {
01035                                  pTSum900_TransReg =  pTSum900_TransReg + track[i]->pt();
01036                                  nTrk900_TransReg++;
01037                                  }
01038                            }
01039                          if(fabs(dphi)>120. && fabs(dphi)<180.)
01040                            {
01041                                  pTSum500_AwayReg =  pTSum500_AwayReg + track[i]->pt();
01042                                  nTrk500_AwayReg++;
01043                                  if(track[i]->pt() > 0.9)
01044                                  {
01045                                  pTSum900_AwayReg =  pTSum900_AwayReg + track[i]->pt();
01046                                  nTrk900_AwayReg++;
01047                                  }
01048                            }
01049                          if(fabs(dphi)<60.)
01050                            {
01051                                  pTSum500_TowardReg =  pTSum500_TowardReg + track[i]->pt();
01052                                  nTrk500_TowardReg++;
01053                                  if(track[i]->pt() > 0.9)
01054                                  {
01055                                  pTSum900_TowardReg =  pTSum900_TowardReg + track[i]->pt();
01056                                  nTrk900_TowardReg++; 
01057                                  }
01058                            }
01059                        }// tracks loop 
01060 
01061                    }// leading calo jet
01062                  fillProfile(hdNdEtadPhi_caloJet_Toward500_, (caloJets->begin())->pt(),nTrk500_TowardReg,w);
01063                  fillProfile(hdNdEtadPhi_caloJet_Transverse500_, (caloJets->begin())->pt(),nTrk500_TransReg,w);
01064                  fillProfile(hdNdEtadPhi_caloJet_Away500_, (caloJets->begin())->pt(),nTrk500_AwayReg,w);
01065                    
01066                  fillProfile(hpTSumdEtadPhi_caloJet_Toward500_, (caloJets->begin())->pt(),pTSum500_TowardReg,w);
01067                  fillProfile(hpTSumdEtadPhi_caloJet_Transverse500_, (caloJets->begin())->pt(),pTSum500_TransReg,w);
01068                  fillProfile(hpTSumdEtadPhi_caloJet_Away500_, (caloJets->begin())->pt(),pTSum500_AwayReg,w);
01069 
01070                  fillProfile(hdNdEtadPhi_caloJet_Toward900_, (caloJets->begin())->pt(),nTrk900_TowardReg,w);
01071                  fillProfile(hdNdEtadPhi_caloJet_Transverse900_, (caloJets->begin())->pt(),nTrk900_TransReg,w);
01072                  fillProfile(hdNdEtadPhi_caloJet_Away900_, (caloJets->begin())->pt(),nTrk900_AwayReg,w);
01073 
01074                  fillProfile(hpTSumdEtadPhi_caloJet_Toward900_, (caloJets->begin())->pt(),pTSum900_TowardReg,w);
01075                  fillProfile(hpTSumdEtadPhi_caloJet_Transverse900_, (caloJets->begin())->pt(),pTSum900_TransReg,w);
01076                  fillProfile(hpTSumdEtadPhi_caloJet_Away900_, (caloJets->begin())->pt(),pTSum900_AwayReg,w);
01077 
01078                  
01079 }
01080 
01081 */
01082 void QcdUeDQM::fillHltBits(const Event &iEvent,const EventSetup &iSetup)
01083 {
01084   // Fill HLT trigger bits.
01085 
01086   Handle<TriggerResults> triggerResultsHLT;
01087   getProduct(hltUsedResName_, triggerResultsHLT, iEvent);
01088   
01089 /*  const unsigned int ntrigs(triggerResultsHLT.product()->size());
01090   if( ntrigs != 0 ) {
01091   const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResultsHLT);
01092   for (unsigned int j=0; j!=ntrigs; j++) {
01093 //    if(triggerResultsHLT->accept(j)){
01094 //    unsigned int hlt_prescale = hltConfig_.prescaleValue(iEvent, iSetup, triggerName);
01095     cout<<"trigger fired"<<triggerNames.triggerName(j)<<endl;
01096     for(unsigned int itrigName = 0; itrigName < hltTrgNames_.size(); itrigName++ ) {
01097      unsigned int hlt_prescale = hltConfig.prescaleValue(iEvent, iSetup, hltTrgNames_[itrigName]);
01098 
01099      if(triggerNames.triggerIndex(hltTrgNames_[itrigName]) >= (unsigned int)ntrigs ) continue; 
01100 //    if( triggerResultsHLT->accept(triggerNames.triggerIndex(hltTrgNames_[itrigName])) )cout<<hltTrgNames_[itrigName]<<endl;
01101 
01102  }
01103     }
01104    } 
01105  // }
01106 */
01107   for(size_t i=0;i<hltTrgBits_.size();++i) {
01108     if (hltTrgBits_.at(i)<0) 
01109       continue; //ignore unknown trigger 
01110     size_t tbit = hltTrgBits_.at(i);
01111     if (tbit<triggerResultsHLT->size()) {
01112       hltTrgDeci_[i] = triggerResultsHLT->accept(tbit);
01113   }
01114  }
01115   // fill correlation histogram
01116   for(size_t i=0;i<hltTrgBits_.size();++i) {
01117     if (hltTrgDeci_.at(i))
01118       h2TrigCorr_->Fill(i,i);
01119     for(size_t j=i+1;j<hltTrgBits_.size();++j) {
01120       if (hltTrgDeci_.at(i) && hltTrgDeci_.at(j))
01121         h2TrigCorr_->Fill(i,j);
01122       if (hltTrgDeci_.at(i) && !hltTrgDeci_.at(j))
01123         h2TrigCorr_->Fill(j,i);
01124     }
01125   }
01126 }
01127 
01128 
01129 
01130 //--------------------------------------------------------------------------------------------------
01131