CMS 3D CMS Logo

TreeDump.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 
3 #include <TH1F.h>
4 #include <TROOT.h>
5 #include <TFile.h>
6 #include <TSystem.h>
7 #include <sstream>
8 #include <fstream>
9 
12 
22 // Useful function to convert 4-vector coordinates
23 // -----------------------------------------------
24 lorentzVector fromPtEtaPhiToPxPyPz(const double* ptEtaPhiE) {
25  double muMass = 0.105658;
26  double px = ptEtaPhiE[0] * cos(ptEtaPhiE[2]);
27  double py = ptEtaPhiE[0] * sin(ptEtaPhiE[2]);
28  double tmp = 2 * atan(exp(-ptEtaPhiE[1]));
29  double pz = ptEtaPhiE[0] * cos(tmp) / sin(tmp);
30  double E = sqrt(px * px + py * py + pz * pz + muMass * muMass);
31 
32  return lorentzVector(px, py, pz, E);
33 }
34 
35 int main(int argc, char* argv[]) {
36  if (argc != 3) {
37  std::cout << "Please provide the name of the file (with file: or rfio: as needed) and if there is generator "
38  "information (0 is false)"
39  << std::endl;
40  exit(1);
41  }
43  if (fileName.find("file:") != 0 && fileName.find("rfio:") != 0) {
44  std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
45  exit(1);
46  }
47  std::stringstream ss;
48  ss << argv[2];
49  bool genInfo = false;
50  ss >> genInfo;
51  std::cout << "Dumping tree with genInfo = " << genInfo << std::endl;
52 
53  // load framework libraries
54  gSystem->Load("libFWCoreFWLite");
56 
57  // open input file (can be located on castor)
58  TFile* inFile = TFile::Open(fileName.c_str());
59 
60  // MuonPairVector pairVector;
61  MuonPairVector pairVector;
62  MuonPairVector genPairVector;
63 
64  // Create the RootTreeHandler to save the events in the root tree
65  RootTreeHandler treeHandler;
66  // treeHandler.readTree(-1, fileName, &pairVector, &genPairVector);
67  std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
68  treeHandler.readTree(-1, fileName, &pairVector, -20, &evtRun, &genPairVector);
69 
70  if ((pairVector.size() != genPairVector.size()) && genInfo) {
71  std::cout << "Error: the size of pairVector and genPairVector is different" << std::endl;
72  }
73 
74  std::ofstream outputFile;
75  outputFile.open("TreeDump.txt");
76 
77  MuonPairVector::const_iterator it = pairVector.begin();
78  MuonPairVector::const_iterator genIt = genPairVector.begin();
79  std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
80  for (; it != pairVector.end(); ++it, ++genIt, ++evtRunIt) {
81  // Write the information to a txt file
82  outputFile << it->first.pt() << " " << it->first.eta() << " " << it->first.phi() << " " << it->second.pt() << " "
83  << it->second.eta() << " " << it->second.phi() << " ";
84  if (genInfo) {
85  outputFile << genIt->first.pt() << " " << genIt->first.eta() << " " << genIt->first.phi() << " "
86  << genIt->second.pt() << " " << genIt->second.eta() << " " << genIt->second.phi() << " ";
87  }
88  outputFile << " " << evtRunIt->first << " " << evtRunIt->second;
89  outputFile << std::endl;
90  }
91 
92  // size_t namePos = fileName.find_last_of("/");
93  // treeHandler.writeTree(("tree_"+fileName.substr(namePos+1, fileName.size())).c_str(), &pairVector);
94 
95  // close input and output files
96  inFile->Close();
97  outputFile.close();
98 
99  return 0;
100 }
cmsBatch.argv
argv
Definition: cmsBatch.py:279
RootTreeHandler
Definition: RootTreeHandler.h:24
dir2webdir.argc
argc
Definition: dir2webdir.py:39
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
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MuonPairVector
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
Definition: RootTreeHandler.h:13
download_sqlite_cfg.outputFile
outputFile
Definition: download_sqlite_cfg.py:5
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
main
int main(int argc, char *argv[])
Definition: TreeDump.cc:35
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
RootTreeHandler.h
FWLiteEnabler::enable
static void enable()
enable automatic library loading
Definition: FWLiteEnabler.cc:46
lorentzVector
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
fastsim::Constants::muMass
static constexpr double muMass
Muon mass [GeV].
Definition: Constants.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
RootTreeHandler::readTree
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=nullptr)
Definition: RootTreeHandler.h:86
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:52
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
FWLiteEnabler.h
fromPtEtaPhiToPxPyPz
lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
Definition: TreeDump.cc:24