Go to the documentation of this file.00001 #include <memory>
00002 #include <string>
00003 #include <vector>
00004 #include <sstream>
00005 #include <fstream>
00006 #include <iostream>
00007
00008 #include <TH1F.h>
00009 #include <TROOT.h>
00010 #include <TFile.h>
00011 #include <TSystem.h>
00012
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "DataFormats/FWLite/interface/Event.h"
00015 #include "DataFormats/PatCandidates/interface/Muon.h"
00016 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00017 #include "DataFormats/FWLite/interface/Handle.h"
00018 #include "DataFormats/Common/interface/Handle.h"
00019 #include "PhysicsTools/FWLite/interface/TFileService.h"
00020 #include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h"
00021
00022
00023
00024 lorentzVector fromPtEtaPhiToPxPyPz( const double* ptEtaPhiE )
00025 {
00026 double muMass = 0.105658;
00027 double px = ptEtaPhiE[0]*cos(ptEtaPhiE[2]);
00028 double py = ptEtaPhiE[0]*sin(ptEtaPhiE[2]);
00029 double tmp = 2*atan(exp(-ptEtaPhiE[1]));
00030 double pz = ptEtaPhiE[0]*cos(tmp)/sin(tmp);
00031 double E = sqrt(px*px+py*py+pz*pz+muMass*muMass);
00032
00033
00034
00035
00036
00037 return lorentzVector(px,py,pz,E);
00038 }
00039
00040 int main(int argc, char* argv[])
00041 {
00042
00043 if( argc != 2 ) {
00044 std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
00045 exit(1);
00046 }
00047 std::string fileName(argv[1]);
00048 if( fileName.find("file:") != 0 && fileName.find("rfio:") != 0 ) {
00049 std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
00050 exit(1);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 gSystem->Load( "libFWCoreFWLite" );
00063 AutoLibraryLoader::enable();
00064
00065
00066 fwlite::TFileService fs = fwlite::TFileService("analyzeBasics.root");
00067 TFileDirectory theDir = fs.mkdir("analyzeBasic");
00068 TH1F* muonPt_ = theDir.make<TH1F>("muonPt", "pt", 100, 0.,300.);
00069 TH1F* muonEta_ = theDir.make<TH1F>("muonEta","eta", 100, -3., 3.);
00070 TH1F* muonPhi_ = theDir.make<TH1F>("muonPhi","phi", 100, -5., 5.);
00071
00072
00073 TFile* inFile = TFile::Open(fileName.c_str());
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 RootTreeHandler treeHandler;
00093
00094 std::vector<MuonPair> pairVector;
00095
00096
00097 unsigned int iEvent=0;
00098 fwlite::Event ev(inFile);
00099 for(ev.toBegin(); !ev.atEnd(); ++ev, ++iEvent){
00100
00101
00102 if(iEvent>0 && iEvent%100==0){
00103 std::cout << " processing event: " << iEvent << std::endl;
00104 }
00105
00106
00107 fwlite::Handle<std::vector<float> > muon1pt;
00108 fwlite::Handle<std::vector<float> > muon1eta;
00109 fwlite::Handle<std::vector<float> > muon1phi;
00110 fwlite::Handle<std::vector<float> > muon2pt;
00111 fwlite::Handle<std::vector<float> > muon2eta;
00112 fwlite::Handle<std::vector<float> > muon2phi;
00113 muon1pt.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Pt");
00114 muon1eta.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Eta");
00115 muon1phi.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau1Phi");
00116 muon2pt.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Pt");
00117 muon2eta.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Eta");
00118 muon2phi.getByLabel(ev, "goodZToMuMuEdmNtupleLoose", "zGoldenDau2Phi");
00119
00120 if( !muon1pt.isValid() ) continue;
00121 if( !muon1eta.isValid() ) continue;
00122 if( !muon1phi.isValid() ) continue;
00123 if( !muon2pt.isValid() ) continue;
00124 if( !muon2eta.isValid() ) continue;
00125 if( !muon2phi.isValid() ) continue;
00126
00127
00128
00129 if( muon1pt->size() != muon2pt->size() ) {
00130 std::cout << "Error: size of muon1 and muon2 is different. Skipping event" << std::endl;
00131 continue;
00132 }
00133 for(unsigned i=0; i<muon1pt->size(); ++i){
00134 muonPt_->Fill( (*muon1pt)[i] );
00135 muonEta_->Fill( (*muon1eta)[i] );
00136 muonPhi_->Fill( (*muon1phi)[i] );
00137 muonPt_->Fill( (*muon2pt)[i] );
00138 muonEta_->Fill( (*muon2eta)[i] );
00139 muonPhi_->Fill( (*muon2phi)[i] );
00140
00141 double muon1[3] = {(*muon1pt)[i], (*muon1eta)[i], (*muon1phi)[i]};
00142 double muon2[3] = {(*muon2pt)[i], (*muon2eta)[i], (*muon2phi)[i]};
00143
00144
00145 pairVector.push_back( MuonPair(fromPtEtaPhiToPxPyPz(muon1), fromPtEtaPhiToPxPyPz(muon2), 0, 0 ) );
00146 }
00147 }
00148 size_t namePos = fileName.find_last_of("/");
00149 treeHandler.writeTree(("tree_"+fileName.substr(namePos+1, fileName.size())).c_str(), &pairVector);
00150
00151
00152 inFile->Close();
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 return 0;
00164 }