CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimTracker/TrackerFilters/plugins/CosmicTIFTrigFilter.cc

Go to the documentation of this file.
00001 // livio.fano@cern.ch
00002 
00003 #include "SimTracker/TrackerFilters/interface/CosmicTIFTrigFilter.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "MagneticField/Engine/interface/MagneticField.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 #include "HepMC/GenVertex.h"
00010 #include <map>
00011 #include <vector>
00012 
00013 using namespace std;
00014 namespace cms
00015 
00016 {
00017   CosmicTIFTrigFilter::CosmicTIFTrigFilter(const edm::ParameterSet& conf):    conf_(conf)
00018   {
00019     trigconf  = conf_.getParameter<int>("trig_conf");
00020     trigS1  = conf_.getParameter<std::vector<double> >("PosScint1");
00021     trigS2  = conf_.getParameter<std::vector<double> >("PosScint2");
00022     trigS3  = conf_.getParameter<std::vector<double> >("PosScint3");
00023     trigS4  = conf_.getParameter<std::vector<double> >("PosScint4");
00024 
00025     /*
00026     std::cout << "S1 = " << trigS1[0] << ", " <<  trigS1[1] << ", " <<trigS1[2]
00027               << "\nS2 = " << trigS2[0] << ", " <<  trigS2[1] << ", " <<trigS2[2]
00028               << "\nS3 = " << trigS3[0] << ", " <<  trigS3[1] << ", " <<trigS3[2]  
00029               << "\nS4 = " << trigS4[0] << ", " <<  trigS4[1] << ", " <<trigS4[2]  
00030               << std::endl;  
00031     */
00032   }
00033   
00034   bool CosmicTIFTrigFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00035   {
00036     
00037     
00038     edm::Handle<edm::HepMCProduct>HepMCEvt;
00039     iEvent.getByLabel("source","",HepMCEvt);
00040     const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
00041     
00042     bool hit1=false;
00043     bool hit2=false;
00044     bool hit3=false;
00045     bool hit4=false;
00046     
00047     
00048     for(HepMC::GenEvent::particle_const_iterator i=MCEvt->particles_begin(); i != MCEvt->particles_end();++i)
00049       {
00050         int myId = (*i)->pdg_id();
00051         if (abs(myId)==13)
00052           {
00053             
00054             // Get the muon position and momentum
00055             HepMC::GenVertex* pv = (*i)->production_vertex();
00056             HepMC::FourVector vertex = pv->position();
00057             
00058             HepMC::FourVector  momentum=(*i)->momentum();
00059 
00060             //std::cout << "\t vertex for cut = " << vertex << std::endl; 
00061             //std::cout << "\t momentum  = " << momentum << std::endl; 
00062             
00063             if(trigconf==1){
00064 
00065 /*
00066               HepMC::FourVector S1(350.,1600.,500.,0.);
00067               HepMC::FourVector S2(350.,-1600.,400.,0.);
00068               HepMC::FourVector S3(350.,1600.,1600.,0.);
00069 */
00070 /*
00071 //numbers taken from real data
00072              HepMC::FourVector S1(150.,1600.,550.,0.);
00073              HepMC::FourVector S2(400.,-1600.,50.,0.);
00074              HepMC::FourVector S3(0.,1600.,2400.,0.);
00075 */
00076               HepMC::FourVector S1(trigS1[0],trigS1[1],trigS1[2],0.);
00077               HepMC::FourVector S2(trigS2[0],trigS2[1],trigS2[2],0.);
00078               HepMC::FourVector S3(trigS3[0],trigS3[1],trigS3[2],0.);
00079               
00080               hit1=Sci_trig(vertex, momentum, S1);
00081               hit2=Sci_trig(vertex, momentum, S2);
00082               hit3=Sci_trig(vertex, momentum, S3);
00083               
00084               // trigger conditions
00085               
00086               if((hit1&&hit2) || (hit3&&hit2))
00087                 {
00088                   /*
00089                   cout << "\tGot a trigger in configuration A " << endl; 
00090                   if(hit1)cout << "hit1 " << endl;
00091                   if(hit2)cout << "hit2 " << endl;
00092                   if(hit3)cout << "hit3 " << endl;
00093                   */
00094                   trig1++;
00095                   return true;
00096                 }
00097             }else if(trigconf ==2) {
00098 
00099               /*
00100               HepMC::FourVector S1(350.,1600.,850.,0.);
00101               HepMC::FourVector S2(0.,-1550.,-1650.,0.);
00102               HepMC::FourVector S3(350.,1600.,2300.,0.);
00103               */
00104 
00105               HepMC::FourVector S1(trigS1[0],trigS1[1],trigS1[2],0.);
00106               HepMC::FourVector S2(trigS2[0],trigS2[1],trigS2[2],0.);
00107               HepMC::FourVector S3(trigS3[0],trigS3[1],trigS3[2],0.);
00108 
00109               
00110               hit1=Sci_trig(vertex, momentum, S1);
00111               hit2=Sci_trig(vertex, momentum, S2);
00112               hit3=Sci_trig(vertex, momentum, S3);
00113               
00114               // trigger conditions
00115               
00116               if((hit1&&hit2) || (hit3&&hit2))
00117                 {
00118                   /*
00119                   cout << "\tGot a trigger in configuration B " << endl; 
00120                   if(hit1)cout << "hit1 " << endl;
00121                   if(hit2)cout << "hit2 " << endl;
00122                   if(hit3)cout << "hit3 " << endl;
00123                   */
00124                   trig2++;
00125                   return true;
00126                 }
00127 
00128             }else if(trigconf ==3) {
00129 /*
00130               HepMC::FourVector S1(350.,1600.,850.,0.);
00131               HepMC::FourVector S2(350.,-1600.,400.,0.);
00132               HepMC::FourVector S3(350.,1600.,2300.,0.);
00133               HepMC::FourVector S4(0.,-1600.,-2000.,0.);
00134 */
00135 /*
00136 //new configuration from data
00137               HepMC::FourVector S1(150.,1600.,900.,0.);
00138               HepMC::FourVector S2(400.,-1600.,100.,0.);
00139               HepMC::FourVector S3(50.,1600.,2450.,0.);
00140               HepMC::FourVector S4(-250.,-1600.,-2050.,0.);
00141 */            
00142 
00143               HepMC::FourVector S1(trigS1[0],trigS1[1],trigS1[2],0.);
00144               HepMC::FourVector S2(trigS2[0],trigS2[1],trigS2[2],0.);
00145               HepMC::FourVector S3(trigS3[0],trigS3[1],trigS3[2],0.);
00146               HepMC::FourVector S4(trigS4[0],trigS4[1],trigS4[2],0.);
00147               
00148 
00149               /*              std::cout << "S1 = " << S1.x() << "," << S1.y() << ", " << S1.z()  
00150                         << "\nS2 = " << S2.x() << "," << S2.y() << ", " << S2.z()  
00151                         << "\nS3 = " << S3.x() << "," << S3.y() << ", " << S3.z()  
00152                         << "\nS4 = " << S4.x() << "," << S4.y() << ", " << S4.z() 
00153                         << std::endl;  
00154               */
00155 
00156               hit1=Sci_trig(vertex, momentum, S1);
00157               hit2=Sci_trig(vertex, momentum, S2);
00158               hit3=Sci_trig(vertex, momentum, S3);
00159               hit4=Sci_trig(vertex, momentum, S4);
00160               
00161               // trigger conditions
00162               if((hit1&&hit2) || (hit3&&hit2) || (hit1&&hit4) || (hit3&&hit4))
00163                 {
00164 
00165                   /*
00166                   cout << "\tGot a trigger in configuration C " << endl; 
00167                   if(hit1)cout << "hit1 " << endl;
00168                   if(hit2)cout << "hit2 " << endl;
00169                   if(hit3)cout << "hit3 " << endl;
00170                   if(hit4)cout << "hit4 " << endl;
00171                   */
00172 
00173                   trig3++;
00174                   return true;
00175                 }
00176             }
00177           }
00178       }
00179     
00180     return false;
00181   }
00182   
00183   bool CosmicTIFTrigFilter::Sci_trig(HepMC::FourVector vertex,  HepMC::FourVector momentum, HepMC::FourVector S)
00184   {
00185     float x0= vertex.x();
00186     float y0= vertex.y();
00187     float z0= vertex.z();
00188     float px0=momentum.x();
00189     float py0=momentum.y();
00190     float pz0=momentum.z();
00191     float Sx=S.x();
00192     float Sy=S.y();
00193     float Sz=S.z();
00194     
00195     //float ys=Sy;
00196     float zs=(Sy-y0)*(pz0/py0)+z0;
00197     //    float xs=((Sy-y0)*(pz0/py0)-z0)*(px0/pz0)+x0;
00198     float xs=(Sy-y0)*(px0/py0)+x0;
00199     
00200     //    std::cout << Sx << " " << Sz << " " << xs << " " << zs << std::endl;
00201     //std::cout << x0 << " " << z0 << " " << px0 << " " << py0 << " " << pz0 << endl;
00202     
00203     if((xs<Sx+500 && xs>Sx-500) && (zs<Sz+500 && zs>Sz-500) )
00204       {
00205         //std::cout << "PASSED" << std::endl;
00206         return true;
00207       }
00208     else
00209       {
00210         return false;
00211       }
00212     
00213   }
00214   
00215 }
00216