CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SUSYBSMAnalysis/HSCP/src/BetaCalculatorRPC.cc

Go to the documentation of this file.
00001 #include "SUSYBSMAnalysis/HSCP/interface/BetaCalculatorRPC.h"
00002 
00003 BetaCalculatorRPC::BetaCalculatorRPC(const edm::ParameterSet& iConfig){
00004 
00005   rpcRecHitsLabel = iConfig.getParameter<edm::InputTag>("rpcRecHits");
00006 
00007 }
00008 
00009 void BetaCalculatorRPC::algo(std::vector<susybsm::RPCHit4D> HSCPRPCRecHits){
00010 
00011   int lastbx=-7;
00012   bool outOfTime = false;
00013   bool increasing = true;
00014   bool anydifferentzero = true;
00015   bool anydifferentone = true;
00016   
00017   //std::cout<<"Inside BetaCalculatorRPC \t \t Preliminar loop on the RPCHit4D!!!"<<std::endl;
00018 
00019   std::sort(HSCPRPCRecHits.begin(), HSCPRPCRecHits.end()); //Organizing them
00020 
00021   for(std::vector<susybsm::RPCHit4D>::iterator point = HSCPRPCRecHits.begin(); point < HSCPRPCRecHits.end(); ++point) {
00022     outOfTime |= (point->bx!=0); //condition 1: at least one measurement must have BX!=0
00023     increasing &= (point->bx>=lastbx); //condition 2: BX must be increase when going inside-out.
00024     anydifferentzero &= (!point->bx==0); //to check one knee withoutzeros
00025     anydifferentone &= (!point->bx==1); //to check one knee withoutones
00026     lastbx = point->bx;
00027     //float r=point->gp.mag();
00028     //std::cout<<"Inside BetaCalculatorRPC \t \t  r="<<r<<" phi="<<point->gp.phi()<<" eta="<<point->gp.eta()<<" bx="<<point->bx<<" outOfTime"<<outOfTime<<" increasing"<<increasing<<" anydifferentzero"<<anydifferentzero<<std::endl;
00029   }
00030   
00031   bool Candidate = (outOfTime&&increasing);
00032 
00033   // here we should get some pattern-based estimate
00034 
00035   //Counting knees
00036 
00037   float delay=12.5;
00038   lastbx=-7; //already declared for the preliminar loop
00039   int knees=0;
00040   float maginknee = 0;
00041   float maginfirstknee = 0;
00042   for(std::vector<susybsm::RPCHit4D>::iterator point = HSCPRPCRecHits.begin(); point < HSCPRPCRecHits.end(); ++point) {
00043     if(lastbx==-7){
00044       maginfirstknee = point->gp.mag();
00045     }else if((lastbx!=point->bx)){
00046       //std::cout<<"Inside BetaCalculatorRPC \t \t \t one knee between"<<lastbx<<point->bx<<std::endl;
00047       maginknee=point->gp.mag();
00048       knees++;
00049     }
00050     lastbx=point->bx;
00051   }
00052       
00053   if(knees==0){
00054     //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t knees="<<knees<<std::endl;
00055     betavalue=maginfirstknee/(25.-delay+maginfirstknee/30.)/30.;
00056   }else if(knees==1){
00057     float betavalue1=0;
00058     float betavalue2=0;
00059     //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t knees="<<knees<<std::endl;
00060     //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t anydifferentzero="<<anydifferentzero<<" anydifferentone="<<anydifferentone<<std::endl;
00061     if(!anydifferentzero){
00062       betavalue=maginknee/(25-delay+maginknee/30.)/30.;
00063     }else if(!anydifferentone){//i.e non zeros and no ones
00064       betavalue=maginknee/(50-delay+maginknee/30.)/30.;
00065     }else{
00066       betavalue1=maginknee/(25-delay+maginknee/30.)/30.;
00067       float dr =(maginknee-maginfirstknee);
00068       betavalue2 = dr/(25.-delay+dr/30.);
00069       //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t \t not zero neither ones betavalue1="<<betavalue1<<" betavalue2="<<betavalue2<<std::endl;
00070       betavalue = (betavalue1 + betavalue2)*0.5;
00071     }
00072   }else if(knees==2){
00073     //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t knees="<<knees<<std::endl;
00074     knees=0;
00075     float betavalue1=0;
00076     float betavalue2=0;
00077     lastbx=-7;
00078     //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t looping again on the RPCRecHits4D="<<knees<<std::endl;
00079     for(std::vector<susybsm::RPCHit4D>::iterator point = HSCPRPCRecHits.begin(); point < HSCPRPCRecHits.end(); ++point) {
00080       if(lastbx==-7){
00081         maginfirstknee = point->gp.mag();
00082       }else if((lastbx!=point->bx)){
00083         //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t \t one knee between"<<lastbx<<point->bx<<std::endl;
00084         knees++;
00085         if(knees==2){
00086           float maginsecondknee=point->gp.mag();
00087           betavalue1=maginknee/(25-delay+maginknee/30.)/30.;
00088           float dr =(maginknee-maginsecondknee);
00089           betavalue2 = dr/(25.+dr/30.);
00090           //std::cout<<"Inside BetaCalculatorRPC \t \t \t \t \t betavalue1="<<betavalue1<<" betavalue2="<<betavalue2<<std::endl;
00091         }
00092       }
00093       lastbx=point->bx;
00094     }
00095     betavalue = (betavalue1 + betavalue2)*0.5;
00096   }
00097   
00098   if(Candidate){
00099     //std::cout<<"Inside BetaCalculatorRPC \t \t \t yes! We found an HSCPs let's try to estimate beta"<<std::endl;
00100   }else{
00101     //std::cout<<"Inside BetaCalculatorRPC \t \t \t seems that there is no RPC HSCP Candidate in the set of RPC4DHit"<<std::endl;
00102     betavalue = 1.;
00103   }
00104   
00105   if(HSCPRPCRecHits.size()==0){
00106     //std::cout<<"Inside BetaCalculatorRPC \t WARINNG EMPTY RPC4DRecHits CONTAINER!!!"<<std::endl;
00107     betavalue = 1.;
00108   }
00109 }
00110 
00111 
00112 
00113 void BetaCalculatorRPC::addInfoToCandidate(HSCParticle& candidate, const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00114 
00115   edm::ESHandle<RPCGeometry> rpcGeo;
00116   iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00117 
00118   edm::Handle<RPCRecHitCollection> rpcHits;
00119   iEvent.getByLabel(rpcRecHitsLabel,rpcHits);
00120 
00121 
00122   // here we do basically as in RPCHSCPCANDIDATE.cc, but just for the hits on the muon of interest
00123   RPCBetaMeasurement result;
00124   std::vector<RPCHit4D> hits;
00125   // so, loop on the RPC hits of the muon
00126   trackingRecHit_iterator start,stop;
00127   reco::Track track;
00128 
00129   if(      candidate.hasMuonRef() && candidate.muonRef()->combinedMuon()  .isNonnull()){ 
00130      start = candidate.muonRef()->combinedMuon()->recHitsBegin();
00131      stop  = candidate.muonRef()->combinedMuon()->recHitsEnd();    
00132   }else if(candidate.hasMuonRef() && candidate.muonRef()->standAloneMuon().isNonnull()){ track=*(candidate.muonRef()->standAloneMuon());
00133      start = candidate.muonRef()->standAloneMuon()->recHitsBegin();
00134      stop  = candidate.muonRef()->standAloneMuon()->recHitsEnd();  
00135   }else return;
00136 /*
00137   if(candidate.hasMuonCombinedTrack()) {
00138     start = candidate.combinedTrack().recHitsBegin();
00139     stop  = candidate.combinedTrack().recHitsEnd();
00140   } else if(candidate.hasMuonStaTrack()) {
00141     start = candidate.staTrack().recHitsBegin();
00142     stop  = candidate.staTrack().recHitsEnd();
00143   } else return; 
00144 */
00145   for(trackingRecHit_iterator recHit = start; recHit != stop; ++recHit) {
00146     if ( (*recHit)->geographicalId().subdetId() != MuonSubdetId::RPC ) continue;
00147     if ( (*recHit)->geographicalId().det() != DetId::Muon  ) continue;
00148     if (!(*recHit)->isValid()) continue; //Is Valid?
00149        
00150     RPCDetId rollId = (RPCDetId)(*recHit)->geographicalId();
00151 
00152     typedef std::pair<RPCRecHitCollection::const_iterator, RPCRecHitCollection::const_iterator> rangeRecHits;
00153     rangeRecHits recHitCollection =  rpcHits->get(rollId);
00154     RPCRecHitCollection::const_iterator recHitC;
00155     int size = 0;
00156     int clusterS=0;
00157     for(recHitC = recHitCollection.first; recHitC != recHitCollection.second ; recHitC++) {
00158       clusterS=(*recHitC).clusterSize();
00159       RPCDetId rollId = (RPCDetId)(*recHitC).geographicalId();
00160 //      std::cout<<"\t \t \t \t"<<rollId<<" bx "<<(*recHitC).BunchX()<<std::endl;
00161       size++;
00162     }
00163     if(size>1) continue; //Is the only RecHit in this roll.?                                                                                                         
00164     if(clusterS>4) continue; //Is the Cluster Size 5 or bigger?    
00165     
00166     LocalPoint recHitPos=(*recHit)->localPosition();
00167     const RPCRoll* rollasociated = rpcGeo->roll(rollId);
00168     const BoundPlane & RPCSurface = rollasociated->surface();
00169     
00170     RPCHit4D ThisHit;
00171     ThisHit.bx = ((RPCRecHit*)(&(**recHit)))->BunchX();
00172     ThisHit.gp = RPCSurface.toGlobal(recHitPos);
00173     ThisHit.id = (RPCDetId)(*recHit)->geographicalId().rawId();
00174     hits.push_back(ThisHit);
00175     
00176   }
00177   // here we go on with the RPC procedure 
00178   std::sort(hits.begin(), hits.end());
00179   int lastbx=-7;
00180   bool increasing = true;
00181   bool outOfTime = false;
00182   for(std::vector<RPCHit4D>::iterator point = hits.begin(); point < hits.end(); ++point) {
00183     outOfTime |= (point->bx!=0); //condition 1: at least one measurement must have BX!=0
00184     increasing &= (point->bx>=lastbx); //condition 2: BX must increase when going inside-out.
00185     lastbx = point->bx;
00186   }
00187   result.isCandidate = (outOfTime&&increasing);
00188  
00189   //result.beta = 1; // here we should get some pattern-based estimate
00190   algo(hits);
00191   result.beta = beta();
00192   candidate.setRpc(result);
00193 }
00194 
00195