/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/lcio/createLcioCalorimeterHit.cc File Reference

#include "IO/LCWriter.h"
#include "IMPL/LCRunHeaderImpl.h"
#include "IMPL/LCEventImpl.h"
#include "IMPL/LCTOOLS.h"
#include "IMPL/CalorimeterHitImpl.h"
#include "IMPL/LCCollectionVec.h"
#include "IMPL/LCFlagImpl.h"
#include "lcio.h"
#include "tools/MicroException.hh"
#include "tools/Arguments.hh"
#include <sstream>
#include <iostream>
#include <TRandom.h>
#include <TTree.h>
#include <TFile.h>
#include <TStyle.h>
#include <TKey.h>
#include <TreeClass.hh>
#include <Riostream.h>
#include <string>
#include "mysql/Mysql.hh"
#include <fstream>
#include "TH2I.h"

Include dependency graph for createLcioCalorimeterHit.cc:

Go to the source code of this file.

Functions

void selectAndCopyEvent (const string &inputFileName, const string &outputFileName)
Long64_t buildCaloEvent (const MTEvent &evt, LCEventImpl &, Long64_t bcidAbsPrev, bool &track, TH1F &hResidualX, TH1F &hResidualY)
void usage (void)
int main (int argc, char **argv)


Function Documentation

void selectAndCopyEvent ( const string &  inputFileName,
const string &  outputFileName 
)

Long64_t buildCaloEvent ( const MTEvent evt,
LCEventImpl &  ,
Long64_t  bcidAbsPrev,
bool &  track,
TH1F &  hResidualX,
TH1F &  hResidualY 
)

Definition at line 192 of file createLcioCalorimeterHit.cc.

