29 void writeTree(
const TString &
fileName,
const std::vector<MuonPair> * savedPair,
const int muonType = 0,
30 const std::vector<GenMuonPair> * genPair = 0,
const bool saveAll =
false )
33 TFile *
f1 =
new TFile(fileName,
"RECREATE");
34 TTree *
tree =
new TTree(
"T",
"Muon pairs");
38 tree->Branch(
"event",
"MuonPair", &muonPair);
40 tree->Branch(
"genEvent",
"GenMuonPair", &genMuonPair);
43 if( savedPair->size() != genPair->size() ) {
45 << savedPair->size() <<
") and genPair size ("
46 << genPair->size() <<
") are different. This is severe and I will not write the tree." << std::endl;
50 std::cout <<
"savedPair->size() is "<<savedPair->size()<< std::endl;
51 std::vector<MuonPair>::const_iterator muonPairIt = savedPair->begin();
53 for( ; muonPairIt != savedPair->end(); ++muonPairIt, ++iev ) {
55 if( saveAll || ( (muonPairIt->mu1.p4() != emptyLorentzVector) && (muonPairIt->mu2.p4() != emptyLorentzVector) ) ) {
58 muonPair->
copy(*muonPairIt);
66 genMuonPair->
copy((*genPair)[iev]);
76 TH1F muonTypeHisto(
"MuonType",
"MuonType", 40, -20, 20);
77 muonTypeHisto.Fill(muonType);
78 muonTypeHisto.Write();
89 const int muonType, std::vector<std::pair<unsigned int, unsigned long long> > * evtRun,
MuonPairVector * genPair = 0)
91 TFile *
file = TFile::Open(fileName,
"READ");
93 TTree *
tree = (TTree*)file->Get(
"T");
97 tree->SetBranchAddress(
"event", &muonPair);
99 tree->SetBranchAddress(
"genEvent", &genMuonPair);
102 Long64_t nentries = tree->GetEntries();
103 if ((maxEvents != -1) && (nentries > maxEvents)) nentries =
maxEvents;
104 for (Long64_t
i=0;
i<nentries; ++
i) {
107 savedPair->push_back(std::make_pair(muonPair->
mu1.
p4(), muonPair->
mu2.
p4()));
111 genPair->push_back(std::make_pair(genMuonPair->
mu1.
p4(), genMuonPair->
mu2.
p4()));
118 std::cout <<
"ERROR: no file " << fileName <<
" found. Please, correct the file name or specify an empty field in the InputRootTreeFileName parameter to read events from the edm source." << std::endl;
125 const int muonType, std::vector<std::pair<unsigned int, unsigned long long> > * evtRun,
MuonPairExtendedVector * genPair = 0)
127 TFile *
file = TFile::Open(fileName,
"READ");
128 if (file->IsOpen()) {
129 TTree *
tree = (TTree*)file->Get(
"T");
132 tree->SetBranchAddress(
"event", &muonPair);
134 tree->SetBranchAddress(
"genEvent", &genMuonPair);
136 Long64_t nentries = tree->GetEntries();
137 if ((maxEvents != -1) && (nentries > maxEvents)) nentries =
maxEvents;
138 for (Long64_t
i=0;
i<nentries; ++
i) {
141 savedPair->push_back(std::make_pair(muonPair->
mu1, muonPair->
mu2));
145 genPair->push_back(std::make_pair(genMuonPair->
mu1, genMuonPair->
mu2));
152 std::cout <<
"ERROR: no file " << fileName <<
" found. Please, correct the file name or specify an empty field in the InputRootTreeFileName parameter to read events from the edm source." << std::endl;
161 const int muonType, std::vector<GenMuonPair> * genPair = 0)
163 TFile *
file = TFile::Open(fileName,
"READ");
164 if (file->IsOpen()) {
165 TTree *
tree = (TTree*)file->Get(
"T");
168 tree->SetBranchAddress(
"event", &muonPair);
170 tree->SetBranchAddress(
"genEvent", &genMuonPair);
173 Long64_t nentries = tree->GetEntries();
174 if ((maxEvents != -1) && (nentries > maxEvents)) nentries =
maxEvents;
175 for (Long64_t
i=0;
i<nentries; ++
i) {
177 savedPair->push_back(*muonPair);
179 genPair->push_back(*genMuonPair);
184 std::cout <<
"ERROR: no file " << fileName <<
" found. Please, correct the file name or specify an empty field in the InputRootTreeFileName parameter to read events from the edm source." << std::endl;
reco::Particle::LorentzVector lorentzVector
std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > MuonPairExtendedVector
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=0, const bool saveAll=false)
void copy(const MuonPair ©Pair)
Used to copy the content of another MuonPair.
void copy(const GenMuonPair ©Pair)
Used to copy the content of another GenMuonPair.
void readTree(const int maxEvents, const TString &fileName, std::vector< MuonPair > *savedPair, const int muonType, std::vector< GenMuonPair > *genPair=0)
Used to read the external trees.
void readTree(const int maxEvents, const TString &fileName, MuonPairExtendedVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairExtendedVector *genPair=0)
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairVector *genPair=0)