CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimCalorimetry/EcalTestBeamAlgos/src/EcalTBReadout.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 
00003 #include "SimCalorimetry/EcalTestBeamAlgos/interface/EcalTBReadout.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include "SimDataFormats/EcalTestBeam/interface/PEcalTBInfo.h"
00007 
00008 EcalTBReadout::EcalTBReadout(const std::string theEcalTBInfoLabel) : 
00009    ecalTBInfoLabel_(theEcalTBInfoLabel)
00010 {
00011    theTargetCrystal_ = -1 ;
00012    theTTlist_.reserve(1) ;
00013 }
00014 
00015 void 
00016 EcalTBReadout::findTTlist( const int& crysId, 
00017                            const EcalTrigTowerConstituentsMap& etmap ) 
00018 {
00019 
00020   // search for the TT involved in the NCRYMATRIX x NCRYMATRIX
00021   // around the target crystal if a new target, otherwise use
00022   // the list already filled
00023 
00024    if ( crysId == theTargetCrystal_ ) { return; }
00025 
00026    theTTlist_.clear();
00027 
00031   
00032    EBDetId theTargetId;
00033    std::vector<DetId>::const_iterator idItr = theDetIds->begin();
00034    unsigned int ncount = 0;
00035    bool found = false;
00036   
00037    while  ( (ncount < theDetIds->size()) && !found ) 
00038    {
00039       EBDetId thisEBdetid(idItr->rawId());
00040       if (thisEBdetid.ic() == crysId) {
00041          theTargetId = thisEBdetid;
00042          found = true;
00043       }
00044       ++idItr;
00045       ++ncount;
00046    }
00047    if ( !found ) {
00048       throw cms::Exception("ObjectNotFound", "Ecal TB target crystal not found in geometry");
00049       return;
00050    }
00051    theTargetCrystal_ = theTargetId.ic();
00052 
00055 
00056    int myEta = theTargetId.ieta();
00057    int myPhi = theTargetId.iphi();
00058 
00059 
00060    for ( int icrysEta = (myEta-(NCRYMATRIX-1)/2) ; icrysEta <= (myEta+(NCRYMATRIX-1)/2) ; ++icrysEta ) {
00061       for ( int icrysPhi = (myPhi-(NCRYMATRIX-1)/2) ; icrysPhi <= (myPhi+(NCRYMATRIX-1)/2) ; ++icrysPhi ) {
00062       
00064 
00065          EBDetId thisEBdetid;
00066 
00067          idItr = theDetIds->begin();
00068          ncount = 0;
00069          found = false;
00070   
00071          while  ( (ncount < theDetIds->size()) && !found ) 
00072          {
00073             EBDetId myEBdetid(idItr->rawId());
00074             if ( (myEBdetid.ieta() == icrysEta) && (myEBdetid.iphi() == icrysPhi) ) {
00075                thisEBdetid = myEBdetid;
00076                found = true;
00077             }
00078             ++idItr;
00079             ++ncount;
00080          }
00081 
00082          if ( found ) {
00083             
00084             EcalTrigTowerDetId thisTTdetId=etmap.towerOf(thisEBdetid);
00085             
00086             LogDebug("EcalDigi") << "Crystal to be readout: sequential id = " << thisEBdetid.ic() << " eta = " << icrysEta << " phi = " << icrysPhi << " from TT = " << thisTTdetId;
00087             
00088             if ( theTTlist_.size() == 0 || ( theTTlist_.size() == 1 && theTTlist_[0] != thisTTdetId )) {
00089                theTTlist_.push_back(thisTTdetId);
00090             }
00091             else {
00092                std::vector<EcalTrigTowerDetId>::iterator ttFound = find(theTTlist_.begin(), theTTlist_.end(), thisTTdetId);
00093                if ( theTTlist_.size() > 1 && ttFound == theTTlist_.end() && *(theTTlist_.end()) != thisTTdetId ) { 
00094                   theTTlist_.push_back(thisTTdetId);
00095                }
00096             }
00097          }
00098       }
00099    }
00100    
00101    edm::LogInfo("EcalDigi") << " TT to be read: ";
00102    for ( unsigned int i = 0 ; i < theTTlist_.size() ; ++i ) {
00103       edm::LogInfo("EcalDigi") << " TT " << i << " " << theTTlist_[i];
00104    }
00105 }
00106 
00107 void 
00108 EcalTBReadout::readOut( const  EBDigiCollection&            input  ,
00109                         EBDigiCollection&                   output ,
00110                         const EcalTrigTowerConstituentsMap& etmap    ) 
00111 {
00112   /*
00113   for(EBDigiCollection::const_iterator digiItr = input.begin();
00114       digiItr != input.end(); ++digiItr)
00115     {
00116       EcalTrigTowerDetId thisTTdetId=etmap.towerOf(digiItr->id());
00117       std::vector<EcalTrigTowerDetId>::iterator ttFound = find(theTTlist_.begin(), theTTlist_.end(), thisTTdetId);
00118       if ((ttFound != theTTlist_.end()) || *(theTTlist_.end()) == thisTTdetId) { 
00119         output.push_back(*digiItr);
00120       }
00121     }
00122   edm::LogInfo("EcalDigi") << "Read EB Digis: " << output.size();
00123   */
00124 
00125    std::cout<<"%%%%%%% In readOut(), size="<< input.size() <<std::endl ;
00126 
00127    for( unsigned int digis=0; digis<input.size(); ++digis )
00128    {
00129       EBDataFrame ebdf = input[digis];
00130     
00131       EcalTrigTowerDetId thisTTdetId=etmap.towerOf(ebdf.id());
00132       std::vector<EcalTrigTowerDetId>::iterator ttFound = find(theTTlist_.begin(), theTTlist_.end(), thisTTdetId);
00133 
00134       if ((ttFound != theTTlist_.end()) || *(theTTlist_.end()) == thisTTdetId) {      
00135          output.push_back( ebdf.id() ) ;
00136          EBDataFrame ebdf2( output.back() );
00137          std::copy( ebdf.frame().begin(),
00138                     ebdf.frame().end(),
00139                     ebdf2.frame().begin() );
00140       }
00141    }
00142 }
00143 
00144 void 
00145 EcalTBReadout::readOut( const EEDigiCollection&             input  , 
00146                         EEDigiCollection&                   output , 
00147                         const EcalTrigTowerConstituentsMap& etmap    ) 
00148 {
00149    for (unsigned int digis=0; digis<input.size(); ++digis)
00150    { 
00151       EEDataFrame eedf ( input[digis] ) ;
00152 
00153       EcalTrigTowerDetId thisTTdetId ( etmap.towerOf( eedf.id() ) ) ;
00154 
00155       std::vector<EcalTrigTowerDetId>::iterator ttFound 
00156          ( find(theTTlist_.begin(), theTTlist_.end(), thisTTdetId ) ) ;
00157 
00158       if( ( ttFound != theTTlist_.end() ) ||
00159           *(theTTlist_.end()) == thisTTdetId ) 
00160       {      
00161          output.push_back( eedf.id() ) ;
00162          EEDataFrame eedf2( output.back() ) ;
00163          std::copy( eedf.frame().begin(), 
00164                     eedf.frame().end(),
00165                     eedf2.frame().begin() );
00166       }
00167    }
00168 }
00169 
00170 void
00171 EcalTBReadout::performReadout( edm::Event&                         event    , 
00172                                const EcalTrigTowerConstituentsMap& theTTmap , 
00173                                const EBDigiCollection&             input    , 
00174                                EBDigiCollection&                   output     ) 
00175 {
00176    // TB readout
00177    // step 1: get the target crystal index
00178 
00179    edm::Handle<PEcalTBInfo> theEcalTBInfo;
00180    event.getByLabel(ecalTBInfoLabel_,theEcalTBInfo);
00181 
00182    int crysId = theEcalTBInfo->nCrystal();
00183   
00184    // step 2: update (if needed) the TT list to be read
00185 
00186    findTTlist(crysId, theTTmap);
00187 
00188    // step 3: perform the readout
00189 
00190    readOut( input, output, theTTmap ) ;
00191 }
00192 
00193 void 
00194 EcalTBReadout::performReadout( edm::Event&                         event    , 
00195                                const EcalTrigTowerConstituentsMap& theTTmap , 
00196                                const EEDigiCollection&             input    , 
00197                                EEDigiCollection&                   output      ) 
00198 {
00199 
00200    // TB readout
00201    // step 1: get the target crystal index
00202 
00203    edm::Handle<PEcalTBInfo> theEcalTBInfo;
00204    event.getByLabel(ecalTBInfoLabel_,theEcalTBInfo);
00205 
00206    int crysId = theEcalTBInfo->nCrystal();
00207   
00208    // step 2: update (if needed) the TT list to be read
00209 
00210    findTTlist(crysId, theTTmap);
00211 
00212    // step 3: perform the readout
00213 
00214    readOut( input, output, theTTmap) ;
00215 }