CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NtupleROOTFile.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <map>
10 #include <iomanip>
11 
12 #include <fstream>
13 using namespace std;
14 
15 //-------------------------------------------------------
17 
18  // check if File exists
19  std::ifstream * input= new ifstream(filename.c_str(), ios::in | ios::binary);
20  if(! (*input))
21  {
22  throw cms::Exception("NtplNotFound", "NtupleROOTFile: Ntpl not found")
23  << "File " << filename << " could not be opened.\n";
24  }
25  if (input){
26  input->close();
27  delete input;
28  }
29  file = new TFile(filename.c_str(),"READ");
30 
31  tree = (TTree*)file->Get("h101");
32  if (tree != NULL) id = 101;
33  if (tree == NULL) {
34  tree = (TTree*)file->Get("h100");
35  if (tree != NULL) id = 100;
36  }
37 
38  // Check: Is is a cmkin root file ?
39  switch(id){
40 
41  case 101:
42  tree = (TTree*)file->Get("h101");
43  if (tree==NULL){
44  throw cms::Exception("NtplNotValid",
45  "NtupleROOTFile: Ntpl seems not to be a valid ")
46  << "File " << filename << " could not be opened.\n";
47  }
48  tree->SetBranchAddress("Jsmhep",Jsmhep);
49  tree->SetBranchAddress("Jsdhep",Jsdhep);
50  break;
51  case 100:
52  tree = (TTree*)file->Get("h100");
53  if (tree==NULL){
54  throw cms::Exception("NtplNotValid",
55  "NtupleROOTFile: Ntpl seems not to be a valid ")
56  << "File; " << filename << " could not be opened.\n";
57  }
58  tree->SetBranchAddress("Jmohep",Jmohep);
59  tree->SetBranchAddress("Jdahep",Jdahep);
60  tree->SetBranchAddress("Isthep",Isthep);
61  break;
62  // Not supported:
63  default:
64 
65  // Check: Is it a valid id ?
66  throw cms::Exception("NtplNotValid", "NtupleROOTFile: Ntpl not valid")
67  << "File " << filename << " could not be opened.\n";
68 
69  }
70  id_ =id;
71  tree->SetBranchAddress("Nhep",&Nhep);
72  tree->SetBranchAddress("Nevhep",&Nevhep);
73  tree->SetBranchAddress("Phep",Phep);
74  tree->SetBranchAddress("Vhep",Vhep);
75  tree->SetBranchAddress("Idhep",Idhep);
76 }
77 
78 //-------------------------------------------------------
80  delete tree;
81  delete file;
82 }
83 
84 //-------------------------------------------------------
86  tree->GetEntry(event);
87 }
88 
89 //-------------------------------------------------------
91  return Nhep;
92 }
93 //-------------------------------------------------------
95 
96  return tree->GetEntries();
97 
98  // jw 8.3.2006:changed, since there seem to be ntpls
99  // where this entry is not correctly filled
100  //return Nevhep;
101 }
102 
103 //-------------------------------------------------------
105  return Idhep[j-1];
106 }
107 
108 
109 //-------------------------------------------------------
111  if(getId() != 101){
112  cout<<"NtupleROOTFile::getJsmhep: ERROR: "
113  <<"only available for ID 101 ntuples"<<endl;
114  return 0;
115  }
116  return Jsmhep[j-1];
117 }
118 
119 
120 //-------------------------------------------------------
122  if(getId() != 101){
123  cout<<"NtupleROOTFile::getJsdhep: ERROR: "
124  <<"only available for ID 101 ntuples"<<endl;
125  return 0;
126  }
127  return Jsdhep[j-1];
128 }
129 
130 //-------------------------------------------------------
132  if(getId() != 100){
133 
134  int jsm= this->getJsmhep(j);
135  int jsd= this->getJsdhep(j);
136  // this is the CMS compression for ntuple id 101
137  int idj=jsm/16000000;
138  int idk=jsd/16000000;
139  int status = idk*100+idj;
140  return status;
141  }
142  return Isthep[j-1];
143 }
144 
145 
146 //-------------------------------------------------------
147 int NtupleROOTFile::getJmohep(int j, int idx) const{
148  if(getId() != 100){
149 
150  int jsm= this->getJsmhep(j);
151  //we have to compute it
152  // this is the CMS compression for ntuple id 101
153  int mo1 = (jsm%16000000)/4000;
154  int mo2 = jsm%4000;
155  // 1. mother
156  if (idx==0) return mo1;
157  // 2. mother
158  if (idx==1) return mo2;
159  }
160  return Jmohep[j-1][idx];
161 }
162 
163 //-------------------------------------------------------
164 int NtupleROOTFile::getJdahep(int j, int idx) const{
165  if(getId() != 100){
166  int jsd= this->getJsdhep(j);
167  // we have to compute it
168  // this is the CMS compression for ntuple id 101
169  int da1 = (jsd%16000000)/4000;
170  int da2= jsd%4000;
171  // 1. daughter
172  if (idx==0) return da1;
173  // 2. daughter
174  if (idx==1) return da2;
175  }
176  return Jdahep[j-1][idx];
177 }
178 
179 //-------------------------------------------------------
180 double NtupleROOTFile::getPhep(int j, int idx) const{
181  return Phep[j-1][idx];
182 }
183 
184 //-------------------------------------------------------
185 double NtupleROOTFile::getVhep(int j, int idx) const{
186  return Vhep[j-1][idx];
187 }
188 
189 //-------------------------------------------------------
191  return (int)tree->GetEntries();
192 }
virtual int getNevhep() const
virtual int getJsdhep(int j) const
virtual int getJsmhep(int j) const
virtual ~NtupleROOTFile()
static unsigned int getId(void)
#define NULL
Definition: scimark2.h:8
virtual int getJdahep(int j, int idx) const
virtual double getVhep(int j, int idx) const
int j
Definition: DBlmapReader.cc:9
virtual int getIsthep(int j) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual int getEntries() const
virtual void setEvent(int event) const
virtual int getNhep() const
virtual int getIdhep(int j) const
virtual double getPhep(int j, int idx) const
tuple filename
Definition: lut2db_cfg.py:20
virtual int getJmohep(int j, int idx) const
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245