00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TXXXUnpackProc.h"
00017
00018 #include "Riostream.h"
00019 #include <time.h>
00020
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TCutG.h"
00024 #include "snprintf.h"
00025
00026 #include "s_filhe_swap.h"
00027 #include "s_bufhe_swap.h"
00028
00029 #include "TGo4MbsEvent.h"
00030 #include "TGo4WinCond.h"
00031 #include "TGo4PolyCond.h"
00032 #include "TGo4CondArray.h"
00033 #include "TGo4Picture.h"
00034
00035 #include "TXXXParameter.h"
00036 #include "TXXXUnpackEvent.h"
00037
00038
00039 TXXXUnpackProc::TXXXUnpackProc() :
00040 TGo4EventProcessor()
00041 {
00042 }
00043
00044
00045 TXXXUnpackProc::TXXXUnpackProc(const char* name) :
00046 TGo4EventProcessor(name)
00047 {
00048 cout << "**** TXXXUnpackProc: Create" << endl;
00049
00050 Text_t chis[16];
00051 Text_t chead[64];
00052 Int_t i;
00053
00055
00056 fParam1 = (TXXXParameter *) GetParameter("XXXPar1");
00057 fParam2 = (TXXXParameter *) GetParameter("XXXPar2");
00058 fParam1->PrintParameter(0,0);
00059 fParam2->PrintParameter(0,0);
00060
00061
00062 if(GetHistogram("Crate1/Cr1Ch01")==0)
00063 {
00064 for(i =0;i<8;i++)
00065 {
00066 snprintf(chis,15,"Cr1Ch%02d",i+1);
00067 snprintf(chead,63,"Crate 1 channel %2d",i+1);
00068 fCr1Ch[i] = new TH1I (chis,chead,5000,1,5000);
00069 AddHistogram(fCr1Ch[i],"Crate1");
00070 snprintf(chis,15,"Cr2Ch%02d",i+1);
00071 snprintf(chead,63,"Crate 2 channel %2d",i+1);
00072 fCr2Ch[i] = new TH1I (chis,chead,5000,1,5000);
00073 AddHistogram(fCr2Ch[i],"Crate2");
00074 }
00075 fCr1Ch1x2 = new TH2I("Cr1Ch1x2","Crate 1 channel 1x2",200,1,5000,200,1,5000);
00076 AddHistogram(fCr1Ch1x2);
00077 fHis1 = new TH1I ("His1","Condition histogram",5000,1,5000);
00078 AddHistogram(fHis1);
00079 fHis2 = new TH1I ("His2","Condition histogram",5000,1,5000);
00080 AddHistogram(fHis2);
00081 fHis1gate = new TH1I ("His1g","Gated histogram",5000,1,5000);
00082 AddHistogram(fHis1gate);
00083 fHis2gate = new TH1I ("His2g","Gated histogram",5000,1,5000);
00084 AddHistogram(fHis2gate);
00085 }
00086 else
00087 {
00088 for(i =0;i<8;i++)
00089 {
00090 snprintf(chis,15,"Crate1/Cr1Ch%02d",i+1);
00091 fCr1Ch[i]=(TH1I*)GetHistogram(chis);
00092 snprintf(chis,15,"Crate2/Cr2Ch%02d",i+1);
00093 fCr2Ch[i]=(TH1I*)GetHistogram(chis);
00094 }
00095 fCr1Ch1x2=(TH2I*)GetHistogram("Cr1Ch1x2");
00096 fHis1=(TH1I*)GetHistogram("His1");
00097 fHis2=(TH1I*)GetHistogram("His2");
00098 fHis1gate=(TH1I*)GetHistogram("His1g");
00099 fHis2gate=(TH1I*)GetHistogram("His2g");
00100 cout << "Unpack: Restored histograms from autosave" << endl;
00101 }
00102
00103 if(GetAnalysisCondition("wincon1")==0)
00104 {
00105 fWinCon1= new TGo4WinCond("wincon1");
00106 fWinCon1->SetValues(50,2000);
00107 fWinCon1->Disable(true);
00108
00109 fWinCon2= new TGo4WinCond("wincon2");
00110 fWinCon2->SetValues(50,70,90,120);
00111 fWinCon2->Disable(true);
00112 fWinCon2->Invert(kTRUE);
00113
00114 fconHis1= new TGo4WinCond("cHis1");
00115 fconHis2= new TGo4WinCond("cHis2");
00116 fconHis1->SetValues(100,2000);
00117 fconHis2->SetValues(100,2000);
00118
00119 fConArr1= new TGo4CondArray("winconar",30,"TGo4WinCond");
00120 fConArr1->SetValues(100,500);
00121 fConArr1->Disable(true);
00122 ((*fConArr1)[0])->SetValues(200,400);
00123 ((*fConArr1)[1])->SetValues(700,1000);
00124 ((*fConArr1)[2])->SetValues(1500,2000);
00125 fConArr1->SetHistogram("Sum3");
00126
00127 Double_t xvalues[4]={400,700,600,400};
00128 Double_t yvalues[4]={800,900,1100,800};
00129 TCutG* mycut= new TCutG("cut1",4,xvalues,yvalues);
00130 fPolyCon1= new TGo4PolyCond("polycon");
00131 fPolyCon1->SetValues(mycut);
00132 fPolyCon1->Disable(true);
00133 delete mycut;
00134
00135 xvalues[0]=1000;xvalues[1]=2000;xvalues[2]=1500;xvalues[3]=1000;
00136 yvalues[0]=1000;yvalues[1]=1000;yvalues[2]=3000;yvalues[3]=1000;
00137 mycut= new TCutG("cut2",4,xvalues,yvalues);
00138 fConArr2= new TGo4CondArray("polyconar",5,"TGo4PolyCond");
00139 fConArr2->SetValues(mycut);
00140 fConArr2->Disable(true);
00141 delete mycut;
00142
00143 AddAnalysisCondition(fWinCon1);
00144 AddAnalysisCondition(fWinCon2);
00145 AddAnalysisCondition(fPolyCon1);
00146 AddAnalysisCondition(fConArr1);
00147 AddAnalysisCondition(fConArr2);
00148 AddAnalysisCondition(fconHis1);
00149 AddAnalysisCondition(fconHis2);
00150 }
00151 else
00152 {
00153 fWinCon1 = (TGo4WinCond*) GetAnalysisCondition("wincon1");
00154 fWinCon2 = (TGo4WinCond*) GetAnalysisCondition("wincon2");
00155 fPolyCon1 = (TGo4PolyCond*) GetAnalysisCondition("polycon");
00156 fConArr1 = (TGo4CondArray*)GetAnalysisCondition("winconar");
00157 fConArr2 = (TGo4CondArray*)GetAnalysisCondition("polyconar");
00158 fconHis1 = (TGo4WinCond*) GetAnalysisCondition("cHis1");
00159 fconHis2 = (TGo4WinCond*) GetAnalysisCondition("cHis2");
00160 fconHis1->ResetCounts();
00161 fconHis2->ResetCounts();
00162 fWinCon1->ResetCounts();
00163 fWinCon2->ResetCounts();
00164 fPolyCon1->ResetCounts();
00165 fConArr1->ResetCounts();
00166 fConArr2->ResetCounts();
00167
00168 cout << "Unpack: Restored conditions from autosave" << endl;
00169 }
00170
00171 fconHis1->SetHistogram("His1");
00172 fconHis2->SetHistogram("His2");
00173 fconHis1->Enable();
00174 fconHis2->Enable();
00175 fconHis1->PrintCondition(true);
00176 fconHis2->PrintCondition(true);
00177
00178 if (GetPicture("Picture1")==0)
00179 {
00180 fcondSet = new TGo4Picture("condSet","Set conditions");
00181 fcondSet->SetDrawHeader(kTRUE);
00182 fcondSet->SetDivision(2,2);
00183 fcondSet->Pic(0,0)->AddObject(fHis1);
00184 fcondSet->Pic(0,1)->AddObject(fHis2);
00185 fcondSet->Pic(0,0)->AddCondition(fconHis1);
00186 fcondSet->Pic(0,1)->AddCondition(fconHis2);
00187 fcondSet->Pic(1,0)->AddObject(fHis1gate);
00188 fcondSet->Pic(1,1)->AddObject(fHis2gate);
00189 fcondSet->Pic(1,0)->SetFillAtt(4, 1001);
00190 fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
00191 fcondSet->Pic(1,1)->SetFillAtt(9, 1001);
00192 fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
00193 AddPicture(fcondSet);
00194
00195 Picture1 = new TGo4Picture("Picture1","Picture example");
00196 Picture1->SetLinesDivision(3, 2,3,1);
00197 Picture1->LPic(0,0)->AddObject(fCr1Ch[0]);
00198 Picture1->LPic(0,0)->SetFillAtt(5, 3001);
00199 Picture1->LPic(0,0)->SetLineAtt(5,1,1);
00200 Picture1->LPic(0,1)->AddObject(fCr1Ch[1]);
00201 Picture1->LPic(0,1)->SetFillAtt(4, 3001);
00202 Picture1->LPic(0,1)->SetLineAtt(4,1,1);
00203 Picture1->LPic(1,0)->AddObject(fCr1Ch[2]);
00204 Picture1->LPic(1,0)->SetFillAtt(6, 1001);
00205 Picture1->LPic(1,0)->SetLineAtt(6,1,1);
00206 Picture1->LPic(1,1)->AddObject(fCr1Ch[3]);
00207 Picture1->LPic(1,1)->SetFillAtt(7, 1001);
00208 Picture1->LPic(1,1)->SetLineAtt(7,1,1);
00209 Picture1->LPic(1,2)->AddObject(fCr1Ch[4]);
00210 Picture1->LPic(3,0)->AddObject(fCr1Ch1x2);
00211 Picture1->LPic(3,0)->SetDrawOption("CONT");
00212
00213 AddPicture(Picture1);
00214
00215 }
00216 else
00217 {
00218 Picture1 = GetPicture("Picture1");
00219 fcondSet = (TGo4Picture *)GetPicture("condSet");
00220 }
00221
00222 fWinCon1->Enable();
00223 fWinCon1->PrintCondition(true);
00224 fPolyCon1->Enable();
00225 fPolyCon1->PrintCondition(true);
00226 ((*fConArr2)[0])->Enable();
00227 ((*fConArr2)[1])->Enable();
00228 }
00229
00230 TXXXUnpackProc::~TXXXUnpackProc()
00231 {
00232 fWinCon1->PrintCondition(true);
00233 fPolyCon1->PrintCondition(true);
00234 }
00235
00236
00237
00238 void TXXXUnpackProc::XXXUnpack(TXXXUnpackEvent* poutevt)
00239 {
00240 TGo4MbsSubEvent* psubevt;
00241 Int_t index=0;
00242 Int_t value=0;
00243 Int_t lwords;
00244 Int_t *pdata;
00245 fInput = (TGo4MbsEvent* ) GetInputEvent();
00246 if(fInput)
00247 {
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00266
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00287
00288 fInput->ResetIterator();
00289 while ((psubevt = fInput->NextSubEvent()) != 0)
00290 {
00291 if( psubevt->GetSubcrate() == 1)
00292 {
00293 pdata=psubevt->GetDataField();
00294 lwords= psubevt->GetIntLen();
00295 if(lwords >= 8) lwords=8;
00296 for(Int_t i = 0; i<lwords; ++i)
00297 {
00298 index = *pdata&0xfff;
00299
00300 if(*pdata != 0)
00301 {
00302 fCr1Ch[i]->Fill((Float_t)(*pdata));
00303 poutevt->fiCrate1[i] = *pdata;
00304 if(i == 0)
00305 {
00306 if(fconHis1->Test(*pdata))fHis1gate->Fill((Float_t)(*pdata));
00307 fHis1->Fill((Float_t)(*pdata));
00308 }
00309 if(i == 1)
00310 {
00311 if(fconHis2->Test(*pdata))fHis2gate->Fill((Float_t)(*pdata));
00312 fHis2->Fill((Float_t)(*pdata));
00313
00314 if(fPolyCon1->Test(*pdata,value)) fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00315 if(((*fConArr2)[0])->Test(*pdata,value))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00316 if(((*fConArr2)[1])->Test(*pdata,value))fCr1Ch1x2->Fill((Float_t)(*pdata),(Float_t)value);
00317 }
00318 }
00319 value = *pdata;
00320 pdata++;
00321 }
00322 }
00323 if( psubevt->GetSubcrate() == 2)
00324 {
00325 pdata=psubevt->GetDataField();
00326 lwords= (psubevt->GetDlen() -2) * sizeof(Short_t)/sizeof(Int_t);
00327 if(lwords >= 8) lwords=8;
00328 for(Int_t i = 0; i<lwords; ++i)
00329 {
00330 index=*pdata&0xfff;
00331 value=(*pdata>>16)&0xfff;
00332 if(*pdata != 0)
00333 {
00334 poutevt->fiCrate2[i] = *pdata;
00335 fCr2Ch[i]->Fill((Float_t)(*pdata));
00336 }
00337 pdata++;
00338 }
00339 }
00340 }
00341 poutevt->SetValid(kTRUE);
00342 }
00343 else cout << "XXXUnpackProc: no input event !"<< endl;
00344 }
00345
00346