00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TYYYUnpackProc.h"
00015
00016 #include "TClass.h"
00017 #include "TCanvas.h"
00018 #include "TMath.h"
00019 #include "TH1.h"
00020 #include "TH2.h"
00021 #include "TCutG.h"
00022 #include "TMath.h"
00023
00024 #include "TGo4Log.h"
00025 #include "TGo4WinCond.h"
00026 #include "TGo4PolyCond.h"
00027
00028 #include "TYYYUnpackEvent.h"
00029 #include "TYYYRawEvent.h"
00030 #include "TYYYParameter.h"
00031
00032
00033 TYYYUnpackProc::TYYYUnpackProc() :
00034 TGo4EventProcessor(),
00035 fX(0),fY(0),fZ(0),fVX(0),fVY(0),fVZ(0),fNumScatt(0),
00036 fXY(0),fVXVY(0), fXYCond(0), fVXVYCond(0), fEmitX(0), fEmitY(0), fEmitDist(0),
00037 fWinConR(0), fWinConV(0), fPolyConEmit(0),
00038 fParam1(0)
00039 {
00040 }
00041
00042 TYYYUnpackProc::TYYYUnpackProc(const char* name) :
00043 TGo4EventProcessor(name),
00044 fX(0),fY(0),fZ(0),fVX(0),fVY(0),fVZ(0),fNumScatt(0),
00045 fXY(0),fVXVY(0), fXYCond(0), fVXVYCond(0), fEmitX(0), fEmitY(0), fEmitDist(0),
00046 fWinConR(0), fWinConV(0), fPolyConEmit(0),
00047 fParam1(0)
00048 {
00049 TGo4Log::Info("TYYYUnpackProc: Create %s", name);
00050
00052
00053 fParam1 = (TYYYParameter *) GetParameter("YYYPar1");
00054 fParam1->PrintParameter(0,0);
00055
00056 fX = MakeTH1('D', "Position/Xfinal", "Scatt sim x (nm)",1000,-1e7,1e+7);
00057 fY = MakeTH1('D', "Position/Yfinal", "Scatt sim y (nm)",1000,-1e7,1e+7);
00058 fZ = MakeTH1('D', "Position/Zfinal", "Scatt sim z (nm)",1000, 1., 1e+8);
00059
00060 fVX = MakeTH1('D', "Velocity/Vxfinal", "Scatt sim vx (nm/ps)",10000, -5e+3,5e+3);
00061 fVY = MakeTH1('D', "Velocity/Vyfinal", "Scatt sim vy (nm/ps)",10000, -5e+3,5e+3);
00062 fVZ = MakeTH1('D', "Velocity/Vzfinal", "Scatt sim vz (nm/ps)",10000, 1.,3e+4);
00063 fThetaX=MakeTH1('D', "Angle/thetax", "Scatt sim x' (mrad)",10000, -5e+2,5e+2);
00064 fThetaY=MakeTH1('D', "Angle/thetay", "Scatt sim y' (mrad)",10000, -5e+2,5e+2);
00065 fThetaR=MakeTH1('D', "Angle/thetaR", "Scatt sim r' (mrad)",10000, 0,2e+3);
00066 fNumScatt = MakeTH1('D', "Nscatt", "Multiple scattering collisions",50000, 0, 50000.);
00067
00068 fXY = MakeTH2('D', "Position/X-Y","x versus y final",100,-1e7,1e+7,100,-1e+7,1e+7);
00069 fVXVY = MakeTH2('D', "Velocity/Vx-Vy","vx versus vy final",1000,-5e+3,5e+3,1000,-5e+3,5e+3);
00070 fXYCond = MakeTH2('D', "Position/X-Y-cond","x versus y final",1000,-1e+7,1e+7,1000,-1e+7,1e+7);
00071 fVXVYCond = MakeTH2('D', "Velocity/Vx-Vy-cond","vx versus vy final",100,-1e+3,1e+3,100,-1e+3,1e+3);
00072
00073 fEmitX = MakeTH2('D', "X-X'","transverse emittance x",1000,-1e+7,1e+7,1000,-0.1,0.1);
00074 fEmitY = MakeTH2('D', "Y-Y'","transverse emittance y",1000,-1e+7,1e+7,1000,-0.1,0.1);
00075 fEmitDist = MakeTH1('D', "Emit4d","transverse emittance distribution",4000,0,2e+5);
00076
00077 fWinConR = MakeWinCond("RCondition", 50., 70.);
00078 fWinConV = MakeWinCond("VCondition", 50, 70, 90, 120);
00079 if (IsObjMade()) {
00080 fWinConV->Disable(true);
00081 fWinConV->Invert(kTRUE);
00082 }
00083
00084 Double_t cutpnts[3][2] = { {400, 800}, {700, 900}, {600, 1100} };
00085 fPolyConEmit = MakePolyCond("EmittCondition", 3, cutpnts);
00086
00087 fWinConR->PrintCondition(true);
00088 fPolyConEmit->PrintCondition(true);
00089
00090 if (GetCanvas("TestCanvas2")==0) {
00091 TCanvas* mycan = new TCanvas("TestCanvas2","Does this work2?");
00092 mycan->Divide(2,2);
00093 AddCanvas(mycan);
00094 }
00095 }
00096
00097 TYYYUnpackProc::~TYYYUnpackProc()
00098 {
00099 fWinConR->PrintCondition(true);
00100 fPolyConEmit->PrintCondition(true);
00101 }
00102
00103
00104 Bool_t TYYYUnpackProc::CheckEventClass(TClass* cl)
00105 {
00106 return cl->InheritsFrom(TYYYUnpackEvent::Class());
00107 }
00108
00109
00110
00111
00112 Bool_t TYYYUnpackProc::BuildEvent(TGo4EventElement* dest)
00113 {
00114 TYYYRawEvent *inp = dynamic_cast<TYYYRawEvent*> (GetInputEvent());
00115
00116 TYYYUnpackEvent* poutevt = (TYYYUnpackEvent*) (dest);
00117
00118 if ((inp==0) || (poutevt==0)) {
00119 TGo4Log::Error("YYYUnpackProc: events are not specified!");
00120 return kFALSE;
00121 }
00122
00123
00124 for(Int_t i=0; i<3;++i)
00125 {
00126 poutevt->fdR[i] = inp->fdData[i];
00127 poutevt->fdV[i] = inp->fdData[i+3];
00128 }
00129 poutevt->fdR[0]-=5e+6;
00130 poutevt->fdR[1]-=5e+6;
00131 poutevt->fiNumScatt= (Int_t) inp->fdData[6];
00132
00133 if(poutevt->fdV[2]) poutevt->fdGam[0]=poutevt->fdV[0]/poutevt->fdV[2];
00134 if(poutevt->fdV[2]) poutevt->fdGam[1]=poutevt->fdV[1]/poutevt->fdV[2];
00135 Double_t scalefact=1e-3;
00136 poutevt->fdEmittX=poutevt->fdR[0]*poutevt->fdGam[0]*TMath::Pi()*scalefact;
00137 poutevt->fdEmittY=poutevt->fdR[1]*poutevt->fdGam[1]*TMath::Pi()*scalefact;
00138 poutevt->fdEmitt4d=poutevt->fdEmittX*poutevt->fdEmittY;
00139
00140 fX->Fill(poutevt->fdR[0]);
00141 fY->Fill(poutevt->fdR[1]);
00142 fZ->Fill(poutevt->fdR[2]);;
00143 fVX->Fill(poutevt->fdV[0]);
00144 fVY->Fill(poutevt->fdV[1]);
00145 fVZ->Fill(poutevt->fdV[2]);
00146 if(poutevt->fdV[2])
00147 {
00148 fThetaX->Fill(poutevt->fdV[0]/poutevt->fdV[2] * 1000);
00149 fThetaY->Fill(poutevt->fdV[1]/poutevt->fdV[2] * 1000);
00150 fThetaR->Fill(TMath::Sqrt(poutevt->fdV[1]*poutevt->fdV[1] + poutevt->fdV[0]*poutevt->fdV[0])/poutevt->fdV[2] * 1000);
00151 }
00152 fNumScatt->Fill(poutevt->fiNumScatt);
00153 fXY->Fill(poutevt->fdR[0],poutevt->fdR[1]);
00154 fVXVY->Fill(poutevt->fdV[0],poutevt->fdV[1]);
00155 if(fWinConR->Test(poutevt->fdR[0],poutevt->fdR[1]))
00156 fXYCond->Fill(poutevt->fdR[0],poutevt->fdR[1]);
00157 if(fWinConV->Test(poutevt->fdV[0],poutevt->fdV[1]))
00158 fVXVYCond->Fill(poutevt->fdV[0],poutevt->fdV[1]);
00159 fEmitX->Fill(poutevt->fdR[0],poutevt->fdGam[0]);
00160 fEmitY->Fill(poutevt->fdR[1],poutevt->fdGam[1]);
00161 fEmitDist->Fill(poutevt->fdEmitt4d);
00162
00163 return kTRUE;
00164 }