CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

AsciiNeutronReader Class Reference

#include <AsciiNeutronReader.h>

Inheritance diagram for AsciiNeutronReader:
NeutronReader

List of all members.

Public Member Functions

 AsciiNeutronReader (std::string fileNameBase)
virtual void readNextEvent (int chamberType, edm::PSimHitContainer &result)

Private Member Functions

int read_nhits (std::ifstream &fin, int chamberType)
void resetStreampos (std::ifstream &fin, int chamberType)

Private Attributes

std::string theFileNameBase
std::vector< std::streampos > theStreamPos

Detailed Description

This reads patterns of neutron hits in muon chambers from an ASCII database, so they can be superimposed onto signal events. It reads the events sequentially, and loops back to the beginning when it reaches EOF

Definition at line 17 of file AsciiNeutronReader.h.


Constructor & Destructor Documentation

AsciiNeutronReader::AsciiNeutronReader ( std::string  fileNameBase)

Definition at line 10 of file AsciiNeutronReader.cc.

                                                          :
  theFileNameBase(fileNameBase),
  //theStreamPos(nChamberTypes+1, 0) //TODO WON"T WORK!  replace with a map 
  theStreamPos(11,0)
{
}

Member Function Documentation

int AsciiNeutronReader::read_nhits ( std::ifstream &  fin,
int  chamberType 
) [private]

Definition at line 45 of file AsciiNeutronReader.cc.

References LogDebug, resetStreampos(), and theStreamPos.

Referenced by readNextEvent().

                                                                  {
  int nhits = 0;
    // go to the last saved place
  fin.seekg(theStreamPos[chamberType]);
  if(fin.eof()) {
    resetStreampos(fin, chamberType);
  }
  LogDebug("NeutronReader") << "starting from pos " << theStreamPos[chamberType] 
                  << " EOF " << fin.eof();
  fin >> nhits;
  if(fin.eof()) {
    resetStreampos(fin, chamberType);
    fin >> nhits;
  }
  LogDebug("NeutronReader") << "returning nhits " << nhits;
  return nhits;
}
void AsciiNeutronReader::readNextEvent ( int  chamberType,
edm::PSimHitContainer result 
) [virtual]

Implements NeutronReader.

Definition at line 18 of file AsciiNeutronReader.cc.

References Exception, cmsRelvalreport::exit, convertXMLtoSQLite_cfg::fileName, groupFilesInBlocks::fin, recoMuon::in, AlCaHLTBitMon_ParallelJobs::p, phi, read_nhits(), theFileNameBase, theStreamPos, and theta().

                                                                                    {
  stringstream fileName;
  fileName << theFileNameBase << chamberType;
  ifstream fin(fileName.str().c_str(), ios::in);
  if(!fin.is_open()) {
    throw cms::Exception("NeutronReader") 
      << "Muon neutron noise file missing " << fileName.str();
  }

  int nhits = read_nhits(fin, chamberType);
  for(int ihit = 0; ihit < nhits; ++ihit) {
    float entryX, entryY, entryZ, exitX, exitY, exitZ;
    float p, tof, eloss, theta, phi;
    int type, layer, track;

    fin >> entryX >> entryY >> entryZ
        >> exitX  >> exitY  >> exitZ
        >> p >> tof >> eloss >> type >> layer >> track >> theta >> phi;
    LocalPoint entry(entryX, entryY, entryZ);
    LocalPoint exit (exitX,  exitY,  exitZ);
    PSimHit phit(entry, exit, p, tof, eloss, type, layer, track, theta, phi);
    result.push_back(phit);
  }
  theStreamPos[chamberType] = fin.tellg();
}
void AsciiNeutronReader::resetStreampos ( std::ifstream &  fin,
int  chamberType 
) [private]

Definition at line 64 of file AsciiNeutronReader.cc.

References LogDebug, and theStreamPos.

Referenced by read_nhits().

                                                                       {
  LogDebug("NeutronReader") << "reached EOF, resetting streampos ";
  theStreamPos[chamberType] = 0;
  fin.clear();
  fin.seekg(0, ios::beg);
}

Member Data Documentation

std::string AsciiNeutronReader::theFileNameBase [private]

Definition at line 29 of file AsciiNeutronReader.h.

Referenced by readNextEvent().

std::vector<std::streampos> AsciiNeutronReader::theStreamPos [private]

Definition at line 30 of file AsciiNeutronReader.h.

Referenced by read_nhits(), readNextEvent(), and resetStreampos().