/**
Simulated data of proton-proton collisions of the TPC,
one set of tracks is given,
with single measured events of electron clouds reaching one of the two read-out chambers after a certain time with a certain charge

KV, 02/2010 (Data from Matevz Tadel), prepared for SBEII
**/

(
q = ();
q.dataFolder = Document.current.dir ++ "/TPC_m_data_96/";
q.myfileName = "m_data_96";

// get all tracks including [tracknumber, # of data associated with track]:
q.headerArchive = ZArchive.read(q.dataFolder +/+ q.myfileName ++ "_tracks.zar");
q.trackInfos = q.headerArchive.readItem;

	// read and post data for ONE track:
q.readTPC = { |q, index = 0|
	var trackID = q.trackInfos[index][0];
	var trackArchive = ZArchive.read(q.dataFolder +/+ q.myfileName ++ "_" ++ trackID ++ ".zar");
	var data = trackArchive.readItem;
	trackArchive.close; 
	
	data.do { |track, i| 
		track[3] = (track[4].abs)/2.6 * 100 
	}; // correct time! 
 	data
};
	// q.readTPC(14);

q.allTPCdata = q.trackInfos.size.collect { |i| 
	var track = q.readTPC(i);
	"read track %.\n".postf(i);
	track
};
)

/**
	// [units are in cm]
	q.track = q.allTPCdata[0];
	i = q.track[0] 	// track id, 			
	r = q.track[0]		// radius 	r,		[0..250] cm 
	p = q.track.flop[2] 	// angle 		phi,		[-pi, pi]
	t = q.track.flop[3]	// time 		t,		[0, 100] microsec, 
											= (2.6-(z.abs))/2.58 (2.58=drift velocity)
											BUT sometimes negative, therefore corrected!
	z = q.track.flop[4] 	// coordinate	z,		[-2.6, 2.6] // in meter: total size is 5m!
	x = q.track.flop[5] 	// coordinate	x,		[-250, 250] cm		
	y = q.track.flop[6] 	// coordinate	y, 		[-200, 225] cm
	c = q.track.flop[7] 	// charge 	q,  		in out.dat: [0, 272] nb. of electrons
	k = q.track.flop[8]		// kind of particle that produced the track, see TPCmontecarlorpp.pdf
	
	q.track.flop.do { |x| x.plot }; // plot all.
	q.track.flop.plot2; // plot all.
**/