Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ExampleSimple/TXXXProc.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TXXXProc.h"
00017 
00018 #include <iostream.h>
00019 #include <time.h>
00020 
00021 #include "TXXXEvent.h"
00022 #include "MbsAPI/s_filhe_swap.h"
00023 #include "MbsAPI/s_bufhe_swap.h"
00024 
00025 //***********************************************************
00026 TXXXProc::TXXXProc() : TGo4EventProcessor("Proc")
00027 {
00028   cout << "**** TXXXProc: Create instance " << endl;
00029 }
00030 //***********************************************************
00031 TXXXProc::~TXXXProc()
00032 {
00033   cout << "**** TXXXProc: Delete instance " << endl;
00034 }
00035 //***********************************************************
00036 // this one is used in standard factory
00037 TXXXProc::TXXXProc(const char* name) : TGo4EventProcessor(name)
00038 {
00039   cout << "**** TXXXProc: Create instance " << name << endl;
00040 
00041   Text_t chis[16];
00042   Text_t chead[64];
00043   Int_t i;
00044 
00046 
00047   // Creation of parameters (check if restored from auto save file):
00048   if(GetParameter("Par1")==0)
00049     {// no auto save, create new
00050       fParam = new TXXXParam("Par1");
00051       AddParameter(fParam);
00052       cout << "**** TXXXProc: Created parameter" << endl;
00053     }
00054   else // got them from autosave file, restore pointers
00055     {
00056       fParam=(TXXXParam *)GetParameter("Par1");
00057       cout << "**** TXXXProc: Restored parameter from autosave" << endl;
00058     }
00059 
00060   // Creation of histograms (check if restored from auto save file):
00061   if(GetHistogram("Crate1/Cr1Ch01")==0)
00062     {// no auto save, create new
00063       for(i =0;i<8;i++)
00064    {
00065      snprintf(chis,15,"Cr1Ch%02d",i+1);  snprintf(chead,63,"Crate 1 channel %2d",i+1);
00066           fCr1Ch[i] = new TH1I (chis,chead,5000,1,5000);
00067           AddHistogram(fCr1Ch[i],"Crate1");
00068      snprintf(chis,15,"Cr2Ch%02d",i+1);  snprintf(chead,63, "Crate 2 channel %2d",i+1);
00069           fCr2Ch[i] = new TH1I (chis,chead,5000,1,5000);
00070           AddHistogram(fCr2Ch[i],"Crate2");
00071    }
00072       fCr1Ch1x2 = new TH2I("Cr1Ch1x2","Crate 1 channel 1x2",200,1,5000,200,1,5000);
00073       AddHistogram(fCr1Ch1x2);
00074       fHis1     = new TH1I ("His1","Condition histogram",5000,1,5000);
00075       AddHistogram(fHis1);
00076       fHis2     = new TH1I ("His2","Condition histogram",5000,1,5000);
00077       AddHistogram(fHis2);
00078       fHis1gate = new TH1I ("His1g","Gated histogram",5000,1,5000);
00079       AddHistogram(fHis1gate);
00080       fHis2gate = new TH1I ("His2g","Gated histogram",5000,1,5000);
00081       AddHistogram(fHis2gate);
00082       cout << "**** TXXXProc: Created histograms" << endl;
00083     }
00084   else // got them from autosave file, restore pointers
00085     {
00086       for(i =0;i<8;i++)
00087    {
00088      snprintf(chis,15,"Crate1/Cr1Ch%02d",i+1); fCr1Ch[i] = (TH1I*)GetHistogram(chis);
00089      snprintf(chis,15,"Crate2/Cr2Ch%02d",i+1); fCr2Ch[i] = (TH1I*)GetHistogram(chis);
00090    }
00091       fCr1Ch1x2 = (TH2I*)GetHistogram("Cr1Ch1x2");
00092       fHis1     = (TH1I*)GetHistogram("His1");
00093       fHis2     = (TH1I*)GetHistogram("His2");
00094       fHis1gate = (TH1I*)GetHistogram("His1g");
00095       fHis2gate = (TH1I*)GetHistogram("His2g");
00096       cout << "**** TXXXProc: Restored histograms from autosave" << endl;
00097     }
00098   // Creation of conditions (check if restored from auto save file):
00099   if(GetAnalysisCondition("cHis1")==0)
00100     {// no auto save, create new
00101       fconHis1= new TGo4WinCond("cHis1");
00102       fconHis2= new TGo4WinCond("cHis2");
00103       fconHis1->SetValues(100,2000);
00104       fconHis2->SetValues(100,2000);
00105       AddAnalysisCondition(fconHis1);
00106       AddAnalysisCondition(fconHis2);
00107 
00108       Double_t xvalues[4]={400,700,600,400};
00109       Double_t yvalues[4]={800,900,1100,800};
00110       TCutG* mycut= new TCutG("initialcut",4,xvalues,yvalues);
00111       fPolyCon= new TGo4PolyCond("polycon");
00112       fPolyCon->SetValues(mycut); // copies mycat into fPolyCon
00113       fPolyCon->Disable(true);   // means: condition check always returns true
00114       delete mycut; // mycat has been copied into the conditions
00115       AddAnalysisCondition(fPolyCon);
00116 
00117       xvalues[0]=1000;xvalues[1]=2000;xvalues[2]=1500;xvalues[3]=1000;
00118       yvalues[0]=1000;yvalues[1]=1000;yvalues[2]=3000;yvalues[3]=1000;
00119       mycut= new TCutG("initialcut",4,xvalues,yvalues);
00120       fConArr = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
00121       fConArr->SetValues(mycut);
00122       fConArr->Disable(true);   // means: condition check always returns true
00123       delete mycut; // mycat has been copied into the conditions
00124       AddAnalysisCondition(fConArr);
00125       cout << "**** TXXXProc: Created conditions" << endl;
00126     }
00127   else // got them from autosave file, restore pointers
00128     {
00129       fPolyCon  = (TGo4PolyCond*) GetAnalysisCondition("polycon");
00130       fConArr   = (TGo4CondArray*)GetAnalysisCondition("polyconar");
00131       fconHis1  = (TGo4WinCond*)  GetAnalysisCondition("cHis1");
00132       fconHis2  = (TGo4WinCond*)  GetAnalysisCondition("cHis2");
00133       fconHis1->ResetCounts();
00134       fconHis2->ResetCounts();
00135       fPolyCon->ResetCounts();
00136       fConArr->ResetCounts();
00137       cout << "**** TXXXProc: Restored conditions from autosave" << endl;
00138     }
00139   // connect histograms to conditions. will be drawn when condition is edited.
00140   fconHis1->SetHistogram("His1");
00141   fconHis2->SetHistogram("His2");
00142   fconHis1->Enable();
00143   fconHis2->Enable();
00144   fPolyCon->Enable();
00145   ((*fConArr)[0])->Enable();
00146   ((*fConArr)[1])->Enable(); // 2 and 3 remain disabled
00147 
00148   if (GetPicture("Picture")==0)
00149     {// no auto save, create new
00150       // in the upper two pads, the condition limits can be set,
00151       // in the lower two pads, the resulting histograms are shown
00152       fcondSet = new TGo4Picture("condSet","Set conditions");
00153       fcondSet->SetLinesDivision(2,2,2);
00154       fcondSet->LPic(0,0)->AddObject(fHis1);
00155       fcondSet->LPic(0,1)->AddObject(fHis2);
00156       fcondSet->LPic(0,0)->AddCondition(fconHis1);
00157       fcondSet->LPic(0,1)->AddCondition(fconHis2);
00158       fcondSet->LPic(1,0)->AddObject(fHis1gate);
00159       fcondSet->LPic(1,1)->AddObject(fHis2gate);
00160       fcondSet->LPic(1,0)->SetFillAtt(4, 1001); // solid
00161       fcondSet->LPic(1,0)->SetLineAtt(4,1,1);
00162       fcondSet->LPic(1,1)->SetFillAtt(9, 1001); // solid
00163       fcondSet->LPic(1,1)->SetLineAtt(9,1,1);
00164       AddPicture(fcondSet);
00165 
00166       fPicture = new TGo4Picture("Picture","Picture example");
00167       fPicture->SetLinesDivision(3, 2,3,1);
00168       fPicture->LPic(0,0)->AddObject(fCr1Ch[0]);
00169       fPicture->LPic(0,0)->SetFillAtt(5, 3001); // pattern
00170       fPicture->LPic(0,0)->SetLineAtt(5,1,1);
00171       fPicture->LPic(0,1)->AddObject(fCr1Ch[1]);
00172       fPicture->LPic(0,1)->SetFillAtt(4, 3001); // pattern
00173       fPicture->LPic(0,1)->SetLineAtt(4,1,1);
00174       fPicture->LPic(1,0)->AddObject(fCr1Ch[2]);
00175       fPicture->LPic(1,0)->SetFillAtt(6, 1001); // solid
00176       fPicture->LPic(1,0)->SetLineAtt(6,1,1);
00177       fPicture->LPic(1,1)->AddObject(fCr1Ch[3]);
00178       fPicture->LPic(1,1)->SetFillAtt(7, 1001); // solid
00179       fPicture->LPic(1,1)->SetLineAtt(7,1,1);
00180       fPicture->LPic(1,2)->AddObject(fCr1Ch[4]);
00181       fPicture->LPic(3,0)->AddObject(fCr1Ch1x2);
00182       fPicture->LPic(3,0)->SetDrawOption("CONT");
00183       AddPicture(fPicture);
00184       cout << "**** TXXXProc: Created pictures" << endl;
00185     }
00186   else  // got them from autosave file, restore pointers
00187     {
00188       fPicture = GetPicture("Picture");
00189       fcondSet = GetPicture("condSet");
00190       cout << "**** TXXXProc: Restored pictures from autosave" << endl;
00191     }
00192 }
00193 //-----------------------------------------------------------
00194 // event function
00195 void TXXXProc::Event(TXXXEvent* XXXEvent)
00196 {  // called by TXXXEvent. We dont use XXXEvent here
00197 
00198   TGo4MbsSubEvent* psubevt;
00199   Int_t index=0;
00200   Float_t value1=0;
00201   Float_t value2=0;
00202   Float_t value=0;
00203   Int_t lwords,i;
00204   Int_t *pdata;
00205 
00206   fInput = (TGo4MbsEvent* ) GetInputEvent();
00207   if(fInput == 0)
00208     {
00209     cout << "AnlProc: no input event !"<< endl;
00210     return;
00211     }
00212   if(fInput->GetTrigger() > 11)
00213     {
00214       cout << "**** TXXXProc: Skip trigger event"<<endl;
00215       return;
00216     }
00217   // first we fill the arrays fCrate1,2 with data from MBS source
00218   // we have up to two subevents, crate 1 and 2
00219   // Note that one has to loop over all subevents and select them by
00220   // crate number:   psubevt->GetSubcrate(),
00221   // procid:         psubevt->GetProcid(),
00222   // and/or control: psubevt->GetControl()
00223   // here we use only crate number
00224 
00225   fInput->ResetIterator();
00226   while((psubevt = fInput->NextSubEvent()) != 0) // loop over subevents
00227     {
00228       pdata=psubevt->GetDataField();
00229       lwords= (psubevt->GetDlen() -2) * sizeof(Short_t)/sizeof(Int_t);
00230       if(lwords > 8) lwords=8; // take only first 8 lwords
00231 
00232       if(psubevt->GetSubcrate() == 1)
00233    {
00234      for(i = 0; i<lwords; i++)
00235        {
00236          //index =  *pdata&0xfff;      // in case low word is index
00237          //value = (*pdata>>16)&0xfff; // and high word is data
00238          value=(Float_t)*pdata++;      // otherwise longword data
00239          index=i;                      // and index in order
00240          fCrate1[index] = value; // copy to output event
00241        }
00242    }
00243       if(psubevt->GetSubcrate() == 2)
00244    {
00245      for(i = 0; i<lwords; i++) fCrate2[i] = (Float_t)*pdata++;
00246    }
00247     }
00248 
00249   // now we fill histograms from the arrays
00250   for(i = 0; i<8; i++)
00251     {
00252       fCr1Ch[i]->Fill(fCrate1[i]);
00253       fCr2Ch[i]->Fill(fCrate2[i]);
00254     }
00255   value1=fCrate1[0];
00256   value2=fCrate1[1];
00257   fHis1->Fill(value1); //fill histograms without gate
00258   fHis2->Fill(value2);
00259   if(fconHis1->Test(value1))fHis1gate->Fill(value1); //fill histograms with gate
00260   if(fconHis2->Test(value2))fHis2gate->Fill(value2);
00261   // fill Cr1Ch1x2 for three polygons:
00262   if(fPolyCon->Test(value1,value2))        fCr1Ch1x2->Fill(value1,value2);
00263   if(((*fConArr)[0])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
00264   if(((*fConArr)[1])->Test(value1,value2)) fCr1Ch1x2->Fill(value1,value2);
00265   return;
00266 }
00267 //-----------------------------------------------------------
00268 ClassImp(TXXXProc)
00269 
00270 
00271 
00272 
00273 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:54 2005 for Go4-v2.10-5 by doxygen1.2.15