CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

DoCastorAnalysis Class Reference

#include <DoCastorAnalysis.h>

Inheritance diagram for DoCastorAnalysis:
SimWatcher Observer< const BeginOfJob * > Observer< const BeginOfRun * > Observer< const EndOfRun * > Observer< const BeginOfEvent * > Observer< const EndOfEvent * > Observer< const G4Step * >

List of all members.

Public Member Functions

 DoCastorAnalysis (const edm::ParameterSet &p)
virtual ~DoCastorAnalysis ()

Private Member Functions

void update (const BeginOfJob *run)
 This routine will be called when the appropriate signal arrives.
void update (const G4Step *step)
 This routine will be called when the appropriate signal arrives.
void update (const EndOfEvent *evt)
 This routine will be called when the appropriate signal arrives.
void update (const BeginOfEvent *evt)
 This routine will be called when the appropriate signal arrives.
void update (const EndOfRun *run)
 This routine will be called when the appropriate signal arrives.
void update (const BeginOfRun *run)
 This routine will be called when the appropriate signal arrives.

Private Attributes

TFile * CastorOutputEventFile
TTree * CastorTree
int eventIndex
std::vector< double > * psimhit_energy
std::vector< double > * psimhit_eta
std::vector< int > * psimhit_module
std::vector< double > * psimhit_phi
std::vector< int > * psimhit_sector
std::vector< double > * psimhit_x
std::vector< double > * psimhit_y
std::vector< double > * psimhit_z
std::vector< double > simhit_energy
std::vector< double > simhit_eta
double simhit_etot
std::vector< int > simhit_module
std::vector< double > simhit_phi
std::vector< int > simhit_sector
std::vector< double > simhit_x
std::vector< double > simhit_y
std::vector< double > simhit_z
std::string TreeFileName
int verbosity

Detailed Description

Definition at line 62 of file DoCastorAnalysis.h.


Constructor & Destructor Documentation

DoCastorAnalysis::DoCastorAnalysis ( const edm::ParameterSet p)

Definition at line 28 of file DoCastorAnalysis.cc.

References CastorOutputEventFile, CastorTree, gather_cfg::cout, debug, edm::ParameterSet::getParameter(), psimhit_energy, psimhit_eta, psimhit_module, psimhit_phi, psimhit_sector, psimhit_x, psimhit_y, psimhit_z, simhit_etot, AlCaHLTBitMon_QueryRunRegistry::string, TreeFileName, and verbosity.

                                                           {

  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("DoCastorAnalysis");
  verbosity    = m_Anal.getParameter<int>("Verbosity");

  TreeFileName = m_Anal.getParameter<std::string>("CastorTreeFileName");

  if (verbosity > 0) {

    std::cout<<std::endl;
    std::cout<<"============================================================================"<<std::endl;
    std::cout << "DoCastorAnalysis:: Initialized as observer"<< std::endl;
    
    std::cout <<" Castor Tree will be created"<< std::endl;
    std::cout <<" Castor Tree will be in file: "<<TreeFileName<<std::endl;
    if(debug) getchar();
  
    std::cout<<"============================================================================"<<std::endl;
    std::cout<<std::endl;
  }

  std::cout << "DoCastorAnalysis: output event root file created"<< std::endl;
  TString treefilename = TreeFileName;
  CastorOutputEventFile = new TFile(treefilename,"RECREATE");

  CastorTree = new TTree("Sim","Sim");

  CastorTree->Branch("simhit_x","std::vector<double>",&psimhit_x);
  CastorTree->Branch("simhit_y","std::vector<double>",&psimhit_y);
  CastorTree->Branch("simhit_z","std::vector<double>",&psimhit_z);

  CastorTree->Branch("simhit_eta","std::vector<double>",&psimhit_eta);
  CastorTree->Branch("simhit_phi","std::vector<double>",&psimhit_phi);
  CastorTree->Branch("simhit_energy","std::vector<double>",&psimhit_energy);

  // CastorTree->Branch("simhit_time","std::vector<double>",&psimhit_time);
  CastorTree->Branch("simhit_sector","std::vector<int>",&psimhit_sector);
  CastorTree->Branch("simhit_module","std::vector<int>",&psimhit_module);

  CastorTree->Branch("simhit_etot",&simhit_etot,"simhit_etot/D");
}
DoCastorAnalysis::~DoCastorAnalysis ( ) [virtual]

