CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes
CastorShowerLibrary Class Reference

#include <CastorShowerLibrary.h>

Public Member Functions

 CastorShowerLibrary (const std::string &name, edm::ParameterSet const &p)
 
int FindEnergyBin (double)
 
int FindEtaBin (double)
 
int FindPhiBin (double)
 
CastorShowerEvent getShowerHits (const G4Step *, bool &)
 
 ~CastorShowerLibrary ()
 

Protected Member Functions

CastorShowerEvent getRecord (int, int)
 
void initFile (edm::ParameterSet const &)
 
void loadEventInfo (TBranch *)
 
CastorShowerEvent select (int, double, double=0, double=9)
 

Private Attributes

TBranch * emBranch
 
unsigned int evtPerBin
 
TBranch * hadBranch
 
TFile * hf
 
unsigned int nBinsE
 
unsigned int nBinsEta
 
unsigned int nBinsPhi
 
unsigned int nEvtPerBinE
 
unsigned int nEvtPerBinEta
 
unsigned int nEvtPerBinPhi
 
unsigned int nMomBin
 
std::vector< double > pmom
 
std::vector< double > SLenergies
 
std::vector< double > SLetas
 
std::vector< double > SLphis
 
unsigned int totEvents
 
bool verbose
 

Detailed Description

Definition at line 27 of file CastorShowerLibrary.h.

Constructor & Destructor Documentation

◆ CastorShowerLibrary()

CastorShowerLibrary::CastorShowerLibrary ( const std::string &  name,
edm::ParameterSet const &  p 
)

Definition at line 30 of file CastorShowerLibrary.cc.

References initFile(), and AlCaHLTBitMon_ParallelJobs::p.

31  : hf(nullptr),
32  emBranch(nullptr),
33  hadBranch(nullptr),
34  verbose(false),
35  nMomBin(0),
36  totEvents(0),
37  evtPerBin(0),
38  nBinsE(0),
39  nBinsEta(0),
40  nBinsPhi(0),
41  nEvtPerBinE(0),
42  nEvtPerBinEta(0),
43  nEvtPerBinPhi(0),
44  SLenergies(),
45  SLetas(),
46  SLphis() {
47  initFile(p);
48 }
std::vector< double > SLetas
std::vector< double > SLphis
void initFile(edm::ParameterSet const &)
std::vector< double > SLenergies

◆ ~CastorShowerLibrary()

CastorShowerLibrary::~CastorShowerLibrary ( )

Definition at line 52 of file CastorShowerLibrary.cc.

References hf.

52  {
53  if (hf)
54  hf->Close();
55 }

Member Function Documentation

◆ FindEnergyBin()

int CastorShowerLibrary::FindEnergyBin ( double  energy)

Definition at line 331 of file CastorShowerLibrary.cc.

References hcalRecHitTable_cff::energy, mps_fire::i, and SLenergies.

Referenced by select().

331  {
332  //
333  // returns the integer index of the energy bin, taken from SLenergies vector
334  // returns -1 if ouside valid range
335  //
336  if (energy >= SLenergies.back())
337  return SLenergies.size() - 1;
338 
339  unsigned int i = 0;
340  for (; i < SLenergies.size() - 1; i++)
341  if (energy >= SLenergies.at(i) && energy < SLenergies.at(i + 1))
342  return (int)i;
343 
344  // now i points to the last but 1 bin
345  if (energy >= SLenergies.at(i))
346  return (int)i;
347  // energy outside bin range
348  return -1;
349 }
std::vector< double > SLenergies

◆ FindEtaBin()

int CastorShowerLibrary::FindEtaBin ( double  eta)

Definition at line 353 of file CastorShowerLibrary.cc.

References PVValHelper::eta, mps_fire::i, and SLetas.

Referenced by select().

353  {
354  //
355  // returns the integer index of the eta bin, taken from SLetas vector
356  // returns -1 if ouside valid range
357  //
358  if (eta >= SLetas.back())
359  return SLetas.size() - 1;
360  unsigned int i = 0;
361  for (; i < SLetas.size() - 1; i++)
362  if (eta >= SLetas.at(i) && eta < SLetas.at(i + 1))
363  return (int)i;
364  // now i points to the last but 1 bin
365  if (eta >= SLetas.at(i))
366  return (int)i;
367  // eta outside bin range
368  return -1;
369 }
std::vector< double > SLetas

