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

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

Private Attributes

TBranchObject * emBranch
 
CastorShowerLibraryInfoeventInfo
 
TBranchObject * evtInfo
 
unsigned int evtPerBin
 
TBranchObject * 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
 
CastorShowerEventshowerEvent
 
std::vector< double > SLenergies
 
std::vector< double > SLetas
 
std::vector< double > SLphis
 
unsigned int totEvents
 
bool verbose
 

Detailed Description

Definition at line 28 of file CastorShowerLibrary.h.

Constructor & Destructor Documentation

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

Definition at line 30 of file CastorShowerLibrary.cc.

References initFile().

31  : hf(nullptr),
32  evtInfo(nullptr),
33  emBranch(nullptr),
34  hadBranch(nullptr),
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
TBranchObject * emBranch
std::vector< double > SLphis
TBranchObject * hadBranch
void initFile(edm::ParameterSet const &)
std::vector< double > SLenergies
TBranchObject * evtInfo
CastorShowerLibrary::~CastorShowerLibrary ( )

Definition at line 52 of file CastorShowerLibrary.cc.

References hf.

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

Member Function Documentation

int CastorShowerLibrary::FindEnergyBin ( double  energy)

Definition at line 313 of file CastorShowerLibrary.cc.

References mps_fire::i, and SLenergies.

Referenced by select().

313  {
314  //
315  // returns the integer index of the energy bin, taken from SLenergies vector
316  // returns -1 if ouside valid range
317  //
318  if (energy >= SLenergies.back())
319  return SLenergies.size() - 1;
320 
321  unsigned int i = 0;
322  for (; i < SLenergies.size() - 1; i++)
323  if (energy >= SLenergies.at(i) && energy < SLenergies.at(i + 1))
324  return (int)i;
325 
326  // now i points to the last but 1 bin
327  if (energy >= SLenergies.at(i))
328  return (int)i;
329  // energy outside bin range
330  return -1;
331 }
std::vector< double > SLenergies
int CastorShowerLibrary::FindEtaBin ( double  eta)

Definition at line 335 of file CastorShowerLibrary.cc.

References mps_fire::i, and SLetas.

Referenced by select().

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

Definition at line 355 of file CastorShowerLibrary.cc.

References mps_fire::i, and SLphis.

Referenced by select().

355  {
356  //
357  // returns the integer index of the phi bin, taken from SLphis vector
358  // returns -1 if ouside valid range
359  //
360  // needs protection in case phi is outside range -pi,pi
361  //
362  if (phi >= SLphis.back())
363  return SLphis.size() - 1;
364  unsigned int i = 0;
365  for (; i < SLphis.size() - 1; i++)
366  if (phi >= SLphis.at(i) && phi < SLphis.at(i + 1))
367  return (int)i;
368  // now i points to the last but 1 bin
369  if (phi >= SLphis.at(i))
370  return (int)i;
371  // phi outside bin range
372  return -1;
373 }
std::vector< double > SLphis
void CastorShowerLibrary::getRecord ( int  type,
int  record 
)
protected

Definition at line 213 of file CastorShowerLibrary.cc.

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

Referenced by select().

213  {
215  //
216  // Retrieve event # "record" from the library and stores it
217  // into vector<CastorShowerHit> showerHit;
218  //
219  // Based on HFShowerLibrary::getRecord
220  //
221  // Modified 02/02/09 by W. Carvalho
222  //
224 
225 #ifdef DebugLog
226  LogDebug("CastorShower") << "CastorShowerLibrary::getRecord: ";
227 #endif
228  int nrc = record;
230  if (type > 0) {
231  hadBranch->SetAddress(&showerEvent);
232  hadBranch->GetEntry(nrc);
233  } else {
234  emBranch->SetAddress(&showerEvent);
235  emBranch->GetEntry(nrc);
236  }
237 
238 #ifdef DebugLog
239  int nHit = showerEvent->getNhit();
240  LogDebug("CastorShower") << "CastorShowerLibrary::getRecord: Record " << record << " of type " << type << " with "
241  << nHit << " CastorShowerHits";
242 
243 #endif
244 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
JetCorrectorParameters::Record record
Definition: classes.h:7
TBranchObject * emBranch
TBranchObject * hadBranch
CastorShowerEvent * showerEvent
unsigned int getNhit()
CastorShowerEvent CastorShowerLibrary::getShowerHits ( const G4Step *  aStep,
bool &  ok 
)

Definition at line 174 of file CastorShowerLibrary.cc.

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

Referenced by CastorSD::getFromLibrary().

174  {
175  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
176  G4Track* track = aStep->GetTrack();
177 
178  const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
179 
181  hit.Clear();
182 
183  ok = false;
185  if (!isEM && !G4TrackToParticleID::isStableHadronIon(track)) {
186  return hit;
187  }
188  ok = true;
189 
190  double pin = preStepPoint->GetTotalEnergy();
191  double zint = hitPoint.z();
192  double R = sqrt(hitPoint.x() * hitPoint.x() + hitPoint.y() * hitPoint.y());
193  double theta = atan2(R, std::abs(zint));
194  double phiin = atan2(hitPoint.y(), hitPoint.x());
195  double etain = -std::log(std::tan((CLHEP::pi - theta) * 0.5));
196 
197  // Replace "interpolation/extrapolation" by new method "select" that just randomly
198  // selects a record from the appropriate energy bin and fills its content to
199  // "showerEvent" instance of class CastorShowerEvent
200 
201  if (isEM) {
202  select(0, pin, etain, phiin);
203  } else {
204  select(1, pin, etain, phiin);
205  }
206 
207  hit = (*showerEvent);
208  return hit;
209 }
void Clear(Option_t *option="") override
void select(int, double, double=0, double=9)
Geom::Theta< T > theta() const
const Double_t pi
T sqrt(T t)
Definition: SSEVec.h:19
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)
void CastorShowerLibrary::initFile ( edm::ParameterSet const &  p)
protected

