CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CaloOnlineTools/EcalTools/plugins/EcalDisplaysByEvent.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:   EcalDisplaysByEvent 
00004 // Class:     EcalDisplaysByEvent 
00005 // 
00013 //
00014 // Original Author:  Seth COOPER
00015 //         Created:  Th Aug 28 5:46:22 CEST 2007
00016 // $Id: EcalDisplaysByEvent.cc,v 1.5 2010/10/20 10:01:59 elmer Exp $
00017 //
00018 //
00019 
00020 #include "CaloOnlineTools/EcalTools/plugins/EcalDisplaysByEvent.h"
00021 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
00022 #include "TLatex.h"
00023 #include "TLine.h"
00024 #include "TProfile2D.h"
00025 #include <utility> 
00026 #include <string> 
00027 #include <vector> 
00028 using namespace edm;
00029 using namespace std;
00030 
00031 //
00032 // constants, enums and typedefs
00033 //
00034 
00035 //
00036 // static data member definitions
00037 //
00038 float EcalDisplaysByEvent::gainRatio[3] = { 1., 2. , 12. }; 
00039 edm::Service<TFileService> EcalDisplaysByEvent::fileService;
00040 
00041 //
00042 // constructors and destructor
00043 //
00044 EcalDisplaysByEvent::EcalDisplaysByEvent(const edm::ParameterSet& iConfig) :
00045   EBRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EcalRecHitCollectionEB")),
00046   EERecHitCollection_ (iConfig.getParameter<edm::InputTag>("EcalRecHitCollectionEE")),
00047   EBDigis_ (iConfig.getParameter<edm::InputTag>("EBDigiCollection")),
00048   EEDigis_ (iConfig.getParameter<edm::InputTag>("EEDigiCollection")),
00049   headerProducer_ (iConfig.getParameter<edm::InputTag> ("headerProducer")),
00050   runNum_(-1),
00051   side_ (iConfig.getUntrackedParameter<int>("side", 3)),
00052   threshold_ (iConfig.getUntrackedParameter<double>("amplitudeThreshold", 0.5)),
00053   minTimingAmp_ (iConfig.getUntrackedParameter<double>("minimumTimingAmplitude", 0.100)),
00054   makeDigiGraphs_ (iConfig.getUntrackedParameter<bool>("makeDigiGraphs", false)),
00055   makeTimingHistos_ (iConfig.getUntrackedParameter<bool>("makeTimingHistos", true)),
00056   makeEnergyHistos_ (iConfig.getUntrackedParameter<bool>("makeEnergyHistos", true)),
00057   makeOccupancyHistos_ (iConfig.getUntrackedParameter<bool>("makeOccupancyHistos", true)),
00058   histRangeMin_ (iConfig.getUntrackedParameter<double>("histogramMinRange",0.0)),
00059   histRangeMax_ (iConfig.getUntrackedParameter<double>("histogramMaxRange",1.8)),
00060   minTimingEnergyEB_ (iConfig.getUntrackedParameter<double>("minTimingEnergyEB",0.0)),
00061   minTimingEnergyEE_ (iConfig.getUntrackedParameter<double>("minTimingEnergyEE",0.0))
00062 {
00063   vector<int> listDefaults;
00064   listDefaults.push_back(-1);
00065   
00066   maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
00067   maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
00068   seedCrys_ = iConfig.getUntrackedParameter<vector<int> >("seedCrys",listDefaults);
00069 
00070   vector<string> defaultMaskedEBs;
00071   defaultMaskedEBs.push_back("none");
00072   maskedEBs_ =  iConfig.getUntrackedParameter<vector<string> >("maskedEBs",defaultMaskedEBs);
00073   
00074   fedMap_ = new EcalFedMap();
00075 
00076   string title1 = "Jitter for all FEDs all events";
00077   string name1 = "JitterAllFEDsAllEvents";
00078   allFedsTimingHist_ = fileService->make<TH1F>(name1.c_str(),title1.c_str(),150,-7,7);
00079 
00080   // load up the maskedFED list with the proper FEDids
00081   if(maskedFEDs_[0]==-1)
00082   {
00083     //if "actual" EB id given, then convert to FEDid and put in listFEDs_
00084     if(maskedEBs_[0] != "none")
00085     {
00086       maskedFEDs_.clear();
00087       for(vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr)
00088       {
00089         maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
00090       }
00091     }
00092   }
00093   
00094   for (int i=0; i<10; i++)        
00095     abscissa[i] = i;
00096   
00097   naiveEvtNum_ = 0;
00098 
00099   initAllEventHistos();
00100 }
00101 
00102 
00103 EcalDisplaysByEvent::~EcalDisplaysByEvent()
00104 {
00105 }
00106 
00107 
00108 //
00109 // member functions
00110 //
00111 
00112 // ------------ method called once each job just before starting event loop  ------------
00113 void 
00114 EcalDisplaysByEvent::beginRun(edm::Run const &, edm::EventSetup const & c)
00115 {
00116   edm::ESHandle< EcalElectronicsMapping > handle;
00117   c.get< EcalMappingRcd >().get(handle);
00118   ecalElectronicsMap_ = handle.product();
00119 }
00120 
00121 // ------------ method called to for each event  ------------
00122 void
00123 EcalDisplaysByEvent::analyze(edm::Event const & iEvent, edm::EventSetup const & iSetup)
00124 {
00125 
00126   // get the headers
00127   // (one header for each supermodule)
00128   edm::Handle<EcalRawDataCollection> DCCHeaders;
00129   iEvent.getByLabel(headerProducer_, DCCHeaders);
00130 
00131   for (EcalRawDataCollection::const_iterator headerItr= DCCHeaders->begin();
00132                   headerItr != DCCHeaders->end (); 
00133                   ++headerItr) 
00134   {
00135     FEDsAndDCCHeaders_[headerItr->id()+600] = *headerItr;
00136   }
00137 
00138   int ievt = iEvent.id().event();
00139   naiveEvtNum_++;
00140 
00141   if(runNum_==-1)
00142   {
00143     runNum_ = iEvent.id().run();
00144     canvasNames_ = fileService->make<TTree>("canvasNames","Names of written canvases");
00145     names = new std::vector<string>();
00146     canvasNames_->Branch("names","vector<string>",&names);
00147     
00148     histoCanvasNames_ = fileService->make<TTree>("histoCanvasNames","Names of written canvases with histos");
00149     histoCanvasNamesVector = new std::vector<string>();
00150     histoCanvasNames_->Branch("histoCanvasNamesVector","vector<string>",&histoCanvasNamesVector);
00151   }
00152 
00153   //We only want the 3x3's for this event...
00154   listEBChannels.clear();
00155   listEEChannels.clear();
00156 
00157   //Get hits, digis, caloTopology from event/eventSetup
00158   Handle<EcalRecHitCollection> EBhits;
00159   Handle<EcalRecHitCollection> EEhits;
00160   ESHandle<CaloTopology> caloTopo;
00161   iSetup.get<CaloTopologyRecord>().get(caloTopo);
00162   iEvent.getByLabel(EBRecHitCollection_, EBhits);
00163   iEvent.getByLabel(EERecHitCollection_, EEhits);
00164   iEvent.getByLabel(EBDigis_, EBdigisHandle);
00165   iEvent.getByLabel(EEDigis_, EEdigisHandle);
00166 
00167   // Initialize histos for this event
00168   initEvtByEvtHists(naiveEvtNum_, ievt);
00169   
00170   bool hasEBdigis = false;
00171   bool hasEEdigis = false;
00172   if(EBdigisHandle->size() > 0)
00173     hasEBdigis = true;
00174   if(EEdigisHandle->size() > 0)
00175     hasEEdigis = true;
00176 
00177   // Produce the digi graphs
00178   if(makeDigiGraphs_)
00179   {
00180     if(hasEBdigis) //if event has digis, it should have hits
00181       selectHits(EBhits, ievt, caloTopo);
00182     if(hasEEdigis)
00183       selectHits(EEhits, ievt, caloTopo);
00184   }
00185 
00186   // Produce the histos
00187   if(hasEBdigis)
00188   {
00189     makeHistos(EBdigisHandle);
00190     makeHistos(EBhits);
00191   }
00192   if(hasEEdigis)
00193   {
00194     makeHistos(EEdigisHandle);
00195     makeHistos(EEhits);
00196   }
00197 
00198   if(hasEBdigis || hasEEdigis)
00199     drawHistos();
00200 
00201   deleteEvtByEvtHists();
00202 }
00203 
00204 
00205 void EcalDisplaysByEvent::selectHits(Handle<EcalRecHitCollection> hits,
00206     int ievt, ESHandle<CaloTopology> caloTopo)
00207 {
00208   for (EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr)
00209   {
00210     EcalRecHit hit = (*hitItr);
00211     DetId det = hit.id();
00212     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(det);
00213     int FEDid = 600+elecId.dccId();
00214     bool isBarrel = true;
00215     if(FEDid < 610 || FEDid > 645)
00216       isBarrel = false;
00217     int cryIndex = isBarrel ? ((EBDetId)det).hashedIndex() : getEEIndex(elecId);
00218     int ic = isBarrel ? ((EBDetId)det).ic() : getEEIndex(elecId);
00219     
00220     float ampli = hit.energy();
00221 
00222     vector<int>::iterator result;
00223     result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
00224     if(result != maskedFEDs_.end())
00225     {
00226       //LogWarning("EcalDisplaysByEvent") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
00227       continue;
00228     }      
00229     result = find(maskedChannels_.begin(), maskedChannels_.end(), cryIndex);
00230     if  (result != maskedChannels_.end())
00231     {
00232       //LogWarning("EcalDisplaysByEvent") << "skipping uncalRecHit for channel: " << cryIndex << " in fed: " << FEDid << " with amplitude " << ampli ;
00233       continue;
00234     } 
00235     bool cryIsInList = false;
00236     result = find(seedCrys_.begin(), seedCrys_.end(), cryIndex);
00237     if  (result != seedCrys_.end())
00238       cryIsInList = true;
00239 
00240     // Either we must have a user-requested cry (in which case there is no amplitude selection)
00241     // Or we pick all crys that pass the amplitude cut (in which case there is no fixed crystal selection)
00242     if(cryIsInList || (seedCrys_.empty() && ampli > threshold_))
00243     {
00244       // We have a winner!
00245       crysAndAmplitudesMap_[cryIndex] = ampli;
00246       string name = "Digis_Event" + intToString(naiveEvtNum_) + "_ic" + intToString(ic)
00247         + "_FED" + intToString(FEDid);
00248       string title = "Digis";
00249       string seed = "ic" + intToString(ic) + "_FED" + intToString(FEDid);
00250       int freq=1;
00251       pair<map<string,int>::iterator,bool> pair = seedFrequencyMap_.insert(make_pair(seed,freq));
00252       if(!pair.second)
00253       {
00254         ++(pair.first->second);
00255       }
00256       
00257       //TODO: move this also to TFileService
00258       TCanvas can(name.c_str(),title.c_str(),200,50,900,900);
00259       can.Divide(side_,side_);
00260       TGraph* myGraph;
00261 
00262       CaloNavigator<DetId> cursor = CaloNavigator<DetId>(det,caloTopo->getSubdetectorTopology(det));
00263       //Now put each graph in one by one
00264       for(int j=side_/2; j>=-side_/2; --j)
00265       {
00266         for(int i=-side_/2; i<=side_/2; ++i)
00267         {
00268           cursor.home();
00269           cursor.offsetBy(i,j);
00270           can.cd(i+1+side_/2+side_*(1-j));
00271           myGraph = selectDigi(*cursor,ievt);
00272           myGraph->Draw("A*");
00273         }
00274       }
00275       can.Write();
00276       names->push_back(name);
00277     }
00278   }
00279 }
00280 
00281 TGraph* EcalDisplaysByEvent::selectDigi(DetId thisDet, int ievt)
00282 {
00283   int emptyY[10];
00284   for (int i=0; i<10; i++)
00285     emptyY[i] = 0;
00286   TGraph* emptyGraph = fileService->make<TGraph>(10, abscissa, emptyY);
00287   emptyGraph->SetTitle("NOT ECAL");
00288   
00289   //If the DetId is not from Ecal, return
00290   if(thisDet.det() != DetId::Ecal)
00291     return emptyGraph;
00292   
00293   emptyGraph->SetTitle("NO DIGIS");
00294   //find digi we need  -- can't get find() to work; need DataFrame(DetId det) to work? 
00295   EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(thisDet);
00296   int FEDid = 600+elecId.dccId();
00297   bool isBarrel = true;
00298   if(FEDid < 610 || FEDid > 645)
00299     isBarrel = false;
00300   int cryIndex = isBarrel ? ((EBDetId)thisDet).hashedIndex() : getEEIndex(elecId);
00301   int ic = isBarrel ? ((EBDetId)thisDet).ic() : cryIndex;
00302 
00303   string sliceName = fedMap_->getSliceFromFed(FEDid);
00304   EcalDataFrame df;
00305   if(isBarrel)
00306   {
00307     EBDigiCollection::const_iterator digiItr = EBdigisHandle->begin();
00308     while(digiItr != EBdigisHandle->end() && ((*digiItr).id() != (EBDetId)thisDet))
00309     {
00310       ++digiItr;
00311     }
00312     if(digiItr==EBdigisHandle->end())
00313     {
00314       //LogWarning("EcalDisplaysByEvent") << "Cannot find digi for ic:" << ic
00315       //  << " FED:" << FEDid << " evt:" << naiveEvtNum_;
00316       return emptyGraph;
00317     }
00318     else
00319       df = *digiItr;
00320   }
00321   else
00322   {
00323     EEDigiCollection::const_iterator digiItr = EEdigisHandle->begin();
00324     while(digiItr != EEdigisHandle->end() && ((*digiItr).id() != (EEDetId)thisDet))
00325     {
00326       ++digiItr;
00327     }
00328     if(digiItr==EEdigisHandle->end())
00329     {
00330       //LogWarning("EcalDisplaysByEvent") << "Cannot find digi for ic:" << ic
00331       //  << " FED:" << FEDid << " evt:" << naiveEvtNum_;
00332       return emptyGraph;
00333     }
00334     else df = *digiItr;
00335   }
00336 
00337   int gainId = FEDsAndDCCHeaders_[FEDid].getMgpaGain();
00338   int gainHuman;
00339   if      (gainId ==1) gainHuman =12;
00340   else if (gainId ==2) gainHuman =6;
00341   else if (gainId ==3) gainHuman =1;
00342   else                 gainHuman =-1; 
00343 
00344   double pedestal = 200;
00345 
00346   emptyGraph->SetTitle("FIRST TWO SAMPLES NOT GAIN12");
00347   if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) return emptyGraph; //goes to the next digi
00348   else {
00349     ordinate[0] = df.sample(0).adc();
00350     ordinate[1] = df.sample(1).adc();
00351     pedestal = (double)(ordinate[0]+ordinate[1])/(double)2;
00352   } 
00353 
00354 
00355   for (int i=0; i < df.size(); ++i ) {
00356     if (df.sample(i).gainId() != 0)
00357       ordinate[i] = (int)(pedestal+(df.sample(i).adc()-pedestal)*gainRatio[df.sample(i).gainId()-1]);
00358     else
00359       ordinate[i] = 49152; //Saturation of gain1 
00360   }
00361 
00362   TGraph* oneGraph = fileService->make<TGraph>(10, abscissa, ordinate);
00363   string name = "Graph_ev" + intToString(naiveEvtNum_) + "_ic" + intToString(ic)
00364     + "_FED" + intToString(FEDid);
00365   string gainString = (gainId==1) ? "Free" : intToString(gainHuman);
00366   string title = "Event" + intToString(naiveEvtNum_) + "_lv1a" + intToString(ievt) +
00367     "_ic" + intToString(ic) + "_" + sliceName + "_gain" + gainString;
00368     
00369   float energy = 0;
00370   map<int,float>::const_iterator itr;
00371   itr = crysAndAmplitudesMap_.find(cryIndex);
00372   if(itr!=crysAndAmplitudesMap_.end())
00373   {
00374     //edm::LogWarning("EcalDisplaysByEvent")<< "itr->second(ampli)="<< itr->second;
00375     energy = (float) itr->second;
00376   }
00377   //else
00378   //edm::LogWarning("EcalDisplaysByEvent") << "cry " << ic << "not found in ampMap";
00379 
00380   title+="_Energy"+floatToString(round(energy*1000));
00381 
00382   oneGraph->SetTitle(title.c_str());
00383   oneGraph->SetName(name.c_str());
00384   oneGraph->GetXaxis()->SetTitle("sample");
00385   oneGraph->GetYaxis()->SetTitle("ADC");
00386   return oneGraph;
00387 }
00388 
00389 int EcalDisplaysByEvent::getEEIndex(EcalElectronicsId elecId)
00390 {
00391   int FEDid = 600+elecId.dccId();
00392   return 10000*FEDid+100*elecId.towerId()+5*(elecId.stripId()-1)+elecId.xtalId();
00393 }
00394 
00395 void EcalDisplaysByEvent::makeHistos(Handle<EBDigiCollection> ebDigiHandle) {
00396    const EBDigiCollection* ebDigis = ebDigiHandle.product();
00397    for(EBDigiCollection::const_iterator digiItr = ebDigis->begin(); digiItr != ebDigis->end(); ++digiItr) {
00398       EBDetId digiId = digiItr->id();
00399       int ieta = digiId.ieta();
00400       int iphi = digiId.iphi();
00401       digiOccupancyEBAll_->Fill(iphi,ieta);
00402       digiOccupancyEBcoarseAll_->Fill(iphi,ieta);
00403       if(makeOccupancyHistos_)
00404       {
00405         digiOccupancyEB_->Fill(iphi,ieta);
00406         digiOccupancyEBcoarse_->Fill(iphi,ieta);
00407       }
00408    }
00409 }
00410 
00411 void EcalDisplaysByEvent::makeHistos(Handle<EEDigiCollection> eeDigiHandle) {
00412    const EEDigiCollection* eeDigis = eeDigiHandle.product();
00413    for(EEDigiCollection::const_iterator digiItr = eeDigis->begin(); digiItr != eeDigis->end(); ++digiItr) {
00414       DetId det = digiItr->id();
00415       EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(det);
00416       int FEDid = 600+elecId.dccId();
00417       bool isEEM = false;
00418       if(FEDid < 610 || FEDid > 645)
00419       {
00420          if(FEDid < 610)
00421             isEEM = true;
00422       }
00423       EEDetId digiId = digiItr->id();
00424       int ieta = digiId.iy();
00425       int iphi = digiId.ix();
00426       if(isEEM)
00427       {
00428          digiOccupancyEEMAll_->Fill(iphi,ieta);
00429          digiOccupancyEEMcoarseAll_->Fill(iphi,ieta);
00430          if(makeOccupancyHistos_)
00431          {
00432            digiOccupancyEEMcoarse_->Fill(iphi,ieta);
00433            digiOccupancyEEM_->Fill(iphi,ieta);
00434          }
00435       }
00436       else
00437       {
00438          digiOccupancyEEPAll_->Fill(iphi,ieta);
00439          digiOccupancyEEPcoarseAll_->Fill(iphi,ieta);
00440          if(makeOccupancyHistos_)
00441          {
00442            digiOccupancyEEP_->Fill(iphi,ieta);
00443            digiOccupancyEEPcoarse_->Fill(iphi,ieta);
00444          }
00445       }  
00446    }
00447 }
00448 
00449 void EcalDisplaysByEvent::makeHistos(Handle<EcalRecHitCollection> hits)
00450 {
00451   for (EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr)
00452   {
00453     EcalRecHit hit = (*hitItr);
00454     DetId det = hit.id();
00455     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(det);
00456     int FEDid = 600+elecId.dccId();
00457     bool isBarrel = true;
00458     bool isEEM = false;
00459     if(FEDid < 610 || FEDid > 645)
00460     {
00461       isBarrel = false;
00462       if(FEDid < 610)
00463         isEEM = true;
00464     }
00465     int iphi = isBarrel ? ((EBDetId)det).iphi() : ((EEDetId)det).ix();
00466     int ieta = isBarrel ? ((EBDetId)det).ieta() : ((EEDetId)det).iy();
00467     float energy = hit.energy();
00468     float time = hit.time();
00469     
00470     // Fill energy histos
00471     if(makeEnergyHistos_)
00472     {
00473       if(isBarrel)
00474       {
00475         energyEB_->Fill(energy);
00476         energyMapEB_->Fill(iphi,ieta,energy);
00477         energyMapEBcoarse_->Fill(iphi,ieta,energy);
00478       }
00479       else if(isEEM)
00480       {
00481         energyEEM_->Fill(energy);
00482         energyMapEEM_->Fill(iphi,ieta,energy);
00483         energyMapEEMcoarse_->Fill(iphi,ieta,energy);
00484       }
00485       else
00486       {
00487         energyEEP_->Fill(energy);
00488         energyMapEEP_->Fill(iphi,ieta,energy);
00489         energyMapEEPcoarse_->Fill(iphi,ieta,energy);
00490       }
00491     }
00492     // Fill occupancy histos
00493     if(makeOccupancyHistos_)
00494     {
00495       if(isBarrel)
00496       {
00497         recHitOccupancyEB_->Fill(iphi,ieta);
00498         recHitOccupancyEBcoarse_->Fill(iphi,ieta);
00499       }
00500       else if(isEEM)
00501       {
00502          recHitOccupancyEEM_->Fill(iphi,ieta);
00503          recHitOccupancyEEMcoarse_->Fill(iphi,ieta);
00504       }
00505       else
00506       {
00507          recHitOccupancyEEP_->Fill(iphi,ieta);
00508          recHitOccupancyEEPcoarse_->Fill(iphi,ieta);
00509       }
00510     }
00511 
00512     // Fill timing histos
00513     if(makeTimingHistos_)
00514     {
00515       if(isBarrel) {
00516         timingEB_->Fill(time);
00517         if(energy > minTimingEnergyEB_) {
00518            timingMapEB_->Fill(iphi,ieta,time);
00519            //timingMapEBCoarse_->Fill(iphi,ieta,time);
00520         }
00521       }
00522       else if(isEEM) {
00523          timingEEM_->Fill(time);
00524          if(energy > minTimingEnergyEE_)
00525          {
00526             timingMapEEM_->Fill(iphi,ieta,time);
00527             //timingMapEEMCoarse_->Fill(iphi,ieta,time);
00528          }
00529       }
00530       else {
00531          timingEEP_->Fill(time);
00532          if(energy > minTimingEnergyEE_)
00533          {
00534             timingMapEEP_->Fill(iphi,ieta,time);
00535             //timingMapEEPCoarse_->Fill(iphi,ieta,time);
00536          }
00537       }
00538     }
00539 
00540     //All events
00541     if(isBarrel)
00542     {
00543       energyEBAll_->Fill(energy);
00544       energyMapEBAll_->Fill(iphi,ieta,energy);
00545       energyMapEBcoarseAll_->Fill(iphi,ieta,energy);
00546       recHitOccupancyEBAll_->Fill(iphi,ieta);
00547       recHitOccupancyEBcoarseAll_->Fill(iphi,ieta);
00548       timingEBAll_->Fill(time);
00549       if(energy > minTimingEnergyEB_)
00550       {
00551         timingMapEBAll_->Fill(iphi,ieta,time);
00552         timingMapEBCoarseAll_->Fill(iphi,ieta,time);
00553       }
00554     }
00555     else if(isEEM)
00556     {
00557       energyEEMAll_->Fill(energy);
00558       energyMapEEMAll_->Fill(iphi,ieta,energy);
00559       energyMapEEMcoarseAll_->Fill(iphi,ieta,energy);
00560       recHitOccupancyEEMAll_->Fill(iphi,ieta);
00561       recHitOccupancyEEMcoarseAll_->Fill(iphi,ieta);
00562       timingEEMAll_->Fill(time);
00563       if(energy > minTimingEnergyEE_)
00564       {
00565         timingMapEEMAll_->Fill(iphi,ieta,time);
00566         timingMapEEMCoarseAll_->Fill(iphi,ieta,time);
00567       }
00568     }
00569     else
00570     {
00571       energyEEPAll_->Fill(energy);
00572       energyMapEEPAll_->Fill(iphi,ieta,energy);
00573       energyMapEEPcoarseAll_->Fill(iphi,ieta,energy);
00574       recHitOccupancyEEPAll_->Fill(iphi,ieta);
00575       recHitOccupancyEEPcoarseAll_->Fill(iphi,ieta);
00576       timingEEPAll_->Fill(time);
00577       if(energy > minTimingEnergyEE_)
00578       {
00579         timingMapEEPAll_->Fill(iphi,ieta,time);
00580         timingMapEEPCoarseAll_->Fill(iphi,ieta,time);
00581       }
00582     }
00583     // Fill FED-by-FED timing histos (all events)
00584     TH1F* timingHist = FEDsAndTimingHists_[FEDid];
00585     if(timingHist==0)
00586     {
00587       initHists(FEDid);
00588       timingHist = FEDsAndTimingHists_[FEDid];
00589     }
00590     if(energy > minTimingAmp_)
00591     {
00592       timingHist->Fill(hit.time());
00593       allFedsTimingHist_->Fill(hit.time());
00594     }
00595   }
00596 }
00597 
00598 // ------------ method called once each job just after ending the event loop  ------------
00599 void 
00600 EcalDisplaysByEvent::endJob()
00601 {
00602   //All-event canvases
00603   drawCanvas(timingCanvasAll_,timingEEMAll_,timingEBAll_,timingEEPAll_);
00604   drawCanvas(timingMapCanvasAll_,timingMapEEMAll_,timingMapEBAll_,timingMapEEPAll_);
00605   drawCanvas(energyCanvasAll_,energyEEMAll_,energyEBAll_,energyEEPAll_);
00606   drawCanvas(energyMapCanvasAll_,energyMapEEMAll_,energyMapEBAll_,energyMapEEPAll_);
00607   drawCanvas(energyMapCoarseCanvasAll_,energyMapEEMcoarseAll_,energyMapEBcoarseAll_,energyMapEEPcoarseAll_);
00608   drawCanvas(recHitOccupancyCanvasAll_,recHitOccupancyEEMAll_,recHitOccupancyEBAll_,recHitOccupancyEEPAll_);
00609   drawCanvas(recHitOccupancyCoarseCanvasAll_,recHitOccupancyEEMcoarseAll_,recHitOccupancyEBcoarseAll_,recHitOccupancyEEPcoarseAll_);
00610   drawCanvas(digiOccupancyCanvasAll_,digiOccupancyEEMAll_,digiOccupancyEBAll_,digiOccupancyEEPAll_);
00611   drawCanvas(digiOccupancyCoarseCanvasAll_,digiOccupancyEEMcoarseAll_,digiOccupancyEBcoarseAll_,digiOccupancyEEPcoarseAll_);
00612 
00613   if(runNum_ != -1) {
00614     canvasNames_->Fill();
00615     histoCanvasNames_->Fill();
00616   }
00617 
00618   string frequencies = "";
00619   for(std::map<std::string,int>::const_iterator itr = seedFrequencyMap_.begin();
00620       itr != seedFrequencyMap_.end(); ++itr)
00621   {
00622     if(itr->second > 1)
00623     {
00624       frequencies+=itr->first;
00625       frequencies+=" Frequency: ";
00626       frequencies+=intToString(itr->second);
00627       frequencies+="\n";
00628     }
00629   }
00630   LogWarning("EcalDisplaysByEvent") << "Found seeds with frequency > 1: " << "\n\n" << frequencies;
00631   
00632   std::string channels;
00633   for(std::vector<int>::const_iterator itr = maskedChannels_.begin();
00634       itr != maskedChannels_.end(); ++itr)
00635   {
00636     channels+=intToString(*itr);
00637     channels+=",";
00638   }
00639   
00640   std::string feds;
00641   for(std::vector<int>::const_iterator itr = maskedFEDs_.begin();
00642       itr != maskedFEDs_.end(); ++itr)
00643   {
00644     feds+=intToString(*itr);
00645     feds+=",";
00646   }
00647 
00648   LogWarning("EcalDisplaysByEvent") << "Masked channels are: " << channels;
00649   LogWarning("EcalDisplaysByEvent") << "Masked FEDs are: " << feds << " and that is all!";
00650 }
00651 
00652 std::string EcalDisplaysByEvent::intToString(int num)
00653 {
00654     using namespace std;
00655     ostringstream myStream;
00656     myStream << num << flush;
00657     return(myStream.str()); //returns the string form of the stringstream object
00658 }
00659 
00660 std::string EcalDisplaysByEvent::floatToString(float num)
00661 {
00662     using namespace std;
00663     ostringstream myStream;
00664     myStream << num << flush;
00665     return(myStream.str()); //returns the string form of the stringstream object
00666 }
00667 
00668 // insert the hist map into the map keyed by FED number
00669 void EcalDisplaysByEvent::initHists(int FED)
00670 {
00671   using namespace std;
00672   
00673   string title1 = "Jitter for ";
00674   title1.append(fedMap_->getSliceFromFed(FED));
00675   string name1 = "JitterFED";
00676   name1.append(intToString(FED));
00677   TH1F* timingHist = fileService->make<TH1F>(name1.c_str(),title1.c_str(),150,-7,7);
00678   FEDsAndTimingHists_[FED] = timingHist;
00679 }
00680 
00681 void EcalDisplaysByEvent::initEvtByEvtHists(int naiveEvtNum_, int ievt)
00682 {
00683   string lastPart = intToString(naiveEvtNum_)+"_LV1a"+intToString(ievt);
00684   if(makeTimingHistos_)
00685   {
00686     string canvasTitle = "Timing_Event"+lastPart;
00687     timingEB_ = new TH1F("timeForAllFedsEB","timeForAllFeds;Relative Time (1 clock = 25ns)",78,-7,7);
00688     timingEEM_ = new TH1F("timeForAllFedsEEM","timeForAllFeds_EEM;Relative Time (1 clock = 25ns)",78,-7,7);
00689     timingEEP_ = new TH1F("timeForAllFedsEEP","timeForAllFeds_EEP;Relative Time (1 clock = 25ns)",78,-7,7);
00690     timingCanvas_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00691     timingMapEB_ = init3DEcalHist("TimingMap", EB_FINE);
00692     timingMapEEM_ = init3DEcalHist("TimingMap", EEM_FINE);
00693     timingMapEEP_ = init3DEcalHist("TimingMap", EEP_FINE);
00694     timingMapCanvas_ = init2DEcalCanvas("TimingMap_Event"+lastPart);
00695     //timingMapEBCoarse_ = init3DEcalHist("TimingMap", EB_COARSE);
00696     timingMapEEMCoarse_ = init3DEcalHist("TimingMap", EEM_COARSE);
00697     timingMapEEPCoarse_ = init3DEcalHist("TimingMap", EEP_COARSE);
00698     //timingMapCoarseCanvas_ = init2DEcalCanvas("TimingMapCoarse_Event"+lastPart);  
00699   }
00700   if(makeEnergyHistos_)
00701   {
00702     energyEB_ = new TH1F("energyEB","Energy for EB Feds (GeV)",200,histRangeMin_,histRangeMax_);
00703     energyEEM_ = new TH1F("energyEEM","Energy for EEM Feds (GeV)",200,histRangeMin_,10.0);
00704     energyEEP_ = new TH1F("energyEEP","Energy for EEP Feds (GeV)",200,histRangeMin_,10.0);
00705     string canvasTitle = "Energy_Event"+lastPart;
00706     energyCanvas_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00707 
00708     // Energy map hists
00709     energyMapEB_            = init2DEcalHist("EnergyMap",EB_FINE);
00710     energyMapEBcoarse_      = init2DEcalHist("EnergyMap",EB_COARSE);
00711     energyMapEEMcoarse_           = init2DEcalHist("EnergyMap",EEM_COARSE);
00712     energyMapEEM_                 = init2DEcalHist("EnergyMap",EEM_FINE);
00713     energyMapEEPcoarse_           = init2DEcalHist("EnergyMap",EEP_COARSE);
00714     energyMapEEP_                 = init2DEcalHist("EnergyMap",EEP_FINE);
00715     energyMapCanvas_ = init2DEcalCanvas("EnergyMap_Event"+lastPart);
00716     energyMapCoarseCanvas_ = init2DEcalCanvas("EnergyMapCoarse_Event"+lastPart);
00717   }
00718   if(makeOccupancyHistos_) 
00719   {
00720      // RecHit Occupancy
00721     recHitOccupancyEB_ = init2DEcalHist("RecHitOccupancy",EB_FINE);
00722     recHitOccupancyEBcoarse_ = init2DEcalHist("RecHitOccupancy",EB_COARSE);
00723     recHitOccupancyEEMcoarse_ = init2DEcalHist("RecHitOccupancy",EEM_COARSE);
00724     recHitOccupancyEEM_ = init2DEcalHist("RecHitOccupancy",EEM_FINE);
00725     recHitOccupancyEEPcoarse_ = init2DEcalHist("RecHitOccupancy",EEP_COARSE);
00726     recHitOccupancyEEP_ = init2DEcalHist("RecHitOccupancy",EEP_FINE);
00727     recHitOccupancyCanvas_ = init2DEcalCanvas("RecHitOccupancy_Event"+lastPart);
00728     recHitOccupancyCoarseCanvas_ =init2DEcalCanvas("RecHitOccupancyCoarse_Event"+lastPart);
00729 
00730     //DigiOccupancy
00731     digiOccupancyEB_ = init2DEcalHist("DigiOccupancy",EB_FINE);
00732     digiOccupancyEBcoarse_ = init2DEcalHist("DigiOccupancy", EB_COARSE);
00733     digiOccupancyEEMcoarse_ = init2DEcalHist("DigiOccupancy",EEM_COARSE);
00734     digiOccupancyEEM_ = init2DEcalHist("DigiOccupancy",EEM_FINE);
00735     digiOccupancyEEPcoarse_ = init2DEcalHist("DigiOccupancy",EEP_COARSE);
00736     digiOccupancyEEP_ = init2DEcalHist("DigiOccupancy",EEP_FINE);
00737     digiOccupancyCanvas_ = init2DEcalCanvas("DigiOccupancy_Event"+lastPart);
00738     digiOccupancyCoarseCanvas_ = init2DEcalCanvas("DigiOccupancyCoarse_Event"+lastPart);
00739   }
00740 }
00741 
00742 void EcalDisplaysByEvent::deleteEvtByEvtHists()
00743 {
00744     delete timingEB_;
00745     delete timingEEM_;
00746     delete timingEEP_;
00747     delete timingMapEB_;
00748     delete timingMapEEM_;
00749     delete timingMapEEP_;
00750     delete timingCanvas_;
00751     delete timingMapCanvas_;
00752     delete energyEB_;
00753     delete energyEEM_;
00754     delete energyEEP_;
00755     delete energyMapEB_;
00756     delete energyMapEEM_;
00757     delete energyMapEEP_;
00758     delete energyMapEBcoarse_;
00759     delete energyMapEEMcoarse_;
00760     delete energyMapEEPcoarse_;
00761     delete energyCanvas_;
00762     delete energyMapCanvas_;
00763     delete energyMapCoarseCanvas_;
00764     delete recHitOccupancyEB_;
00765     delete recHitOccupancyEEP_;
00766     delete recHitOccupancyEEM_;
00767     delete recHitOccupancyEBcoarse_;
00768     delete recHitOccupancyEEMcoarse_;
00769     delete recHitOccupancyEEPcoarse_;
00770     delete digiOccupancyEB_;
00771     delete digiOccupancyEEM_;
00772     delete digiOccupancyEEP_;
00773     delete digiOccupancyEBcoarse_;
00774     delete digiOccupancyEEMcoarse_;
00775     delete digiOccupancyEEPcoarse_;
00776     delete recHitOccupancyCanvas_;
00777     delete recHitOccupancyCoarseCanvas_;
00778     delete digiOccupancyCanvas_;
00779     delete digiOccupancyCoarseCanvas_;
00780 }
00781 
00782 void EcalDisplaysByEvent::initAllEventHistos()
00783 {
00784   string canvasTitle = "Timing_AllEvents";
00785   timingEBAll_ = new TH1F("timeForAllFedsEBAll","timeForAllFeds;Relative Time (1 clock = 25ns)",78,-7,7);
00786   timingEEMAll_ = new TH1F("timeForAllFedsEEMAll","timeForAllFeds_EEM;Relative Time (1 clock = 25ns)",78,-7,7);
00787   timingEEPAll_ = new TH1F("timeForAllFedsEEPAll","timeForAllFeds_EEP;Relative Time (1 clock = 25ns)",78,-7,7);
00788   timingCanvasAll_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00789   timingMapEBAll_ = init3DEcalHist("TimingMapA", EB_FINE);
00790   timingMapEEMAll_ = init3DEcalHist("TimingMapA", EEM_FINE);
00791   timingMapEEPAll_ = init3DEcalHist("TimingMapA", EEP_FINE);
00792   timingMapCanvasAll_ = init2DEcalCanvas("TimingMap_AllEvents");
00793   timingMapEBCoarseAll_ = init3DEcalHist("TimingMapA", EB_COARSE);
00794   timingMapEEMCoarseAll_ = init3DEcalHist("TimingMapA", EEM_COARSE);
00795   timingMapEEPCoarseAll_ = init3DEcalHist("TimingMapA", EEP_COARSE);
00796   //timingMapCoarseCanvasAll_ = init2DEcalCanvas("TimingMapCoarse_AllEvents"); 
00797   energyEBAll_ = new TH1F("energyEBAllEvents","Energy for EB Feds (GeV)",200,histRangeMin_,histRangeMax_);
00798   energyEEMAll_ = new TH1F("energyEEMAllEvents","Energy for EEM Feds (GeV)",200,histRangeMin_,10.0);
00799   energyEEPAll_ = new TH1F("energyEEPAllEvents","Energy for EEP Feds (GeV)",200,histRangeMin_,10.0);
00800   canvasTitle = "Energy_AllEvents";
00801   energyCanvasAll_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00802 
00803   // Energy map hists
00804   energyMapEBAll_            = init2DEcalHist("EnergyMapA",EB_FINE);
00805   energyMapEBcoarseAll_      = init2DEcalHist("EnergyMapA",EB_COARSE);
00806   energyMapEEMcoarseAll_           = init2DEcalHist("EnergyMapA",EEM_COARSE);
00807   energyMapEEMAll_                 = init2DEcalHist("EnergyMapA",EEM_FINE);
00808   energyMapEEPcoarseAll_           = init2DEcalHist("EnergyMapA",EEP_COARSE);
00809   energyMapEEPAll_                 = init2DEcalHist("EnergyMapA",EEP_FINE);
00810   energyMapCanvasAll_ = init2DEcalCanvas("EnergyMap_AllEvents");
00811   energyMapCoarseCanvasAll_ = init2DEcalCanvas("EnergyMapCoarse_AllEvents");
00812   // RecHit Occupancy
00813   recHitOccupancyEBAll_ = init2DEcalHist("RecHitOccupancyA",EB_FINE);
00814   recHitOccupancyEBcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EB_COARSE);
00815   recHitOccupancyEEMcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EEM_COARSE);
00816   recHitOccupancyEEMAll_ = init2DEcalHist("RecHitOccupancyA",EEM_FINE);
00817   recHitOccupancyEEPcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EEP_COARSE);
00818   recHitOccupancyEEPAll_ = init2DEcalHist("RecHitOccupancyA",EEP_FINE);
00819   recHitOccupancyCanvasAll_ = init2DEcalCanvas("RecHitOccupancy_AllEvents");
00820   recHitOccupancyCoarseCanvasAll_ =init2DEcalCanvas("RecHitOccupancyCoarse_AllEvents");
00821 
00822   //DigiOccupancy
00823   digiOccupancyEBAll_ = init2DEcalHist("DigiOccupancyA",EB_FINE);
00824   digiOccupancyEBcoarseAll_ = init2DEcalHist("DigiOccupancyA", EB_COARSE);
00825   digiOccupancyEEMcoarseAll_ = init2DEcalHist("DigiOccupancyA",EEM_COARSE);
00826   digiOccupancyEEMAll_ = init2DEcalHist("DigiOccupancyA",EEM_FINE);
00827   digiOccupancyEEPcoarseAll_ = init2DEcalHist("DigiOccupancyA",EEP_COARSE);
00828   digiOccupancyEEPAll_ = init2DEcalHist("DigiOccupancyA",EEP_FINE);
00829   digiOccupancyCanvasAll_ = init2DEcalCanvas("DigiOccupancy_AllEvents");
00830   digiOccupancyCoarseCanvasAll_ = init2DEcalCanvas("DigiOccupancyCoarse_AllEvents");
00831 
00832 }
00833 
00834 
00835 TH3F* EcalDisplaysByEvent::init3DEcalHist(std::string histTypeName, int subDet) {
00836    TH3F* hist;
00837    bool isBarrel = (subDet == EB_FINE || subDet == EB_COARSE) ? true : false;
00838    bool isCoarse = (subDet == EB_COARSE || subDet == EEM_COARSE || subDet == EEP_COARSE) ? true : false; 
00839    bool isEEM = (subDet == EEM_FINE || subDet == EEM_COARSE) ? true : false;
00840    std::string histName = histTypeName;
00841    std::string histTitle = histTypeName;
00842    double ttEtaBins[36] = {-85, -80, -75, -70, -65, -60, -55, -50, -45, -40, -35, -30, -25, -20, -15, -10, -5, 0, 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86 };
00843    double modEtaBins[10]={-85, -65, -45, -25, 0, 1, 26, 46, 66, 86};
00844    double ttPhiBins[73];
00845    double modPhiBins[19];
00846    double timingBins[79];
00847    double highEBins[11];
00848    for (int i = 0; i < 79; ++i)
00849    {
00850       timingBins[i]= 6 - 7. + double(i) * 14. / 78.;
00851       if (i<73)  
00852       {       
00853          ttPhiBins[i]=1+5*i;
00854          if ( i < 19) 
00855          {       
00856             modPhiBins[i]=1+20*i;
00857             if (i < 11)
00858             {       
00859                highEBins[i]=10.+double(i)*20.;
00860             }       
00861          }       
00862       }       
00863 
00864    }
00865 
00866    if(isBarrel) {
00867       histName = histName + "EB";
00868       histTitle = histTitle + " EB";
00869       if(isCoarse) {
00870          histName = histName + "Coarse";
00871          histTitle = histTitle + " by Module Nominal value = 6;iphi;ieta ";
00872          hist = new TH3F(histName.c_str(),histTitle.c_str(),18,modPhiBins,9,modEtaBins,78,timingBins);
00873       }
00874       else {
00875          histTitle = histTitle + " by TT Nominal value = 6;iphi;ieta";
00876          hist = new TH3F(histName.c_str(),histTitle.c_str(),360/5,ttPhiBins,35,ttEtaBins,78,timingBins);
00877       }
00878    }
00879    else {
00880       double ttXBins[21];
00881       double ttYBins[21];
00882       for(int i=0;i!=21;++i) {
00883          ttXBins[i] = 1 + 5*i;
00884          ttYBins[i] = 1 + 5*i;
00885       }
00886       if(isEEM) {
00887          histName = histName + "EEM";
00888          histTitle = histTitle + " EEM";
00889       }
00890       else {
00891          histName = histName + "EEP";
00892          histTitle = histTitle + " EEP";
00893       }
00894       if(isCoarse) {
00895          histName = histName + "Coarse";
00896          histTitle = histTitle + " by Module Nominal value = 6;ix;iy";
00897          hist = new TH3F(histName.c_str(),histTitle.c_str(),20,ttXBins,20,ttYBins,78,timingBins);
00898       }
00899       else {
00900          histTitle = histTitle + " by TT Nominal value = 6;ix;iy";
00901          hist = new TH3F(histName.c_str(),histTitle.c_str(),20,ttXBins,20,ttYBins,78,timingBins);
00902       }
00903    }
00904    return hist;
00905 }
00906 
00907 TH2F* EcalDisplaysByEvent::init2DEcalHist(std::string histTypeName, int subDet) {
00908    TH2F* hist;
00909    bool isBarrel = (subDet == EB_FINE || subDet == EB_COARSE) ? true : false;
00910    bool isCoarse = (subDet == EB_COARSE || subDet == EEM_COARSE || subDet == EEP_COARSE) ? true : false; 
00911    bool isEEM = (subDet == EEM_FINE || subDet == EEM_COARSE) ? true : false;
00912    std::string histName = histTypeName;
00913    std::string histTitle = histTypeName;
00914    if(isBarrel) {
00915       histName = histName + "EB";
00916       histTitle = histTitle + " EB";
00917       if(isCoarse) {
00918          histName = histName + "Coarse";
00919          histTitle = histTitle + " Coarse;iphi;ieta";
00920          double ttEtaBins[36] = {-85, -80, -75, -70, -65, -60, -55, -50, -45, -40, 
00921             -35, -30, -25, -20, -15, -10, -5, 0, 1, 6, 11, 16, 
00922             21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86 };
00923          hist = new TH2F(histName.c_str(),histTitle.c_str(),360/5,1,361.,35,ttEtaBins);
00924       }
00925       else {
00926          histTitle = histTitle + ";iphi;ieta";
00927          hist = new TH2F(histName.c_str(),histTitle.c_str(),360,1,361.,172,-86,86);
00928       }
00929    }
00930    else {
00931       if(isEEM) {
00932          histName = histName + "EEM";
00933          histTitle = histTitle + " EEM";
00934       }
00935       else {
00936          histName = histName + "EEP";
00937          histTitle = histTitle + " EEP";
00938       }
00939       if(isCoarse) {
00940          histName = histName + "Coarse";
00941          histTitle = histTitle + " Coarse;ix;iy";
00942          hist = new TH2F(histName.c_str(),histTitle.c_str(),20,1,101,20,1,101);
00943       }
00944       else {
00945          histTitle = histTitle + ";ix;iy";
00946          hist = new TH2F(histName.c_str(),histTitle.c_str(),100,1,101,100,1,101);
00947       }
00948    }
00949    return hist;
00950 }
00951 
00952 TCanvas* EcalDisplaysByEvent::init2DEcalCanvas(std::string canvasTitle) {
00953     TCanvas* canvas = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00954     return canvas;
00955 }
00956 
00957 void EcalDisplaysByEvent::drawHistos()
00958 {
00959   if(makeTimingHistos_)
00960   {
00961     // Put the timing canvas together
00962     drawCanvas(timingCanvas_,timingEEM_,timingEB_,timingEEP_);
00963     //   drawCanvas(timingMapCoarseCanvas_,timingMapEEMCoarse_,timingMapEBCoarse_,timingMapEEPCoarse_);
00964     drawCanvas(timingMapCanvas_,timingMapEEM_,timingMapEB_,timingMapEEP_);
00965   }
00966   if(makeEnergyHistos_)
00967   {
00968     // Put the energy canvas together
00969     drawCanvas(energyCanvas_,energyEEM_,energyEB_,energyEEP_);
00970     // Put the energy map canvas together
00971     drawCanvas(energyMapCanvas_,energyMapEEM_,energyMapEB_,energyMapEEP_);
00972     drawCanvas(energyMapCoarseCanvas_,energyMapEEMcoarse_,energyMapEBcoarse_,energyMapEEPcoarse_);
00973   }
00974   if(makeOccupancyHistos_)
00975   {
00976     // Put the occupancy canvas together
00977     drawCanvas(recHitOccupancyCanvas_,recHitOccupancyEEM_,recHitOccupancyEB_,recHitOccupancyEEP_);
00978     drawCanvas(recHitOccupancyCoarseCanvas_,recHitOccupancyEEMcoarse_,recHitOccupancyEBcoarse_,recHitOccupancyEEPcoarse_);
00979     // And the same for the digis
00980     drawCanvas(digiOccupancyCanvas_,digiOccupancyEEM_,digiOccupancyEB_,digiOccupancyEEP_);
00981     drawCanvas(digiOccupancyCoarseCanvas_,digiOccupancyEEMcoarse_,digiOccupancyEBcoarse_,digiOccupancyEEPcoarse_);
00982   }
00983 }
00984 
00985 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH1F* hist1, TH1F* hist2, TH1F* hist3) {
00986   canvas->Divide(1,2); 
00987   canvas->cd(1)->Divide(2,1); 
00988   canvas->cd(1)->cd(1);
00989   hist1->Draw();
00990   canvas->cd(2); 
00991   hist2->Draw();
00992   canvas->cd(1)->cd(2);
00993   hist3->Draw(); 
00994   histoCanvasNamesVector->push_back(canvas->GetName());
00995   canvas->SetCanvasSize(500,500);
00996   canvas->SetFixedAspectRatio(true);
00997   canvas->Write();
00998 }
00999 
01000 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH2F* hist1, TH2F* hist2, TH2F* hist3) {
01001   canvas->Divide(1,2);
01002   canvas->cd(1)->Divide(2,1);
01003   // EEM
01004   canvas->cd(1)->cd(1);
01005   hist1->Draw("colz");
01006   drawEELines();  
01007   // EB
01008   canvas->cd(2);
01009   hist2->Draw("colz");
01010   hist2->GetXaxis()->SetNdivisions(-18);
01011   hist2->GetYaxis()->SetNdivisions(2);
01012   canvas->GetPad(2)->SetGridx(1);
01013   canvas->GetPad(2)->SetGridy(1);
01014   // EEP
01015   canvas->cd(1)->cd(2);
01016   hist3->Draw("colz");
01017   drawEELines();  
01018   histoCanvasNamesVector->push_back(canvas->GetName());
01019   canvas->SetCanvasSize(500,500);
01020   canvas->SetFixedAspectRatio(true);
01021   canvas->Write();
01022 }
01023 
01024 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH3F* hist1, TH3F* hist2, TH3F* hist3) {
01025    if(canvas == timingMapCoarseCanvas_) {
01026       canvas->cd();
01027       TProfile2D* profile2 = (TProfile2D*) hist2->Project3DProfile("yx");
01028       profile2->Draw("colz");
01029       drawTimingErrors(profile2);
01030    }
01031    else {
01032       canvas->Divide(1,2);
01033       canvas->cd(1)->Divide(2,1);
01034       // EEM
01035       canvas->cd(1)->cd(1);
01036       TProfile2D* profile1 = (TProfile2D*) hist1->Project3DProfile("yx");
01037       profile1->Draw("colz");
01038       drawEELines();  
01039       // EB
01040       canvas->cd(2);
01041       TProfile2D* profile2 = (TProfile2D*) hist2->Project3DProfile("yx");
01042       profile2->Draw("colz");
01043       profile2->GetXaxis()->SetNdivisions(-18);
01044       profile2->GetYaxis()->SetNdivisions(2);
01045       canvas->GetPad(2)->SetGridx(1);
01046       canvas->GetPad(2)->SetGridy(1);
01047       // EEP
01048       canvas->cd(1)->cd(2);
01049       TProfile2D* profile3 = (TProfile2D*) hist3->Project3DProfile("yx");
01050       profile3->Draw("colz");
01051       drawEELines();  
01052    }
01053    histoCanvasNamesVector->push_back(canvas->GetName());
01054    canvas->SetCanvasSize(500,500);
01055    canvas->SetFixedAspectRatio(true);
01056    canvas->Write();
01057 }
01058 
01059 void EcalDisplaysByEvent::drawTimingErrors(TProfile2D* profile) {
01060    int nxb = profile->GetNbinsX();
01061    int nyb = profile->GetNbinsY();
01062    char tempErr[200];
01063    for(int i=0;i!=nxb;++i) {
01064       for(int j=0;j!=nyb;++j) {
01065          int xb = i+1;
01066          int yb = j+1;
01067 //   std::cout << "xb: " << xb << "\tyb: " << yb << std::endl;
01068          double xcorr = profile->GetBinCenter(xb);
01069          double ycorr = profile->GetBinCenter(yb);
01070          sprintf(tempErr,"%0.2f",profile->GetBinError(xb,yb));
01071          int nBin = profile->GetBin(xb,yb,0);
01072          int nBinEntries = (int) profile->GetBinEntries(nBin);
01073          if(nBinEntries != 0) {
01074             TLatex* tex = new TLatex(xcorr,ycorr,tempErr);
01075             tex->SetTextAlign(23);
01076             tex->SetTextSize(42);
01077             tex->SetTextSize(0.025);
01078             tex->SetLineWidth(2);
01079             tex->Draw();
01080             delete tex;
01081          }
01082          sprintf(tempErr,"%i",nBinEntries);
01083          if(nBinEntries!=0) {
01084             TLatex* tex = new TLatex(xcorr,ycorr,tempErr);
01085             tex->SetTextAlign(21);
01086             tex->SetTextFont(42);
01087             tex->SetTextSize(0.025);
01088             tex->SetLineWidth(2);
01089             tex->Draw();
01090             delete tex;
01091          }
01092       }
01093    }
01094 }
01095 
01096 void EcalDisplaysByEvent::drawEELines() {
01097 
01098   int ixSectorsEE[202] = {61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 55, 55, 45, 45, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 45, 45, 55, 55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 0,100,100, 97, 97, 95, 95, 92, 92, 87, 87, 85, 85, 80, 80, 75, 75, 65, 65, 60, 60, 40, 40, 35, 35, 25, 25, 20, 20, 15, 15, 13, 13,  8,  8,  5,  5,  3,  3,  0,  0,  3,  3,  5,  5,  8,  8, 13, 13, 15, 15, 20, 20, 25, 25, 35, 35, 40, 40, 60, 60, 65, 65, 75, 75, 80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97,100,100,  0, 61, 65, 65, 70, 70, 80, 80, 90, 90, 92,  0, 61, 65, 65, 90, 90, 97,  0, 57, 60, 60, 65, 65, 70, 70, 75, 75, 80, 80,  0, 50, 50,  0, 43, 40, 40, 35, 35, 30, 30, 25, 25, 20, 20,  0, 39, 35, 35, 10, 10,  3,  0, 39, 35, 35, 30, 30, 20, 20, 10, 10,  8,  0, 45, 45, 40, 40, 35, 35,  0, 55, 55, 60, 60, 65, 65};
01099  
01100   int iySectorsEE[202] = {50, 55, 55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 55, 55, 45, 45, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 45, 45, 50,  0, 50, 60, 60, 65, 65, 75, 75, 80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97,100,100, 97, 97, 95, 95, 92, 92, 87, 87, 85, 85, 80, 80, 75, 75, 65, 65, 60, 60, 40, 40, 35, 35, 25, 25, 20, 20, 15, 15, 13, 13,  8,  8,  5,  5,  3,  3,  0,  0,  3,  3,  5,  5,  8,  8, 13, 13, 15, 15, 20, 20, 25, 25, 35, 35, 40, 40, 50,  0, 45, 45, 40, 40, 35, 35, 30, 30, 25, 25,  0, 50, 50, 55, 55, 60, 60,  0, 60, 60, 65, 65, 70, 70, 75, 75, 85, 85, 87,  0, 61,100,  0, 60, 60, 65, 65, 70, 70, 75, 75, 85, 85, 87,  0, 50, 50, 55, 55, 60, 60,  0, 45, 45, 40, 40, 35, 35, 30, 30, 25, 25,  0, 39, 30, 30, 15, 15,  5,  0, 39, 30, 30, 15, 15,  5};
01101 
01102 
01103  for ( int i=0; i<202; i++) {
01104    ixSectorsEE[i] += 1;
01105    iySectorsEE[i] += 1;
01106 //   std::cout << i << " " << ixSectorsEE[i] << " " << iySectorsEE[i] << std::endl;
01107  }
01108 
01109  TLine l;
01110  l.SetLineWidth(1);
01111  for ( int i=0; i<201; i=i+1) {
01112    if ( (ixSectorsEE[i]!=1 || iySectorsEE[i]!=1) && 
01113         (ixSectorsEE[i+1]!=1 || iySectorsEE[i+1]!=1) ) {
01114      l.DrawLine(ixSectorsEE[i], iySectorsEE[i], 
01115                 ixSectorsEE[i+1], iySectorsEE[i+1]);
01116    }
01117  }
01118 
01119 
01120 }