◆ FindPhiBin()

int CastorShowerLibrary::FindPhiBin ( double  phi)

Definition at line 373 of file CastorShowerLibrary.cc.

References mps_fire::i, phi, and SLphis.

Referenced by select().

373  {
374  //
375  // returns the integer index of the phi bin, taken from SLphis vector
376  // returns -1 if ouside valid range
377  //
378  // needs protection in case phi is outside range -pi,pi
379  //
380  if (phi >= SLphis.back())
381  return SLphis.size() - 1;
382  unsigned int i = 0;
383  for (; i < SLphis.size() - 1; i++)
384  if (phi >= SLphis.at(i) && phi < SLphis.at(i + 1))
385  return (int)i;
386  // now i points to the last but 1 bin
387  if (phi >= SLphis.at(i))
388  return (int)i;
389  // phi outside bin range
390  return -1;
391 }
std::vector< double > SLphis

◆ getRecord()

CastorShowerEvent CastorShowerLibrary::getRecord ( int  type,
int  record 
)
protected

Definition at line 229 of file CastorShowerLibrary.cc.

References emBranch, CastorShowerEvent::getNhit(), hadBranch, LogDebug, and AlCaHarvesting_cff::record.

Referenced by select().

229  {
231  //
232  // Retrieve event # "record" from the library and stores it
233  // into vector<CastorShowerHit> showerHit;
234  //
235  // Based on HFShowerLibrary::getRecord
236  //
237  // Modified 02/02/09 by W. Carvalho
238  //
240 
241 #ifdef EDM_ML_DEBUG
242  LogDebug("CastorShower") << "CastorShowerLibrary::getRecord: ";
243 #endif
244  int nrc = record;
245  CastorShowerEvent retValue;
246  CastorShowerEvent* showerEvent = &retValue;
247  if (type > 0) {
248  hadBranch->SetAddress(&showerEvent);
249  hadBranch->GetEntry(nrc);
250  } else {
251  emBranch->SetAddress(&showerEvent);
252  emBranch->GetEntry(nrc);
253  }
254 
255 #ifdef EDM_ML_DEBUG
256  int nHit = showerEvent->getNhit();
257  LogDebug("CastorShower") << "CastorShowerLibrary::getRecord: Record " << record << " of type " << type << " with "
258  << nHit << " CastorShowerHits";
259 
260 #endif
261  return retValue;
262 }
unsigned int getNhit()
#define LogDebug(id)

◆ getShowerHits()

CastorShowerEvent CastorShowerLibrary::getShowerHits ( const G4Step *  aStep,
bool &  ok 
)

Definition at line 191 of file CastorShowerLibrary.cc.

References funct::abs(), G4TrackToParticleID::isGammaElectronPositron(), G4TrackToParticleID::isStableHadronIon(), dqm-mbProfile::log, convertSQLiteXML::ok, pi, dttmaxenums::R, select(), mathSSE::sqrt(), funct::tan(), theta(), and HLT_2024v14_cff::track.

Referenced by CastorSD::getFromLibrary().

191  {
192  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
193  G4Track* track = aStep->GetTrack();
194 
195  const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
196 
198  hit.Clear();
199 
200  ok = false;
203  return hit;
204  }
205  ok = true;
206 
207  double pin = preStepPoint->GetTotalEnergy();
208  double zint = hitPoint.z();
209  double R = sqrt(hitPoint.x() * hitPoint.x() + hitPoint.y() * hitPoint.y());
210  double theta = atan2(R, std::abs(zint));
211  double phiin = atan2(hitPoint.y(), hitPoint.x());
212  double etain = -std::log(std::tan((CLHEP::pi - theta) * 0.5));
213 
214  // Replace "interpolation/extrapolation" by new method "select" that just randomly
215  // selects a record from the appropriate energy bin and fills its content to
216  // "showerEvent" instance of class CastorShowerEvent
217 
218  if (isEM) {
219  hit = select(0, pin, etain, phiin);
220  } else {
221  hit = select(1, pin, etain, phiin);
222  }
223 
224  return hit;
225 }
const Double_t pi
T sqrt(T t)
Definition: SSEVec.h:23
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static bool isStableHadronIon(const G4Track *)
static bool isGammaElectronPositron(int pdgCode)
CastorShowerEvent select(int, double, double=0, double=9)
Geom::Theta< T > theta() const

