TNeProc.cxx 35.4 KB
Newer Older
Pavel Sharov's avatar
Pavel Sharov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//===================================================================
//==   EXPERIMENT A-2
//==   VERSION:   30.10.2018
//===================================================================
using namespace std;

#include "TNeProc.h"

#include <stdint.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "Riostream.h"

#include "TH1.h"
#include "TH2.h"
#include "TROOT.h"
#include "TCutG.h"
#include "TGo4WinCond.h"
#include "TGo4PolyCond.h"
#include "TGo4CondArray.h"
#include "TGo4Picture.h"
#include "TGo4MbsEvent.h"
#include "snprintf.h"
Pavel Sharov's avatar
Pavel Sharov committed
25

Pavel Sharov's avatar
Pavel Sharov committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include "TNeEvent.h"
#include "TNeDet16.h"
#include "TNeAnalysis.h"
#include "TRandom.h"
#include "TNeMParms.h"

//#include "TNeSel.h"

long TNeProc::bit[32] =
  {0x00000001, 0x00000002, 0x00000004, 0x00000008
   ,0x00000010, 0x00000020, 0x00000040, 0x00000080
   ,0x00000100, 0x00000200, 0x00000400, 0x00000800
   ,0x00001000, 0x00002000, 0x00004000, 0x00008000
   ,0x00010000, 0x00020000, 0x00040000, 0x00080000
   ,0x00100000, 0x00200000, 0x00400000, 0x00800000
   ,0x01000000, 0x02000000, 0x04000000, 0x08000000
   ,0x10000000, 0x20000000, 0x40000000, 0x80000000};


TNeProc::TNeProc() : TGo4EventProcessor()
{
	int i;
	cout << "**** TNeProc: Create instance " << endl;
	fTrigger = NULL;
	fSubEvents = NULL;
	fEventsSizes = NULL;

	for(i = 0; i < 4; ++i)
	{
		d1F3[i] = NULL;
		d1tF3[i] = NULL;
		d1F5[i] = NULL;
		d1tF5[i] = NULL;

		d1tMWPC[i] = NULL;

	}

	for(i = 0; i < 16; ++i)
	{
66 67 68 69 70 71 72 73 74 75 76 77 78
//-----Si-----
		d1Lxa[i] = NULL;
		d1Lxt[i] = NULL;
		d1Lxc[i] = NULL;
		d1Lya[i] = NULL;
		d1Lyt[i] = NULL;
		d1Lyc[i] = NULL;
		d1Rxa[i] = NULL;
		d1Rxt[i] = NULL;
		d1Rxc[i] = NULL;
		d1Rya[i] = NULL;
		d1Ryt[i] = NULL;
		d1Ryc[i] = NULL;
mbsdaq's avatar
mbsdaq committed
79 80 81
		d1Rva[i] = NULL;
		d1Rvt[i] = NULL;
		d1Rvc[i] = NULL;
Pavel Sharov's avatar
Pavel Sharov committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
	}
//_________________________________Neutrons
//
	d1ToF    = NULL;
	d1aF3    = NULL;
	d2ToFaF3 = NULL;
	d1aF5    = NULL;
	d2ToFaF5 = NULL;

	d1X1 = NULL;
	d1Y1 = NULL;
	d1X2 = NULL;
	d1Y2 = NULL;
	d1NX1 = NULL;
	d1NY1 = NULL;
	d1NX2 = NULL;
	d1NY2 = NULL;
	d2XY1 = NULL;
	d2XY2 = NULL;

	d1CX1 = NULL;
	d1CY1 = NULL;
	d1CX2 = NULL;
	d1CY2 = NULL;
mbsdaq's avatar
mbsdaq committed
106
	d2XYbeamOnTar = NULL;
Pavel Sharov's avatar
Pavel Sharov committed
107 108 109 110 111 112 113 114 115

} //-------------------------------------------------------------------

TNeProc::~TNeProc()
{
	cout << "**** TNeProc: Delete instance " << endl;
} //-------------------------------------------------------------------

