Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:16

0001 #include "HcalVisualSelector.h"
0002 #include "HcalElectronicsSelector.h"//k*^
0003 #include "PlotAllDisplay.h"
0004 
0005 class PlotAllAdapter : public HcalVisualSelector::Callbacks {
0006 public:
0007   PlotAllAdapter(PlotAllDisplay* disp, int evtType, int flavType) :
0008     m_disp(disp), m_evtType(evtType), m_flavType(flavType){
0009   }
0010   virtual void plot(const MyHcalDetId& id) {
0011     m_disp->displayOne(id,m_evtType,m_flavType);
0012   }
0013   virtual MyHcalSubdetector getSubdet(int ieta, int depth) {
0014     return m_disp->getSubDetector(ieta,depth);
0015   }
0016 private:
0017   PlotAllDisplay* m_disp;
0018   int m_evtType, m_flavType;
0019 };
0020 
0021 
0022 class PlotAllElecAdapter : public HcalElectronicsSelector::Callbacks {
0023  public:
0024    PlotAllElecAdapter(PlotAllDisplay* disp, int evtType, int flavType) :
0025      m_disp(disp), m_evtType(evtType), m_flavType(flavType){
0026    }
0027    virtual void plot(const MyElectronicsId& id) {
0028      m_disp->displayElecOne(id,m_evtType,m_flavType);
0029    }
0030 
0031  private:
0032    PlotAllDisplay* m_disp;
0033    int m_evtType, m_flavType;
0034  };
0035 
0036 //===========================================================================
0037 
0038 std::vector<MyHcalDetId>
0039 PlotAllDisplay::spatialFilter(int ieta,
0040                   int iphi,
0041                   const std::vector<MyHcalDetId>& inputs)
0042 {
0043   std::vector<MyHcalDetId> retval;
0044   std::vector<MyHcalDetId>::const_iterator ii;
0045   for (ii=inputs.begin(); ii!=inputs.end(); ii++) {
0046     if (iphi!=0 && ii->iphi!=iphi) continue;
0047     if (ieta!=0 && ii->ieta!=ieta) continue;
0048     retval.push_back(*ii);
0049   }  
0050   return retval;
0051 }
0052 
0053 //===========================================================================
0054 
0055 TH1* PlotAllDisplay::bookMasterHistogram(DisplaySetupStruct& ss,
0056                      const std::string& basename, int lo,
0057                      int hi)
0058 {
0059   char name[120];
0060   TH1* retval=0;
0061   if (ss.iphi!=0) {
0062     sprintf(name,"%s:%s-%s IPHI=%d",
0063         ss.eventTypeStr.c_str(),ss.flavTypeStr.c_str(),
0064         basename.c_str(),ss.iphi);
0065     retval=new TH1F(name,name, hi-lo+1, lo-0.5, hi+0.5);
0066     retval->GetXaxis()->SetTitle("IETA");
0067   } else {
0068     sprintf(name,"%s:%s-%s IETA=%d",
0069         ss.eventTypeStr.c_str(),ss.flavTypeStr.c_str(),
0070         basename.c_str(),ss.ieta);
0071     retval=new TH1F(name,name, hi-lo+1, lo-0.5, hi+0.5);
0072     retval->GetXaxis()->SetTitle("IPHI");
0073   }
0074   retval->SetDirectory(0);
0075   retval->SetStats(0);
0076   return retval;
0077 }
0078 
0079 //===========================================================================
0080 
0081 MyHcalSubdetector PlotAllDisplay::getSubDetector(int ieta, int depth)
0082 {
0083   MyHcalSubdetector retval=HcalEmpty;
0084   int aieta = abs(ieta);
0085 
0086   if(aieta<=16 && depth<=2) retval=HcalBarrel;
0087   if(aieta<=15 && depth==4) retval=HcalOuter;
0088   if( (aieta==16&&depth==3)||(aieta>16&&aieta<29) ) retval=HcalEndcap;
0089   if(aieta>28) retval=HcalForward;
0090 
0091   // NOTE: based on above, HE29 is not plottable!
0092 
0093   if(retval==HcalEmpty) printf("Bad detector coordinates!\n");
0094 
0095   return retval;
0096 }
0097 
0098 //===========================================================================
0099 
0100 void PlotAllDisplay::displaySummary(int ieta, int iphi,
0101                     int evtType, int flavType)
0102 {
0103   HistoManager::EventType et=(HistoManager::EventType)evtType;
0104   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0105   DisplaySetupStruct setup;
0106   setup.ieta=ieta;
0107   setup.iphi=iphi;
0108   setup.eventTypeStr=HistoManager::nameForEvent(et);
0109   setup.flavTypeStr=HistoManager::nameForFlavor(ht);
0110 
0111   std::vector<MyHcalDetId> KeyIds = histKeys.getDetIdsForType(ht,et);
0112   std::vector<MyHcalDetId> ids = spatialFilter(ieta,iphi,KeyIds);
0113 
0114   if (ids.size()==0) {
0115     printf("The iphi or ieta value entered was not found!\n");
0116     printf("Make sure the correct event type is selected and the correct ieta/iphi values are entered.\n");
0117     return;
0118   }
0119 
0120   std::vector<MyHcalDetId>::const_iterator ii;
0121 
0122   std::cout << "Summing channels" << std::flush;
0123 
0124   // Sum of all channels
0125   TH1* sum=0;
0126   for (ii=ids.begin(); ii!=ids.end(); ii++) {
0127     std::cout << '.' << std::flush;
0128     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0129     if (h==0) continue;
0130     if (sum==0) {
0131       sum=(TH1*)h->Clone("All");
0132       sum->SetDirectory(0);
0133       char name[120];
0134       sprintf(name,"All %s:%s",
0135           setup.eventTypeStr.c_str(),setup.flavTypeStr.c_str());
0136       sum->SetTitle(name);
0137     } else sum->Add(h);
0138   }
0139 
0140   TCanvas* c=new TCanvas("All","All",60,60,800,600);
0141   c->cd();
0142   sum->Draw();
0143   sum->Draw("SAMEHIST");
0144 
0145   std::cout << "done." << std::endl;
0146 
0147   if (ht==HistoManager::PULSE) return;
0148 
0149   // profile of an ieta or iphi
0150 
0151   if (iphi!=0 || ieta!=0) {
0152     TH1* meanSummary[5];
0153     TH1* RMSSummary[5];
0154 
0155     std::cout << "Compiling eta/phi profiles";
0156 
0157     int range_lo=100000, range_hi=-100000;
0158     for(ii=ids.begin(); ii!=ids.end(); ii++) {
0159       int ibin=(iphi!=0)?(ii->ieta):(ii->iphi);
0160       if (ibin>range_hi) range_hi=ibin;
0161       if (ibin<range_lo) range_lo=ibin;
0162     }
0163 
0164     meanSummary[0]=bookMasterHistogram(setup,"MEAN",range_lo,range_hi);
0165     RMSSummary[0]=bookMasterHistogram(setup,"RMS",range_lo,range_hi);
0166     for (int j=1; j<5; j++) {
0167       std::cout << '.' << std::flush;
0168       int marker=j+23;
0169       if (j==4) marker=30;
0170 
0171       char aname[120];
0172       sprintf(aname,"Mean_Depth%d",j);
0173       meanSummary[j]=new TH1F(aname,aname,(range_hi-range_lo)+1,
0174                   range_lo-0.5,range_hi+0.5);
0175       meanSummary[j]->SetDirectory(0);
0176       meanSummary[j]->SetMarkerStyle(marker);
0177       meanSummary[j]->SetMarkerColor(j);
0178 
0179       sprintf(aname,"RMS_Depth%d",j);
0180       RMSSummary[j]=new TH1F(aname,aname,(range_hi-range_lo)+1,
0181                  range_lo-0.5,range_hi+0.5);
0182       RMSSummary[j]->SetDirectory(0);
0183       RMSSummary[j]->SetMarkerStyle(marker);
0184       RMSSummary[j]->SetMarkerColor(j);
0185     }
0186 
0187     for(ii=ids.begin(); ii!=ids.end(); ii++) {
0188       std::cout << '.' << std::flush;
0189       TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0190       if (h==0) continue;
0191       double bin=(iphi!=0)?(ii->ieta*1.0):(ii->iphi*1.0);
0192       meanSummary[ii->depth]->Fill(bin, h->GetMean());
0193       RMSSummary[ii->depth]->Fill(bin, h->GetRMS());
0194     }
0195 
0196     double ml=1e16,mh=-1e16;
0197     for (int j=1; j<5; j++) {
0198       std::cout << '.' << std::flush;
0199       for (int jj=1; jj<=meanSummary[j]->GetNbinsX(); jj++)
0200     if (meanSummary[j]->GetBinError(jj)==0.0)
0201       meanSummary[j]->SetBinContent(jj,-1e6);
0202     else {
0203       if (meanSummary[j]->GetBinContent(jj)<ml)
0204         ml=meanSummary[j]->GetBinContent(jj);
0205       if (meanSummary[j]->GetBinContent(jj)>mh)
0206         mh=meanSummary[j]->GetBinContent(jj);
0207     }
0208     }
0209     meanSummary[0]->SetMaximum(mh+(mh-ml)*0.05);
0210     meanSummary[0]->SetMinimum(ml-(mh-ml)*0.05);
0211 
0212     ml=1e16,mh=-1e16;
0213     for (int j=1; j<5; j++) {
0214       std::cout << '.' << std::flush;
0215       for (int jj=1; jj<=RMSSummary[j]->GetNbinsX(); jj++)
0216     if (RMSSummary[j]->GetBinError(jj)==0.0)
0217       RMSSummary[j]->SetBinContent(jj,-1e6);
0218     else {
0219       if (RMSSummary[j]->GetBinContent(jj)<ml)
0220         ml=RMSSummary[j]->GetBinContent(jj);
0221       if (RMSSummary[j]->GetBinContent(jj)>mh)
0222         mh=RMSSummary[j]->GetBinContent(jj);
0223     }
0224     }
0225     RMSSummary[0]->SetMaximum(mh+(mh-ml)*0.05);
0226     RMSSummary[0]->SetMinimum(ml-(mh-ml)*0.05);
0227 
0228 
0229     TCanvas* myplot=new TCanvas(setup.eventTypeStr.c_str(),
0230                 setup.eventTypeStr.c_str(),
0231                 20,20,800,600);
0232     myplot->Divide(1,2);
0233 
0234     myplot->cd(1);
0235     meanSummary[0]->Draw("P");
0236     for (int j=1; j<5; j++)
0237       meanSummary[j]->Draw("SAMEP");
0238     myplot->cd(2);
0239     RMSSummary[0]->Draw("P");
0240     for (int j=1; j<5; j++)
0241       RMSSummary[j]->Draw("SAMEP");
0242 
0243     std::cout << "done." << std::endl;
0244   }
0245   
0246   // global distributions
0247   
0248   {
0249     std::cout << "Compiling global distributions" << std::flush;
0250 
0251     double mean_lo=1e160, mean_hi=-1e160;
0252     double RMS_lo=1e160, RMS_hi=-1e160;
0253     for (ii=ids.begin(); ii!=ids.end(); ii++) {
0254       std::cout << '.' << std::flush;
0255       TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0256       if (h==0) continue;
0257       double mean=h->GetMean();
0258       double RMS=h->GetRMS();
0259       if (mean<mean_lo) mean_lo=mean;
0260       if (mean>mean_hi) mean_hi=mean;
0261       if (RMS<RMS_lo) RMS_lo=RMS;
0262       if (RMS>RMS_hi) RMS_hi=RMS;
0263     }
0264 
0265     //adjust range to include endpoints
0266     mean_lo = mean_lo - 0.05*(mean_hi-mean_lo);
0267     mean_hi = mean_hi + 0.05*(mean_hi-mean_lo);
0268     RMS_lo = RMS_lo - 0.05*(RMS_hi-RMS_lo);
0269     RMS_hi = RMS_hi + 0.05*(RMS_hi-RMS_lo);
0270 
0271     TH1* means=new TH1F("MEANS","MEANS",50,mean_lo,mean_hi);
0272     means->SetDirectory(0);
0273 
0274     TH1* RMSs=new TH1F("RMSs","RMSs",50,RMS_lo,RMS_hi);
0275     RMSs->SetDirectory(0);
0276 
0277     for (ii=ids.begin(); ii!=ids.end(); ii++) {
0278       std::cout << '.' << std::flush;
0279       TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0280       if (h==0) continue;
0281       means->Fill(h->GetMean());
0282       RMSs->Fill(h->GetRMS());
0283     } 
0284     
0285     TCanvas * myplot = new TCanvas("Statistics","Statistics",
0286                    40,40,800,600);
0287     
0288     myplot->Divide(1,2);
0289     
0290     myplot->cd(1);
0291     means->Draw();
0292     myplot->cd(2);
0293     RMSs->Draw();
0294 
0295     std::cout << "done." << std::endl;
0296   }
0297 }
0298 
0299 //===========================================================================
0300 
0301 void PlotAllDisplay::displayOne(int ieta, int iphi, int depth,
0302                 int evtType, int flavType)
0303 {
0304   MyHcalSubdetector subDet = getSubDetector(ieta,depth);
0305 
0306   if (subDet != HcalEmpty) {
0307     MyHcalDetId id = {subDet,ieta,iphi,depth};
0308     displayOne(id,evtType,flavType);
0309   }
0310 }
0311 
0312 //===========================================================================
0313 
0314 void PlotAllDisplay::displayOne(const MyHcalDetId& id,
0315                 int evtType, int flavType)
0316 {
0317   HistoManager::EventType et=(HistoManager::EventType)evtType;
0318   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0319 
0320   TH1* h=histKeys.GetAHistogram(id,ht,et);
0321   
0322   if (h==0) {
0323     printf("The ieta and/or iphi values were not found!\n");
0324     printf("Make sure the correct event type is selected and the correct iphi/ieta values are entered.\n");
0325     return;
0326   }
0327 
0328   if (m_movie==0) {
0329     m_movie=new TCanvas("Selected","Selected",50,50,800,600);
0330     m_movie->Divide(3,2);
0331   }
0332 
0333   n_movie=(n_movie%6)+1;
0334   m_movie->cd(n_movie);
0335 
0336   if (ht==HistoManager::PULSE) 
0337     h->Draw("HIST");
0338   else 
0339     h->Draw();
0340   m_movie->Flush();
0341   m_movie->Update();
0342   m_movie->Paint();
0343 }
0344 
0345 //===========================================================================
0346 
0347 void PlotAllDisplay::displaySelector(int evtType, int flavType,
0348                      int plotStatType)
0349 {
0350   HistoManager::EventType et=(HistoManager::EventType)evtType;
0351   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0352 
0353   std::vector<MyHcalDetId> KeyIds = histKeys.getDetIdsForType(ht,et);
0354 
0355   if (KeyIds.empty()) {
0356     printf("No histograms found for specified event type and flavor type\n");
0357     return;
0358   }
0359 
0360   int ieta_lo=10000;
0361   int ieta_hi=-10000;
0362   int iphi_lo=10000;
0363   int iphi_hi=-10000;
0364   for(std::vector<MyHcalDetId>::iterator jj=KeyIds.begin();
0365       jj!=KeyIds.end();
0366       jj++) {
0367     if( jj->ieta>ieta_hi ) ieta_hi=jj->ieta;
0368     if( jj->ieta<ieta_lo ) ieta_lo=jj->ieta;
0369     if( jj->iphi>iphi_hi ) iphi_hi=jj->iphi;
0370     if( jj->iphi<iphi_lo ) iphi_lo=jj->iphi;
0371   }
0372 
0373   //  printf("eta_lo=%d eta_hi=%d phi_lo=%d phi_hi=%d\n",
0374   //          ieta_lo,ieta_hi,iphi_lo,iphi_hi);
0375 
0376   HcalVisualSelector* vs=
0377     new HcalVisualSelector(new PlotAllAdapter(this,evtType,flavType),
0378                            ieta_lo,ieta_hi,iphi_lo,iphi_hi);
0379 
0380   for (std::vector<MyHcalDetId>::iterator ii=KeyIds.begin();
0381        ii!=KeyIds.end(); 
0382        ii++) {
0383     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0384     if (h==0) {
0385       printf("ieta=%d, iphi=%d not found\n", ii->ieta, ii->iphi);
0386       continue;
0387     }
0388     if (!plotStatType)
0389       vs->fill(*ii,h->GetMean());
0390     else
0391       vs->fill(*ii,h->GetRMS());
0392   }
0393 
0394   vs->Update();
0395 }
0396 
0397 
0398 
0399 std::vector<MyElectronicsId> PlotAllDisplay::electronicsFilter(int fiber,int fiberChan,int crate,int Slot,int tb,
0400                   const std::vector<MyElectronicsId>& inputs)
0401 {
0402   std::vector<MyElectronicsId> retval;
0403   std::vector<MyElectronicsId>::const_iterator ii;
0404   for (ii=inputs.begin(); ii!=inputs.end(); ii++) {
0405     if ((fiber!=-1 && ii->fiber!=fiber)&&(fiberChan!=-1 && ii->fiberChan!=fiberChan)) continue;
0406     if (crate!=-1 && ii->crate!=crate) continue;
0407     if (Slot!=-1 && ii->Slot!=Slot) continue;
0408     if(tb!=-1 && ii->tb!=tb) continue;
0409     retval.push_back(*ii);
0410   }  
0411   return retval;
0412 }
0413 
0414 
0415 TH1* PlotAllDisplay::bookMasterHistogram(DisplayElecSetup& ss,
0416                      const std::string& basename, int lo,
0417                      int hi)
0418 {
0419   char name[120];
0420   TH1* retval=0;
0421   char bt = (ss.tb==1)?('t'):('b');
0422    
0423   sprintf(name,"%s:%s-%s Crate=%d FPGA=%d%c",
0424       ss.eventTypeStr.c_str(),ss.flavTypeStr.c_str(),basename.c_str(),ss.crate,ss.Slot,bt);
0425   retval=new TH1F(name,name, hi-lo+1, lo-0.5, hi+0.5);
0426   retval->GetXaxis()->SetTitle("HTR Channel");
0427 
0428   retval->SetDirectory(0);
0429   retval->SetStats(0);
0430   return retval;
0431 }
0432 
0433 
0434 void PlotAllDisplay::displayElecSummary(int crate,int Slot,int tb, int evtType, int flavType) {
0435   HistoManager::EventType et=(HistoManager::EventType)evtType;
0436   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0437   DisplayElecSetup setup;
0438   setup.fiber=-1;
0439   setup.fiberChan=-1;
0440   setup.crate=crate;
0441   setup.Slot=Slot;
0442   setup.tb=tb;
0443   setup.eventTypeStr=HistoManager::nameForEvent(et);
0444   setup.flavTypeStr=HistoManager::nameForFlavor(ht);
0445   
0446   std::vector<MyElectronicsId> KeyIds = histKeys.getElecIdsForType(ht,et);
0447   std::vector<MyElectronicsId> ids = electronicsFilter(-1,-1,crate,Slot,tb,KeyIds);
0448   
0449   if (ids.size()==0) {
0450     printf("The fiber/fiber channel/crate/slot values were not found!\n");
0451     printf("Make sure the correct event type is selected and the correct fiber/fiber channel/crate/slot values are entered.\n");    
0452     return;
0453   } //else printf("I found %d histograms.\n",ids.size());
0454   
0455   std::vector<MyElectronicsId>::const_iterator ii;
0456   
0457   // Sum of all channels
0458   TH1* sum=0;
0459   for (ii=ids.begin(); ii!=ids.end(); ii++) {
0460     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0461     if (h==0) continue;
0462     if (sum==0) {
0463       sum=(TH1*)h->Clone("All");
0464       sum->SetDirectory(0);
0465       char name[120];
0466       sprintf(name,"All %s:%s",setup.eventTypeStr.c_str(),setup.flavTypeStr.c_str());
0467       sum->SetTitle(name);
0468     } else sum->Add(h);
0469   }
0470   
0471   TCanvas* c=new TCanvas("All","All",60,60,800,600);
0472   c->cd();
0473   sum->Draw();
0474   sum->Draw("SAMEHIST");
0475 
0476   if (ht==HistoManager::PULSE) return;    
0477 
0478   
0479   TH1* meanSummary;
0480   TH1* RMSSummary;
0481     
0482   int range_lo=100000, range_hi=-100000;
0483   for(ii=ids.begin(); ii!=ids.end(); ii++) {
0484     int ibin=(ii->fiber-1)*3+ii->fiberChan+1;
0485     if (ibin>range_hi) range_hi=ibin;
0486     if (ibin<range_lo) range_lo=ibin;
0487 
0488 }
0489   
0490   meanSummary=bookMasterHistogram(setup,"MEAN",range_lo,range_hi);
0491   RMSSummary=bookMasterHistogram(setup,"RMS",range_lo,range_hi);
0492    
0493       
0494   int marker=24;
0495 
0496   meanSummary->SetMarkerStyle(marker);
0497   RMSSummary->SetMarkerStyle(marker);
0498   
0499   
0500   for(ii=ids.begin(); ii!=ids.end(); ii++) {
0501     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0502     if (h==0) continue;
0503     double bin=(ii->fiber-1)*3+ii->fiberChan+1;
0504     meanSummary->Fill(bin, h->GetMean());
0505     RMSSummary->Fill(bin, h->GetRMS());
0506     // printf("%d %d %f %f %f \n",ii->fiber,ii->fiberChan,bin, h->GetMean(),h->GetRMS());  
0507 }
0508   
0509   double ml=1e16,mh=-1e16;
0510    
0511   for (int jj=1; jj<=meanSummary->GetNbinsX(); jj++)
0512     if (meanSummary->GetBinError(jj)==0.0){
0513       //meanSummary->SetBinContent(jj,-1e6);
0514       } else {
0515       if (meanSummary->GetBinContent(jj)<ml)
0516     ml=meanSummary->GetBinContent(jj);
0517       if (meanSummary->GetBinContent(jj)>mh)
0518     mh=meanSummary->GetBinContent(jj);
0519     }
0520   
0521   meanSummary->SetMaximum(mh+(mh-ml)*0.05);
0522   meanSummary->SetMinimum(ml-(mh-ml)*0.05);
0523   
0524   ml=1e16,mh=-1e16;
0525   
0526   for (int jj=1; jj<=RMSSummary->GetNbinsX(); jj++)
0527     if (RMSSummary->GetBinError(jj)==0.0){
0528       //      RMSSummary->SetBinContent(jj,-1e6);
0529     } else {
0530       if (RMSSummary->GetBinContent(jj)<ml)
0531     ml=RMSSummary->GetBinContent(jj);
0532       if (RMSSummary->GetBinContent(jj)>mh)
0533     mh=RMSSummary->GetBinContent(jj);
0534     }
0535   
0536   RMSSummary->SetMaximum(mh+(mh-ml)*0.05);
0537   RMSSummary->SetMinimum(ml-(mh-ml)*0.05);
0538   
0539   
0540   TCanvas* myplot=new TCanvas(setup.eventTypeStr.c_str(),
0541                   setup.eventTypeStr.c_str(),
0542                   20,20,800,600);
0543   myplot->Divide(1,2);
0544   
0545   myplot->cd(1);
0546   meanSummary->Draw("P");
0547   
0548   myplot->cd(2);
0549   RMSSummary->Draw("P");
0550     
0551   
0552   // global distributions
0553   
0554   
0555   double mean_lo=1e160, mean_hi=-1e160;
0556   double RMS_lo=1e160, RMS_hi=-1e160;
0557   for (ii=ids.begin(); ii!=ids.end(); ii++) {
0558     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0559     if (h==0) continue;
0560     double mean=h->GetMean();
0561     double RMS=h->GetRMS();
0562     if (mean<mean_lo) mean_lo=mean;
0563     if (mean>mean_hi) mean_hi=mean;
0564     if (RMS<RMS_lo) RMS_lo=RMS;
0565     if (RMS>RMS_hi) RMS_hi=RMS;
0566   }
0567 
0568   //adjust range to include endpoints
0569   mean_lo = mean_lo - 0.05*(mean_hi-mean_lo);
0570   mean_hi = mean_hi + 0.05*(mean_hi-mean_lo);
0571   RMS_lo = RMS_lo - 0.05*(RMS_hi-RMS_lo);
0572   RMS_hi = RMS_hi + 0.05*(RMS_hi-RMS_lo);
0573   
0574   TH1* means=new TH1F("MEANS","MEANS",50,mean_lo,mean_hi);
0575   means->SetDirectory(0);
0576   
0577   TH1* RMSs=new TH1F("RMSs","RMSs",50,RMS_lo,RMS_hi);
0578   RMSs->SetDirectory(0);
0579   
0580   for (ii=ids.begin(); ii!=ids.end(); ii++) {
0581     TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0582     if (h==0) continue;
0583     means->Fill(h->GetMean());
0584     RMSs->Fill(h->GetRMS());
0585   } 
0586   
0587   TCanvas * myplot2 = new TCanvas("Statistics","Statistics",
0588                   40,40,800,600);
0589   
0590   myplot2->Divide(1,2);
0591   
0592   myplot2->cd(1);
0593   means->Draw();
0594   myplot2->cd(2);
0595   RMSs->Draw();
0596   
0597 }
0598 
0599 
0600   void PlotAllDisplay::displayElecOne(int fiber, int fiberChan, int crate,int Slot,int tb, int evtType, int flavType){
0601  
0602     
0603     MyElectronicsId id = {fiber,fiberChan,crate,Slot,tb};
0604     displayElecOne(id,evtType,flavType);
0605     
0606 }
0607 
0608 void PlotAllDisplay::displayElecOne(const MyElectronicsId& id,
0609                 int evtType, int flavType){
0610 
0611  HistoManager::EventType et=(HistoManager::EventType)evtType;
0612   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0613   
0614 
0615  
0616 
0617   TH1* h=histKeys.GetAHistogram(id,ht,et);
0618   
0619   if (h==0) {
0620     printf("The fiber/fiber channel/crate/slot values were not found!\n");
0621     printf("Make sure the correct event type is selected and the correct fiber/fiber channel/crate/slot values are entered.\n");
0622     return;
0623   }
0624 
0625   if (m_movie==0) {
0626     m_movie=new TCanvas("Selected","Selected",50,50,800,600);
0627     m_movie->Divide(3,2);
0628   }
0629 
0630   n_movie=(n_movie%6)+1;
0631   m_movie->cd(n_movie);
0632 
0633   if (ht==HistoManager::PULSE) 
0634     h->Draw("HIST");
0635   else 
0636     h->Draw();
0637   m_movie->Flush();
0638   m_movie->Update();
0639   m_movie->Paint();
0640 }
0641 
0642 
0643 void PlotAllDisplay:: CrateDisplaySelector(int crate, int evtType, int flavType,int plotStatType)
0644 {
0645   HistoManager::EventType et=(HistoManager::EventType)evtType;
0646   HistoManager::HistType ht=(HistoManager::HistType)flavType;
0647   
0648   std::vector<MyElectronicsId> FirstKeyIds = histKeys.getElecIdsForType(ht,et);
0649   std::vector<MyElectronicsId> KeyIds;
0650 
0651   for(std::vector<MyElectronicsId>::iterator kk=FirstKeyIds.begin();kk!=FirstKeyIds.end();kk++){
0652     if(kk->crate==crate){KeyIds.push_back(*kk);}
0653   }
0654 
0655   if (KeyIds.empty()) {
0656     printf("No histograms found for specified event type and flavor type\n");
0657     return;
0658   }
0659   int htrChan=0;
0660   int fpga=0;
0661   int htrChan_lo=10000;
0662   int htrChan_hi=-10000;
0663   int fpga_lo=10000;
0664   int fpga_hi=-10000;
0665  
0666  for(std::vector<MyElectronicsId>::iterator jj=KeyIds.begin();
0667       jj!=KeyIds.end();
0668       jj++) {
0669   
0670     htrChan=(jj->fiber-1)*3+jj->fiberChan+1;
0671     fpga=jj->Slot;    
0672 //if((jj->tb)==1){fpga=jj->Slot;}else{fpga=-(jj->Slot);}
0673 
0674 
0675  if( htrChan>htrChan_hi ) htrChan_hi=htrChan;
0676     if(htrChan<htrChan_lo ) htrChan_lo=htrChan;
0677     if( fpga>fpga_hi ) fpga_hi=fpga;
0678     if( fpga<fpga_lo ) fpga_lo=fpga;
0679 
0680 
0681     htrChan=0;fpga=0;
0682 
0683 }
0684 
0685     printf("htrChan_lo=%d htrChan_hi=%d fpga_lo=%d fpga_hi=%d\n",
0686             htrChan_lo,htrChan_hi,fpga_lo,fpga_hi);
0687 
0688   HcalElectronicsSelector* vs=
0689     new HcalElectronicsSelector(new PlotAllElecAdapter(this,evtType,flavType),
0690                 htrChan_lo,htrChan_hi,fpga_lo,fpga_hi,crate);
0691 
0692   for (std::vector<MyElectronicsId>::iterator ii=KeyIds.begin();
0693        ii!=KeyIds.end(); 
0694        ii++) {
0695     
0696     htrChan=(ii->fiber-1)*3+ii->fiberChan+1;
0697     if((ii->tb)==1){fpga=ii->Slot;}else{fpga=-(ii->Slot);}
0698 
0699 TH1* h=histKeys.GetAHistogram(*ii,ht,et);
0700     if (h==0) {
0701       printf("htrChan=%d, fpga=%d not found\n", htrChan, fpga);
0702       continue;
0703     }
0704     
0705     if (!plotStatType)
0706       vs->fill(*ii,h->GetMean());
0707     else
0708       vs->fill(*ii,h->GetRMS());
0709   }
0710   
0711   vs->Update();
0712 }
0713 
0714