/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/bookkeeping/Complete_detector/Beam/complete_detector_profiles.C

Go to the documentation of this file.
00001     {
00002    gROOT->Reset();
00003    //gROOT->SetStyle("Bold");
00004    gStyle->SetPalette(1);
00005    gStyle->SetOptStat(0);
00006    gSystem->Load("/LC/Detecteurs/MicroMegas/Offline/micromegasFrameWork/trunk/lib/libMicro.so");
00007 
00008 
00009    /*Set rotated telescope*/
00010    bool rotate90 = false;
00011 
00012    /*m2 prototype time cut*/
00013    int dt_min = 6;
00014    int dt_max = 8;
00015 
00016    /*telescope energy cut*/
00017    int adc_cut = 30;
00018 
00019 
00020 
00021    int nhit_max = 1e9;
00022 
00023 
00024 
00025 
00026    bool display = 0;
00027    int nshower = 250;
00028 
00029    if (display)
00030      {
00031        TCanvas * c2 = new TCanvas("c2","",10,10,500,500);
00032        //c2->Divide(3,1);
00033      }
00034 
00035 
00036 
00037 
00038    //READ INFO FROM XML
00039    std::ifstream xml;
00040    xml.open("complete_detector.xml",ifstream::in);
00041    std::string line = "";
00042    std::string lineb = "";
00043    while(line.find("path=")==string::npos || lineb.find("<output")==string::npos)
00044      {
00045         lineb=line;
00046         xml>>line;
00047      }
00048    int start = line.find("\"")+1;
00049    int end =  line.rfind("\"")-6;
00050    TString file = line.substr(start,end);
00051 
00052    for (int i=0;i<5;i++){file.Chop();}
00053    file += "_MGT.root";
00054 
00055 
00056 
00057 
00058    bool noisy[9][32][32];
00059    for (int i=0;i<32;i++){
00060      for (int j=0;j<32;j++){
00061        for (int k=0;k<9;k++){
00062          noisy[k][i][j] = 0;}}}
00063 
00064 
00065 
00066      if (rotate90)
00067   {
00068      /*HV pad*/
00069      noisy[6][5][5] = 1;
00070      noisy[7][5][5] = 1;
00071      noisy[8][5][5] = 1;
00072 
00073      /*floating pad*/
00074      noisy[6][5][17] = 1;
00075      noisy[8][1][15] = 1;
00076   }
00077   else
00078   {
00079      /*HV pad*/
00080 /*
00081      noisy[6][5][5-2] = 1;
00082      noisy[7][5][5-2] = 1;
00083      noisy[8][5][5-2] = 1;
00084 */
00085      /*floating pad*/
00086 /*
00087      noisy[6][17][5-2] = 1;
00088      noisy[8][15][9-2] = 1;
00089 */
00090    }
00091 
00092 
00093 
00094 
00095 
00096    int nchannel = 0;
00097    int hardid = 0;
00098    int chipid = 0;
00099    int nhit = 0;
00100    int nhit_cut = 0;
00101    int nhit_cut_dac1 = 0;
00102    int nhit_cut_dac2 = 0;
00103    int neff = 0;
00104    float xpos = 0;  
00105    float ypos = 0;  
00106    float zpos = 0;  
00107    int adc = 0;
00108    int chbid = 0;
00109    int ntree = 0;
00110 
00111    Long64_t t,t0,t1,t2,t3,dt;
00112    
00113    TH2I * hxy_m2 = new TH2I("hxy_m2","Hit position distribution;y (cm);x (cm)",96,0,96,96,0,96);
00114    TH2I * hxy_m2_cut = new TH2I("hxy_m2_cut","Hit position distribution - time cut;y (cm);x (cm)",96,0,96,96,0,96);
00115 
00116    TH2I * hxy_m2_dac3 = new TH2I("hxy_m2_dac3","Hit position distribution;y (pad);x (pad)",96,0,96,96,0,96);
00117    TH2I * hxy_m2_cut_dac3 = new TH2I("hxy_m2_cut_dac3","Hit position distribution - time cut;y (pad);x (pad)",96,0,96,96,0,96);
00118 
00119    TH2I * hxy_m2_dac0 = new TH2I("hxy_m2_dac0","Hit position distribution;y (pad);x (pad)",96,0,96,96,0,96);
00120    TH2I * hxy_m2_cut_dac0 = new TH2I("hxy_m2_cut_dac0","Hit position distribution - time cut;y (pad);x (pad)",96,0,96,96,0,96);
00121 
00122    TH2I * hxy_m2_dac1 = new TH2I("hxy_m2_dac1","Hit position distribution;y (pad);x (pad)",96,0,96,96,0,96);
00123    TH2I * hxy_m2_cut_dac1 = new TH2I("hxy_m2_cut_dac1","Hit position distribution - time cut;y (pad);x (pad)",96,0,96,96,0,96);
00124 
00125    TH2I * hxy_m2_dac2 = new TH2I("hxy_m2_dac2","Hit position distribution;y (pad);x (pad)",96,0,96,96,0,96);
00126    TH2I * hxy_m2_cut_dac2 = new TH2I("hxy_m2_cut_dac2","Hit position distribution - time cut;y (pad);x (pad)",96,0,96,96,0,96);
00127 
00128    TH2F * hxy_ratio_10 = new TH2F("hxy_ratio_10","Ratio of Nhit med/low;y (pad);x (pad)",96,0,96,96,0,96);
00129    TH2F * hxy_ratio_20 = new TH2F("hxy_ratio_20","Ratio of Nhit high/low;y (pad);x (pad)",96,0,96,96,0,96);
00130 
00131    TH1F * hy_ratio_10 = new TH1F("hy_ratio_10","Ratio of Nhit med/low;y (pad);ratio",96,0,96);
00132    TH1F * hy_ratio_20 = new TH1F("hy_ratio_20","Ratio of Nhit high/low;y (pad);ratio",96,0,96);
00133 
00134    TH1I * hnhit = new TH1I("hnhit","Number of hit distribution;Nhits",10000,0,10000);
00135 
00136    TH1I * hnhit_cut = new TH1I("hnhit_cut","Number of hits above low threshold;Nhits",10000,0,10000);
00137    TH1I * hnhit_cut_dac1 = new TH1I("hnhit_cut_dac1","Number of hits above medium threshold;Nhits",10000,0,10000);
00138    TH1I * hnhit_cut_dac2 = new TH1I("hnhit_cut_dac2","Number of hits above high threshold;Nhits",10000,0,10000);
00139 
00140    TH1I * hdt = new TH1I("hdt","Time to readout disitribution;time (200 ns clock cycle)",200,0,200);
00141    TH2I * hxy_tel[9];
00142    TString title,name;
00143 
00144    for (int i=0;i<9;i++)
00145      {
00146        name = Form("hxy_tel_chamber_%i",i+1);
00147        title = Form("Hit pattern (adc>%i) chamber %i;y (cm),x (cm)",adc_cut,i+1);
00148        hxy_tel[i] = new TH2I(name,title,32,0,32,32,0,32);
00149      }
00150 
00151 
00152 
00153    
00154    TFile *f = new TFile(file);
00155    cout<<endl;
00156    cout<<"Reading file : "<<file<<endl;
00157    cout<<endl;
00158 
00159    TIter nextkey(f.GetListOfKeys());
00160    TKey *key;
00161 
00162 
00163 
00164 
00165    while (key = (TKey*)nextkey())
00166      {
00167 
00168        TTree *tree = (TTree*)key->ReadObj();                
00169        MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00170 
00171        int nEvent = tree.GetEntries();
00172        ntree++;
00173        cout<<"  Tree "<<ntree<<" contains "<<nEvent<<" events"<<endl;
00174 
00175        MTEvent *evt = new MTEvent();
00176 
00177        TBranch *branch= tree->GetBranch("MTEvent");
00178        branch->SetAddress(&evt);
00179 
00180        //for (int i=0;i<nEvent-1;i++)
00181          for (int i=0;i<20;i++)
00182          {
00183 
00184 cout<<endl;
00185 cout<<"event "<<i<<endl;
00186 
00187            //if (i%100==0){cout<<"Progress: "<<i/1./nEvent*100<<" \r"<<flush;}
00188 
00189            tree.GetEntry(i);
00190            nchannel = evt->GetNchannel();
00191            hnhit->Fill(nchannel);
00192 
00193            if (nchannel < nhit_max)
00194              {
00195                if (i>0)
00196                  {
00197                    hnhit_cut->Fill(nhit_cut);
00198                    hnhit_cut_dac1->Fill(nhit_cut_dac1);
00199                    hnhit_cut_dac2->Fill(nhit_cut_dac2);
00200                    
00201                    nhit_cut = 0;
00202                    nhit_cut_dac1 = 0;
00203                    nhit_cut_dac2 = 0;
00204                  }
00205 
00206                if (display)
00207                  {
00208                    hxy_m2_cut_dac0->Reset();
00209                    hxy_m2_cut_dac1->Reset();
00210                    hxy_m2_cut_dac2->Reset();
00211                    hxy_m2_cut_dac3->Reset();
00212                  }
00213 
00214                for (int j=0;j<nchannel;j++)
00215                  {
00216                    
00217                    MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00218                    
00219                    chbid = channel->GetChamberId();
00220                    if(rotate90 && chbid!=10)
00221                      {
00222                        //xpos = channel->GetY()*1e-4;
00223                        //ypos = 10 - channel->GetX()*1e-4;
00224                        xpos = channel->GetY()*1e-4;
00225                        ypos = 10 - channel->GetX()*1e-4;
00226                      }
00227                    else
00228                      {
00229                        xpos = channel->GetX()*1e-4;
00230                        ypos = channel->GetY()*1e-4;
00231                      }             
00232                    
00233                    /*if m2*/
00234                    if (chbid == 10)
00235                      {
00236                        
00237                        hxy_m2->Fill(ypos,xpos);
00238                        t2 = channel->GetBcId_Dif();
00239                        t3 = channel->GetBcId_Hit();
00240                        dt = t2 - t3;
00241                        hdt->Fill(dt);
00242                        
00243                        int digit = channel->GetDigitalValue();
00244                        if (digit>=1)
00245                          {
00246                            hxy_m2_dac0->Fill(ypos,xpos);
00247                            hxy_m2_dac3->SetBinContent(ypos+1,xpos+1,1);
00248                            if (digit>=2)
00249                              {
00250                                hxy_m2_dac1->Fill(ypos,xpos);
00251                                hxy_m2_dac3->SetBinContent(ypos+1,xpos+1,2);
00252                                if (digit==3)
00253                                  {
00254                                    hxy_m2_dac2->Fill(ypos,xpos);
00255                                    hxy_m2_dac3->SetBinContent(ypos+1,xpos+1,3);
00256                                  }
00257                              }
00258                          }
00259                        
00260                        if (dt>=dt_min && dt<dt_max)
00261                          {
00262                            nhit_cut++;
00263                            hxy_m2_cut->Fill(ypos,xpos);
00264                            
00265                            if (digit>=1)
00266                              {
00267                                hxy_m2_cut_dac0->Fill(ypos,xpos);
00268                                hxy_m2_cut_dac3->SetBinContent(ypos+1,xpos+1,1);
00269                                if (digit>=2)
00270                                  {
00271                                    nhit_cut_dac1++;
00272                                    hxy_m2_cut_dac1->Fill(ypos,xpos);
00273                                    hxy_m2_cut_dac3->SetBinContent(ypos+1,xpos+1,2);
00274                                    if (digit==3)
00275                                      {
00276                                        nhit_cut_dac2++;
00277                                        hxy_m2_cut_dac2->Fill(ypos,xpos);
00278                                        hxy_m2_cut_dac3->SetBinContent(ypos+1,xpos+1,3);
00279                                      }
00280                                  }
00281                              }
00282                            
00283                            /*estimate of efficiency*/
00284                            if (nhit_cut == 1)
00285                              {
00286                                neff++;
00287                              }
00288                            
00289                          }
00290                      }
00291                
00292                    /*telescope*/
00293                    else
00294                      {                 
00295                        if (!noisy[chbid-1][ypos][xpos])
00296                          {
00297                            
00298                            adc = channel->GetAnalogValue();
00299                            
00300                            if (adc>=adc_cut)
00301                              {
00302 
00303                                 if (chbid<=6){xpos=xpos*1e4/250;ypos=ypos*1e4/250;}
00304 
00305                                 cout<<chbid<<" "<<xpos<<" "<<ypos<<" "<<adc<<endl;
00306         
00307                                hxy_tel[chbid-1]->Fill(ypos,xpos);
00308                              }
00309                          }
00310                      }
00311                  }
00312 
00313                if (nhit_cut>=nshower){
00314                  
00315                  if (display){
00316                    cout<<endl;
00317                    cout<<i<<" "<<nhit_cut<<endl;
00318                    cout<<endl;}
00319                  
00320                  if (display)
00321                    {
00322                      title = Form("Event %i",i+1);
00323                      hxy_m2_cut_dac3->SetTitle(title.Data());
00324                      hxy_m2_cut_dac3->Draw("zcol");
00325                      /*
00326                        c2->cd(1);
00327                        hxy_m2_cut_dac0->Draw("zcol");
00328                        c2->cd(2);
00329                        hxy_m2_cut_dac1->Draw("zcol");
00330                        c2->cd(3);
00331                        hxy_m2_cut_dac2->Draw("zcol");
00332                      */
00333                      c2->Update();
00334                      
00335                      title = Form("~/hxy_shower_375v_event_%i.png",i+1);
00336                      c2->Print(title.Data());
00337                      
00338                      title = Form("~/hxy_shower_375v_event_%i.C",i+1);
00339                      c2->Print(title.Data());
00340                      
00341                      /*
00342                        int temp = 0;
00343                        cin>>temp;
00344                        if (temp==9){break;}
00345                      */
00346                    }
00347                }
00348                
00349              }
00350          }
00351      }
00352     
00353 
00354 
00355    cout<<endl;
00356    cout<<"Nhot_m2 / Nevent = "<<neff<<" / "<<nEvent<<" = "<<neff*100./nEvent<<" %"<<endl;
00357    cout<<endl;
00358 
00359 
00360 
00361 
00362    //Ratios
00363 
00364    for (int i=0;i<96;i++)
00365      {
00366        int content0 = hxy_m2_cut_dac0->ProjectionX()->GetBinContent(i+1);
00367        
00368        if(content0!=0)
00369          {
00370            int content1 = hxy_m2_cut_dac1->ProjectionX()->GetBinContent(i+1);
00371            
00372            if(content1>10)
00373              {
00374                float ratio10 = 1.*content1/content0;
00375                float ratio10_err = ratio10 * sqrt(1./content0 + 1./content1);
00376                
00377                hy_ratio_10->SetBinContent(i+1,ratio10);
00378                hy_ratio_10->SetBinError(i+1,ratio10_err);
00379                
00380                int content2 = hxy_m2_cut_dac2->ProjectionX()->GetBinContent(i+1);
00381                
00382                if(content2>10)
00383                  {
00384                    float ratio20 = 1.*content2/content0;
00385                    float ratio20_err = ratio20 * sqrt(1./content0 + 1./content2);                  
00386 
00387                    hy_ratio_20->SetBinContent(i+1,ratio20);
00388                    hy_ratio_20->SetBinError(i+1,ratio20_err);
00389                  }
00390              }
00391          }
00392      }
00393    
00394 
00395 for (int i=0;i<96;i++)
00396      {
00397        for (int j=0;j<96;j++)
00398          {
00399            int content0 = hxy_m2_cut_dac0->GetBinContent(i+1,j+1);
00400            
00401            if(content0!=0)
00402              {
00403                int content1 = hxy_m2_cut_dac1->GetBinContent(i+1,j+1);
00404 
00405                if(content1>10)
00406                  {
00407                    float ratio10 = 1.*content1/content0;
00408 
00409                    hxy_ratio_10->SetBinContent(i+1,j+1,ratio10);
00410 
00411                    int content2 = hxy_m2_cut_dac2->GetBinContent(i+1,j+1);
00412 
00413                    if(content2>10)
00414                      {
00415                        float ratio20 = 1.*content2/content0;
00416 
00417                        hxy_ratio_20->SetBinContent(i+1,j+1,ratio20);
00418                      }
00419                  }
00420              }
00421          }
00422      }
00423 
00424 
00425 
00426 
00427 
00428 
00429 
00430    int xmax_tel[9];
00431    int ymax_tel[9];
00432    int xmax_m2 = 0;
00433    int ymax_m2 = 0;
00434    int zmax = 0;
00435 
00436 
00437    hxy_m2_cut->GetMaximumBin(ymax_m2,xmax_m2,zmax);
00438 
00439 
00440    cout<<endl;
00441    cout<<endl;
00442    cout<<"Maximum of hit profile in m2 prototype"<<endl;
00443    cout<<endl;
00444    cout<<"    y-horiz. (cm) = "<<ymax_m2-1<<endl;
00445    cout<<"    x-verti. (cm) = "<<xmax_m2-1<<endl;
00446    cout<<endl;
00447    cout<<endl;
00448 
00449    cout<<"Maximum of hit profile in telescope pad chambers"<<endl;
00450    cout<<endl;
00451 
00452    for (int i=6;i<9;i++)
00453      {
00454  
00455        hxy_tel[i]->GetMaximumBin(ymax_tel[i],xmax_tel[i],zmax);
00456 
00457        cout<<"  Chamber "<<i+1<<endl;
00458        cout<<"    y-horiz. (cm) = "<<ymax_tel[i]-1<<endl;
00459        cout<<"    x-verti. (cm) = "<<xmax_tel[i]-1<<endl;
00460        cout<<endl;
00461 
00462      }
00463 
00464 
00465 
00466 
00467     
00468 
00469 
00470 if (0){
00471 
00472 
00473    TCanvas * c0 = new TCanvas("c0","Prototype m2",10,10,1200,800);
00474    c0->Divide(3,2);
00475 
00476    c0->cd(1);
00477    hxy_m2->Draw("zcol");
00478 
00479    c0->cd(2);
00480    hdt->Draw("zcol");
00481 
00482    c0->cd(3);
00483    hxy_m2_cut->Draw("zcol");
00484 
00485    c0->cd(4);
00486    hxy_tel[6]->Draw("zcol");
00487 
00488    c0->cd(5);
00489    hxy_tel[7]->Draw("zcol");
00490 
00491    c0->cd(6);
00492    hxy_tel[8]->Draw("zcol");
00493 
00494    c0->Print("Plots/complete_detector_beam_profile_2d.png");
00495 
00496 
00497    TCanvas * c1 = new TCanvas("c1","Prototype m2",10,10,1200,600);
00498    c1->Divide(4,2);
00499 
00500    c1->cd(1);
00501    hxy_m2_cut->ProjectionX()->SetFillColor(2);
00502    hxy_m2_cut->ProjectionX()->SetLineColor(1);
00503    hxy_m2_cut->ProjectionX()->Draw();
00504 
00505    c1->cd(1+4);
00506    hxy_m2_cut->ProjectionY()->SetFillColor(3);
00507    hxy_m2_cut->ProjectionY()->SetLineColor(1);
00508    hxy_m2_cut->ProjectionY()->Draw();
00509 
00510    c1->cd(2);
00511    hxy_tel[6]->ProjectionX()->Draw();
00512    hxy_tel[7]->ProjectionX()->SetLineColor(1);
00513    hxy_tel[6]->ProjectionX()->SetFillColor(2);
00514 
00515    c1->cd(2+4);
00516    hxy_tel[6]->ProjectionY()->Draw();
00517    hxy_tel[6]->ProjectionY()->SetLineColor(1);
00518    hxy_tel[6]->ProjectionY()->SetFillColor(3);
00519 
00520    c1->cd(3);
00521    hxy_tel[7]->ProjectionX()->Draw();
00522    hxy_tel[7]->ProjectionX()->SetLineColor(1);
00523    hxy_tel[7]->ProjectionX()->SetFillColor(2);
00524 
00525    c1->cd(3+4);
00526    hxy_tel[7]->ProjectionY()->Draw();
00527    hxy_tel[7]->ProjectionY()->SetLineColor(1);
00528    hxy_tel[7]->ProjectionY()->SetFillColor(3);
00529 
00530    c1->cd(4);
00531    hxy_tel[8]->ProjectionX()->Draw();
00532    hxy_tel[8]->ProjectionX()->SetLineColor(1);
00533    hxy_tel[8]->ProjectionX()->SetFillColor(2);
00534 
00535    c1->cd(4+4);
00536    hxy_tel[8]->ProjectionY()->Draw();
00537    hxy_tel[8]->ProjectionY()->SetLineColor(1);
00538    hxy_tel[8]->ProjectionY()->SetFillColor(3);
00539 
00540 
00541    c1->Print("Plots/complete_detector_beam_profile_1d.png");
00542 
00543 
00544    cout<<endl;}
00545 
00546 }
00547 
00548 }

Generated on Mon Jan 7 13:15:20 2013 for MicromegasFramework by  doxygen 1.4.7