/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/Damien/evt_carre.C

Go to the documentation of this file.
00001 //####################################################
00002 //
00003 //--- Identifier et compter les évennements carrés ---
00004 //
00005 //####################################################
00006 {  
00007   
00008 gROOT->Reset();
00009 gROOT->SetStyle("Bold");
00010 gStyle->SetPalette(1);
00011 gSystem->Load("~/Micromegas/Analyse/trunk/lib/libMicro.so");
00012 
00013 gSystem->Load("~/Micromegas/Analyse/trunk/src/analyse/Damien/load.C");
00014 
00015 //using namespace std;
00016 
00017   //-----------------
00018   //User's parameters
00019   
00020   //which event do you want to plot (0 = no plot, a number = the event you want)
00021   bool plot = 1;
00022   
00023   //Do you want some info ? (0 = no, 1 = yes a little, 2 = yes a lot, 3 = yes all for debug purpose)
00024   Int_t blabla = 2;
00025   
00026   //threshold (number of hits in a given asu at a given time (maximum=1536))
00027   Int_t threshold = 500;
00028 
00029   //input data
00030   string file = "05082011_1055_MGT.root";  
00031   //-----------------
00032   
00033 
00034   //our data file
00035   TFile *f = new TFile(file.c_str());
00036   if(blabla==1||blabla==2||blabla==3){
00037     cout<<endl;
00038     cout<<"reading File : "<<file<<endl;
00039   }
00040   
00041   //key iterator
00042   TIter nextkey(f.GetListOfKeys());
00043   TKey *key;
00044   UInt_t counter = 0;
00045     
00046 //Là y'a un truc bizarre:
00047 //si la déclaration de hxy est dans le if -> ca rame, si elle est hors du if -> ca tourne bien
00048 //je comprends pas du tout pourquoi ??? 
00049   TH2I *hxy = new TH2I("hxy","Hit position distribution;y (cm);x (cm)",96,0,96,96,0,96);
00050   TH1I *hdt = new TH1I("hdt","Hit time distribution;N_hits;delta_t (/200ns)",128,0,128);
00051   if(plot){
00052     //TH2I *hxy = new TH2I("hxy","Hit position distribution;y (cm);x (cm)",96,0,96,96,0,96);
00053     TCanvas *c0 = new TCanvas("c0", "Prototype m2", 100, 50, 1000, 500);
00054     c0->Divide(2,1);
00055   }  
00056   if(blabla==1||blabla==2||blabla==3) cout<<endl;
00057   
00058 
00059   //loop on all the keys
00060   while (key = (TKey*)nextkey()) {
00061     
00062     counter++;
00063     if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl;
00064     
00065     TTree *tree = (TTree*)key->ReadObj();                
00066     MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00067 
00068     Int_t nEvent = tree.GetEntries();
00069     if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl;
00070     
00071     MTEvent *evt = new MTEvent();
00072     
00073     TBranch *branch= tree->GetBranch("MTEvent");
00074     branch->SetAddress(&evt);
00075     
00076     UInt_t list_event[nEvent];
00077     
00078     //at each new key, declare the event counters
00079     std::map<unsigned int,std::map<unsigned int,int> > nb_square;// key1=asu (board_id), key2=abs_time      
00080     UInt_t nb_tot;
00081 
00082     
00083     //loop on all the events of the key
00084     for (int i=0;i<nEvent-1;i++){
00085       
00086       tree.GetEntry(i);
00087       
00088       UInt_t nchannel = evt->GetNchannel();
00089       if(blabla==3) cout<<"Event "<<i+1<<" / "<<nEvent<<"; nb of channels=  "<<nchannel<<endl;
00090 
00091       //at each event declare the hits counter
00092       std::map<unsigned int,std::map<unsigned int,int> > channels_map;// key1=asu (board_id), key2=abs_time      
00093       
00094 
00095       //loop on all the channels of the event
00096       for (int j=0;j<nchannel;j++){
00097         
00098         //create this channel
00099         MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j);
00100 
00101         //at each channel declare board_id and abs_time
00102         UInt_t board_id = channel->GetBoardId();
00103         UInt_t abs_time =  channel->GetBcId_Abs() - (channel->GetBcId_Dif() - channel->GetBcId_Hit() );
00104         
00105         //upgrade the hits counter of the good board at the good time
00106         if ( channels_map.find(board_id) == channels_map.end()) { // if this asu doesn't exist yet
00107           std::map<unsigned int, int> nbHitMap;
00108           nbHitMap[abs_time]=1;
00109           channels_map.insert(make_pair(board_id,nbHitMap));
00110         }
00111         else{ // if this asu already exist 
00112           std::map<unsigned int, int> &nbHitMap =  channels_map.find(board_id)->second;
00113           if (nbHitMap.find(abs_time) == nbHitMap.end()){ //if this abs_time doesn't exist yet
00114             nbHitMap.insert(make_pair(abs_time,1)); 
00115           }
00116           else{ //if this abs time already exist
00117             nbHitMap[abs_time] = nbHitMap[abs_time]++;
00118           }
00119         }  
00120         
00121         if(blabla==3) cout<<"Channel : "<<channel<<"; hit on asu "<<board_id<<"; at memory order "<<mem_order<<endl;
00122         
00123         //if we want to plot this event, fill the histogramm
00124         if (plot){
00125           hxy->Fill(channel->GetY()/10000,channel->GetX()/10000);
00126           hdt->Fill(abs_time);
00127         }
00128       }
00129 
00130 
00131       //On each board, at each time, identify the events which are square
00132       std::map<unsigned int, std::map<unsigned int,int> >::iterator iter1;
00133       for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00134         
00135         unsigned int azu=iter1->first;
00136         std::map<unsigned int,int> hits_per_abstime=iter1->second;
00137         
00138         std::map<unsigned int,int>::iterator iter2;
00139         for(iter2=hits_per_abstime.begin();iter2!=hits_per_abstime.end();iter2++){
00140           
00141           unsigned int abstime = iter2->first;
00142           int nb_hits = iter2->second;
00143           
00144           if (nb_hits>= threshold) {
00145             if(blabla==2||blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at abs_time "<<abstime<<" with n_hits = "<<nb_hits<<endl;
00146 
00147             //update the event square counter of the good board at the good time
00148               if ( nb_square.find(board_id) == nb_square.end()) { // if this asu doesn't exist yet
00149                 std::map<unsigned int, int> nbHitMap;
00150                 nbHitMap[abs_time]=1;
00151                 nb_square.insert(make_pair(board_id,nbHitMap));
00152               }
00153               else{ // if this asu already exist 
00154                 std::map<unsigned int, int> &nbHitMap =  nb_square.find(board_id)->second;
00155                 if (nbHitMap.find(abs_time) == nbHitMap.end()){ //if this abs_time doesn't exist yet
00156                   nbHitMap.insert(make_pair(abs_time,1)); 
00157                 }
00158                 else{ //if this abs time already exist
00159                   nbHitMap[abs_time] = nbHitMap[abs_time]++;
00160                 }
00161               }  
00162               
00163               //update the total event square counter of this key
00164               nb_tot++;
00165               
00166               //update the event list
00167               list_event[nb_tot-1] = i+1;
00168           }   
00169         }
00170       }
00171       
00172       //if we want to plot this event, let's do it now
00173       if (plot){
00174         c0->cd(1);
00175         hxy->SetTitle("Hits position");
00176         hxy.GetXaxis()->SetTitle("X (cm)");
00177         hxy.GetYaxis()->SetTitle("Y (cm)");
00178         hxy.GetYaxis()->SetLogy();
00179         hxy.GetYaxis()->SetGridy();
00180         hxy->Draw("zcol");
00181 
00182         c0->cd(2);
00183         hdt->SetTitle("Hits time");
00184         hdt.GetXaxis()->SetTitle("delta t (/ 200 ns)");
00185         hdt.GetYaxis()->SetTitle("Nb hits");
00186         hdt.GetYaxis()->SetLogy();
00187         hdt.GetYaxis()->SetGridy();
00188         hdt->Draw();
00189       }
00190     }
00191     
00192 
00193     //Now the outputs: 
00194     if(blabla==2||blabla==3) cout<<endl;
00195     if(blabla==1||blabla==2||blabla==3) {
00196 
00197       //at each key print nb of evts square
00198       cout<<"In key "<<counter<<" Nb tot evt square = "<<nb_tot<<endl;
00199 
00200       //at each key print print the liste of square events
00201       cout<<"List of square events: "<<endl;
00202 
00203       for(int it=0;it<nb_tot;it++) cout<<" "<<list_event[it];
00204       cout<<endl<<endl;
00205     }
00206 
00207     if(blabla==2||blabla==3) {
00208 
00209       //if you want more details print also the position(asu) and time(memory order) of the square events
00210       cout<<"Hereafter I show the nb of event square in each board/asu at each time:"<<endl<<endl<<"Board/asu i"<<endl<<"memory order:";
00211       for (int ti=0;ti<128;ti++) cout<<" "<<ti;
00212       cout<<endl;
00213 
00214       std::map<unsigned int, std::map<unsigned int,int> >::iterator iter1;
00215       for(iter1=nb_square.begin();iter1!=nb_square.end();iter1++){
00216         
00217         unsigned int azu=iter1->first;
00218         std::map<unsigned int,int> nb_square_per_abstime=iter1->second;
00219         
00220         cout<<endl;
00221         cout<<"asu "<<azu<<endl;
00222 
00223         std::map<unsigned int,int>::iterator iter2;
00224         for(iter2=nb_square_per_abstime.begin();iter2!=nb_square_per_abstime.end();iter2++){
00225           
00226           unsigned int abstime = iter2->first;
00227           int nb_hits = iter2->second;
00228           
00229           cout<<" "<<nb_hits;
00230         }
00231         cout<<endl;
00232       }
00233       cout<<endl;
00234     }
00235     cout<<endl;
00236   }
00237   return 0; 
00238 }
00239 

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