CMS 3D CMS Logo

Functions

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/MuonAnalysis/MomentumScaleCalibration/bin/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/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)

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(), funct::exp(), funct::sin(), mathSSE::sqrt(), and tmp.

Referenced by TestCorrection::correctMuon(), and main().

{
  double muMass = 0.105658;
  double px = ptEtaPhiE[0]*cos(ptEtaPhiE[2]);
  double py = ptEtaPhiE[0]*sin(ptEtaPhiE[2]);
  double tmp = 2*atan(exp(-ptEtaPhiE[1]));
  double pz = ptEtaPhiE[0]*cos(tmp)/sin(tmp);
  double E  = sqrt(px*px+py*py+pz*pz+muMass*muMass);

  return lorentzVector(px,py,pz,E);
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 36 of file TreeDump.cc.

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

{

  if( argc != 3 ) {
    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;
    exit(1);
  }
  std::string fileName(argv[1]);
  if( fileName.find("file:") != 0 && fileName.find("rfio:") != 0 ) {
    std::cout << "Please provide the name of the file with file: or rfio: as needed" << std::endl;
    exit(1);
  }
  std::stringstream ss;
  ss << argv[2];
  bool genInfo = false;
  ss >> genInfo;
  std::cout << "Dumping tree with genInfo = " << genInfo << std::endl;

  // load framework libraries
  gSystem->Load( "libFWCoreFWLite" );
  AutoLibraryLoader::enable();
  
  // open input file (can be located on castor)
  TFile* inFile = TFile::Open(fileName.c_str());

  // MuonPairVector pairVector;
  MuonPairVector pairVector;
  MuonPairVector genPairVector;

  // Create the RootTreeHandler to save the events in the root tree
  RootTreeHandler treeHandler;
  // treeHandler.readTree(-1, fileName, &pairVector, &genPairVector);
  std::vector<std::pair<int, int> > evtRun;
  treeHandler.readTree(-1, fileName, &pairVector, -20, &evtRun, &genPairVector);

  if( (pairVector.size() != genPairVector.size()) && genInfo ) {
    std::cout << "Error: the size of pairVector and genPairVector is different" << std::endl;
  }

  ofstream outputFile;
  outputFile.open("TreeDump.txt");

  MuonPairVector::const_iterator it = pairVector.begin();
  MuonPairVector::const_iterator genIt = genPairVector.begin();
  std::vector<std::pair<int, int> >::iterator evtRunIt = evtRun.begin();
  for( ; it != pairVector.end(); ++it, ++genIt, ++evtRunIt ) {
    // Write the information to a txt file
    outputFile << it->first.pt()  << " " << it->first.eta()  << " " << it->first.phi()  << " "
               << it->second.pt() << " " << it->second.eta() << " " << it->second.phi() << " ";
    if( genInfo ) {
      outputFile << genIt->first.pt()  << " " << genIt->first.eta()  << " " << genIt->first.phi()  << " "
                 << genIt->second.pt() << " " << genIt->second.eta() << " " << genIt->second.phi() << " ";
    }
    outputFile << " " << evtRunIt->first << " " << evtRunIt->second;
    outputFile << std::endl;
  }
  
  // size_t namePos = fileName.find_last_of("/");
  // treeHandler.writeTree(("tree_"+fileName.substr(namePos+1, fileName.size())).c_str(), &pairVector);

  // close input and output files
  inFile->Close();
  outputFile.close();

  return 0;
}