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 12 of file CaloMeanResponse.cc.

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

12  {
13  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("CaloResponse");
14  edm::FileInPath fp = m_p.getParameter<edm::FileInPath>("ResponseFile");
15  std::string fName = fp.fullPath();
16  useTable = m_p.getParameter<bool>("UseResponseTable");
17  scale = m_p.getParameter<double>("ResponseScale");
18  edm::LogVerbatim("CaloSim") << "CaloMeanResponse initialized with scale " << scale << " and use Table " << useTable
19  << " from file " << fName;
21 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void readResponse(std::string fName)

◆ ~CaloMeanResponse()

CaloMeanResponse::~CaloMeanResponse ( )
virtual

Definition at line 23 of file CaloMeanResponse.cc.

23 {}

Member Function Documentation

◆ getWeight()

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

Definition at line 25 of file CaloMeanResponse.cc.

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

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

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

Referenced by CaloMeanResponse().

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