00001
00002
00003
00004
00005
00006
00007
00008 #include <map>
00009 #include <iostream>
00010 #include "TH1I.h"
00011 #include "TH2I.h"
00012 #include "TCanvas.h"
00013 #include "TFile.h"
00014 #include <TROOT.h>
00015 #include <TRint.h>
00016 #include <TKey.h>
00017 #include "TTree.h"
00018 #include <TApplication.h>
00019
00020 #include "root/MTRun.hh"
00021 #include "root/MTEvent.hh"
00022 #include "root/MTChannel.hh"
00023
00024
00025 using namespace std;
00026
00027
00028
00029 void add(map<unsigned int,map<unsigned int ,int> >&channels_map, unsigned int asu, unsigned int hit_time){
00030
00031 if ( channels_map.find(asu) == channels_map.end()) {
00032
00033 map<unsigned int, int> nbHitMap;
00034 nbHitMap[hit_time]=1;
00035 channels_map.insert(make_pair(asu,nbHitMap));
00036 }
00037 else{
00038
00039 map<unsigned int, int> &nbHitMap = channels_map.find(asu)->second;
00040 if (nbHitMap.find(hit_time) == nbHitMap.end()){
00041
00042 nbHitMap.insert(make_pair(hit_time,1));
00043 }
00044 else{
00045
00046 nbHitMap[hit_time] = nbHitMap[hit_time]++;
00047 }
00048 }
00049 }
00050
00051
00052
00053 int main(void){
00054
00055
00056
00057
00058
00059 bool plot = 1;
00060
00061
00062 Int_t blabla = 2;
00063
00064
00065 Int_t threshold = 400;
00066
00067
00068 Int_t E_threshold = 123;
00069
00070
00071 Int_t nb_plots = 30;
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 string file = "/lapp_data/LC/Detecteurs/MicroMegas/data/TB2012/SPS_H2_may_2012/Production/CaloHits/CaloHit_DHCAL_714448_I4_0.slcio.root";
00095
00096
00097
00098
00099 TApplication *theApp;
00100 theApp = new TRint("App", 0, NULL);
00101 TCanvas *c0 = new TCanvas("c0", "Prototype m2", 100, 50, 1000, 600);
00102 TH2I *hxy = new TH2I("hxy","Hit position distribution (No time cut);y (cm);x (cm)",96,0,96,96,0,96);
00103 TH2I *hxy2 = new TH2I("hxy2","Hit position distribution (at the time where it is square);y (cm);x (cm)",96,0,96,96,0,96);
00104 TH2I *hxy3 = new TH2I("hxy3","Hit position distribution (at t_square - 3 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00105 TH2I *hxy4 = new TH2I("hxy4","Hit position distribution (at t_square - 2 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00106 TH2I *hxy5 = new TH2I("hxy5","Hit position distribution (at t_square - 1 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00107 TH2I *hxy6 = new TH2I("hxy6","Hit position distribution (at t_square + 1 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00108 TH2I *hxy7 = new TH2I("hxy7","Hit position distribution (at t_square + 2 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00109 TH2I *hxy8 = new TH2I("hxy8","Hit position distribution (at t_square + 3 bcid);y (cm);x (cm)",96,0,96,96,0,96);
00110
00111
00112
00113 TFile *f = new TFile(file.c_str());
00114 if(blabla==1||blabla==2||blabla==3){
00115 cout<<endl;
00116 cout<<"reading File : "<<file<<endl;
00117
00118 }
00119
00120
00121 TIter nextkey(f->GetListOfKeys());
00122 TKey *key;
00123 UInt_t counter = 0;
00124
00125 if(blabla==1||blabla==2||blabla==3) cout<<endl;
00126
00127
00128
00129 while (key = (TKey*)nextkey()) {
00130
00131 counter++;
00132 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00133
00134 TTree *tree = (TTree*)key->ReadObj();
00135 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00136
00137 Int_t nEvent = tree->GetEntries();
00138 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl;
00139
00140 MTEvent *evt = new MTEvent();
00141
00142 TBranch *branch= tree->GetBranch("MTEvent");
00143 branch->SetAddress(&evt);
00144 if(blabla==2||blabla==3) f->Print();
00145
00146
00147 bool IsSquare = 0;
00148 Int_t list_square_events[nEvent][4];
00149
00150 UInt_t list_event[nEvent];
00151
00152 UInt_t nb_tot = 0;
00153
00154 UInt_t begin_t = 0;
00155 UInt_t end_t = 0;
00156
00157
00158
00159 for (int i=0;i<nEvent-1;i++){
00160
00161 tree->GetEntry(i);
00162
00163 UInt_t nchannel = evt->GetNchannel();
00164
00165
00166
00167 map<unsigned int,map<unsigned int,int> > channels_map;
00168
00169
00170 Int_t tmin=0;
00171 Int_t tmax=0;
00172
00173
00174 IsSquare=0;
00175
00176
00177 UInt_t SquareTime=0;
00178
00179
00180 for (int j=0;j<nchannel;j++){
00181
00182
00183 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00184
00185
00186 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00187 UInt_t board_id = channel->GetBoardId();
00188 int DigiEng = channel->GetDigitalValue();
00189
00190
00191
00192 if(j==0) {
00193 tmin=hit_time;
00194 tmax=hit_time;
00195 }
00196 if(hit_time<tmin) tmin=hit_time;
00197 if(hit_time>tmax) tmax=hit_time;
00198
00199
00200 if(i==0 && j==0) {
00201 begin_t=hit_time;
00202 end_t=hit_time;
00203 }
00204 if(hit_time<begin_t) begin_t=hit_time;
00205 if(hit_time>end_t) end_t=hit_time;
00206
00207
00208 if(E_threshold==123) if(DigiEng>=1) add(channels_map, board_id, hit_time);
00209 else if(DigiEng>=E_threshold) add(channels_map, board_id, hit_time);
00210 }
00211
00212 unsigned int timeold=0;
00213
00214
00215 map<unsigned int, map<unsigned int,int> >::iterator iter1;
00216 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00217
00218 unsigned int azu=iter1->first;
00219 map<unsigned int,int> hits_per_time=iter1->second;
00220
00221 map<unsigned int,int>::iterator iter2;
00222 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00223
00224 unsigned int time = iter2->first;
00225 int nb_hits = iter2->second;
00226
00227
00228 if (nb_hits>=threshold) {
00229
00230
00231 IsSquare=1;
00232
00233
00234 SquareTime=time;
00235
00236 if(blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at time "<<time<<" with n_hits = "<<nb_hits<<" DELTA T= "<<time-timeold<<endl;
00237 timeold=time;
00238
00239
00240 list_square_events[nb_tot][0] = i+1;
00241 list_square_events[nb_tot][1] = azu;
00242 list_square_events[nb_tot][2] = time;
00243 list_square_events[nb_tot][3] = nb_hits;
00244
00245
00246
00247
00248
00249
00250
00251
00252 nb_tot++;
00253
00254
00255
00256 list_event[nb_tot-1] = i+1;
00257
00258 }
00259 }
00260 }
00261
00262
00263 if (IsSquare && plot){
00264
00265
00266 for (int j=0;j<nchannel;j++){
00267
00268
00269 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00270
00271
00272 UInt_t board_id = channel->GetBoardId();
00273 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00274 int DigiEng = channel->GetDigitalValue();
00275
00276
00277 if(E_threshold==123){
00278 if(DigiEng>=1){
00279 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00280 if(hit_time==SquareTime) hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00281 if(hit_time==SquareTime-3) hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00282 if(hit_time==SquareTime-2) hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00283 if(hit_time==SquareTime-1) hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00284 if(hit_time==SquareTime+1) hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00285 if(hit_time==SquareTime+2) hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00286 if(hit_time==SquareTime+3) hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00287 }
00288 if(DigiEng>=2){
00289 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00290 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00291 if(hit_time==SquareTime) {
00292
00293 hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00294 hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00295 }
00296 if(hit_time==SquareTime-3) {
00297 hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00298 hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00299 }
00300 if(hit_time==SquareTime-2) {
00301 hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00302 hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00303 }
00304 if(hit_time==SquareTime-1) {
00305 hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00306 hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00307 }
00308 if(hit_time==SquareTime+1) {
00309 hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00310 hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00311 }
00312 if(hit_time==SquareTime+2) {
00313 hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00314 hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00315 }
00316 if(hit_time==SquareTime+3) {
00317 hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00318 hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00319 }
00320 }
00321 if(DigiEng>=3){
00322 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00323 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00324 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00325 if(hit_time==SquareTime) {
00326
00327 hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00328 hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00329 hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00330 }
00331 if(hit_time==SquareTime-3) {
00332 hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00333 hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00334 hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00335 }
00336 if(hit_time==SquareTime-2) {
00337 hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00338 hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00339 hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00340 }
00341 if(hit_time==SquareTime-1) {
00342 hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00343 hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00344 hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00345 }
00346 if(hit_time==SquareTime+1) {
00347 hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00348 hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00349 hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00350 }
00351 if(hit_time==SquareTime+2) {
00352 hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00353 hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00354 hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00355 }
00356 if(hit_time==SquareTime+3) {
00357 hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00358 hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00359 hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00360 }
00361 }
00362 }
00363 else{
00364 hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00365 if(hit_time==SquareTime) hxy2->Fill(channel->GetY()/10000,channel->GetX()/10000);
00366 if(hit_time==SquareTime-3) hxy3->Fill(channel->GetY()/10000,channel->GetX()/10000);
00367 if(hit_time==SquareTime-2) hxy4->Fill(channel->GetY()/10000,channel->GetX()/10000);
00368 if(hit_time==SquareTime-1) hxy5->Fill(channel->GetY()/10000,channel->GetX()/10000);
00369 if(hit_time==SquareTime+1) hxy6->Fill(channel->GetY()/10000,channel->GetX()/10000);
00370 if(hit_time==SquareTime+2) hxy7->Fill(channel->GetY()/10000,channel->GetX()/10000);
00371 if(hit_time==SquareTime+3) hxy8->Fill(channel->GetY()/10000,channel->GetX()/10000);
00372 }
00373 }
00374
00375
00376 c0->Divide(4,2);
00377 c0->cd(1);
00378 hxy->GetXaxis()->SetTitle("X (cm)");
00379 hxy->GetYaxis()->SetTitle("Y (cm)");
00380 hxy->Draw("zcol");
00381
00382 c0->cd(2);
00383 hxy3->GetXaxis()->SetTitle("X (cm)");
00384 hxy3->GetYaxis()->SetTitle("Y (cm)");
00385 hxy3->Draw("zcol");
00386
00387 c0->cd(3);
00388 hxy4->GetXaxis()->SetTitle("X (cm)");
00389 hxy4->GetYaxis()->SetTitle("Y (cm)");
00390 hxy4->Draw("zcol");
00391
00392 c0->cd(4);
00393 hxy5->GetXaxis()->SetTitle("X (cm)");
00394 hxy5->GetYaxis()->SetTitle("Y (cm)");
00395 hxy5->Draw("zcol");
00396
00397 c0->cd(5);
00398 hxy2->GetXaxis()->SetTitle("X (cm)");
00399 hxy2->GetYaxis()->SetTitle("Y (cm)");
00400 hxy2->Draw("zcol");
00401
00402 c0->cd(6);
00403 hxy6->GetXaxis()->SetTitle("X (cm)");
00404 hxy6->GetYaxis()->SetTitle("Y (cm)");
00405 hxy6->Draw("zcol");
00406
00407 c0->cd(7);
00408 hxy7->GetXaxis()->SetTitle("X (cm)");
00409 hxy7->GetYaxis()->SetTitle("Y (cm)");
00410 hxy7->Draw("zcol");
00411
00412 c0->cd(8);
00413 hxy8->GetXaxis()->SetTitle("X (cm)");
00414 hxy8->GetYaxis()->SetTitle("Y (cm)");
00415 hxy8->Draw("zcol");
00416
00417
00418 char plotname[20] = "TH123_plot_evt";
00419 char buf[10];
00420 sprintf(buf,"%d",i+1);
00421 strcat(plotname, buf);
00422 strcat(plotname,".gif");
00423 c0->SaveAs(plotname);
00424
00425
00426 c0->Clear();
00427
00428
00429 hxy->Reset();
00430 hxy2->Reset();
00431 hxy3->Reset();
00432 hxy4->Reset();
00433 hxy5->Reset();
00434 hxy6->Reset();
00435 hxy7->Reset();
00436 hxy8->Reset();
00437 }
00438 if(nb_tot > nb_plots) break;
00439 }
00440
00441
00442 if(blabla==2||blabla==3) cout<<endl;
00443 if(blabla==1||blabla==2||blabla==3) {
00444
00445
00446 cout<<"In key "<<counter<<":"<<endl<<endl;;
00447 cout<<" Nb square evt = "<<nb_tot<<endl;
00448 cout<<" Nb square evt / Nevent tot = "<<1.0*nb_tot/nEvent*100.<<" %"<<endl;
00449
00450 float rate = float(nb_tot)/(end_t-begin_t)*1000000000/200*60;
00451 cout<<" Square event rate = "<<rate<<" event/min"<<endl<<endl;
00452
00453
00454 cout<<"List of square events: "<<endl;
00455 for(int it=0;it<nb_tot;it++) cout<<" "<<list_event[it];
00456 cout<<endl<<endl;
00457
00458
00459
00460
00461
00462 }
00463
00464 if(blabla==2||blabla==3) {
00465
00466
00467 cout<<"Hereafter I show the list of square events in each board/asu at each time and their number of hits:"<<endl;
00468 cout<<"Event, Board/asu, time, Nb_hits"<<endl;
00469 for(int it=0;it<nb_tot;it++) {
00470 for(int itt=0;itt<4;itt++) cout<<list_square_events[it][itt]<<"; ";
00471 cout<<endl;
00472 }
00473 cout<<endl;
00474
00475
00476
00477
00478
00479
00480 cout<<endl;
00481 }
00482 cout<<endl;
00483 }
00484 theApp->Run();
00485 delete theApp;
00486 return 0;
00487 }
00488