00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TXXXUnpackProc.h"
00015 #include "TGo4UserException.h"
00016
00017 #include <time.h>
00018 #include "TROOT.h"
00019
00020 #include "TH1.h"
00021 #include "TF1.h"
00022 #include "TH2.h"
00023 #include "TCutG.h"
00024 #include "TArc.h"
00025
00026 #include "s_filhe_swap.h"
00027 #include "s_bufhe_swap.h"
00028
00029 #include "TGo4Log.h"
00030 #include "TGo4MbsEvent.h"
00031 #include "TGo4WinCond.h"
00032 #include "TGo4PolyCond.h"
00033 #include "TGo4CondArray.h"
00034 #include "TGo4Picture.h"
00035
00036 #include "TXXXParameter.h"
00037 #include "TXXXUnpackEvent.h"
00038
00039
00040 TXXXUnpackProc::TXXXUnpackProc() :
00041 TGo4EventProcessor(),
00042 fCr1Ch1x2(0),
00043 fHis1(0),
00044 fHis1gate(0),
00045 fHis2(0),
00046 fHis2gate(0),
00047 fconHis1(0),
00048 fconHis2(0),
00049 fWinCon1(0),
00050 fWinCon2(0),
00051 fPolyCon1(0),
00052 fConArr1(0),
00053 fConArr2(0),
00054 fParam(0),
00055 fPicture1(0),
00056 fcondSet(0),
00057 fLaText(0)
00058 {
00059 for (int n=0;n<XXX_NUM_CHAN;n++) {
00060 fCr1Ch[n] = 0;
00061 fCr2Ch[n] = 0;
00062 }
00063 }
00064
00065 TXXXUnpackProc::TXXXUnpackProc(const char* name) :
00066 TGo4EventProcessor(name),
00067 fCr1Ch1x2(0),
00068 fHis1(0),
00069 fHis1gate(0),
00070 fHis2(0),
00071 fHis2gate(0),
00072 fconHis1(0),
00073 fconHis2(0),
00074 fWinCon1(0),
00075 fWinCon2(0),
00076 fPolyCon1(0),
00077 fConArr1(0),
00078 fConArr2(0),
00079 fParam(0),
00080 fPicture1(0),
00081 fcondSet(0),
00082 fLaText(0)
00083 {
00084 for (int n=0;n<XXX_NUM_CHAN;n++) {
00085 fCr1Ch[n] = 0;
00086 fCr2Ch[n] = 0;
00087 }
00088
00089 TGo4Log::Info("TXXXUnpackProc: Create");
00090
00092
00093
00094 fParam = (TXXXParameter*) MakeParameter("XXXParameter","TXXXParameter" ,"set_Par.C");
00095
00096
00097 fWinCon1 = (TGo4WinCond *) GetAnalysisCondition("wincon1", "TGo4WinCond");
00098
00099 if(fParam->fbHisto){
00100
00101 TGo4Log::Info("TXXXUnpackProc: Produce histograms");
00102
00103 for(int i=0;i<XXX_NUM_CHAN;i++) {
00104 fCr1Ch[i] = MakeTH1('I', Form("Crate1/Cr1Ch%02d",i+1), Form("Crate 1 channel %2d",i+1), 5000, 1., 5001.);
00105 fCr2Ch[i] = MakeTH1('I', Form("Crate2/Cr2Ch%02d",i+1), Form("Crate 2 channel %2d",i+1), 5000, 1., 5001.);
00106 }
00107
00108 fCr1Ch1x2 = MakeTH2('I', "Cr1Ch1x2","Crate 1 channel 1x2", 200, 1., 5001., 200, 1., 5001.);
00109 fHis1 = MakeTH1('I', "His1","Condition histogram", 5000, 1., 5001.);
00110 fHis2 = MakeTH1('I', "His2","Condition histogram", 5000, 1., 5001.);
00111 fHis1gate = MakeTH1('I', "His1g","Gated histogram", 5000, 1., 5001.);
00112 fHis2gate = MakeTH1('I', "His2g","Gated histogram", 5000, 1., 5001.);
00113
00114 TGo4Log::Info("TXXXUnpackProc: Produce conditions");
00115
00116
00117 fWinCon2 = MakeWinCond("wincon2", 50, 70, 90, 120);
00118 fconHis1 = MakeWinCond("cHis1", 100, 2000, "His1");
00119 fconHis2 = MakeWinCond("cHis2", 100, 2000, "His2");
00120
00121 Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
00122 fPolyCon1 = MakePolyCond("polycon", 3, cutpnts);
00123
00124 fConArr1 = (TGo4CondArray*)GetAnalysisCondition("winconar");
00125 if (fConArr1==0) {
00126 fConArr1 = new TGo4CondArray("winconar",30,"TGo4WinCond");
00127 fConArr1->SetValues(100,500);
00128 fConArr1->Disable(true);
00129 ((*fConArr1)[0])->SetValues(200,400);
00130 ((*fConArr1)[1])->SetValues(700,1000);
00131 ((*fConArr1)[2])->SetValues(1500,2000);
00132 fConArr1->SetHistogram("Sum3");
00133 AddAnalysisCondition(fConArr1);
00134 } else {
00135 fConArr1->ResetCounts();
00136 }
00137
00138 fConArr2 = (TGo4CondArray*)GetAnalysisCondition("polyconar");
00139 if(fConArr2==0) {
00140
00141 TGo4Log::Info("TXXXUnpackProc: Create condition polyconar");
00142 Double_t xvalues[4] = { 1000, 2000, 1500, 1000 };
00143 Double_t yvalues[4] = { 1000, 1000, 3000, 1000 };
00144 TCutG* mycut = new TCutG("cut2", 4, xvalues, yvalues);
00145 fConArr2 = new TGo4CondArray("polyconar",4,"TGo4PolyCond");
00146 fConArr2->SetValues(mycut);
00147 fConArr2->Disable(true);
00148 delete mycut;
00149 AddAnalysisCondition(fConArr2);
00150 } else {
00151 TGo4Log::Info("TXXXUnpackProc: Restore condition polyconar from autosave");
00152 fConArr2->ResetCounts();
00153 }
00154
00155
00156 fWinCon1->Enable();
00157 fWinCon2->Disable(true);
00158 fWinCon2->Invert(kTRUE);
00159 fWinCon1->PrintCondition(true);
00160 fconHis1->PrintCondition(true);
00161 fconHis2->PrintCondition(true);
00162 fPolyCon1->Enable();
00163 fPolyCon1->PrintCondition(true);
00164 ((*fConArr2)[0])->Enable();
00165 ((*fConArr2)[1])->Enable();
00166
00167 fcondSet = GetPicture("condSet");
00168 if (fcondSet==0) {
00169
00170
00171 fcondSet = new TGo4Picture("condSet","Set conditions");
00172 fcondSet->SetDivision(2,2);
00173 fcondSet->Pic(0,0)->AddObject(fHis1);
00174 fcondSet->Pic(0,1)->AddObject(fHis2);
00175 fcondSet->Pic(0,0)->AddCondition(fconHis1);
00176 fcondSet->Pic(0,1)->AddCondition(fconHis2);
00177 fcondSet->Pic(1,0)->AddObject(fHis1gate);
00178 fcondSet->Pic(1,1)->AddObject(fHis2gate);
00179 fcondSet->Pic(1,0)->SetFillAtt(4, 1001);
00180 fcondSet->Pic(1,0)->SetLineAtt(4,1,1);
00181 fcondSet->Pic(1,1)->SetFillAtt(9, 1001);
00182 fcondSet->Pic(1,1)->SetLineAtt(9,1,1);
00183 fcondSet->Pic(0,0)->SetTitleAttr(0.05, 0.85, 0.8, 0.95);
00184
00185
00189
00190
00191
00192
00193
00194
00195 AddPicture(fcondSet);
00196 }
00197
00198
00199 fLaText = new TLatex(0.5,0.5,"-- demo text --");
00200 fLaText->SetName("LatexObjectDemo");
00201 fLaText->SetNDC();
00202 AddObject(fLaText);
00203
00204 fPicture1 = GetPicture("Picture1");
00205 if (fPicture1 == 0) {
00206 fPicture1 = new TGo4Picture("Picture1","Picture example");
00207 fPicture1->SetLinesDivision(3, 2,3,1);
00208
00209 fPicture1->LPic(0,0)->AddObject(fCr1Ch[0]);
00210 fPicture1->LPic(0,0)->SetFillAtt(5, 3001);
00211 fPicture1->LPic(0,0)->SetLineAtt(5,1,1);
00212 fPicture1->LPic(0,0)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00213 fPicture1->LPic(0,0)->SetAxisLabelFontSize(0, 0.07, 0);
00214 fPicture1->LPic(0,0)->SetAxisLabelFontSize(1, 0.07, 0);
00215 fPicture1->LPic(0,0)->SetHisTitle(false);
00216 fPicture1->LPic(0,0)->SetTitleAttr(0.1,0.75,0.7,0.9);
00217
00218 fPicture1->LPic(0,0)->AddObject(fLaText);
00219
00220 fPicture1->LPic(0,1)->AddObject(fCr1Ch[1]);
00221 fPicture1->LPic(0,1)->SetFillAtt(4, 3001);
00222 fPicture1->LPic(0,1)->SetLineAtt(4,1,1);
00223 fPicture1->LPic(0,1)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00224 fPicture1->LPic(0,1)->SetAxisLabelFontSize(0, 0.07, 0);
00225 fPicture1->LPic(0,1)->SetAxisLabelFontSize(1, 0.07, 0);
00226 fPicture1->LPic(0,1)->SetHisTitle(false);
00227 fPicture1->LPic(0,1)->SetTitleAttr(0.1,0.75,0.7,0.9);
00228
00229 fPicture1->LPic(1,0)->AddObject(fCr1Ch[2]);
00230 fPicture1->LPic(1,0)->SetFillAtt(6, 1001);
00231 fPicture1->LPic(1,0)->SetLineAtt(6,1,1);
00232 fPicture1->LPic(1,0)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00233 fPicture1->LPic(1,0)->SetAxisLabelFontSize(0, 0.07, 0);
00234 fPicture1->LPic(1,0)->SetAxisLabelFontSize(1, 0.07, 0);
00235 fPicture1->LPic(1,0)->SetHisTitle(false);
00236 fPicture1->LPic(1,0)->SetTitleAttr(0.1,0.75,0.7,0.9);
00237
00238 fPicture1->LPic(1,1)->AddObject(fCr1Ch[3]);
00239 fPicture1->LPic(1,1)->SetFillAtt(7, 1001);
00240 fPicture1->LPic(1,1)->SetLineAtt(7,1,1);
00241 fPicture1->LPic(1,1)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00242 fPicture1->LPic(1,1)->SetAxisLabelFontSize(0, 0.07, 0);
00243 fPicture1->LPic(1,1)->SetAxisLabelFontSize(1, 0.07, 0);
00244 fPicture1->LPic(1,1)->SetHisTitle(false);
00245 fPicture1->LPic(1,1)->SetTitleAttr(0.1,0.75,0.7,0.9);
00246
00247 fPicture1->LPic(1,2)->AddObject(fCr1Ch[4]);
00248 fPicture1->LPic(1,2)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00249 fPicture1->LPic(1,2)->SetAxisLabelFontSize(0, 0.07, 0);
00250 fPicture1->LPic(1,2)->SetAxisLabelFontSize(1, 0.07, 0);
00251 fPicture1->LPic(1,2)->SetHisTitle(false);
00252 fPicture1->LPic(1,2)->SetTitleAttr(0.1,0.75,0.7,0.9);
00253
00254 fPicture1->LPic(2,0)->AddObject(fCr1Ch1x2);
00255 fPicture1->LPic(2,0)->SetDrawOption("CONT");
00256 fPicture1->LPic(2,0)->SetStatsAttr(0.1,0.6,0.4,0.9,101);
00257 fPicture1->LPic(2,0)->SetAxisLabelFontSize(0, 0.07, 0);
00258 fPicture1->LPic(2,0)->SetAxisLabelFontSize(1, 0.07, 0);
00259 fPicture1->LPic(2,0)->SetHisTitle(false);
00260 fPicture1->LPic(2,0)->SetTitleAttr(0.1,0.75,0.7,0.9);
00261 AddPicture(fPicture1);
00262 }
00263 }
00264 }
00265
00266 TXXXUnpackProc::~TXXXUnpackProc()
00267 {
00268 TGo4Log::Info("TXXXUnpackProc: Delete");
00269 if(fParam->fbHisto){
00270 fWinCon1->PrintCondition(true);
00271 fPolyCon1->PrintCondition(true);
00272 }
00273 }
00274
00275 Bool_t TXXXUnpackProc::BuildEvent(TGo4EventElement* dest)
00276 {
00277 Bool_t isValid=kFALSE;
00278
00279 TGo4MbsEvent* inp_evt = (TGo4MbsEvent* ) GetInputEvent();
00280 TXXXUnpackEvent* out_evt = (TXXXUnpackEvent*) dest;
00281
00282 if (inp_evt==0) {
00283 TGo4Log::Error("XXXUnpackProc: no input event !");
00284 out_evt->SetValid(isValid);
00285
00286 return isValid;
00287 }
00288 isValid=kTRUE;
00289
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00310
00311
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00330
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00350
00351
00352 inp_evt->ResetIterator();
00353 TGo4MbsSubEvent* psubevt(0);
00354 while ((psubevt = inp_evt->NextSubEvent()) != 0)
00355 {
00356 if( psubevt->GetSubcrate() == 1)
00357 {
00358 Int_t* pdata = psubevt->GetDataField();
00359 Int_t lwords = psubevt->GetIntLen();
00360 if(lwords > XXX_NUM_CHAN) lwords = XXX_NUM_CHAN;
00361 Int_t lastvalue = 0;
00362 for(Int_t i = 0; i<lwords; ++i)
00363 {
00364
00365
00366 if(*pdata != 0)
00367 {
00368 out_evt->fiCrate1[i] = *pdata;
00369
00370 if (fCr1Ch[i]) fCr1Ch[i]->Fill(*pdata);
00371
00372 if(fParam->fbHisto) {
00373 if(i == 0)
00374 {
00375 if(fconHis1->Test(*pdata)) fHis1gate->Fill(*pdata);
00376 fHis1->Fill(*pdata);
00377 }
00378 if(i == 1)
00379 {
00380 if(fconHis2->Test(*pdata)) fHis2gate->Fill(*pdata);
00381 fHis2->Fill(*pdata);
00382
00383 if(fPolyCon1->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill(*pdata, lastvalue);
00384 if(((*fConArr2)[0])->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill(*pdata, lastvalue);
00385 if(((*fConArr2)[1])->Test(*pdata,lastvalue)) fCr1Ch1x2->Fill(*pdata, lastvalue);
00386 }
00387 }
00388 }
00389 lastvalue = *pdata;
00390 pdata++;
00391 }
00392 }
00393 if( psubevt->GetSubcrate() == 2)
00394 {
00395 Int_t* pdata = psubevt->GetDataField();
00396 Int_t lwords = psubevt->GetIntLen();
00397 if(lwords > XXX_NUM_CHAN) lwords=XXX_NUM_CHAN;
00398 for(Int_t i = 0; i<lwords; ++i) {
00399 if(*pdata != 0) {
00400 out_evt->fiCrate2[i] = *pdata;
00401 if(fCr2Ch[i]) fCr2Ch[i]->Fill((Float_t)(*pdata));
00402 }
00403 pdata++;
00404 }
00405 }
00406 }
00407
00408
00409 if (fLaText)
00410 fLaText->SetText(0.5,0.5,Form("#scale[3.0]{#color[2]{Event number:%d}}",inp_evt->GetCount()));
00411
00412 out_evt->SetValid(isValid);
00413
00414
00415 return isValid;
00416
00417
00418 }