Go to the documentation of this file.00001 #include "Alignment/TrackerAlignment/plugins/AlignmentPrescaler.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "DataFormats/Common/interface/View.h"
00005 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00006 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00007 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00008 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00009 #include "Alignment/CommonAlignment/interface/Alignable.h"
00010 #include "Alignment/CommonAlignment/interface/Utilities.h"
00011 #include "Utilities/General/interface/ClassName.h"
00012
00013 #include "DataFormats/TrackReco/interface/Track.h"
00014 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfo.h"
00015
00016 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00017 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00018 #include "RecoTracker/TransientTrackingRecHit/interface/TSiStripRecHit2DLocalPos.h"
00019 #include "RecoTracker/TransientTrackingRecHit/interface/TSiPixelRecHit.h"
00020 #include "DataFormats/Alignment/interface/AlignmentClusterFlag.h"
00021 #include "DataFormats/Alignment/interface/AliClusterValueMap.h"
00022
00023
00024
00025 using namespace std;
00026
00027 AlignmentPrescaler::AlignmentPrescaler(const edm::ParameterSet &iConfig):
00028 src_(iConfig.getParameter<edm::InputTag>("src")),
00029 srcQualityMap_(iConfig.getParameter<edm::InputTag>("assomap")),
00030 prescfilename_(iConfig.getParameter<std::string>("PrescFileName")),
00031 presctreename_(iConfig.getParameter<std::string>("PrescTreeName"))
00032 {
00033
00034 produces<AliClusterValueMap>();
00035 produces<AliTrackTakenClusterValueMap>();
00036
00037 }
00038
00039 AlignmentPrescaler::~AlignmentPrescaler(){
00040
00041 }
00042
00043 void AlignmentPrescaler::beginJob(){
00044
00045 std::cout<<"in AlignmentPrescaler::beginJob"<<std::flush;
00046 fpresc_=new TFile(prescfilename_.c_str(),"READ");
00047 tpresc_=(TTree*)fpresc_->Get(presctreename_.c_str());
00048 tpresc_->BuildIndex("DetId");
00049 tpresc_->SetBranchStatus("*",0);
00050 tpresc_->SetBranchStatus("DetId",1);
00051 tpresc_->SetBranchStatus("PrescaleFactor",1);
00052 tpresc_->SetBranchStatus("PrescaleFactorOverlap",1);
00053 cout<<" Branches activated "<<std::flush;
00054 detid_=0;
00055 hitPrescFactor_=99.0;
00056 overlapPrescFactor_=88.0;
00057
00058 tpresc_->SetBranchAddress("DetId",&detid_);
00059 tpresc_->SetBranchAddress("PrescaleFactor",&hitPrescFactor_);
00060 tpresc_->SetBranchAddress("PrescaleFactorOverlap",&overlapPrescFactor_);
00061 cout<<" addressed "<<std::flush;
00062 myrand_=new TRandom3();
00063
00064 cout<<" ok "<<std::endl;
00065
00066 }
00067
00068 void AlignmentPrescaler::endJob( ){
00069
00070 delete tpresc_;
00071 fpresc_->Close();
00072 delete fpresc_;
00073 delete myrand_;
00074 }
00075
00076 void AlignmentPrescaler::produce(edm::Event &iEvent, const edm::EventSetup &iSetup){
00077
00078 edm::Handle<reco::TrackCollection> Tracks;
00079 iEvent.getByLabel(src_, Tracks);
00080
00081
00082 edm::Handle<AliClusterValueMap> hMap;
00083 iEvent.getByLabel(srcQualityMap_, hMap);
00084 AliClusterValueMap InValMap=*hMap;
00085
00086
00087 std::vector<int> trackflags(Tracks->size(),0);
00088
00089
00090
00091
00092
00093 for(std::vector<reco::Track>::const_iterator ittrk = Tracks->begin(), edtrk = Tracks->end(); ittrk != edtrk; ++ittrk){
00094
00095
00096 int nhit=0;
00097 int ntakenhits=0;
00098 bool firstTakenHit=false;
00099
00100 for (trackingRecHit_iterator ith = ittrk->recHitsBegin(), edh = ittrk->recHitsEnd(); ith != edh; ++ith) {
00101 const TrackingRecHit *hit = ith->get();
00102 if(! hit->isValid()){
00103 nhit++;
00104 continue;
00105 }
00106 uint32_t tmpdetid = hit->geographicalId().rawId();
00107 tpresc_->GetEntryWithIndex(tmpdetid);
00108
00109
00110
00111
00112 bool takeit=false;
00113 int subdetId=hit->geographicalId().subdetId();
00114
00115
00116
00117 bool isOverlapHit=false;
00118
00119
00120 const SiPixelRecHit* pixelhit= dynamic_cast<const SiPixelRecHit*>(hit);
00121 const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
00122 const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
00123
00124 AlignmentClusterFlag tmpflag(hit->geographicalId());
00125 int stripType=0;
00126 if(subdetId>2){
00127 const std::type_info &type = typeid(*hit);
00128 if (type == typeid(SiStripRecHit1D)) stripType=1;
00129 else if (type == typeid(SiStripRecHit2D)) stripType=2;
00130 else stripType=3;
00131
00132 if(stripType==1) {
00133
00134
00135 if(stripHit1D!=0){
00136 SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
00137 tmpflag=InValMap[stripclust];
00138 tmpflag.SetDetId(hit->geographicalId());
00139 if(tmpflag.isOverlap())isOverlapHit=true;
00140
00141
00142
00143
00144 }
00145 }
00146 else if (stripType==2) {
00147
00148 if(stripHit2D!=0){
00149 SiStripRecHit2D::ClusterRef stripclust(stripHit2D->cluster());
00150 tmpflag=InValMap[stripclust];
00151 tmpflag.SetDetId(hit->geographicalId());
00152 if(tmpflag.isOverlap())isOverlapHit=true;
00153
00154
00155
00156
00157 }
00158 }
00159 }
00160 else{
00161
00162 if(pixelhit!=0){
00163
00164 SiPixelClusterRefNew pixclust(pixelhit->cluster());
00165 tmpflag=InValMap[pixclust];
00166 tmpflag.SetDetId(hit->geographicalId());
00167 if(tmpflag.isOverlap())isOverlapHit=true;
00168 }
00169 }
00170
00171
00172 if( isOverlapHit ){
00173
00174 takeit=(float(myrand_->Rndm())<=overlapPrescFactor_);
00175 }
00176 if( !takeit ){
00177 float rr=float(myrand_->Rndm());
00178 takeit=(rr<=hitPrescFactor_);
00179 }
00180 if(takeit){
00181
00182 tmpflag.SetTakenFlag();
00183
00184 if(subdetId>2){
00185 if(stripType==1){
00186 SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
00187 InValMap[stripclust]=tmpflag;
00188 }
00189 else if(stripType==2){
00190 SiStripRecHit1D::ClusterRef stripclust(stripHit2D->cluster());
00191 InValMap[stripclust]=tmpflag;
00192 }
00193 else std::cout<<"Unknown type of strip hit"<<std::endl;
00194 }
00195 else{
00196 SiPixelClusterRefNew pixclust(pixelhit->cluster());
00197 InValMap[pixclust]=tmpflag;
00198 }
00199
00200 if(!firstTakenHit){
00201 firstTakenHit=true;
00202
00203
00204 }
00205 ntakenhits++;
00206 }
00207
00208
00209 nhit++;
00210
00211 }
00212 trackflags[ittrk-Tracks->begin()]=ntakenhits;
00213
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 std::auto_ptr<AliClusterValueMap> OutVM( new AliClusterValueMap);
00226 *OutVM=InValMap;
00227
00228 iEvent.put(OutVM);
00229
00230
00231 std::auto_ptr<AliTrackTakenClusterValueMap> trkVM( new AliTrackTakenClusterValueMap);
00232 AliTrackTakenClusterValueMap::Filler trkmapfiller(*trkVM);
00233 trkmapfiller.insert(Tracks,trackflags.begin(),trackflags.end() );
00234 trkmapfiller.fill();
00235 iEvent.put(trkVM);
00236
00237
00238 }
00239
00240
00241 int AlignmentPrescaler::layerFromId (const DetId& id, const TrackerTopology* tTopo) const
00242 {
00243 if ( uint32_t(id.subdetId())==PixelSubdetector::PixelBarrel ) {
00244
00245 return tTopo->pxbLayer(id);
00246 }
00247 else if ( uint32_t(id.subdetId())==PixelSubdetector::PixelEndcap ) {
00248
00249 return tTopo->pxfDisk(id) + (3*(tTopo->pxfSide(id)-1));
00250 }
00251 else if ( id.subdetId()==StripSubdetector::TIB ) {
00252
00253 return tTopo->tibLayer(id);
00254 }
00255 else if ( id.subdetId()==StripSubdetector::TOB ) {
00256
00257 return tTopo->tobLayer(id);
00258 }
00259 else if ( id.subdetId()==StripSubdetector::TEC ) {
00260
00261 return tTopo->tecWheel(id) + (9*(tTopo->pxfSide(id)-1));
00262 }
00263 else if ( id.subdetId()==StripSubdetector::TID ) {
00264
00265 return tTopo->tidWheel(id) + (3*(tTopo->tidSide(id)-1));
00266 }
00267 return -1;
00268
00269 }
00270
00271
00272 #include "FWCore/PluginManager/interface/ModuleDef.h"
00273 #include "FWCore/Framework/interface/MakerMacros.h"
00274 DEFINE_FWK_MODULE(AlignmentPrescaler);