TNeProc::TNeProc(const char* name) : TGo4EventProcessor(name)
Pavel Sharov's avatar
Pavel Sharov committed
116
{
Pavel Sharov's avatar
Pavel Sharov committed
117 118 119 120 121 122 123
	TGo4Log::Info("**** TNeProc: Create instance %s", name);
	fTrigger    = MakeTH1('I', "Trigger",    "Values of trigger",   16, 0., 15.);
	fSubEvents  = MakeTH1('I', "SubEvents",  "Number of subevents", 16, 0, 15);
	fEventsSizes = MakeTH1('I', "EventSizes", "Size of each event", 1024, 0, 1023);
	int i;
	for (i = 0; i < 16; ++i) {
//-----SQ telescope raw-----
Pavel Sharov's avatar
Pavel Sharov committed
124
		d1Lxa[i]   = MakeTH1('I', Form("Lxa/Lxas_%2.2d",i)			//указывать не повторяющуюся структуру папок и уникальные имена
125 126 127 128 129 130
				, Form("L x amp CH %2.2d",i), 8192, 0., 8192.);
		d1Lxt[i]   = MakeTH1('I', Form("Lxt/Lxts_%2.2d",i)
				, Form("L x time CH %2.2d",i), 4096, 1., 4096);
		d1Lxc[i]   = MakeTH1('D', Form("Lxc/Lxcs_%2.2d",i)
				, Form("L x energy MeV %2.2d",i), 4000, -2., 98.);
//
Pavel Sharov's avatar
Pavel Sharov committed
131
		d1Lya[i]   = MakeTH1('I', Form("Lya/Lyas_%2.2d",i)			//указывать не повторяющуюся структуру папок и уникальные имена
132 133 134 135 136 137
				, Form("L x amp CH %2.2d",i), 8192, 0., 8192.);
		d1Lyt[i]   = MakeTH1('I', Form("Lyt/Lyts_%2.2d",i)
				, Form("L x time CH %2.2d",i), 4096, 1, 4096);
		d1Lyc[i]   = MakeTH1('D', Form("Lyc/Lycs_%2.2d",i)
//
				, Form("L x energy MeV %2.2d",i), 4000, -2., 98.);
mbsdaq's avatar
mbsdaq committed
138
		d1Rxa[i]   = MakeTH1('I', Form("Rxa/Rxas_%2.2d",i)			
139 140 141 142 143 144
				, Form("R x amp CH %2.2d",i), 8192, 0., 8192.);
		d1Rxt[i]   = MakeTH1('I', Form("Rxt/Rxts_%2.2d",i)
				, Form("R x time CH %2.2d",i), 4096, 1., 4096);
		d1Rxc[i]   = MakeTH1('D', Form("Rxc/Rxcs_%2.2d",i)
				, Form("R x energy MeV %2.2d",i), 4000, -2., 98.);
//
mbsdaq's avatar
mbsdaq committed
145
		d1Rya[i]   = MakeTH1('I', Form("Rya/Ryas_%2.2d",i)			
146 147 148 149 150 151
				, Form("R x amp CH %2.2d",i), 8192, 0., 8192.);
		d1Ryt[i]   = MakeTH1('I', Form("Ryt/Ryts_%2.2d",i)
				, Form("R x time CH %2.2d",i), 4096, 1, 4096);
		d1Ryc[i]   = MakeTH1('D', Form("Ryc/Rycs_%2.2d",i)
				, Form("R x energy MeV %2.2d",i), 4000, -2., 98.);
//
mbsdaq's avatar
mbsdaq committed
152 153 154 155 156 157 158 159
		d1Rva[i]   = MakeTH1('I', Form("Rva/Rvas_%2.2d",i)			
				, Form("R veto amp CH %2.2d",i), 8192, 0., 8192.);
		d1Rvt[i]   = MakeTH1('I', Form("Rvt/Rvts_%2.2d",i)
				, Form("R veto time CH %2.2d",i), 4096, 1, 4096);
		d1Rvc[i]   = MakeTH1('D', Form("Rvc/Rvcs_%2.2d",i)
				, Form("R veto energy MeV %2.2d",i), 4000, -2., 98.);
//
		d1AnSa[i]   = MakeTH1('I', Form("AnSa/AnSas_%2.2d",i)		
160 161 162 163 164 165
				, Form("Sect amp CH %2.2d",i), 8192, 0., 8192.);
		d1AnSt[i]   = MakeTH1('I', Form("AnSt/AnSts_%2.2d",i)
				, Form("Sect time CH %2.2d",i), 4096, 1, 4096);
		d1AnSc[i]   = MakeTH1('D', Form("AnSc/AnScs_%2.2d",i)
				, Form("Sect energy MeV %2.2d",i), 4000, -2., 98.);
//
mbsdaq's avatar
mbsdaq committed
166
		d1AnRa[i]   = MakeTH1('I', Form("AnRa/AnRas_%2.2d",i)		
167 168 169 170 171
				, Form("Ring amp CH %2.2d",i), 8192, 0., 8192.);
		d1AnRt[i]   = MakeTH1('I', Form("AnRt/AnRts_%2.2d",i)
				, Form("Ring time CH %2.2d",i), 4096, 1, 4096);
		d1AnRc[i]   = MakeTH1('D', Form("AnRc/AnRcs_%2.2d",i)
				, Form("Ring energy MeV %2.2d",i), 4000, -2., 98.);
mbsdaq's avatar
mbsdaq committed
172 173 174 175 176 177 178 179

		d1AnVa[i]   = MakeTH1('I', Form("AnVa/AnVas_%2.2d",i)		
				, Form("Veto amp CH %2.2d",i), 8192, 0., 8192.);
		d1AnVt[i]   = MakeTH1('I', Form("AnVt/AnVts_%2.2d",i)
				, Form("Veto time CH %2.2d",i), 4096, 1, 4096);
		d1AnVc[i]   = MakeTH1('D', Form("AnVc/AnVcs_%2.2d",i)
				, Form("Veto energy MeV %2.2d",i), 4000, -2., 98.);
//
Pavel Sharov's avatar
Pavel Sharov committed
180
	}
Pavel Sharov's avatar
Pavel Sharov committed
181 182
	for (int i = 0; i < 16; ++i) {
		d1Lcsa[i] = MakeTH1('I', Form("Lcsa/Lcsa_%02d",i),
mbsdaq's avatar
mbsdaq committed
183
				      Form("Lcs amp CH %02d",i), 8192, 0., 8192);
Pavel Sharov's avatar
Pavel Sharov committed
184 185 186
		d1Lcst[i] = MakeTH1('I', Form("Lcst/Lcst_%02d",i)
				, Form("Lcs time CH %02d",i), 4096, 1., 4095);
		d1Lcsc[i] = MakeTH1('D', Form("Lcsc/Lcsc_%02d",i),
mbsdaq's avatar
mbsdaq committed
187
				    Form("Lcs energy MeV %2.2d",i), 4000, 0.,  8192.);
Pavel Sharov's avatar
Pavel Sharov committed
188 189 190
	}
	for (int i = 0; i < 16; ++i) {
		d1Rcsa[i] = MakeTH1('I', Form("Rcsa/Rcsa_%02d",i),
mbsdaq's avatar
mbsdaq committed
191
				      Form("Rcs amp CH %02d",i), 8192, 0., 8192);
Pavel Sharov's avatar
Pavel Sharov committed
192 193 194 195 196 197 198
		d1Rcst[i] = MakeTH1('I', Form("Rcst/Rcst_%02d",i)
				, Form("Rcs time CH %02d",i), 4096, 1., 4095);
		d1Rcsc[i] = MakeTH1('D', Form("Rcsc/Rcsc_%02d",i),
				    Form("Rcs energy MeV %2.2d",i), 4000, -2., 98.);
	}
	for (int i = 0; i < 16; ++i) {
		d1R20a[i] = MakeTH1('I', Form("R20a/R20a_%02d",i),
mbsdaq's avatar
mbsdaq committed
199
				      Form("R20 amp CH %02d",i), 8192, 0., 8192);
Pavel Sharov's avatar
Pavel Sharov committed
200 201 202 203 204 205
		d1R20t[i] = MakeTH1('I', Form("R20t/R20t_%02d",i)
				, Form("R20 time CH %02d",i), 4096, 1., 4095);
		d1R20c[i] = MakeTH1('D', Form("R20c/R20c_%02d",i),
				    Form("R20 energy MeV %2.2d",i), 4000, -2., 98.);

	}
mbsdaq's avatar
mbsdaq committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225

	d2ede = MakeTH2('D', "ede", "ede", 200,0.,20.,200,0.,20.,"e","de");

	d2LyLcs1 = MakeTH2('D', "2D/LyLcs1", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs2 = MakeTH2('D', "2D/LyLcs2", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs3 = MakeTH2('D', "2D/LyLcs3", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs4 = MakeTH2('D', "2D/LyLcs4", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs5 = MakeTH2('D', "2D/LyLcs5", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs6 = MakeTH2('D', "2D/LyLcs6", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs7 = MakeTH2('D', "2D/LyLcs7", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs8 = MakeTH2('D', "2D/LyLcs8", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs9 = MakeTH2('D', "2D/LyLcs9", "Lx vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs10 = MakeTH2('D', "2D/LyLcs10", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs11 = MakeTH2('D', "2D/LyLcs11", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs12 = MakeTH2('D', "2D/LyLcs12", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs13 = MakeTH2('D', "2D/LyLcs13", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs14 = MakeTH2('D', "2D/LyLcs14", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs15 = MakeTH2('D', "2D/LyLcs15", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");
	d2LyLcs16 = MakeTH2('D', "2D/LyLcs16", "Ly vs Lcs", 200,0.,8200.,200,0.,80.,"Lcs","Ly");

Pavel Sharov's avatar
Pavel Sharov committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
//
	d1F3[0]   = MakeTH1('I',"F3/QDC/F3_QDC_L","F3 QDC  left", 4096, 0., 4095.);
	d1F3[1]   = MakeTH1('I',"F3/QDC/F3_QDC_R","F3 QDC right", 4096, 0., 4095.);
	d1F3[2]   = MakeTH1('I',"F3/QDC/F3_QDC_U","F3 QDC    up", 4096, 0., 4095.);
	d1F3[3]   = MakeTH1('I',"F3/QDC/F3_QDC_D","F3 QDC  down", 4096, 0., 4095.);
	d1tF3[0]  = MakeTH1('I',"F3/TDC/tF3_TDC_L","F3 TDC  left", 10000, 0, 9999);
	d1tF3[1]  = MakeTH1('I',"F3/TDC/tF3_TDC_R","F3 TDC right", 10000, 0, 9999);
	d1tF3[2]  = MakeTH1('I',"F3/TDC/tF3_TDC_U","F3 TDC    up", 10000, 0, 9999);
	d1tF3[3]  = MakeTH1('I',"F3/TDC/tF3_TDC_D","F3 TDC  down", 10000, 0, 9999);
//
	d1F5[0]   = MakeTH1('I',"F5/QDC/F5_QDC_L","F5 QDC  left", 4096, 0., 4095.);
	d1F5[1]   = MakeTH1('I',"F5/QDC/F5_QDC_R","F5 QDC right", 4096, 0., 4095.);
	d1F5[2]   = MakeTH1('I',"F5/QDC/F5_QDC_U","F5 QDC    up", 4096, 0., 4095.);
	d1F5[3]   = MakeTH1('I',"F5/QDC/F5_QDC_D","F5 QDC  down", 4096, 0., 4095.);
	d1tF5[0]  = MakeTH1('I',"F5/TDC/tF5_TDC_L","F5 TDC  left", 10000, 0, 9999);
	d1tF5[1]  = MakeTH1('I',"F5/TDC/tF5_TDC_R","F5 TDC right", 10000, 0, 9999);
	d1tF5[2]  = MakeTH1('I',"F5/TDC/tF5_TDC_U","F5 TDC    up", 10000, 0, 9999);
	d1tF5[3]  = MakeTH1('I',"F5/TDC/tF5_TDC_D","F5 TDC  down", 10000, 0, 9999);
//

//-----ToF-----
	d1ToF = MakeTH1('D', "ToF/ToF", "time of flight", 10000,-100.,400.,"ToF(ns)");

	d1aF3 = MakeTH1('D', "ToF/aF3", "amplitude of plastic F3", 4000,0.,4000.,"amp F3");
	d2ToFaF3 = MakeTH2('D', "ToF/ToFaF3", "ToF vs aF3", 400,50.,200.,400,0.,4000.,"ToF","aF3");

	d1aF5 = MakeTH1('D', "ToF/aF5", "amplitude of plastic F5", 4000,0.,4000.,"amp F5");
	d2ToFaF5 = MakeTH2('D', "ToF/ToFaF5", "ToF vs aF5", 400,50.,200.,400,0.,4000.,"ToF","aF5");

Pavel Sharov's avatar
Pavel Sharov committed
255 256

//-----MWPC-----
Pavel Sharov's avatar
Pavel Sharov committed
257 258
	d2XY1 = MakeTH2('I', "MWPC/XY1", "WIRES 1 Y1 vs X1", 32,0.,32.,32,0.,32.,"X1","Y1");
	d2XY2 = MakeTH2('I', "MWPC/XY2", "WIRES 2 Y2 vs X2", 32,0.,32.,32,0.,32.,"X2","Y2");
mbsdaq's avatar
mbsdaq committed
259 260
	d2XYbeamOnTar = MakeTH2('f', "MWPC/XY_beamOnTar", "beam profile at target", 200,-50.0,50.0,200,-50,50,"X(Z=-70.0mm)","Y(Z=-70.0mm)");
	
Pavel Sharov's avatar
Pavel Sharov committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	d1X1 = MakeTH1('I', "MWPC/X1","WIRES X1",32,0.,32.);
	d1Y1 = MakeTH1('I', "MWPC/Y1","WIRES Y1",32,0.,32.);
	d1X2 = MakeTH1('I', "MWPC/X2","WIRES X2",32,0.,32.);
	d1Y2 = MakeTH1('I', "MWPC/Y2","WIRES Y2",32,0.,32.);

	d1tMWPC[0]  = MakeTH1('I',"MWPC/tX1","MWPC TDC  X1", 10000, 0, 9999);
	d1tMWPC[1]  = MakeTH1('I',"MWPC/tY1","MWPC TDC  Y1", 10000, 0, 9999);
	d1tMWPC[2]  = MakeTH1('I',"MWPC/tX2","MWPC TDC  X2", 10000, 0, 9999);
	d1tMWPC[3]  = MakeTH1('I',"MWPC/tY2","MWPC TDC  Y2", 10000, 0, 9999);

	d1NX1 = MakeTH1('I', "MWPC/NX1","WIRES X1",32,0.,32.);
	d1NY1 = MakeTH1('I', "MWPC/NY1","WIRES Y1",32,0.,32.);
	d1NX2 = MakeTH1('I', "MWPC/NX2","WIRES X2",32,0.,32.);
	d1NY2 = MakeTH1('I', "MWPC/NY2","WIRES Y2",32,0.,32.);

	d1CX1 = MakeTH1('I', "MWPC/CX1","clusters X1",32,0.,32.);
	d1CY1 = MakeTH1('I', "MWPC/CY1","clusters Y1",32,0.,32.);
	d1CX2 = MakeTH1('I', "MWPC/CX2","clusters X2",32,0.,32.);
	d1CY2 = MakeTH1('I', "MWPC/CY2","clusters Y2",32,0.,32.);


//------

//------------------------------------------------------------
}//------------------------------------------------------------

Bool_t TNeProc::BuildEvent(TGo4EventElement* target)
{
// called by framework from TNeEvent to fill it

mbsdaq's avatar
mbsdaq committed
291
	TGo4Analysis *go4 = TGo4Analysis::Instance();
Pavel Sharov's avatar
Pavel Sharov committed
292 293

	TNeEvent* NeEvent = (TNeEvent*) target;
294
	target->Clear();
Pavel Sharov's avatar
Pavel Sharov committed
295 296 297
	TGo4MbsSubEvent* psubevt;

	TGo4MbsEvent* fInput = (TGo4MbsEvent* ) GetInputEvent();
Pavel Sharov's avatar
Pavel Sharov committed
298 299 300
	if(fInput == 0) {
		TGo4Log::Error( "TNeProc::BuildEvent: no input event !");
		return false;
Pavel Sharov's avatar
Pavel Sharov committed
301 302
	}
	bool dooutput = false;
mbsdaq's avatar
mbsdaq committed
303 304 305 306
	double value1, value2;
	double eLxa = 0,eLya = 0, eRxa = 0, eRya = 0, eR20a = 0, eRva = 0, eAnSa = 0, eAnRa = 0, eRcsa = 0, eLcsa = 0;
	int mLxa = 0, mLya = 0, mRxa = 0, mRya = 0, mR20a = 0, mRva = 0, mAnSa = 0, mAnRa = 0, mRcsa = 0, mLcsa = 0;
	int nLxa = -1, nLya = -1, nRxa = -1, nRya = -1, nR20a = -1, nRva = -1, nAnSa = -1, nAnRa = -1, nRcsa = -1, nLcsa = -1;
Pavel Sharov's avatar
Pavel Sharov committed
307 308
//
	int num = 0, sz = 0;
Pavel Sharov's avatar
Pavel Sharov committed
309
	int i, n, geo, typ, header,caen_header, module_id=0, crate=-1, cnt, chnl, evnt /*,gch*/;
Pavel Sharov's avatar
Pavel Sharov committed
310 311 312 313 314
//	int mDSD_X, mDSD_Y, mCsI;
	bool m_bool= false, c_bool = false;
	uint16_t MSB, LSB;
	uint32_t MSBLSB, adc;
	uint32_t *idata;
Pavel Sharov's avatar
Pavel Sharov committed
315

Pavel Sharov's avatar
Pavel Sharov committed
316 317 318 319 320 321 322 323
	double af3=0., af5=0., tf3=0., tf5=0., ToF=0.;

	fInput->ResetIterator();
	while((psubevt = fInput->NextSubEvent()) != 0)
	{
		num++;
		sz += psubevt->GetIntLen();
		idata = (uint32_t*) psubevt->GetDataField();
Pavel Sharov's avatar
Pavel Sharov committed
324

Pavel Sharov's avatar
Pavel Sharov committed
325
		n = -1;
Pavel Sharov's avatar
Pavel Sharov committed
326
		while(++n < psubevt->GetIntLen())
Pavel Sharov's avatar
Pavel Sharov committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
		{
			header = idata[n]  >> 24;
			caen_header = header & 0x7;
			if (dooutput)
				printf("Raw data = %x\n", idata[n]);

			switch (psubevt->GetProcid())
			{
				case 100: //VME_0, see setup.usf


					if (header==0x40)
						m_bool=true; //MESYTEC header flag
					else if (caen_header == 2)
						c_bool=true;  //CAEN  header flag
					else if ((idata[n]==0xaffeaffe) || (idata[n]== 0x06000000) || (idata[n]== 0x05000000))
					{
						c_bool=false;
						m_bool=false;
					}


Pavel Sharov's avatar
Pavel Sharov committed
349
					if (m_bool) {//in case of MESYTEC data
Pavel Sharov's avatar
Pavel Sharov committed
350
						typ=idata[n]  >> 30;
Pavel Sharov's avatar
Pavel Sharov committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

						switch(typ)	{
						case 1: //MESYTEC header
							module_id = (idata[n] >> 16) & 0xff;
							if (dooutput)
								printf("Mesytec Module ID %d\n", module_id);
							break;


						case 0: //MESYTEC data
							if(idata[n]  >> 24!=0x04) break;
							switch (module_id) {
							case 0:	//mTDC: ToF
								if ((idata[n] >> 16) & 0x20) break; //T bit analysis
								chnl= (idata[n] >> 16) & 0x1f;
								adc = idata[n] & 0xffff; //only 16 bits
								if(chnl<4) NeEvent->tF3[chnl] = adc;
								else if(chnl<8) NeEvent->tF5[chnl-4] = adc;
								else if(chnl<12);
								else if(chnl<16) NeEvent->tMWPC[chnl-12] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
371
								break;
Pavel Sharov's avatar
Pavel Sharov committed
372 373 374 375 376
							case 1:	//mQDC:
								chnl= (idata[n] >> 16) & 0x1f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<4) NeEvent->F3[chnl] = adc;
								else if(chnl<8) NeEvent->F5[chnl-4] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
377

Pavel Sharov's avatar
Pavel Sharov committed
378
								break;
Pavel Sharov's avatar
Pavel Sharov committed
379

Pavel Sharov's avatar
Pavel Sharov committed
380 381 382 383
							case 6: //scaler v560
								for(i = 0; i < 16; ++i)
									NeEvent->scaler[i]=idata[n++] & 0x07ffffff;
								break;
Pavel Sharov's avatar
Pavel Sharov committed
384

Pavel Sharov's avatar
Pavel Sharov committed
385 386 387 388 389 390 391 392 393
							case 8:	// mTDC: time Lx & Ly
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) {
									NeEvent->Lxt[chnl] = adc;
								} else if(chnl<32) {
									NeEvent->Lyt[chnl-16] = adc;
								}
								break;
Pavel Sharov's avatar
Pavel Sharov committed
394

Pavel Sharov's avatar
Pavel Sharov committed
395 396
							case 9:	// mADC: amp Lx & Ly
								chnl= (idata[n] >> 16)&0x1f;
mbsdaq's avatar
mbsdaq committed
397
								adc = idata[n] & 0x1fff; //only 12 bits
Pavel Sharov's avatar
Pavel Sharov committed
398 399 400 401 402 403
								if(chnl<16) {
									NeEvent->Lxa[chnl] = adc;
								} else {
									NeEvent->Lya[chnl-16] = adc;
								}
								break;
404

Pavel Sharov's avatar
Pavel Sharov committed
405 406 407 408 409 410 411 412 413
							case 10:	// mTDC: time Rx & Ry
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) {
									NeEvent->Rxt[chnl] = adc;
								} else if(chnl<32) {
									NeEvent->Ryt[chnl-16] = adc;
								}
								break;
414

Pavel Sharov's avatar
Pavel Sharov committed
415 416
							case 11:	// mADC: amp Rx & Ry
								chnl= (idata[n] >> 16)&0x1f;
mbsdaq's avatar
mbsdaq committed
417
								adc = idata[n] & 0x1fff; //only 12 bits
Pavel Sharov's avatar
Pavel Sharov committed
418 419 420 421 422 423
								if(chnl<16) {
									NeEvent->Rxa[chnl] = adc;
								} else {
									NeEvent->Rya[chnl-16] = adc;
								}
								break;
424

Pavel Sharov's avatar
Pavel Sharov committed
425 426 427 428 429 430 431 432 433
							case 12:	// mTDC: time An S  & R
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) {
									NeEvent->AnSt[chnl] = adc;
								} else if(chnl<32) {
									NeEvent->AnRt[chnl-16] = adc;
								}
								break;
434

Pavel Sharov's avatar
Pavel Sharov committed
435 436
							case 13:	// mADC: amp An S  & R
								chnl= (idata[n] >> 16)&0x1f;
mbsdaq's avatar
mbsdaq committed
437
								adc = idata[n] & 0x1fff; //only 12 bits
Pavel Sharov's avatar
Pavel Sharov committed
438 439 440 441 442 443
								if(chnl<16) {
									NeEvent->AnSa[chnl] = adc;
								} else {
									NeEvent->AnRa[chnl-16] = adc;
								}
								break;
444

Pavel Sharov's avatar
Pavel Sharov committed
445 446 447 448 449 450 451 452 453
							case 14:	// mTDC: time R20  & AnV
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) {
									NeEvent->AnVt[chnl] = adc;
								} else if(chnl<32) {
									NeEvent->R20t[chnl-16] = adc;
								}
								break;
454

Pavel Sharov's avatar
Pavel Sharov committed
455 456
							case 15:	// mADC: amp R20  & AnV
								chnl= (idata[n] >> 16)&0x1f;
mbsdaq's avatar
mbsdaq committed
457
								adc = idata[n] & 0x1fff; //only 12 bits
Pavel Sharov's avatar
Pavel Sharov committed
458 459 460 461 462 463
								if(chnl<16) {
									NeEvent->AnVa[chnl] = adc;
								} else {
									NeEvent->R20a[chnl-16] = adc;
								}
								break;
464

mbsdaq's avatar
mbsdaq committed
465
							case 2:	// mTDC: time Rcs  & Lcs
Pavel Sharov's avatar
Pavel Sharov committed
466 467 468 469 470 471 472 473 474
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) {
									NeEvent->Lcst[chnl] = adc;
								} else if(chnl<32) {
									NeEvent->Rcst[chnl-16] = adc;
								}
								break;

mbsdaq's avatar
mbsdaq committed
475
							case 3:	// mADC: amp Rcs  & Lcs
Pavel Sharov's avatar
Pavel Sharov committed
476
								chnl= (idata[n] >> 16)&0x1f;
mbsdaq's avatar
mbsdaq committed
477
								adc = idata[n] & 0x1fff; //only 12 bits
Pavel Sharov's avatar
Pavel Sharov committed
478 479 480 481
								if(chnl<16) {
									NeEvent->Lcsa[chnl] = adc;
								} else {
									NeEvent->Rcsa[chnl-16] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
482 483 484
								}
								break;

mbsdaq's avatar
mbsdaq committed
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
							case 4:	// mTDC: time Rvt 
								chnl= (idata[n] >> 16)&0x3f;
								adc = idata[n] & 0xfff; //only 12 bits
								if(chnl<16) NeEvent->Rvt[chnl] = adc;
								break;

							case 5:	// mADC: amp Ra 
								chnl= (idata[n] >> 16)&0x1f;
								adc = idata[n] & 0x1fff; //only 12 bits
								if(chnl<16) NeEvent->Rva[chnl] = adc;
								break;

							}
							break;

Pavel Sharov's avatar
Pavel Sharov committed
500 501 502 503 504
							case 3: //-----MESYTEC footer-----
								m_bool=false;
								break;

							default:
Pavel Sharov's avatar
Pavel Sharov committed
505 506 507
								printf("ERROR !!!!!! Unknown MESYTEC typ %d\n", typ);
								printf("Data = %x\n", idata[n]);
							break;
Pavel Sharov's avatar
Pavel Sharov committed
508 509 510 511 512 513
						}
					}
					else if (c_bool) //in case of CAEN data
					{
						typ   = (idata[n] >> 24) & 0x7;
						geo   = idata[n]  >> 27;
Pavel Sharov's avatar
Pavel Sharov committed
514
						if (dooutput)
Pavel Sharov's avatar
Pavel Sharov committed
515 516
							printf("CAEN geo %d\n", geo);

Pavel Sharov's avatar
Pavel Sharov committed
517
						switch(typ)
Pavel Sharov's avatar
Pavel Sharov committed
518 519 520 521 522 523
						{
							case 2: //CAEN header
								crate = (idata[n] >> 16) & 0xff;
								cnt = (idata[n] >> 8) & 0x1f;
								if (geo==30)
									NeEvent->mtime=idata[++n];//machine time
Pavel Sharov's avatar
Pavel Sharov committed
524

Pavel Sharov's avatar
Pavel Sharov committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
								if (dooutput)
									printf("Header: geo:%d crate:%d cnt = %d\n", geo, crate, cnt);
								break;

							case 0: //CAEN data
								adc = idata[n] & 0xfff;
								chnl = (idata[n] >> 16) & 0x1f;
								//printf("DATA: geo:%d Channel = %d\n", geo, chnl);
								switch(geo)
								{
								}
								//                printf("  Data: geo:%d chnl:%d adc:%d\n", geo, chnl, adc);
								break;

							case 4: //CAEN footer
								c_bool = false;
Pavel Sharov's avatar
Pavel Sharov committed
541
								evnt = idata[n] & 0xffffff;
Pavel Sharov's avatar
Pavel Sharov committed
542 543 544 545 546 547 548 549 550 551 552 553 554
								if (dooutput)
								   printf("  Event: geo:%d number:%d\n", geo, evnt);
								break;

							case 6: //CAEN no valid data
								c_bool = false;
								if (dooutput)
									printf("!!!No valid data from CAEN!!!");
								break;

							default:
								printf("ERROR !!!!!! Uncknown CAEN typ %d\n", typ);
								printf("Data = %x\n", idata[n]);
Pavel Sharov's avatar
Pavel Sharov committed
555

Pavel Sharov's avatar
Pavel Sharov committed
556 557 558 559 560 561 562 563 564 565 566
							break;
						}
					}
					break; //end of VME_0

				case 101: // CAMAC through VME_0, see setup.usf
					    geo   = idata[n]  >> 27;

					    switch(geo)
					    {

Pavel Sharov's avatar
Pavel Sharov committed
567
						case 1:
Pavel Sharov's avatar
Pavel Sharov committed
568 569 570 571 572
						     NeEvent->nx1 = 0;
						     adc = idata[++n];
						     LSB=adc;
						     //printf("First word from MWPC X1= %x\n", adc);
						     for(i = 0; i < 16; ++i)
Pavel Sharov's avatar
Pavel Sharov committed
573
							if((adc & bit[i]) > 0) NeEvent->x1[NeEvent->nx1++] = i;
Pavel Sharov's avatar
Pavel Sharov committed
574 575 576 577 578
						     adc = idata[++n];
						     MSB = adc;
						     MSBLSB = (MSB << 16) | LSB;
						     //printf("Second word from MWPC X1= %x\n", adc);
						     for(i = 0; i < 16; ++i)
Pavel Sharov's avatar
Pavel Sharov committed
579
							if((adc & bit[i]) > 0) NeEvent->x1[NeEvent->nx1++] = i+16;
Pavel Sharov's avatar
Pavel Sharov committed
580 581 582 583 584 585 586 587 588 589 590
						     adc = idata[++n];//pass throug footer
						     //printf("Third word from MWPC X1= %x\n", adc);
						     NeEvent->rx1=MSBLSB;
						     break;

						case 2:
						      NeEvent->ny1 = 0;
						      adc = idata[++n];
						      LSB=adc;
						      //printf("First word from MWPC Y1 = %x\n", adc);
						      for(i = 0; i < 16; ++i)
Pavel Sharov's avatar
Pavel Sharov committed
591
							if((adc & bit[i]) > 0) NeEvent->y1[NeEvent->ny1++] = i;
Pavel Sharov's avatar
Pavel Sharov committed
592 593 594 595 596 597 598 599 600
						      adc = idata[++n];
						      MSB = adc;
						      MSBLSB= (MSB << 16) | LSB;
						      //printf("Second word from MWPC Y1 = %x\n", adc);
						      for(i = 0; i < 16; ++i)
							if((adc & bit[i]) > 0) NeEvent->y1[NeEvent->ny1++] = i+16;
						      adc = idata[++n];//pass through footer
						      //printf("Third word from MWPC Y1 = %x\n", adc);
						      NeEvent->ry1=MSBLSB;
Pavel Sharov's avatar
Pavel Sharov committed
601
						      break;
Pavel Sharov's avatar
Pavel Sharov committed
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
						case 3:
						      NeEvent->nx2 = 0;
						      adc = idata[++n];
						      LSB=adc;
						      //printf("First word from MWPC X2 = %x\n", adc);
						      for(i = 0; i < 16; ++i)
							if((adc & bit[i]) > 0) NeEvent->x2[NeEvent->nx2++] = i;
						      adc = idata[++n];
						      MSB = adc;
						      MSBLSB= (MSB << 16) | LSB;
						      //printf("Second word from MWPC X2 = %x\n", adc);
						      for(i = 0; i < 16; ++i)
							if((adc & bit[i]) > 0) NeEvent->x2[NeEvent->nx2++] = i+16;
						      adc = idata[++n];//pass through footer
						      //printf("Third word from MWPC X2 = %x\n", adc);
						      NeEvent->rx2=MSBLSB;
						      break;
						case 4:
						      NeEvent->ny2 = 0;
						      adc = idata[++n];
						      LSB=adc;
						      //printf("First word from MWPC Y2 = %x\n", adc);
Pavel Sharov's avatar
Pavel Sharov committed
624
						      for(i = 0; i < 16; ++i)
Pavel Sharov's avatar
Pavel Sharov committed
625 626 627 628 629 630 631 632 633 634 635 636
							if((adc & bit[i]) > 0) NeEvent->y2[NeEvent->ny2++] = i;
						      adc = idata[++n];
						      MSB = adc;
						      MSBLSB= (MSB << 16) | LSB;
						      //printf("Second word from MWPC Y2 = %x\n", adc);
						      for(i = 0; i < 16; ++i)
							if((adc & bit[i]) > 0) NeEvent->y2[NeEvent->ny2++] = i+16;
						      adc = idata[++n];//pass throug footer
						      //printf("Third word from MWPC Y2 = %x\n", adc);
						      NeEvent->ry2=MSBLSB;
						      break;
						 }
Pavel Sharov's avatar
Pavel Sharov committed
637

Pavel Sharov's avatar
Pavel Sharov committed
638
					break; // end of CAMAC
Pavel Sharov's avatar
Pavel Sharov committed
639

Pavel Sharov's avatar
Pavel Sharov committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
					case 200: //VME_1, see setup.usf


					if (header==0x40)
						m_bool=true; //MESYTEC header flag
					else if (caen_header == 2)
						c_bool=true;  //CAEN  header flag
					else if ((idata[n]==0xaffeaffe) || (idata[n]== 0x06000000) || (idata[n]== 0x05000000))
					{
						c_bool=false;
						m_bool=false;
					}


					if (m_bool) //in case of MESYTEC data
					{
						typ=idata[n]  >> 30;
Pavel Sharov's avatar
Pavel Sharov committed
657 658

						switch(typ)
Pavel Sharov's avatar
Pavel Sharov committed
659 660 661
						{
							case 1: //MESYTEC header
								module_id = (idata[n] >> 16) & 0xff;
Pavel Sharov's avatar
Pavel Sharov committed
662
								if (dooutput)
Pavel Sharov's avatar
Pavel Sharov committed
663 664 665 666 667 668 669 670 671
									printf("Mesytec Module ID %d\n", module_id);
								break;


							case 0: //MESYTEC data
								if(idata[n]  >> 24!=0x04) break;
								switch (module_id)
								{
									case 3:	// mTDC: time sect & rings p1
672
										chnl= (idata[n] >> 16)&0x3f;
Pavel Sharov's avatar
Pavel Sharov committed
673 674
										adc = idata[n] & 0xfff; //only 12 bits
										if(chnl<16) {
675
											NeEvent->Lxt[chnl] = adc;
676
										} else if(chnl<32) {
677
											NeEvent->Lyt[chnl-16] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
678 679 680 681 682 683 684
										}
										break;

									case 4:	// mADC: amp sect & rings p1
										chnl= (idata[n] >> 16)&0x1f;
										adc = idata[n] & 0xfff; //only 12 bits
										if(chnl<16) {
685
											NeEvent->Lxa[chnl] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
686
										} else {
687
											NeEvent->Lya[chnl-16] = adc;
Pavel Sharov's avatar
Pavel Sharov committed
688 689 690 691 692 693 694 695 696 697 698
										}
										break;

								}
								break;

							case 3: //-----MESYTEC footer-----
								m_bool=false;
								break;

							default:
Pavel Sharov's avatar
Pavel Sharov committed
699 700 701
								printf("ERROR !!!!!! Unknown MESYTEC typ %d\n", typ);
								printf("Data = %x\n", idata[n]);
							break;
Pavel Sharov's avatar
Pavel Sharov committed
702 703 704 705 706 707
						}
					}
					else if (c_bool) //in case of CAEN data
					{
						typ   = (idata[n] >> 24) & 0x7;
						geo   = idata[n]  >> 27;
Pavel Sharov's avatar
Pavel Sharov committed
708
						if (dooutput)
Pavel Sharov's avatar
Pavel Sharov committed
709 710
							printf("CAEN geo %d\n", geo);

Pavel Sharov's avatar
Pavel Sharov committed
711
						switch(typ)
Pavel Sharov's avatar
Pavel Sharov committed
712 713 714 715 716 717
						{
							case 2: //CAEN header
								crate = (idata[n] >> 16) & 0xff;
								cnt = (idata[n] >> 8) & 0x1f;
								if (geo==30)
									NeEvent->mtime=idata[++n];//machine time
Pavel Sharov's avatar
Pavel Sharov committed
718

Pavel Sharov's avatar
Pavel Sharov committed
719 720 721 722 723 724 725 726 727 728 729
								if (dooutput)
									printf("Header: geo:%d crate:%d cnt = %d\n", geo, crate, cnt);
								break;

							case 0: //CAEN data
								adc = idata[n] & 0xfff;
								chnl = (idata[n] >> 16) & 0x1f;
								//printf("DATA: geo:%d Channel = %d\n", geo, chnl);
								switch(geo)
								{
									case 6: //scaler v560
Pavel Sharov's avatar
Pavel Sharov committed
730
									for(i = 0; i < 16; ++i)
Pavel Sharov's avatar
Pavel Sharov committed
731 732 733 734 735 736 737 738
									NeEvent->scaler[i]=idata[n++] & 0x07ffffff;
									break;
								}
								//                printf("  Data: geo:%d chnl:%d adc:%d\n", geo, chnl, adc);
								break;

							case 4: //CAEN footer
								c_bool = false;
Pavel Sharov's avatar
Pavel Sharov committed
739
								evnt = idata[n] & 0xffffff;
Pavel Sharov's avatar
Pavel Sharov committed
740 741 742 743 744 745 746 747 748 749 750 751 752
								if (dooutput)
								   printf("  Event: geo:%d number:%d\n", geo, evnt);
								break;

							case 6: //CAEN no valid data
								c_bool = false;
								if (dooutput)
									printf("!!!No valid data from CAEN!!!");
								break;

							default:
								printf("ERROR !!!!!! Uncknown CAEN typ %d\n", typ);
								printf("Data = %x\n", idata[n]);
Pavel Sharov's avatar
Pavel Sharov committed
753

Pavel Sharov's avatar
Pavel Sharov committed
754 755 756 757 758 759 760 761 762 763 764
							break;
						}
					}
					break; //end of VME_1


			} //end of GetProcID
		} //end of GetIntLen
	} //end of NextSubEvent

	NeEvent->nevent		= fInput->GetCount();
Pavel Sharov's avatar
Pavel Sharov committed
765
	NeEvent->trigger	= fInput->GetTrigger();
Pavel Sharov's avatar
Pavel Sharov committed
766 767 768 769 770 771 772
	NeEvent->subevents	= num;
	NeEvent->evsize		= sz;

	fTrigger->Fill(NeEvent->trigger);
	fSubEvents->Fill(num);
	fEventsSizes->Fill(sz);

Pavel Sharov's avatar
Pavel Sharov committed
773
//
Pavel Sharov's avatar
Pavel Sharov committed
774 775

	for (n=0; n<4; ++n)
Pavel Sharov's avatar
Pavel Sharov committed
776
//	if(NeEvent->trigger == 2)
Pavel Sharov's avatar
Pavel Sharov committed
777 778 779 780 781 782 783 784 785 786 787 788
	{
	if(NeEvent->F3[n] > 0 ) d1F3[n]->Fill(NeEvent->F3[n]);
	if(NeEvent->F5[n] > 0) d1F5[n]->Fill(NeEvent->F5[n]);

	if(NeEvent->tF3[n] > 0) d1tF3[n]->Fill(NeEvent->tF3[n]);
	if(NeEvent->tF5[n] > 0) d1tF5[n]->Fill(NeEvent->tF5[n]);

	if(NeEvent->tMWPC[n] > 0) d1tMWPC[n]->Fill(NeEvent->tMWPC[n]);
	}
//
	if(NeEvent->F3[0]>0&&NeEvent->F3[1]>0&&NeEvent->F3[2]>0&&NeEvent->F3[3]>0)
		 af3 = (NeEvent->F3[0]+NeEvent->F3[1]+NeEvent->F3[2]+NeEvent->F3[3]+4.*gRandom->Uniform())/4.;
Pavel Sharov's avatar
Pavel Sharov committed
789
	if(NeEvent->F5[0]>0&&NeEvent->F5[1]>0&&NeEvent->F5[2]>0&&NeEvent->F5[3]>0)
Pavel Sharov's avatar
Pavel Sharov committed
790 791 792 793
		af5 = (NeEvent->F5[0]+NeEvent->F5[1]+NeEvent->F5[2]+NeEvent->F5[3]+4.*gRandom->Uniform())/4.;

	if(NeEvent->tF3[0]>0&&NeEvent->tF3[1]>0&&NeEvent->tF3[2]>0&&NeEvent->tF3[3]>0)
		 tf3 = (NeEvent->tF3[0]+NeEvent->tF3[1]+NeEvent->tF3[2]+NeEvent->tF3[3]+4.*gRandom->Uniform())/4.;
Pavel Sharov's avatar
Pavel Sharov committed
794
	if(NeEvent->tF5[0]>0&&NeEvent->tF5[1]>0&&NeEvent->tF5[2]>0&&NeEvent->tF5[3]>0)
Pavel Sharov's avatar
Pavel Sharov committed
795 796 797 798 799 800 801 802 803 804 805
		 tf5 = (NeEvent->tF5[0]+NeEvent->tF5[1]+NeEvent->tF5[2]+NeEvent->tF5[3]+4.*gRandom->Uniform())/4.;

//
//	ToF = (tf5 - tf3)*0.125+89.165;
//	ToF = (tf5 - tf3)*0.0625;
//	ToF = (tf5 - tf3)*0.0625 + 68.55;
//	ToF = (tf5 - tf3)*0.0625 + 68.475;
ToF = (tf5 - tf3)*0.015625 + 68.475;

	if(af3*af5*tf3*tf5!=0)
	{
Pavel Sharov's avatar
Pavel Sharov committed
806
//		if(NeEvent->trigger == 1)
Pavel Sharov's avatar
Pavel Sharov committed
807 808 809 810 811 812 813 814 815 816
		{
			d1ToF->Fill(ToF);
			d1aF3->Fill(af3);
			d2ToFaF3->Fill(ToF,af3);

			d1aF5->Fill(af5);
			d2ToFaF5->Fill(ToF,af5);

		}
	}
Pavel Sharov's avatar
Pavel Sharov committed
817
	for (int n=0; n<16; ++n) {
mbsdaq's avatar
mbsdaq committed
818 819
//		if(NeEvent->Lxt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
820 821 822
			d1Lxa[n]->Fill(NeEvent->Lxa[n]);
			d1Lxt[n]->Fill(NeEvent->Lxt[n]);
		}
mbsdaq's avatar
mbsdaq committed
823 824
//		if(NeEvent->Lyt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
825 826 827
			d1Lya[n]->Fill(NeEvent->Lya[n]);
			d1Lyt[n]->Fill(NeEvent->Lyt[n]);
		}
mbsdaq's avatar
mbsdaq committed
828 829
//		if(NeEvent->Rxt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
830 831 832
			d1Rxa[n]->Fill(NeEvent->Rxa[n]);
			d1Rxt[n]->Fill(NeEvent->Rxt[n]);
		}
mbsdaq's avatar
mbsdaq committed
833 834
//		if(NeEvent->Ryt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
835 836 837
			d1Rya[n]->Fill(NeEvent->Rya[n]);
			d1Ryt[n]->Fill(NeEvent->Ryt[n]);
		}