Definition at line 70 of file DoCastorAnalysis.cc.

References CastorOutputEventFile, CastorTree, gather_cfg::cout, debug, and verbosity.

                                    {

  //destructor of DoCastorAnalysis
    
  CastorOutputEventFile->cd();
  //-- CastorOutputEventFile->Write();
  CastorTree->Write("",TObject::kOverwrite);
  std::cout << "DoCastorAnalysis: Ntuple event written" << std::endl;
  if(debug) getchar();
  CastorOutputEventFile->Close();
  std::cout << "DoCastorAnalysis: Event file closed" << std::endl;
  if(debug) getchar();

  if (verbosity > 0) {
    std::cout<<std::endl<<"DoCastorAnalysis: end of process"<<std::endl; 
    if(debug) getchar();
  }

}

Member Function Documentation

void DoCastorAnalysis::update ( const BeginOfJob ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfJob * >.

Definition at line 92 of file DoCastorAnalysis.cc.

References gather_cfg::cout.

                                                    {

  std::cout << " Starting new job " << std::endl;
}
void DoCastorAnalysis::update ( const G4Step *  ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 221 of file DoCastorAnalysis.cc.

{;}
void DoCastorAnalysis::update ( const EndOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfEvent * >.

Definition at line 118 of file DoCastorAnalysis.cc.

References CastorTree, gather_cfg::cout, debug, relval_parameters_module::energy, eta, CaloG4Hit::getEnergyDeposit(), CaloG4Hit::getPosition(), CaloG4Hit::getUnitID(), funct::log(), phi, pos, psimhit_energy, psimhit_eta, psimhit_module, psimhit_phi, psimhit_sector, psimhit_x, psimhit_y, psimhit_z, simhit_energy, simhit_eta, simhit_etot, simhit_module, simhit_phi, simhit_sector, simhit_x, simhit_y, simhit_z, funct::tan(), theta(), and CastorNumberingScheme::unpackIndex().

                                                    {

  // Look for the Hit Collection 

  // access to the G4 hit collections 
  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
 
  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI");    
  CaloG4HitCollection* theCAFI = (CaloG4HitCollection*) allHC->GetHC(CAFIid);

  CastorNumberingScheme *theCastorNumScheme = new CastorNumberingScheme();

  unsigned int volumeID=0;
  // std::map<int,float,std::less<int> > themap;
  
  int nentries = theCAFI->entries();
  if(debug) std::cout<<"nentries in CAFI: "<<nentries<<std::endl;
  if(debug) getchar();

  psimhit_x=&simhit_x;
  psimhit_x->clear();
  psimhit_x->reserve(nentries);

  psimhit_y=&simhit_y;
  psimhit_y->clear();
  psimhit_y->reserve(nentries);

  psimhit_z=&simhit_z;
  psimhit_z->clear();
  psimhit_z->reserve(nentries);

  psimhit_eta=&simhit_eta;
  psimhit_eta->clear();
  psimhit_eta->reserve(nentries);
  
  psimhit_phi=&simhit_phi;
  psimhit_phi->clear();
  psimhit_phi->reserve(nentries);
  
  psimhit_energy=&simhit_energy;
  psimhit_energy->clear();
  psimhit_energy->reserve(nentries);
  
  //psimhit_time=&simhit_time;
  //psimhit_time->clear();
  //psimhit_time->reserve(nentries);
  
  psimhit_sector=&simhit_sector;
  psimhit_sector->clear();
  psimhit_sector->reserve(nentries);

  psimhit_module=&simhit_module;
  psimhit_module->clear();
  psimhit_module->reserve(nentries);

  simhit_etot = 0;

  if (nentries > 0) {

    for (int ihit = 0; ihit < nentries; ihit++) {
      CaloG4Hit* aHit = (*theCAFI)[ihit];
      volumeID = aHit->getUnitID();

      //themap[volumeID] += aHit->getEnergyDeposit();
      int zside,sector,zmodule;

      theCastorNumScheme->unpackIndex(volumeID,zside,sector,zmodule);

      double energy   = aHit->getEnergyDeposit()/GeV;
      //double time     = aHit->getTimeSlice();
      
      math::XYZPoint pos  = aHit->getPosition();
      double theta    = pos.theta();
      double   eta    = -log(tan(theta/2.));
      double   phi    = pos.phi();
      
      psimhit_x->push_back(pos.x());
      psimhit_y->push_back(pos.y());
      psimhit_z->push_back(pos.z());
      
      psimhit_eta->push_back(eta);
      psimhit_phi->push_back(phi);
      psimhit_energy->push_back(energy);

      // psimhit_time->push_back(time);
      psimhit_sector->push_back(sector);
      psimhit_module->push_back(zmodule);

      simhit_etot+=energy;
       
      if(debug) std::cout<<"hit "<<ihit+1<<" : x = "<<(*psimhit_x)[ihit]<<" , eta =  "<<(*psimhit_eta)[ihit]
                    <<" , phi = "<<(*psimhit_phi)[ihit]<<" , energy = "<<(*psimhit_energy)[ihit]<<std::endl;
    }

    //if(debug) std::cout<<" total energy = "<<simhit_etot<<std::endl;
    if(debug) getchar();
    CastorTree->Fill();
        
  } // nentries > 0
}
void DoCastorAnalysis::update ( const BeginOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 110 of file DoCastorAnalysis.cc.

References gather_cfg::cout, and eventIndex.

                                                      {
  std::cout << "DoCastorAnalysis: Processing Event Number: "<<eventIndex<< std::endl;
  eventIndex++;
}
void DoCastorAnalysis::update ( const EndOfRun ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfRun * >.

Definition at line 219 of file DoCastorAnalysis.cc.

{;}
void DoCastorAnalysis::update ( const BeginOfRun ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 99 of file DoCastorAnalysis.cc.

References gather_cfg::cout, and eventIndex.

                                                    {

  std::cout << std::endl << "DoCastorAnalysis: Starting Run"<< std::endl; 

  // std::cout << "DoCastorAnalysis: output event root file created"<< std::endl;
  // TString treefilename = TreeFileName;
  // CastorOutputEventFile = new TFile(treefilename,"RECREATE");
  
  eventIndex = 1;
}

Member Data Documentation

Definition at line 89 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and ~DoCastorAnalysis().

TTree* DoCastorAnalysis::CastorTree [private]

Definition at line 90 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), update(), and ~DoCastorAnalysis().

Definition at line 92 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> * DoCastorAnalysis::psimhit_energy [private]

Definition at line 100 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double>* DoCastorAnalysis::psimhit_eta [private]

Definition at line 100 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<int> * DoCastorAnalysis::psimhit_module [private]

Definition at line 101 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double> * DoCastorAnalysis::psimhit_phi [private]

Definition at line 100 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<int>* DoCastorAnalysis::psimhit_sector [private]

Definition at line 101 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double>* DoCastorAnalysis::psimhit_x [private]

Definition at line 99 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double> * DoCastorAnalysis::psimhit_y [private]

Definition at line 99 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double> * DoCastorAnalysis::psimhit_z [private]

Definition at line 99 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<double> DoCastorAnalysis::simhit_energy [private]

Definition at line 95 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> DoCastorAnalysis::simhit_eta [private]

Definition at line 95 of file DoCastorAnalysis.h.

Referenced by update().

Definition at line 104 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and update().

std::vector<int> DoCastorAnalysis::simhit_module [private]

Definition at line 96 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> DoCastorAnalysis::simhit_phi [private]

Definition at line 95 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<int> DoCastorAnalysis::simhit_sector [private]

Definition at line 96 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> DoCastorAnalysis::simhit_x [private]

Definition at line 94 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> DoCastorAnalysis::simhit_y [private]

Definition at line 94 of file DoCastorAnalysis.h.

Referenced by update().

std::vector<double> DoCastorAnalysis::simhit_z [private]

Definition at line 94 of file DoCastorAnalysis.h.

Referenced by update().

std::string DoCastorAnalysis::TreeFileName [private]

Definition at line 87 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis().

Definition at line 85 of file DoCastorAnalysis.h.

Referenced by DoCastorAnalysis(), and ~DoCastorAnalysis().