MuonAnalysis
MomentumScaleCalibration
bin
TreeFromDump.cc
Go to the documentation of this file.
1
#include <memory>
2
#include <string>
3
#include <vector>
4
#include <sstream>
5
#include <fstream>
6
#include <iostream>
7
#include <cstdlib>
8
9
#include <TH1F.h>
10
#include <TROOT.h>
11
#include <TFile.h>
12
#include <TSystem.h>
13
14
#include "
FWCore/FWLite/interface/FWLiteEnabler.h
"
15
#include "
MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h
"
16
21
// Useful function to convert 4-vector coordinates
22
// -----------------------------------------------
23
lorentzVector
fromPtEtaPhiToPxPyPz
(
const
double
* ptEtaPhiE) {
24
double
muMass
= 0.105658;
25
double
px
= ptEtaPhiE[0] *
cos
(ptEtaPhiE[2]);
26
double
py
= ptEtaPhiE[0] *
sin
(ptEtaPhiE[2]);
27
double
tmp
= 2 * atan(
exp
(-ptEtaPhiE[1]));
28
double
pz = ptEtaPhiE[0] *
cos
(
tmp
) /
sin
(
tmp
);
29
double
E =
sqrt
(
px
*
px
+
py
*
py
+ pz * pz +
muMass
*
muMass
);
30
31
return
lorentzVector
(
px
,
py
, pz, E);
32
}
33
34
int
main
(
int
argc
,
char
*
argv
[]) {
35
if
(
argc
!= 3) {
36
std::cout
<<
"Please provide the name of the file and if there is generator information (0 is false)"
<< std::endl;
37
exit
(1);
38
}
39
std::string
fileName
(
argv
[1]);
40
std::stringstream
ss
;
41
ss
<<
argv
[2];
42
bool
genInfo =
false
;
43
ss
>> genInfo;
44
std::cout
<<
"Reading tree dump with genInfo = "
<< genInfo << std::endl;
45
46
// load framework libraries
47
gSystem->Load(
"libFWCoreFWLite"
);
48
FWLiteEnabler::enable
();
49
50
// MuonPairVector pairVector;
51
std::vector<MuonPair> pairVector;
52
std::vector<GenMuonPair> genPairVector;
53
54
// Create the RootTreeHandler to save the events in the root tree
55
RootTreeHandler
treeHandler;
56
57
std::ifstream
inputFile
;
58
inputFile
.open(
fileName
.c_str());
59
60
std::string
line
;
61
double
value
[6];
62
double
genValue[6];
63
// Read the information from a txt file
64
while
(!
inputFile
.eof()) {
65
getline(
inputFile
,
line
);
66
if
(!
line
.empty()) {
67
// std::cout << "line = " << line << std::endl;
68
std::stringstream
ss
(
line
);
69
for
(
int
i
= 0;
i
< 6; ++
i
) {
70
ss
>>
value
[
i
];
71
// std::cout << "value["<<i<<"] = " << value[i] << std::endl;
72
}
73
pairVector.push_back(
74
MuonPair
(
fromPtEtaPhiToPxPyPz
(
value
),
fromPtEtaPhiToPxPyPz
(&(
value
[3])),
MuScleFitEvent
(0, 0, 0, 0, 0, 0)));
75
if
(genInfo) {
76
for
(
int
i
= 0;
i
< 6; ++
i
) {
77
ss
>> genValue[
i
];
78
// std::cout << "genValue["<<i<<"] = " << genValue[i] << std::endl;
79
}
80
genPairVector.push_back(
GenMuonPair
(
fromPtEtaPhiToPxPyPz
(genValue),
fromPtEtaPhiToPxPyPz
(&(genValue[3])), 0));
81
}
82
}
83
}
84
inputFile
.close();
85
86
if
((pairVector.size() != genPairVector.size()) && genInfo) {
87
std::cout
<<
"Error: the size of pairVector and genPairVector is different"
<< std::endl;
88
}
89
90
if
(genInfo) {
91
treeHandler.
writeTree
(
"TreeFromDump.root"
, &pairVector, 0, &genPairVector);
92
std::cout
<<
"Filling tree with genInfo"
<< std::endl;
93
}
else
{
94
treeHandler.
writeTree
(
"TreeFromDump.root"
, &pairVector);
95
std::cout
<<
"Filling tree"
<< std::endl;
96
}
97
// close input file
98
inputFile
.close();
99
100
return
0;
101
}
cmsBatch.argv
argv
Definition:
cmsBatch.py:279
mps_fire.i
i
Definition:
mps_fire.py:428
RootTreeHandler
Definition:
RootTreeHandler.h:24
dir2webdir.argc
argc
Definition:
dir2webdir.py:39
GenMuonPair
Definition:
GenMuonPair.h:19
multPhiCorr_741_25nsDY_cfi.py
py
Definition:
multPhiCorr_741_25nsDY_cfi.py:12
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
MillePedeFileConverter_cfg.fileName
fileName
Definition:
MillePedeFileConverter_cfg.py:32
createJobs.tmp
tmp
align.sh
Definition:
createJobs.py:716
MuonPair
Definition:
MuonPair.h:13
funct::sin
Sin< T >::type sin(const T &t)
Definition:
Sin.h:22
contentValuesCheck.ss
ss
Definition:
contentValuesCheck.py:33
funct::cos
Cos< T >::type cos(const T &t)
Definition:
Cos.h:22
mathSSE::sqrt
T sqrt(T t)
Definition:
SSEVec.h:19
RootTreeHandler.h
RootTreeHandler::writeTree
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
Definition:
RootTreeHandler.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
FWLiteEnabler::enable
static void enable()
enable automatic library loading
Definition:
FWLiteEnabler.cc:46
lorentzVector
reco::Particle::LorentzVector lorentzVector
Definition:
GenMuonPair.h:9
dtResolutionTest_cfi.inputFile
inputFile
Definition:
dtResolutionTest_cfi.py:14
value
Definition:
value.py:1
fastsim::Constants::muMass
static constexpr double muMass
Muon mass [GeV].
Definition:
Constants.h:14
fromPtEtaPhiToPxPyPz
lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
Definition:
TreeFromDump.cc:23
MuScleFitEvent
Definition:
Event.h:6
main
int main(int argc, char *argv[])
Definition:
TreeFromDump.cc:34
multPhiCorr_741_25nsDY_cfi.px
px
Definition:
multPhiCorr_741_25nsDY_cfi.py:10
beamvalidation.exit
def exit(msg="")
Definition:
beamvalidation.py:53
JetChargeProducer_cfi.exp
exp
Definition:
JetChargeProducer_cfi.py:6
mps_splice.line
line
Definition:
mps_splice.py:76
FWLiteEnabler.h
Generated for CMSSW Reference Manual by
1.8.16