CMS 3D CMS Logo

Functions
TreeDump.cc File Reference
#include <stdlib.h>
#include <TH1F.h>
#include <TROOT.h>
#include <TFile.h>
#include <TSystem.h>
#include <sstream>
#include <fstream>
#include "FWCore/FWLite/interface/FWLiteEnabler.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)

Dumps the content of a tree to a local TreeDump.txt file.
The txt file contains one pair per row and the values are:

  • for genInfo = 0
    pt1 eta1 phi1 pt2 eta2 phi2
  • for genInfo != 0
    pt1 eta1 phi1 pt2 eta2 phi2 genPt1 genEta1 genPhi1 genPt2 genEta2 genPhi2.

Definition at line 24 of file TreeDump.cc.

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

25 {
26  double muMass = 0.105658;
27  double px = ptEtaPhiE[0]*cos(ptEtaPhiE[2]);
28  double py = ptEtaPhiE[0]*sin(ptEtaPhiE[2]);
29  double tmp = 2*atan(exp(-ptEtaPhiE[1]));
30  double pz = ptEtaPhiE[0]*cos(tmp)/sin(tmp);
31  double E = sqrt(px*px+py*py+pz*pz+muMass*muMass);
32 
33  return lorentzVector(px,py,pz,E);
34 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
T sqrt(T t)
Definition: SSEVec.h:18
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 36 of file TreeDump.cc.

References gather_cfg::cout, FWLiteEnabler::enable(), cmsRelvalreport::exit, MillePedeFileConverter_cfg::fileName, download_sqlite_cfg::outputFile, RootTreeHandler::readTree(), and AlCaHLTBitMon_QueryRunRegistry::string.

37 {
38 
39  if( argc != 3 ) {
40  std::cout << "Please provide the name of the file (with file: or rfio: as needed) and if there is generator information (0 is false)" << std::endl;
41  exit(1);
42  }
44  if( fileName.find("file:") != 0 && fileName.find("rfio:") != 0 ) {
45  std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
46  exit(1);
47  }
48  std::stringstream ss;
49  ss << argv[2];
50  bool genInfo = false;
51  ss >> genInfo;
52  std::cout << "Dumping tree with genInfo = " << genInfo << std::endl;
53 
54  // load framework libraries
55  gSystem->Load( "libFWCoreFWLite" );
57 
58  // open input file (can be located on castor)
59  TFile* inFile = TFile::Open(fileName.c_str());
60 
61  // MuonPairVector pairVector;
62  MuonPairVector pairVector;
63  MuonPairVector genPairVector;
64 
65  // Create the RootTreeHandler to save the events in the root tree
66  RootTreeHandler treeHandler;
67  // treeHandler.readTree(-1, fileName, &pairVector, &genPairVector);
68  std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
69  treeHandler.readTree(-1, fileName, &pairVector, -20, &evtRun, &genPairVector);
70 
71  if( (pairVector.size() != genPairVector.size()) && genInfo ) {
72  std::cout << "Error: the size of pairVector and genPairVector is different" << std::endl;
73  }
74 
75  std::ofstream outputFile;
76  outputFile.open("TreeDump.txt");
77 
78  MuonPairVector::const_iterator it = pairVector.begin();
79  MuonPairVector::const_iterator genIt = genPairVector.begin();
80  std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
81  for( ; it != pairVector.end(); ++it, ++genIt, ++evtRunIt ) {
82  // Write the information to a txt file
83  outputFile << it->first.pt() << " " << it->first.eta() << " " << it->first.phi() << " "
84  << it->second.pt() << " " << it->second.eta() << " " << it->second.phi() << " ";
85  if( genInfo ) {
86  outputFile << genIt->first.pt() << " " << genIt->first.eta() << " " << genIt->first.phi() << " "
87  << genIt->second.pt() << " " << genIt->second.eta() << " " << genIt->second.phi() << " ";
88  }
89  outputFile << " " << evtRunIt->first << " " << evtRunIt->second;
90  outputFile << std::endl;
91  }
92 
93  // size_t namePos = fileName.find_last_of("/");
94  // treeHandler.writeTree(("tree_"+fileName.substr(namePos+1, fileName.size())).c_str(), &pairVector);
95 
96  // close input and output files
97  inFile->Close();
98  outputFile.close();
99 
100  return 0;
101 }
static void enable()
enable automatic library loading
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
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=0)