/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/TB2010/Testbeam_june_10/Gassiplex/Telescope/Track_finder_study.C

Go to the documentation of this file.
00001 {
00002   gROOT->Reset();
00003   gStyle->SetPalette(1);
00004   gSystem->Load("/home/chefdevi/micromegas_framework_03032011/trunk/libMicro.so");
00005 
00006 
00007   TString file = "b0624_5_acq_HR2_24062010_0634_merged.root";
00008   TString ped_file = "p0624_1.dat";
00009 
00010   TString filename = "/home/chefdevi/lapp_data/LC/Detecteurs/MicroMegas/data/TB2010/SPS_H4_june_2010/Root_files/pro/"+file;
00011 
00012   int event = 0;
00013   int nsigma = 2;
00014 
00015 
00016 
00017 
00018   /*Variables*/
00019 
00020   int nsuper = 0;
00021   int ntrack = 0;
00022   int nstraight = 0;
00023   int thr = 0;
00024   int adc = 0;
00025   int xpos = 0;
00026   int ypos = 0;
00027   int nchannel = 0;
00028   int xadc_max_all = 0;
00029   int yadc_max_all = 0;
00030   int content = 0;
00031   int nquiet = 0;
00032   int nhot = 0;
00033 
00034   float nEvent = 0;
00035 
00036   bool hit = 0;
00037   bool inside = 0;
00038   bool quiet = 0;
00039   bool aligned = 0;
00040 
00041   bool hot[4];
00042   int nhit[4];
00043   int xadc_max[4];
00044   int yadc_max[4];
00045   float ped_rms[4][96*4];
00046   float ped_mean[4][96*4];
00047 
00048   TH1F * hhot = new TH1F("hhot","Hot chambers",4,0,4);
00049   TH1F * hnhot = new TH1F("hnhot","Number of hot chambers per event",5,0,5);
00050   TH1F * hnhot_cumul = new TH1F("hnhot_cumul","Cumulative of number of hot chambers per event",5,0,5);
00051 
00052   TH1F * hx_raw = new TH1F("hx_raw","Raw hit pattern in X direction;x (cm)",32,0,32);
00053   TH1F * hy_raw = new TH1F("hy_raw","Raw hit pattern in Y direction;y (cm)",32,0,32);
00054 
00055   TH1F * hx_clean = new TH1F("hx_clean","Hit pattern in X direction after noise removal;x (cm)",32,0,32);
00056   TH1F * hy_clean = new TH1F("hy_clean","Hit pattern in Y direction noise removal;y (cm)",32,0,32);
00057 
00058   TH1F * hx_adc_all = new TH1F("hx_adc_all","ADC pattern in X direction;x (cm); ADC counts",32,0,32);
00059   TH1F * hy_adc_all = new TH1F("hy_adc_all","ADC pattern in Y direction;y (cm); ADC counts",32,0,32);
00060 
00061   TH1F * hthr[4];
00062   TH1F hadc_all[4];
00063   TH1F * hx_adc[4];
00064   TH1F * hy_adc[4];
00065   TH1F * hnhit_raw[4];
00066   TH1F * hnhit_clean[4];
00067   TH1F * hnhit_gold[4];
00068   TH1F * hnhit_raw_cumul[4];
00069   TH2F * hxy_raw[4];
00070   TH2F * hxy_clean[4];
00071   TString title,name;
00072 
00073   for (int i=0;i<4;i++){
00074 
00075     hot[i] = 0;
00076     nhit[i] = 0;
00077     xadc_max[i] = 0;
00078     yadc_max[i] = 0;
00079 
00080     title = Form("hthr_%i",i+1);
00081     name = Form("Threshold at 2#sigma in chamber %i;thr (fC)",i+1);
00082     hthr[i] = new TH1F(title,name,500,0,10);
00083 
00084     title = Form("hadc_all_%i",i+1);
00085     name = Form("ADC distribution in chamber %i;ADC counts",i+1);
00086     hadc_all[i] = new TH1F(title,name,1024,0,1024);
00087 
00088     title = Form("hx_adc_%i",i+1);
00089     name = Form("ADC pattern in chamber %i after noise removal;x (cm); ADC counts",i+1);
00090     hx_adc[i] = new TH1F(title,name,32,0,32);
00091 
00092     title = Form("hy_adc_%i",i+1);
00093     name = Form("ADC pattern in chamber %i after noise removal;y (cm);ADC counts",i+1);
00094     hy_adc[i] = new TH1F(title,name,32,0,32);
00095     
00096     title = Form("hnhit_clean_%i",i+1);
00097     name = Form("Number of hit in chamber %i after noise removal;nhit",i+1);
00098     hnhit_clean[i] = new TH1F(title,name,96*4,0,96*4);
00099 
00100     title = Form("hnhit_gold_%i",i+1);
00101     name = Form("Number of hit in chamber %i for golden events;nhit",i+1);
00102     hnhit_gold[i] = new TH1F(title,name,96*4,0,96*4);
00103 
00104     title = Form("hnhit_raw_%i",i+1);
00105     name = Form("Number of hit in chamber %i;nhit",i+1);
00106     hnhit_raw[i] = new TH1F(title,name,96*4,0,96*4);
00107 
00108     title = Form("hnhit_raw_cumul_%i",i+1);
00109     name = Form("Cumulative of number of hit in chamber %i;nhit",i+1);
00110     hnhit_raw_cumul[i] = new TH1F(title,name,96*4,0,96*4);
00111 
00112     title = Form("hxy_raw_%i",i+1);
00113     name = Form("Raw hit pattern in chamber %i;y (cm);x (cm)",i+1);
00114     hxy_raw[i] = new TH2F(title,name,32,0,32,32,0,32);
00115 
00116     title = Form("hxy_clean_%i",i+1);
00117     name = Form("Hit pattern in chamber %i after noise removal;y (cm);x (cm)",i+1);
00118     hxy_clean[i] = new TH2F(title,name,32,0,32,32,0,32);
00119 
00120     for (int k=0;k<96*4;k++){
00121 
00122       ped_mean[i][k] = 0;
00123       ped_rms[i][k] = 0;}}
00124 
00125 
00126 
00127 
00128   /*Read pedestal file*/
00129 
00130   int chb,chn,thr_adc,x,y;
00131   float pede,pede_err,noise,noise_err,gain;
00132 
00133   cout<<"Read file "<<ped_file<<endl;
00134   ifstream in(ped_file.Data());
00135   while(in>>chn>>x>>y>>chb>>pede>>pede_err>>noise>>noise_err>>gain){
00136     hthr[chb-1]->Fill(noise*2/gain);
00137     ped_mean[chb-1][chn] = pede;
00138     ped_rms[chb-1][chn] = noise;}
00139 
00140 
00141 
00142 
00143 
00144 
00145   /*Read data file and look for hits*/
00146 
00147   TFile *f = new TFile(filename);
00148   cout<<"reading File : "<<filename<<endl;
00149   TIter nextkey(f.GetListOfKeys());
00150   TKey *key;
00151 
00152   while (key = (TKey*)nextkey()) {
00153     
00154     TTree *tree = (TTree*)key->ReadObj();                
00155     MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00156 
00157     nEvent = tree.GetEntries();
00158     cout <<"nEvent="<<nEvent<<endl;
00159 
00160     MTEvent *evt = new MTEvent();
00161     TBranch *branch= tree->GetBranch("MTEvent");
00162     branch->SetAddress(&evt);
00163 
00164 
00165     for (int i=0;i<nEvent;i++){
00166       //for (int i=event;i<event+1;i++){
00167 
00168       /*Reset histos and variables*/
00169 
00170       nhot = 0;
00171       hx_adc_all->Reset();
00172       hy_adc_all->Reset();
00173       for (int k=0;k<4;k++){
00174         hot[k] = 0;
00175         nhit[k] = 0;
00176         xadc_max[k] = 0;
00177         yadc_max[k] = 0;
00178         hx_adc[k]->Reset();
00179         hy_adc[k]->Reset();
00180         hxy_clean[k]->Reset();
00181         hxy_raw[k]->Reset();}
00182 
00183       tree.GetEntry(i);
00184       nchannel = evt->GetNchannel();
00185       if (i%100==0){cout<<i/(1.*nEvent)*100.<<" % \r"<<flush;}
00186 
00187       for (int j=0;j<nchannel;j++){
00188 
00189         /*Get channel info*/
00190 
00191         MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00192         chb = channel->GetChamberId()-1;
00193 
00194         if (chb!=4){
00195 
00196         xpos = channel->GetX();
00197         ypos = channel->GetY();
00198 
00199         /*Test for hit*/
00200 
00201         inside = (ypos>=6) && (ypos<=22) && (xpos>=3) && (xpos<=9);
00202 
00203         if (inside){
00204 
00205           chn = channel->GetHardId();
00206           adc = channel->GetAnalogValue();
00207 
00208           hadc_all[chb]->Fill(adc);
00209           thr = floor(ped_mean[chb][chn] + nsigma * ped_rms[chb][chn] + 1);
00210           hit = ((adc + ped_mean[chb][chn] - 20) >= thr);
00211 
00212           if (hit){
00213 
00214             hx_adc_all->Fill(xpos,adc);
00215             hy_adc_all->Fill(ypos,adc);
00216             hxy_raw[chb]->Fill(ypos,xpos,adc);}}}}
00217 
00218       for (int k=0;k<4;k++){hnhit_raw[k]->Fill(hxy_raw[k]->GetEntries());}
00219 
00220       /*Look events with less than 10 hits in each chambers*/
00221 
00222       quiet = ((hxy_raw[0]->GetEntries()<10) && (hxy_raw[1]->GetEntries()<10) && (hxy_raw[2]->GetEntries()<10) && (hxy_raw[3]->GetEntries()<10));
00223 
00224       if (quiet){
00225 
00226         nquiet++;
00227 
00228         /*Identify 3x3 region of track candidate*/
00229 
00230         xadc_max_all = hx_adc_all->GetMaximumBin()-1;
00231         yadc_max_all = hy_adc_all->GetMaximumBin()-1;
00232 
00233         /*Keep hits inside region*/
00234 
00235         for (int j=0;j<nchannel;j++){
00236 
00237         MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00238         chb = channel->GetChamberId()-1;
00239 
00240         if (chb!=4){
00241 
00242           /*Get channel info*/
00243 
00244           xpos = channel->GetX();
00245           ypos = channel->GetY();
00246 
00247           /*Test for hit*/
00248 
00249           inside = ((fabs(xpos-xadc_max_all)<=1) && (fabs(ypos-yadc_max_all)<=1));
00250 
00251           if (inside){
00252 
00253             chb = channel->GetChamberId()-1;
00254             chn = channel->GetHardId();
00255             adc = channel->GetAnalogValue();
00256 
00257             thr = floor(ped_mean[chb][chn] + nsigma * ped_rms[chb][chn] + 1);
00258             hit = ((adc + ped_mean[chb][chn] - 20) >= thr);
00259 
00260             if (hit){
00261 
00262               hx_adc[chb]->Fill(xpos,adc);
00263               hy_adc[chb]->Fill(ypos,adc);
00264 
00265               hxy_clean[chb]->Fill(ypos,xpos,adc);
00266               nhit[chb]++;}}}}
00267 
00268         /*Identify hot chambers and max of ADC pattern*/
00269 
00270         for (int k=0;k<4;k++){
00271 
00272           if (nhit[k]!=0){
00273 
00274             hot[k] = 1;
00275             hhot->Fill(k);
00276             nhot++;
00277 
00278             xadc_max[k] = hx_adc[k]->GetMaximumBin()-1;
00279             yadc_max[k] = hy_adc[k]->GetMaximumBin()-1;}
00280 
00281           hnhit_clean[k]->Fill(nhit[k]);}
00282 
00283         hnhot->Fill(nhot);
00284 
00285 
00286         /*Measure gross telescope performance*/
00287 
00288         if (hot[0] && hot[1] && hot[2]){hnhit_gold[3]->Fill(nhit[3]);}
00289         if (hot[0] && hot[1] && hot[3]){hnhit_gold[2]->Fill(nhit[2]);}
00290         if (hot[0] && hot[2] && hot[3]){hnhit_gold[1]->Fill(nhit[1]);}
00291         if (hot[1] && hot[2] && hot[3]){hnhit_gold[0]->Fill(nhit[0]);}
00292 
00293 
00294         /*Select straight tracks*/
00295 
00296         if (hot[0] && hot[3] && (hot[1] || hot[2])){
00297 
00298           ntrack++;
00299 
00300           if ((xadc_max[0] == xadc_max[3]) && (yadc_max[0] == yadc_max[3])){
00301 
00302             nstraight++;
00303 
00304             if (nhit[0]==1 && nhit[3]==1){
00305 
00306               nsuper++;}}}}}}
00307 
00308 
00309 
00310   
00311 
00312   /*Calculate cumulatives*/
00313 
00314     hnhot_cumul->SetBinContent(5,hnhot->GetBinContent(5));
00315 
00316     for (int j=3;j>=0;j--){
00317       content = hnhot_cumul->GetBinContent(j+2) + hnhot->GetBinContent(j+1);
00318       hnhot_cumul->SetBinContent(j+1,content);}
00319 
00320     hnhot_cumul->Scale(1/(1.*hnhot->GetEntries()));
00321 
00322     for (int k=0;k<4;k++){
00323 
00324       hnhit_raw_cumul[k]->SetBinContent(1,hnhit_raw[k]->GetBinContent(1));
00325 
00326       for (int j=1;j<96;j++){
00327 
00328         content = hnhit_raw_cumul[k]->GetBinContent(j) + hnhit_raw[k]->GetBinContent(j+1);
00329         hnhit_raw_cumul[k]->SetBinContent(j+1,content);}
00330       
00331       hnhit_raw_cumul[k]->Scale(1/(1.*hnhit_raw[k]->GetEntries()));}
00332 
00333 
00334 
00335 
00336 
00337 
00338     cout<<endl;
00339     cout<<"Fraction of events with less than 10 hits in each chamber = "<<nquiet/nEvent*100.<<" %"<<endl;
00340     cout<<"  with 3 or 4 hot chambers = "<<hnhot->Integral(4,5)/nEvent*100.<<" %"<<endl;
00341     cout<<"    with chamber 1 and 4 hot = "<<ntrack/nEvent*100.<<" %"<<endl;
00342     cout<<"      with max in chamber 1 and 4 aligned = "<<nstraight/nEvent*100.<<" %"<<endl;
00343     cout<<"        with single hits in chamber 1 and 4 = "<<nsuper/nEvent*100.<<" %"<<endl;
00344     cout<<endl;
00345 
00346 
00347     float eff[4];
00348     float eff_err[4];
00349     float mult[4];
00350 
00351     float fnt = 0;
00352     float fn0 = 0;
00353     float fm = 0;
00354     float fnh = 0;
00355 
00356     cout<<"Telescope performance with golden events"<<endl;
00357     cout<<endl;
00358 
00359     for (i=0;i<4;i++){
00360 
00361       fm = 0;
00362       fnt = hnhit_gold[i]->GetEntries();
00363       fn0 = hnhit_gold[i]->GetBinContent(1);
00364       fnh = hnhit_gold[i]->Integral(2,10);
00365 
00366       for (k=2;k<10;k++){fm += (k-1)*hnhit_gold[i]->GetBinContent(k)/fnh;}
00367 
00368       cout<<"Chamber "<<i+1<<endl;
00369       cout<<"eff  = "<<(1-fn0/fnt)*100.<<" +/- "<<100.*sqrt(fn0/fnt/fnt/fnt*(fnt-fn0))<<" %"<<endl;
00370       cout<<"mult = "<<fm<<endl;
00371     }
00372 
00373     cout<<endl;
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381 
00382 }
00383 

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