CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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.6 2011/10/10 09:05:21 eulisse 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       size_t FEDid = 600+elecId.dccId();
00417       bool isEEM = false;
00418       if(FEDid < 610)
00419         isEEM = true;
00420       EEDetId digiId = digiItr->id();
00421       int ieta = digiId.iy();
00422       int iphi = digiId.ix();
00423       if(isEEM)
00424       {
00425          digiOccupancyEEMAll_->Fill(iphi,ieta);
00426          digiOccupancyEEMcoarseAll_->Fill(iphi,ieta);
00427          if(makeOccupancyHistos_)
00428          {
00429            digiOccupancyEEMcoarse_->Fill(iphi,ieta);
00430            digiOccupancyEEM_->Fill(iphi,ieta);
00431          }
00432       }
00433       else
00434       {
00435          digiOccupancyEEPAll_->Fill(iphi,ieta);
00436          digiOccupancyEEPcoarseAll_->Fill(iphi,ieta);
00437          if(makeOccupancyHistos_)
00438          {
00439            digiOccupancyEEP_->Fill(iphi,ieta);
00440            digiOccupancyEEPcoarse_->Fill(iphi,ieta);
00441          }
00442       }  
00443    }
00444 }
00445 
00446 void EcalDisplaysByEvent::makeHistos(Handle<EcalRecHitCollection> hits)
00447 {
00448   for (EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr)
00449   {
00450     EcalRecHit hit = (*hitItr);
00451     DetId det = hit.id();
00452     EcalElectronicsId elecId = ecalElectronicsMap_->getElectronicsId(det);
00453     int FEDid = 600+elecId.dccId();
00454     bool isBarrel = true;
00455     bool isEEM = false;
00456     if(FEDid < 610 || FEDid > 645)
00457     {
00458       isBarrel = false;
00459       if(FEDid < 610)
00460         isEEM = true;
00461     }
00462     int iphi = isBarrel ? ((EBDetId)det).iphi() : ((EEDetId)det).ix();
00463     int ieta = isBarrel ? ((EBDetId)det).ieta() : ((EEDetId)det).iy();
00464     float energy = hit.energy();
00465     float time = hit.time();
00466     
00467     // Fill energy histos
00468     if(makeEnergyHistos_)
00469     {
00470       if(isBarrel)
00471       {
00472         energyEB_->Fill(energy);
00473         energyMapEB_->Fill(iphi,ieta,energy);
00474         energyMapEBcoarse_->Fill(iphi,ieta,energy);
00475       }
00476       else if(isEEM)
00477       {
00478         energyEEM_->Fill(energy);
00479         energyMapEEM_->Fill(iphi,ieta,energy);
00480         energyMapEEMcoarse_->Fill(iphi,ieta,energy);
00481       }
00482       else
00483       {
00484         energyEEP_->Fill(energy);
00485         energyMapEEP_->Fill(iphi,ieta,energy);
00486         energyMapEEPcoarse_->Fill(iphi,ieta,energy);
00487       }
00488     }
00489     // Fill occupancy histos
00490     if(makeOccupancyHistos_)
00491     {
00492       if(isBarrel)
00493       {
00494         recHitOccupancyEB_->Fill(iphi,ieta);
00495         recHitOccupancyEBcoarse_->Fill(iphi,ieta);
00496       }
00497       else if(isEEM)
00498       {
00499          recHitOccupancyEEM_->Fill(iphi,ieta);
00500          recHitOccupancyEEMcoarse_->Fill(iphi,ieta);
00501       }
00502       else
00503       {
00504          recHitOccupancyEEP_->Fill(iphi,ieta);
00505          recHitOccupancyEEPcoarse_->Fill(iphi,ieta);
00506       }
00507     }
00508 
00509     // Fill timing histos
00510     if(makeTimingHistos_)
00511     {
00512       if(isBarrel) {
00513         timingEB_->Fill(time);
00514         if(energy > minTimingEnergyEB_) {
00515            timingMapEB_->Fill(iphi,ieta,time);
00516            //timingMapEBCoarse_->Fill(iphi,ieta,time);
00517         }
00518       }
00519       else if(isEEM) {
00520          timingEEM_->Fill(time);
00521          if(energy > minTimingEnergyEE_)
00522          {
00523             timingMapEEM_->Fill(iphi,ieta,time);
00524             //timingMapEEMCoarse_->Fill(iphi,ieta,time);
00525          }
00526       }
00527       else {
00528          timingEEP_->Fill(time);
00529          if(energy > minTimingEnergyEE_)
00530          {
00531             timingMapEEP_->Fill(iphi,ieta,time);
00532             //timingMapEEPCoarse_->Fill(iphi,ieta,time);
00533          }
00534       }
00535     }
00536 
00537     //All events
00538     if(isBarrel)
00539     {
00540       energyEBAll_->Fill(energy);
00541       energyMapEBAll_->Fill(iphi,ieta,energy);
00542       energyMapEBcoarseAll_->Fill(iphi,ieta,energy);
00543       recHitOccupancyEBAll_->Fill(iphi,ieta);
00544       recHitOccupancyEBcoarseAll_->Fill(iphi,ieta);
00545       timingEBAll_->Fill(time);
00546       if(energy > minTimingEnergyEB_)
00547       {
00548         timingMapEBAll_->Fill(iphi,ieta,time);
00549         timingMapEBCoarseAll_->Fill(iphi,ieta,time);
00550       }
00551     }
00552     else if(isEEM)
00553     {
00554       energyEEMAll_->Fill(energy);
00555       energyMapEEMAll_->Fill(iphi,ieta,energy);
00556       energyMapEEMcoarseAll_->Fill(iphi,ieta,energy);
00557       recHitOccupancyEEMAll_->Fill(iphi,ieta);
00558       recHitOccupancyEEMcoarseAll_->Fill(iphi,ieta);
00559       timingEEMAll_->Fill(time);
00560       if(energy > minTimingEnergyEE_)
00561       {
00562         timingMapEEMAll_->Fill(iphi,ieta,time);
00563         timingMapEEMCoarseAll_->Fill(iphi,ieta,time);
00564       }
00565     }
00566     else
00567     {
00568       energyEEPAll_->Fill(energy);
00569       energyMapEEPAll_->Fill(iphi,ieta,energy);
00570       energyMapEEPcoarseAll_->Fill(iphi,ieta,energy);
00571       recHitOccupancyEEPAll_->Fill(iphi,ieta);
00572       recHitOccupancyEEPcoarseAll_->Fill(iphi,ieta);
00573       timingEEPAll_->Fill(time);
00574       if(energy > minTimingEnergyEE_)
00575       {
00576         timingMapEEPAll_->Fill(iphi,ieta,time);
00577         timingMapEEPCoarseAll_->Fill(iphi,ieta,time);
00578       }
00579     }
00580     // Fill FED-by-FED timing histos (all events)
00581     TH1F* timingHist = FEDsAndTimingHists_[FEDid];
00582     if(timingHist==0)
00583     {
00584       initHists(FEDid);
00585       timingHist = FEDsAndTimingHists_[FEDid];
00586     }
00587     if(energy > minTimingAmp_)
00588     {
00589       timingHist->Fill(hit.time());
00590       allFedsTimingHist_->Fill(hit.time());
00591     }
00592   }
00593 }
00594 
00595 // ------------ method called once each job just after ending the event loop  ------------
00596 void 
00597 EcalDisplaysByEvent::endJob()
00598 {
00599   //All-event canvases
00600   drawCanvas(timingCanvasAll_,timingEEMAll_,timingEBAll_,timingEEPAll_);
00601   drawCanvas(timingMapCanvasAll_,timingMapEEMAll_,timingMapEBAll_,timingMapEEPAll_);
00602   drawCanvas(energyCanvasAll_,energyEEMAll_,energyEBAll_,energyEEPAll_);
00603   drawCanvas(energyMapCanvasAll_,energyMapEEMAll_,energyMapEBAll_,energyMapEEPAll_);
00604   drawCanvas(energyMapCoarseCanvasAll_,energyMapEEMcoarseAll_,energyMapEBcoarseAll_,energyMapEEPcoarseAll_);
00605   drawCanvas(recHitOccupancyCanvasAll_,recHitOccupancyEEMAll_,recHitOccupancyEBAll_,recHitOccupancyEEPAll_);
00606   drawCanvas(recHitOccupancyCoarseCanvasAll_,recHitOccupancyEEMcoarseAll_,recHitOccupancyEBcoarseAll_,recHitOccupancyEEPcoarseAll_);
00607   drawCanvas(digiOccupancyCanvasAll_,digiOccupancyEEMAll_,digiOccupancyEBAll_,digiOccupancyEEPAll_);
00608   drawCanvas(digiOccupancyCoarseCanvasAll_,digiOccupancyEEMcoarseAll_,digiOccupancyEBcoarseAll_,digiOccupancyEEPcoarseAll_);
00609 
00610   if(runNum_ != -1) {
00611     canvasNames_->Fill();
00612     histoCanvasNames_->Fill();
00613   }
00614 
00615   string frequencies = "";
00616   for(std::map<std::string,int>::const_iterator itr = seedFrequencyMap_.begin();
00617       itr != seedFrequencyMap_.end(); ++itr)
00618   {
00619     if(itr->second > 1)
00620     {
00621       frequencies+=itr->first;
00622       frequencies+=" Frequency: ";
00623       frequencies+=intToString(itr->second);
00624       frequencies+="\n";
00625     }
00626   }
00627   LogWarning("EcalDisplaysByEvent") << "Found seeds with frequency > 1: " << "\n\n" << frequencies;
00628   
00629   std::string channels;
00630   for(std::vector<int>::const_iterator itr = maskedChannels_.begin();
00631       itr != maskedChannels_.end(); ++itr)
00632   {
00633     channels+=intToString(*itr);
00634     channels+=",";
00635   }
00636   
00637   std::string feds;
00638   for(std::vector<int>::const_iterator itr = maskedFEDs_.begin();
00639       itr != maskedFEDs_.end(); ++itr)
00640   {
00641     feds+=intToString(*itr);
00642     feds+=",";
00643   }
00644 
00645   LogWarning("EcalDisplaysByEvent") << "Masked channels are: " << channels;
00646   LogWarning("EcalDisplaysByEvent") << "Masked FEDs are: " << feds << " and that is all!";
00647 }
00648 
00649 std::string EcalDisplaysByEvent::intToString(int num)
00650 {
00651     using namespace std;
00652     ostringstream myStream;
00653     myStream << num << flush;
00654     return(myStream.str()); //returns the string form of the stringstream object
00655 }
00656 
00657 std::string EcalDisplaysByEvent::floatToString(float num)
00658 {
00659     using namespace std;
00660     ostringstream myStream;
00661     myStream << num << flush;
00662     return(myStream.str()); //returns the string form of the stringstream object
00663 }
00664 
00665 // insert the hist map into the map keyed by FED number
00666 void EcalDisplaysByEvent::initHists(int FED)
00667 {
00668   using namespace std;
00669   
00670   string title1 = "Jitter for ";
00671   title1.append(fedMap_->getSliceFromFed(FED));
00672   string name1 = "JitterFED";
00673   name1.append(intToString(FED));
00674   TH1F* timingHist = fileService->make<TH1F>(name1.c_str(),title1.c_str(),150,-7,7);
00675   FEDsAndTimingHists_[FED] = timingHist;
00676 }
00677 
00678 void EcalDisplaysByEvent::initEvtByEvtHists(int naiveEvtNum_, int ievt)
00679 {
00680   string lastPart = intToString(naiveEvtNum_)+"_LV1a"+intToString(ievt);
00681   if(makeTimingHistos_)
00682   {
00683     string canvasTitle = "Timing_Event"+lastPart;
00684     timingEB_ = new TH1F("timeForAllFedsEB","timeForAllFeds;Relative Time (1 clock = 25ns)",78,-7,7);
00685     timingEEM_ = new TH1F("timeForAllFedsEEM","timeForAllFeds_EEM;Relative Time (1 clock = 25ns)",78,-7,7);
00686     timingEEP_ = new TH1F("timeForAllFedsEEP","timeForAllFeds_EEP;Relative Time (1 clock = 25ns)",78,-7,7);
00687     timingCanvas_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00688     timingMapEB_ = init3DEcalHist("TimingMap", EB_FINE);
00689     timingMapEEM_ = init3DEcalHist("TimingMap", EEM_FINE);
00690     timingMapEEP_ = init3DEcalHist("TimingMap", EEP_FINE);
00691     timingMapCanvas_ = init2DEcalCanvas("TimingMap_Event"+lastPart);
00692     //timingMapEBCoarse_ = init3DEcalHist("TimingMap", EB_COARSE);
00693     timingMapEEMCoarse_ = init3DEcalHist("TimingMap", EEM_COARSE);
00694     timingMapEEPCoarse_ = init3DEcalHist("TimingMap", EEP_COARSE);
00695     //timingMapCoarseCanvas_ = init2DEcalCanvas("TimingMapCoarse_Event"+lastPart);  
00696   }
00697   if(makeEnergyHistos_)
00698   {
00699     energyEB_ = new TH1F("energyEB","Energy for EB Feds (GeV)",200,histRangeMin_,histRangeMax_);
00700     energyEEM_ = new TH1F("energyEEM","Energy for EEM Feds (GeV)",200,histRangeMin_,10.0);
00701     energyEEP_ = new TH1F("energyEEP","Energy for EEP Feds (GeV)",200,histRangeMin_,10.0);
00702     string canvasTitle = "Energy_Event"+lastPart;
00703     energyCanvas_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00704 
00705     // Energy map hists
00706     energyMapEB_            = init2DEcalHist("EnergyMap",EB_FINE);
00707     energyMapEBcoarse_      = init2DEcalHist("EnergyMap",EB_COARSE);
00708     energyMapEEMcoarse_           = init2DEcalHist("EnergyMap",EEM_COARSE);
00709     energyMapEEM_                 = init2DEcalHist("EnergyMap",EEM_FINE);
00710     energyMapEEPcoarse_           = init2DEcalHist("EnergyMap",EEP_COARSE);
00711     energyMapEEP_                 = init2DEcalHist("EnergyMap",EEP_FINE);
00712     energyMapCanvas_ = init2DEcalCanvas("EnergyMap_Event"+lastPart);
00713     energyMapCoarseCanvas_ = init2DEcalCanvas("EnergyMapCoarse_Event"+lastPart);
00714   }
00715   if(makeOccupancyHistos_) 
00716   {
00717      // RecHit Occupancy
00718     recHitOccupancyEB_ = init2DEcalHist("RecHitOccupancy",EB_FINE);
00719     recHitOccupancyEBcoarse_ = init2DEcalHist("RecHitOccupancy",EB_COARSE);
00720     recHitOccupancyEEMcoarse_ = init2DEcalHist("RecHitOccupancy",EEM_COARSE);
00721     recHitOccupancyEEM_ = init2DEcalHist("RecHitOccupancy",EEM_FINE);
00722     recHitOccupancyEEPcoarse_ = init2DEcalHist("RecHitOccupancy",EEP_COARSE);
00723     recHitOccupancyEEP_ = init2DEcalHist("RecHitOccupancy",EEP_FINE);
00724     recHitOccupancyCanvas_ = init2DEcalCanvas("RecHitOccupancy_Event"+lastPart);
00725     recHitOccupancyCoarseCanvas_ =init2DEcalCanvas("RecHitOccupancyCoarse_Event"+lastPart);
00726 
00727     //DigiOccupancy
00728     digiOccupancyEB_ = init2DEcalHist("DigiOccupancy",EB_FINE);
00729     digiOccupancyEBcoarse_ = init2DEcalHist("DigiOccupancy", EB_COARSE);
00730     digiOccupancyEEMcoarse_ = init2DEcalHist("DigiOccupancy",EEM_COARSE);
00731     digiOccupancyEEM_ = init2DEcalHist("DigiOccupancy",EEM_FINE);
00732     digiOccupancyEEPcoarse_ = init2DEcalHist("DigiOccupancy",EEP_COARSE);
00733     digiOccupancyEEP_ = init2DEcalHist("DigiOccupancy",EEP_FINE);
00734     digiOccupancyCanvas_ = init2DEcalCanvas("DigiOccupancy_Event"+lastPart);
00735     digiOccupancyCoarseCanvas_ = init2DEcalCanvas("DigiOccupancyCoarse_Event"+lastPart);
00736   }
00737 }
00738 
00739 void EcalDisplaysByEvent::deleteEvtByEvtHists()
00740 {
00741     delete timingEB_;
00742     delete timingEEM_;
00743     delete timingEEP_;
00744     delete timingMapEB_;
00745     delete timingMapEEM_;
00746     delete timingMapEEP_;
00747     delete timingCanvas_;
00748     delete timingMapCanvas_;
00749     delete energyEB_;
00750     delete energyEEM_;
00751     delete energyEEP_;
00752     delete energyMapEB_;
00753     delete energyMapEEM_;
00754     delete energyMapEEP_;
00755     delete energyMapEBcoarse_;
00756     delete energyMapEEMcoarse_;
00757     delete energyMapEEPcoarse_;
00758     delete energyCanvas_;
00759     delete energyMapCanvas_;
00760     delete energyMapCoarseCanvas_;
00761     delete recHitOccupancyEB_;
00762     delete recHitOccupancyEEP_;
00763     delete recHitOccupancyEEM_;
00764     delete recHitOccupancyEBcoarse_;
00765     delete recHitOccupancyEEMcoarse_;
00766     delete recHitOccupancyEEPcoarse_;
00767     delete digiOccupancyEB_;
00768     delete digiOccupancyEEM_;
00769     delete digiOccupancyEEP_;
00770     delete digiOccupancyEBcoarse_;
00771     delete digiOccupancyEEMcoarse_;
00772     delete digiOccupancyEEPcoarse_;
00773     delete recHitOccupancyCanvas_;
00774     delete recHitOccupancyCoarseCanvas_;
00775     delete digiOccupancyCanvas_;
00776     delete digiOccupancyCoarseCanvas_;
00777 }
00778 
00779 void EcalDisplaysByEvent::initAllEventHistos()
00780 {
00781   string canvasTitle = "Timing_AllEvents";
00782   timingEBAll_ = new TH1F("timeForAllFedsEBAll","timeForAllFeds;Relative Time (1 clock = 25ns)",78,-7,7);
00783   timingEEMAll_ = new TH1F("timeForAllFedsEEMAll","timeForAllFeds_EEM;Relative Time (1 clock = 25ns)",78,-7,7);
00784   timingEEPAll_ = new TH1F("timeForAllFedsEEPAll","timeForAllFeds_EEP;Relative Time (1 clock = 25ns)",78,-7,7);
00785   timingCanvasAll_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00786   timingMapEBAll_ = init3DEcalHist("TimingMapA", EB_FINE);
00787   timingMapEEMAll_ = init3DEcalHist("TimingMapA", EEM_FINE);
00788   timingMapEEPAll_ = init3DEcalHist("TimingMapA", EEP_FINE);
00789   timingMapCanvasAll_ = init2DEcalCanvas("TimingMap_AllEvents");
00790   timingMapEBCoarseAll_ = init3DEcalHist("TimingMapA", EB_COARSE);
00791   timingMapEEMCoarseAll_ = init3DEcalHist("TimingMapA", EEM_COARSE);
00792   timingMapEEPCoarseAll_ = init3DEcalHist("TimingMapA", EEP_COARSE);
00793   //timingMapCoarseCanvasAll_ = init2DEcalCanvas("TimingMapCoarse_AllEvents"); 
00794   energyEBAll_ = new TH1F("energyEBAllEvents","Energy for EB Feds (GeV)",200,histRangeMin_,histRangeMax_);
00795   energyEEMAll_ = new TH1F("energyEEMAllEvents","Energy for EEM Feds (GeV)",200,histRangeMin_,10.0);
00796   energyEEPAll_ = new TH1F("energyEEPAllEvents","Energy for EEP Feds (GeV)",200,histRangeMin_,10.0);
00797   canvasTitle = "Energy_AllEvents";
00798   energyCanvasAll_ = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00799 
00800   // Energy map hists
00801   energyMapEBAll_            = init2DEcalHist("EnergyMapA",EB_FINE);
00802   energyMapEBcoarseAll_      = init2DEcalHist("EnergyMapA",EB_COARSE);
00803   energyMapEEMcoarseAll_           = init2DEcalHist("EnergyMapA",EEM_COARSE);
00804   energyMapEEMAll_                 = init2DEcalHist("EnergyMapA",EEM_FINE);
00805   energyMapEEPcoarseAll_           = init2DEcalHist("EnergyMapA",EEP_COARSE);
00806   energyMapEEPAll_                 = init2DEcalHist("EnergyMapA",EEP_FINE);
00807   energyMapCanvasAll_ = init2DEcalCanvas("EnergyMap_AllEvents");
00808   energyMapCoarseCanvasAll_ = init2DEcalCanvas("EnergyMapCoarse_AllEvents");
00809   // RecHit Occupancy
00810   recHitOccupancyEBAll_ = init2DEcalHist("RecHitOccupancyA",EB_FINE);
00811   recHitOccupancyEBcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EB_COARSE);
00812   recHitOccupancyEEMcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EEM_COARSE);
00813   recHitOccupancyEEMAll_ = init2DEcalHist("RecHitOccupancyA",EEM_FINE);
00814   recHitOccupancyEEPcoarseAll_ = init2DEcalHist("RecHitOccupancyA",EEP_COARSE);
00815   recHitOccupancyEEPAll_ = init2DEcalHist("RecHitOccupancyA",EEP_FINE);
00816   recHitOccupancyCanvasAll_ = init2DEcalCanvas("RecHitOccupancy_AllEvents");
00817   recHitOccupancyCoarseCanvasAll_ =init2DEcalCanvas("RecHitOccupancyCoarse_AllEvents");
00818 
00819   //DigiOccupancy
00820   digiOccupancyEBAll_ = init2DEcalHist("DigiOccupancyA",EB_FINE);
00821   digiOccupancyEBcoarseAll_ = init2DEcalHist("DigiOccupancyA", EB_COARSE);
00822   digiOccupancyEEMcoarseAll_ = init2DEcalHist("DigiOccupancyA",EEM_COARSE);
00823   digiOccupancyEEMAll_ = init2DEcalHist("DigiOccupancyA",EEM_FINE);
00824   digiOccupancyEEPcoarseAll_ = init2DEcalHist("DigiOccupancyA",EEP_COARSE);
00825   digiOccupancyEEPAll_ = init2DEcalHist("DigiOccupancyA",EEP_FINE);
00826   digiOccupancyCanvasAll_ = init2DEcalCanvas("DigiOccupancy_AllEvents");
00827   digiOccupancyCoarseCanvasAll_ = init2DEcalCanvas("DigiOccupancyCoarse_AllEvents");
00828 
00829 }
00830 
00831 
00832 TH3F* EcalDisplaysByEvent::init3DEcalHist(std::string histTypeName, int subDet) {
00833    TH3F* hist;
00834    bool isBarrel = (subDet == EB_FINE || subDet == EB_COARSE) ? true : false;
00835    bool isCoarse = (subDet == EB_COARSE || subDet == EEM_COARSE || subDet == EEP_COARSE) ? true : false; 
00836    bool isEEM = (subDet == EEM_FINE || subDet == EEM_COARSE) ? true : false;
00837    std::string histName = histTypeName;
00838    std::string histTitle = histTypeName;
00839    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 };
00840    double modEtaBins[10]={-85, -65, -45, -25, 0, 1, 26, 46, 66, 86};
00841    double ttPhiBins[73];
00842    double modPhiBins[19];
00843    double timingBins[79];
00844    for (int i = 0; i < 79; ++i)
00845    {
00846       timingBins[i]= 6 - 7. + double(i) * 14. / 78.;
00847       if (i<73)  
00848       {       
00849          ttPhiBins[i]=1+5*i;
00850          if ( i < 19) 
00851          {       
00852             modPhiBins[i]=1+20*i;
00853          }       
00854       }       
00855 
00856    }
00857 
00858    if(isBarrel) {
00859       histName = histName + "EB";
00860       histTitle = histTitle + " EB";
00861       if(isCoarse) {
00862          histName = histName + "Coarse";
00863          histTitle = histTitle + " by Module Nominal value = 6;iphi;ieta ";
00864          hist = new TH3F(histName.c_str(),histTitle.c_str(),18,modPhiBins,9,modEtaBins,78,timingBins);
00865       }
00866       else {
00867          histTitle = histTitle + " by TT Nominal value = 6;iphi;ieta";
00868          hist = new TH3F(histName.c_str(),histTitle.c_str(),360/5,ttPhiBins,35,ttEtaBins,78,timingBins);
00869       }
00870    }
00871    else {
00872       double ttXBins[21];
00873       double ttYBins[21];
00874       for(int i=0;i!=21;++i) {
00875          ttXBins[i] = 1 + 5*i;
00876          ttYBins[i] = 1 + 5*i;
00877       }
00878       if(isEEM) {
00879          histName = histName + "EEM";
00880          histTitle = histTitle + " EEM";
00881       }
00882       else {
00883          histName = histName + "EEP";
00884          histTitle = histTitle + " EEP";
00885       }
00886       if(isCoarse) {
00887          histName = histName + "Coarse";
00888          histTitle = histTitle + " by Module Nominal value = 6;ix;iy";
00889          hist = new TH3F(histName.c_str(),histTitle.c_str(),20,ttXBins,20,ttYBins,78,timingBins);
00890       }
00891       else {
00892          histTitle = histTitle + " by TT Nominal value = 6;ix;iy";
00893          hist = new TH3F(histName.c_str(),histTitle.c_str(),20,ttXBins,20,ttYBins,78,timingBins);
00894       }
00895    }
00896    return hist;
00897 }
00898 
00899 TH2F* EcalDisplaysByEvent::init2DEcalHist(std::string histTypeName, int subDet) {
00900    TH2F* hist;
00901    bool isBarrel = (subDet == EB_FINE || subDet == EB_COARSE) ? true : false;
00902    bool isCoarse = (subDet == EB_COARSE || subDet == EEM_COARSE || subDet == EEP_COARSE) ? true : false; 
00903    bool isEEM = (subDet == EEM_FINE || subDet == EEM_COARSE) ? true : false;
00904    std::string histName = histTypeName;
00905    std::string histTitle = histTypeName;
00906    if(isBarrel) {
00907       histName = histName + "EB";
00908       histTitle = histTitle + " EB";
00909       if(isCoarse) {
00910          histName = histName + "Coarse";
00911          histTitle = histTitle + " Coarse;iphi;ieta";
00912          double ttEtaBins[36] = {-85, -80, -75, -70, -65, -60, -55, -50, -45, -40, 
00913             -35, -30, -25, -20, -15, -10, -5, 0, 1, 6, 11, 16, 
00914             21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86 };
00915          hist = new TH2F(histName.c_str(),histTitle.c_str(),360/5,1,361.,35,ttEtaBins);
00916       }
00917       else {
00918          histTitle = histTitle + ";iphi;ieta";
00919          hist = new TH2F(histName.c_str(),histTitle.c_str(),360,1,361.,172,-86,86);
00920       }
00921    }
00922    else {
00923       if(isEEM) {
00924          histName = histName + "EEM";
00925          histTitle = histTitle + " EEM";
00926       }
00927       else {
00928          histName = histName + "EEP";
00929          histTitle = histTitle + " EEP";
00930       }
00931       if(isCoarse) {
00932          histName = histName + "Coarse";
00933          histTitle = histTitle + " Coarse;ix;iy";
00934          hist = new TH2F(histName.c_str(),histTitle.c_str(),20,1,101,20,1,101);
00935       }
00936       else {
00937          histTitle = histTitle + ";ix;iy";
00938          hist = new TH2F(histName.c_str(),histTitle.c_str(),100,1,101,100,1,101);
00939       }
00940    }
00941    return hist;
00942 }
00943 
00944 TCanvas* EcalDisplaysByEvent::init2DEcalCanvas(std::string canvasTitle) {
00945     TCanvas* canvas = new TCanvas(canvasTitle.c_str(), canvasTitle.c_str(),300,60,500,200);
00946     return canvas;
00947 }
00948 
00949 void EcalDisplaysByEvent::drawHistos()
00950 {
00951   if(makeTimingHistos_)
00952   {
00953     // Put the timing canvas together
00954     drawCanvas(timingCanvas_,timingEEM_,timingEB_,timingEEP_);
00955     //   drawCanvas(timingMapCoarseCanvas_,timingMapEEMCoarse_,timingMapEBCoarse_,timingMapEEPCoarse_);
00956     drawCanvas(timingMapCanvas_,timingMapEEM_,timingMapEB_,timingMapEEP_);
00957   }
00958   if(makeEnergyHistos_)
00959   {
00960     // Put the energy canvas together
00961     drawCanvas(energyCanvas_,energyEEM_,energyEB_,energyEEP_);
00962     // Put the energy map canvas together
00963     drawCanvas(energyMapCanvas_,energyMapEEM_,energyMapEB_,energyMapEEP_);
00964     drawCanvas(energyMapCoarseCanvas_,energyMapEEMcoarse_,energyMapEBcoarse_,energyMapEEPcoarse_);
00965   }
00966   if(makeOccupancyHistos_)
00967   {
00968     // Put the occupancy canvas together
00969     drawCanvas(recHitOccupancyCanvas_,recHitOccupancyEEM_,recHitOccupancyEB_,recHitOccupancyEEP_);
00970     drawCanvas(recHitOccupancyCoarseCanvas_,recHitOccupancyEEMcoarse_,recHitOccupancyEBcoarse_,recHitOccupancyEEPcoarse_);
00971     // And the same for the digis
00972     drawCanvas(digiOccupancyCanvas_,digiOccupancyEEM_,digiOccupancyEB_,digiOccupancyEEP_);
00973     drawCanvas(digiOccupancyCoarseCanvas_,digiOccupancyEEMcoarse_,digiOccupancyEBcoarse_,digiOccupancyEEPcoarse_);
00974   }
00975 }
00976 
00977 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH1F* hist1, TH1F* hist2, TH1F* hist3) {
00978   canvas->Divide(1,2); 
00979   canvas->cd(1)->Divide(2,1); 
00980   canvas->cd(1)->cd(1);
00981   hist1->Draw();
00982   canvas->cd(2); 
00983   hist2->Draw();
00984   canvas->cd(1)->cd(2);
00985   hist3->Draw(); 
00986   histoCanvasNamesVector->push_back(canvas->GetName());
00987   canvas->SetCanvasSize(500,500);
00988   canvas->SetFixedAspectRatio(true);
00989   canvas->Write();
00990 }
00991 
00992 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH2F* hist1, TH2F* hist2, TH2F* hist3) {
00993   canvas->Divide(1,2);
00994   canvas->cd(1)->Divide(2,1);
00995   // EEM
00996   canvas->cd(1)->cd(1);
00997   hist1->Draw("colz");
00998   drawEELines();  
00999   // EB
01000   canvas->cd(2);
01001   hist2->Draw("colz");
01002   hist2->GetXaxis()->SetNdivisions(-18);
01003   hist2->GetYaxis()->SetNdivisions(2);
01004   canvas->GetPad(2)->SetGridx(1);
01005   canvas->GetPad(2)->SetGridy(1);
01006   // EEP
01007   canvas->cd(1)->cd(2);
01008   hist3->Draw("colz");
01009   drawEELines();  
01010   histoCanvasNamesVector->push_back(canvas->GetName());
01011   canvas->SetCanvasSize(500,500);
01012   canvas->SetFixedAspectRatio(true);
01013   canvas->Write();
01014 }
01015 
01016 void EcalDisplaysByEvent::drawCanvas(TCanvas* canvas, TH3F* hist1, TH3F* hist2, TH3F* hist3) {
01017    if(canvas == timingMapCoarseCanvas_) {
01018       canvas->cd();
01019       TProfile2D* profile2 = (TProfile2D*) hist2->Project3DProfile("yx");
01020       profile2->Draw("colz");
01021       drawTimingErrors(profile2);
01022    }
01023    else {
01024       canvas->Divide(1,2);
01025       canvas->cd(1)->Divide(2,1);
01026       // EEM
01027       canvas->cd(1)->cd(1);
01028       TProfile2D* profile1 = (TProfile2D*) hist1->Project3DProfile("yx");
01029       profile1->Draw("colz");
01030       drawEELines();  
01031       // EB
01032       canvas->cd(2);
01033       TProfile2D* profile2 = (TProfile2D*) hist2->Project3DProfile("yx");
01034       profile2->Draw("colz");
01035       profile2->GetXaxis()->SetNdivisions(-18);
01036       profile2->GetYaxis()->SetNdivisions(2);
01037       canvas->GetPad(2)->SetGridx(1);
01038       canvas->GetPad(2)->SetGridy(1);
01039       // EEP
01040       canvas->cd(1)->cd(2);
01041       TProfile2D* profile3 = (TProfile2D*) hist3->Project3DProfile("yx");
01042       profile3->Draw("colz");
01043       drawEELines();  
01044    }
01045    histoCanvasNamesVector->push_back(canvas->GetName());
01046    canvas->SetCanvasSize(500,500);
01047    canvas->SetFixedAspectRatio(true);
01048    canvas->Write();
01049 }
01050 
01051 void EcalDisplaysByEvent::drawTimingErrors(TProfile2D* profile) {
01052    int nxb = profile->GetNbinsX();
01053    int nyb = profile->GetNbinsY();
01054    char tempErr[200];
01055    for(int i=0;i!=nxb;++i) {
01056       for(int j=0;j!=nyb;++j) {
01057          int xb = i+1;
01058          int yb = j+1;
01059 //   std::cout << "xb: " << xb << "\tyb: " << yb << std::endl;
01060          double xcorr = profile->GetBinCenter(xb);
01061          double ycorr = profile->GetBinCenter(yb);
01062          sprintf(tempErr,"%0.2f",profile->GetBinError(xb,yb));
01063          int nBin = profile->GetBin(xb,yb,0);
01064          int nBinEntries = (int) profile->GetBinEntries(nBin);
01065          if(nBinEntries != 0) {
01066             TLatex* tex = new TLatex(xcorr,ycorr,tempErr);
01067             tex->SetTextAlign(23);
01068             tex->SetTextSize(42);
01069             tex->SetTextSize(0.025);
01070             tex->SetLineWidth(2);
01071             tex->Draw();
01072             delete tex;
01073          }
01074          sprintf(tempErr,"%i",nBinEntries);
01075          if(nBinEntries!=0) {
01076             TLatex* tex = new TLatex(xcorr,ycorr,tempErr);
01077             tex->SetTextAlign(21);
01078             tex->SetTextFont(42);
01079             tex->SetTextSize(0.025);
01080             tex->SetLineWidth(2);
01081             tex->Draw();
01082             delete tex;
01083          }
01084       }
01085    }
01086 }
01087 
01088 void EcalDisplaysByEvent::drawEELines() {
01089 
01090   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};
01091  
01092   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};
01093 
01094 
01095  for ( int i=0; i<202; i++) {
01096    ixSectorsEE[i] += 1;
01097    iySectorsEE[i] += 1;
01098 //   std::cout << i << " " << ixSectorsEE[i] << " " << iySectorsEE[i] << std::endl;
01099  }
01100 
01101  TLine l;
01102  l.SetLineWidth(1);
01103  for ( int i=0; i<201; i=i+1) {
01104    if ( (ixSectorsEE[i]!=1 || iySectorsEE[i]!=1) && 
01105         (ixSectorsEE[i+1]!=1 || iySectorsEE[i+1]!=1) ) {
01106      l.DrawLine(ixSectorsEE[i], iySectorsEE[i], 
01107                 ixSectorsEE[i+1], iySectorsEE[i+1]);
01108    }
01109  }
01110 
01111 
01112 }