28 void writeTree(
const TString &
fileName,
const std::vector<MuonPair> * savedPair,
const int muonType = 0,
29 const std::vector<GenMuonPair> * genPair = 0,
const bool saveAll =
false )
32 TFile *
f1 =
new TFile(fileName,
"RECREATE");
33 TTree *
tree =
new TTree(
"T",
"Muon pairs");
37 tree->Branch(
"event",
"MuonPair", &muonPair);
39 tree->Branch(
"genEvent",
"GenMuonPair", &genMuonPair);
42 if( savedPair->size() != genPair->size() ) {
44 << savedPair->size() <<
") and genPair size ("
45 << genPair->size() <<
") are different. This is severe and I will not write the tree." << std::endl;
49 std::cout <<
"savedPair->size() is "<<savedPair->size()<< std::endl;
50 std::vector<MuonPair>::const_iterator muonPairIt = savedPair->begin();
52 for( ; muonPairIt != savedPair->end(); ++muonPairIt, ++iev ) {
54 if( saveAll || ( (muonPairIt->mu1 != emptyLorentzVector) && (muonPairIt->mu2 != emptyLorentzVector) ) ) {
57 muonPair->
copy(*muonPairIt);
65 genMuonPair->
copy((*genPair)[iev]);
75 TH1F muonTypeHisto(
"MuonType",
"MuonType", 40, -20, 20);
76 muonTypeHisto.Fill(muonType);
77 muonTypeHisto.Write();
88 const int muonType, std::vector<std::pair<int, int> > * evtRun,
MuonPairVector * genPair = 0 )
90 TFile *
file = TFile::Open(fileName,
"READ");
91 if( file->IsOpen() ) {
92 TTree *
tree = (TTree*)file->Get(
"T");
96 tree->SetBranchAddress(
"event",&muonPair);
98 tree->SetBranchAddress(
"genEvent",&genMuonPair);
101 Long64_t nentries = tree->GetEntries();
102 if( (maxEvents != -1) && (nentries > maxEvents) ) nentries =
maxEvents;
103 for( Long64_t
i=0;
i<nentries; ++
i ) {
105 savedPair->push_back(std::make_pair(muonPair->
mu1, muonPair->
mu2));
106 evtRun->push_back(std::make_pair(muonPair->
event, muonPair->
run));
109 genPair->push_back(std::make_pair(genMuonPair->
mu1, genMuonPair->
mu2));
115 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;
123 const int muonType, std::vector<GenMuonPair> * genPair = 0 )
125 TFile *
file = TFile::Open(fileName,
"READ");
126 if( file->IsOpen() ) {
127 TTree *
tree = (TTree*)file->Get(
"T");
130 tree->SetBranchAddress(
"event",&muonPair);
132 tree->SetBranchAddress(
"genEvent",&genMuonPair);
135 Long64_t nentries = tree->GetEntries();
136 if( (maxEvents != -1) && (nentries > maxEvents) ) nentries =
maxEvents;
137 for( Long64_t
i=0;
i<nentries; ++
i ) {
139 savedPair->push_back(*muonPair);
141 genPair->push_back(*genMuonPair);
146 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;
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< int, int > > *evtRun, MuonPairVector *genPair=0)
reco::Particle::LorentzVector lorentzVector
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.