Ejemplo n.º 1
0
void CaloEvaluator::printOutputInfo(PHCompositeNode *topNode) {
  
  if (verbosity > 2) cout << "CaloEvaluator::printOutputInfo() entered" << endl;

  CaloRawClusterEval* clustereval = _caloevalstack->get_rawcluster_eval();
  CaloTruthEval*        trutheval = _caloevalstack->get_truth_eval();
  
  //==========================================
  // print out some useful stuff for debugging
  //==========================================

  if (verbosity > 1) {
    
    // event information
    cout << endl;
    cout << PHWHERE << "   NEW OUTPUT FOR EVENT " << _ievent << endl;
    cout << endl;

    // need things off of the DST...
    PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo");
    if (!truthinfo) {
      cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl;
      exit(-1);
    }

    // need things off of the DST...
    SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap");
      
    PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx( truthinfo->GetPrimaryVertexIndex() );
    float gvx = gvertex->get_x();
    float gvy = gvertex->get_y();
    float gvz = gvertex->get_z();

    float vx = NAN;
    float vy = NAN;
    float vz = NAN;
    if (vertexmap) {
      if (!vertexmap->empty()) {
	SvtxVertex* vertex = (vertexmap->begin()->second);
	
	vx = vertex->get_x();
	vy = vertex->get_y();
	vz = vertex->get_z();
      }
    }

    cout << "vtrue = (" << gvx << "," << gvy << "," << gvz << ") => vreco = (" << vx << "," << vy << "," << vz << ")" << endl;

    PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange();
    for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
	 iter != range.second; 
	 ++iter) {
      PHG4Particle* primary = iter->second;
      
      cout << endl;
      
      cout << "===Primary PHG4Particle=========================================" << endl;
      cout << " particle id = " << primary->get_track_id() << endl;
      cout << " flavor = " << primary->get_pid() << endl;
      cout << " (px,py,pz,e) = (";

      float gpx = primary->get_px();
      float gpy = primary->get_py();
      float gpz = primary->get_pz();
      float ge = primary->get_e();
	
      cout.width(5); cout << gpx;
      cout << ",";
      cout.width(5); cout << gpy;
      cout << ",";
      cout.width(5); cout << gpz;
      cout << ",";
      cout.width(5); cout << ge;
      cout << ")" << endl;

      float gpt = sqrt(gpx*gpx+gpy*gpy);
      float geta = NAN;
      if (gpt != 0.0) geta = asinh(gpz/gpt);
      float gphi = atan2(gpy,gpx);
      
      cout << "(eta,phi,e,pt) = (";
      cout.width(5); cout << geta;
      cout << ",";
      cout.width(5); cout << gphi;
      cout << ",";
      cout.width(5); cout << ge;
      cout << ",";
      cout.width(5); cout << gpt;
      cout << ")" << endl;

      PHG4VtxPoint* vtx = trutheval->get_vertex(primary);	
      float gvx      = vtx->get_x();
      float gvy      = vtx->get_y();
      float gvz      = vtx->get_z();
      
      cout << " vtrue = (";
      cout.width(5); cout << gvx;
      cout << ",";
      cout.width(5); cout << gvy;
      cout << ",";
      cout.width(5); cout << gvz;
      cout << ")" << endl;

      cout << " embed = " << trutheval->get_embed(primary) << endl;
      cout << " edep = " << trutheval->get_shower_energy_deposit(primary) << endl;
      cout << " mrad = " << trutheval->get_shower_moliere_radius(primary) << endl;

      std::set<RawCluster*> clusters = clustereval->all_clusters_from(primary);
      for (std::set<RawCluster*>::iterator clusiter = clusters.begin();
	   clusiter != clusters.end();
	   ++clusiter) {
	RawCluster* cluster = (*clusiter);
	   
	float ntowers   = cluster->getNTowers();
	float eta       = cluster->get_eta();
	float phi       = cluster->get_phi();
	float e         = cluster->get_energy();
	
	float efromtruth     = clustereval->get_energy_contribution(cluster, primary);
	
	cout << " => #" << cluster->get_id() << " (eta,phi,e) = (";
	cout.width(5); cout << eta;
	cout << ",";
	cout.width(5); cout << phi;
	cout << ",";
	cout.width(5); cout << e;
	cout << "), ntowers = "<< ntowers <<", efromtruth = " << efromtruth << endl;
      }
    }
    cout << endl;
  }

  return;
}
Ejemplo n.º 2
0
void CaloEvaluator::fillOutputNtuples(PHCompositeNode *topNode) {
  
  if (verbosity > 2) cout << "CaloEvaluator::fillOutputNtuples() entered" << endl;

  CaloRawClusterEval* clustereval = _caloevalstack->get_rawcluster_eval();
  CaloRawTowerEval*     towereval = _caloevalstack->get_rawtower_eval();
  CaloTruthEval*        trutheval = _caloevalstack->get_truth_eval();
  
  //----------------------
  // fill the Event NTuple
  //----------------------

  if (_do_gpoint_eval) {
    // need things off of the DST...
    PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo");
    if (!truthinfo) {
      cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl;
      exit(-1);
    }

    // need things off of the DST...
    SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap");

    PHG4VtxPoint *gvertex = truthinfo->GetPrimaryVtx( truthinfo->GetPrimaryVertexIndex() );
    float gvx = gvertex->get_x();
    float gvy = gvertex->get_y();
    float gvz = gvertex->get_z();

    float vx = NAN;
    float vy = NAN;
    float vz = NAN;
    if (vertexmap) {
      if (!vertexmap->empty()) {
	SvtxVertex* vertex = (vertexmap->begin()->second);
	
	vx = vertex->get_x();
	vy = vertex->get_y();
	vz = vertex->get_z();
      }
    }
	
    float gpoint_data[7] = {_ievent,
			    gvx,
			    gvy,
			    gvz,
			    vx,
			    vy,
			    vz
    };

    _ntp_gpoint->Fill(gpoint_data);   
  }
  
  //------------------------
  // fill the Gshower NTuple
  //------------------------
  
  if (_ntp_gshower) {

    if (verbosity > 1) cout << "CaloEvaluator::filling gshower ntuple..." << endl;
    
    PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo");   
    if (!truthinfo) {
      cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl;
      exit(-1);
    }

    PHG4TruthInfoContainer::ConstRange range = truthinfo->GetPrimaryParticleRange();
    for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
	 iter != range.second; 
	 ++iter) {
    
      PHG4Particle* primary = iter->second;

      if (primary->get_e() < _truth_e_threshold) continue;
      
      if (!_truth_trace_embed_flags.empty()) {
	if (_truth_trace_embed_flags.find(trutheval->get_embed(primary)) ==
	    _truth_trace_embed_flags.end()) continue;
      }
      
      float gparticleID = primary->get_track_id();
      float gflavor     = primary->get_pid();
      
      std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary);     
      float gnhits   = g4hits.size();	
      float gpx      = primary->get_px();
      float gpy      = primary->get_py();
      float gpz      = primary->get_pz();
      float ge       = primary->get_e();

      float gpt = sqrt(gpx*gpx+gpy*gpy);
      float geta = NAN;
      if (gpt != 0.0) geta = asinh(gpz/gpt);
      float gphi = atan2(gpy,gpx);
      
      PHG4VtxPoint* vtx = trutheval->get_vertex(primary);	
      float gvx      = vtx->get_x();
      float gvy      = vtx->get_y();
      float gvz      = vtx->get_z();
      
      float gembed   = trutheval->get_embed(primary);
      float gedep    = trutheval->get_shower_energy_deposit(primary);
      float gmrad    = trutheval->get_shower_moliere_radius(primary);

      RawCluster* cluster = clustereval->best_cluster_from(primary);

      float clusterID = NAN;
      float ntowers   = NAN;
      float eta       = NAN;
      float phi       = NAN;
      float e         = NAN;
      
      float efromtruth     = NAN;

      if (cluster) {      
	clusterID = cluster->get_id();
	ntowers   = cluster->getNTowers();
	eta       = cluster->get_eta();
	phi       = cluster->get_phi();
	e         = cluster->get_energy();
	
	efromtruth     = clustereval->get_energy_contribution(cluster, primary);
      }
      
      float shower_data[20] = {_ievent,
			       gparticleID,
			       gflavor,
			       gnhits,
			       geta,
			       gphi,
			       ge,
			       gpt,
			       gvx,
			       gvy,
			       gvz,
			       gembed,
			       gedep,
			       gmrad,
			       clusterID,
			       ntowers,
			       eta,
			       phi,
			       e,
			       efromtruth
      };

      _ntp_gshower->Fill(shower_data);
    }
  }

  //----------------------
  // fill the Tower NTuple
  //----------------------
 
  if (_do_tower_eval) {

    if (verbosity > 1) cout << "CaloEvaluator::filling tower ntuple..." << endl;
    
    string towernode = "TOWER_CALIB_" + _caloname;
    RawTowerContainer* towers = findNode::getClass<RawTowerContainer>(topNode,towernode.c_str());
    if (!towers) {
      cerr << PHWHERE << " ERROR: Can't find " << towernode << endl;
      exit(-1);
    }
    
    string towergeomnode = "TOWERGEOM_" + _caloname;
    RawTowerGeomContainer* towergeom = findNode::getClass<RawTowerGeomContainer>(topNode,towergeomnode.c_str());
    if (!towergeom) {
      cerr << PHWHERE << " ERROR: Can't find " << towergeomnode << endl;
      exit(-1);
    }
  
    RawTowerContainer::ConstRange begin_end = towers->getTowers();
    RawTowerContainer::ConstIterator rtiter;
    for (rtiter = begin_end.first; rtiter !=  begin_end.second; ++rtiter) {
      RawTower *tower = rtiter->second;

      if (tower->get_energy() < _reco_e_threshold) continue;
      
      float towerid = tower->get_id();
      float ieta    = tower->get_bineta();
      float iphi    = tower->get_binphi();
      float eta     = towergeom->get_etacenter(tower->get_bineta());
      float phi     = towergeom->get_phicenter(tower->get_binphi());
      float e       = tower->get_energy();

      PHG4Particle* primary = towereval->max_truth_primary_by_energy(tower);

      float gparticleID = NAN;
      float gflavor     = NAN;
      float gnhits   = NAN;
      float gpx      = NAN;
      float gpy      = NAN;
      float gpz      = NAN;
      float ge       = NAN;

      float gpt = NAN;
      float geta = NAN;
      float gphi = NAN;

      float gvx      = NAN;
      float gvy      = NAN;
      float gvz      = NAN;

      float gembed   = NAN;
      float gedep    = NAN;
      float gmrad    = NAN;

      float efromtruth = NAN;

      if (primary) {

	gparticleID = primary->get_track_id();
	gflavor = primary->get_pid();

	std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary);
	gnhits = g4hits.size();
	gpx = primary->get_px();
	gpy = primary->get_py();
	gpz = primary->get_pz();
	ge = primary->get_e();

	gpt = sqrt(gpx * gpx + gpy * gpy);
	if (gpt != 0.0) geta = asinh(gpz / gpt);
	gphi = atan2(gpy, gpx);

	PHG4VtxPoint* vtx = trutheval->get_vertex(primary);

	if (vtx) {
	  gvx = vtx->get_x();
	  gvy = vtx->get_y();
	  gvz = vtx->get_z();
	}

	gembed = trutheval->get_embed(primary);
	gedep = trutheval->get_shower_energy_deposit(primary);
	gmrad = trutheval->get_shower_moliere_radius(primary);

	efromtruth = towereval->get_energy_contribution(tower, primary);
      }

      float tower_data[21] = {_ievent,
			      towerid,
			      ieta,
			      iphi,
			      eta,
			      phi,
			      e,
			      gparticleID,
			      gflavor,
			      gnhits,
			      geta,
			      gphi,
			      ge,
			      gpt,
			      gvx,
			      gvy,
			      gvz,
			      gembed,
			      gedep,
			      gmrad,
			      efromtruth
      };
      
      _ntp_tower->Fill(tower_data);
    }
  }

  //------------------------
  // fill the Cluster NTuple
  //------------------------

  if (_do_cluster_eval) {
    if (verbosity > 1) cout << "CaloEvaluator::filling gcluster ntuple..." << endl;

    string clusternode = "CLUSTER_" + _caloname;
    RawClusterContainer* clusters = findNode::getClass<RawClusterContainer>(topNode,clusternode.c_str());
    if (!clusters) {
      cerr << PHWHERE << " ERROR: Can't find " << clusternode << endl;
      exit(-1);
    }
  
    // for every cluster
    for (unsigned int icluster = 0; icluster < clusters->size(); icluster++) {
      RawCluster *cluster = clusters->getCluster(icluster);

      if (cluster->get_energy() < _reco_e_threshold) continue;
      
      float clusterID = cluster->get_id();
      float ntowers   = cluster->getNTowers();
      float eta       = cluster->get_eta();
      float phi       = cluster->get_phi();
      float e         = cluster->get_energy();
      
      PHG4Particle* primary = clustereval->max_truth_primary_by_energy(cluster);

      float gparticleID = NAN;
      float gflavor     = NAN;

      float gnhits   = NAN;
      float gpx      = NAN;
      float gpy      = NAN;
      float gpz      = NAN;
      float ge       = NAN;

      float gpt = NAN;
      float geta = NAN;
      float gphi = NAN;
      
      float gvx      = NAN;
      float gvy      = NAN;
      float gvz      = NAN;
      
      float gembed   = NAN;
      float gedep    = NAN;
      float gmrad    = NAN;

      float efromtruth = NAN;

      if (primary) {
	gparticleID = primary->get_track_id();
	gflavor = primary->get_pid();
	
	std::set<PHG4Hit*> g4hits = trutheval->get_shower_from_primary(primary);
	gnhits = g4hits.size();
	gpx = primary->get_px();
	gpy = primary->get_py();
	gpz = primary->get_pz();
	ge = primary->get_e();

	gpt = sqrt(gpx * gpx + gpy * gpy);
	if (gpt != 0.0) geta = asinh(gpz / gpt);
	gphi = atan2(gpy, gpx);

	PHG4VtxPoint* vtx = trutheval->get_vertex(primary);

	if (vtx) {
	  gvx = vtx->get_x();
	  gvy = vtx->get_y();
	  gvz = vtx->get_z();
	}
	
	gembed = trutheval->get_embed(primary);
	gedep = trutheval->get_shower_energy_deposit(primary);
	gmrad = trutheval->get_shower_moliere_radius(primary);

	efromtruth = clustereval->get_energy_contribution(cluster,
							  primary);
      }
      
      float cluster_data[20] = {_ievent,
				clusterID,
				ntowers,
				eta,
				phi,
				e,
				gparticleID,
				gflavor,
				gnhits,
				geta,
				gphi,
				ge,
				gpt,
				gvx,
				gvy,
				gvz,
				gembed,
				gedep,
				gmrad,
				efromtruth
      };

      _ntp_cluster->Fill(cluster_data);
    }
  }

  return;
}
int
QAG4SimulationCalorimeter::process_event_Cluster(PHCompositeNode *topNode)
{

  if (verbosity > 2)
    cout << "QAG4SimulationCalorimeter::process_event_Cluster() entered"
        << endl;

  Fun4AllHistoManager *hm = QAHistManagerDef::getHistoManager();
  assert(hm);
  string towergeomnodename = "TOWERGEOM_" + _calo_name;
  RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(
      topNode, towergeomnodename.c_str());
  if (!towergeom)
    {
      cout << PHWHERE << ": Could not find node " << towergeomnodename.c_str()
          << endl;
      return Fun4AllReturnCodes::ABORTRUN;
    }

  //get a cluster count
  TH1D* h_norm = dynamic_cast<TH1D*>(hm->getHisto(
      get_histo_prefix() + "_Normalization"));
  assert(h_norm);

  std::string nodename = "CLUSTER_" + _calo_name;
  RawClusterContainer* clusters = findNode::getClass<RawClusterContainer>(
      topNode, nodename.c_str());
  assert(clusters);
  h_norm->Fill("Cluster", clusters->size());

  // get primary
  assert(_truth_container);
  assert(not _truth_container->GetMap().empty());
  PHG4Particle * last_primary = _truth_container->GetMap().rbegin()->second;
  assert(last_primary);

  if (verbosity > 2)
    {
      cout
          << "QAG4SimulationCalorimeter::process_event_Cluster() handle this truth particle"
          << endl;
      last_primary->identify();
    }

  assert(_caloevalstack);
  CaloRawClusterEval* clustereval = _caloevalstack->get_rawcluster_eval();
  assert(clustereval);

  TH1F* h = dynamic_cast<TH1F*>(hm->getHisto(
      get_histo_prefix() + "_Cluster_BestMatchERatio"));
  assert(h);

  RawCluster* cluster = clustereval->best_cluster_from(last_primary);
  if (cluster)
    {
      // has a cluster matched and best cluster selected

      if (verbosity > 3)
        cout << "QAG4SimulationCalorimeter::process_event_Cluster::"
            << _calo_name << " - get cluster with energy "
            << cluster->get_energy() << " VS primary energy "
            << last_primary->get_e() << endl;

      h->Fill(cluster->get_energy() / (last_primary->get_e() + 1e-9)); //avoids divide zero

      // now work on the projection:
      const CLHEP::Hep3Vector hit(cluster->get_position());

      const PHG4VtxPoint* primary_vtx = //
          _truth_container->GetPrimaryVtx(last_primary->get_vtx_id());
      assert(primary_vtx);
      if (verbosity > 2)
        {
          cout
              << "QAG4SimulationCalorimeter::process_event_Cluster() handle this vertex"
              << endl;
          primary_vtx->identify();
        }

      const CLHEP::Hep3Vector  vertex(primary_vtx->get_x(), primary_vtx->get_y(),
          primary_vtx->get_z());

      // projection axis
      CLHEP::Hep3Vector axis_proj(last_primary->get_px(), last_primary->get_py(),
          last_primary->get_pz());
      if (axis_proj.mag() == 0)
        axis_proj.set(0, 0, 1);
      axis_proj = axis_proj.unit();

      // azimuthal direction axis
      CLHEP::Hep3Vector axis_azimuth = axis_proj.cross(CLHEP::Hep3Vector(0, 0, 1));
      if (axis_azimuth.mag() == 0)
        axis_azimuth.set(1, 0, 0);
      axis_azimuth = axis_azimuth.unit();

      // polar direction axis
      CLHEP::Hep3Vector axis_polar = axis_proj.cross(axis_azimuth);
      assert(axis_polar.mag() > 0);
      axis_polar = axis_polar.unit();

      TH2F * hlat = dynamic_cast<TH2F*>(hm->getHisto(
          get_histo_prefix() + "_Cluster_LateralTruthProjection"));
      assert(hlat);

      const double hit_azimuth = axis_azimuth.dot(hit - vertex);
      const double hit_polar = axis_polar.dot(hit - vertex);
      hlat->Fill(hit_polar, hit_azimuth);

    }
  else
    {
      if (verbosity > 3)
        cout << "QAG4SimulationCalorimeter::process_event_Cluster::"
            << _calo_name << " - missing cluster !";
      h->Fill(0); // no cluster matched
    }

  return Fun4AllReturnCodes::EVENT_OK;
}