CMS 3D CMS Logo

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::CaloMeanResponse ( edm::ParameterSet const &  p)

Definition at line 13 of file CaloMeanResponse.cc.

References isotrackTrainRegressor::fName, personalPlayback::fp, edm::ParameterSet::getParameter(), AlCaHLTBitMon_ParallelJobs::p, readResponse(), scale, AlCaHLTBitMon_QueryRunRegistry::string, and useTable.

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::LogVerbatim("CaloSim") << "CaloMeanResponse initialized with scale " << scale << " and use Table " << useTable
20  << " from file " << fName;
22 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void readResponse(std::string fName)

◆ ~CaloMeanResponse()

CaloMeanResponse::~CaloMeanResponse ( )
virtual

Definition at line 24 of file CaloMeanResponse.cc.

24 {}

Member Function Documentation

◆ getWeight()

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

Definition at line 26 of file CaloMeanResponse.cc.

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

26  {
27  double weight = 1;
28  bool found = false;
29  for (unsigned int i = 0; i < pionTypes.size(); i++) {
30  if (genPID == pionTypes[i]) {
31  found = true;
32  break;
33  }
34  }
35  if (found) {
36  weight = scale;
37  if (useTable) {
38  if (piLast >= 0)
40  for (unsigned int i = 0; i < pionTable.size(); i++) {
41  if (genP < pionMomentum[i]) {
42  if (i == 0)
43  weight = scale * pionTable[i];
44  else
45  weight =
46  scale * ((pionTable[i - 1] * (pionMomentum[i] - genP) + pionTable[i] * (genP - pionMomentum[i - 1])) /
47  (pionMomentum[i] - pionMomentum[i - 1]));
48  break;
49  }
50  }
51  }
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID << " uses pion list and gets weight "
54  << weight << " 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)
68  for (unsigned int i = 0; i < protonTable.size(); i++) {
69  if (genP < protonMomentum[i]) {
70  if (i == 0)
72  else
73  weight =
74  scale *
75  ((protonTable[i - 1] * (protonMomentum[i] - genP) + protonTable[i] * (genP - protonMomentum[i - 1])) /
76  (protonMomentum[i] - protonMomentum[i - 1]));
77  break;
78  }
79  }
80  }
81 #ifdef EDM_ML_DEBUG
82  edm::LogVerbatim("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID << " uses proton list and gets "
83  << "weight " << weight << " for momentum " << genP / GeV << " GeV/c";
84 #endif
85  } else {
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("CaloSim") << "CaloMeanResponse::getWeight PID " << genPID << " is not in either lists and "
88  << "weight " << weight;
89 #endif
90  }
91  }
92  return weight;
93 }
Log< level::Info, true > LogVerbatim
std::vector< int > protonTypes
Definition: weight.py:1
std::vector< double > protonMomentum
std::vector< double > pionTable
std::vector< int > pionTypes
std::vector< double > protonTable
std::vector< double > pionMomentum

◆ readResponse()

void CaloMeanResponse::readResponse ( std::string  fName)
private

Definition at line 95 of file CaloMeanResponse.cc.

References isotrackTrainRegressor::fName, mps_fire::i, recoMuon::in, timingPdfMaker::infile, createfilelist::int, npart, piLast, pionMomentum, pionTable, pionTypes, pLast, protonMomentum, protonTable, and protonTypes.

Referenced by CaloMeanResponse().

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

Member Data Documentation

◆ piLast

int CaloMeanResponse::piLast
private

Definition at line 21 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ pionMomentum

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

Definition at line 23 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ pionTable

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

Definition at line 23 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ pionTypes

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

Definition at line 22 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ pLast

int CaloMeanResponse::pLast
private

Definition at line 21 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ protonMomentum

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

Definition at line 24 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ protonTable

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

Definition at line 24 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ protonTypes

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

Definition at line 22 of file CaloMeanResponse.h.

Referenced by getWeight(), and readResponse().

◆ scale

double CaloMeanResponse::scale
private

Definition at line 20 of file CaloMeanResponse.h.

Referenced by CaloMeanResponse(), and getWeight().

◆ useTable

bool CaloMeanResponse::useTable
private

Definition at line 19 of file CaloMeanResponse.h.

Referenced by CaloMeanResponse(), and getWeight().