CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
CaloMeanResponse Class Reference

#include <CaloMeanResponse.h>

Public Member Functions

 CaloMeanResponse (edm::ParameterSet const &p)
 
double getWeight (int genPID, double genP)
 
virtual ~CaloMeanResponse ()
 

Private Member Functions

void readResponse (std::string fName)
 

Private Attributes

int piLast
 
std::vector< double > pionMomentum
 
std::vector< double > pionTable
 
std::vector< int > pionTypes
 
int pLast
 
std::vector< double > protonMomentum
 
std::vector< double > protonTable
 
std::vector< int > protonTypes
 
double scale
 
bool useTable
 

Detailed Description

Definition at line 10 of file CaloMeanResponse.h.

Constructor & Destructor Documentation

CaloMeanResponse::CaloMeanResponse ( edm::ParameterSet const &  p)

Definition at line 12 of file CaloMeanResponse.cc.

References edm::ParameterSet::getParameter(), readResponse(), scale, AlCaHLTBitMon_QueryRunRegistry::string, and useTable.

12  {
13 
14  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("CaloResponse");
15  edm::FileInPath fp = m_p.getParameter<edm::FileInPath>("ResponseFile");
16  std::string fName = fp.fullPath();
17  useTable = m_p.getParameter<bool>("UseResponseTable");
18  scale = m_p.getParameter<double>("ResponseScale");
19  edm::LogInfo("CaloSim") << "CaloMeanResponse initialized with scale "
20  << scale << " and use Table " << useTable
21  << " from file " << fName;
22 
23  readResponse (fName);
24 }
T getParameter(std::string const &) const
void readResponse(std::string fName)
CaloMeanResponse::~CaloMeanResponse ( )
virtual

Definition at line 26 of file CaloMeanResponse.cc.

26 {}

Member Function Documentation

double CaloMeanResponse::getWeight ( int  genPID,
double  genP 
)

Definition at line 28 of file CaloMeanResponse.cc.

References newFWLiteAna::found, i, LogDebug, piLast, pionMomentum, pionTable, pionTypes, pLast, protonMomentum, protonTable, protonTypes, scale, useTable, and histoStyle::weight.

Referenced by CaloSD::getResponseWt().

