コード例 #1
0
ファイル: fitter.cpp プロジェクト: sonia3994/SaRoMaN
//*************************************************************
bool fitter::CreateSingleTrajectory(Trajectory& traj) {
  //*************************************************************
 
  _m.message("+++ CreateSingleTrajectory function ++++",bhep::VERBOSE);
  
  
  //--------- add measurements to trajectory --------//
     
  ///create the trajectory  
  std::vector<cluster*>::iterator it1;
  for (it1 = _meas.begin();it1 != _meas.end();it1++){
    RecObject* ro = new RecObject();
    ro = dynamic_cast<RecObject*>(*it1);
    Node temp;
    temp.set_measurement(*ro);
    traj.add_node(temp);
    // measurement( *(*it1) );
  }
  
  _m.message("Trajectory created:",traj,bhep::VVERBOSE);

  return true;
}
コード例 #2
0
ファイル: fitter.cpp プロジェクト: sonia3994/SaRoMaN
//*************************************************************
void fitter::rec_had_edep(int j){
  //*************************************************************
  double hadEdep = 0;
  EVector hadCentroid = EVector(3,0);
  std::vector<cluster*> hadHits;
  // create a new trajectory based on the hadron hits alone.
  Trajectory* hadTraj = new Trajectory();
  double minZ=999999.9, maxZ=-99999.9;
  
  _nonMuonEdep.push_back(0.0);
  _nonMuonHits.push_back(0);
  _showerDir.push_back(EVector(3,0));
  _showerVertZ.push_back(0.0);
  _showerNplanes.push_back(0);
  _showerXtent.push_back(0.0);

  if((int)_trajs.size() != 0 && j != (int)_trajs.size()) {

    //sort the trajectories
    sort( _trajs.begin(), _trajs.end(), sortTrajByLength());

    //loop over trajectories
    EVector hadCentroid = EVector(3,0);
    for(int i=0; i<(int)_trajs.size(); i++){
      
      hadHits = _hadmeas;
      // cout<<i<<" _muonindex[i] ="<< _muonindex[i]<<endl; 
      // if(i == _muonindex[i]) continue;
      if(i == j) continue;
      
      Trajectory& traj = *_trajs[i];
      
      std::vector<Node*> hits = traj.nodes();
      
      //Add total non-muon hits
      _nonMuonHits[j] += hits.size();
      
      for ( int iHit=0; iHit < (int)hits.size(); iHit++){
	EVector hpos = EVector(3,0);
	hpos[0] = hits[iHit]->measurement().position()[0];
	hpos[1] = hits[iHit]->measurement().position()[1];
	hpos[2] = hits[iHit]->measurement().position()[2] ;
	
	if(hpos[2] < minZ) minZ = hpos[2];
	if(hpos[2] > maxZ) maxZ = hpos[2];
	hadEdep += get_classifier().correctEdep((hits[iHit]->measurement().hv("energy").vector()[0])*MeV,hpos[0],hpos[1],hpos[2]);
	
	//sum of position to calculate centroid
	hadCentroid[0] += hpos[0];
	hadCentroid[1] += hpos[1];
	hadCentroid[2] += hpos[2];
	
      }
      _m.message("i=",i," hits =",hits.size(),"  _nonMuonHits=",_nonMuonHits[j]," hadEdep = ",hadEdep," hadHits=",hadHits.size(),bhep::VERBOSE);
    }
  }
  else
    hadHits = _meas;
 
  // total edep for non-muon hits
  _nonMuonEdep[j] += hadEdep ;
  _nonMuonHits[j] += hadHits.size();
  _m.message(" hadHits=",hadHits.size(),bhep::VERBOSE); 
      
  if(hadHits.size() !=0){
    for(int ih=0;ih<(int)hadHits.size();ih++){
      RecObject* ro = dynamic_cast<RecObject*>(hadHits[ih]);
      hadTraj->add_node(Node(*ro));
      EVector hadPos = EVector(3,0);
      hadPos[0] = hadHits[ih]->position()[0];
      hadPos[1] = hadHits[ih]->position()[1];
      hadPos[2] = hadHits[ih]->position()[2];
      
      if(hadPos[2] < minZ) minZ = hadPos[2];
      if(hadPos[2] > maxZ) maxZ = hadPos[2];
      //edep
      _nonMuonEdep[j] += get_classifier().correctEdep((hadHits[ih]->get_eng())*MeV,hadPos[0],hadPos[1],hadPos[2]) ;
      
      //sum of position to calculate centroid
      hadCentroid[0] += hadPos[0];
      hadCentroid[1] += hadPos[1];
      hadCentroid[2] += hadPos[2];
    }
  }
  // else hadCentroid = EVector(3,0);
  
  //calculate the centroid
  if (_nonMuonHits[j]) hadCentroid /= _nonMuonHits[j];
  else hadCentroid = EVector(3,0);
  
  _m.message(" hadEdep= ",hadEdep,"  nonMuonEdep= ",_nonMuonEdep[j],"  nonMuonHits= ",_nonMuonHits[j],bhep::VERBOSE);
  
  //direction w.r.t reconstructed vertex
  double dxdz=0, dydz=0, dz = 0, norm = 0;
  EVector vertex = EVector(3,0);
  
  // reconstructed vertex
  if(_trajs.size() != 0 
     && _trajs[0]->quality("fitcheck") > 0 && _trajs[0]->quality("fitted")) 
    // Use the first node of the longest trajectory.
    vertex = _trajs[0]->state(_trajs[0]->first_fitted_node()).vector();
  else
    // Use the first node in the event.
    vertex = _meas[0]->vector(); 
  
  
  _m.message("vertex   =",vertex[0],"   ",vertex[1],"  ",vertex[2], bhep::VERBOSE);
  _m.message("centroid =",hadCentroid[0],"   ",hadCentroid[1],"  ",hadCentroid[2],bhep::VERBOSE);
  
  //direction
  dz   = (hadCentroid[2] -vertex[2]);
  dxdz = (hadCentroid[0] -vertex[0])/dz;
  dydz = (hadCentroid[1] -vertex[1])/dz;
  
  //unit direction
  norm = sqrt(1 + pow(dxdz,2) + pow(dydz,2));
  
    
  if(norm != 0) {
    _showerDir[j][0] = dxdz/norm; 
    _showerDir[j][1] = dydz/norm;
    _showerDir[j][2] = 1./norm;
  }
  else _showerDir[j] = EVector(3,0);
  
  _showerVertZ[j]   = minZ;
  _showerNplanes[j] = int((maxZ - minZ)/(_geom.getPieceWidth()));
  _showerXtent[j]   = maxZ - minZ;

  // Can only add the hadron trajectory once
  /*
  if(0){
    hadTraj->set_quality("failType",10);
    hadTraj->set_quality("intType",10);
    hadTraj->set_quality("nplanes,"int((maxZ - minZ)/(_geom.getPieceWidth())));
    hadTraj->set_quality("freeplanes",0);
    hadTraj->set_quality("reseed",0);
    hadTraj->set_quality("xtent",maxZ - minZ);
    hadTraj->set_quality("initialqP", 0.0);
    hadTraj->set_quality("fitted", 0);
    hadTraj->set_quality("vertZ", minZ);
    hadTraj->set_quality("fitcheck", 0);
    
    trajs.push_back(hadTraj);
  }
  */
  _m.message("Rec hadron Unit direction components:", _showerDir[j][0], _showerDir[j][1], _showerDir[j][2],bhep::VERBOSE);
  
}