Producer.cc File Reference

#include <iostream>
#include "TApplication.h"
#include "TROOT.h"
#include "TH1.h"
#include "TH2.h"
#include "TRandom.h"
#include "TSystem.h"
#include "TSocket.h"
#include "TServerSocket.h"
#include "TMath.h"
#include "TMessage.h"
#include "TMonitor.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TConsumerInfo.h"
#include "ConsumerExport.h"

Go to the source code of this file.

Functions

void InitGui ()
TROOT producer ("producer","Simple histogram producer", initfuncs)
void stoploop (int sig)
int main (int argc, char **argv)

Variables

VoidFuncPtr_t initfuncs [] = { InitGui, 0 }
static Bool_t loopContinue = 1

Function Documentation

void InitGui (  ) 
int main ( int  argc,
char **  argv 
)

Definition at line 80 of file Producer.cc.

References TConsumerInfo::addObject(), count, gSystem(), loopContinue, TConsumerInfo::removeObject(), ConsumerExport::send(), TConsumerInfo::setNevents(), and stoploop().

00081 {
00082   const int updatenum=5;
00083   const int printSupp=5;
00084   const int runNumber=1530; 
00085   //const int testAddNum = 300;
00086   const int testAddNum = 150;
00087   //const int testRemoveNum =600;
00088   const int testRemoveNum =300;
00089   const int s2nHistNum=15;
00090   const int histPerCanvas=4; 
00091   const int maxevnt=2000;
00092   const int maxPipeCell=46;
00093   const int maxChannel=640; 
00094   char histname[80];
00095 
00096   signal(SIGABRT, stoploop);
00097   signal(SIGTERM, stoploop);
00098   signal(SIGINT, stoploop);
00099   signal(SIGSEGV, stoploop);
00100   signal(SIGTRAP, stoploop);
00101   signal(SIGKILL, stoploop);
00102 
00103 
00104   gROOT->SetBatch(kTRUE);
00105   TApplication app("app",&argc,argv);
00106 
00107   ConsumerExport consExp(9050);
00108 
00109   //-----------------------------------------------------------------------
00110   TConsumerInfo *consinfo = new TConsumerInfo("Producer", runNumber);
00111   //-----------------------------------------------------------------------
00112 
00113   //-----------------------------------------------------------------------
00114   // Create  1d and  2d  histograms. These objects will
00115   // be automatically added to the current directory.
00116   Double_t **noiseArray1;  // Arrays for noise following
00117   Double_t **noiseArray2; 
00118   TH1F *histo1; 
00119   TH1F *histo2;
00120   TH2F *histo3;
00121   TH2F* noiseHist1 = 0;
00122   TH2F* noiseHist2 = 0;
00123   TH1F **s2nhistos;
00124   TCanvas **canvases;
00125   TCanvas* noiseCanvas1 = 0;
00126   TCanvas* noiseCanvas2 = 0;
00127 
00128   noiseArray1 = new Double_t*[maxChannel];
00129   noiseArray2 = new Double_t*[maxChannel];
00130   for (int iChan=0; iChan<maxChannel; iChan++) {
00131     noiseArray1[iChan] = new Double_t[maxPipeCell];
00132     noiseArray2[iChan] = new Double_t[maxPipeCell];
00133     // Initialize all this
00134     for (int iCell=0; iCell<maxPipeCell; iCell++) {
00135       noiseArray1[iChan][iCell] = 0.0;
00136     }
00137   }
00138 
00139   histo1 = new TH1F("Muon_Energy","Muon Energy",50,0,30);
00140   histo1->SetXTitle("muon energy");
00141   histo1->SetYTitle("event count");
00142   histo1->SetFillColor(48);
00143   
00144   histo2 = new TH1F("Muon_Pt","Muon Pt",50,0,30);
00145   histo2->SetXTitle("muon pt");
00146   histo2->SetYTitle("event count");
00147   histo2->SetFillColor(48);
00148   
00149   histo3 = new TH2F("Muon_py_vs_px","Muon py vs px",50,0,30,50,0,30);
00150   histo3->SetXTitle("muon px");
00151   histo3->SetYTitle("muon py");  
00152 
00153   consinfo->addObject("Muon_Energy", "Producer/Muon", 0, histo1);
00154 
00155   s2nhistos = new TH1F*[s2nHistNum];
00156   for (int ihist=0; ihist < s2nHistNum; ihist++) {
00157     sprintf(histname, "S2N_Barrel_%d", (400+ihist));
00158     s2nhistos[ihist] = new TH1F(histname, histname, 101, -0.5 , 100.5);
00159     if (ihist%2 == 0)  s2nhistos[ihist]->SetFillColor(3);
00160     else               s2nhistos[ihist]->SetFillColor(7);  
00161     consinfo->addObject(histname, "Producer/S2N", 0, s2nhistos[ihist]);
00162     s2nhistos[ihist]->SetXTitle("S/N");
00163     s2nhistos[ihist]->SetTitleOffset(1.4, "X");
00164   }
00165 
00166   // Calculate number of canvases needed
00167   Int_t nCanvas = s2nHistNum/histPerCanvas;
00168   if (nCanvas*histPerCanvas < s2nHistNum) nCanvas++;  
00169 
00170   canvases = new TCanvas*[nCanvas];
00171   for (Int_t iCan=0; iCan<nCanvas; iCan++) {
00172     sprintf(histname, "S2N_Canvas_%d", iCan);
00173     canvases[iCan] = new TCanvas(histname,histname,200,10,700,500);
00174     consinfo->addObject(histname, "Producer/SlideShow", 0, canvases[iCan]);
00175     canvases[iCan]->Divide(2,2);    // Carefull, hardcoded ! Clean this up later!
00176     canvases[iCan]->cd();
00177     for (Int_t iPad=0; iPad<histPerCanvas; iPad++) {
00178       canvases[iCan]->cd(iPad+1);
00179       Int_t ihist = iCan*histPerCanvas+iPad;
00180       if (ihist < s2nHistNum) s2nhistos[ihist]->Draw();
00181     } 
00182   }
00183 
00184   Float_t s2nMean[s2nHistNum];
00185   for (Int_t iHist=0; iHist<s2nHistNum; iHist++) {
00186     s2nMean[iHist] = (Float_t) gRandom->Gaus(25.0, 5.0);
00187   }
00188 
00189   // Define 2 big noise histograms
00190   sprintf(histname, 
00191   "Noise: cell number versus channel number, SVD 2c, Module ID: B3-067X-498");
00192   noiseHist1 = new TH2F (histname, histname, maxChannel, 0, (maxChannel-1),
00193                          maxPipeCell, 0, (maxPipeCell-1));
00194   consinfo->addObject(histname, "Producer/Noise", 0, noiseHist1);  
00195   noiseHist1->SetOption("COLZ");
00196   noiseHist1->SetStats(0);
00197   noiseHist1->SetXTitle("Channel No.");
00198   noiseHist1->SetYTitle("Cell No.");
00199   noiseHist1->SetTitleOffset(1.4, "X");
00200   noiseHist1->SetTitleOffset(1.4, "Y");
00201 
00202   sprintf(histname, 
00203   "Module ID: B3-067X-321: Noise: cell number versus channel number, SVD 2c");
00204   noiseHist2 = new TH2F (histname, histname, maxChannel, 0, (maxChannel-1), 
00205                          maxPipeCell, 0, (maxPipeCell-1));
00206   consinfo->addObject(histname, "Producer/Noise", 0, noiseHist2);
00207   noiseHist2->SetOption("COLZ"); 
00208   noiseHist2->SetStats(0);
00209   noiseHist2->SetXTitle("Channel No.");
00210   noiseHist2->SetYTitle("Cell No.");
00211   noiseHist2->SetTitleOffset(1.4, "X");
00212   noiseHist2->SetTitleOffset(1.4, "Y");
00213 
00214 
00215   // Define 2 big Canvases 
00216   sprintf(histname, "NoiseCanvas_1");
00217   noiseCanvas1 = new TCanvas(histname,histname,200,10,1000,700);
00218   consinfo->addObject(histname, "Producer/SlideShow", 0, noiseCanvas1);
00219   noiseCanvas1->cd();
00220   noiseHist1->Draw("COLZ");
00221   sprintf(histname, "NoiseCanvas_2");
00222   noiseCanvas2 = new TCanvas(histname,histname,200,10,1000,700);
00223   consinfo->addObject(histname, "Producer/Noise", 0, noiseCanvas2);
00224   noiseCanvas2->cd();
00225   noiseHist2->Draw("COLZ");
00226  
00227   // Define a hot channel and a hot cell list.
00228   // Doesn't catch the case that a number is selected twice.
00229   // They are also the same for both ladders.
00230   Int_t hotChan[10];
00231   cout << "Hot channels: ";
00232   for (Int_t iHot=0; iHot<10; iHot++) {
00233     hotChan[iHot] = gRandom->Integer(maxChannel);
00234     cout << hotChan[iHot] << ", ";
00235   }
00236   cout << endl;
00237 
00238   Int_t hotCell[5];
00239   cout << "Hot cells: "; 
00240   for (Int_t iHot=0; iHot<5; iHot++) {
00241     hotCell[iHot] = gRandom->Integer(maxPipeCell);
00242     cout << hotCell[iHot] << ", "; 
00243   }
00244   cout << endl;
00245 
00246   //-----------------------------------------------------------------------
00247   Float_t muon_Energy,muon_Pt,muon_Px,muon_Py;
00248   Double_t s2n;
00249   int count = 1;
00250   // now start endless loop
00251   while (loopContinue && (count <= maxevnt)) {
00252     // get random number for muon px and py:   
00253     gRandom->Rannor(muon_Px,muon_Py);
00254     muon_Px     = muon_Px + 10.;
00255     muon_Py     = muon_Py + 10.;
00256     muon_Pt     = sqrt(muon_Px*muon_Px+muon_Py*muon_Py);
00257     muon_Energy = sqrt(0.105*0.105+muon_Pt*muon_Pt);
00258     histo1->Fill(muon_Energy,1.0);
00259     histo2->Fill(muon_Pt,1.0);
00260     histo3->Fill(muon_Px,muon_Py,1.0);
00261     //---------------------------------------------------------------
00262     // Fill random numbers obeying a Landau distribution into the S/N 
00263     // histograms 
00264     for (int ihist=0; ihist<s2nHistNum; ihist++) {
00265       s2n = gRandom->Landau( s2nMean[ihist], 3.0);
00266       s2nhistos[ihist]->Fill((Float_t)s2n,1.0); 
00267     }
00268     //---------------------------------------------------------------
00269     // Now we slow down the program a bit and do some noise following.
00270     Double_t omega = 0.0;
00271     if (count < 250) omega = 1/((Double_t)count); // generic mean
00272     else             omega = 1/250.0;             // constant weight factor
00273     for (int iCell=0; iCell<maxPipeCell; iCell++) {
00274       Bool_t cellIsHot = kFALSE;
00275       for (int iHotCell=0; iHotCell<5; iHotCell++) { 
00276         if (hotCell[iHotCell] == iCell) {
00277           cellIsHot=kTRUE;
00278           continue;
00279         }
00280       }
00281       for (int iChan=0; iChan<maxChannel; iChan++) {
00282         Double_t sigma=3.0;
00283         for (int iHotChan=0; iHotChan<10; iHotChan++) {
00284           if (hotChan[iHotChan] == iChan) {
00285             sigma = 20.0;
00286             continue;
00287           } 
00288         }
00289         if (cellIsHot) sigma += 15.0;  
00290         Double_t pedSub = 0.0;
00291         Double_t noise  = 0.0;
00292         // All this is not optimized for speed. It's just a demo.
00293         pedSub = gRandom->Gaus(0.0, sigma);
00294         noise  = TMath::Abs(pedSub);
00295         noiseArray1[iChan][iCell] = noiseArray1[iChan][iCell] * (1 - omega) 
00296                                     + noise * omega; 
00297         pedSub = gRandom->Gaus(0.0, sigma);
00298         noise  = TMath::Abs(pedSub);
00299         noiseArray2[iChan][iCell] = noiseArray2[iChan][iCell] * (1 - omega) 
00300                                     + noise * omega; 
00301       }
00302     }  
00303 
00304     gSystem->Sleep(100);   // sleep for 0.1 seconds (don't swamp the system)
00305       
00306     if (count % updatenum == 0) {
00307       noiseHist1->Reset();
00308       noiseHist2->Reset();
00309       for (Int_t iChan=0; iChan<maxChannel; iChan++) {
00310         for (Int_t iCell=0; iCell<maxPipeCell; iCell++) {
00311           noiseHist1->Fill( (float)iChan, (float)iCell, 
00312                             (Float_t) noiseArray1[iChan][iCell]);
00313           noiseHist2->Fill( (float)iChan, (float)iCell, 
00314                             (Float_t) noiseArray2[iChan][iCell]); 
00315         }
00316       }
00317       // Histograms are sent every <updatenum> events.
00318       // You might want to change this when processing a lot of events.
00319       //
00320       // Here we test to add some histograms after a certain number
00321       // of events.
00322       if (count == testAddNum) {
00323         //consinfo->addObject("Muon_Pt", "Producer/Muon", 0, histo2);
00324         consinfo->addObject("Muon_Pt", "Producer/Warning", 0, histo2);
00325         //consinfo->addObject("Muon_py_vs_px", "Producer/Muon", 0, histo3);  
00326         consinfo->addObject("Muon_py_vs_px", "Producer/Warning", 0, histo3);  
00327       }
00328       // Here we test to take some histograms away.  
00329       if (count == testRemoveNum) {
00330         for (int ihist=0; ihist < s2nHistNum; ihist++) {
00331           consinfo->removeObject(s2nhistos[ihist]);
00332         }
00333       }
00334       // Update the consumer info event number
00335       consinfo->setNevents(count);
00336 
00337       // Send out the consumer info and all objects in its list.
00338       consExp.send(consinfo);
00339 
00340       if (count%(updatenum*printSupp) == 0) { 
00341         cout << "Producer: Sent out objects to the Server. " 
00342              << "Event # "<< count << endl;
00343       }
00344     }
00345     ++count;
00346   }
00347 
00348   for (Int_t ihist=0; ihist<s2nHistNum; ihist++) delete s2nhistos[ihist];
00349   delete [] s2nhistos;
00350 
00351   for (Int_t iCan=0; iCan<nCanvas; iCan++) delete canvases[iCan];
00352   delete [] canvases;
00353 
00354   return 1;
00355 }

TROOT producer ( "producer"  ,
"Simple histogram producer"  ,
initfuncs   
)

Referenced by main().

void stoploop ( int  sig  ) 

Definition at line 66 of file Producer.cc.

References loopContinue.

Referenced by main().

00067   {
00068     signal(SIGABRT, SIG_DFL);
00069     signal(SIGTERM, SIG_DFL);
00070     signal(SIGINT, SIG_DFL);
00071     signal(SIGSEGV, SIG_DFL);
00072     signal(SIGTRAP, SIG_DFL);
00073     signal(SIGKILL, SIG_DFL);
00074     cout << "Producer: stoploop(): ending loop with signal " << sig << endl;
00075     loopContinue=0; 
00076   } 


Variable Documentation

VoidFuncPtr_t initfuncs[] = { InitGui, 0 }

Definition at line 59 of file Producer.cc.

Bool_t loopContinue = 1 [static]

Definition at line 62 of file Producer.cc.

Referenced by main(), and stoploop().


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1