Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TXXXProc.cxx

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

Generated on Fri Nov 28 12:59:10 2008 for Go4-v3.04-1 by  doxygen 1.4.2