CMS 3D CMS Logo

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