mbsdaq's avatar
mbsdaq committed
838 839
//		if(NeEvent->R20t[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
840 841 842
			d1R20a[n]->Fill(NeEvent->R20a[n]);
			d1R20t[n]->Fill(NeEvent->R20t[n]);
		}
mbsdaq's avatar
mbsdaq committed
843 844
//		if(NeEvent->AnSt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
845 846 847
			d1AnSa[n]->Fill(NeEvent->AnSa[n]);
			d1AnSt[n]->Fill(NeEvent->AnSt[n]);
		}
mbsdaq's avatar
mbsdaq committed
848 849
//		if(NeEvent->AnRt[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
850 851 852
			d1AnRa[n]->Fill(NeEvent->AnRa[n]);
			d1AnRt[n]->Fill(NeEvent->AnRt[n]);
		}
mbsdaq's avatar
mbsdaq committed
853 854 855 856 857 858 859 860 861

//		if(NeEvent->AnVt[n]>0)
		{
			d1AnVa[n]->Fill(NeEvent->AnVa[n]);
			d1AnVt[n]->Fill(NeEvent->AnVt[n]);
		}

//		if(NeEvent->Rcst[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
862 863 864
			d1Rcsa[n]->Fill(NeEvent->Rcsa[n]);
			d1Rcst[n]->Fill(NeEvent->Rcst[n]);
		}
