CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/L1Trigger/DTTrigger/src/DTTrigTest.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00015 //
00016 //--------------------------------------------------
00017 
00018 // This class's header
00019 #include "L1Trigger/DTTrigger/interface/DTTrigTest.h"
00020 
00021 // Framework related classes
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 
00025 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManager.h"
00026 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigManagerRcd.h"
00027 
00028 // Trigger and DataFormats headers
00029 #include "L1Trigger/DTSectorCollector/interface/DTSectCollPhSegm.h"
00030 #include "L1Trigger/DTSectorCollector/interface/DTSectCollThSegm.h"
00031 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00032 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00033 
00034 // ROOT headers 
00035 #include "TROOT.h"
00036 #include "TTree.h"
00037 #include "TFile.h"
00038 
00039 // Collaborating classes
00040 #include "DataFormats/Math/interface/LorentzVector.h"
00041 #include <CLHEP/Vector/LorentzVector.h>
00042 
00043 // C++ headers
00044 #include <iostream>
00045 #include <math.h>
00046 #include<time.h>
00047 
00048 using namespace std;
00049 using namespace edm;
00050 
00051 const double DTTrigTest::my_TtoTDC = 32./25.;
00052 
00053 DTTrigTest::DTTrigTest(const ParameterSet& pset): my_trig(0) { 
00054 
00055   my_debug= pset.getUntrackedParameter<bool>("debug");
00056   string outputfile = pset.getUntrackedParameter<string>("outputFileName");
00057   if (my_debug) 
00058     cout << "[DTTrigTest] Creating rootfile " <<  outputfile <<endl;
00059   my_rootfile = new TFile(outputfile.c_str(),"RECREATE");
00060   my_tree = new TTree("h1","GMT",0);
00061   my_params = pset;
00062   if (my_debug) cout << "[DTTrigTest] Constructor executed!!!" << endl;
00063 
00064 
00065 }
00066 
00067 DTTrigTest::~DTTrigTest(){ 
00068 
00069   if (my_trig != 0) delete my_trig;
00070   delete my_rootfile;
00071   if (my_debug) 
00072     cout << "[DTTrigTest] Destructor executed!!!" << endl;
00073 
00074 }
00075 
00076 void DTTrigTest::endJob(){
00077 
00078   if (my_debug) 
00079     cout << "[DTTrigTest] Writing Tree and Closing File" << endl;
00080   my_tree->Write();
00081   delete my_tree;
00082   my_rootfile->Close();
00083 
00084 }
00085 
00086 //void DTTrigTest::beginJob(const EventSetup & iEventSetup){   
00087 void DTTrigTest::beginJob(){   
00088   // get DTConfigManager
00089   // ESHandle< DTConfigManager > confManager ;
00090   // iEventSetup.get< DTConfigManagerRcd >().get( confManager ) ;
00091 
00092   //for testing purpose....
00093   //DTBtiId btiid(1,1,1,1,1);
00094   //confManager->getDTConfigBti(btiid)->print();
00095 
00096 //   my_trig = new DTTrig(my_params);
00097 
00098 //   my_trig->createTUs(iEventSetup);
00099 //   if (my_debug) 
00100 //     cout << "[DTTrigTest] TU's Created" << endl;
00101   
00102   // BOOKING of the tree's varables
00103   // GENERAL block branches
00104   my_tree->Branch("Run",&runn,"Run/I");
00105   my_tree->Branch("Event",&eventn,"Event/I");
00106   my_tree->Branch("Weight",&weight,"Weight/F");  
00107   // GEANT block branches
00108   my_tree->Branch("Ngen",&ngen,"Ngen/I");
00109   my_tree->Branch("Pxgen",pxgen,"Pxgen[Ngen]/F");
00110   my_tree->Branch("Pygen",pygen,"Pygen[Ngen]/F");
00111   my_tree->Branch("Pzgen",pzgen,"Pzgen[Ngen]/F");
00112   my_tree->Branch("Ptgen",ptgen,"Ptgen[Ngen]/F");
00113   my_tree->Branch("Etagen",etagen,"Etagen[Ngen]/F");
00114   my_tree->Branch("Phigen",phigen,"Phigen[Ngen]/F");
00115   my_tree->Branch("Chagen",chagen,"Chagen[Ngen]/I");
00116   my_tree->Branch("Vxgen",vxgen,"Vxgen[Ngen]/F");
00117   my_tree->Branch("Vygen",vygen,"Vygen[Ngen]/F");
00118   my_tree->Branch("Vzgen",vzgen,"Vzgen[Ngen]/F");
00119   // L1MuDTBtiChipS block
00120   my_tree->Branch("Nbti",&nbti,"Nbti/I");
00121   my_tree->Branch("bwh",bwh,"bwh[Nbti]/I"); 
00122   my_tree->Branch("bstat",bstat,"bstat[Nbti]/I");    
00123   my_tree->Branch("bsect",bsect,"bsect[Nbti]/I");  
00124   my_tree->Branch("bsl",bsl,"bsl[Nbti]/I");
00125   my_tree->Branch("bnum",bnum,"bnum[Nbti]/I");
00126   my_tree->Branch("bbx",bbx,"bbx[Nbti]/I");
00127   my_tree->Branch("bcod",bcod,"bcod[Nbti]/I");
00128   my_tree->Branch("bk",bk,"bk[Nbti]/I");
00129   my_tree->Branch("bx",bx,"bx[Nbti]/I");
00130   my_tree->Branch("bposx",bposx,"bposx[Nbti]/F");
00131   my_tree->Branch("bposy",bposy,"bposy[Nbti]/F");
00132   my_tree->Branch("bposz",bposz,"bposz[Nbti]/F");
00133   my_tree->Branch("bdirx",bdirx,"bdirx[Nbti]/F");
00134   my_tree->Branch("bdiry",bdiry,"bdiry[Nbti]/F");
00135   my_tree->Branch("bdirz",bdirz,"bdirz[Nbti]/F");
00136   // L1MuDTTracoChipS block
00137   my_tree->Branch("Ntraco",&ntraco,"Ntraco/I");
00138   my_tree->Branch("twh",twh,"twh[Ntraco]/I"); 
00139   my_tree->Branch("tstat",tstat,"tstat[Ntraco]/I");    
00140   my_tree->Branch("tsect",tsect,"tsect[Ntraco]/I");  
00141   my_tree->Branch("tnum",tnum,"tnum[Ntraco]/I"); 
00142   my_tree->Branch("tbx",tbx,"tbx[Ntraco]/I");
00143   my_tree->Branch("tcod",tcod,"tcod[Ntraco]/I");
00144   my_tree->Branch("tk",tk,"tk[Ntraco]/I");
00145   my_tree->Branch("tx",tx,"tx[Ntraco]/I");
00146   my_tree->Branch("tposx",tposx,"tposx[Ntraco]/F");
00147   my_tree->Branch("tposy",tposy,"tposy[Ntraco]/F");
00148   my_tree->Branch("tposz",tposz,"tposz[Ntraco]/F");
00149   my_tree->Branch("tdirx",tdirx,"tdirx[Ntraco]/F");
00150   my_tree->Branch("tdiry",tdiry,"tdiry[Ntraco]/F");
00151   my_tree->Branch("tdirz",tdirz,"tdirz[Ntraco]/F");
00152   // TSPHI block
00153   my_tree->Branch("Ntsphi",&ntsphi,"Ntsphi/I");
00154   my_tree->Branch("swh",swh,"swh[Ntsphi]/I"); 
00155   my_tree->Branch("sstat",sstat,"sstat[Ntsphi]/I");    
00156   my_tree->Branch("ssect",ssect,"ssect[Ntsphi]/I");  
00157   my_tree->Branch("sbx",sbx,"sbx[Ntsphi]/I");
00158   my_tree->Branch("scod",scod,"scod[Ntsphi]/I");
00159   my_tree->Branch("sphi",sphi,"sphi[Ntsphi]/I");
00160   my_tree->Branch("sphib",sphib,"sphib[Ntsphi]/I");
00161   my_tree->Branch("sposx",sposx,"sposx[Ntsphi]/F");
00162   my_tree->Branch("sposy",sposy,"sposy[Ntsphi]/F");
00163   my_tree->Branch("sposz",sposz,"sposz[Ntsphi]/F");
00164   my_tree->Branch("sdirx",sdirx,"sdirx[Ntsphi]/F");
00165   my_tree->Branch("sdiry",sdiry,"sdiry[Ntsphi]/F");
00166   my_tree->Branch("sdirz",sdirz,"sdirz[Ntsphi]/F");
00167   // TSTHETA block
00168   my_tree->Branch("Ntstheta",&ntstheta,"Ntstheta/I");
00169   my_tree->Branch("thwh",thwh,"thwh[Ntstheta]/I"); 
00170   my_tree->Branch("thstat",thstat,"thstat[Ntstheta]/I");    
00171   my_tree->Branch("thsect",thsect,"thsect[Ntstheta]/I");  
00172   my_tree->Branch("thbx",thbx,"thbx[Ntstheta]/I");
00173   my_tree->Branch("thcode",thcode,"thcode[Ntstheta][7]/I");
00174   my_tree->Branch("thpos",thpos,"thpos[Ntstheta][7]/I");
00175   my_tree->Branch("thqual",thqual,"thqual[Ntstheta][7]/I");
00176   // SC PHI block
00177   my_tree->Branch("Nscphi",&nscphi,"Nscphi/I");
00178   my_tree->Branch("scphwh",scphwh,"scphwh[Nscphi]/I"); 
00179   my_tree->Branch("scphstat",scphstat,"scphstat[Nscphi]/I");    
00180   my_tree->Branch("scphsect",scphsect,"scphsect[Nscphi]/I");  
00181   my_tree->Branch("scphbx",scphbx,"scphbx[Nscphi]/I");
00182   my_tree->Branch("scphcod",scphcod,"scphcod[Nscphi]/I");
00183   my_tree->Branch("scphphi",scphphi,"scphphi[Nscphi]/I");
00184   my_tree->Branch("scphphib",scphphib,"scphphib[Nscphi]/I");
00185   my_tree->Branch("scphposx",scphposx,"scphposx[Nscphi]/F");
00186   my_tree->Branch("scphposy",scphposy,"scphposy[Nscphi]/F");
00187   my_tree->Branch("scphposz",scphposz,"scphposz[Nscphi]/F");
00188   my_tree->Branch("scphdirx",scphdirx,"scphdirx[Nscphi]/F");
00189   my_tree->Branch("scphdiry",scphdiry,"scphdiry[Nscphi]/F");
00190   my_tree->Branch("scphdirz",scphdirz,"scphdirz[Nscphi]/F");
00191   // SC THETA block
00192   my_tree->Branch("Nsctheta",&nsctheta,"Nsctheta/I");
00193   my_tree->Branch("scthwh",scthwh,"scthwh[Nsctheta]/I"); 
00194   my_tree->Branch("scthstat",scthstat,"scthstat[Nsctheta]/I");    
00195   my_tree->Branch("scthsect",scthsect,"scthsect[Nsctheta]/I");  
00196   my_tree->Branch("scthbx",scthbx,"scthbx[Nsctheta]/I");
00197   my_tree->Branch("scthcode",scthcode,"scthcode[Nsctheta][7]/I");
00198   my_tree->Branch("scthpos",scthpos,"scthpos[Nsctheta][7]/I");
00199   my_tree->Branch("scthqual",scthqual,"scthqual[Nsctheta][7]/I");
00200 
00201 }
00202 
00203 void DTTrigTest::beginRun(const edm::Run& iRun, const edm::EventSetup& iEventSetup) {
00204 
00205   if (!my_trig) {
00206     my_trig = new DTTrig(my_params);
00207     my_trig->createTUs(iEventSetup);
00208     if (my_debug)
00209       cout << "[DTTrigTest] TU's Created" << endl;
00210   }
00211 
00212 }
00213 
00214 
00215 
00216 void DTTrigTest::analyze(const Event & iEvent, const EventSetup& iEventSetup){
00217   
00218   const int MAXGEN  = 10;
00219   const float ptcut  = 1.0;
00220   const float etacut = 2.4;
00221   my_trig->triggerReco(iEvent,iEventSetup);
00222   if (my_debug)
00223     cout << "[DTTrigTest] Trigger algorithm executed for run " << iEvent.id().run() 
00224          <<" event " << iEvent.id().event() << endl;
00225   
00226   // GENERAL Block
00227   runn   = iEvent.id().run();
00228   eventn = iEvent.id().event();
00229   weight = 1; // FIXME what to do with this varable?
00230   
00231   // GEANT Block
00232   Handle<vector<SimTrack> > MyTracks;
00233   Handle<vector<SimVertex> > MyVertexes;
00234   iEvent.getByLabel("g4SimHits",MyTracks);
00235   iEvent.getByLabel("g4SimHits",MyVertexes);
00236   vector<SimTrack>::const_iterator itrack;
00237   ngen=0;
00238   if (my_debug) 
00239     cout  << "[DTTrigTest] Tracks found in the detector (not only muons) " << MyTracks->size() <<endl;
00240   
00241   for (itrack=MyTracks->begin(); itrack!=MyTracks->end(); itrack++){
00242     if ( abs(itrack->type())==13){
00243       math::XYZTLorentzVectorD momentum = itrack->momentum();
00244       float pt  = momentum.Pt();
00245       float eta = momentum.eta();
00246       if ( pt>ptcut && fabs(eta)<etacut ){
00247         float phi = momentum.phi();
00248         int charge = static_cast<int> (-itrack->type()/13); //static_cast<int> (itrack->charge());
00249         if ( phi<0 ) phi = 2*M_PI + phi;
00250         int vtxindex = itrack->vertIndex();
00251         float gvx=0,gvy=0,gvz=0;
00252         if (vtxindex >-1){
00253           gvx=MyVertexes->at(vtxindex).position().x();
00254           gvy=MyVertexes->at(vtxindex).position().y();
00255           gvz=MyVertexes->at(vtxindex).position().z();
00256         }
00257         if ( ngen < MAXGEN ) {
00258           pxgen[ngen]=momentum.x();
00259           pygen[ngen]=momentum.y();
00260           pzgen[ngen]=momentum.z();
00261           ptgen[ngen]=pt;
00262           etagen[ngen]=eta;
00263           phigen[ngen]=phi;
00264           chagen[ngen]=charge;
00265           vxgen[ngen]=gvx;
00266           vygen[ngen]=gvy;
00267           vzgen[ngen]=gvz;
00268           ngen++;
00269         }
00270       }
00271     }
00272   }
00273   
00274   // L1 Local Trigger Block
00275   // BTI
00276   vector<DTBtiTrigData> btitrigs = my_trig->BtiTrigs();
00277   vector<DTBtiTrigData>::const_iterator pbti;
00278   int ibti = 0;
00279   if (my_debug)
00280     cout << "[DTTrigTest] " << btitrigs.size() << " BTI triggers found" << endl;
00281   
00282   for ( pbti = btitrigs.begin(); pbti != btitrigs.end(); pbti++ ) {
00283     if ( ibti < 100 ) {
00284       bwh[ibti]=pbti->wheel();
00285       bstat[ibti]=pbti->station();
00286       bsect[ibti]=pbti->sector();
00287       bsl[ibti]=pbti->btiSL();
00288       bnum[ibti]=pbti->btiNumber();
00289       bbx[ibti]=pbti->step();
00290       bcod[ibti]=pbti->code();
00291       bk[ibti]=pbti->K();
00292       bx[ibti]=pbti->X();
00293       GlobalPoint pos = my_trig->CMSPosition(&(*pbti));
00294       GlobalVector dir = my_trig->CMSDirection(&(*pbti));
00295       bposx[ibti] = pos.x();
00296       bposy[ibti] = pos.y();
00297       bposz[ibti] = pos.z();
00298       bdirx[ibti] = dir.x();
00299       bdiry[ibti] = dir.y();
00300       bdirz[ibti] = dir.z();
00301       ibti++;
00302     }
00303   } 
00304   nbti = ibti;
00305   
00306   //TRACO
00307   vector<DTTracoTrigData> tracotrigs = my_trig->TracoTrigs();
00308   vector<DTTracoTrigData>::const_iterator ptc;
00309   int itraco = 0;
00310   if (my_debug)
00311     cout << "[DTTrigTest] " << tracotrigs.size() << " TRACO triggers found" << endl;
00312   
00313   for (ptc=tracotrigs.begin(); ptc!=tracotrigs.end(); ptc++) {
00314     if (itraco<80) {
00315       twh[itraco]=ptc->wheel();
00316       tstat[itraco]=ptc->station();
00317       tsect[itraco]=ptc->sector();
00318       tnum[itraco]=ptc->tracoNumber();
00319       tbx[itraco]=ptc->step();
00320       tcod[itraco]=ptc->code();
00321       tk[itraco]=ptc->K();
00322       tx[itraco]=ptc->X();
00323       GlobalPoint pos = my_trig->CMSPosition(&(*ptc));
00324       GlobalVector dir = my_trig->CMSDirection(&(*ptc));
00325       tposx[itraco] = pos.x();
00326       tposy[itraco] = pos.y();
00327       tposz[itraco] = pos.z();
00328       tdirx[itraco] = dir.x();
00329       tdiry[itraco] = dir.y();
00330       tdirz[itraco] = dir.z();
00331       itraco++;
00332     }
00333   }
00334   ntraco = itraco;
00335   
00336   //TSPHI
00337   vector<DTChambPhSegm> tsphtrigs = my_trig->TSPhTrigs();
00338   vector<DTChambPhSegm>::const_iterator ptsph;
00339   int itsphi = 0; 
00340   if (my_debug ) 
00341     cout << "[DTTrigTest] " << tsphtrigs.size() << " TSPhi triggers found" << endl;
00342   
00343   for (ptsph=tsphtrigs.begin(); ptsph!=tsphtrigs.end(); ptsph++) {
00344     if (itsphi<40 ) {
00345       swh[itsphi] = ptsph->wheel();
00346       sstat[itsphi] = ptsph->station();
00347       ssect[itsphi] = ptsph->sector();
00348       sbx[itsphi] = ptsph->step();
00349       scod[itsphi] = ptsph->oldCode();
00350       sphi[itsphi] = ptsph->phi();
00351       sphib[itsphi] = ptsph->phiB();
00352       GlobalPoint pos = my_trig->CMSPosition(&(*ptsph)); 
00353       GlobalVector dir = my_trig->CMSDirection(&(*ptsph));
00354       sposx[itsphi] = pos.x();
00355       sposy[itsphi] = pos.y();
00356       sposz[itsphi] = pos.z();
00357       sdirx[itsphi] = dir.x();
00358       sdiry[itsphi] = dir.y();
00359       sdirz[itsphi] = dir.z();
00360       itsphi++;
00361     }
00362   }
00363   ntsphi = itsphi;
00364   
00365   //TSTHETA
00366   vector<DTChambThSegm> tsthtrigs = my_trig->TSThTrigs();
00367   vector<DTChambThSegm>::const_iterator ptsth;
00368   int itstheta = 0; 
00369   if (my_debug) 
00370     cout << "[DTTrigTest] " << tsthtrigs.size() << " TSTheta triggers found" << endl;
00371   
00372   for (ptsth=tsthtrigs.begin(); ptsth!=tsthtrigs.end(); ptsth++) {
00373     if (itstheta<40 ) {
00374       thwh[itstheta] = ptsth->ChamberId().wheel();
00375       thstat[itstheta] = ptsth->ChamberId().station();
00376       thsect[itstheta] = ptsth->ChamberId().sector();
00377       thbx[itstheta] = ptsth->step();
00378       for(int i=0;i<7;i++) {
00379           thcode[itstheta][i] = ptsth->code(i);
00380           thpos[itstheta][i] = ptsth->position(i);
00381           thqual[itstheta][i] = ptsth->quality(i);
00382       }
00383       itstheta++;
00384     }
00385   }
00386   ntstheta = itstheta;
00387   
00388   //SCPHI
00389   vector<DTSectCollPhSegm> scphtrigs = my_trig->SCPhTrigs();
00390   vector<DTSectCollPhSegm>::const_iterator pscph;
00391   int iscphi = 0; 
00392   if (my_debug ) 
00393     cout << "[DTTrigTest] " << scphtrigs.size() << " SectCollPhi triggers found" << endl;
00394   
00395   for (pscph=scphtrigs.begin(); pscph!=scphtrigs.end(); pscph++) {
00396     if (iscphi<40 ) {
00397       const DTChambPhSegm *seg = (*pscph).tsPhiTrig();
00398       scphwh[iscphi] = pscph->wheel();
00399       scphstat[iscphi] = pscph->station();
00400       scphsect[iscphi] = pscph->sector();
00401       scphbx[iscphi] = pscph->step();
00402       scphcod[iscphi] = pscph->oldCode();
00403       scphphi[iscphi] = pscph->phi();
00404       scphphib[iscphi] = pscph->phiB();
00405       GlobalPoint pos = my_trig->CMSPosition(seg); 
00406       GlobalVector dir = my_trig->CMSDirection(seg);
00407       scphposx[iscphi] = pos.x();
00408       scphposy[iscphi] = pos.y();
00409       scphposz[iscphi] = pos.z();
00410       scphdirx[iscphi] = dir.x();
00411       scphdiry[iscphi] = dir.y();
00412       scphdirz[iscphi] = dir.z();
00413       iscphi++;
00414     }
00415   }
00416   nscphi = iscphi;
00417   
00418   //SCTHETA
00419   vector<DTSectCollThSegm> scthtrigs = my_trig->SCThTrigs();
00420   vector<DTSectCollThSegm>::const_iterator pscth;
00421   int isctheta = 0; 
00422   if (my_debug) 
00423     cout << "[DTTrigTest] " << scthtrigs.size() << " SectCollTheta triggers found" << endl;
00424   
00425   for (pscth=scthtrigs.begin(); pscth!=scthtrigs.end(); pscth++) {
00426     if (isctheta<40 ) {
00427       scthwh[isctheta] = pscth->ChamberId().wheel();
00428       scthstat[isctheta] = pscth->ChamberId().station();
00429       scthsect[isctheta] = pscth->ChamberId().sector();
00430       scthbx[isctheta] = pscth->step();
00431       for(int i=0;i<7;i++) {
00432           scthcode[isctheta][i] = pscth->code(i);
00433           scthpos[isctheta][i] = pscth->position(i);
00434           scthqual[isctheta][i] = pscth->quality(i);
00435       }
00436       isctheta++;
00437     }
00438   }
00439   nsctheta = isctheta;
00440   
00441   //Fill the tree
00442   my_tree->Fill();
00443 
00444 }