28  {
29  double weight = 1;
30  bool found=false;
31  for (unsigned int i=0; i<pionTypes.size(); i++) {
32  if (genPID == pionTypes[i]) {
33  found = true;
34  break;
35  }
36  }
37  if (found) {
38  weight = scale;
39  if (useTable) {
40  if (piLast >= 0) weight *= pionTable[piLast];
41  for (unsigned int i=0; i<pionTable.size(); i++) {
42  if (genP < pionMomentum[i]) {
43  if (i == 0) weight = scale*pionTable[i];
44  else weight = scale*((pionTable[i-1]*(pionMomentum[i]-genP)+
45  pionTable[i]*(genP-pionMomentum[i-1]))/
46  (pionMomentum[i]-pionMomentum[i-1]));
47  break;
48  }
49  }
50  }
51 #ifdef DebugLog
52  LogDebug("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID
53  << " uses pion list and gets weight " << weight
54  << " for momentum " << genP/GeV << " GeV/c";
55 #endif
56  } else {
57  for (unsigned int i=0; i<protonTypes.size(); i++) {
58  if (genPID == protonTypes[i]) {
59  found = true;
60  break;
61  }
62  }
63  if (found) {
64  weight = scale;
65  if (useTable) {
66  if (pLast >= 0) weight *= protonTable[pLast];
67  for (unsigned int i=0; i<protonTable.size(); i++) {
68  if (genP < protonMomentum[i]) {
69  if (i == 0) weight = scale*protonTable[i];
70  else weight = scale*((protonTable[i-1]*(protonMomentum[i]-genP)+
71  protonTable[i]*(genP-protonMomentum[i-1]))/
72  (protonMomentum[i]-protonMomentum[i-1]));
73  break;
74  }
75  }
76  }
77 #ifdef DebugLog
78  LogDebug("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID
79  << " uses proton list and gets weight " << weight
80  << " for momentum " << genP/GeV << " GeV/c";
81 #endif
82  } else {
83 #ifdef DebugLog
84  LogDebug("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID
85  << " is not in either lists and weight " << weight;
86 #endif
87  }
88  }
89  return weight;
90 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< int > protonTypes
std::vector< double > protonMomentum
std::vector< double > pionTable
std::vector< int > pionTypes
std::vector< double > protonTable
std::vector< double > pionMomentum
int weight
Definition: histoStyle.py:50
void CaloMeanResponse::readResponse ( std::string  fName)
private

Definition at line 92 of file CaloMeanResponse.cc.

References i, recoMuon::in, EdgesToViz::infile, LogDebug, npart, evf::utils::pid, piLast, pionMomentum, pionTable, pionTypes, pLast, protonMomentum, protonTable, and protonTypes.

Referenced by CaloMeanResponse().

92  {
93 
94  std::ifstream infile;
95  infile.open(fName.c_str(), std::ios::in);
96 
97  if (infile) {
98  int nene, npart, pid;
99  double ene, responseData, responseMC, ratio;
100 
101  // First read the pion data
102  infile >> nene >> npart;
103  for (int i=0; i<npart; i++) {
104  infile >> pid;
105  pionTypes.push_back(pid);
106  }
107  for (int i=0; i<nene; i++) {
108  infile >> ene >> responseData >> responseMC;
109  if (responseMC > 0) ratio = responseData/responseMC;
110  else ratio = 1;
111  pionMomentum.push_back(ene*GeV);
112  pionTable.push_back(ratio);
113  }
114 
115  // Then read the proton data
116  infile >> nene >> npart;
117  for (int i=0; i<npart; i++) {
118  infile >> pid;
119  protonTypes.push_back(pid);
120  }
121  for (int i=0; i<nene; i++) {
122  infile >> ene >> responseData >> responseMC;
123  if (responseMC > 0) ratio = responseData/responseMC;
124  else ratio = 1;
125  protonMomentum.push_back(ene*GeV);
126  protonTable.push_back(ratio);
127  }
128  infile.close();
129  }
130 
131  piLast = (int)(pionTable.size()) - 1;
132  pLast = (int)(protonTable.size()) - 1;
133 #ifdef DebugLog
134  LogDebug("CaloSim") << "CaloMeanResponse::readResponse finds "
135  << pionTypes.size() << " particles to use pion response"
136  << " map with a table of " << pionTable.size()
137  << " data points " << piLast;
138  for (unsigned int i=0; i<pionTypes.size(); i++)
139  LogDebug("CaloSim") << "Particle ID[" << i << "] = " << pionTypes[i];
140  for (unsigned int i=0; i<pionTable.size(); i++)
141  LogDebug("CaloSim") << "Momentum[" << i << "] (" << pionMomentum[i]/GeV
142  << " GeV/c) --> " << pionTable[i];
143  LogDebug("CaloSim") << "CaloMeanResponse::readResponse finds "
144  << protonTypes.size() << " particles to use proton "
145  << "response map with a table of " << protonTable.size()
146  << " data points " << pLast;
147  for (unsigned int i=0; i<protonTypes.size(); i++)
148  LogDebug("CaloSim") << "Particle ID[" << i << "] = " << protonTypes[i];
149  for (unsigned int i=0; i<protonTable.size(); i++)
150  LogDebug("CaloSim") << "Momentum[" << i << "] (" << protonMomentum[i]/GeV
151  << " GeV/c) --> " << protonTable[i];
152 #endif
153 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< int > protonTypes
double npart
Definition: HydjetWrapper.h:45
std::vector< double > protonMomentum
std::vector< double > pionTable
std::vector< int > pionTypes
list infile
Definition: EdgesToViz.py:90
std::vector< double > protonTable
std::vector< double > pionMomentum

Member Data Documentation

int CaloMeanResponse::piLast
private

Definition at line 24 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<double> CaloMeanResponse::pionMomentum
private

Definition at line 26 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<double> CaloMeanResponse::pionTable
private

Definition at line 26 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<int> CaloMeanResponse::pionTypes
private

Definition at line 25 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

int CaloMeanResponse::pLast
private

Definition at line 24 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<double> CaloMeanResponse::protonMomentum
private

Definition at line 27 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<double> CaloMeanResponse::protonTable
private

Definition at line 27 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

std::vector<int> CaloMeanResponse::protonTypes
private

Definition at line 25 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

double CaloMeanResponse::scale
private
bool CaloMeanResponse::useTable
private

Definition at line 22 of file CaloMeanResponse.h.

Referenced by CaloMeanResponse(), and getWeight().