◆ initFile()

void CastorShowerLibrary::initFile ( edm::ParameterSet const &  p)
protected

Definition at line 59 of file CastorShowerLibrary.cc.

References emBranch, Exception, personalPlayback::fp, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), hadBranch, hf, loadEventInfo(), AlCaHLTBitMon_ParallelJobs::p, AlCaHLTBitMon_QueryRunRegistry::string, and verbose.

Referenced by CastorShowerLibrary().

59  {
61  //
62  // Init TFile and associated TBranch's of CASTOR Root file
63  // holding library events
64  //
66 
67  //
68  // Read PSet for Castor shower library
69  //
70 
71  edm::ParameterSet m_CS = p.getParameter<edm::ParameterSet>("CastorShowerLibrary");
72  edm::FileInPath fp = m_CS.getParameter<edm::FileInPath>("FileName");
73  std::string pTreeName = fp.fullPath();
74  std::string branchEvInfo = m_CS.getUntrackedParameter<std::string>("BranchEvt");
75  std::string branchEM = m_CS.getUntrackedParameter<std::string>("BranchEM");
76  std::string branchHAD = m_CS.getUntrackedParameter<std::string>("BranchHAD");
77  verbose = m_CS.getUntrackedParameter<bool>("Verbosity", false);
78 
79  // Open TFile
80  if (pTreeName.find('.') == 0)
81  pTreeName.erase(0, 2);
82  const char* nTree = pTreeName.c_str();
83  hf = TFile::Open(nTree);
84 
85  // Check that TFile has been successfully opened
86  if (!hf->IsOpen()) {
87  edm::LogError("CastorShower") << "CastorShowerLibrary: opening " << nTree << " failed";
88  throw cms::Exception("Unknown", "CastorShowerLibrary") << "Opening of " << pTreeName << " fails\n";
89  } else {
90  edm::LogVerbatim("CastorShower") << "CastorShowerLibrary: opening " << nTree << " successfully";
91  }
92 
93  // Check for the TBranch holding EventVerbatim in "Events" TTree
94  TTree* event = hf->Get<TTree>("CastorCherenkovPhotons");
95  if (event) {
96  auto evtInfo = event->GetBranch(branchEvInfo.c_str());
97  if (evtInfo) {
98  loadEventInfo(evtInfo);
99  } else {
100  edm::LogError("CastorShower") << "CastorShowerLibrary: " << branchEvInfo.c_str()
101  << " Branch does not exit in Event";
102  throw cms::Exception("Unknown", "CastorShowerLibrary") << "Event information absent\n";
103  }
104  } else {
105  edm::LogError("CastorShower") << "CastorShowerLibrary: Events Tree does not exist";
106  throw cms::Exception("Unknown", "CastorShowerLibrary") << "Events tree absent\n";
107  }
108 
109  // Get EM and HAD Branchs
110  emBranch = event->GetBranch(branchEM.c_str());
111  if (verbose)
112  emBranch->Print();
113  hadBranch = event->GetBranch(branchHAD.c_str());
114  if (verbose)
115  hadBranch->Print();
116  edm::LogVerbatim("CastorShower") << "CastorShowerLibrary: Branch " << branchEM << " has " << emBranch->GetEntries()
117  << " entries and Branch " << branchHAD << " has " << hadBranch->GetEntries()
118  << " entries";
119 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
void loadEventInfo(TBranch *)
Definition: event.py:1

◆ loadEventInfo()

void CastorShowerLibrary::loadEventInfo ( TBranch *  branch)
protected

Definition at line 123 of file CastorShowerLibrary.cc.

References MicroEventContent_cff::branch, dumpTauVariables_cfi::eventInfo, mps_fire::i, nBinsE, nBinsEta, nBinsPhi, nEvtPerBinE, nEvtPerBinEta, nEvtPerBinPhi, SLenergies, SLetas, SLphis, and totEvents.

Referenced by initFile().

123  {
125  //
126  // Get EventInfo from the "TBranch* branch" of Root file
127  // holding library events
128  //
129  // Based on HFShowerLibrary::loadEventInfo
130  //
132 
133  CastorShowerLibraryInfo tempInfo;
134  auto* eventInfo = &tempInfo;
135  branch->SetAddress(&eventInfo);
136  branch->GetEntry(0);
137  // Initialize shower library general parameters
138 
139  totEvents = eventInfo->Energy.getNEvts();
140  nBinsE = eventInfo->Energy.getNBins();
141  nEvtPerBinE = eventInfo->Energy.getNEvtPerBin();
142  SLenergies = eventInfo->Energy.getBin();
143  nBinsEta = eventInfo->Eta.getNBins();
144  nEvtPerBinEta = eventInfo->Eta.getNEvtPerBin();
145  SLetas = eventInfo->Eta.getBin();
146  nBinsPhi = eventInfo->Phi.getNBins();
147  nEvtPerBinPhi = eventInfo->Phi.getNEvtPerBin();
148  SLphis = eventInfo->Phi.getBin();
149 
150  // Convert from GeV to MeV
151  for (unsigned int i = 0; i < SLenergies.size(); i++) {
152  SLenergies[i] *= CLHEP::GeV;
153  }
154 
155  edm::LogVerbatim("CastorShower") << " CastorShowerLibrary::loadEventInfo : "
156  << "\n \n Total number of events : " << totEvents
157  << "\n Number of bins (E) : " << nBinsE
158  << "\n Number of events/bin (E) : " << nEvtPerBinE
159  << "\n Number of bins (Eta) : " << nBinsEta
160  << "\n Number of events/bin (Eta) : " << nEvtPerBinEta
161  << "\n Number of bins (Phi) : " << nBinsPhi
162  << "\n Number of events/bin (Phi) : " << nEvtPerBinPhi << "\n";
163 
164  std::stringstream ss1;
165  ss1 << "CastorShowerLibrary: energies in GeV:\n";
166  for (unsigned int i = 0; i < nBinsE; ++i) {
167  if (i > 0 && i / 10 * 10 == i) {
168  ss1 << "\n";
169  }
170  ss1 << " " << SLenergies[i] / CLHEP::GeV;
171  }
172  ss1 << "\nCastorShowerLibrary: etas:\n";
173  for (unsigned int i = 0; i < nBinsEta; ++i) {
174  if (i > 0 && i / 10 * 10 == i) {
175  ss1 << "\n";
176  }
177  ss1 << " " << SLetas[i];
178  }
179  ss1 << "\nCastorShowerLibrary: phis:\n";
180  for (unsigned int i = 0; i < nBinsPhi; ++i) {
181  if (i > 0 && i / 10 * 10 == i) {
182  ss1 << "\n";
183  }
184  ss1 << " " << SLphis[i];
185  }
186  edm::LogVerbatim("CastorShower") << ss1.str();
187 }
Log< level::Info, true > LogVerbatim
std::vector< double > SLetas
std::vector< double > SLphis
std::vector< double > SLenergies
eventInfo
add run, event number and lumi section

◆ select()

CastorShowerEvent CastorShowerLibrary::select ( int  type,
double  pin,
double  etain = 0,
double  phiin = 9 
)
protected

Definition at line 266 of file CastorShowerLibrary.cc.

References FindEnergyBin(), FindEtaBin(), FindPhiBin(), getRecord(), hcalRecHitTable_cff::ieta, createfilelist::int, hcalRecHitTable_cff::iphi, M_PI, nEvtPerBinE, nEvtPerBinEta, nEvtPerBinPhi, AlignmentTrackSelector_cfi::phiMax, AlignmentTrackSelector_cfi::phiMin, alignCSCRings::r, and verbose.

Referenced by getShowerHits().

266  {
268  //
269  // Selects an event from the library based on
270  //
271  // type: 0 --> em
272  // >0 --> had
273  // pin : momentum
274  // etain: eta (if not given, disregard the eta binning
275  // phiin: phi (if not given, disregard the phi binning
276  //
277  // Created 30/01/09 by W. Carvalho
278  //
280 
281  int irec; // to hold record number
282  double r = G4UniformRand(); // to randomly select within an energy bin (r=[0,1])
283 
284  // Randomly select a record from the right energy bin in the library,
285  // based on track momentum (pin)
286 
287  int ienergy = FindEnergyBin(pin);
288  int ieta = FindEtaBin(etain);
289 #ifdef EDM_ML_DEBUG
290  if (verbose)
291  edm::LogVerbatim("CastorShower") << " ienergy = " << ienergy;
292  if (verbose)
293  edm::LogVerbatim("CastorShower") << " ieta = " << ieta;
294 #endif
295 
296  int iphi;
297  const double phiMin = 0.;
298  const double phiMax = M_PI / 4.; // 45 * (pi/180) rad
299  if (phiin < phiMin)
300  phiin = phiin + M_PI;
301  if (phiin >= phiMin && phiin < phiMax) {
302  iphi = FindPhiBin(phiin);
303  } else {
304  double remainder = fmod(phiin, phiMax);
305  phiin = phiMin + remainder;
306  iphi = FindPhiBin(phiin);
307  }
308 #ifdef EDM_ML_DEBUG
309  if (verbose)
310  edm::LogVerbatim("CastorShower") << " iphi = " << iphi;
311 #endif
312  if (ienergy == -1)
313  ienergy = 0; // if pin < first bin, choose an event in the first one
314  if (ieta == -1)
315  ieta = 0; // idem for eta
316  if (iphi != -1)
317  irec = int(nEvtPerBinE * ienergy + nEvtPerBinEta * ieta + nEvtPerBinPhi * (iphi + r));
318  else
319  irec = int(nEvtPerBinE * (ienergy + r));
320 
321 #ifdef EDM_ML_DEBUG
322  edm::LogVerbatim("CastorShower") << "CastorShowerLibrary:: Select record " << irec << " of type " << type;
323 #endif
324 
325  // Retrieve record number "irec" from the library
326  return getRecord(type, irec);
327 }
Log< level::Info, true > LogVerbatim
#define M_PI
CastorShowerEvent getRecord(int, int)

Member Data Documentation

◆ emBranch

TBranch* CastorShowerLibrary::emBranch
private

Definition at line 48 of file CastorShowerLibrary.h.

Referenced by getRecord(), and initFile().

◆ evtPerBin

unsigned int CastorShowerLibrary::evtPerBin
private

Definition at line 51 of file CastorShowerLibrary.h.

◆ hadBranch

TBranch * CastorShowerLibrary::hadBranch
private

Definition at line 48 of file CastorShowerLibrary.h.

Referenced by getRecord(), and initFile().

◆ hf

TFile* CastorShowerLibrary::hf
private

Definition at line 47 of file CastorShowerLibrary.h.

Referenced by initFile(), and ~CastorShowerLibrary().

◆ nBinsE

unsigned int CastorShowerLibrary::nBinsE
private

Definition at line 56 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

◆ nBinsEta

unsigned int CastorShowerLibrary::nBinsEta
private

Definition at line 56 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

◆ nBinsPhi

unsigned int CastorShowerLibrary::nBinsPhi
private

Definition at line 56 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

◆ nEvtPerBinE

unsigned int CastorShowerLibrary::nEvtPerBinE
private

Definition at line 57 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

◆ nEvtPerBinEta

unsigned int CastorShowerLibrary::nEvtPerBinEta
private

Definition at line 57 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

◆ nEvtPerBinPhi

unsigned int CastorShowerLibrary::nEvtPerBinPhi
private

Definition at line 57 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

◆ nMomBin

unsigned int CastorShowerLibrary::nMomBin
private

Definition at line 51 of file CastorShowerLibrary.h.

◆ pmom

std::vector<double> CastorShowerLibrary::pmom
private

Definition at line 53 of file CastorShowerLibrary.h.

◆ SLenergies

std::vector<double> CastorShowerLibrary::SLenergies
private

Definition at line 58 of file CastorShowerLibrary.h.

Referenced by FindEnergyBin(), and loadEventInfo().

◆ SLetas

std::vector<double> CastorShowerLibrary::SLetas
private

Definition at line 59 of file CastorShowerLibrary.h.

Referenced by FindEtaBin(), and loadEventInfo().

◆ SLphis

std::vector<double> CastorShowerLibrary::SLphis
private

Definition at line 60 of file CastorShowerLibrary.h.

Referenced by FindPhiBin(), and loadEventInfo().

◆ totEvents

unsigned int CastorShowerLibrary::totEvents
private

Definition at line 51 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

◆ verbose

bool CastorShowerLibrary::verbose
private

Definition at line 50 of file CastorShowerLibrary.h.

Referenced by initFile(), and select().