CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoParticleFlow/Benchmark/src/PFMETBenchmark.cc

Go to the documentation of this file.
00001 #include "RecoParticleFlow/Benchmark/interface/PFMETBenchmark.h"
00002 //#include "TCanvas.h"
00003 #include "TProfile.h"
00004 #include "TF1.h"
00005 #include "TH1F.h"
00006 
00007 // preprocessor macro for booking 1d histos with DQMStore -or- bare Root
00008 #define BOOK1D(name,title,nbinsx,lowx,highx) \
00009   h##name = dbe_ ? dbe_->book1D(#name,title,nbinsx,lowx,highx)->getTH1F() \
00010     : new TH1F(#name,title,nbinsx,lowx,highx)
00011 
00012 // preprocessor macro for booking 2d histos with DQMStore -or- bare Root
00013 #define BOOK2D(name,title,nbinsx,lowx,highx,nbinsy,lowy,highy) \
00014   h##name = dbe_ ? dbe_->book2D(#name,title,nbinsx,lowx,highx,nbinsy,lowy,highy)->getTH2F() \
00015     : new TH2F(#name,title,nbinsx,lowx,highx,nbinsy,lowy,highy)
00016 
00017 // all versions OK
00018 // preprocesor macro for setting axis titles
00019 #define SETAXES(name,xtitle,ytitle) \
00020   h##name->GetXaxis()->SetTitle(xtitle); h##name->GetYaxis()->SetTitle(ytitle)
00021 
00022 
00023 /*#define SET2AXES(name,xtitle,ytitle) \
00024   hE##name->GetXaxis()->SetTitle(xtitle); hE##name->GetYaxis()->SetTitle(ytitle);  hB##name->GetXaxis()->SetTitle(xtitle); hB##name->GetYaxis()->SetTitle(ytitle)
00025 */
00026 
00027 #define PT (plotAgainstReco_)?"reconstructed P_{T}" :"generated P_{T}"
00028 
00029 using namespace reco;
00030 using namespace std;
00031 
00032 class MonitorElement;
00033 
00034 PFMETBenchmark::PFMETBenchmark() : file_(0) {}
00035 
00036 PFMETBenchmark::~PFMETBenchmark() {
00037   if(file_) file_->Close();
00038 }
00039 
00040 void PFMETBenchmark::write() {
00041    // Store the DAQ Histograms 
00042   if (outputFile_.size() != 0) {
00043     if (dbe_)
00044           dbe_->save(outputFile_.c_str());
00045     // use bare Root if no DQM (FWLite applications)
00046     else if (file_) {
00047        file_->Write(outputFile_.c_str());
00048        cout << "Benchmark output written to file " << outputFile_.c_str() << endl;
00049        file_->Close();
00050        }
00051   }
00052   else 
00053     cout << "No output file specified ("<<outputFile_<<"). Results will not be saved!" << endl;
00054     
00055 } 
00056 
00057 void PFMETBenchmark::setup(
00058                            string Filename,
00059                            bool debug, 
00060                            bool plotAgainstReco,
00061                            string benchmarkLabel_, 
00062                            DQMStore * dbe_store) {
00063   debug_ = debug; 
00064   plotAgainstReco_ = plotAgainstReco;
00065   outputFile_=Filename;
00066   file_ = NULL;
00067   dbe_ = dbe_store;
00068   // print parameters
00069   //cout<< "PFMETBenchmark Setup parameters =============================================="<<endl;
00070   cout << "Filename to write histograms " << Filename<<endl;
00071   cout << "PFMETBenchmark debug " << debug_<< endl;
00072   cout << "plotAgainstReco " << plotAgainstReco_ << endl;
00073   cout << "benchmarkLabel " << benchmarkLabel_ << endl;
00074   
00075   // Book histogram
00076 
00077   // Establish DQM Store
00078   string path = "PFTask/Benchmarks/"+ benchmarkLabel_ + "/";
00079   if (plotAgainstReco) path += "Reco"; else path += "Gen";
00080   if (dbe_) {
00081     dbe_->setCurrentFolder(path.c_str());
00082   }
00083   else {
00084     file_ = new TFile(outputFile_.c_str(), "recreate");
00085 //    TTree * tr = new TTree("PFTast");
00086 //    tr->Branch("Benchmarks/ParticleFlow")
00087     cout << "Info: DQM is not available to provide data storage service. Using TFile to save histograms. "<<endl;
00088   }
00089 
00090   // delta Pt or E quantities for Barrel
00091   BOOK1D(MEX,"Particle Flow",400,-200,200);
00092   BOOK1D(DeltaMEX,"Particle Flow",400,-200,200);
00093   BOOK1D(DeltaMET,"Particle Flow",400,-200,200);
00094   BOOK1D(DeltaPhi,"Particle Flow", 1000, -3.2, 3.2);
00095   BOOK1D(DeltaSET,"Particle Flow",400,-200,200);
00096   BOOK2D(SETvsDeltaMET,"Particle Flow",200, 0.0, 1000.0, 400, -200.0, 200.0);        
00097   BOOK2D(SETvsDeltaSET,"Particle Flow",200, 0.0, 1000.0, 400, -200.0, 200.0);       
00098   profileSETvsSETresp = new TProfile("#DeltaPFSET / trueSET vs trueSET", "", 200, 0.0, 1000.0, -1.0, 1.0);
00099   profileMETvsMETresp = new TProfile("#DeltaPFMET / trueMET vs trueMET", "", 50, 0.0,  200.0, -1.0, 1.0);
00100         
00101   BOOK1D(CaloMEX,"Calorimeter",400,-200,200);
00102   BOOK1D(DeltaCaloMEX,"Calorimeter",400,-200,200);
00103   BOOK1D(DeltaCaloMET,"Calorimeter",400,-200,200);
00104   BOOK1D(DeltaCaloPhi,"Calorimeter", 1000, -3.2, 3.2);
00105   BOOK1D(DeltaCaloSET,"Calorimeter",400,-200,200);
00106   BOOK2D(CaloSETvsDeltaCaloMET,"Calorimeter",200, 0.0, 1000.0, 400, -200.0, 200.0);        
00107   BOOK2D(CaloSETvsDeltaCaloSET,"Calorimeter",200, 0.0, 1000.0, 400, -200.0, 200.0);       
00108   profileCaloSETvsCaloSETresp = new TProfile("#DeltaCaloSET / trueSET vs trueSET", "", 200, 0.0, 1000.0, -1.0, 1.0);
00109   profileCaloMETvsCaloMETresp = new TProfile("#DeltaCaloMET / trueMET vs trueMET", "", 200, 0.0,  200.0, -1.0, 1.0);
00110 
00111   BOOK2D(DeltaPFMETvstrueMET,"Particle Flow", 500, 0.0, 1000.0, 400, -200.0, 200.0);      
00112   BOOK2D(DeltaCaloMETvstrueMET,"Calorimeter", 500, 0.0, 1000.0, 400, -200.0, 200.0);      
00113   BOOK2D(DeltaPFPhivstrueMET,"Particle Flow", 500, 0.0, 1000.0, 400, -3.2, 3.2);      
00114   BOOK2D(DeltaCaloPhivstrueMET,"Calorimeter", 500, 0.0, 1000.0, 400, -3.2, 3.2);      
00115   BOOK2D(CaloMETvstrueMET,"Calorimeter", 500, 0.0, 1000.0, 500, 0.0, 1000.0);      
00116   BOOK2D(PFMETvstrueMET,"Particle Flow", 500, 0.0, 1000.0, 500, 0.0, 1000.0);
00117 
00118   BOOK2D(DeltaCaloMEXvstrueSET,"Calorimeter",200, 0.0, 1000.0, 400, -200.0, 200.0);
00119   BOOK2D(DeltaPFMEXvstrueSET,"Particle Flow",200, 0.0, 1000.0, 400, -200.0, 200.0);
00120    
00121   BOOK1D(TrueMET,"MC truth", 500, 0.0, 1000.0);      
00122   BOOK1D(CaloMET,"Calorimeter", 500, 0.0, 1000.0);
00123   BOOK1D(PFMET,"Particle Flow", 500, 0.0, 1000.0);
00124 
00125   BOOK1D(TCMEX,"Track Corrected",400,-200,200);
00126   BOOK1D(DeltaTCMEX,"Track Corrected",400,-200,200);
00127   BOOK1D(DeltaTCMET,"Track Corrected",400,-200,200);
00128   BOOK1D(DeltaTCPhi,"Track Corrected", 1000, -3.2, 3.2);
00129   BOOK1D(DeltaTCSET,"Track Corrected",400,-200,200);
00130   BOOK2D(TCSETvsDeltaTCMET,"Track Corrected",200, 0.0, 1000.0, 400, -200.0, 200.0);        
00131   BOOK2D(TCSETvsDeltaTCSET,"Track Corrected",200, 0.0, 1000.0, 400, -200.0, 200.0);       
00132   profileTCSETvsTCSETresp = new TProfile("#DeltaTCSET / trueSET vs trueSET", "", 200, 0.0, 1000.0, -1.0, 1.0);
00133   profileTCMETvsTCMETresp = new TProfile("#DeltaTCMET / trueMET vs trueMET", "", 200, 0.0,  200.0, -1.0, 1.0);
00134         
00135   BOOK1D(TCMET,"Track Corrected",500,0,1000);
00136   BOOK2D(DeltaTCMETvstrueMET,"Track Corrected", 500, 0.0, 1000.0, 400, -200.0, 200.0);
00137   BOOK2D(DeltaTCPhivstrueMET,"Track Corrected", 500, 0.0, 1000.0, 400, -3.2, 3.2);
00138 
00139   BOOK2D(DeltaTCMEXvstrueSET,"Track Corrected", 200, 0.0, 1000.0, 400, -200.0, 200.0);
00140   BOOK2D(TCMETvstrueMET,"Track Corrected", 200, 0.0, 1000.0, 500, 0.0, 1000.0);
00141 
00142   //BOOK1D(meanPF,    "Mean PFMEX", 100, 0.0, 1600.0);
00143   //BOOK1D(meanCalo,  "Mean CaloMEX", 100, 0.0, 1600.0);
00144   //BOOK1D(sigmaPF,   "#sigma(PFMEX)", 100, 0.0, 1600.0);
00145   //BOOK1D(sigmaCalo, "#sigma(CaloMEX)", 100, 0.0, 1600.0);
00146   //BOOK1D(rmsPF,     "RMS(PFMEX)", 100, 0.0, 1600.0);
00147   //BOOK1D(rmsCalo,   "RMS(CaloMEX)", 100, 0.0, 1600.0);
00148 
00149   // Set Axis Titles
00150   // delta Pt or E quantities for Barrel and Endcap
00151   SETAXES(MEX, "MEX",  "Events");
00152   SETAXES(DeltaMEX, "#DeltaMEX",  "Events");
00153   SETAXES(DeltaMET, "#DeltaMET",  "Events");
00154   SETAXES(DeltaPhi, "#Delta#phi", "Events");
00155   SETAXES(DeltaSET, "#DeltaSET",  "Events");
00156   SETAXES(SETvsDeltaMET, "SET", "#DeltaMET");
00157   SETAXES(SETvsDeltaSET, "SET", "#DeltaSET");
00158 
00159   SETAXES(DeltaPFMETvstrueMET, "trueMET", "#DeltaMET");
00160   SETAXES(DeltaCaloMETvstrueMET, "trueMET", "#DeltaCaloMET");
00161   SETAXES(DeltaPFPhivstrueMET, "trueMET", "#DeltaPFPhi");
00162   SETAXES(DeltaCaloPhivstrueMET, "trueMET", "#DeltaCaloPhi");
00163   SETAXES(CaloMETvstrueMET, "trueMET", "CaloMET");
00164   SETAXES(PFMETvstrueMET, "trueMET", "PFMET");
00165   SETAXES(DeltaCaloMEXvstrueSET, "trueSET", "#DeltaCaloMEX");
00166   SETAXES(DeltaPFMEXvstrueSET, "trueSET", "#DeltaPFMEX");
00167   SETAXES(TrueMET, "trueMET", "Events");
00168   SETAXES(CaloMET, "CaloMET", "Events");
00169   SETAXES(PFMET, "PFMET", "Events");
00170   SETAXES(TCMET, "TCMET", "Events");
00171 
00172   SETAXES(CaloMEX, "MEX",  "Events");
00173   SETAXES(DeltaCaloMEX, "#DeltaMEX",  "Events");
00174   SETAXES(DeltaCaloMET, "#DeltaMET",  "Events");
00175   SETAXES(DeltaCaloPhi, "#Delta#phi", "Events");
00176   SETAXES(DeltaCaloSET, "#DeltaSET",  "Events");
00177   SETAXES(CaloSETvsDeltaCaloMET, "SET", "#DeltaMET");
00178   SETAXES(CaloSETvsDeltaCaloSET, "SET", "#DeltaSET");
00179 
00180   SETAXES(TCMEX, "MEX",  "Events");
00181   SETAXES(DeltaTCMEX, "#DeltaMEX",  "Events");
00182   SETAXES(DeltaTCMET, "#DeltaMET",  "Events");
00183   SETAXES(DeltaTCPhi, "#Delta#phi", "Events");
00184   SETAXES(DeltaTCSET, "#DeltaSET",  "Events");
00185   SETAXES(TCSETvsDeltaTCMET, "SET", "#DeltaMET");
00186   SETAXES(TCSETvsDeltaTCSET, "SET", "#DeltaSET");
00187 
00188   SETAXES(DeltaTCMETvstrueMET, "trueMET", "#DeltaTCMET");
00189   SETAXES(DeltaTCPhivstrueMET, "trueMET", "#DeltaTCPhi");
00190 
00191   SETAXES(DeltaTCMEXvstrueSET, "trueSET", "#DeltaTCMEX");
00192   SETAXES(TCMETvstrueMET, "trueMET", "TCMET");
00193 }
00194 
00195 
00196 //void PFMETBenchmark::process(const reco::PFMETCollection& pfMets, const reco::GenMETCollection& genMets) {
00197 void PFMETBenchmark::process( const reco::PFMETCollection& pfMets, 
00198                               const reco::GenParticleCollection& genParticleList, 
00199                               const reco::CaloMETCollection& caloMets,
00200                               const reco::METCollection& tcMets ) {
00201   calculateQuantities(pfMets, genParticleList, caloMets, tcMets);
00202   if (debug_) {
00203     cout << "  =========PFMET  " << rec_met  << ", " << rec_phi  << endl;
00204     cout << "  =========GenMET " << true_met << ", " << true_phi << endl;
00205     cout << "  =========CaloMET " << calo_met << ", " << calo_phi << endl;
00206     cout << "  =========TCMET " << tc_met << ", " << tc_phi << endl;
00207   }                     
00208   // fill histograms
00209   hTrueMET->Fill(true_met);
00210   // delta Pt or E quantities
00211   // PF
00212   hDeltaMET->Fill( rec_met - true_met );
00213   hMEX->Fill( rec_mex );
00214   hMEX->Fill( rec_mey );
00215   hDeltaMEX->Fill( rec_mex - true_mex );
00216   hDeltaMEX->Fill( rec_mey - true_mey );
00217   hDeltaPhi->Fill( rec_phi - true_phi );
00218   hDeltaSET->Fill( rec_set - true_set );
00219   if( true_met > 5.0 ) hSETvsDeltaMET->Fill( rec_set, rec_met - true_met );
00220   else                 hSETvsDeltaMET->Fill( rec_set, rec_mex - true_mex );
00221   hSETvsDeltaSET->Fill( rec_set, rec_set - true_set );
00222   if( true_met > 5.0 ) profileMETvsMETresp->Fill(true_met, (rec_met-true_met)/true_met);
00223   profileSETvsSETresp->Fill(true_set, (rec_set-true_set)/true_set);
00224 
00225   hDeltaPFMETvstrueMET->Fill(true_met, rec_met - true_met);
00226   hDeltaPFPhivstrueMET->Fill(true_met, rec_phi - true_phi);
00227   hPFMETvstrueMET->Fill(true_met, rec_met);
00228   hPFMET->Fill(rec_met);
00229 
00230   hDeltaPFMEXvstrueSET->Fill(true_set, rec_mex - true_mex);
00231   hDeltaPFMEXvstrueSET->Fill(true_set, rec_mey - true_mey);
00232 
00233   // Calo
00234   hDeltaCaloMET->Fill( calo_met - true_met );
00235   hCaloMEX->Fill( calo_mex );
00236   hCaloMEX->Fill( calo_mey );
00237   hDeltaCaloMEX->Fill( calo_mex - true_mex);
00238   hDeltaCaloMEX->Fill( calo_mey - true_mey);
00239   hDeltaCaloPhi->Fill( calo_phi - true_phi );
00240   hDeltaCaloSET->Fill( calo_set - true_set );
00241   if( true_met > 5.0 ) hCaloSETvsDeltaCaloMET->Fill( calo_set, calo_met - true_met );
00242   else                 hCaloSETvsDeltaCaloMET->Fill( calo_set, calo_mex - true_mex);
00243   hCaloSETvsDeltaCaloSET->Fill( calo_set, calo_set - true_set );
00244   if( true_met > 5.0 ) profileCaloMETvsCaloMETresp->Fill(true_met, (calo_met-true_met)/true_met);
00245   profileCaloSETvsCaloSETresp->Fill(true_set, (calo_set-true_set)/true_set);
00246 
00247   hDeltaCaloMETvstrueMET->Fill(true_met, calo_met - true_met);
00248   hDeltaCaloPhivstrueMET->Fill(true_met, calo_phi - true_phi);
00249   hCaloMETvstrueMET->Fill(true_met, calo_met);
00250   hCaloMET->Fill(calo_met);
00251 
00252   hDeltaCaloMEXvstrueSET->Fill(true_set, calo_mex - true_mex);
00253   hDeltaCaloMEXvstrueSET->Fill(true_set, calo_mey - true_mey);
00254 
00255   // TC
00256   hDeltaTCMET->Fill( tc_met - true_met );
00257   hTCMET->Fill( tc_met );
00258   hTCMEX->Fill( tc_mex );
00259   hTCMEX->Fill( tc_mey );
00260   hDeltaTCMEX->Fill( tc_mex - true_mex);
00261   hDeltaTCMEX->Fill( tc_mey - true_mey);
00262   hDeltaTCPhi->Fill( tc_phi - true_phi );
00263   hDeltaTCSET->Fill( tc_set - true_set );
00264   if( true_met > 5.0 ) hTCSETvsDeltaTCMET->Fill( tc_set, tc_met - true_met );
00265   else                 hTCSETvsDeltaTCMET->Fill( tc_set, tc_mex - true_mex);
00266   hTCSETvsDeltaTCSET->Fill( tc_set, tc_set - true_set );
00267   if( true_met > 5.0 ) profileTCMETvsTCMETresp->Fill(true_met, (tc_met-true_met)/true_met);
00268   profileTCSETvsTCSETresp->Fill(true_set, (tc_set-true_set)/true_set);
00269 
00270   hDeltaTCMETvstrueMET->Fill( true_met, tc_met - true_met);
00271   hDeltaTCPhivstrueMET->Fill( true_met, tc_phi - true_phi);
00272   hDeltaTCMEXvstrueSET->Fill( true_set, tc_mex - true_mex);
00273   hDeltaTCMEXvstrueSET->Fill( true_set, tc_mey - true_mey);
00274   hTCMETvstrueMET->Fill( true_met, tc_met );
00275 
00276 }
00277 
00278 void PFMETBenchmark::calculateQuantities( const reco::PFMETCollection& pfMets, 
00279                                           const reco::GenParticleCollection& genParticleList, 
00280                                           const reco::CaloMETCollection& caloMets,
00281                                           const reco::METCollection& tcMets) 
00282 {
00283   const reco::PFMET&    pfm = pfMets[0];
00284   const reco::CaloMET&  cm  = caloMets[0];
00285   const reco::MET&  tcm  = tcMets[0];
00286 
00287   double trueMEY  = 0.0;
00288   double trueMEX  = 0.0;;
00289   true_set  = 0.0;;
00290 
00291   //  for( genParticle = genParticleList.begin(); genParticle != genParticleList.end(); genParticle++ )
00292   for( unsigned i = 0; i < genParticleList.size(); i++ ) {
00293     if( genParticleList[i].status() == 1 && fabs(genParticleList[i].eta()) < 5.0 ) { 
00294       if( std::abs(genParticleList[i].pdgId()) == 12 ||
00295           std::abs(genParticleList[i].pdgId()) == 14 ||
00296           std::abs(genParticleList[i].pdgId()) == 16 || 
00297           std::abs(genParticleList[i].pdgId()) < 7   || 
00298           std::abs(genParticleList[i].pdgId()) == 21 ) {
00299         trueMEX += genParticleList[i].px();
00300         trueMEY += genParticleList[i].py();
00301       } else {
00302         true_set += genParticleList[i].pt();
00303       }
00304     }
00305   }
00306   true_mex = -trueMEX;
00307   true_mey = -trueMEY;
00308   true_met = sqrt( trueMEX*trueMEX + trueMEY*trueMEY );
00309   true_phi = atan2(trueMEY,trueMEX);
00310   rec_met  = pfm.pt();
00311   rec_mex  = pfm.px();
00312   rec_mex  = pfm.py();
00313   rec_phi  = pfm.phi();
00314   rec_set  = pfm.sumEt();
00315   calo_met = cm.pt();
00316   calo_mex = cm.px();
00317   calo_mey = cm.py();
00318   calo_phi = cm.phi();
00319   calo_set = cm.sumEt();
00320   tc_met = tcm.pt();
00321   tc_mex = tcm.px();
00322   tc_mey = tcm.py();
00323   tc_phi = tcm.phi();
00324   tc_set = tcm.sumEt();
00325 
00326   if (debug_) {
00327     cout << "  =========PFMET  " << rec_met  << ", " << rec_phi  << endl;
00328     cout << "  =========trueMET " << true_met << ", " << true_phi << endl;
00329     cout << "  =========CaloMET " << calo_met << ", " << calo_phi << endl;
00330     cout << "  =========TCMET " << tc_met << ", " << tc_phi << endl;
00331   }                     
00332 }
00333 
00334 void PFMETBenchmark::calculateQuantities( const reco::PFMETCollection& pfMets, 
00335                                           const reco::GenParticleCollection& genParticleList, 
00336                                           const reco::CaloMETCollection& caloMets,
00337                                           const reco::METCollection& tcMets,
00338                                           const std::vector<reco::CaloJet> caloJets,
00339                                           const std::vector<reco::CaloJet> corr_caloJets) 
00340 {
00341   const reco::PFMET&    pfm = pfMets[0];
00342   const reco::CaloMET&  cm  = caloMets[0];
00343   const reco::MET&  tcm  = tcMets[0];
00344 
00345   double trueMEY  = 0.0;
00346   double trueMEX  = 0.0;;
00347   true_set  = 0.0;;
00348 
00349   //  for( genParticle = genParticleList.begin(); genParticle != genParticleList.end(); genParticle++ )
00350   for( unsigned i = 0; i < genParticleList.size(); i++ ) {
00351     if( genParticleList[i].status() == 1 && fabs(genParticleList[i].eta()) < 5.0 ) { 
00352       if( std::abs(genParticleList[i].pdgId()) == 12 ||
00353           std::abs(genParticleList[i].pdgId()) == 14 ||
00354           std::abs(genParticleList[i].pdgId()) == 16 || 
00355           std::abs(genParticleList[i].pdgId()) < 7   || 
00356           std::abs(genParticleList[i].pdgId()) == 21 ) {
00357         trueMEX += genParticleList[i].px();
00358         trueMEY += genParticleList[i].py();
00359       } else {
00360         true_set += genParticleList[i].pt();
00361       }
00362     }
00363   }
00364   true_mex = -trueMEX;
00365   true_mey = -trueMEY;
00366   true_met = sqrt( trueMEX*trueMEX + trueMEY*trueMEY );
00367   true_phi = atan2(trueMEY,trueMEX);
00368   rec_met  = pfm.pt();
00369   rec_mex  = pfm.px();
00370   rec_mex  = pfm.py();
00371   rec_phi  = pfm.phi();
00372   rec_set  = pfm.sumEt();
00373 
00374   // propagation of the JEC to the caloMET:
00375   double caloJetCorPX = 0.0;
00376   double caloJetCorPY = 0.0;
00377 
00378   for(unsigned int caloJetc=0;caloJetc<caloJets.size();++caloJetc)
00379   {
00380     //std::cout << "caloJets[" << caloJetc << "].pt() = " << caloJets[caloJetc].pt() << std::endl;
00381     //std::cout << "caloJets[" << caloJetc << "].phi() = " << caloJets[caloJetc].phi() << std::endl;
00382     //std::cout << "caloJets[" << caloJetc << "].eta() = " << caloJets[caloJetc].eta() << std::endl;
00383     //}
00384     for(unsigned int corr_caloJetc=0;corr_caloJetc<corr_caloJets.size();++corr_caloJetc)
00385     {
00386       //std::cout << "corr_caloJets[" << corr_caloJetc << "].pt() = " << corr_caloJets[corr_caloJetc].pt() << std::endl;
00387       //std::cout << "corr_caloJets[" << corr_caloJetc << "].phi() = " << corr_caloJets[corr_caloJetc].phi() << std::endl;
00388       //std::cout << "corr_caloJets[" << corr_caloJetc << "].eta() = " << corr_caloJets[corr_caloJetc].eta() << std::endl;
00389       //}
00390       Float_t DeltaPhi = corr_caloJets[corr_caloJetc].phi() - caloJets[caloJetc].phi();
00391       Float_t DeltaEta = corr_caloJets[corr_caloJetc].eta() - caloJets[caloJetc].eta();
00392       Float_t DeltaR2 = DeltaPhi*DeltaPhi + DeltaEta*DeltaEta;
00393       if( DeltaR2 < 0.0001 && caloJets[caloJetc].pt() > 20.0 ) 
00394       {
00395         caloJetCorPX += (corr_caloJets[corr_caloJetc].px() - caloJets[caloJetc].px());
00396         caloJetCorPY += (corr_caloJets[corr_caloJetc].py() - caloJets[caloJetc].py());
00397       }
00398     }
00399   }
00400   double corr_calomet=sqrt((cm.px()-caloJetCorPX)*(cm.px()-caloJetCorPX)+(cm.py()-caloJetCorPY)*(cm.py()-caloJetCorPY));
00401   calo_met = corr_calomet;
00402   calo_mex = cm.px()-caloJetCorPX;
00403   calo_mey = cm.py()-caloJetCorPY;
00404   calo_phi = atan2((cm.py()-caloJetCorPY),(cm.px()-caloJetCorPX));
00405   //calo_met = cm.pt();
00406   //calo_mex = cm.px();
00407   //calo_mey = cm.py();
00408   //calo_phi = cm.phi();
00409 
00410   calo_set = cm.sumEt();
00411   tc_met = tcm.pt();
00412   tc_mex = tcm.px();
00413   tc_mey = tcm.py();
00414   tc_phi = tcm.phi();
00415   tc_set = tcm.sumEt();
00416 
00417   if (debug_) {
00418     cout << "  =========PFMET  " << rec_met  << ", " << rec_phi  << endl;
00419     cout << "  =========trueMET " << true_met << ", " << true_phi << endl;
00420     cout << "  =========CaloMET " << calo_met << ", " << calo_phi << endl;
00421     cout << "  =========TCMET " << tc_met << ", " << tc_phi << endl;
00422   }                     
00423 }
00424 
00425 //double fitf(double *x, double *par)
00426 //{
00427 //  double fitval = sqrt( par[0]*par[0] + 
00428 //                      par[1]*par[1]*(x[0]-par[3]) + 
00429 //                      par[2]*par[2]*(x[0]-par[3])*(x[0]-par[3]) );
00430 //  return fitval;
00431 //}
00432 
00433 void PFMETBenchmark::analyse() 
00434 {
00435   //Define fit functions and histograms
00436   //TF1* func1 = new TF1("fit1", fitf, 0, 40, 4);
00437   //TF1* func2 = new TF1("fit2", fitf, 0, 40, 4);
00438   //TF1* func3 = new TF1("fit3", fitf, 0, 40, 4);
00439   //TF1* func4 = new TF1("fit4", fitf, 0, 40, 4);
00440 
00441   //fit gaussian to Delta MET corresponding to different slices in MET, store fit values (mean,sigma) in histos
00446 
00453 
00454   // Make the MET resolution versus SET plot
00455   /*
00456   TCanvas* canvas_MetResVsRecoSet = new TCanvas("MetResVsRecoSet", "MET Sigma vs Reco SET", 500,500);
00457   hsigmaPF->SetStats(0); 
00458   func1->SetLineColor(1); 
00459   func1->SetParNames("Noise", "Stochastic", "Constant", "Offset");
00460   func1->SetParameters(10.0, 0.8, 0.1, 100.0);
00461   hsigmaPF->Fit("fit1", "", "", 100.0, 900.0);
00462   func2->SetLineColor(2); 
00463   func2->SetParNames("Noise", "Stochastic", "Constant", "Offset");
00464   func2->SetParameters(10.0, 0.8, 0.1, 100.0);
00465   hsigmaCalo->Fit("fit2", "", "", 100.0, 900.0);
00466   func3->SetLineColor(4); 
00467   func3->SetParNames("Noise", "Stochastic", "Constant", "Offset");
00468   func3->SetParameters(10.0, 0.8, 0.1, 100.0);
00469   hrmsPF->Fit("fit3", "", "", 100.0, 900.0);
00470   func4->SetLineColor(6); 
00471   func4->SetParNames("Noise", "Stochastic", "Constant", "Offset");
00472   func4->SetParameters(10.0, 0.8, 0.1, 100.0);
00473   hrmsCalo->Fit("fit4", "", "", 100.0, 900.0);
00474   (hsigmaPF->GetYaxis())->SetRangeUser( 0.0, 50.0);
00475   hsigmaPF->SetLineWidth(2); 
00476   hsigmaPF->SetLineColor(1); 
00477   hsigmaPF->Draw();
00478   hsigmaCalo->SetLineWidth(2);
00479   hsigmaCalo->SetLineColor(2);
00480   hsigmaCalo->Draw("SAME");
00481   hrmsPF->SetLineWidth(2);
00482   hrmsPF->SetLineColor(4);
00483   hrmsPF->Draw("SAME");  
00484   hrmsCalo->SetLineWidth(2);
00485   hrmsCalo->SetLineColor(6);
00486   hrmsCalo->Draw("SAME");
00487   */
00488 
00489   // Make the SET response versus SET plot
00490   /*
00491   TCanvas* canvas_SetRespVsTrueSet = new TCanvas("SetRespVsTrueSet", "SET Response vs True SET", 500,500);
00492   profileSETvsSETresp->SetStats(0); 
00493   profileSETvsSETresp->SetStats(0); 
00494   (profileSETvsSETresp->GetYaxis())->SetRangeUser(-1.0, 1.0);
00495   profileSETvsSETresp->SetLineWidth(2); 
00496   profileSETvsSETresp->SetLineColor(4); 
00497   profileSETvsSETresp->Draw();
00498   profileCaloSETvsCaloSETresp->SetLineWidth(2); 
00499   profileCaloSETvsCaloSETresp->SetLineColor(2); 
00500   profileCaloSETvsCaloSETresp->Draw("SAME");
00501   */
00502 
00503   // Make the MET response versus MET plot
00504   /*
00505   TCanvas* canvas_MetRespVsTrueMet = new TCanvas("MetRespVsTrueMet", "MET Response vs True MET", 500,500);
00506   profileMETvsMETresp->SetStats(0); 
00507   profileMETvsMETresp->SetStats(0); 
00508   (profileMETvsMETresp->GetYaxis())->SetRangeUser(-1.0, 1.0);
00509   profileMETvsMETresp->SetLineWidth(2); 
00510   profileMETvsMETresp->SetLineColor(4); 
00511   profileMETvsMETresp->Draw();
00512   profileCaloMETvsCaloMETresp->SetLineWidth(2); 
00513   profileCaloMETvsCaloMETresp->SetLineColor(2); 
00514   profileCaloMETvsCaloMETresp->Draw("SAME");
00515   */
00516 
00517   //print the resulting plots to file
00518   /*
00519   canvas_MetResVsRecoSet->Print("MetResVsRecoSet.ps");
00520   canvas_SetRespVsTrueSet->Print("SetRespVsTrueSet.ps");
00521   canvas_MetRespVsTrueMet->Print("MetRespVsTrueMet.ps");  
00522   */
00523 }
00524 
00525 //void PFMETBenchmark::FitSlicesInY(TH2F* h, TH1F* mean, TH1F* sigma, bool doGausFit, int type )
00526 //{
00527 //  TAxis *fXaxis = h->GetXaxis();
00528 //  TAxis *fYaxis = h->GetYaxis();
00529 //  Int_t nbins  = fXaxis->GetNbins();
00530 //
00531 //  //std::cout << "nbins = " << nbins << std::endl;
00532 //
00533 //  Int_t binmin = 1;
00534 //  Int_t binmax = nbins;
00535 //  TString option = "QNR";
00536 //  TString opt = option;
00537 //  opt.ToLower();
00538 //  Float_t ngroup = 1;
00539 //  ngroup = 1;
00540 //
00541 //  //std::cout << "fYaxis->GetXmin() = " << fYaxis->GetXmin() << std::endl;
00542 //  //std::cout << "fYaxis->GetXmax() = " << fYaxis->GetXmax() << std::endl;
00543 //
00544 //  //default is to fit with a gaussian
00545 //  TF1 *f1 = 0;
00546 //  if (f1 == 0) 
00547 //    {
00548 //      //f1 = (TF1*)gROOT->GetFunction("gaus");
00549 //      if (f1 == 0) f1 = new TF1("gaus","gaus", fYaxis->GetXmin(), fYaxis->GetXmax());
00550 //      else         f1->SetRange( fYaxis->GetXmin(), fYaxis->GetXmax());
00551 //    }
00552 //  Int_t npar = f1->GetNpar();
00553 //
00554 //  //std::cout << "npar = " << npar << std::endl;
00555 //
00556 //  if (npar <= 0) return;
00557 //
00558 //  Double_t *parsave = new Double_t[npar];
00559 //  f1->GetParameters(parsave);
00560 //
00562 //  Int_t ipar;
00563 //  TH1F **hlist = new TH1F*[npar];
00564 //  char *name   = new char[2000];
00565 //  char *title  = new char[2000];
00566 //  const TArrayD *bins = fXaxis->GetXbins();
00567 //  for( ipar=0; ipar < npar; ipar++ ) 
00568 //    {
00569 //      if( ipar == 1 ) 
00570 //      if( type == 1 )   sprintf(name,"meanPF");
00571 //      else              sprintf(name,"meanCalo");
00572 //      else
00573 //      if( doGausFit ) 
00574 //        if( type == 1 ) sprintf(name,"sigmaPF");
00575 //        else            sprintf(name,"sigmaCalo");
00576 //      else 
00577 //        if( type == 1 ) sprintf(name,"rmsPF");
00578 //        else            sprintf(name,"rmsCalo");
00579 //      if( type == 1 )     sprintf(title,"Particle Flow");
00580 //      else                sprintf(title,"Calorimeter");
00581 //      delete gDirectory->FindObject(name);
00582 //      if (bins->fN == 0) 
00583 //      hlist[ipar] = new TH1F(name,title, nbins, fXaxis->GetXmin(), fXaxis->GetXmax());
00584 //      else
00585 //      hlist[ipar] = new TH1F(name,title, nbins,bins->fArray);
00586 //      hlist[ipar]->GetXaxis()->SetTitle(fXaxis->GetTitle());
00587 //    }
00588 //  sprintf(name,"test_chi2");
00589 //  delete gDirectory->FindObject(name);
00590 //  TH1F *hchi2 = new TH1F(name,"chisquare", nbins, fXaxis->GetXmin(), fXaxis->GetXmax());
00591 //  hchi2->GetXaxis()->SetTitle(fXaxis->GetTitle());
00592 //
00593 //  //Loop on all bins in X, generate a projection along Y
00594 //  Int_t bin;
00595 //  Int_t nentries;
00596 //  for( bin = (Int_t) binmin; bin <= (Int_t) binmax; bin += (Int_t)ngroup ) 
00597 //    {
00598 //      TH1F *hpy = (TH1F*) h->ProjectionY("_temp", (Int_t) bin, (Int_t) (bin + ngroup - 1), "e");
00599 //      if(hpy == 0) continue;
00600 //      nentries = Int_t( hpy->GetEntries() );
00601 //      if(nentries == 0 ) {delete hpy; continue;}
00602 //      f1->SetParameters(parsave);
00603 //      hpy->Fit( f1, opt.Data() );
00604 //      Int_t npfits = f1->GetNumberFitPoints(); 
00605 //      //cout << "bin = " << bin << "; Npfits = " << npfits << "; npar = " << npar << endl;
00606 //      if( npfits > npar ) 
00607 //      {
00608 //        Int_t biny = bin + (Int_t)ngroup/2;
00609 //        for( ipar=0; ipar < npar; ipar++ ) 
00610 //          {
00611 //            if( doGausFit ) hlist[ipar]->Fill( fXaxis->GetBinCenter(biny), f1->GetParameter(ipar) );
00612 //            else            hlist[ipar]->Fill( fXaxis->GetBinCenter(biny), hpy->GetRMS() );
00613 //            //cout << "bin[" << bin << "]: RMS = " << hpy->GetRMS() << "; sigma = " << f1->GetParameter(ipar) << endl;
00614 //            hlist[ipar]->SetBinError( biny, f1->GetParError(ipar) );
00615 //          }
00616 //        hchi2->Fill( fXaxis->GetBinCenter(biny), f1->GetChisquare()/(npfits-npar) );
00617 //      }
00618 //      delete hpy;
00619 //      ngroup += ngroup*0.2;//0.1  //used for non-uniform binning
00620 //    }
00621 //  *mean = *hlist[1];
00622 //  *sigma = *hlist[2];
00623 //  cout << "Entries = " << hlist[0]->GetEntries() << endl;
00624 //}
00625 
00626 double   
00627 PFMETBenchmark::mpi_pi(double angle) {
00628 
00629   const double pi = 3.14159265358979323;
00630   const double pi2 = pi*2.;
00631   while(angle>pi) angle -= pi2;
00632   while(angle<-pi) angle += pi2;
00633   return angle;
00634 
00635 }