#include <map>
#include <iostream>
#include "TFile.h"
#include <TROOT.h>
#include <TRint.h>
#include <TKey.h>
#include "TTree.h"
#include "root/MTRun.hh"
#include "root/MTEvent.hh"
#include "root/MTChannel.hh"
Include dependency graph for square_event_tagging.cpp:
Go to the source code of this file.
Functions | |
int | main (void) |
int main | ( | void | ) |
Definition at line 22 of file square_event_tagging.cpp.
00022 { 00023 00024 //----------------- 00025 //User's parameters 00026 00027 //Do you want some info ? (0 = not at all, 1 = yes a little, 2 = yes a lot, 3 = yes all : for debug purpose) 00028 Int_t blabla = 3; 00029 00030 //threshold (number of hits in a given asu at a given time (maximum=1536)) 00031 Int_t threshold = 1000; 00032 00033 //input data 00034 string file = "05082011_1055_MGT.root"; 00035 //----------------- 00036 00037 00038 //our data file 00039 TFile *f = new TFile(file.c_str()); 00040 if(blabla==1||blabla==2||blabla==3){ 00041 cout<<endl; 00042 cout<<"reading File : "<<file<<endl; 00043 } 00044 00045 //key iterator 00046 TIter nextkey(f->GetListOfKeys()); 00047 TKey *key; 00048 UInt_t counter = 0; 00049 00050 if(blabla==1||blabla==2||blabla==3) cout<<endl; 00051 00052 00053 //loop on all the keys 00054 while (key = (TKey*)nextkey()) { 00055 00056 counter++; 00057 if(blabla==1||blabla==2||blabla==3) cout<<"key number = "<<counter<<endl; 00058 00059 TTree *tree = (TTree*)key->ReadObj(); 00060 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun"); 00061 00062 Int_t nEvent = tree->GetEntries(); 00063 if(blabla==1||blabla==2||blabla==3) cout <<"Nevent = "<<nEvent<<endl<<endl; 00064 00065 MTEvent *evt = new MTEvent(); 00066 00067 TBranch *branch= tree->GetBranch("MTEvent"); 00068 branch->SetAddress(&evt); 00069 00070 //at each new key, declare the event counters and indicators 00071 bool IsSquare; 00072 Int_t Asu; 00073 Int_t AbsTime; 00074 00075 00076 //loop on all the events of the key 00077 for (int i=0;i<nEvent-1;i++){ 00078 00079 tree->GetEntry(i); 00080 00081 UInt_t nchannel = evt->GetNchannel(); 00082 if(blabla==3) cout<<"Event "<<i+1<<" / "<<nEvent<<"; nb of channels= "<<nchannel<<endl; 00083 00084 //at each event declare the hits counter 00085 map<unsigned int,map<unsigned int,int> > channels_map;// key1=asu (board_id), key2=hit_time 00086 00087 //at each event reset the square indicator 00088 IsSquare=0; 00089 Asu = -1; 00090 AbsTime = -1; 00091 00092 //loop on all the channels of the event 00093 for (int j=0;j<nchannel;j++){ 00094 00095 //this channel 00096 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j); 00097 00098 //at each channel get board_id and hit_time 00099 UInt_t hit_time = channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() ); 00100 UInt_t board_id = channel->GetBoardId(); 00101 //if(blabla==3) cout<<"Channel : "<<j<<"; hit on asu "<<board_id<<"; at time "<<hit_time<<endl; 00102 00103 //upgrade the hits counter of the good board at the good time 00104 if ( channels_map.find(board_id) == channels_map.end()) { // if this asu doesn't exist yet 00105 00106 map<unsigned int, int> nbHitMap; 00107 nbHitMap[hit_time]=1; 00108 channels_map.insert(make_pair(board_id,nbHitMap)); 00109 } 00110 else{ // if this asu already exist 00111 00112 map<unsigned int, int> &nbHitMap = channels_map.find(board_id)->second; 00113 if (nbHitMap.find(hit_time) == nbHitMap.end()){ //if this hit_time doesn't exist yet 00114 00115 nbHitMap.insert(make_pair(hit_time,1)); 00116 } 00117 else{ //if this abs time already exist 00118 00119 nbHitMap[hit_time] = nbHitMap[hit_time]++; 00120 } 00121 } 00122 } 00123 00124 //Loop on each board, at each time, to identify if this event is square 00125 map<unsigned int, map<unsigned int,int> >::iterator iter1; 00126 for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){ 00127 00128 unsigned int azu=iter1->first; 00129 map<unsigned int,int> hits_per_time=iter1->second; 00130 00131 map<unsigned int,int>::iterator iter2; 00132 for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){ 00133 00134 unsigned int time = iter2->first; 00135 int nb_hits = iter2->second; 00136 00137 //if this is a square event 00138 if (nb_hits>=threshold) { 00139 00140 //set square event indicator to 1 00141 IsSquare = 1; 00142 Asu = azu; 00143 AbsTime = time; 00144 00145 if(blabla==2) cout<<"*"; 00146 if(blabla==3) cout <<" -> event: "<<i+1<<" = square in asu no "<<azu<<" at abstime "<<time<<" with n_hits = "<<nb_hits<<endl; 00147 } 00148 } 00149 } 00150 } 00151 if(blabla==2||blabla==3) cout<<endl; 00152 } 00153 if(blabla==1||blabla==2||blabla==3) cout<<endl; 00154 return 0; 00155 }