mbsdaq's avatar
mbsdaq committed
865 866
//		if(NeEvent->Lcst[n]>0)
		{
Pavel Sharov's avatar
Pavel Sharov committed
867 868 869 870
			d1Lcsa[n]->Fill(NeEvent->Lcsa[n]);
			d1Lcst[n]->Fill(NeEvent->Lcst[n]);
		}

mbsdaq's avatar
mbsdaq committed
871 872 873 874 875 876
//		if(NeEvent->Rvt[n]>0)
		{
			d1Rva[n]->Fill(NeEvent->Rva[n]);
			d1Rvt[n]->Fill(NeEvent->Rvt[n]);
		}

Pavel Sharov's avatar
Pavel Sharov committed
877 878


Pavel Sharov's avatar
Pavel Sharov committed
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
	}
//-----p1 secrors amp.-----
/*
	for (n=0; n<16; ++n)
	{
		if(NeEvent->p1s[n] > 0)
			d1_p1s[n]->Fill(NeEvent->p1s[n]);
	}

//----- time of p1 sectors ---
	for (n=0; n<16; ++n)
	{
		if(NeEvent->tp1s[n] > 0)
			d1_p1s[n]->Fill(NeEvent->tp1s[n]);
	}
mbsdaq's avatar
mbsdaq committed
894
*/
Pavel Sharov's avatar
Pavel Sharov committed
895 896 897 898
//______ calibrated spectra __________________________

	for (n=0; n<16; ++n)
	{
mbsdaq's avatar
mbsdaq committed
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
		if(NeEvent->Lxt[n]>0){
		    value1 = (double)NeEvent->Lxa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Lxa->Energy(value1, n);
			d1Lxc[n]->Fill(value2);
			mLxa++;
			eLxa = value2;
		}
		
		if(NeEvent->Lyt[n]>0){
		    value1 = (double)NeEvent->Lya[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Lya->Energy(value1, n);
			d1Lyc[n]->Fill(value2);
			mLya++;
			eLya = value2;
		}

		if(NeEvent->Rxt[n]>0){		
		    value1 = (double)NeEvent->Rxa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Rxa->Energy(value1, n);
			d1Rxc[n]->Fill(value2);
			mRxa++;
			eRxa = value2;
		}

		if(NeEvent->Ryt[n]>0){
		    value1 = (double)NeEvent->Rya[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Rya->Energy(value1, n);
			d1Ryc[n]->Fill(value2);
			mRya++;
			eRya = value2;
		}

		if(NeEvent->R20t[n]>0){
		    value1 = (double)NeEvent->R20a[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_R20a->Energy(value1, n);
			d1R20c[n]->Fill(value2);
			mR20a++;
			eR20a = value2;
		}

		if(NeEvent->Rvt[n]>0){
		    value1 = (double)NeEvent->Rva[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Rva->Energy(value1, n);
			d1Rvc[n]->Fill(value2);
			mRva++;
			eRva = value2;
		}

		if(NeEvent->AnSt[n]>0){
		    value1 = (double)NeEvent->AnSa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_AnSa->Energy(value1, n);
			d1AnSc[n]->Fill(value2);
			mAnSa++;
			eAnSa = value2;
		}

		if(NeEvent->AnRt[n]>0){
		    value1 = (double)NeEvent->AnRa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_AnRa->Energy(value1, n);
			d1AnRc[n]->Fill(value2);
			mAnRa++;
			eAnRa = value2;
		}

		if(NeEvent->Rcst[n]>0){
		    value1 = (double)NeEvent->Rcsa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Rcsa->Energy(value1, n);
			d1Rcsc[n]->Fill(value2);
			mRcsa++;
			eRcsa = value2;
		}

		if(NeEvent->Lcst[n]>0 && NeEvent->Lcsa[n]>2500){
		    value1 = (double)NeEvent->Lcsa[n] + gRandom->Uniform();
			value2 = ((TNeAnalysis*)go4)->p_Lcsa->Energy(value1, n);
			d1Lcsc[n]->Fill(value2);
			mLcsa++;
			nLcsa = n;
			eLcsa = value2;
		}
Pavel Sharov's avatar
Pavel Sharov committed
979
	}
mbsdaq's avatar
mbsdaq committed
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
		if(mRya==1 && mR20a==1)
		{
			d2ede->Fill(eRya,eR20a);
		}

		if(mLya==1 && mLcsa==1)
		{
			if(nLcsa == 0) d2LyLcs1->Fill(eLcsa,eLya);
			else if(nLcsa == 1) d2LyLcs2->Fill(eLcsa,eLya);
			else if(nLcsa == 2) d2LyLcs3->Fill(eLcsa,eLya);
			else if(nLcsa == 3) d2LyLcs4->Fill(eLcsa,eLya);
			else if(nLcsa == 4) d2LyLcs5->Fill(eLcsa,eLya);
			else if(nLcsa == 5) d2LyLcs6->Fill(eLcsa,eLya);
			else if(nLcsa == 6) d2LyLcs7->Fill(eLcsa,eLya);
			else if(nLcsa == 7) d2LyLcs8->Fill(eLcsa,eLya);
			else if(nLcsa == 8) d2LyLcs9->Fill(eLcsa,eLya);
			else if(nLcsa == 9) d2LyLcs10->Fill(eLcsa,eLya);
			else if(nLcsa == 10) d2LyLcs11->Fill(eLcsa,eLya);
			else if(nLcsa == 11) d2LyLcs12->Fill(eLcsa,eLya);
			else if(nLcsa == 12) d2LyLcs13->Fill(eLcsa,eLya);
			else if(nLcsa == 13) d2LyLcs14->Fill(eLcsa,eLya);
			else if(nLcsa == 14) d2LyLcs15->Fill(eLcsa,eLya);
			else if(nLcsa == 15) d2LyLcs16->Fill(eLcsa,eLya);
		}

//---------------------start of MWPC----------------------------------------
//	if(NeEvent->trigger == 1 && ToF > 165 && ToF <185)
//	{ 
	
	   for(i = 0; i < NeEvent->nx1; ++i) d1X1->Fill(NeEvent->x1[i]);
	   for(i = 0; i < NeEvent->ny1; ++i) d1Y1->Fill(NeEvent->y1[i]);
	   for(i = 0; i < NeEvent->nx2; ++i) d1X2->Fill(NeEvent->x2[i]);
	   for(i = 0; i < NeEvent->ny2; ++i) d1Y2->Fill(NeEvent->y2[i]);
//	}	

	   if(NeEvent->nx1 > 0) d1NX1->Fill(NeEvent->nx1);

	   if(NeEvent->ny1 > 0) d1NY1->Fill(NeEvent->ny1);

	   if(NeEvent->nx2 > 0) d1NX2->Fill(NeEvent->nx2);

	   if(NeEvent->ny2 > 0) d1NY2->Fill(NeEvent->ny2);

      if(NeEvent->nx1 > 0)
		d1CX1->Fill(GetClasters(NeEvent->nx1, NeEvent->x1));

	   if(NeEvent->ny1 > 0)
		d1CY1->Fill(GetClasters(NeEvent->ny1, NeEvent->y1));

	   if(NeEvent->nx2 > 0)
		d1CX2->Fill(GetClasters(NeEvent->nx2, NeEvent->x2));

	   if(NeEvent->ny2 > 0)
		d1CY2->Fill(GetClasters(NeEvent->ny2, NeEvent->y2));

// Li9
//	if (NeEvent->nx1*NeEvent->ny1*NeEvent->nx2*NeEvent->ny2 == 1 && 162<ToF && ToF<170 && 1000<af3 && af3<1700) 
	
// He6	   
//	if (NeEvent->nx1*NeEvent->ny1*NeEvent->nx2*NeEvent->ny2 == 1 && ToF>158 && ToF<168 && af3>500 && af3<1100)
	   if (NeEvent->nx1*NeEvent->ny1*NeEvent->nx2*NeEvent->ny2 == 1)
		{
				mwz1 = -816;
				mwx1 = (16 - NeEvent->x1[0] + gRandom->Uniform())*1.25;
				mwy1 = (NeEvent->y1[0] - 16 + gRandom->Uniform())*1.25;
			
				mwz2 = -270;
				mwx2 = (16 - NeEvent->x2[0] + gRandom->Uniform())*1.25;
				mwy2 = (NeEvent->y2[0] - 16 + gRandom->Uniform())*1.25;
	
				zbt = -70;
				xbt = mwx2 + (mwx2 - mwx1)*(zbt-mwz2)/(mwz2-mwz1);
				ybt = mwy2 + (mwy2 - mwy1)*(zbt-mwz2)/(mwz2-mwz1);
				
//				if (NeEvent->trigger == 1)
				{
					d2XYbeamOnTar->Fill(xbt, ybt);
				}

				/*if (NeEvent->trigger == 2, NeEvent->trigger == 3, NeEvent->trigger == 4, NeEvent->trigger == 5)
				{
					d2XYbeamOnTar_trig2->Fill(xbt, ybt);
				}

				if (NeEvent->tF6[0]*NeEvent->tF6[1]*NeEvent->tF6[2]*NeEvent->tF6[3]>0)
				{
					d2XYbeamOnTar_F6->Fill(xbt, ybt);
				}
*/
		}
		

// 
	   if(NeEvent->nx1 > 0 && NeEvent->ny1 > 0 && (GetClasters(NeEvent->nx1, NeEvent->x1)) == 1 && (GetClasters(NeEvent->ny1, NeEvent->y1)) == 1)
	   {
		d2XY1->Fill(NeEvent->x1[0],NeEvent->y1[0]);
//		if(NeEvent->tF6[2] >100) d2XY1beam->Fill(NeEvent->x1[0],NeEvent->y1[0]);
//		if(NeEvent->trigger == 1) d2XY1beam->Fill(NeEvent->x1[0],NeEvent->y1[0]);
//		else	d2XY1->Fill(NeEvent->x1[0],NeEvent->y1[0]);
	   }
	
	   if(NeEvent->nx2 > 0 && NeEvent->ny2 > 0 && (GetClasters(NeEvent->nx2, NeEvent->x2)) == 1 && (GetClasters(NeEvent->ny2, NeEvent->y2)) == 1)
	   {
		d2XY2->Fill(NeEvent->x2[0],NeEvent->y2[0]);
//		if(NeEvent->tF6[2] >100) d2XY2beam->Fill(NeEvent->x2[0],NeEvent->y2[0]);
//		if(NeEvent->trigger == 1) d2XY2beam->Fill(NeEvent->x2[0],NeEvent->y2[0]);
//		else	d2XY2->Fill(NeEvent->x2[0],NeEvent->y2[0]);
	   }

/*
	   if(NeEvent->nx1 == 1 && NeEvent->ny1 == 1 && NeEvent->trigger == 1)
	   {
		d2XY1->Fill(NeEvent->x1[0],NeEvent->y1[0]);
	   }
	
	   if(NeEvent->nx2 == 1 && NeEvent->ny2 == 1 && NeEvent->trigger == 1)
	   {
		d2XY2->Fill(NeEvent->x2[0],NeEvent->y2[0]);
	   }

Pavel Sharov's avatar
Pavel Sharov committed
1100
*/
mbsdaq's avatar
mbsdaq committed
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

//---Pictures---
/*
	   if(NeEvent->nx1 == 1 && NeEvent->nx2 == 1)
	   {
		ya1 = -0.5*pya1 + dx1 + (pya1 / 32.)*NeEvent->x1[0];
	        ya2 = -0.5*pya2 + dx2 + (pya2 / 32.)*NeEvent->x2[0];
	        ya3 = ya1 + dtx + (ya2 - ya1) * (pxa3 - pxa1) / (pxa2 - pxa1); 

               if(ya3 > -0.5*pya1 && ya3 < 0.5*pya1)
	       {    
   			if(((TNeAnalysis*)go4)->pMTracks->mtracksx != ntrackx)
			{
				ntrackx = ((TNeAnalysis*)go4)->pMTracks->mtracksx;
				fTracksX->Set(3*ntrackx);
				itrackAX = 0;
				for(i = 0; i < fTracksX->GetN(); ++i)
	   				fTracksX->SetPoint(i,pxb1,0.);
			}
			if(itrackAX == fTracksX->GetN()) itrackAX = 0;
   
			fTracksX->SetPoint(itrackAX++,pxa1,ya1);
			fTracksX->SetPoint(itrackAX++,pxa3,ya3);
			fTracksX->SetPoint(itrackAX++,pxa1,ya1);
	   	}
	   } 
 
	   if(NeEvent->ny1 == 1 && NeEvent->ny2 == 1)
   	   {
	    	yb1 = -0.5*pyb1 + dy1+ (pyb1 / 32.)*NeEvent->y1[0];
	   	yb2 = -0.5*pyb2 + dy2+ (pyb2 / 32.)*NeEvent->y2[0];
	 
	   	yb3 = yb1 + dty + (yb2 - yb1) * (pxb3 - pxb1) / (pxb2 - pxb1); 

   		if(yb3 > -0.5*pyb1 && yb3 < 0.5*pyb1)
   		{    
   			if(((TNeAnalysis*)go4)->pMTracks->mtracksy != ntracky)
			{
				ntracky = ((TNeAnalysis*)go4)->pMTracks->mtracksy;
				fTracksY->Set(3*ntracky);
				itrackBX = 0;
				for(i = 0; i < fTracksY->GetN(); ++i)
   					fTracksY->SetPoint(i,pxb1,0.);
			}
			if(itrackBX == fTracksY->GetN()) itrackBX = 0;
   
			fTracksY->SetPoint(itrackBX++,pxb1,yb1);
			fTracksY->SetPoint(itrackBX++,pxb3,yb3);
			fTracksY->SetPoint(itrackBX++,pxb1,yb1);
   		}
  	 }
	  if(NeEvent->nx1 == 1 && NeEvent->nx2 == 1 && NeEvent->ny1 == 1 && NeEvent->ny2 == 1 )
	   {

			d2Target->Fill(ya3,yb3);
	   }*/

//--------------------end of MWPC----------------------------------------



Pavel Sharov's avatar
Pavel Sharov committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
	NeEvent->SetValid(kTRUE); // to store
	return kTRUE;
} //-------------------------------------------------------------------

double TNeProc::GetClasters(unsigned short n, unsigned short *x)
{
	int i;
	double clasters = 1;

	if(n == 0) clasters = 0.;
	else if(n > 1)
	{
		for(i = 1; i < n; ++i)
		{
			if(abs(x[i] - x[i-1]) > 1) clasters += 1.;
		}
	}
	return clasters;
} //--------------------------------------------------------------------