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