/////////////////////////////////////////////////////////////// // TLANDEvent IMPLEMENTATION // Apr 2011 // ver. 1.0 event unpacker // Taken from N. Kurs 05/06/2008 // // mod. version 1/2012 v. 1.1 light rev1., p.r., e.d.f. // note: "light" revision rev1 maintains original data structures // just a tentative cleaning of the original source file // // v 1.2 rev2 v1.2 p.r., e.d.f. // note: danger: this revision contains strong modifications // of the original data structures. Anyway // the original design and LAND mapping is maintained //////////////////////////////////////////////////////////////// #include "TLANDEvent.h" #include #include #include #include "Riostream.h" #include "TROOT.h" #include "TH1.h" #include "TH2.h" #include "TF1.h" #include "TList.h" #include "TGraph.h" #include "TCanvas.h" #include #include "TCanvas.h" #include "TLANDstruct.h" #define rot2 0.065 #include "TMath.h" double lcalC1[200]; double lcalC2[200]; double lcalC5[200]; double lcalC6[200]; double lcalM1[200]; double lcalM2[200]; double lcalM5[200]; double lcalM6[200]; int l_i; int l_check; int l_mult; int l_mult1; int l_mult2; int l_dat, l_da0, l_da1; int l_sam_id; int l_gtb_id; int l_da_siz; int l_tac_addr; int l_tac_ch; int l_cal; double l_tcal[480]; //calibtime int l_ch_tim; int l_charge; int l_17_ct; double l_tim[30][17]; double l_q[30][17]; int l_17[30][17]; double l_17tim[30][17]; int l_sum[30][17]; Sl_map_ta l_map_ta[20][2]; Sl_map_tc l_map_tc[20][2]; Sl_map_tim l_map_tim[20][2]; Sl_map_QDC l_map_QDC[20][2]; Sl_map_tusync l_map_tusync[20][2]; Sl_map_cl l_map_cl[20][2]; Sl_map_hit l_map_hit[20]; int l_once; static int l_phy_evt_ct=0; TLANDEvent *glandevent = 0; //Constructor TLANDEvent::TLANDEvent(string landcaldir) { flandcaldir=landcaldir; if(glandevent==0)glandevent = this; } //Destructor TLANDEvent::~TLANDEvent() { // cout<<"TLANDEvent destructor...done"<> 28; //identifies the sam // cout << "sam was " << l_sam_id << endl; l_gtb_id = (l_dat & 0x0f000000) >> 24; //0 or 1, identifies which of the 2 cables of the sam //cout << "gtb was " << l_gtb_id << endl; l_da_siz = (l_dat & 0x000001ff); //Don't forget this includes the 17th channel //OK so now we have 2 sams: sam5 and sam6. Sam5 has GTB0 and sam6 has GTB0 and 1. //Need to loop over these as well as the data size. //in the case of second or third branch, find the size of the first branch subevt //generalise to all //expand this! //extra loop l_i++; for(int l_2_i = 1; l_2_i<=l_da_siz; l_2_i+=2) { //incr by 2 to loop over data size. //because we loop over subevent data size we don't need to loop over the sams. l_da0 = *(pl_se_dat + l_i ); //tac l_da1 = *(pl_se_dat + l_i + 1); //qdc l_tac_addr = (l_da0 & 0xf8000000) >> 27; //tac mod address l_tac_ch = (l_da0 & 0x07c00000) >> 22; //tac channel no l_cal = (l_da0 & 0x00100000) >> 20; //calibration bit, 0 for physics l_17_ct = (l_da0 & 0x0003f000) >> 12; //cntrl data // cout << l_17_ct <<" "<<" "<0)) { for(int lp17=0; lp17<17; lp17++) { // cout<0) && (l_tac_ch!=16)) { l_mult++; } //if(l_tac_ch==16) l_tim[new_l_tac_addr-1][l_tac_ch]=-2000; } } } l_i+=2; } //Am I at the end of the data size? if no, keep going... } //while {....} //not convert l_tim to real l_tim (counter and 17th ch) for(int l_loopaddrs=0; l_loopaddrs<30; l_loopaddrs++) { for(int l_loopchs=0; l_loopchs<16;l_loopchs++) { int l_clocktime = l_17[l_loopaddrs][l_loopchs]*25; // cout << "Clock time gives " << l_clocktime << endl; //when I have the calib file, use l_tcal[l_loopchs+(l_loopaddrs*10)] to get l_tim in ns, then do: // l_tim[l_loopaddrs][l_loopchs]=l_tim[l_loopaddrs][l_loopchs]-l_17tim[l_loopaddrs]+l_clocktime; //for now I will just take it to be 10 ps/bin. I should take 17th ch from this (check file) double l_nstime=l_tim[l_loopaddrs][l_loopchs]*(0.01/25); //l_tim[l_loopaddrs][l_loopchs]=(l_nstime+l_clocktime); } } int ftotfired=l_mult; // cout << "Mult is " << l_mult << endl; // cout << "The number of hit channels was " << l_check<< " but for some reason da_siz was " << l_da_siz <rawmulti = l_mult; //initialise tim etc for(int l_init=0; l_init<20; l_init++) { for(int j=0; j<=9; j++) { l_map_tim[l_init][0].tim[j] = 0; l_map_tim[l_init][1].tim[j] = 0; l_map_QDC[l_init][0].QDC[j] = 0; l_map_QDC[l_init][1].QDC[j] = 0; l_map_tim[l_init][0].tim17[j] = 0; l_map_tim[l_init][1].tim17[j] = 0; l_map_cl[l_init][0].cl[j] = 0; l_map_cl[l_init][1].cl[j] = 0; l_map_hit[l_init].hit[j] = 0; } l_map_tim[l_init][0].timV = 0; l_map_tim[l_init][1].timV = 0; l_map_QDC[l_init][0].QDCV = 0; l_map_QDC[l_init][1].QDCV = 0; l_map_tim[l_init][0].tim17V = 0; l_map_tim[l_init][1].tim17V = 0; l_map_cl[l_init][0].clV = 0; l_map_cl[l_init][1].clV = 0; l_map_hit[l_init].hitV = 0; } // cout << "initializing is ok...."<0) && (l_map_tim[paddlemap2][1].tim[j]>0)) { l_mult2++; l_map_hit[paddlemap2].hit[j] = 2; }else if ((l_map_tim[paddlemap2][0].tim[j]>0) || (l_map_tim[paddlemap2][1].tim[j]>0)){ l_mult1++; l_map_hit[paddlemap2].hit[j] = 1; } //Do the same for clock info, ch17 (17tim), read calibs from file to make a TGraph and //you can get real (unsynced) time. //For now though I just do it in the data format and guess that each bin is X ns roughly. l_map_tim[paddlemap2][0].tim17[j] = l_17tim[kta0][ktc0]; l_map_tim[paddlemap2][1].tim17[j] = l_17tim[kta1][ktc1]; //same for clock cycle counts l_map_cl[paddlemap2][0].cl[j] =l_17[kta0][ktc0]; l_map_cl[paddlemap2][1].cl[j] =l_17[kta1][ktc1]; //same for QDC info l_map_QDC[paddlemap2][0].QDC[j]= l_q[kta0][ktc0]; l_map_QDC[paddlemap2][1].QDC[j]= l_q[kta1][ktc1]; } //for j=0..9 int ktaV0 = l_map_ta[paddlemap2][0].taV; int ktcV0 = l_map_tc[paddlemap2][0].tcV; int ktaV1 = l_map_ta[paddlemap2][1].taV; int ktcV1 = l_map_tc[paddlemap2][1].tcV; l_map_tim[paddlemap2][0].timV =l_tim[ktaV0][ktcV0]; l_map_tim[paddlemap2][1].timV =l_tim[ktaV1][ktcV1]; if((l_map_tim[paddlemap2][0].timV>0) && (l_map_tim[paddlemap2][1].timV>0)) { l_mult2++; l_map_hit[paddlemap2].hitV = 1; } l_map_tim[paddlemap2][0].tim17V = l_17tim[ktaV0][ktcV0]; l_map_tim[paddlemap2][1].tim17V = l_17tim[ktaV1][ktcV1]; l_map_cl[paddlemap2][0].clV = l_17[ktaV0][ktcV0]; l_map_cl[paddlemap2][1].clV = l_17[ktaV1][ktcV1]; l_map_QDC[paddlemap2][0].QDCV = l_q[ktaV0][ktcV0]; l_map_QDC[paddlemap2][1].QDCV = l_q[ktaV1][ktcV1]; } //for{int paddlemap2=0; paddlemap2<20 .....} // // int nt=l_mult2; // cout << " End of primary LAND unpacking section nt= "<out_l_map_QDC[lrttree][0].QDC[j] = l_map_QDC[lrttree][0].QDC[j]; //qdc info first plane //note landevt->out_l_map_QDC[lrttree][1].QDC[j] = l_map_QDC[lrttree][1].QDC[j]; //qdc info first plane //note landevt->out_l_map_TAC[lrttree][0].tim[j] = l_map_tim[lrttree][0].tim[j]; //tac info first plane //note landevt->out_l_map_TAC[lrttree][1].tim[j] = l_map_tim[lrttree][1].tim[j]; //tac info first plane //note landevt->out_l_map_TAC[lrttree][0].tim17[j] = l_map_tim[lrttree][0].tim17[j]; //t17 info first plane //note landevt->out_l_map_TAC[lrttree][1].tim17[j] = l_map_tim[lrttree][1].tim17[j]; //t17 info first plane //note landevt->out_l_map_cl[lrttree][0].cl[j] = l_map_cl[lrttree][0].cl[j]; //cl info first plane //note landevt->out_l_map_cl[lrttree][1].cl[j] = l_map_cl[lrttree][1].cl[j]; //cl info first plane //note landevt->out_l_map_hit[lrttree].hit[j] = l_map_hit[lrttree].hit[j]; //hits //note } // "V" section //note landevt->out_l_map_QDC[lrttree][0].QDCV = l_map_QDC[lrttree][0].QDCV; //qdc info first plane //note landevt->out_l_map_QDC[lrttree][1].QDCV = l_map_QDC[lrttree][1].QDCV; //qdc info first plane //note landevt->out_l_map_TAC[lrttree][0].timV = l_map_tim[lrttree][0].timV; //tac info first plane //note landevt->out_l_map_TAC[lrttree][1].timV = l_map_tim[lrttree][1].timV; //tac info first plane //note landevt->out_l_map_TAC[lrttree][0].tim17V = l_map_tim[lrttree][0].tim17V; //t17 info first plane //note landevt->out_l_map_TAC[lrttree][1].tim17V = l_map_tim[lrttree][1].tim17V; //t17 info first plane //note landevt->out_l_map_cl[lrttree][0].clV = l_map_cl[lrttree][0].clV; //cl info first plane //note landevt->out_l_map_cl[lrttree][1].clV = l_map_cl[lrttree][1].clV; //cl info first plane //note landevt->out_l_map_hit[lrttree].hitV = l_map_hit[lrttree].hitV; //hits //note } //for(int lrttree=0....) // //can now try to define/use/save sync data // double taccal[10][2]; double t17cal[10][2]; double tclcy[10][2]; //initialization to 0 memset(taccal,0,sizeof(taccal)); memset(t17cal,0,sizeof(t17cal)); memset(tclcy, 0,sizeof(tclcy)); //main loop int num=0; for(int hj=0; hj<20; hj++) { //what about TDiff, TSync? Need to apply these as well... for(int j=0; j<=9; j++) { int kindex = (j*20) + hj; //////// TAC PM, planes if(l_map_tim[hj][0].tim[j] !=0) { taccal[j][0] = (l_map_tim[hj][0].tim[j]*lcalM1[kindex]) + lcalC1[kindex]; } if(l_map_tim[hj][1].tim[j]!=0) { taccal[j][1] = (l_map_tim[hj][1].tim[j]*lcalM2[kindex]) + lcalC2[kindex]; } ///////// T17 PM, Planes. // Warning: hj=0 or hj>0 if j=0 have an inchoerent source in the original code if(l_map_tim[hj][0].tim17[j]!=0) { t17cal[j][0] = (l_map_tim[hj][0].tim17[j]*lcalM5[kindex]) + lcalC5[kindex]; } if(l_map_tim[hj][1].tim17[j]!=0) { t17cal[j][1] = (l_map_tim[hj][1].tim17[j]*lcalM6[kindex]) + lcalC6[kindex]; } //clock cycle time tclcy[j][0] = l_map_cl[hj][0].cl[j] *25; tclcy[j][1] = l_map_cl[hj][1].cl[j] *25; } //for(int j=0; j<=9; j++) ... //set tusync val to 0 for(int j=0; j<=9; j++) { l_map_tusync[hj][0].tusync[j] = 0; l_map_tusync[hj][1].tusync[j] = 0; l_map_hit[hj].ut[j] = -1000; } //final tsync value for(int j=0; j<=9; j++) { if(l_map_hit[hj].hit[j]!=0) { l_map_tusync[hj][0].tusync[j] = (taccal[j][0] + tclcy[j][0]) - t17cal[j][0]; l_map_tusync[hj][1].tusync[j] = (taccal[j][1] + tclcy[j][1]) - t17cal[j][1]; l_map_hit[hj].ut[j] = l_map_tusync[hj][0].tusync[j] - l_map_tusync[hj][1].tusync[j]; } } //for(int j=0; j<=9; j++) .... // t1-t2 and usT (tusync); Root tree assignement for(int j=0; j<=9; j++) { if(l_map_hit[hj].hit[j]> 0){ landevt->padID[num]=j*100+hj; qdc1norm=l_map_QDC[hj][0].QDC[j]*gain1[j][hj]/qdiff[j][hj]; qdc2norm=l_map_QDC[hj][1].QDC[j]*gain2[j][hj]*qdiff[j][hj]; qposecm=2*(log(qdc1norm)-log(qdc2norm))*qlarg[j][hj]; qpost=l_map_tusync[hj][0].tusync[j] - l_map_tusync[hj][1].tusync[j]; qposecmrot= qposecm*cos(rot2)+qpost*sin(rot2); qpostcmrot=-qposecm*sin(rot2)+qpost*cos(rot2); if (corr==true){ if(qpostcmrot> tcutmax[j][hj] && qpostcmrot<(tcutmax[j][hj]+25)){ l_map_cl[hj][0].cl[j]=l_map_cl[hj][0].cl[j]-1; l_map_tusync[hj][0].tusync[j]=l_map_tusync[hj][0].tusync[j]-25.; } if(qpostcmrot(tcutmin[j][hj]-25)){ l_map_cl[hj][1].cl[j]=l_map_cl[hj][1].cl[j]-1; l_map_tusync[hj][1].tusync[j]=l_map_tusync[hj][1].tusync[j]-25.; } if(qpostcmrot> (tcutmax[j][hj]+25) && qpostcmrot< (tcutmax[j][hj]+50)){ l_map_cl[hj][0].cl[j]=l_map_cl[hj][0].cl[j]-2; l_map_tusync[hj][0].tusync[j]=l_map_tusync[hj][0].tusync[j]-50.; } if(qpostcmrot<(tcutmin[j][hj]-25) && qpostcmrot> (tcutmin[j][hj]-50) ){ l_map_cl[hj][1].cl[j]=l_map_cl[hj][1].cl[j]-2; l_map_tusync[hj][1].tusync[j]=l_map_tusync[hj][1].tusync[j]-50.; } } landevt->qdc1[num]=l_map_QDC[hj][0].QDC[j]; landevt->qdc2[num]=l_map_QDC[hj][1].QDC[j]; landevt->tac1[num]=l_map_tim[hj][0].tim[j]; landevt->tac2[num]=l_map_tim[hj][1].tim[j]; landevt->t171[num]=l_map_tim[hj][0].tim17[j]; landevt->t172[num]=l_map_tim[hj][1].tim17[j]; landevt->tcl1[num]=l_map_cl[hj][0].cl[j]; landevt->tcl2[num]=l_map_cl[hj][1].cl[j]; landevt->hit[num]=l_map_hit[hj].hit[j]; landevt->tcal1[num]=l_map_tusync[hj][0].tusync[j]; landevt->tcal2[num]=l_map_tusync[hj][1].tusync[j]; num++; } } //reinitialise the variables here? } //for(int hj=0; hj<20; hj++) .. landevt->rawmulti=num; //need to put all the l_map_tusync vals into the trootevent as well as the l_map_ut (t1-t2) //then try plotting as a histo return nt; } int TLANDEvent::TLANDTSync() { const char *name[] = {"landsynctac1int.txt", "landsynctac2int.txt", "landsynct171int.txt", "landsynct172int.txt", "landsynctac1grad.txt","landsynctac2grad.txt", "landsynct171grad.txt","landsynct172grad.txt"}; // string flandmapping = flandcaldir + "LANDMAPPING.txt"; FILE *infile[8]; //reset all to 0 memset(lcalC1, 0, sizeof(lcalC1)); memset(lcalC2, 0, sizeof(lcalC2)); memset(lcalC5, 0, sizeof(lcalC5)); memset(lcalC6, 0, sizeof(lcalC6)); memset(lcalM1, 0, sizeof(lcalM1)); memset(lcalM2, 0, sizeof(lcalM2)); memset(lcalM5, 0, sizeof(lcalM5)); memset(lcalM6, 0, sizeof(lcalM6)); int ok = 8; for(int i=0; i<8; i++) { string flandcalfile = flandcaldir + name[i]; cout << flandcalfile.c_str() << endl; // getchar(); // infile[i] = fopen(name[i], "r"); infile[i] = fopen(flandcalfile.c_str(), "r"); if(infile[i]==0) { cout << "TLANDTSync>> Could not get calib file:" <> Could not get par file:" <> Could not get par file:" <> Could not get par file:" <