CMS 3D CMS Logo

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