Go to the documentation of this file.00001
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 #include "IOMC/NtupleConverter/interface/NtupleROOTFile.h"
00008 #include <iostream>
00009 #include <map>
00010 #include <iomanip>
00011
00012 #include <fstream>
00013 using namespace std;
00014
00015
00016 NtupleROOTFile::NtupleROOTFile(string filename,int id) {
00017
00018
00019 std::ifstream * input= new ifstream(filename.c_str(), ios::in | ios::binary);
00020 if(! (*input))
00021 {
00022 throw cms::Exception("NtplNotFound", "NtupleROOTFile: Ntpl not found")
00023 << "File " << filename << " could not be opened.\n";
00024 }
00025 if (input){
00026 input->close();
00027 delete input;
00028 }
00029 file = new TFile(filename.c_str(),"READ");
00030
00031 tree = (TTree*)file->Get("h101");
00032 if (tree != NULL) id = 101;
00033 if (tree == NULL) {
00034 tree = (TTree*)file->Get("h100");
00035 if (tree != NULL) id = 100;
00036 }
00037
00038
00039 switch(id){
00040
00041 case 101:
00042 tree = (TTree*)file->Get("h101");
00043 if (tree==NULL){
00044 throw cms::Exception("NtplNotValid",
00045 "NtupleROOTFile: Ntpl seems not to be a valid ")
00046 << "File " << filename << " could not be opened.\n";
00047 }
00048 tree->SetBranchAddress("Jsmhep",Jsmhep);
00049 tree->SetBranchAddress("Jsdhep",Jsdhep);
00050 break;
00051 case 100:
00052 tree = (TTree*)file->Get("h100");
00053 if (tree==NULL){
00054 throw cms::Exception("NtplNotValid",
00055 "NtupleROOTFile: Ntpl seems not to be a valid ")
00056 << "File; " << filename << " could not be opened.\n";
00057 }
00058 tree->SetBranchAddress("Jmohep",Jmohep);
00059 tree->SetBranchAddress("Jdahep",Jdahep);
00060 tree->SetBranchAddress("Isthep",Isthep);
00061 break;
00062
00063 default:
00064
00065
00066 throw cms::Exception("NtplNotValid", "NtupleROOTFile: Ntpl not valid")
00067 << "File " << filename << " could not be opened.\n";
00068
00069 }
00070 id_ =id;
00071 tree->SetBranchAddress("Nhep",&Nhep);
00072 tree->SetBranchAddress("Nevhep",&Nevhep);
00073 tree->SetBranchAddress("Phep",Phep);
00074 tree->SetBranchAddress("Vhep",Vhep);
00075 tree->SetBranchAddress("Idhep",Idhep);
00076 }
00077
00078
00079 NtupleROOTFile::~NtupleROOTFile() {
00080 delete tree;
00081 delete file;
00082 }
00083
00084
00085 void NtupleROOTFile::setEvent(int event) const {
00086 tree->GetEntry(event);
00087 }
00088
00089
00090 int NtupleROOTFile::getNhep()const{
00091 return Nhep;
00092 }
00093
00094 int NtupleROOTFile::getNevhep() const{
00095
00096 return tree->GetEntries();
00097
00098
00099
00100
00101 }
00102
00103
00104 int NtupleROOTFile::getIdhep(int j) const{
00105 return Idhep[j-1];
00106 }
00107
00108
00109
00110 int NtupleROOTFile::getJsmhep(int j) const{
00111 if(getId() != 101){
00112 cout<<"NtupleROOTFile::getJsmhep: ERROR: "
00113 <<"only available for ID 101 ntuples"<<endl;
00114 return 0;
00115 }
00116 return Jsmhep[j-1];
00117 }
00118
00119
00120
00121 int NtupleROOTFile::getJsdhep(int j) const{
00122 if(getId() != 101){
00123 cout<<"NtupleROOTFile::getJsdhep: ERROR: "
00124 <<"only available for ID 101 ntuples"<<endl;
00125 return 0;
00126 }
00127 return Jsdhep[j-1];
00128 }
00129
00130
00131 int NtupleROOTFile::getIsthep(int j) const{
00132 if(getId() != 100){
00133
00134 int jsm= this->getJsmhep(j);
00135 int jsd= this->getJsdhep(j);
00136
00137 int idj=jsm/16000000;
00138 int idk=jsd/16000000;
00139 int status = idk*100+idj;
00140 return status;
00141 }
00142 return Isthep[j-1];
00143 }
00144
00145
00146
00147 int NtupleROOTFile::getJmohep(int j, int idx) const{
00148 if(getId() != 100){
00149
00150 int jsm= this->getJsmhep(j);
00151
00152
00153 int mo1 = (jsm%16000000)/4000;
00154 int mo2 = jsm%4000;
00155
00156 if (idx==0) return mo1;
00157
00158 if (idx==1) return mo2;
00159 }
00160 return Jmohep[j-1][idx];
00161 }
00162
00163
00164 int NtupleROOTFile::getJdahep(int j, int idx) const{
00165 if(getId() != 100){
00166 int jsd= this->getJsdhep(j);
00167
00168
00169 int da1 = (jsd%16000000)/4000;
00170 int da2= jsd%4000;
00171
00172 if (idx==0) return da1;
00173
00174 if (idx==1) return da2;
00175 }
00176 return Jdahep[j-1][idx];
00177 }
00178
00179
00180 double NtupleROOTFile::getPhep(int j, int idx) const{
00181 return Phep[j-1][idx];
00182 }
00183
00184
00185 double NtupleROOTFile::getVhep(int j, int idx) const{
00186 return Vhep[j-1][idx];
00187 }
00188
00189
00190 int NtupleROOTFile::getEntries() const{
00191 return (int)tree->GetEntries();
00192 }