// Author: David Lawrence June 25, 2004 // // // MyProcessor.cc // #include #include #include #include using namespace std; #include #include #include #include #include #include #include #include #include #include //#include #include #include #include #include #include #include "bcview.h" #include "bcv_mainframe.h" #include "MyProcessor.h" extern TCanvas *maincanvas; extern bcv_mainframe *bcvmf; extern bool GO; // true=continuously display events false=wait for user extern int DOT_SOURCE; // 1=section 2=shower 3=none extern int Z_SOURCE; // 1=TDC 2=ADC extern int AMP_SOURCE; // 1=Raw 2=Calibrated extern int POSITION_WEIGHT; // 1=linear 2=logarithmic //TGeometry *geom; //------------------------------------------------------------------ // MyProcessor //------------------------------------------------------------------ MyProcessor::MyProcessor() { drew_detectors=0; adc_max = 100; shower_index = 0; Z_CENTER_BOXES = 0.0; for(int i=0; iSetRun(runnumber); ADC_TO_GEV = 0.005/125.0; // 5MeV = 125 ADC counts jparms.GetParameter("BCAL:ADC_TO_GEV", ADC_TO_GEV); return NOERROR; } //------------------------------------------------------------------ // evnt //------------------------------------------------------------------ jerror_t MyProcessor::evnt(JEventLoop *loop, int eventnumber) { // Get data vector hits; vector trigs; loop->Get(hits); loop->Get(trigs); int latch=0; if(trigs.size())latch=trigs[0]->latch; // Set event number bcvmf->SetEvent(eventnumber); // Delete objects from last event ClearEvent(); // Initialize arrays of amplitude values float left_E[18]; float right_E[18]; for(int i=0; i<18; i++)left_E[i]=right_E[i]=0.0; // Copy real data into arrays for(unsigned int i=0; isector-1)*6+hit->layer; // 1-18 if(id<1 || id>18)continue; float amp = AMP_SOURCE==1 ? (float)(hit->adc-hit->ped):hit->E_attenuated; if(amp<0.0)amp=0.0; if(hit->end==0)right_E[id-1] = amp; if(hit->end==1)left_E[id-1] = amp; } // Calculate z and E for all sections and set colors float center_E[18]; float z_segment[18]; float Etotal = 0.0; for(int i=0; i<18; i++){ center_E[i] = sqrt(left_E[i]*right_E[i]); left_boxes[i]->SetFillColor(GetShade(left_E[i])); right_boxes[i]->SetFillColor(GetShade(right_E[i])); center_boxes[i]->SetFillColor(GetShade(center_E[i],true)); Etotal += center_E[i]; // Calculate z for info at two ends float L = 400.0; float z = 0.0; if(Z_SOURCE==1){ // TDC z=0.0; }else{ // ADC float lambda = 300.0;// effective attenutation length in cm float R = left_E[i]/right_E[i]; z = (L - lambda*log(R))/2.0; if(!finite(z))z=left_boxes[i]==0 ? 0.0:L; if(z<0.0)z=0.0; if(z>L)z=L; z-=L/2.0; } z_segment[i] = z; } // Draw single dot for shower or multiple dots for sections if(DOT_SOURCE==1){ // section for(int i=0; i<18; i++){ if(left_E[i]==0.0 || right_E[i]==0.0)continue; TMarker *t = dots[marker_index++%dots.size()]; float X,Y; GetXY(x_center[i], y_center[i],z_segment[i],X,Y); Z_SHOWER[shower_index++%MAX_HIT_MARKERS] = z_segment[i]; t->SetX(X); t->SetY(Y); t->SetMarkerColor(GetDotColor(z_segment[i],X,Y)); } }else if(DOT_SOURCE==2){ // shower float xavg=0.0; float yavg=0.0; float zavg=0.0; float amp_total = 0.0; for(int i=0; i<18; i++){ float E = center_E[i]*1.0E4; //scale up so log values are positive if(E<=1.0)continue; // avoid pole at log(x=0) float amp = POSITION_WEIGHT==1 ? E:log(E); amp_total += amp; xavg += x_center[i]*amp; yavg += y_center[i]*amp; zavg += z_segment[i]*center_E[i]; } xavg /= amp_total; yavg /= amp_total; zavg /= Etotal; float X,Y; GetXY(xavg,yavg,zavg,X,Y); Z_SHOWER[shower_index++%MAX_HIT_MARKERS] = zavg; TMarker *t = dots[marker_index++%dots.size()]; t->SetX(X); t->SetY(Y); t->SetMarkerColor(GetDotColor(zavg,X,Y)); }else{ for(unsigned int i=0; iSetX(0); t->SetY(0); } } // Move z-coordinate of center plane every MAX_HIT_MARKERS events // to average of last MAX_HIT_MARKERS showers static unsigned int events_seen =0; if((events_seen++%(MAX_HIT_MARKERS/2)) == 0){ float zavg = 0.0; float n=0.0; for(int i=0; iUpdate(); return NOERROR; } //------------------------------------------------------------------ // DrawDetectors //------------------------------------------------------------------ jerror_t MyProcessor::DrawDetectors(void) { // If detectors were already drawn before, delete // the old objects for(unsigned int i=0;iSetLineColor(kBlack); box->SetLineWidth(1); box->SetFillColor(GetShade(0,k==1)); box->SetBorderSize(1); box->SetBorderMode(0); switch(k){ case 0: left_boxes.push_back(box); break; case 1: center_boxes.push_back(box); break; case 2: right_boxes.push_back(box); break; } graphics.push_back(box); } } if(k==1){ right_border_index = graphics.size(); graphics.push_back(NULL); } } // Lines to give 3-D effect xl1 = left_boxes[0]->GetX1(); yl1 = left_boxes[0]->GetY2(); xl2 = left_boxes[17]->GetX2(); yl2 = left_boxes[17]->GetY1(); xr1 = right_boxes[0]->GetX1(); yr1 = right_boxes[0]->GetY2(); xr2 = right_boxes[17]->GetX2(); yr2 = right_boxes[17]->GetY1(); TBox *box = new TBox(xl1-1, yl2-1, xl2+1, yl1+1); box->SetFillColor(kBlack); graphics[index_3D++] = box; box = new TBox(xr1-2, yr2-1, xr2+1, yr1+1); box->SetFillColor(kBlack); graphics[right_border_index] = box; // see note above TLine *line; line = new TLine(xl1-1,yl1+1,xr1-1,yr1+1); graphics.push_back(line); line = new TLine(xl2+1,yl1+1,xr2+1,yr1+1); graphics[index_3D++] = line; line = new TLine(xl1-1,yl2-1,xr1-1,yr2-1); graphics[index_3D++] = line; line = new TLine(xl2+1,yl2-1,xr2+1,yr2-1); graphics[index_3D++] = line; // Conversion factors from 3D lab coordinates to 2D screen coordinates dXdz = (xr1-xl1)/400.0; dYdz = (yr1-yl1)/400.0; dXdx = (xl2-xl1)/23.0; // bcal module is 23cm wide dYdy = (yl2-yl1)/13.0; // bcal module is 13cm high // Labels TText *left_label = new TText(50.0, 265.0,"BCAL-S"); left_label->SetTextSize(0.08); TText *center_label = new TText(265, 225.0,"Total"); center_label->SetTextSize(0.08); TText *right_label = new TText(445, 160.0,"BCAL-N"); right_label->SetTextSize(0.08); graphics.push_back(left_label); graphics.push_back(center_label); graphics.push_back(right_label); // Beam label TText *beam_lab = new TText(10.0, 120.0,"beam"); beam_lab->SetTextSize(0.06); beam_lab->SetTextAngle(0.0); TArrow *beam = new TArrow(10.0, 140.0, 50.0, 140.0, 0.02, "|>"); beam->SetLineWidth(3); graphics.push_back(beam_lab); graphics.push_back(beam); // Dots dots.clear(); marker_index = 0; for(int i=0; iDraw(); maincanvas->Update(); drew_detectors = 1; return NOERROR; } //------------------------------------------------------------------ // MoveCenterBoxes //------------------------------------------------------------------ void MyProcessor::MoveCenterBoxes(float z) { // To move to an arbitrary z position, first we find the // the deltaX and deltaY the z position is from the left // boxes. Then reposition the center boxes to be at the // left box position plus the deltas. // Don't bother moving if it is essentially in the same place if(fabs(z-Z_CENTER_BOXES)<1.0)return; float L=400.0; float x=0.0, y=0.0, X1, Y1, X2, Y2; GetXY(x,y,-L/2.0,X1,Y1); GetXY(x,y,z,X2,Y2); float deltaX = X2-X1; float deltaY = Y2-Y1; for(int i=0; i<18; i++){ center_boxes[i]->SetX1(left_boxes[i]->GetX1()+deltaX); center_boxes[i]->SetX2(left_boxes[i]->GetX2()+deltaX); center_boxes[i]->SetY1(left_boxes[i]->GetY1()+deltaY); center_boxes[i]->SetY2(left_boxes[i]->GetY2()+deltaY); } Z_CENTER_BOXES = z; } //------------------------------------------------------------------ // GetShade //------------------------------------------------------------------ int MyProcessor::GetShade(int ADC, bool transparent) { if(ADC > adc_max)ADC = adc_max; if(ADC < 0)ADC = 0; float grey = 0.8; float f = (float)ADC/(float)adc_max; f = sqrt(f); float s = 1.0 - f; float r = s*grey; float g = s*grey; float b = f*(1.0-grey) + grey; if(transparent){ r = sqrt(r); g = sqrt(g); b = sqrt(b); } return TColor::GetColor(r,g,b); } //------------------------------------------------------------------ // GetShade //------------------------------------------------------------------ int MyProcessor::GetShade(float E, bool transparent) { // This will need to do a better job once the scale is determined // from real data. if(AMP_SOURCE==1)return GetShade((int)E, transparent); return GetShade((int)(E/ADC_TO_GEV), transparent); } //------------------------------------------------------------------ // GetXY //------------------------------------------------------------------ void MyProcessor::GetXY(float x, float y, float z, float &X, float &Y) { // origin is at center of bcal X = (xl1+xr1)/2.0 + x*dXdx + z*dXdz; Y = (yl1+yr1)/2.0 + y*dYdy + z*dYdz; } //------------------------------------------------------------------ // GetDotColor //------------------------------------------------------------------ int MyProcessor::GetDotColor(float &z, float &X, float &Y) { if(z>Z_CENTER_BOXES)return kBlack; if(X > center_boxes[5]->GetX2())return kBlack; if(X < center_boxes[0]->GetX1())return kBlack; if(Y < center_boxes[0]->GetY1())return kBlack; if(Y > center_boxes[12]->GetY2())return kBlack; return 15; }