00193   {
00194 
00195   caloEvent.setTimeStamp( evt.GetTimestamp() * 1000000  ) ;
00196   caloEvent.setDetectorName( "Lapp Microroc Micromegas and Gassiplex telecope" ) ;
00197 
00198 
00199   int nchannel = 0;
00200   //Define bcIdAbsPrev, bcid_abs of first readout
00201   if (bcIdAbsPrev == -1)
00202   {
00203     nchannel = evt.GetNchannel();
00204 
00205     for (int j=0;j<nchannel;j++)
00206     {             
00207       MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
00208 
00209       if (channel->GetChamberId() == 10)
00210       {
00211        return  channel->GetBcId_Abs();
00212       }
00213     }
00214   }
00215 
00216 
00217   /*m2 prototype time cut*/
00218   int dt_min = 4;
00219   int dt_max = 10;
00220 
00221   /*spark cut = Nhit inside 0-20 dt region*/
00222   int nhit_spark_cut = 1000;
00223 
00224   /*telescope energy cut*/
00225   int adc_cut = 25;
00226 
00227   int i = 0;
00228   int t = 0;
00229   int adc = 0;
00230   int xpos = 0;
00231   int ypos = 0;
00232   int zpos = 0;
00233   int zmax = 0;
00234   int digit = 0;
00235   int chbid = 0;
00236   int nhit_m2_cut = 0;
00237   double time = 0;
00238   TString name,title;
00239   Long64_t tprev,t0,t1,t2,t3,dt;
00240 
00241   int nhit[3];
00242   int xmax[3];
00243   int ymax[3];
00244 
00245   TH2I * hxy_tel_adc[3];
00246 
00247 
00248   for (int i=0;i<3;i++)
00249   {
00250     nhit[i] = 0;
00251     xmax[i] = 0;
00252     ymax[i] = 0;
00253 
00254     name = Form("hxy_tel_adc_chamber_%i",i+7);
00255     title = Form("Hit pattern (adc>%i) chamber %i;y (cm);x (cm)",adc_cut,i+7);
00256     hxy_tel_adc[i] = new TH2I(name,title,32,0,32,32,0,32);
00257   }
00258 
00259   //if t0 is defined start loop over events
00260 
00261   nchannel = evt.GetNchannel();
00262 
00263   if (nchannel!=0)
00264   {
00265     //determine time to previous readout
00266     for (int j=0;j<nchannel;j++)
00267     {
00268       MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
00269       if (channel->GetChamberId() == 10)
00270       {
00271         t1 = channel->GetBcId_Abs();
00272         j = nchannel;
00273       }
00274     }
00275 
00276     time = t1 - bcIdAbsPrev;
00277     time *= 200e-9;
00278     bcIdAbsPrev = t1;
00279 
00280 
00281     //if readout occured after less than 3.35 s of previous readout
00282     //skip also first event as hit time info is wrong
00283     if (time <= 3.35)
00284     {
00285       //look for a track in telescope
00286       for (int j=0;j<nchannel;j++)
00287       {
00288         MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
00289         chbid = channel->GetChamberId();
00290 
00291         //look in pad chambers
00292         if (chbid == 7 || chbid == 8 || chbid == 9)
00293         {
00294           adc = channel->GetAnalogValue();
00295 
00296           if (adc >= adc_cut)
00297           {
00298             nhit[chbid-7]++;
00299             hxy_tel_adc[chbid-7]->Fill(channel->GetY()*1e-4,channel->GetX()*1e-4,adc);
00300           }
00301         }
00302       }
00303 
00304       //require that 3 pad chambers have at least 1 hit
00305       if (nhit[0]>0 && nhit[1]>0 && nhit[2]>0)
00306       {
00307         //find position of ADC maxima
00308 
00309         for (int k=0;k<3;k++)
00310         {
00311           hxy_tel_adc[k]->GetMaximumBin(ymax[k],xmax[k],zmax);
00312         }
00313 
00314         //require aligned maxima
00315 
00316         if (ymax[0]==ymax[1] && ymax[0]==ymax[2] &&
00317             xmax[0]==xmax[1] && xmax[0]==xmax[2])
00318         {
00319           //reloop over hits
00320           nhit_m2_cut = 0;
00321 
00322           for (int j=0;j<nchannel;j++)
00323           {
00324             MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
00325 
00326             //look in m2 prototype
00327             if (channel->GetChamberId() == 10)
00328             {                                 
00329               t2 = channel->GetBcId_Dif();
00330               t3 = channel->GetBcId_Hit();
00331               dt = t2 - t3;
00332 
00333               if (dt>=0 && dt<=20)
00334               {
00335                 nhit_m2_cut++;
00336               }
00337             }
00338           }
00339 
00340           //reject high multiplicity event in time region of signal
00341           if (nhit_m2_cut < nhit_spark_cut)
00342           {
00343                   track = 1;    
00344             caloEvent.parameters().setValue("XTelescope", xmax[0] );
00345             caloEvent.parameters().setValue("YTelescope", ymax[0] );
00346 
00347             //reloop over hits
00348             LCCollectionVec* calVec = new LCCollectionVec( LCIO::CALORIMETERHIT )  ;
00349             for (int j=0;j<nchannel;j++)
00350             {
00351               MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
00352 
00353               //look in m2 prototype
00354               if (channel->GetChamberId() == 10)
00355               {
00356                 t3 = channel->GetBcId_Hit();
00357                 dt = t2 - t3;
00358 
00359                 if (dt>=dt_min && dt<=dt_max)
00360                 {
00361                   digit = channel->GetDigitalValue();
00362                   xpos = (int)channel->GetX();
00363                   ypos = (int)channel->GetY();
00364                   zpos = (int)channel->GetZ();
00365 
00366                   xpos /= 10000;
00367                   ypos /= 10000;
00368 
00369                   t = (int)dt;
00370 
00371 //                  CaloHit hit;
00372                         hResidualX.Fill(xmax[0]-xpos);
00373                         hResidualY.Fill(ymax[0]-ypos);
00374 /*
00375                   hit.SetDeltaT(t);
00376                   hit.SetThreshold(digit);
00377 */
00378 
00379                   CalorimeterHitImpl* caloHit = new CalorimeterHitImpl() ;
00380                   //caloHit->parameters().setValue("DeltaT", t);
00381                   //caloHit->parameters().setValue("Threshold", digit);
00382                   try
00383                   {
00384                     // Create RawCalorimeterHit
00385                     caloHit->setEnergy( digit )  ;
00386                     caloHit->setTime( t )  ;
00387                     const float pos[3] = { xpos, ypos, 0};
00388                     caloHit->setPosition(pos);
00389 
00390 
00391 
00392                       LCFlagImpl chFlag(0) ;
00393                       //chFlag.setBit( LCIO::CHBIT_ID1 ) ;
00394                       chFlag.setBit( LCIO::RCHBIT_LONG )   ;  // long(1) - short(0) , incl./excl. position
00395                       chFlag.setBit( LCIO::RCHBIT_BARREL ) ;  // barrel(1) - endcap(0)
00396                       chFlag.setBit( LCIO::RCHBIT_TIME   ) ; // 1: time information stored
00397                       //chFlag.setBit( LCIO::RCHBIT_ID1   )  ;  // cellid1 stored
00398                       chFlag.setBit( LCIO::RCHBIT_NO_PTR ) ; // 1: pointer tag not added
00399                       //chFlag.setBit( LCIO::RCHBIT_ENERGY_ERROR )  ;   // 1: store energy error
00400                       calVec->setFlag( chFlag.getFlag()) ;
00401 
00402                     calVec->push_back( caloHit ) ;
00403 
00404                   } // end try block
00405                   catch (MicroException e)
00406                   {
00407                   }
00408                   //LCTOOLS::printRawCalorimeterHits(calVec);
00409                   // add all collections to the event
00410 
00411                 }
00412               }
00413             }
00414             caloEvent.addCollection( calVec , "m2" ) ;
00415           }
00416           else { track = 0; }
00417         }
00418       } //end nhit[0]>0 && nhit[1]>0 && nhit[2]>0
00419     } // end time <= 3.35 && i != 0
00420   } // enf if nChannel != 0
00421     
00422   for (int i=0;i<3;i++)
00423   {
00424    delete hxy_tel_adc[i];
00425   }
00426 
00427   return bcIdAbsPrev;
00428 }

void usage ( void   ) 

Definition at line 45 of file createLcioCalorimeterHit.cc.

00046 {
00047     cout  << "     : buildCaloHits -f filename outputfileName" << endl;
00048 }

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file createLcioCalorimeterHit.cc.

00050                                 {
00051 
00052   if ( argc < 4 || argc > 5 )
00053   {
00054     usage();
00055     return -1;
00056   }
00057 
00058   // Get input file name in a input file
00059   if ( strcmp (argv[1] ,"-f") == 0 )
00060   {
00061      if ( argc != 4 ) { usage(); return -1; } 
00062      string outputFileName = argv[3];
00063 
00064      ifstream myReadFile;
00065      myReadFile.open(argv[2]);
00066      string inputRootFile;
00067      if (myReadFile.is_open()) {
00068      while (!myReadFile.eof()) {
00069         getline(myReadFile,inputRootFile);
00070         if ( inputRootFile.size() > 0 ) 
00071         {
00072           selectAndCopyEvent(inputRootFile,outputFileName);
00073         }
00074      }
00075     }
00076     myReadFile.close();
00077     return 0;
00078   }
00079   else 
00080   {
00081     usage();
00082     return -1;
00083   }
00084   return 0;
00085 }


Generated on Mon Jan 7 13:16:59 2013 for MicromegasFramework by  doxygen 1.4.7