/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/event/Event.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1765 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2012-06-07 17:01:44 +0200 (Thu, 07 Jun 2012) $ */
00002 
00003 //#include <c++/4.0.0/bits/stl_map.h>
00004 
00005 
00006 
00007 #include "event/ChannelHit.hh"
00008 #include "event/Event.hh"
00009 #include "event/Run.hh"
00010 #include "geometry/Chip.hh"
00011 #include "geometry/Dif.hh"
00012 #include "geometry/Board.hh"
00013 #include "geometry/Chamber.hh"
00014 #include "geometry/Detector.hh"
00015 #include "geometry/Channel.hh"
00016 
00017 #include "tools/MicroException.hh"
00018 #include "tools/Log.hh"
00019 #include "slowControl/SlowControlEntry.hh"
00020 #include "slowControl/ChamberSlowControl.hh"
00021 
00022 
00023 #include <string>
00024 /*
00025 #include "UTIL/LCTime.h"
00026 #include "IMPL/LCFlagImpl.h"
00027 #include "IMPL/LCCollectionVec.h"
00028 #include "UTIL/CellIDEncoder.h"
00029 #include "IMPL/RawCalorimeterHitImpl.h"
00030 #include "IMPL/CalorimeterHitImpl.h"
00031 #include "IMPL/LCTOOLS.h"
00032 
00033 #include "IO/LCWriter.h"
00034 #include "EVENT/LCIO.h"
00035 #include "DATA/LCFloatVec.h"
00036 #include "DATA/LCIntVec.h"
00037 
00038 #include "IMPL/LCEventImpl.h"
00039 #include "IMPL/LCRunHeaderImpl.h"
00040 #include "IMPL/LCCollectionVec.h"
00041 #include "IMPL/RawCalorimeterHitImpl.h"
00042 #include "IMPL/SimTrackerHitImpl.h"
00043 #include "IMPL/MCParticleImpl.h"
00044 #include "IMPL/LCFlagImpl.h"
00045 #include "IMPL/LCTOOLS.h"
00046 
00047 #include "IMPL/TrackerRawDataImpl.h"
00048 #include "IMPL/TrackerDataImpl.h"
00049 #include "IMPL/TrackerPulseImpl.h"
00050 
00051 #include "UTIL/LCRelationNavigator.h"
00052 #include "UTIL/LCTime.h"
00053 #include "UTIL/CellIDEncoder.h"
00054 #include "UTIL/LCTypedVector.h"
00055 
00056 #include "UTIL/LCSplitWriter.h"
00057 
00058 static const int NEVENT = 10 ; // events
00059 static const int NMCPART = 10 ;  // mc particles per event
00060 static const int NHITS = 5 ;  // calorimeter hits per event
00061 */
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 using namespace std;
00071 
00072 
00073   std::ostream& operator <<(std::ostream &out, const Event &x) {
00074     return(x.operator <<(out));
00075   }
00076 
00077 
00078 Event::Event(Run& aRun):run(aRun), slowControlEntry(NULL)
00079 {
00080   //FILE_LOG(logDEBUG) << "-Event contructor"<< endl;
00081 //  initChannelHitVector();
00082 timestamp = 0;
00083 difSynchro = 0;
00084 id = 0;
00085 slowControlEntry = NULL;
00086 crcIsCorrect = true;
00087 valid = VALID;
00088 }
00089 
00090  Event::Event(Run& aRun, i64 aTimestamp, i32 aId):run(aRun), timestamp(aTimestamp), id(aId), slowControlEntry(NULL)
00091  {
00092   timestamp = 0;
00093   difSynchro = 0;
00094   id = 0;
00095   slowControlEntry = NULL;
00096   crcIsCorrect = true;
00097   valid = VALID;
00098      //FILE_LOG(logDEBUG) << "-Event contructor with id: "<< aId << endl;
00099  }
00100 
00101 Event::~Event()
00102 {
00103   //FILE_LOG(logDEBUG) << "-Event destructor"<< endl;
00104 
00105    map<ui16, multiset<ChannelHit*,sorter>* >::iterator iter;
00106 
00107   for (iter=channelHits.begin(); iter!=channelHits.end(); iter++)
00108   {
00109       multiset<ChannelHit*,sorter>* list = (*iter).second;
00110       for (multiset<ChannelHit*,sorter>::iterator iterList = list->begin(); iterList!=list->end(); iterList++ )
00111       {
00112           delete (*iterList);
00113       }
00114       delete list;
00115   }
00116 
00117 }
00118 
00119 /*---------------------------------------------------*/
00120 ostream& Event::operator <<(ostream &out) const {
00121   return(out << "-Event id["<< id << "]" << endl
00122              << "-Event timestamp[" << timestamp << "]"  << endl);
00123 }
00124 
00125 /*---------------------------------------------------*/
00126 void Event::initChannelHitVector()
00127     {
00128       ChamberMap_t chambers = this->run.getDetector().getChambers();
00129 
00130       for (ChamberMap_t::iterator iter = chambers.begin() ; iter != chambers.end() ; iter++)
00131       {
00132         i32 chamberId  = (*iter).first;
00133         multiset<ChannelHit*, sorter> *list = new multiset<ChannelHit*, sorter>();
00134              FILE_LOG(logINFO) << "INIT map size BEFORE INSERT:[" << channelHits.size() << "]" << endl;
00135         channelHits[chamberId] = list;  // a ChannilHits* vector per Chamber
00136              FILE_LOG(logINFO) << "INIT map size AFTER INSERT:[" << channelHits.size() << "]" << endl;
00137       }
00138     }
00139 /*---------------------------------------------------*/
00140     const multiset<ChannelHit*,sorter>& Event::getChannelHitVector(const Chamber& aChamber) const
00141     {
00142 
00143          map<ui16, multiset<ChannelHit*,sorter>* >::const_iterator iter = channelHits.find(aChamber.getId());
00144          if( iter != channelHits.end() ) {
00145              return (*iter->second);
00146          }
00147 
00148          throw ( MicroException("No channelHit vector for this chamber"));
00149     //    return channelHits.find(aChamber.getId())->second;
00150     }
00151 /*------------------------------------------------------------------------------------*/
00152     void Event::insertHit(Chamber& aChamber, ChannelHit *aChannelHit)
00153     {
00154          ui16 chamberId  = aChamber.getId();
00155 
00156          multiset<ChannelHit*,sorter>* hits = NULL;
00157 
00158          map<ui16, multiset<ChannelHit*,sorter> *>::iterator iter = channelHits.find(chamberId);
00159 
00160          if( iter == channelHits.end() ) {
00161              hits = new  multiset<ChannelHit*, sorter>();
00162              channelHits.insert(pair<i32, multiset<ChannelHit*,sorter>* > (chamberId,hits));
00163          }
00164 
00165          else
00166          {
00167             hits = iter->second;
00168          }
00169 
00170          hits->insert(aChannelHit);
00171 
00172 
00173     }
00174 /*------------------------------------------------------------------------------------*/
00175 
00176  const ChannelHit& Event::getChannelHitByOrder( ui64 order ,const Chamber& aChamber, i16 aThreshold)
00177  {
00178      if ( getChannelHitByOrder(order+1,aChamber).getAnalogValue() <= aThreshold )
00179      {
00180          return getChannelHitByOrder(order,aChamber);
00181      }
00182      else
00183      {
00184          throw MicroException("No Channel respond for this event, this order, this threshold and this chamber ");
00185      }
00186  }
00187 
00188 /*------------------------------------------------------------------------------------*/
00189  const ChannelHit& Event::getChannelHitByOrder(ui64 order ,const Chamber& aChamber)
00190  {
00191         multiset<ChannelHit*,sorter>* chamberChannelHit = this->channelHits.find(aChamber.getId())->second;//channelHits[aChamber.getId()];
00192         ui64 items=0;
00193                 // Find first chamberChannelHit for select chamber
00194         for (multiset<ChannelHit*,sorter>::const_iterator iter=chamberChannelHit->begin(); iter!=chamberChannelHit->end(); iter++)
00195         {
00196                 if ( (*iter)->getChannel().getChamber().getId() == aChamber.getId() )
00197                 {
00198                     if ( order == items)
00199                     {
00200                         return *(*iter);
00201                     }
00202 
00203                     items++;
00204                 }
00205 
00206         }
00207   throw MicroException("No Channel respond or this event, this order and this chamber ");
00208 
00209  }
00210  /*
00211  //------------------------------------------------------------------------------------
00212  ui64 Event::getChannelHitOrder(const ChannelHit& aChannelHit ,const Chamber& aChamber, bool sort)
00213  {
00214      return this->getChannelHitOrder(aChannelHit.getChannel(),aChamber, sort);
00215  }
00216  //------------------------------------------------------------------------------------
00217  ui64 Event::getChannelHitOrder(const Channel& achannel  ,const Chamber& aChamber)
00218  {
00219      multiset< ChannelHit*,sorter>* list = this->channelHits.find(aChamber.getId())->second;//channelHits[aChamber.getId()];
00220      ui64 order=0;
00221   // Find corresponding channelHit
00222      for (multiset<ChannelHit*,sorter>::const_iterator iter=list->begin(); iter!=list->end(); iter++)
00223      {
00224              if ( (*iter)->getChannel().getSoftId() == achannel.getSoftId())
00225              {
00226                  return order;
00227              }
00228              order++;  // incremente le numero d'ordre pour les channela de la chambre
00229 
00230     }
00231   throw MicroException("No Channel respond for this event, this order and this chamber ");
00232 
00233  }
00234         */
00235 /*------------------------------------------------------------------------------------*/
00236 void Event::setSlowControlParam(const SlowControlEntry* params)
00237 {
00238   slowControlEntry = params;
00239   FILE_LOG(logDEBUG1) << "Event temperature["<< slowControlEntry->getTemperature() << "]" << endl;
00240   FILE_LOG(logDEBUG1) << "Event overPressure["<< slowControlEntry->getOverPressure() << "]" << endl;
00241   FILE_LOG(logDEBUG1) << "Event Pressure["<< slowControlEntry->getPressure() << "]" << endl;
00242 }
00243 
00244 /*------------------------------------------------------------------------------------*/
00245 
00246 void Event::print(void) const
00247 {
00248   FILE_LOG(logINFO) << "-Event id["<< id << "]" << endl;
00249   FILE_LOG(logINFO) << "-Event timestamp[" << timestamp << "]"  << endl ;
00250 }
00251 
00252 /*------------------------------------------------------------------------------------*/
00253 const float Event::getPressure() const
00254 {
00255     if ( slowControlEntry != NULL)
00256     {
00257         return slowControlEntry->getPressure();
00258     }
00259     else
00260     {
00261         return 0;
00262     }
00263 
00264 }
00265 /*------------------------------------------------------------------------------------*/
00266 const float Event::getTemperature() const
00267 {
00268     if ( slowControlEntry != NULL)
00269     {
00270         return slowControlEntry->getTemperature();
00271     }
00272     else
00273     {
00274         return 0;
00275     }
00276 
00277 }
00278 /*------------------------------------------------------------------------------------*/
00279 const BoardSlowControl& Event::getBoardSlowControl(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00280 {
00281     if ( slowControlEntry != NULL)
00282     {
00283        try
00284        {
00285            return slowControlEntry->getBoard(chamberId,difId,boardId);
00286        }
00287        catch ( MicroException e) {}
00288     }
00289 
00290     throw MicroException("Event::getBoardSlowControl: board not found");
00291 }
00292 /*------------------------------------------------------------------------------------*/
00293 const float Event::getBoardDriftVolt(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00294 {
00295     if ( slowControlEntry != NULL)
00296     {
00297        try
00298        {
00299            return slowControlEntry->getBoard(chamberId,difId,boardId).getDrift().voltage;
00300        }
00301        catch ( MicroException e) {}
00302     }
00303     throw MicroException("Event::getBoardSlowControl: board not found");
00304 
00305 }
00306 /*------------------------------------------------------------------------------------*/
00307 const float Event::getBoardMeshVolt(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00308 {
00309     if ( slowControlEntry != NULL)
00310     {
00311        try
00312        {
00313            return slowControlEntry->getBoard(chamberId,difId,boardId).getMesh().voltage;
00314        }
00315        catch ( MicroException e) {}
00316     }
00317     //throw ( MicroException("No mesh voltage for this chamber"));
00318     return -1;
00319 
00320 }
00321 //------------
00322 ui64 Event::getChannelHitSize() const
00323 { 
00324     ui64 size = 0;
00325     for ( std::map<ui16, std::multiset<ChannelHit*,sorter>* >::const_iterator it=channelHits.begin(); it != channelHits.end() ; it++)
00326     {
00327             size +=it->second->size();
00328     }
00329     return size;
00330 }
00331 
00332 //------------
00333 void Event::setTemperature(ui16 difId, float asu1, float asu2, float dif)
00334 {
00335   // Search or create difs container
00336     if ( temperatureAsu1.find(difId) != temperatureAsu1.end())
00337     { // dif already exit/ replace value
00338        temperatureAsu1[difId] = asu1;
00339     }
00340     else
00341     { // does not exit create it
00342       temperatureAsu1.insert(make_pair(difId,asu1));
00343     }
00344   // Search or create difs container
00345     if ( temperatureAsu2.find(difId) != temperatureAsu2.end())
00346     { // dif already exit/ replace value
00347        temperatureAsu2[difId] = asu2;
00348     }
00349     else
00350     { // does not exit create it
00351       temperatureAsu2.insert(make_pair(difId,asu2));
00352     }
00353   // Search or create difs container
00354     if ( temperatureDif.find(difId) != temperatureDif.end())
00355     { // dif already exit/ replace value
00356        temperatureDif[difId] = dif;
00357     }
00358     else
00359     { // does not exit create it
00360       temperatureDif.insert(make_pair(difId,dif));
00361     }
00362 
00363 }
00364 
00365 
00366 
00367 /*------------------------------------------------------------------------------------*/
00368 /*
00369 LCEventImpl* Event::getLcioImpl() 
00370 {
00371 try {
00372         LCEventImpl* evt = new LCEventImpl();
00373 
00374         evt->setRunNumber(  1   ) ;
00375     evt->setDetectorName( "m2" ) ;
00376     evt->setWeight( 1 ) ;
00377 
00378 
00379     evt->setEventNumber( this->id ) ;
00380     // Event timestamp express in millisecond
00381         // But lcio timestamp express in second
00382     evt->setTimeStamp( this->timestamp * 1000000  ) ;
00383 
00384 
00385     evt->parameters().setValue("Dif_syncro",this->difSynchro ) ;
00386     evt->parameters().setValue("Temperature",this->getTemperature() ) ;
00387     evt->parameters().setValue("Pressure",this->getPressure()) ;
00388     evt->parameters().setValue("Global trigger counter",(int)this->globalTriggerCounter ) ;
00389     evt->parameters().setValue("Dif trigger counter",(int)this->difTriggerCounter ) ;
00390     //evt->parameters().setValue("SetDriftVoltage",this->difTriggerCounter ) ;
00391     //evt->parameters().setValue("SetMeshVoltage",this->difTriggerCounter ) ;
00392 
00393 
00394 
00395     // now add some raw calorimeter hits
00396     LCCollectionVec* calVec = new LCCollectionVec( LCIO::RAWCALORIMETERHIT )  ;
00397 
00398     LCFlagImpl chFlag(0) ;
00399     //chFlag.setBit( LCIO::CHBIT_ID1 ) ;
00400 
00401     chFlag.setBit( LCIO::RCHBIT_LONG )   ;  // long(1) - short(0) , incl./excl. position
00402     chFlag.setBit( LCIO::RCHBIT_BARREL ) ;  // barrel(1) - endcap(0)
00403     //chFlag.setBit( LCIO::RCHBIT_TIME   ) ; // 1: time information stored
00404     //chFlag.setBit( LCIO::RCHBIT_ID1   )  ;  // cellid1 stored
00405     //chFlag.setBit( LCIO::RCHBIT_NO_PTR ) ; // 1: pointer tag not added
00406     //chFlag.setBit( LCIO::RCHBIT_ENERGY_ERROR )  ;   // 1: store energy error
00407     calVec->setFlag( chFlag.getFlag()) ;
00408 
00409 
00410 //
00411 //OFFSET_CHAMBER *NB_CHANNEL* GetChamberId()
00412 //+ OFFSET_DIF *NB_CHANNEL*  GetDifId()
00413 //+ OFFSET_CHIP*NB_CHANNEL * GetChipId ()
00414 //+  channelId 
00415 //
00416         // Chambre 1024 -> 2 exp 10
00417         // Dif     128  -> 2 exp 7
00418         // Chip    1024 -> 2 exp 10
00419         // Channel 1024 -> 2 exp 10
00420     std::string cellIDEncoding( "CHAMBER:10,DIF:7,CHIP:10,CHANNEL:10") ;
00421     CellIDEncoder<RawCalorimeterHitImpl> cellEncoder( cellIDEncoding , calVec ) ;
00422 
00423 
00424     ChamberMap_t chamberList = this->getRun().getDetector().getChambers();
00425     for (ChamberMap_t::iterator iter=chamberList.begin(); iter!=chamberList.end(); iter++)
00426     {
00427       Chamber& chamber = *(iter->second);
00428       try
00429       {
00430           const  multiset<ChannelHit*,sorter>& list = this->getChannelHitVector(chamber);
00431           int order = 0 ;
00432           for (set<ChannelHit*,sorter>::iterator iter=list.begin(); iter!=list.end(); iter++)
00433           {
00434             ChannelHit& channelHit = *(*iter);
00435             const Channel& channel = channelHit.getChannel();
00436                 RawCalorimeterHitImpl* rawHit = NULL ;
00437             try
00438             {
00439                           // Create RawCalorimeterHit
00440                   rawHit = new RawCalorimeterHitImpl() ;
00441 
00442               if ( chamber.getType().compare(GASSIPLEXCHAMBER1)==0 ||  chamber.getType().compare(GASSIPLEXCHAMBER4)==0)
00443               {
00444                     channelHit.setTimestamp(this->getTimeStamp());
00445                           }
00446                         
00447                         
00448                   cellEncoder["CHAMBER"] = channel.getChamber().getId(); 
00449                   cellEncoder["DIF"] = channel.getChip().getBoard().getDif()->getId(); 
00450                   cellEncoder["CHIP"] = channel.getChip().getId(); 
00451                   cellEncoder["CHANNEL"] = channel.getHardId(); 
00452                           cellEncoder.setCellID( rawHit ) ;
00453                         
00454                   rawHit->setAmplitude( channelHit.getDigitalValue()   )  ;
00455                   //rawHit->setTimeStamp( channelHit.getTimestamp() / 1000) ; 
00456 
00457               order++;  // because aEvent have already been  sorted
00458                   calVec->push_back( rawHit ) ;
00459             } // end try block
00460             catch (MicroException e)
00461             {
00462             }
00463 
00464           } // end for channelHits for this chamber
00465       }
00466       catch (MicroException e)
00467       {
00468                 // get ChamberHitVector for next chamber
00469       }
00470 
00471     }
00472     //LCTOOLS::printRawCalorimeterHits(calVec);
00473     // add all collections to the event
00474 
00475     evt->addCollection( calVec , "m2" ) ;
00476         return evt;
00477 
00478 
00479   }
00480   catch( Exception& ex){
00481 
00482     cout << " an excpetion occured: " << endl ;
00483     cout << "  " << ex.what() << endl ;
00484     return NULL;
00485   }
00486 
00487     return NULL;
00488 
00489 
00490 }*/
00491 bool Event::isValid(void)
00492 {
00493   if ( valid == VALID ) return true;
00494   return false;
00495 }

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