void SetStreamDelay(Short_t mid,Short_t link, Float_t var){ // // Q. Why is this code tucked away in a subroutine? // A. because CINT objects to the appearance of a reference to the TST object // (e->) even if it is in a section of the main code which is not called // unless the object is present. I must admit that I do not understand why, // since it was (and still is) fine within stan_fitscan. Anyway, the // "proper" fix for this would most likely have been to include a definition // of the TST class, but this was easier... PWP 30.10.00 // if(e->m[mid]->present){ if(link==0){ e->ConfigureVariable(mid,21,var); // ST_STREAM_DELAY0 } else { e->ConfigureVariable(mid,22,var); // ST_STREAM_DELAY1 } } } void StreamDelayPlot(Int_t run, Int_t scan, Int_t moi, Int_t online, Int_t graphics, Int_t postscript) { // // This macro fits the falling and rising edges of the stream delay plateau // and finds a point halfway between the two edges. // // version 0.10 PWP 06.06.01 UNTESTED // version 0.20 PWP 31.07.01 TESTED!! // version 0.21 PWP 08.08.01 bugfix // version 0.22 PWP 21.03.02 add leading zero to PS file time stamp // version 0.23 BJG 30.04.02 Put DUT type on plot // Fix some memory leaks // version 0.24 PWP 05.02.03 Make results output appear after "#" character // - avoids incompatibility with SCT DB // version 0.25 AG 27.05.03 Delay setting optimised for AERO, delay is now set to approx halfway between // the rising and falling edges of the stream delay. This resolves an issue with jitter // on the falling edges of the data - due to an assymetric clock used within MUSTARD this // can cause incorrect decoding of the data streams. // #ifdef DATA_DIRECTORY // do not reload parameters.h #else // must load parameters.h #include #endif Char_t h_name[80], f_name[128], s[100]; Int_t link; // Load other files needed by this one gROOT->LoadMacro("stan_util.cpp"); gROOT->LoadMacro("ToolBox.cpp"); stan_styles(); gStyle->SetOptStat(0); // // Open the root data file and obtain pointers to the event histogram // sprintf(f_name,"%sstrun%d_%d.root",DATA_DIRECTORY,run,scan); TFile *strun = new TFile(f_name); TDatime *dt = new TDatime; Int_t date = dt->GetDate(); Int_t the_time = dt->GetTime(); // // Open the output canvas // Int_t ps_page=0; Int_t screen_page=0; TCanvas* SDC =0; TPostScript* ps =0; if((graphics!=0)||(postscript!=0)){ graphics = 1; SDC=new TCanvas("SDC","Stream Delay Scan",1100,750); } TObjString *time = 0; TObjString *place = 0; TObjString *mname = 0; TObjString *type = 0; TPad *pad_sd = 0; // // loop over modules // Int_t start = 0; Int_t end = 0; if(moi==-1){ start = 0; end = MAX_MODULES; } else { start = moi; end = moi+1; } Int_t dowait=0; if((graphics!=0)&&(end-start>1)){ dowait = 1; } TH1F* hp_link[MAX_LINKS]; Int_t link_centre[MAX_LINKS]; Int_t link_optimal[MAX_LINKS]; Int_t link_fitOK[MAX_LINKS]; hp_link[0]=(TH1F*)0; hp_link[1]=(TH1F*)0; for(moi=start;moiDelete(); link_centre[link]=-1; link_optimal[link]=-1; } if((screen_page>0)&&(dowait)){ printf("Enter a string to continue\n"); scanf("%s",s); } ps_page++; screen_page++; if(ps){ ps->NewPage(); } if(time) delete time; if(place) delete place; if(mname) delete mname; if(type) delete type; time = (TObjString*)strun->Get("Time"); place = (TObjString*)strun->Get("Place"); sprintf(h_name,"ModuleName;%d",moi+1); mname = (TObjString*)strun->Get(h_name); sprintf(h_name,"DUT;%d",moi+1); type = (TObjString*)strun->Get(h_name); sprintf(h_name,"h_scan0;%d",moi+1); TH2F *h_scan0= (TH2F*)strun->Get(h_name); sprintf(h_name,"h_scan1;%d",moi+1); TH2F *h_scan1= (TH2F*)strun->Get(h_name); // // only attempt plotting or fitting if data exists for the module // Int_t links_with_data=0; if((h_scan0!=0)&&(h_scan1!=0)){ printf("Fitting data for module %d\n",moi); if(postscript){ ps_page=0; sprintf(f_name,"%s%s_StreamDelayPlot_%d_%06d.ps",PS_DIRECTORY,mname->GetName(),date,the_time); ps = new TPostScript(f_name,112); } if(SDC){ // the canvas open, therefore the plots are to be drawn SDC->cd(); SDC->Clear(); TPad *pad_t = new TPad("pad_t","Text", 0.01,0.91,0.99,0.99,33); pad_sd = new TPad("pad_sd","Strobe Delays", 0.01,0.01,0.99,0.90,33); pad_t->Draw(); pad_sd->Draw(); pad_sd->Divide(2,1,0,0); pad_t->cd(); TPaveText *t1 = new TPaveText(0.0,0.0,1.0,1.0); t1->SetFillColor(10); t1->SetTextAlign(13); t1->SetTextSize(0.3); t1->SetTextColor(4); sprintf(s,"ATLAS SCT Module Test - Strobe Delay Optimisation"); if(time) sprintf(s,"%s - %s",s,time->GetName()); if(place) sprintf(s,"%s - %s",s,place->GetName()); if(mname) sprintf(s,"%s - Module %s",s, mname->GetName()); t1->AddText(s); sprintf(s,"Page %d Run %d Scan %d Module %d ", ps_page, run, scan, moi); if(type && strlen(type->GetName()) > 0) sprintf(s, "%s - Type %s", s, type->GetName()); t1->AddText(s); t1->Draw(); } // // Loop over the links and do the calculations // for(link=0;linkProjectionY(h_name,0,767); else h_scan1->ProjectionY(h_name,0,767); hp_link[link] = (TH1F*) gDirectory->GetList()->FindObject(h_name); if(hp_link[link]->GetMaximum()>0.0){ // data for this chip links_with_data++; hp_link[link]->SetXTitle("Stream Delay"); hp_link[link]->SetYTitle("Efficiency"); Int_t bin = 0; Int_t lo_bin = 25; Int_t hi_bin = 0; for(bin=1;binGetNbinsX();bin++){ if(hp_link[link]->GetBinContent(bin)<75000){ if(binhi_bin) hi_bin=bin; } } if((hi_bin-lo_bin)<12){ // bad region does not cross zero link_centre[link] = (lo_bin+hi_bin)/2; link_optimal[link] = (link_centre[link]+9)%24; //This line has been modified 27/05/03 }else{ // bad region crosses zero - just choose the centre link_centre[link] = 0; link_optimal[link] = 12; } printf(" Link %d centre %2.1f optimum %2.1f\n", link,link_centre[link],link_optimal[link]); if(SDC){ // the canvas open, therefore the plots are to be drawn pad_sd->cd(link+1); hp_link[link]->Draw(); TMarker *CenMark=new TMarker (link_centre[link],0.5,23); CenMark->SetMarkerColor(kRed); CenMark->SetMarkerSize(1); CenMark->SetMarkerStyle(29); CenMark->Draw("same"); TMarker *OptMark=new TMarker (link_optimal[link],0.5,23); OptMark->SetMarkerColor(kRed); OptMark->SetMarkerSize(1); OptMark->SetMarkerStyle(29); OptMark->Draw("same"); TText * t = new TText(); sprintf(h_name,"%2.1f",link_centre[link]); t->DrawText(link_centre[link]-1,0.35,h_name); sprintf(h_name,"%2.1f",link_optimal[link]); t->DrawText(link_optimal[link]-1,0.35,h_name); } } else { printf(" Link %d NO DATA!!!\n",link); } // end if (data for this link) } // end for(link) if(SDC){ SDC->Update(); } if(ps) { ps->Close(); delete ps; } if(links_with_data>0){ // // Set the values // Int_t n_good_links = 0; for(link=0;link24){ link_fitOK[link] = 2; } else if((link_optimal[link]<0)||(link_optimal[link]>24)){ link_fitOK[link] = 3; } else { link_fitOK[link] = 0; // both fits are OK n_good_links++; } } if(online){ for(link=0;linkDelete(); } strun->Close(); delete strun; } } // // wrappers // void StreamDelayPlot(Int_t run, Int_t scan, Int_t moi){ // basic wrapper for use offline // show graphics but no postscript StreamDelayPlot(run,scan,moi,0,1,0); } void StreamDelayPlot(Int_t run, Int_t scan, Int_t moi, Int_t postscript){ // basic wrapper for use offline // show graphics but no postscript StreamDelayPlot(run,scan,moi,0,1,postscript); }