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.p4() != emptyLorentzVector) && (muonPairIt->mu2.p4() != 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 ) {
106 savedPair->push_back(std::make_pair(muonPair->
mu1.
p4(), muonPair->
mu2.
p4()));
110 genPair->push_back(std::make_pair(genMuonPair->
mu1.
p4(), genMuonPair->
mu2.
p4()));
117 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<GenMuonPair> * 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);
137 Long64_t nentries = tree->GetEntries();
138 if( (maxEvents != -1) && (nentries > maxEvents) ) nentries =
maxEvents;
139 for( Long64_t
i=0;
i<nentries; ++
i ) {
141 savedPair->push_back(*muonPair);
143 genPair->push_back(*genMuonPair);
148 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.