/////////////////////////////////////////////////////////////////////////////// // File: L2STTClusterFactory.cpp // // Purpose: Class for tsim_l2stt package // Mehods: // getMCHaddr : gets channel address (modID) and content. // getHardwaddr : from the MCH modID gets the Crate#, SEQUENCER#, // HDI#,chip# and channel# on chip. // makeClusterfrom Hits : channel# and content are used as the // input for the STT Cluster Algorithm(s). // Created: 12-April-1999, Silvia Tentindo-Repond // 22-April-99 STR added vector Clusters // 23-April-99 STR added case of Cluster belonging to two chips // 21-May-99 STR renamed L2STTClusterFactory // 06-Aug-99 STR ChannelThreshold can now be set by rcp // 20-Sept-99 STR update to new UnpDataChunk v57 // 18-Nov-99 STR write out cable-format data // 24-Nov-99 STR add xyz to class Cluster // 4-Jan-00 STR use rcp's DEBUGcluster // 12-May-00 STR bug fix about cluster's first strip address // 21-May-00 STR use rcp prmtr 'AxialOnly' : when activated, // only the axial clusters are created /////////////////////////////////////////////////////////////////////////////// #include #include #include #include"l2stt_util/L2STTCluster.hpp" #include"tsim_l2stt/L2STTClusterFactory.hpp" // The includes for the UnpDataChunk readin and output. #include "edm/TKey.hpp" #include "edm/THandle.hpp" #include "unpack_evt/UnpDataChunk.hpp" #include "unpack_evt/UnpChunkSelector.hpp" #include "unpack_svx_fe/SMTModule.hpp" // SMT Address #include "smtutil/StripAddress.hpp" #include "smtutil/StripFEAddress.hpp" #include "smtutil/SmtAddressTranslation.hpp" #include "smtutil/SmtFEAddress.hpp" #include "rcp/RCP.hpp" #include "rcp/RCPManager.hpp" using std::vector; using std::list; using std::setw; //***************************************************************** //const string tsim_L2STT::version() //{ // return "$Id: L2STTClusterFactory.cpp,v 1.11 2000/05/22 05:59:12 silvia Exp $"; //} // This is the constructor static int eventcount = 0; static int debugcount = 0; //static int MAXCOUNT = 20; static int MAXCOUNT = 400; L2STTClusterFactory::L2STTClusterFactory() { } // End of Constructor... L2STTClusterFactory::~L2STTClusterFactory() { } // End of Constructor... // Methods int L2STTClusterFactory::makeClusterfromHits(SmtAddressTranslation& addrTranslation, edm::RCP& rcp, std::vector& chvec, std::list& Clusters, std::ofstream& output) { // method of L2STTClusterFactorys that makes a cluster from hits and // puts it in a vector 'Clusters' // init parameters for Cluster before loop over channels int ChipCount = 0; int HDICount = 0; int SeqCount = 0; // not used yet int ClusterCount = 0; int CrateCount = 0; // not used yet int ClusterSeed = 0; // not used yet int lastchip; int lastchan; int lastseq; int lasthdi; int lastcrate; // init stuff to make possible to save the correct hardware address //of a cluster int KeepStripAddress = 0; //init cluster address stuff int firstStripCrate =0; int firstStripSEQ = 0; int firstStripHDI = 0; int firstStripChip = 0; int firstStripChan = 0; int SEQ = 99999; int crate = 99999; int chan = 99999; int chip = 99999; int HDI = 99999; cout << " entering L2STTClusterFactory::makeClusterfromHits " << endl; // PRECONDITION /////////////// // The zero cluster size triggers a new cluster starting with the // first channel ///////////////////////////////////////////////////////////////// int ClusterSize = 0; int ClusterPh = 0; int Numerator = 0; float Centroid; // iterate over the list of Channel objects std::vector::const_iterator i; eventcount++; // Next get the values from the RCP File... int ChThreshold = rcp.getInt("ChannelThreshold"); int doDataStream = rcp.getInt("doDataStream"); int DEBUGCluster = rcp.getInt("DEBUGCluster"); int AxialOnly = rcp.getInt("AxialOnly"); if (DEBUGCluster == 1){ if ( debugcount <= MAXCOUNT ) { cout << "EVENT " << eventcount << endl; } } // LOOP OVER CHANNELS ///////////////////// int count = 0; // set cluster address flag so for 1st event and 1st cluster in input file KeepStripAddress = 1; for( i = chvec.begin(); i != chvec.end(); i++) { count++; // check the version number //int vers = (i)->version(); int vers = 1; //cout << "INSIDE FACTORY - version " << vers << endl; if( vers == 1 ) { // extract the MCHID and data for the channel //std::vector dvec = (i)->data(); int modid = (i->id()).moduleID(); int chid = (i->id()).channelID(); int chdata = (i)->count(); // Use only barrel strips ///////////////////////// StripFEAddress stripFEAddr = StripFEAddress(modid,chid); StripAddress stripAddr; bool ok = addrTranslation.translator(stripFEAddr,stripAddr); int detType = stripAddr.DetType(); if ( detType == 1 ) { // Use only Axial strips, if Axial Only is activated //////////////////////////////////////////////////// // int aView = stripAddr.View(); //if( (aView == 1) && (AxialOnly==1) ) //{ // dvec[0]=0 means mchid gives ChipID // beginning of Chip : save address // convert the MCH address to Hardware Address: // i.e. get crate,SEQ,HDI,chip and channel address // from MCH modid and chid address lastchip = chip; lastchan = chan; lastseq = SEQ; lasthdi = HDI; lastcrate= crate; stripFEAddr.unpackStripFEAddress(crate,SEQ,HDI,chip,chan); if(DEBUGCluster == 1) { if ( debugcount <= MAXCOUNT ) { cout << " crate,SEQ,HDI,chip,chan " << setw(10) << crate << setw(10) << SEQ << setw(10) << HDI << setw(10) << chip << setw(10) << chan << endl; } if ( KeepStripAddress == 1) { firstStripCrate = crate; firstStripSEQ = SEQ; firstStripHDI = HDI; firstStripChip = chip; firstStripChan = chan; KeepStripAddress = 0;// reset cluster address flag ! } } if ( SEQ != lastseq ) { SeqCount++; if ( SeqCount > 1 ) { if(doDataStream>0) output << "ENDSEQ " << 0xC0 << endl; if(doDataStream>0)output << "ENDSEQ " << 0xC0 << endl; } if(doDataStream>0) output << "SEQ " << SEQ << endl; } if ( HDI != lasthdi ) { HDICount++; if ( (HDICount > 1) && (SEQ == lastseq) ) { if(doDataStream>0)output << " ENDHDI " << 0xC0 << endl; } if(doDataStream>0)output << " HDI " << HDI << endl; } if ( chip != lastchip ) { ChipCount++; if(doDataStream>0)output << " CHIP " << chip + 128 << endl; if(doDataStream>0)output << " ZERO " << 0 << endl; } // begin loop over chips - useless because no cable fmt if ( chdata != 0 ) { // begin to read channels for a cluster // CHECK THRESHOLD ////////////////// // reject channels above threshold // reject noisy or dead channels // and save on output file DataStream if( (chdata > ChThreshold) && (chdata < 255) ) { //first save channel id and content into output file //REM - ALL hits are saved, even if only threshold or // noisy if(doDataStream>0)output << " CHAN " << chan <0)output << " VALU " << chdata << endl ; // CHECK FOR END OF CLUSTER /////////////////////////// // no neighbor strip // so save previous cluster AND do beginnibg of new cluster // if( ((chan != (lastchan+1)) || // Not next channel OR (chip != lastchip) || // New chip OR (count == chvec.size())) // End of Data && (ClusterSize > 0) ) // AND non-zero cluster size { ClusterCount++; // buffer Cluster prameters: Centroid etc // calc. Centroid by LUT (LookUpTables 1/4 strip) // calculate strip int Svxchan = Centroid; // truncate value //calculate offset int Offset = (int)( (Centroid - Svxchan) / 0.25); // create a cluster object // May-00 fix: need to save the first strip address for // cluster, not the last strip read address, since thi // doesn't belong to given cluster L2STTCluster x(ClusterCount, Offset, ClusterSize, ClusterPh, Svxchan, firstStripChip, firstStripHDI, firstStripSEQ, firstStripCrate); // enable flag KeepStripAddress // so the next reading of Strip address will be //saved as 'first' Strip Address for next Cluster KeepStripAddress = 1; // add to cluster container Clusters.push_back(x); // printout Cluster Parameters debugcount++; if(DEBUGCluster == 1) { if ( debugcount <= MAXCOUNT ) { cout << x << endl; } } // IMPORTANT: RESET Cluster quantities ////////////////////////////////////// ClusterSize = 0; Numerator = 0; ClusterPh = 0; ClusterSeed = chan ; } // endif not neighbohr strip // BUILD CLUSTER //////////////// // first strip in cluster // or neighbohr strip if(((chan == (lastchan + 1)) && (chip == lastchip)) || (ClusterSize == 0) ) { if(DEBUGCluster == 1) { if ( (debugcount <= MAXCOUNT) && (ClusterSize == 0) ) { cout << " NEW CLUSTER at channel " << chan << endl << endl; } } ClusterSize++; Numerator = Numerator + chan * chdata; ClusterPh = ClusterPh + chdata; Centroid = (float)Numerator / (float)ClusterPh; } ///////////////////////////////////////////////////////// } // endif chdata < 255 and chdata > ChThreshold } // endloop over chips - useless because no cable format // Printout channel info //////////////////////// if(DEBUGCluster == 1) { if ( debugcount <= MAXCOUNT ) { cout << setw(8) << count << setw(10) << " chip " << setw(4) << chip << setw(10) << " chan " << setw(4) << chan << setw(10) << " chdata " << setw(4) << chdata << endl; } } } // Only barrel strips // } // only Axial strips IF AxialOnly is activated } // if (VERS=1) }// for chvec loop if(doDataStream>0)output << "ENDHDI " << 0xC0 << endl; if(doDataStream>0)output << "ENDSEQ " << 0xC0 << endl; return 0; }// end makeClusterfromHits