CMS 3D CMS Logo

SubsystemNeutronWriter Class Reference

theSubsystemNeutronWriter stores "events" which consist of a list of SimHits, grouped by detector type. More...

#include <SimMuon/Neutron/interface/SubsystemNeutronWriter.h>

Inheritance diagram for SubsystemNeutronWriter:

edm::EDAnalyzer CSCNeutronWriter

List of all members.

Public Member Functions

virtual void analyze (edm::Event const &e, edm::EventSetup const &c)
virtual int chamberId (int globalDetId) const =0
virtual int chamberType (int globalDetId) const =0
void initialize (int chamberType)
 good practice to do once for each chamber type
virtual int localDetId (int globalDetId) const =0
void printStats ()
 SubsystemNeutronWriter (edm::ParameterSet const &pset)
virtual ~SubsystemNeutronWriter ()
 destructor prints statistics on number of events written

Protected Member Functions

void adjust (PSimHit &h, float timeOffset)
 helper to add time offsets and local det ID
void updateCount (int chamberType)
 updates the counter
virtual void writeHits (int chamberType, edm::PSimHitContainer &allSimHits)

Private Attributes

bool initialized
std::map< int, inttheCountPerChamberType
NeutronWritertheHitWriter
edm::InputTag theInputTag
double theNeutronTimeCut
int theNEvents
double theTimeWindow


Detailed Description

theSubsystemNeutronWriter stores "events" which consist of a list of SimHits, grouped by detector type.

These can then be read back to model neutron background int muon chambers.

You can specify the cut on how long after the signal event to define something as a Neutron Event with the configurable Muon:NeutronTimeCut

Definition at line 25 of file SubsystemNeutronWriter.h.


Constructor & Destructor Documentation

SubsystemNeutronWriter::SubsystemNeutronWriter ( edm::ParameterSet const &  pset  )  [explicit]

Definition at line 18 of file SubsystemNeutronWriter.cc.

References Exception, edm::ParameterSet::getParameter(), output(), and theHitWriter.

00019 : theInputTag(pset.getParameter<edm::InputTag>("input")),
00020   theNeutronTimeCut(pset.getParameter<double>("neutronTimeCut")),
00021   theTimeWindow(pset.getParameter<double>("timeWindow")),
00022   theNEvents(0),
00023   initialized(false)
00024 {
00025   string writer = pset.getParameter<string>("writer");
00026   string output = pset.getParameter<string>("output");
00027   if(writer == "ASCII")
00028   {
00029     theHitWriter = new AsciiNeutronWriter(output);
00030   }
00031   else if (writer == "ROOT")
00032   {
00033     theHitWriter = new RootNeutronWriter(output);
00034   }
00035   else 
00036   {
00037     throw cms::Exception("NeutronWriter") << "Bad writer: "
00038       << writer;
00039   } 
00040 }

SubsystemNeutronWriter::~SubsystemNeutronWriter (  )  [virtual]

destructor prints statistics on number of events written

Definition at line 43 of file SubsystemNeutronWriter.cc.

References printStats(), and theHitWriter.

00044 {
00045   printStats();
00046   delete theHitWriter;
00047 }


Member Function Documentation

void SubsystemNeutronWriter::adjust ( PSimHit h,
float  timeOffset 
) [protected]

helper to add time offsets and local det ID

Definition at line 134 of file SubsystemNeutronWriter.cc.

References PSimHit::detUnitId(), PSimHit::energyLoss(), PSimHit::entryPoint(), PSimHit::exitPoint(), localDetId(), PSimHit::momentumAtEntry(), PSimHit::pabs(), PSimHit::particleType(), PV3DBase< T, PVType, FrameType >::phi(), PV3DBase< T, PVType, FrameType >::theta(), PSimHit::timeOfFlight(), and PSimHit::trackId().

Referenced by writeHits().

00134                                                                  {
00135   
00136   h = PSimHit( h.entryPoint(), h.exitPoint(), h.pabs(), 
00137                h.timeOfFlight() + timeOffset,
00138                h.energyLoss(), h.particleType(), 
00139                localDetId(h.detUnitId()), h.trackId(),
00140                h.momentumAtEntry().theta(),
00141                h.momentumAtEntry().phi() );
00142 }

