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

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

Generated on Mon Jun 11 16:55:46 2012 for MicromegasFramework by  doxygen 1.4.7