00001 {
00002 gROOT->Reset();
00003 gROOT->SetStyle("Bold");
00004 gStyle->SetPalette(1);
00005 gSystem->Load("/LC/Detecteurs/MicroMegas/Offline/micromegasFrameWork/trunk/lib/libMicro.so");
00006
00007
00008
00009 bool rotate90 = true;
00010
00011
00012 int dt_min = 6;
00013 int dt_max = 8;
00014
00015
00016 int adc_cut = 30;
00017
00018
00019
00020
00021 std::ifstream xml;
00022 xml.open("complete_detector.xml",ifstream::in);
00023 std::string line = "";
00024 std::string lineb = "";
00025 while(line.find("path=")==string::npos || lineb.find("<output")==string::npos)
00026 {
00027 lineb=line;
00028 xml>>line;
00029 }
00030 int start = line.find("\"")+1;
00031 int end = line.rfind("\"")-6;
00032 TString file = line.substr(start,end);
00033
00034 for (int i=0;i<5;i++){file.Chop();}
00035 file += "_MGT.root";
00036
00037
00038
00039
00040 bool noisy[9][32][32];
00041 for (int i=0;i<32;i++){
00042 for (int j=0;j<32;j++){
00043 for (int k=0;k<9;k++){
00044 noisy[k][i][j] = 0;}}}
00045
00046
00047
00048 if (rotate90)
00049 {
00050
00051 noisy[6][5][5] = 1;
00052 noisy[7][5][5] = 1;
00053 noisy[8][5][5] = 1;
00054
00055
00056 noisy[6][5][17] = 1;
00057 noisy[8][1][15] = 1;
00058 }
00059 else
00060 {
00061
00062 noisy[6][5][5] = 1;
00063 noisy[7][5][5] = 1;
00064 noisy[8][5][5] = 1;
00065
00066
00067 noisy[6][17][5] = 1;
00068 noisy[8][15][9] = 1;
00069 }
00070
00071
00072
00073
00074
00075 int nchannel = 0;
00076 int hardid = 0;
00077 int chipid = 0;
00078 int nhit = 0;
00079 int nhit_cut = 0;
00080 int neff = 0;
00081 int xpos = 0;
00082 int ypos = 0;
00083 int zpos = 0;
00084 int adc = 0;
00085 int chbid = 0;
00086 int ntree = 0;
00087
00088 Long64_t t,t0,t1,t2,t3,dt;
00089
00090 TH2I * hxy_m2 = new TH2I("hxy_m2","Hit position distribution;y (cm);x (cm)",96,0,96,96,0,96);
00091 TH2I * hxy_m2_cut = new TH2I("hxy_m2_cut","Hit position distribution - time cut;y (cm);x (cm)",96,0,96,96,0,96);
00092 TH1I * hnhit = new TH1I("hnhit","Number of hit distribution;Nhits",10000,0,10000);
00093 TH1I * hnhit_cut = new TH1I("hnhit_cut","Number of hit distribution - time cut;Nhits",10000,0,10000);
00094 TH1I * hdt = new TH1I("hdt","Time to readout disitribution;time (200 ns clock cycle)",200,0,200);
00095 TH2I * hxy_tel[9];
00096 TString title,name;
00097
00098 for (int i=0;i<9;i++)
00099 {
00100 name = Form("hxy_tel_chamber_%i",i+1);
00101 title = Form("Hit pattern (adc>%i) chamber %i;y (cm),x (cm)",adc_cut,i+1);
00102 hxy_tel[i] = new TH2I(name,title,32,0,32,32,0,32);
00103 }
00104
00105
00106
00107
00108 TFile *f = new TFile(file);
00109 cout<<endl;
00110 cout<<"Reading file : "<<file<<endl;
00111 cout<<endl;
00112
00113 TIter nextkey(f.GetListOfKeys());
00114 TKey *key;
00115
00116
00117
00118
00119 while (key = (TKey*)nextkey())
00120 {
00121
00122 TTree *tree = (TTree*)key->ReadObj();
00123 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00124
00125 int nEvent = tree.GetEntries();
00126 ntree++;
00127 cout<<" Tree "<<ntree<<" contains "<<nEvent<<" events"<<endl;
00128
00129 MTEvent *evt = new MTEvent();
00130
00131 TBranch *branch= tree->GetBranch("MTEvent");
00132 branch->SetAddress(&evt);
00133
00134 for (int i=0;i<nEvent-1;i++)
00135 {
00136
00137 if (i%100==0){cout<<"Progress: "<<i/1./nEvent*100<<" \r"<<flush;}
00138
00139 tree.GetEntry(i);
00140 nchannel = evt->GetNchannel();
00141 hnhit->Fill(nchannel);
00142 if (i>0){hnhit_cut->Fill(nhit_cut);nhit_cut = 0;}
00143
00144
00145 for (int j=0;j<nchannel;j++)
00146 {
00147
00148 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00149
00150 chbid = channel->GetChamberId();
00151 if(rotate90 && chbid!=10)
00152 {
00153
00154
00155 xpos = channel->GetY();
00156 ypos = 10 - channel->GetX();
00157 }
00158 else
00159 {
00160 xpos = channel->GetX();
00161 ypos = channel->GetY();
00162 }
00163
00164
00165
00166
00167 if (chbid == 10)
00168 {
00169 if (xpos==35 && ypos==65) continue;
00170 if (xpos==82 && ypos==63) continue;
00171 if (xpos==2 && ypos==89) continue;
00172 hxy_m2->Fill(ypos,xpos);
00173 t2 = channel->GetBcId_Dif();
00174 t3 = channel->GetBcId_Hit();
00175 dt = t2 - t3;
00176 hdt->Fill(dt);
00177
00178 if (dt>=dt_min && dt<dt_max)
00179 {
00180 nhit_cut++;
00181 hxy_m2_cut->Fill(ypos,xpos);
00182
00183
00184 if (nhit_cut == 1)
00185 {
00186
00187 neff++;
00188
00189 }
00190
00191 }
00192 }
00193
00194
00195 else
00196 {
00197
00198 if (!noisy[chbid-1][ypos][xpos])
00199 {
00200
00201 adc = channel->GetAnalogValue();
00202
00203 if (adc>=adc_cut)
00204 {
00205 hxy_tel[chbid-1]->Fill(ypos,xpos);
00206 }
00207 }
00208 }
00209 }
00210 }
00211 }
00212
00213
00214
00215 cout<<endl;
00216 cout<<"Nhot_m2 / Nevent = "<<neff<<" / "<<nEvent<<" = "<<neff*100./nEvent<<" %"<<endl;
00217 cout<<endl;
00218
00219
00220
00221
00222 int xmax_tel[9];
00223 int ymax_tel[9];
00224 int xmax_m2 = 0;
00225 int ymax_m2 = 0;
00226 int zmax = 0;
00227
00228
00229 hxy_m2_cut->GetMaximumBin(ymax_m2,xmax_m2,zmax);
00230
00231
00232 cout<<endl;
00233 cout<<endl;
00234 cout<<"Maximum of hit profile in m2 prototype"<<endl;
00235 cout<<endl;
00236 cout<<" y-horiz. (cm) = "<<ymax_m2-1<<endl;
00237 cout<<" x-verti. (cm) = "<<xmax_m2-1<<endl;
00238 cout<<endl;
00239 cout<<endl;
00240
00241 cout<<"Maximum of hit profile in telescope pad chambers"<<endl;
00242 cout<<endl;
00243
00244 for (int i=6;i<9;i++)
00245 {
00246
00247 hxy_tel[i]->GetMaximumBin(ymax_tel[i],xmax_tel[i],zmax);
00248
00249 cout<<" Chamber "<<i+1<<endl;
00250 cout<<" y-horiz. (cm) = "<<ymax_tel[i]-1<<endl;
00251 cout<<" x-verti. (cm) = "<<xmax_tel[i]-1<<endl;
00252 cout<<endl;
00253
00254 }
00255
00256 cout<<endl;
00257
00258
00259
00260 }
00261
00262
00263
00264
00265
00266 TCanvas * c0 = new TCanvas("c0","Prototype m2",10,10,1200,800);
00267 c0->Divide(3,2);
00268
00269 c0->cd(1);
00270 hxy_m2->Draw("zcol");
00271
00272 c0->cd(2);
00273 hdt->Draw("zcol");
00274
00275 c0->cd(3);
00276 hxy_m2_cut->Draw("zcol");
00277
00278 c0->cd(4);
00279 hxy_tel[6]->Draw("zcol");
00280
00281 c0->cd(5);
00282 hxy_tel[7]->Draw("zcol");
00283
00284 c0->cd(6);
00285 hxy_tel[8]->Draw("zcol");
00286
00287 c0->Print("Plots/complete_detector_beam_profile_2d.png");
00288
00289
00290 TCanvas * c1 = new TCanvas("c1","Prototype m2",10,10,1200,600);
00291 c1->Divide(4,2);
00292
00293 c1->cd(1);
00294 hxy_m2_cut->ProjectionX()->SetFillColor(2);
00295 hxy_m2_cut->ProjectionX()->SetLineColor(1);
00296 hxy_m2_cut->ProjectionX()->Draw();
00297
00298 c1->cd(1+4);
00299 hxy_m2_cut->ProjectionY()->SetFillColor(3);
00300 hxy_m2_cut->ProjectionY()->SetLineColor(1);
00301 hxy_m2_cut->ProjectionY()->Draw();
00302
00303 c1->cd(2);
00304 hxy_tel[6]->ProjectionX()->Draw();
00305 hxy_tel[7]->ProjectionX()->SetLineColor(1);
00306 hxy_tel[6]->ProjectionX()->SetFillColor(2);
00307
00308 c1->cd(2+4);
00309 hxy_tel[6]->ProjectionY()->Draw();
00310 hxy_tel[6]->ProjectionY()->SetLineColor(1);
00311 hxy_tel[6]->ProjectionY()->SetFillColor(3);
00312
00313 c1->cd(3);
00314 hxy_tel[7]->ProjectionX()->Draw();
00315 hxy_tel[7]->ProjectionX()->SetLineColor(1);
00316 hxy_tel[7]->ProjectionX()->SetFillColor(2);
00317
00318 c1->cd(3+4);
00319 hxy_tel[7]->ProjectionY()->Draw();
00320 hxy_tel[7]->ProjectionY()->SetLineColor(1);
00321 hxy_tel[7]->ProjectionY()->SetFillColor(3);
00322
00323 c1->cd(4);
00324 hxy_tel[8]->ProjectionX()->Draw();
00325 hxy_tel[8]->ProjectionX()->SetLineColor(1);
00326 hxy_tel[8]->ProjectionX()->SetFillColor(2);
00327
00328 c1->cd(4+4);
00329 hxy_tel[8]->ProjectionY()->Draw();
00330 hxy_tel[8]->ProjectionY()->SetLineColor(1);
00331 hxy_tel[8]->ProjectionY()->SetFillColor(3);
00332
00333
00334 c1->Print("Plots/complete_detector_beam_profile_1d.png");
00335
00336
00337 cout<<endl;}