27 void writeTree(
const TString &
fileName,
const std::vector<MuonPair> * savedPair,
const int muonType = 0,
28 const std::vector<GenMuonPair> * genPair = 0,
const bool saveAll =
false )
31 TFile *
f1 =
new TFile(fileName,
"RECREATE");
32 TTree *
tree =
new TTree(
"T",
"Muon pairs");
36 tree->Branch(
"event",
"MuonPair", &muonPair);
38 tree->Branch(
"genEvent",
"GenMuonPair", &genMuonPair);
41 if( savedPair->size() != genPair->size() ) {
43 << savedPair->size() <<
") and genPair size ("
44 << genPair->size() <<
") are different. This is severe and I will not write the tree." << std::endl;
49 std::vector<MuonPair>::const_iterator muonPairIt = savedPair->begin();
51 for( ; muonPairIt != savedPair->end(); ++muonPairIt, ++iev ) {
53 if( saveAll || ( (muonPairIt->mu1 != emptyLorentzVector) && (muonPairIt->mu2 != emptyLorentzVector) ) ) {
55 muonPair->
copy(*muonPairIt);
63 genMuonPair->
copy((*genPair)[iev]);
73 TH1F muonTypeHisto(
"MuonType",
"MuonType", 40, -20, 20);
74 muonTypeHisto.Fill(muonType);
75 muonTypeHisto.Write();
86 TFile *
file =
new TFile(fileName,
"READ");
87 if( file->IsOpen() ) {
88 TTree *
tree = (TTree*)file->Get(
"T");
92 tree->SetBranchAddress(
"event",&muonPair);
94 tree->SetBranchAddress(
"genEvent",&genMuonPair);
97 Long64_t nentries = tree->GetEntries();
98 if( (maxEvents != -1) && (nentries > maxEvents) ) nentries =
maxEvents;
99 for( Long64_t
i=0;
i<nentries; ++
i ) {
101 savedPair->push_back(std::make_pair(muonPair->
mu1, muonPair->
mu2));
104 genPair->push_back(std::make_pair(genMuonPair->
mu1, genMuonPair->
mu2));
110 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;
118 const int muonType, std::vector<GenMuonPair> * genPair = 0 )
120 TFile *
file =
new TFile(fileName,
"READ");
121 if( file->IsOpen() ) {
122 TTree *
tree = (TTree*)file->Get(
"T");
125 tree->SetBranchAddress(
"event",&muonPair);
127 tree->SetBranchAddress(
"genEvent",&genMuonPair);
130 Long64_t nentries = tree->GetEntries();
131 if( (maxEvents != -1) && (nentries > maxEvents) ) nentries =
maxEvents;
132 for( Long64_t
i=0;
i<nentries; ++
i ) {
134 savedPair->push_back(*muonPair);
136 genPair->push_back(*genMuonPair);
141 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< lorentzVector, lorentzVector > > MuonPairVector
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, MuonPairVector *genPair=0)
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.