void SubsystemNeutronWriter::analyze ( edm::Event const &  e,
edm::EventSetup const &  c 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 60 of file SubsystemNeutronWriter.cc.

References chamberId(), chamberType(), edm::Event::getByLabel(), theInputTag, theNEvents, and writeHits().

00061 {
00062   ++theNEvents;
00063   edm::Handle<edm::PSimHitContainer> hits;
00064   e.getByLabel(theInputTag, hits);
00065 
00066   // sort hits by chamber
00067   map<int, edm::PSimHitContainer> hitsByChamber;
00068   for(edm::PSimHitContainer::const_iterator hitItr = hits->begin();
00069       hitItr != hits->end(); ++hitItr)
00070   {
00071     int chamberIndex = chamberId(hitItr->detUnitId());
00072     hitsByChamber[chamberIndex].push_back(*hitItr);
00073   }
00074 
00075   // now write out each chamber's contents
00076   for(map<int, edm::PSimHitContainer>::iterator hitsByChamberItr = hitsByChamber.begin();
00077       hitsByChamberItr != hitsByChamber.end(); ++hitsByChamberItr)
00078   {
00079     int chambertype = chamberType(hitsByChamberItr->first);
00080     writeHits(chambertype, hitsByChamberItr->second);
00081   }
00082 }

virtual int SubsystemNeutronWriter::chamberId ( int  globalDetId  )  const [pure virtual]

Implemented in CSCNeutronWriter.

Referenced by analyze().

virtual int SubsystemNeutronWriter::chamberType ( int  globalDetId  )  const [pure virtual]

Implemented in CSCNeutronWriter.

Referenced by analyze().

void SubsystemNeutronWriter::initialize ( int  chamberType  ) 

good practice to do once for each chamber type

Definition at line 85 of file SubsystemNeutronWriter.cc.

References NeutronWriter::initialize(), and theHitWriter.

Referenced by CSCNeutronWriter::CSCNeutronWriter().

00086 {
00087   // should instantiate one of every chamber type, just so
00088   // ROOT knows what file to associate them with
00089   theHitWriter->initialize(chamberType);
00090 }

virtual int SubsystemNeutronWriter::localDetId ( int  globalDetId  )  const [pure virtual]

Implemented in CSCNeutronWriter.

Referenced by adjust().

void SubsystemNeutronWriter::printStats (  ) 

Definition at line 50 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType, and theNEvents.

Referenced by ~SubsystemNeutronWriter().

00050                                         {
00051   edm::LogInfo("SubsystemNeutronWriter") << "SubsystemNeutronWriter Statistics:\n";
00052   for(map<int,int>::iterator mapItr = theCountPerChamberType.begin();
00053       mapItr != theCountPerChamberType.end();  ++mapItr) {
00054      edm::LogInfo("SubsystemNeutronWriter") << "   theEventOccupancy[" << mapItr->first << "] = "
00055          << mapItr->second << " / " << theNEvents << " / NCT \n";
00056   }
00057 }

void SubsystemNeutronWriter::updateCount ( int  chamberType  )  [protected]

updates the counter

Definition at line 145 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType.

Referenced by writeHits().

00145                                                         {
00146   map<int,int>::iterator entry = theCountPerChamberType.find(chamberType);
00147   if(entry == theCountPerChamberType.end()) {
00148     theCountPerChamberType.insert( pair<int,int>(chamberType, 1) );
00149   } else {
00150     ++(entry->second);
00151   }
00152 }

void SubsystemNeutronWriter::writeHits ( int  chamberType,
edm::PSimHitContainer allSimHits 
) [protected, virtual]

Definition at line 93 of file SubsystemNeutronWriter.cc.

References adjust(), GenMuonPlsPt100GeV_cfg::cout, PSimHit::detUnitId(), lat::endl(), i, LogDebug, PSimHit::pabs(), PSimHit::particleType(), python::multivaluedict::sort(), theHitWriter, theNeutronTimeCut, theTimeWindow, PSimHit::tof(), updateCount(), and NeutronWriter::writeEvent().

Referenced by analyze().

00094 {
00095 
00096   sort(input.begin(), input.end(), SortByTime());
00097   edm::PSimHitContainer current;
00098   float startTime = -1000.;
00099   for(size_t i = 0; i < input.size(); ++i) {
00100     PSimHit hit = input[i];
00101 std::cout << hit << std::endl;
00102     float tof = hit.tof();
00103     LogDebug("SubsystemNeutronWriter") << "found hit from part type " << hit.particleType()
00104                    << " at tof " << tof << " p " << hit.pabs() 
00105                    << " on det " << hit.detUnitId() 
00106                    << " chamber type " << chamberType;
00107     if(tof > theNeutronTimeCut) {
00108       if(tof > (startTime + theTimeWindow) ) { // 1st in cluster
00109         startTime = tof;
00110         if(!current.empty()) {
00111           LogDebug("SubsystemNeutronWriter") << "filling old cluster";
00112           theHitWriter->writeEvent(chamberType, current);
00113           updateCount(chamberType);
00114           current.clear();
00115         }
00116         LogDebug("SubsystemNeutronWriter") << "starting neutron cluster at time " << startTime 
00117           << " on detType " << chamberType;
00118       }
00119       // set the time to be 0 at start of event
00120 std::cout << "ADJUST " << startTime << std::endl;
00121       adjust(hit, -1.*startTime);
00122       current.push_back( hit );
00123 std::cout << "NEXT HIT" << std::endl;
00124     }
00125   }
00126 std::cout << "LOOPED OVER HITS " << theHitWriter << std::endl;
00127   if(!current.empty()) {
00128     theHitWriter->writeEvent(chamberType, current);
00129     updateCount(chamberType);
00130   }
00131 }


Member Data Documentation

bool SubsystemNeutronWriter::initialized [private]

Definition at line 64 of file SubsystemNeutronWriter.h.

std::map<int, int> SubsystemNeutronWriter::theCountPerChamberType [private]

Definition at line 65 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and updateCount().

NeutronWriter* SubsystemNeutronWriter::theHitWriter [private]

Definition at line 59 of file SubsystemNeutronWriter.h.

Referenced by initialize(), SubsystemNeutronWriter(), writeHits(), and ~SubsystemNeutronWriter().

edm::InputTag SubsystemNeutronWriter::theInputTag [private]

Definition at line 60 of file SubsystemNeutronWriter.h.

Referenced by analyze().

double SubsystemNeutronWriter::theNeutronTimeCut [private]

Definition at line 61 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

int SubsystemNeutronWriter::theNEvents [private]

Definition at line 63 of file SubsystemNeutronWriter.h.

Referenced by analyze(), and printStats().

double SubsystemNeutronWriter::theTimeWindow [private]

Definition at line 62 of file SubsystemNeutronWriter.h.

Referenced by writeHits().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:32:56 2009 for CMSSW by  doxygen 1.5.4