Definition at line 59 of file CastorShowerLibrary.cc.

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

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::LogInfo("CastorShower") << "CastorShowerLibrary: opening " << nTree << " successfully";
91  }
92 
93  // Check for the TBranch holding EventInfo in "Events" TTree
94  TTree* event = (TTree*)hf->Get("CastorCherenkovPhotons");
95  if (event) {
96  evtInfo = (TBranchObject*)event->GetBranch(branchEvInfo.c_str());
97  if (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 = (TBranchObject*)event->GetBranch(branchEM.c_str());
111  if (verbose)
112  emBranch->Print();
113  hadBranch = (TBranchObject*)event->GetBranch(branchHAD.c_str());
114  if (verbose)
115  hadBranch->Print();
116  edm::LogInfo("CastorShower") << "CastorShowerLibrary: Branch " << branchEM << " has " << emBranch->GetEntries()
117  << " entries and Branch " << branchHAD << " has " << hadBranch->GetEntries()
118  << " entries";
119 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TBranchObject * emBranch
TBranchObject * hadBranch
void loadEventInfo(TBranchObject *)
TBranchObject * evtInfo
Definition: event.py:1
void CastorShowerLibrary::loadEventInfo ( TBranchObject *  branch)
protected

Definition at line 123 of file CastorShowerLibrary.cc.

References CastorShowerLibraryInfo::Energy, CastorShowerLibraryInfo::Eta, eventInfo, SLBin::getBin(), SLBin::getNBins(), SLBin::getNEvtPerBin(), SLBin::getNEvts(), GeV, mps_fire::i, nBinsE, nBinsEta, nBinsPhi, nEvtPerBinE, nEvtPerBinEta, nEvtPerBinPhi, CastorShowerLibraryInfo::Phi, 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 
134  branch->SetAddress(&eventInfo);
135  branch->GetEntry(0);
136  // Initialize shower library general parameters
137 
144  SLetas = eventInfo->Eta.getBin();
147  SLphis = eventInfo->Phi.getBin();
148 
149  // Convert from GeV to MeV
150  for (unsigned int i = 0; i < SLenergies.size(); i++) {
151  SLenergies[i] *= CLHEP::GeV;
152  }
153 
154  edm::LogInfo("CastorShower") << " CastorShowerLibrary::loadEventInfo : "
155  << "\n \n Total number of events : " << totEvents
156  << "\n Number of bins (E) : " << nBinsE
157  << "\n Number of events/bin (E) : " << nEvtPerBinE
158  << "\n Number of bins (Eta) : " << nBinsEta
159  << "\n Number of events/bin (Eta) : " << nEvtPerBinEta
160  << "\n Number of bins (Phi) : " << nBinsPhi
161  << "\n Number of events/bin (Phi) : " << nEvtPerBinPhi << "\n";
162 
163  for (unsigned int i = 0; i < nBinsE; i++)
164  edm::LogInfo("CastorShower") << "CastorShowerLibrary: SLenergies[" << i << "] = " << SLenergies[i] / CLHEP::GeV
165  << " GeV";
166  for (unsigned int i = 0; i < nBinsEta; i++)
167  edm::LogInfo("CastorShower") << "CastorShowerLibrary: SLetas[" << i << "] = " << SLetas[i];
168  for (unsigned int i = 0; i < nBinsPhi; i++)
169  edm::LogInfo("CastorShower") << "CastorShowerLibrary: SLphis[" << i << "] = " << SLphis[i] << " rad";
170 }
const double GeV
Definition: MathUtil.h:16
std::vector< double > SLetas
unsigned int getNBins()
std::vector< double > SLphis
unsigned int getNEvts()
unsigned int getNEvtPerBin()
std::vector< double > SLenergies
CastorShowerLibraryInfo * eventInfo
double getBin(int i)
void CastorShowerLibrary::select ( int  type,
double  pin,
double  etain = 0,
double  phiin = 9 
)
protected

Definition at line 248 of file CastorShowerLibrary.cc.

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

Referenced by getShowerHits().

248  {
250  //
251  // Selects an event from the library based on
252  //
253  // type: 0 --> em
254  // >0 --> had
255  // pin : momentum
256  // etain: eta (if not given, disregard the eta binning
257  // phiin: phi (if not given, disregard the phi binning
258  //
259  // Created 30/01/09 by W. Carvalho
260  //
262 
263  int irec; // to hold record number
264  double r = G4UniformRand(); // to randomly select within an energy bin (r=[0,1])
265 
266  // Randomly select a record from the right energy bin in the library,
267  // based on track momentum (pin)
268 
269  int ienergy = FindEnergyBin(pin);
270  int ieta = FindEtaBin(etain);
271 #ifdef DebugLog
272  if (verbose)
273  edm::LogInfo("CastorShower") << " ienergy = " << ienergy;
274  if (verbose)
275  edm::LogInfo("CastorShower") << " ieta = " << ieta;
276 #endif
277 
278  int iphi;
279  const double phiMin = 0.;
280  const double phiMax = M_PI / 4.; // 45 * (pi/180) rad
281  if (phiin < phiMin)
282  phiin = phiin + M_PI;
283  if (phiin >= phiMin && phiin < phiMax) {
284  iphi = FindPhiBin(phiin);
285  } else {
286  double remainder = fmod(phiin, phiMax);
287  phiin = phiMin + remainder;
288  iphi = FindPhiBin(phiin);
289  }
290 #ifdef DebugLog
291  if (verbose)
292  edm::LogInfo("CastorShower") << " iphi = " << iphi;
293 #endif
294  if (ienergy == -1)
295  ienergy = 0; // if pin < first bin, choose an event in the first one
296  if (ieta == -1)
297  ieta = 0; // idem for eta
298  if (iphi != -1)
299  irec = int(nEvtPerBinE * ienergy + nEvtPerBinEta * ieta + nEvtPerBinPhi * (iphi + r));
300  else
301  irec = int(nEvtPerBinE * (ienergy + r));
302 
303 #ifdef DebugLog
304  edm::LogInfo("CastorShower") << "CastorShowerLibrary:: Select record " << irec << " of type " << type;
305 #endif
306 
307  // Retrieve record number "irec" from the library
308  getRecord(type, irec);
309 }
type
Definition: HCALResponse.h:21
#define M_PI

Member Data Documentation

TBranchObject* CastorShowerLibrary::emBranch
private

Definition at line 50 of file CastorShowerLibrary.h.

Referenced by getRecord(), and initFile().

CastorShowerLibraryInfo* CastorShowerLibrary::eventInfo
private

Definition at line 53 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

TBranchObject* CastorShowerLibrary::evtInfo
private

Definition at line 49 of file CastorShowerLibrary.h.

Referenced by initFile().

unsigned int CastorShowerLibrary::evtPerBin
private

Definition at line 57 of file CastorShowerLibrary.h.

TBranchObject * CastorShowerLibrary::hadBranch
private

Definition at line 50 of file CastorShowerLibrary.h.

Referenced by getRecord(), and initFile().

TFile* CastorShowerLibrary::hf
private

Definition at line 48 of file CastorShowerLibrary.h.

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

unsigned int CastorShowerLibrary::nBinsE
private

Definition at line 62 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

unsigned int CastorShowerLibrary::nBinsEta
private

Definition at line 62 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

unsigned int CastorShowerLibrary::nBinsPhi
private

Definition at line 62 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

unsigned int CastorShowerLibrary::nEvtPerBinE
private

Definition at line 63 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

unsigned int CastorShowerLibrary::nEvtPerBinEta
private

Definition at line 63 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

unsigned int CastorShowerLibrary::nEvtPerBinPhi
private

Definition at line 63 of file CastorShowerLibrary.h.

Referenced by loadEventInfo(), and select().

unsigned int CastorShowerLibrary::nMomBin
private

Definition at line 57 of file CastorShowerLibrary.h.

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

Definition at line 59 of file CastorShowerLibrary.h.

CastorShowerEvent* CastorShowerLibrary::showerEvent
private

Definition at line 54 of file CastorShowerLibrary.h.

Referenced by getRecord().

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

Definition at line 64 of file CastorShowerLibrary.h.

Referenced by FindEnergyBin(), and loadEventInfo().

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

Definition at line 65 of file CastorShowerLibrary.h.

Referenced by FindEtaBin(), and loadEventInfo().

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

Definition at line 66 of file CastorShowerLibrary.h.

Referenced by FindPhiBin(), and loadEventInfo().

unsigned int CastorShowerLibrary::totEvents
private

Definition at line 57 of file CastorShowerLibrary.h.

Referenced by loadEventInfo().

bool CastorShowerLibrary::verbose
private

Definition at line 56 of file CastorShowerLibrary.h.