CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
TreeFromDump.cc File Reference
#include <memory>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <TH1F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TSystem.h>
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h"

Go to the source code of this file.

Functions

lorentzVector fromPtEtaPhiToPxPyPz (const double *ptEtaPhiE)
 
int main (int argc, char *argv[])
 

Function Documentation

lorentzVector fromPtEtaPhiToPxPyPz ( const double *  ptEtaPhiE)

Builds a tree from the dump in the TreeDump.txt file produced by the TreeDump macro.

Definition at line 23 of file TreeFromDump.cc.

References funct::cos(), create_public_lumi_plots::exp, funct::sin(), mathSSE::sqrt(), and tmp.

24 {
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 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file TreeFromDump.cc.

References gather_cfg::cout, AutoLibraryLoader::enable(), cmsRelvalreport::exit, convertXMLtoSQLite_cfg::fileName, fromPtEtaPhiToPxPyPz(), i, analyzePatCOC_cfg::inputFile, geometryCSVtoXML::line, AlCaHLTBitMon_QueryRunRegistry::string, relativeConstraints::value, and RootTreeHandler::writeTree().

36 {
37 
38  if( argc != 3 ) {
39  std::cout << "Please provide the name of the file and if there is generator information (0 is false)" << std::endl;
40  exit(1);
41  }
43  std::stringstream ss;
44  ss << argv[2];
45  bool genInfo = false;
46  ss >> genInfo;
47  std::cout << "Reading tree dump with genInfo = " << genInfo << std::endl;
48 
49  // load framework libraries
50  gSystem->Load( "libFWCoreFWLite" );
52 
53  // MuonPairVector pairVector;
54  std::vector<MuonPair> pairVector;
55  std::vector<GenMuonPair> genPairVector;
56 
57  // Create the RootTreeHandler to save the events in the root tree
58  RootTreeHandler treeHandler;
59 
60  ifstream inputFile;
61  inputFile.open(fileName.c_str());
62 
64  double value[6];
65  double genValue[6];
66  // Read the information from a txt file
67  while( !inputFile.eof() ) {
68  getline(inputFile, line);
69  if( line != "" ) {
70  // std::cout << "line = " << line << std::endl;
71  std::stringstream ss(line);
72  for( int i=0; i<6; ++i ) {
73  ss >> value[i];
74  // std::cout << "value["<<i<<"] = " << value[i] << std::endl;
75  }
76  pairVector.push_back(MuonPair(fromPtEtaPhiToPxPyPz(value), fromPtEtaPhiToPxPyPz(&(value[3])), 0, 0));
77  if( genInfo ) {
78  for( int i=0; i<6; ++i ) {
79  ss >> genValue[i];
80  // std::cout << "genValue["<<i<<"] = " << genValue[i] << std::endl;
81  }
82  genPairVector.push_back(GenMuonPair(fromPtEtaPhiToPxPyPz(genValue), fromPtEtaPhiToPxPyPz(&(genValue[3])), 0));
83  }
84  }
85  }
86  inputFile.close();
87 
88  if( (pairVector.size() != genPairVector.size()) && genInfo ) {
89  std::cout << "Error: the size of pairVector and genPairVector is different" << std::endl;
90  }
91 
92  if( genInfo ) {
93  treeHandler.writeTree("TreeFromDump.root", &pairVector, 0, &genPairVector);
94  std::cout << "Filling tree with genInfo" << std::endl;
95  }
96  else {
97  treeHandler.writeTree("TreeFromDump.root", &pairVector);
98  std::cout << "Filling tree" << std::endl;
99  }
100  // close input file
101  inputFile.close();
102 
103  return 0;
104 }
int i
Definition: DBlmapReader.cc:9
lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
Definition: TreeDump.cc:24
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=0, const bool saveAll=false)
tuple argc
Definition: dir2webdir.py:41
static void enable()
enable automatic library loading
tuple cout
Definition: gather_cfg.py:121