//--------------------------------------------------------- // File and Version Information : // Implementation of the CprClusterMaker class // // Description: // Implements function to get wire positions and // calculate the cluster position given a collection // of hit wires in the CPR. // // Environment: // Software developed for the CDF Detector. // // Author List: // 04/30/2000 Tania Moulik : created // Revision History : // 02/02/2001 T.Moulik, R. Culbertson : Adding error on cluster position. // //---------------------------------------------------------- //------------- // C Headers -- //------------- #include //------------------- // This class header //------------------- #include "Calor/CprClusterMaker.hh" #include "ErrorLogger_i/gERRLOG.hh" //---------------- // Constructors -- //---------------- #include CprClusterMaker::CprClusterMaker():_seedwire(-100) { } //---------------- // Destructors -- //---------------- CprClusterMaker::~CprClusterMaker(){ } ////////////////////////////////////////////////////////////// // // Perform wire clustering based on track // ////////////////////////////////////////////////////////////// void CprClusterMaker::initCprClusterMaker() { _seedwire = -100; } CprCluster CprClusterMaker::do_cluster_wires(const vector * MyWires, CprClustPar* clustPar, const CdfTrack_clnk &theTrack) { // Initial Check if (MyWires->size()==0) { ERRLOG(ELwarning,"CprClusterMaker: ") << " No input wires for clustering " << endmsg; return CprCluster(); } // // // Initialization // // _valid = 0; _wirePosition=0.; _wireEnergy=0.; _copyWires.clear(); // Cluster parameters int numberofwires = clustPar->numberMaxWires(); int minnumberofwires = clustPar->numberMinWires(); double seedThrs = clustPar->seedThrs(); double wireThrs = clustPar->wireThrs(); double clustThrs = clustPar->clustThrs(); bool printCluster = clustPar->printCluster(); // Get info from wireCollection vector::const_iterator iter_beg = MyWires->begin(); vector::const_iterator iter_end = MyWires->end(); vector::const_iterator iter_seed= MyWires->begin() + (MyWires->size()-1)/2; // Get SeedWire if (_seedwire!=-100) { for (vector ::const_iterator it_wires = iter_beg; it_wires != iter_end; it_wires++){ if (it_wires->getWireNo() == _seedwire ) iter_seed = it_wires; } } if (getenv("CPR_DEBUG")) { cout << "Number of wires in collection:" << iter_end - iter_beg << endl; cout << "Start Wire : " << iter_beg->getWireNo() << " End Wire : " << (iter_end-1)->getWireNo() << " Seed Wire : " << iter_seed->getWireNo() << endl; } int n = int((numberofwires -1)/2) ; vector::const_iterator iter_min; vector::const_iterator iter_max; if ((iter_end-iter_beg)>=n) { iter_min = max(iter_beg,iter_seed-n); iter_max = min(iter_end,iter_seed+n+1); } else { iter_min=iter_beg; iter_max=iter_end; } _barrel = iter_seed->getSide(); _module = iter_seed->getModule(); // No. of wires included int numWires = iter_max - iter_min; if (getenv("CPR_DEBUG")) { cout << "Min wire : " << (iter_min)->getWireNo() << " Max wire : " << (iter_max-1)->getWireNo() << endl; cout << "CprClusterMaker : Number of wires for Cluster :" << numWires << endl; } if (numWires < minnumberofwires) { if (getenv("CPR_DEBUG")) { cout << "--------------------------------------------------------------------" << endl; cout << "CprClusterMaker : Too few wires in this cluster" << endl; cout << "# of wires " << numWires << endl; cout << "--------------------------------------------------------------------" << endl; } return CprCluster(); } // Maximum energy found CprClusterMaker clust; float emax = 0.0; float wirepos2=0.0; int Side=0; int numWiresUsed = 0; for (vector ::const_iterator it_wires = iter_min; it_wires != iter_max; it_wires++){ int wireNo = it_wires->getWireNo(); Side = it_wires->getSide(); double energy = it_wires->getPulseHeight(); float wireLength = wireNo; if (energy > wireThrs) { _copyWires.push_back(*it_wires); _wireEnergy = _wireEnergy + energy; _wirePosition = energy * clust.get_wire_position(wireLength, Side)+ _wirePosition ; wirepos2+=_wirePosition*_wirePosition; numWiresUsed++; if (energy > emax) emax = energy; } } if (emax < seedThrs){ if (getenv("CPR_DEBUG")) { cout << "--------------------------------------------------------------------" << endl; cout << "CprClusterMaker : MAX energy Less than cluster seed threshold" << endl; cout << "Most Energetic wire : " << emax << endl; cout << "--------------------------------------------------------------------" << endl; } return CprCluster(); } if (_wireEnergy < clustThrs){ if (getenv("CPR_DEBUG")) { cout << "--------------------------------------------------------------------" << endl; cout << "CprClusterMaker : Not enough energy in Cluster " << endl; cout << "Total Cluster Energy : " << _wireEnergy << " Energy Cut :" << clustThrs << endl; cout << "--------------------------------------------------------------------" << endl; } return CprCluster(); } // Calculate cluster position _wirePosition = _wirePosition / _wireEnergy; // Calculate error on wirePosition _errorWirePosition = 0.0; if (numWiresUsed>1) { float wtdev=0.0; for (vector ::const_iterator it_wires = iter_min; it_wires < iter_max; it_wires++){ int wireNo = it_wires->getWireNo(); Side = it_wires->getSide(); double energy = it_wires->getPulseHeight(); if (energy > wireThrs) { float dev = ( get_wire_position(wireNo, Side) - _wirePosition); wtdev = wtdev + energy*dev*dev; } } _errorWirePosition = sqrt(wtdev/_wireEnergy); } _valid = 1; CprCluster myWireCluster(_barrel,_module,_wirePosition, _errorWirePosition,_wireEnergy,theTrack,_copyWires); if (printCluster) { cout << "Printing CPR Cluster : " << endl; myWireCluster.print(); } return(myWireCluster); } float CprClusterMaker::get_wire_position(float wireLengths, unsigned int Side) const{ float value=0.0; if (wireLengths > 15 ) { wireLengths = 31-wireLengths; } value = -CPR_WIRE_OFFSET +(2*wireLengths+1.0)/2.0*CPR_WIRE_PITCH; if (Side == 0) { value = -value; } return value; } void CprClusterMaker::setSeedWire(int seed) { _seedwire = seed; } int CprClusterMaker::is_valid() { return _valid; }