/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/root/MTEvent.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1922 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2012-10-24 15:21:19 +0200 (Wed, 24 Oct 2012) $ */
00002 #include "TDirectory.h"
00003 #include "TProcessID.h"
00004 
00005 #include "root/MTEvent.hh"
00006 #include "root/MTChannel.hh"
00007 
00008 #include "event/Event.hh"
00009 #include "event/ChannelHit.hh"
00010 #include "event/Run.hh"
00011 #include "geometry/Chamber.hh"
00012 #include "geometry/Chip.hh"
00013 #include "geometry/Board.hh"
00014 #include "geometry/Dif.hh"
00015 #include "geometry/Detector.hh"
00016 #include "tools/MicroException.hh"
00017 #include "tools/Log.hh"
00018 
00019 
00020 #include <iostream>
00021 #include <sstream>
00022 
00023 using namespace std;
00024 
00025 ClassImp(MTEvent)
00026 
00027 TClonesArray *MTEvent::fgChannels = 0;
00028 
00029 /*------------------------------------------------------------------------------
00030  *
00031  *    MTEvent implementation
00032  */
00033 //______________________________________________________________________________
00034 MTEvent::MTEvent() : fTrack(NULL), fEventId(0), fTemperature(0.), fPressure(0), fTimestamp(0), fDifSynchro(0), fTimeInfo(true), fSquareEvt (false ), fBorderEvt (false ), fChipEvt (false ), fCrcIsCorrect(true), fNchannel(0), fValid(VALID)
00035 {
00036    // Create an MTEvent object.
00037    // When the constructor is invoked for the first time, the class static
00038    // variable fgChannels is 0 and the TClonesArray fgChannels is created.
00039 
00040    if (!fgChannels) {
00041        fgChannels = new TClonesArray("MTChannel", 1000);
00042    }
00043    fChannels = fgChannels;
00044    fNbHitPerAbsTime.clear();
00045 }
00046 
00047 //______________________________________________________________________________
00048 MTEvent::~MTEvent()
00049 {
00050    Clear();
00051 }
00052 
00053 
00054 
00055 //______________________________________________________________________________
00056 MTEvent&  MTEvent::operator=( const  MTEvent& rhs)
00057 {
00058 
00059   // It is not a real copy as Channels are share as static class member
00060   // So both source and destination MTEvent share the same channels and MTTrack
00061    fSquareEvt = rhs.fSquareEvt;
00062    fBorderEvt = rhs.fBorderEvt;
00063    fChipEvt = rhs.fChipEvt;
00064    fTimeInfo = rhs.fTimeInfo;
00065    fEventId = rhs.fEventId;
00066    fTemperature = rhs.fTemperature;
00067    fPressure = rhs.fPressure;
00068    fDifSynchro = rhs.fDifSynchro;
00069    fTimestamp = rhs.fTimestamp;
00070    fGlobalTriggerCounter = rhs.fGlobalTriggerCounter;
00071    fDifTriggerCounter = rhs.fDifTriggerCounter;
00072    fCrcIsCorrect = rhs.fCrcIsCorrect;
00073    fValid = rhs.fValid;
00074    fNchannel = rhs.fNchannel;
00075 
00076    fNbHitPerAbsTime = rhs.fNbHitPerAbsTime;
00077    fChannels = rhs.fChannels;
00078    fMeshVoltage = rhs.fMeshVoltage;
00079    fDriftVoltage = rhs.fDriftVoltage;
00080    fTrack = rhs.fTrack;
00081    //static TClonesArray *gChannels; // Do not copy class static member
00082    fTemperatureAsu1 = rhs.fTemperatureAsu1;
00083    fTemperatureAsu2 = rhs.fTemperatureAsu2;
00084    fTemperatureDif = rhs.fTemperatureDif;
00085 
00086 
00087   // ATTENTION A BIEN MODIFIER src/analuyse/root/merge.cpp FillEvent()
00088 }
00089 
00090 //______________________________________________________________________________
00091 void MTEvent::Build(UInt_t evtId, ULong64_t difSynchro, Double32_t  temperature, Double32_t  pressure , ULong64_t  timestamp )
00092 {
00093 fEventId=evtId;
00094 fTemperature=temperature;
00095 fPressure=pressure;
00096 fTimestamp=timestamp;
00097 fDifSynchro = difSynchro;
00098 }
00099 
00100 //______________________________________________________________________________
00101 MTEvent& MTEvent::operator=(const Event& aEvent)  
00102 
00103 {
00104      try
00105       {
00106         fCrcIsCorrect = aEvent.getCrcIsCorrect();
00107         fValid = aEvent.getValidFlag();
00108         this->Build(aEvent.getId(), aEvent.getDifSynchro(), aEvent.getTemperature(), aEvent.getPressure(), aEvent.getTimeStamp());
00109         fTrack=NULL;
00110         fTimeInfo=true;
00111         fSquareEvt=false;
00112         fBorderEvt=false;
00113         fChipEvt=false;
00114 
00115         fTemperatureAsu1 = aEvent.getTemperatureAsu1();
00116         fTemperatureAsu2 = aEvent.getTemperatureAsu2();
00117         fTemperatureDif = aEvent.getTemperatureDif();
00118 
00119         ChamberMap_t chamberList = aEvent.getRun().getDetector().getChambers();
00120         for (ChamberMap_t::iterator iter=chamberList.begin(); iter!=chamberList.end(); iter++)
00121         {
00122           Chamber& chamber = *(iter->second);
00123           BoardMap_t boardList = chamber.getBoards();
00124           for ( BoardMap_t::iterator boardIter=boardList.begin(); boardIter!=boardList.end(); boardIter++)
00125           {
00126             ui32 difId = 0;
00127             Board& board = *(boardIter->second);
00128             try
00129             {
00130               const Dif* dif = board.getDif();
00131               if ( dif != NULL ) 
00132               {  // ! Gassilplex Board
00133                 difId = board.getDif()->getId(); 
00134               }
00135               const BoardSlowControl& boardSC =  aEvent.getBoardSlowControl(chamber.getId(),difId,board.getId());
00136               this->SetDriftVoltage(chamber.getId(),difId,board.getId(),boardSC.getDrift().voltage);
00137               this->SetMeshVoltage(chamber.getId(),difId,board.getId(),boardSC.getMesh().voltage);
00138             }
00139             catch ( MicroException e) 
00140             {
00141              FILE_LOG(logDEBUG1) << "---BoardSlowControl not found chamberid[" << chamber.getId() << "] difId[" << difId <<"] boardId[" << board.getId() <<"]" << endl; 
00142             }
00143           }
00144 
00145 
00146                                         this->SetGlobalTriggerCounter(aEvent.getGlobalTriggerCounter());
00147                                         this->SetDifTriggerCounter(aEvent.getDifTriggerCounter());
00148           try
00149           {
00150               const  multiset<ChannelHit*,sorter>& list = aEvent.getChannelHitVector(chamber);
00151               int order = 0 ;
00152               for (set<ChannelHit*,sorter>::iterator iter=list.begin(); iter!=list.end(); iter++)
00153               {
00154                 try
00155                 {
00156                   //const ChannelHit& channelHit = *(*iter);
00157                   ChannelHit& channelHit = *(*iter);
00158                   if ( chamber.getType().find("GASSIPLEX")!=string::npos)
00159                                                                         {
00160                                                                                                 channelHit.setTimestamp(aEvent.getTimeStamp());
00161                                                                   }
00162 
00163 
00164                   MTChannel *ch = this->AddChannel(channelHit, order);
00165                   //i32 deltaT = ch->GetBcIdDif() - ch->GetBcIdHit();
00166                   //if ( deltaT < 0 ) cout << "deltaT < 0" << endl;
00167                   //if ( deltaT == 0 ) cout << "deltaT == 0" << endl;
00168                   //ui32 time = ch->GetAbsTime();
00169                   //cout << "----EventId["<< GetId() << "] Dif Id["<< ch->GetSoftId().GetDifId() << "], Chip Id[" << ch->GetSoftId().GetChipId() << "]  deltat " << deltaT << endl;
00170                   //cout << " ---- Abs time:  " << time  << " EventId["<< GetId() << "] Dif Id["<< ch->GetSoftId().GetDifId() << "], Chip Id[" << ch->GetSoftId().GetChipId() << " Abs time:  " << time << endl; 
00171                   
00172     
00173                   
00174 
00175 
00176 
00177                   order++;  // because aEvent have already been  sorted
00178                 } // end try block
00179                 catch (MicroException e)
00180                 {
00181                 }
00182               } // end for channelHits for this chamber
00183           }
00184           catch (MicroException e)
00185           {
00186                     // get ChamberHitVector for next chamber
00187           }
00188         } // end for chamber
00189       this->GetChannels()->Sort(); // sort by absolute time --> See MTChannels.Compare()
00190       } //try block
00191       catch (MicroException e)
00192       {
00193           throw MicroException(e.getMessage());
00194       }
00195        // Save all objects in this file
00196       return *this;
00197 
00198 }
00199 
00200 //------------------------------------------
00201 bool MTEvent::IsSquare(UInt_t nbPad, UInt_t &asu, UInt_t &abs_time, UInt_t chb) 
00202 //input : nbPad = threshold where we consider an event "Square"; chb = chamber ID.
00203 //outputs: asu = the asu where the event is square; abs_time = the abs_time when the event is square.
00204 {
00205   //square boolean identifier
00206   bool square = false;
00207   //set reference values
00208   asu = -1;
00209   abs_time = -1;
00210   
00211   //declare the hits counter map
00212   map<unsigned int,map<unsigned int,int> > channels_map;// key1=asu (board_id), key2=hit_time      
00213   
00214   //loop on all the channels of the event
00215   UInt_t nchannel = this->GetNchannel();
00216   for (int j=0;j<nchannel;j++){
00217     
00218     //this channel
00219     MTChannel* channel = (MTChannel*)this->GetChannels()->UncheckedAt(j);
00220 
00221     if (channel->GetChamberId()==chb)
00222       { 
00223         //at each channel get board_id and hit_time
00224         UInt_t hit_time =  channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00225         UInt_t board_id = channel->GetBoardId();
00226     
00227         //upgrade the hits counter of the good board at the good time:
00228         // if this asu doesn't exist yet
00229         if ( channels_map.find(board_id) == channels_map.end()) { 
00230           //create it in the map and fill it
00231           map<unsigned int, int> nbHitMap;
00232           nbHitMap[hit_time]=1;
00233           channels_map.insert(make_pair(board_id,nbHitMap));
00234         }
00235         // if this asu already exist 
00236         else{ 
00237           //find it
00238           map<unsigned int, int> &nbHitMap =  channels_map.find(board_id)->second;
00239           //if this hit_time doesn't exist yet
00240           if (nbHitMap.find(hit_time) == nbHitMap.end()){ 
00241             //add id
00242             nbHitMap.insert(make_pair(hit_time,1)); 
00243           }
00244           //if this abs time already exist
00245           else{ 
00246             //fill it
00247             nbHitMap[hit_time] = nbHitMap[hit_time]++;
00248           }
00249         }  
00250       }      
00251   }
00252   
00253   //Loop on each board, at each time, to identify if this event is square
00254   map<unsigned int, map<unsigned int,int> >::iterator iter1;
00255   for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00256     
00257     unsigned int azu=iter1->first;
00258     map<unsigned int,int> hits_per_time=iter1->second;
00259     
00260     map<unsigned int,int>::iterator iter2;
00261     for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00262       
00263       unsigned int time = iter2->first;
00264       int nb_hits = iter2->second;
00265       
00266       //if this is a square event
00267       if (nb_hits>=nbPad) {
00268         square=true;
00269         asu = azu;
00270         abs_time = time;
00271       }
00272     }
00273   }
00274   return square;      
00275 }
00276 
00277 //------------------------------------------
00278 bool MTEvent::IsBorder(UInt_t nbPad, UInt_t &asu, UInt_t &abs_time, UInt_t chb) 
00279 //input : nbPad = threshold where we consider an event "Border"; chb = chamber ID.
00280 //outputs: asu = the asu where the event is border; abs_time = the abs_time when the event is border.
00281 {
00282   //border boolean identifier
00283   bool border = false;
00284   //set reference values
00285   asu = -1;
00286   abs_time = -1;
00287   
00288   //an event can be border only if it is not square (square threshold set to 450 hits)
00289   UInt_t A;
00290   UInt_t T;
00291   if(this->IsSquare(450,A,T,chb)==0) {
00292     //declare the hits counter map
00293     map<unsigned int,map<unsigned long,unsigned int> > channels_map;// key1=asu (board_id), key2=hit_time      
00294     
00295     //loop on all the channels of the event
00296     UInt_t nchannel = this->GetNchannel();
00297     for (unsigned int j=0;j<nchannel;j++){
00298       
00299       //this channel
00300       MTChannel* channel = (MTChannel*)this->GetChannels()->UncheckedAt(j);
00301       
00302       if (channel->GetChamberId()==chb)
00303         { 
00304           //at each channel get board_id and hit_time
00305           ULong_t hit_time =  channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00306           UInt_t board_id = channel->GetBoardId();
00307           
00308           //get the position of this hit/channel
00309           //Int_t xpos = channel->GetX()/1000;
00310           //Int_t ypos = channel->GetY()/1000;
00311           
00312           //if the hit is not on the borders of an asu go to next hit
00313           if (channel->GetX() != 0000 && channel->GetX() != 310000 && channel->GetX() != 320000 && channel->GetX() != 640000 && channel->GetX() != 650000 && channel->GetX() != 960000 && channel->GetY() != 000000 && channel->GetY() != 470000 && channel->GetY() != 480000 && channel->GetY() != 960000) continue;
00314           
00315           //upgrade the hits counter of the good board at the good time
00316           if (channels_map.find(board_id) == channels_map.end()) { // if this asu doesn't exist yet
00317             
00318             map<unsigned long, unsigned int> nbHitMap;
00319           nbHitMap[hit_time]=1;
00320           channels_map.insert(make_pair(board_id,nbHitMap));
00321           }
00322           else{ // if this asu already exist 
00323             
00324             map<unsigned long, unsigned int> &nbHitMap =  channels_map.find(board_id)->second;
00325             if (nbHitMap.find(hit_time) == nbHitMap.end()){ //if this hit_time doesn't exist yet
00326               
00327               nbHitMap.insert(make_pair(hit_time,1)); 
00328             }
00329             else{ //if this abs time already exist
00330               
00331               nbHitMap[hit_time] = nbHitMap[hit_time]++;
00332             }
00333           }  
00334         }      
00335       
00336       //Loop on each board, at each time, to identify if this event is border
00337       map<unsigned int, map<unsigned long,unsigned int> >::iterator iter1;
00338       for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00339         
00340         unsigned int azu=iter1->first;
00341         map<unsigned long,unsigned int> hits_per_time=iter1->second;
00342         
00343         map<unsigned long,unsigned int>::iterator iter2;
00344         for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00345           
00346           unsigned long time = iter2->first;
00347           unsigned int nb_hits = iter2->second;
00348           
00349           //if this is a border event
00350           if (nb_hits>=nbPad) {
00351             border = true;
00352             asu = azu;
00353             abs_time = time;
00354           }
00355         }
00356       }
00357     }
00358   }
00359   return border;      
00360 }
00361   
00362 //------------------------------------------
00363 bool MTEvent::IsChip(UInt_t nbPad, UInt_t &chip, UInt_t &abs_time, UInt_t chb) 
00364 //input : nbPad = threshold where we consider an event "Chip"; chb = chamber ID.
00365 //outputs: chip = the chip where the event is chip; abs_time = the abs_time when the event is chip.
00366 {
00367   //chip boolean identifier
00368   bool me_chip = false;
00369   //set reference values
00370   chip = -1;
00371   abs_time = -1;
00372   
00373   //declare the hits counter map
00374   map<unsigned int,map<unsigned long,unsigned int> > channels_map;// key1=chip (chip_id), key2=hit_time      
00375   
00376   //loop on all the channels of the event
00377   UInt_t nchannel = this->GetNchannel();
00378   for (unsigned int j=0;j<nchannel;j++){
00379     
00380     //this channel
00381     MTChannel* channel = (MTChannel*)this->GetChannels()->UncheckedAt(j);
00382     
00383     if (channel->GetChamberId()==chb)
00384       { 
00385         //at each channel get chip_id and hit_time
00386         ULong_t hit_time =  channel->GetBcIdAbs() - (channel->GetBcIdDif() - channel->GetBcIdHit() );
00387         UInt_t chip_id = channel->GetChipId();
00388         
00389         //get the position of this hit/channel
00390         //Int_t xpos = channel->GetX()/1000;
00391         //Int_t ypos = channel->GetY()/1000;
00392         
00393         //if the hit is not on the chips of an chip go to next hit
00394         if (channel->GetX() != 0000 && channel->GetX() != 310000 && channel->GetX() != 320000 && channel->GetX() != 640000 && channel->GetX() != 650000 && channel->GetX() != 960000 && channel->GetY() != 000000 && channel->GetY() != 470000 && channel->GetY() != 480000 && channel->GetY() != 960000) continue;
00395         
00396         //upgrade the hits counter of the good chip at the good time
00397         if (channels_map.find(chip_id) == channels_map.end()) { // if this chip doesn't exist yet
00398           
00399           map<unsigned long, unsigned int> nbHitMap;
00400           nbHitMap[hit_time]=1;
00401           channels_map.insert(make_pair(chip_id,nbHitMap));
00402         }
00403         else{ // if this chip already exist 
00404           
00405           map<unsigned long, unsigned int> &nbHitMap =  channels_map.find(chip_id)->second;
00406           if (nbHitMap.find(hit_time) == nbHitMap.end()){ //if this hit_time doesn't exist yet
00407             
00408             nbHitMap.insert(make_pair(hit_time,1)); 
00409           }
00410           else{ //if this abs time already exist
00411             
00412             nbHitMap[hit_time] = nbHitMap[hit_time]++;
00413           }
00414         }  
00415       }
00416     
00417     //Loop on each chip, at each time, to identify if this event is chip
00418     map<unsigned int, map<unsigned long,unsigned int> >::iterator iter1;
00419     for(iter1=channels_map.begin();iter1!=channels_map.end();iter1++){
00420       
00421       unsigned int chiip=iter1->first;
00422       map<unsigned long,unsigned int> hits_per_time=iter1->second;
00423       
00424       map<unsigned long,unsigned int>::iterator iter2;
00425       for(iter2=hits_per_time.begin();iter2!=hits_per_time.end();iter2++){
00426         
00427         unsigned long time = iter2->first;
00428         unsigned int nb_hits = iter2->second;
00429         
00430         //if this is a chip event
00431         if (nb_hits>=nbPad) {
00432           me_chip = true;
00433           chip = chiip;
00434           abs_time = time;
00435         }
00436       }
00437     }
00438   } 
00439   return me_chip;      
00440 }
00441   
00442   //------------------------------------------
00443 Float_t MTEvent::GetMeshVoltage(const Int_t chamberId,Int_t difId, Int_t boardId) const 
00444 {
00445    if ( fMeshVoltage.find(chamberId) != fMeshVoltage.end())
00446     {
00447       map<UInt_t, map<UInt_t, Float_t>* >* difContainer = fMeshVoltage.find(chamberId)->second;
00448       if (difContainer->find(difId) !=  difContainer->end())
00449       {
00450         map<UInt_t , Float_t>* boardContainer = difContainer->find(difId)->second;
00451         if (boardContainer->find(boardId) !=  boardContainer->end())
00452         {
00453             return boardContainer->find(boardId)->second;
00454         }
00455         else
00456         {
00457           throw MicroException("MTEvent::GetMeshVoltage : no board found");
00458         }
00459       }
00460       else
00461       {
00462           throw MicroException("MTEvent::GetMeshVoltage : no board found");
00463       }
00464     }
00465     else
00466 {
00467 }
00468     {
00469       throw MicroException("MTEvent::GetMeshVoltage : no board found");
00470     }
00471 
00472 }
00473 //------------------------------------------
00474 Float_t MTEvent::GetDriftVoltage(const Int_t chamberId,Int_t difId, Int_t boardId) const
00475 {
00476    if ( fDriftVoltage.find(chamberId) != fDriftVoltage.end())
00477     {
00478       map<UInt_t, map<UInt_t, Float_t>* >* difContainer = fDriftVoltage.find(chamberId)->second;
00479       if (difContainer->find(difId) !=  difContainer->end())
00480       {
00481         map<UInt_t , Float_t>* boardContainer = difContainer->find(difId)->second;
00482         if (boardContainer->find(boardId) !=  boardContainer->end())
00483         {
00484             return boardContainer->find(boardId)->second;
00485         }
00486         else
00487         {
00488           throw MicroException("MTEvent::GetDriftVoltage : no board found");
00489         }
00490       }
00491       else
00492       {
00493           throw MicroException("MTEvent::GetDriftVoltage : no board found");
00494       }
00495     }
00496     else
00497     {
00498       throw MicroException("MTEvent::GetDriftVoltage : no board found");
00499     }
00500 
00501 
00502 
00503 }
00504 //------------------------------------------
00505 void    MTEvent::SetMeshVoltage(const Int_t chamberId, Int_t difId, Int_t boardId,const Float_t aValue) 
00506 {
00507   // Search or create difs container for this chamber id
00508     if ( fMeshVoltage.find(chamberId) != fMeshVoltage.end())
00509     { // difs list already exit for this chamber
00510     }
00511     else
00512     { // does not exit create it
00513       map<UInt_t , map<UInt_t, Float_t>* > *difContainer = new map<UInt_t, map<UInt_t, Float_t>* >();
00514       fMeshVoltage.insert(make_pair(chamberId,difContainer));
00515     }
00516 
00517     // Now we are sure that container for this chamber Id exist
00518     map<UInt_t, map<UInt_t, Float_t>* >* difContainer = fMeshVoltage.find(chamberId)->second;
00519 
00520 
00521     // Search or create boards container for this Difs
00522     if ( difContainer->find(difId) != difContainer->end())
00523     { // board list already exit for this dif
00524     }
00525     else
00526     {
00527       map<UInt_t, Float_t>* boardContainer = new map<UInt_t, Float_t>();
00528       difContainer->insert(make_pair(difId,boardContainer));
00529     }
00530 
00531     // Now we are sure that container for this chamber Id  and DifId exist
00532     map<ui32, Float_t>* boardContainer = difContainer->find(difId)->second;
00533 
00534     if ( boardContainer->find(boardId) != boardContainer->end())
00535     {
00536       (*boardContainer)[boardId] = aValue;
00537     }
00538     else
00539     {
00540       boardContainer->insert(make_pair(boardId,aValue));
00541     }
00542 }
00543 
00544 //------------------------------------------
00545 void    MTEvent::SetDriftVoltage(const Int_t chamberId, Int_t difId, Int_t boardId,const Float_t aValue)
00546 {
00547   // Search or create difs container for this chamber id
00548     if ( fDriftVoltage.find(chamberId) != fDriftVoltage.end())
00549     { // difs list already exit for this chamber
00550     }
00551     else
00552     { // does not exit create it
00553       map<UInt_t , map<UInt_t, Float_t>* > *difContainer = new map<UInt_t, map<UInt_t, Float_t>* >();
00554       fDriftVoltage.insert(make_pair(chamberId,difContainer));
00555     }
00556 
00557     // Now we are sure that container for this chamber Id exist
00558     map<UInt_t, map<UInt_t, Float_t>* >* difContainer = fDriftVoltage.find(chamberId)->second;
00559 
00560 
00561     // Search or create boards container for this Difs
00562     if ( difContainer->find(difId) != difContainer->end())
00563     { // board list already exit for this dif
00564     }
00565     else
00566     {
00567       map<UInt_t, Float_t>* boardContainer = new map<UInt_t, Float_t>();
00568       difContainer->insert(make_pair(difId,boardContainer));
00569     }
00570 
00571     // Now we are sure that container for this chamber Id  and DifId exist
00572     map<ui32, Float_t>* boardContainer = difContainer->find(difId)->second;
00573     if ( boardContainer->find(boardId) != boardContainer->end())
00574     {
00575       (*boardContainer)[boardId] = aValue;
00576     }
00577     else
00578     {
00579       boardContainer->insert(make_pair(boardId,aValue));
00580     }
00581 
00582 
00583 
00584 
00585 
00586 }
00587 
00588 
00589 //______________________________________________________________________________
00590 MTChannel* MTEvent::AddChannel(const ChannelHit& hit, UInt_t order) {
00591 //Int_t value, UInt_t softId, UInt_t hardId, Int_t valueX, Int_t valueY, Int_t valueZ, UInt_t order)
00592 
00593    // Add a new fTrack to the list of fTracks for this event.
00594    // To avoid calling the very time consuming operator new for each fTrack,
00595    // the standard but not well know C++ operator "new with placement"
00596    // is called. If fTracks[i] is 0, a new Track object will be created
00597    // otherwise the previous Track[i] will be overwritten.
00598 
00599 
00600    TClonesArray &channels = *fChannels;
00601 
00602    MTChannel *channel = new(channels[fNchannel++]) MTChannel(hit, order);
00603    UInt_t bcIdHit =  channel->GetBcIdHit();
00604    if ( bcIdHit != 0 )
00605    {
00606      UInt_t boardId = channel->GetSoftId().GetBoardId(); 
00607      UInt_t absolute_time = channel->GetAbsTime() ;
00608      this->AddHitForAbsTime(boardId,absolute_time,1);
00609    }
00610 
00611    return channel;
00612 }
00613 //______________________________________________________________________________
00614 MTChannel* MTEvent::AddChannel(MTChannel* aChannel) {
00615 //Int_t value, UInt_t softId, UInt_t hardId, Int_t valueX, Int_t valueY, Int_t valueZ, UInt_t order)
00616 
00617    // Add a new fTrack to the list of fTracks for this event.
00618    // To avoid calling the very time consuming operator new for each fTrack,
00619    // the standard but not well know C++ operator "new with placement"
00620    // is called. If fTracks[i] is 0, a new Track object will be created
00621    // otherwise the previous Track[i] will be overwritten.
00622 
00623 
00624    TClonesArray &channels = *fChannels;
00625    MTChannel *channel = new(channels[fNchannel++]) MTChannel(*aChannel);
00626    UInt_t bcIdHit =  channel->GetBcIdHit();
00627    if ( bcIdHit != 0 )
00628    {
00629      UInt_t boardId = channel->GetSoftId().GetBoardId(); 
00630      UInt_t absolute_time = channel->GetAbsTime();
00631      this->AddHitForAbsTime(boardId,absolute_time,1);
00632 
00633    }
00634    
00635 
00636 //   channels[fNchannel++]  = aChannel;
00637 
00638    return aChannel;
00639 }
00640 
00641 //______________________________________________________________________________
00642 void MTEvent::Clear(Option_t * /*option*/)
00643 {
00644   fChannels->Clear("C"); //will also call Channel::Clear
00645   fNchannel = 0;
00646 
00647   for (std::map< UInt_t, std::map<UInt_t, UInt_t>* >::iterator iter = fNbHitPerAbsTime.begin(); iter != fNbHitPerAbsTime.end(); iter++)
00648   {
00649     map<UInt_t, UInt_t> *byBoard = iter->second;
00650     delete byBoard;
00651   }
00652   fNbHitPerAbsTime.clear();
00653 }
00654 
00655 
00656 //______________________________________________________________________________
00657 void MTEvent::Reset(Option_t * /*option*/)
00658 {
00659 // Static function to reset all static objects for this event
00660 //   fgChannels->Delete(option);
00661 
00662    delete fgChannels; fgChannels = 0;
00663 }
00664 
00665 //______________________________________________________________________________
00666 void MTEvent::SetNchannel(Int_t n) {
00667     fNchannel = n;
00668     if ( fNchannel == 0 )
00669         { fgChannels->Delete(); }
00670 }
00671 
00672 //______________________________________________________________________________
00673 // Rappel: Les Channels sont trie dans le TClonesArray par Order
00674 
00675 MTChannel* MTEvent::GetChannelByOrder(UInt_t order,UInt_t aChamberId)  const
00676 {
00677    UInt_t items = 0;
00678 
00679    TIter myiter(fChannels);
00680    MTChannel* channel;
00681    while( channel=(MTChannel *)myiter.Next())
00682    {
00683      if ( channel->GetChamberId() == aChamberId )
00684      {
00685        if ( order == items )
00686        {
00687          return channel;
00688        }
00689        items++;
00690      }
00691    }
00692    return NULL;
00693 
00694 
00695 }
00696 
00697 //______________________________________________________________________________
00698 UInt_t MTEvent::GetNchannel(UInt_t aChamberId) const
00699 {
00700    UInt_t items = 0;
00701 
00702    TIter myiter(fChannels);
00703    MTChannel* channel;
00704    while( channel=(MTChannel *)myiter.Next())
00705    {
00706      if ( channel->GetChamberId() == aChamberId )
00707      {
00708        items++;
00709      }
00710    }
00711    return items;
00712 }
00713 
00714 //______________________________________________________________________________
00715 void MTEvent::AddHitForAbsTime(UInt_t boardId, UInt_t abs_time, UInt_t increment)
00716 {
00717 
00718  map<UInt_t, UInt_t>* boardMap = NULL;
00719 
00720  // Search map for the boardId
00721  if ( fNbHitPerAbsTime.find(boardId) != fNbHitPerAbsTime.end())
00722  {
00723     boardMap = fNbHitPerAbsTime.find(boardId)->second;   
00724  }
00725  else
00726  {
00727     boardMap = new map<UInt_t, UInt_t>();
00728     fNbHitPerAbsTime.insert(make_pair(boardId,boardMap));
00729  }
00730 
00731 
00732   // seatch ab_time in boardId map
00733  if (boardMap->find(abs_time) != boardMap->end())
00734  {
00735     UInt_t b4 =  boardMap->find(abs_time)->second;
00736     UInt_t foo = b4   + increment;
00737     (*boardMap)[abs_time]=foo;
00738  }
00739  else
00740  {
00741       boardMap->insert(make_pair(abs_time,increment));
00742  }
00743 
00744  
00745  boardMap = fNbHitPerAbsTime.find(boardId)->second;
00746 
00747 
00748 }
00749 
00750 //______________________________________________________________________________
00751 UInt_t  MTEvent::GetNbHitPerAbsTime(UInt_t boardId,UInt_t abs_time) const 
00752 {
00753   map<UInt_t, UInt_t>* boardMap = NULL;
00754 
00755   if ( fNbHitPerAbsTime.find(boardId) != fNbHitPerAbsTime.end())
00756   {
00757     boardMap = fNbHitPerAbsTime.find(boardId)->second;
00758     return boardMap->find(abs_time)->second;
00759   }
00760 
00761   else
00762   {
00763     return 0;
00764   }
00765 
00766 }
00767 
00768 //______________________________________________________________________________
00769 bool MTEvent::IsValid(void) const
00770 {
00771 
00772    if (( fValid & VALID ) == VALID )return true;
00773   return false;
00774 }
00775 
00776 //______________________________________________________________________________
00777 void MTEvent::SetTemperatureAsu1(UInt_t difId,Float_t asu1)
00778 {
00779   if ( fTemperatureAsu1.find(difId) != fTemperatureAsu1.end())
00780     { // dif already exit/ replace value
00781        fTemperatureAsu1[difId] = asu1;
00782     }
00783     else
00784     { // does not exit create it
00785       fTemperatureAsu1.insert(make_pair(difId,asu1));
00786     }
00787 }
00788 //______________________________________________________________________________
00789 void MTEvent::SetTemperatureAsu2(UInt_t difId,Float_t asu2)
00790 {
00791   if ( fTemperatureAsu2.find(difId) != fTemperatureAsu2.end())
00792     { // dif already exit/ replace value
00793        fTemperatureAsu2[difId] = asu2;
00794     }
00795     else
00796     { // does not exit create it
00797       fTemperatureAsu2.insert(make_pair(difId,asu2));
00798     }
00799 }
00800 //______________________________________________________________________________
00801 void MTEvent::SetTemperatureDif(UInt_t difId,Float_t dif)
00802 {
00803   if ( fTemperatureDif.find(difId) != fTemperatureDif.end())
00804     { // dif already exit/ replace value
00805        fTemperatureDif[difId] = dif;
00806     }
00807     else
00808     { // does not exit create it
00809       fTemperatureDif.insert(make_pair(difId,dif));
00810     }
00811 }
00812 
00813 //______________________________________________________________________________
00814 void MTEvent::SetTemperature(UInt_t difId,Float_t asu1, Float_t asu2, Float_t dif)
00815 {
00816   // Search or create difs container
00817     if ( fTemperatureAsu1.find(difId) != fTemperatureAsu1.end())
00818     { // dif already exit/ replace value
00819        fTemperatureAsu1[difId] = asu1;
00820     }
00821     else
00822     { // does not exit create it
00823       fTemperatureAsu1.insert(make_pair(difId,asu1));
00824     }
00825   // Search or create difs container
00826     if ( fTemperatureAsu2.find(difId) != fTemperatureAsu2.end())
00827     { // dif already exit/ replace value
00828        fTemperatureAsu2[difId] = asu2;
00829     }
00830     else
00831     { // does not exit create it
00832       fTemperatureAsu2.insert(make_pair(difId,asu2));
00833     }
00834   // Search or create difs container
00835     if ( fTemperatureDif.find(difId) != fTemperatureDif.end())
00836     { // dif already exit/ replace value
00837        fTemperatureDif[difId] = dif;
00838     }
00839     else
00840     { // does not exit create it
00841       fTemperatureDif.insert(make_pair(difId,dif));
00842     }
00843 }
00844 //______________________________________________________________________________
00845 Float_t MTEvent::GetTemperatureAsu1( UInt_t difId ) const 
00846 {
00847   if ( fTemperatureAsu1.find(difId) != fTemperatureAsu1.end())
00848   {
00849     return fTemperatureAsu1.find(difId)->second;
00850   }
00851   else
00852   {
00853     throw MicroException("MTEvent::GetTemperatureAsu1 : no difId found");
00854   }
00855 }
00856 //______________________________________________________________________________
00857 Float_t MTEvent::GetTemperatureAsu2( UInt_t difId ) const 
00858 {
00859   if ( fTemperatureAsu2.find(difId) != fTemperatureAsu2.end())
00860   {
00861     return fTemperatureAsu2.find(difId)->second;
00862   }
00863   else
00864   {
00865     throw MicroException("MTEvent::GetTemperatureAsu2 : no difId found");
00866   }
00867 }
00868 //______________________________________________________________________________
00869 Float_t MTEvent::GetTemperatureDif( UInt_t difId ) const 
00870 {
00871   if ( fTemperatureDif.find(difId) != fTemperatureDif.end())
00872   {
00873     return fTemperatureDif.find(difId)->second;
00874   }
00875   else
00876   {
00877     throw MicroException("MTEvent::GetTemperatureDif : no difId found");
00878   }
00879 }
00880 
00881 //______________________________________________________________________________
00882 void MTEvent::SetValidFlag(UInt_t value,bool valid )
00883 {
00884     fValid = fValid | fValid;
00885     if ( ! valid ) { fValid = fValid & 0xFFFE ; }
00886 }
00887 
00888 //______________________________________________________________________________
00889 TString MTEvent::GetValidFlagString(void ) const
00890 {
00891   TString result;
00892   if (  fValid == VALID ) { return "Valid" ;}
00893   if ( (fValid & UNKNOW_NOT_VALID )    == UNKNOW_NOT_VALID )    { result = result + " " + "UNKNOW_NOT_VALID" ;}
00894   if ( (fValid & BAD_CHIP_ID )         == BAD_CHIP_ID )         { result = result + " " + "BAD_CHIP_ID" ;}
00895   if ( (fValid & BAD_BOARD_ID )        == BAD_BOARD_ID )        { result = result + " " + "BAD_BOARD_ID" ;}
00896   if ( (fValid & BAD_DIF_ID )          == BAD_DIF_ID )          { result = result + " " + "BAD_DIF_ID" ;}
00897   if ( (fValid & CRC_ERROR )           == CRC_ERROR )           { result = result + " " + "CRC_ERROR" ;}
00898   if ( (fValid & ONLY_FFFF)            == ONLY_FFFF )           { result = result + " " + "ONLY_FFFF" ;}
00899   if ( (fValid & ONLY_AAAA)            == ONLY_AAAA )           { result = result + " " + "ONLY_AAAA" ;}
00900   if ( (fValid & ONLY_5555)            == ONLY_5555 )           { result = result + " " + "ONLY_5555" ;}
00901   if ( (fValid & GLOBAL_HEADER_ERROR)  == GLOBAL_HEADER_ERROR ) { result = result + " " + "GLOBAL_HEADER_ERROR" ;}
00902   if ( (fValid & FRAME_HEADER_ERROR)   == FRAME_HEADER_ERROR )  { result = result + " " + "FRAME_HEADER_ERROR" ;}
00903   if ( (fValid & TRAILER_C3_FOUND)     == TRAILER_C3_FOUND )    { result = result + " " + "TRAILER_C3_FOUND" ;}
00904   if ( (fValid & END_OF_FILE_ERROR)    == END_OF_FILE_ERROR )   { result = result + " " + "END_OF_FILE_ERROR" ;}
00905 
00906 
00907   return result;
00908 }
00909 

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