#include "Mixture.h" #include #include #include #include "IO/LCReader.h" #include "UTIL/LCTOOLS.h" #include "marlin/Exceptions.h" #include #include #include #include #include #include #include #include #include #include #include "EVENT/CalorimeterHit.h" #include "IMPL/CalorimeterHitImpl.h" #include "IMPL/LCGenericObjectImpl.h" using namespace lcio; using namespace marlin; using namespace std; Mixture aMixture ; //============================================================================ static int _ecal_last_layer(const gear::CalorimeterParameters& pCAL){ //============================================================================ int i; const gear::LayerLayout &lb = pCAL.getLayerLayout() ; int nLayerb = lb.getNLayers() ; double tlb = lb.getThickness(0); double dlb = lb.getAbsorberThickness(0); for( i=1 ; i < nLayerb ; i++ ) if(fabs(tlb-lb.getThickness(i))>0.0000001 || fabs(dlb-lb.getAbsorberThickness(i))>0.0000001) return i; cerr<<"ERROR: Can't get boundary of CAL"< XY_shifts; XY_shifts.push_back(0.0); XY_shifts.push_back(300.0); registerProcessorParameter( "Coordinate shift for additional " , "Coordinate shift for additional " , _XY_shifts,XY_shifts); registerOutputCollection(LCIO::CALORIMETERHIT, "SumOfECALHits", "Name of the hit collection for PANDORA", _ECALHitsCol,std::string("MixtureECAL")); registerOutputCollection(LCIO::CALORIMETERHIT, "SumOfHCALHits", "Name of the hit collection for PANDORA", _HCALHitsCol,std::string("MixtureHCAL")); registerOutputCollection(LCIO::LCGENERICOBJECT, "ParticleProperties", "Name of particle properties collection for PANDORA", _propCol,std::string("ParticleProperties")); } //================================================================================= void Mixture::init() { //================================================================================= // Opening all additional files to make a mixture _lcReaders.resize(_inputFileNames.size()); _numMixture = _inputFileNames.size(); for(int i=0; i < _numMixture; ++i) { _lcReaders[i] = LCFactory::getInstance()->createLCReader(); _lcReaders[i]->open(_inputFileNames[i]); if(_lcReaders[i]){ std::cout<< " File: "<< _inputFileNames[i] <<" was open successfully"<takeCollection("ADDS"); if(firstSelectColl){ std::cout << "first ADDS col. has parameters "; LCGenericObjectImpl* pSelPar = dynamic_cast(firstSelectColl->getElementAt(0)); for(int i=0; i<2;++i){ selPar[i] = pSelPar -> getIntVal(i); cout << selPar[i]<<" "; } showerEnergy = pSelPar -> getFloatVal(3); showerRadius = pSelPar -> getFloatVal(4); cout <<"shower energy ="<setTransient( true ); //cout << "Collection: " << (*name).c_str() << " dropped" << endl; } } return; } // unsigned l = 0; float x = 0.0; float y = 0.0; float z = 0.0; float e = 0.0; int nHitsE = 0; int nHitsH = 0; // int nHitsT = 0; int ix; int jy; int kz; double stp_ecal = 10.0; double shift_int_ecal = 1000.0; double stp_hcal = 30.0; double shift_int_hcal = 1000.0; float ecoef; float sumFullEnergy = 0.; float fullEnergy ; float ECALEnergy = 0.; float HCALEnergy = 0.; // Initialyze amplitudes for(ix=0;ix<200;ix++) for(jy=0;jy<200;jy++) for(kz=0;kz<100;kz++) ampl[ix][jy][kz] = 0.0; EVENT::LCCollection* ecal_coll = 0; EVENT::LCCollection* hcal_coll = 0; EVENT::LCCollection* tcal_coll = 0; // EVENT::LCCollection* ptrk_coll = 0; ecal_coll = evt->takeCollection("ECAL"); hcal_coll = evt->takeCollection("HCAL"); tcal_coll = evt->takeCollection("TCAL"); // ptrk_coll = evt->takeCollection("PTRK"); LCCollectionVec *properties = new LCCollectionVec(LCIO::LCGENERICOBJECT); LCGenericObjectImpl* elProperties = new LCGenericObjectImpl; CalorimeterHit* hit; // pointer of class CalorimeterHit if(ecal_coll){ // Read initial particle ECAL collection into Mixture cout <<"the first "; // cout<<"================= ECAL ====================================="<getNumberOfElements();// Get number of hits in ECAL for( int i = 0 ; i < nHitsE ; i++ ){ // then fill it hit = dynamic_cast(ecal_coll->getElementAt(i)); e = (hit->getEnergy()); // [MIPs] if(e<0.5)continue; x = (hit->getPosition()[0]); y = (hit->getPosition()[1]); z = (hit->getPosition()[2]); kz = (hit->getType()); ecoef = ecal_coeff1; if(kz > 9) ecoef = ecal_coeff2; if(kz > 19) ecoef = ecal_coeff3; ix = int((x+shift_int_ecal)/stp_ecal) + 1; jy = int((y+shift_int_ecal)/stp_ecal) + 1; if(ix >= 0 && jy >= 0 && ix < 200 && jy < 200){ // cout<<"first part. ECAL Hit has "<getNumberOfElements();// Get number of hits in ECAL ecoef = hcal_coeff1; // all coeffs here are the same for( int i = 0 ; i < nHitsH ; i++ ){ // then fill it hit = dynamic_cast(hcal_coll->getElementAt(i)); e = (hit->getEnergy()); // [MIPs] if(e<0.5)continue; x = (hit->getPosition()[0]); y = (hit->getPosition()[1]); z = (hit->getPosition()[2]); kz = (hit->getType()); ix = int((x+shift_int_hcal)/stp_hcal) + 1; jy = int((y+shift_int_hcal)/stp_hcal) + 1; if(ix >= 0 && jy >= 0 && ix < 200 && jy < 200){ //cout<<" HCAL Hit "< setIntVal(0,selPar[0]); elProperties -> setIntVal(1,selPar[1]); elProperties -> setFloatVal(2,showerEnergy); elProperties -> setFloatVal(3,showerRadius); elProperties -> setFloatVal(4,fullEnergy); properties -> addElement(elProperties); } LCEvent * mevt = 0; //222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 // Read all additional files with particles to join in one event //222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 for(int imix=0; imix < _numMixture; ++imix){ mevt = _lcReaders[imix]->readNextEvent(LCIO::UPDATE); float xsh = _XY_shifts[unsigned(2*imix)]; float ysh = _XY_shifts[unsigned(2*imix+1)]; if(mevt){ // cout<<"=============================================================="<takeCollection("ADDS"); if(addSelectColl){ std::cout << " add. ADDS col. has parameters "; LCGenericObjectImpl* pSelPar = dynamic_cast(addSelectColl->getElementAt(0)); for(int i=0; i<2;++i){ selPar[i] = pSelPar -> getIntVal(i); cout << selPar[i]<<" "; } showerEnergy = pSelPar -> getFloatVal(3); showerRadius = pSelPar -> getFloatVal(4); cout <<"shower energy ="<< showerEnergy<<" shower radius =" << showerRadius<* colNames = evt->getCollectionNames(); for( StringVec::const_iterator name = colNames->begin(); name != colNames->end() ; name++ ){ LCCollectionVec* col = dynamic_cast (evt->getCollection( *name ) ); if ( !std::strncmp((*name).data(),"ECAL", 4) || !std::strncmp((*name).data(),"HCAL", 4) || !std::strncmp((*name).data(),"TCAL", 4) || !std::strncmp((*name).data(),"PTRK", 4) || !std::strncmp((*name).data(),"ADDS", 4) ) { col->setTransient( true ); //cout << "Collection: " << (*name).c_str() << " dropped" << endl; } } return; } ecal_coll = mevt->takeCollection("ECAL"); hcal_coll = mevt->takeCollection("HCAL"); tcal_coll = mevt->takeCollection("TCAL"); // ptrk_coll = mevt->takeCollection("PTRK"); ECALEnergy = 0.; HCALEnergy = 0.; LCGenericObjectImpl* elProperties = new LCGenericObjectImpl; if(ecal_coll){ // Read secondary particle ECAL collection into Mixture cout <<"additional"; //cout<<"================= ECAL ====================================="<getNumberOfElements();// Get number of hits in ECAL for( int i = 0 ; i < nHitsE ; i++ ){ // then fill it hit = dynamic_cast(ecal_coll->getElementAt(i)); kz = (hit->getType()); if(kz<(selPar[0]*30+selPar[1]))continue; e = (hit->getEnergy()); // [MIPs] if (e<0.5)continue; x = (hit->getPosition()[0]) + xsh; y = (hit->getPosition()[1]) + ysh; z = (hit->getPosition()[2]); ecoef = ecal_coeff1; if(kz > 9) ecoef = ecal_coeff2; if(kz > 19) ecoef = ecal_coeff3; ix = int((x+shift_int_ecal)/stp_ecal) + 1; jy = int((y+shift_int_ecal)/stp_ecal) + 1; if(ix >= 0 && jy >= 0 && ix < 200 && jy < 200){ // cout<<"second part. ECAL Hit has "<getNumberOfElements();// Get number of hits in HCAL ecoef = hcal_coeff1; // all coeffs here are the same for( int i = 0 ; i < nHitsH ; i++ ){ // then fill it hit = dynamic_cast(hcal_coll->getElementAt(i)); kz = (hit->getType()); if(kz<(selPar[0]*30+selPar[1]))continue; e = (hit->getEnergy()); // [MIPs] if(e<0.5)continue; x = (hit->getPosition()[0]) + xsh; y = (hit->getPosition()[1]) + ysh; z = (hit->getPosition()[2]); ix = int((x+shift_int_hcal)/stp_hcal) + 1; jy = int((y+shift_int_hcal)/stp_hcal) + 1; if(ix >= 0 && jy >= 0 && ix < 200 && jy < 200){ //cout<<" HCAL Hit "< setIntVal(0,selPar[0]); elProperties -> setIntVal(1,selPar[1]); elProperties -> setFloatVal(2,showerEnergy); elProperties -> setFloatVal(3,showerRadius); elProperties -> setFloatVal(4,fullEnergy); properties -> addElement(elProperties); } /* // Make copy of all collections from additional files char coll_name[128]; sprintf(coll_name,"ECAL%1d",imix); evt->addCollection(ecal_coll,coll_name); sprintf(coll_name,"HCAL%1d",imix); evt->addCollection(hcal_coll,coll_name); sprintf(coll_name,"TCAL%1d",imix); evt->addCollection(tcal_coll,coll_name); // sprintf(coll_name,"PTRK%1d",imix); // evt->addCollection(ptrk_coll,coll_name); */ } else { cout<<"+++++++++++ LCIO Reader did nor find next event in file " <<_inputFileNames[imix]<<" ++++++++++++++++++++++++++++\n" <<" +++++++++++++++++ Run should be stopped ++++++++++++++++++++\n" <<" +++++++++++ StopProcessingException is called ++++++++++++++" < addCollection(properties,_propCol); LCCollectionVec *ecalohitVec = new LCCollectionVec(LCIO::CALORIMETERHIT); LCCollectionVec *hcalohitVec = new LCCollectionVec(LCIO::CALORIMETERHIT); ECALEnergy = 0.; HCALEnergy = 0.; // fullEnergy = 0.; float pos[3]; for(kz=0;kz<30;kz++){ // ECAL only for(ix=0;ix<200;ix++){ for(jy=0;jy<200;jy++){ if(ampl[ix][jy][kz] < 0.5) continue; ecoef = ecal_coeff1; if(kz > 9) ecoef = ecal_coeff2; if(kz > 19) ecoef = ecal_coeff3; CalorimeterHitImpl * hit = new CalorimeterHitImpl(); float xx = (ix-0.5)*stp_ecal - shift_int_ecal; float yy = (jy-0.5)*stp_ecal - shift_int_ecal; pos[0] = -xx; pos[1] = er_inner + kz*esampling_1+0.5*esampling_1; // correct step + shift to radius if(kz > 9)pos[1] = er_inner+10*esampling_1+(kz-10)*esampling_2+ 0.5*esampling_2; if(kz > 19)pos[1] = er_inner+10*esampling_1+10*esampling_2 + (kz-20)*esampling_3 + 0.5*esampling_3; pos[2] = yy; // cout<< " new X = "<setPosition(pos); hit->setEnergy(ecoef*ampl[ix][jy][kz]); hcalohitVec ->addElement(hit); } } } fullEnergy = ECALEnergy + HCALEnergy; cout <<" HCALEnergy ="<< HCALEnergy <<" GeV"<<" fullEnergy ="<< fullEnergy<<"("<setFlag( cFlag.getFlag()); hcalohitVec->setFlag( cFlag.getFlag()); evt->addCollection(ecalohitVec,_ECALHitsCol); evt->addCollection(hcalohitVec,_HCALHitsCol); _nEvt++; } //=============================================================================================== void Mixture::check( LCEvent *evt) {;} //=============================================================================================== void Mixture::end(){;} //===============================================================================================