CMS 3D CMS Logo

EcalPnGraphs.cc

Go to the documentation of this file.
00001 
00012 #include <FWCore/Framework/interface/EDAnalyzer.h>
00013 #include <FWCore/Framework/interface/Event.h>
00014 #include <FWCore/Framework/interface/MakerMacros.h>
00015 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
00016 #include <DataFormats/EcalDetId/interface/EcalDetIdCollections.h>
00017 
00018 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h>
00019 #include <DataFormats/EcalDigi/interface/EcalTriggerPrimitiveSample.h>
00020 
00021 #include "CaloOnlineTools/EcalTools/plugins/EcalPnGraphs.h"
00022 #include "CaloOnlineTools/EcalTools/interface/EcalFedMap.h"
00023 
00024 #include <iostream>
00025 #include <vector>
00026 #include <map>
00027 
00028 #include "TFile.h"
00029 #include "TGraph.h"
00030 
00031 
00032 //=============================================================================
00033 EcalPnGraphs::EcalPnGraphs(const edm::ParameterSet& ps){  
00034 //=============================================================================
00035 
00036   digiProducer_     = ps.getParameter<std::string>("digiProducer");
00037   fileName = ps.getUntrackedParameter<std::string >("fileName", std::string("toto") );
00038 
00039   first_Pn = 0;
00040 
00041   listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", std::vector<int>());
00042   numPn   = ps.getUntrackedParameter< int >("numPn");
00043 
00044   std::vector<int> listDefaults;
00045   listDefaults.push_back(-1);
00046   feds_ = ps.getUntrackedParameter<std::vector<int> > ("requestedFeds",listDefaults);
00047   bool fedIsGiven = false;
00048 
00049   std::vector<std::string> ebDefaults;
00050   ebDefaults.push_back("none");
00051   ebs_  = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs",ebDefaults);
00052   bool ebIsGiven  = false;  
00053 
00054   //FEDs and EBs
00055   if ( feds_[0] != -1 ) {
00056     edm::LogInfo("EcalPnGraphs") << "FED id is given! Goining to beginJob! ";
00057     fedIsGiven = true;
00058   }else {
00059     feds_.clear();
00060     if ( ebs_[0] !="none" ) {
00061       ebIsGiven = true;
00062       //EB id is given and convert to FED id
00063       fedMap = new EcalFedMap(); 
00064       for (std::vector<std::string>::const_iterator ebItr = ebs_.begin(); 
00065            ebItr!= ebs_.end();  ++ebItr) {
00066         feds_.push_back(fedMap->getFedFromSlice(*ebItr));
00067       }
00068       delete fedMap;
00069     } else {
00070       //Select all FEDs in the Event
00071       for ( int i=601; i<655; ++i){
00072         feds_.push_back(i);
00073       }
00074     }
00075   }
00076   
00077   // consistency checks checks
00078   inputIsOk       = true;
00079   //check with FEDs
00080   if ( fedIsGiven ) {
00081     std::vector<int>::iterator fedIter;
00082     for (fedIter = feds_.begin(); fedIter!=feds_.end(); ++fedIter) {
00083       if ( (*fedIter) < 601 || (*fedIter) > 654) {                      
00084         std::cout << "[EcalPnGraphs] pn number : " << (*fedIter) << " found in listFeds. "
00085                   << " Valid range is [601-654]. Returning." << std::endl;
00086         inputIsOk = false;
00087         return;
00088       }
00089     }
00090   }
00091 
00092   //Check with Pns
00093   if ( listPns[0] != -1 ) { 
00094     std::vector<int>::iterator intIter;
00095     for (intIter = listPns.begin(); intIter != listPns.end(); intIter++)  {  
00096       if ( ((*intIter) < 1) ||  (10 < (*intIter)) )       {  
00097         std::cout << "[EcalPnGraphs] pn number : " << (*intIter) << " found in listPns. "
00098                   << " Valid range is 1-10. Returning." << std::endl;
00099         inputIsOk = false;
00100         return;
00101       }
00102       if (!first_Pn )   first_Pn = (*intIter);  
00103     }
00104   } else {
00105     listPns.clear();
00106     listPns.push_back(5); 
00107     listPns.push_back(6); 
00108   }
00109   
00110   // setting the abcissa array once for all
00111   for (int i=0; i<50; i++)        abscissa[i] = i;
00112   
00113   // local event counter (in general different from LV1)
00114   eventCounter =0;
00115 }
00116 
00117 
00118 //=============================================================================
00119 EcalPnGraphs::~EcalPnGraphs(){  
00120 //=============================================================================
00121   //delete *;
00122 }
00123 
00124 //=============================================================================
00125 void EcalPnGraphs::beginJob(const edm::EventSetup& c) {
00126 //=============================================================================
00127   edm::LogInfo("EcalPhGraphs") << "entering beginJob! " ;
00128 }
00129 
00130 //=============================================================================
00131 void EcalPnGraphs::analyze( const edm::Event & e, const  edm::EventSetup& c){
00132 //=============================================================================
00133 
00134   eventCounter++;
00135   if (!inputIsOk) return;
00136 
00137   bool pnDigisFound = true;
00138   // retrieving crystal PN diodes from Event
00139   edm::Handle<EcalPnDiodeDigiCollection>  pn_digis;
00140   try {
00141     e.getByLabel(digiProducer_, pn_digis);
00142     pnDigisFound = true;
00143   } catch (cms::Exception& ex) {
00144     edm::LogError("EcalPnGraphs") << "PNs were not found!";
00145   }
00146 
00147   // getting the list of all the Pns which will be dumped on TGraph
00148   // - listPns is the list as given by the user
00149   // -numPn is the number of Pns (centered at Pn from listPns) for which graphs are required
00150   std::vector<int>::iterator pn_it;
00151   for ( pn_it = listPns.begin();  pn_it != listPns.end() ; pn_it++  )
00152     {
00153       int ipn    = (*pn_it);
00154       int hpn = numPn;
00155       
00156       for (int u = (-hpn) ; u<=hpn; u++){         
00157           int ipn_c = ipn + u;
00158           if (ipn_c < 1 || ipn_c > 10) continue;
00159           std::vector<int>::iterator notInList = find(listAllPns.begin(), listAllPns.end(), ipn_c);
00160           if ( notInList == listAllPns.end() ) {
00161             listAllPns.push_back ( ipn_c );
00162           }
00163       }
00164     }
00165   
00166   //Loop over PN digis
00167   for ( EcalPnDiodeDigiCollection::const_iterator pnItr = pn_digis->begin(); pnItr != pn_digis->end(); ++pnItr )  {
00168     //Get PNid of a digi
00169     int ipn = (*pnItr).id().iPnId();
00170     //Get DCC id where the digi is from
00171     int ieb    = EcalPnDiodeDetId((*pnItr).id()).iDCCId();
00172     
00173     //Make sure that these are PnDigis from the requested FEDid
00174     int FEDid = ieb + 600;
00175 
00176     std::vector<int>::iterator fedIter = find(feds_.begin(), feds_.end(), FEDid);
00177 
00178     if ( fedIter == feds_.end() ) {
00179       edm::LogWarning("EcalPnGraphs")<< "For Event " << eventCounter << " PnDigis are not found from requested SM!. returning...";
00180       return;
00181     }
00182     // selecting desired Pns only
00183     std::vector<int>::iterator iPnIter;
00184     iPnIter     = find( listAllPns.begin() , listAllPns.end() , ipn);
00185     if (iPnIter == listAllPns.end()) continue; 
00186     
00187     for ( int i=0; i< (*pnItr).size() && i<50; ++i ) {
00188       ordinate[i] = (*pnItr).sample(i).adc();
00189     }
00190     //make grapn of ph digis
00191     TGraph oneGraph(50, abscissa,ordinate);
00192     std::string title;
00193     title = "Graph_ev" + intToString( eventCounter )
00194           + "_FED" + intToString( FEDid )
00195           + "_ipn" + intToString( ipn );
00196     oneGraph.SetTitle(title.c_str());
00197     oneGraph.SetName(title.c_str());
00198     graphs.push_back(oneGraph);
00199     
00200   }// loop over Pn digis
00201 }
00202 
00203 std::string EcalPnGraphs::intToString(int num)
00204 {
00205   //
00206   // outputs the number into the string stream and then flushes
00207   // the buffer (makes sure the output is put into the stream)
00208   //
00209   std::ostringstream myStream; //creates an ostringstream object
00210   myStream << num << std::flush;
00211   
00212   return(myStream.str()); //returns the string form of the stringstream object
00213 } 
00214 
00215 //=============================================================================
00216 void EcalPnGraphs::endJob() {
00217 //=============================================================================
00218   fileName +=  ( std::string("_Pn")    + intToString(first_Pn) ); 
00219   fileName += ".graph.root";
00220 
00221   root_file = new TFile( fileName.c_str() , "RECREATE" );
00222   std::vector<TGraph>::iterator gr_it;
00223   for ( gr_it = graphs.begin(); gr_it !=  graphs.end(); gr_it++ )      (*gr_it).Write();
00224   root_file->Close();
00225 
00226   edm::LogInfo("EcalPnGraphs") << "DONE!.... " ;
00227 }
00228 

Generated on Tue Jun 9 17:25:53 2009 for CMSSW by  doxygen 1.5.4