Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019 #include <memory>
00020 #include "DataFormats/Common/interface/ValueMap.h"
00021
00022 #include "RecoTracker/DeDx/plugins/DeDxEstimatorProducerPixelTripplet.h"
00023 #include "DataFormats/TrackReco/interface/DeDxData.h"
00024 #include "DataFormats/TrackReco/interface/TrackDeDxHits.h"
00025 #include "DataFormats/TrackReco/interface/DeDxHit.h"
00026 #include "DataFormats/TrackReco/interface/Track.h"
00027 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00028
00029 #include "RecoTracker/DeDx/interface/GenericAverageDeDxEstimator.h"
00030 #include "RecoTracker/DeDx/interface/TruncatedAverageDeDxEstimator.h"
00031 #include "RecoTracker/DeDx/interface/MedianDeDxEstimator.h"
00032 #include "RecoTracker/DeDx/interface/UnbinnedFitDeDxEstimator.h"
00033
00034 #include "FWCore/Framework/interface/ESHandle.h"
00035 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00036 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00037
00038 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00039 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00040
00041
00042 using namespace reco;
00043 using namespace std;
00044 using namespace edm;
00045
00046 DeDxEstimatorProducerPixelTripplet::DeDxEstimatorProducerPixelTripplet(const edm::ParameterSet& iConfig)
00047 {
00048
00049 produces<ValueMap<DeDxData> >();
00050
00051
00052 string estimatorName = iConfig.getParameter<string>("estimator");
00053 if(estimatorName == "median") m_estimator = new MedianDeDxEstimator(-2.);
00054 if(estimatorName == "generic") m_estimator = new GenericAverageDeDxEstimator (iConfig.getParameter<double>("exponent"));
00055 if(estimatorName == "truncated") m_estimator = new TruncatedAverageDeDxEstimator(iConfig.getParameter<double>("fraction"));
00056 if(estimatorName == "unbinnedFit") m_estimator = new UnbinnedFitDeDxEstimator();
00057
00058 MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips" , 255);
00059 MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits" , 4);
00060
00061 m_tracksTag = iConfig.getParameter<edm::InputTag>("tracks");
00062 m_trajTrackAssociationTag = iConfig.getParameter<edm::InputTag>("trajectoryTrackAssociation");
00063
00064 usePixel = iConfig.getParameter<bool>("UsePixel");
00065 useStrip = iConfig.getParameter<bool>("UseStrip");
00066 MeVperADCPixel = iConfig.getParameter<double>("MeVperADCPixel");
00067 MeVperADCStrip = iConfig.getParameter<double>("MeVperADCStrip");
00068
00069 shapetest = iConfig.getParameter<bool>("ShapeTest");
00070 useCalibration = iConfig.getParameter<bool>("UseCalibration");
00071 m_calibrationPath = iConfig.getParameter<string>("calibrationPath");
00072
00073 if(!usePixel && !useStrip)
00074 edm::LogWarning("DeDxHitsProducer") << "Pixel Hits AND Strip Hits will not be used to estimate dEdx --> BUG, Please Update the config file";
00075 }
00076
00077
00078 DeDxEstimatorProducerPixelTripplet::~DeDxEstimatorProducerPixelTripplet()
00079 {
00080 delete m_estimator;
00081 }
00082
00083
00084
00085
00086 void DeDxEstimatorProducerPixelTripplet::beginRun(edm::Run const& run, const edm::EventSetup& iSetup)
00087 {
00088 if(MODsColl.size()!=0)return;
00089
00090
00091 edm::ESHandle<TrackerGeometry> tkGeom;
00092 iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
00093
00094 vector<GeomDet*> Det = tkGeom->dets();
00095 for(unsigned int i=0;i<Det.size();i++){
00096 DetId Detid = Det[i]->geographicalId();
00097
00098 StripGeomDetUnit* StripDetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
00099 PixelGeomDetUnit* PixelDetUnit = dynamic_cast<PixelGeomDetUnit*> (Det[i]);
00100
00101 stModInfo* MOD = new stModInfo;
00102 double Thick=-1, Dist=-1, Norma=-1;
00103 if(StripDetUnit){
00104 Dist = StripDetUnit->position().mag();
00105 Thick = StripDetUnit->surface().bounds().thickness();
00106 Norma = MeVperADCStrip/Thick;
00107 MOD->Normal = StripDetUnit->surface().normalVector();
00108 }else if(PixelDetUnit){
00109 Dist = PixelDetUnit->position().mag();
00110 Thick = PixelDetUnit->surface().bounds().thickness();
00111 Norma = MeVperADCPixel/Thick;
00112 MOD->Normal = PixelDetUnit->surface().normalVector();
00113 }
00114
00115 MOD->DetId = Detid.rawId();
00116 MOD->Thickness = Thick;
00117 MOD->Distance = Dist;
00118 MOD->Normalization = Norma;
00119 MOD->Gain = 1;
00120 MODsColl[MOD->DetId] = MOD;
00121 }
00122
00123 MakeCalibrationMap();
00124 }
00125
00126
00127 void DeDxEstimatorProducerPixelTripplet::endJob(){
00128 MODsColl.clear();
00129 }
00130
00131
00132
00133
00134 void DeDxEstimatorProducerPixelTripplet::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00135 {
00136 auto_ptr<ValueMap<DeDxData> > trackDeDxEstimateAssociation(new ValueMap<DeDxData> );
00137 ValueMap<DeDxData>::Filler filler(*trackDeDxEstimateAssociation);
00138
00139 Handle<TrackCollection> trackCollHandle;
00140 iEvent.getByLabel(m_trajTrackAssociationTag, trackCollHandle);
00141 const TrackCollection trackColl = *trackCollHandle.product();
00142
00143 size_t n = trackColl.size();
00144 std::vector<DeDxData> dedxEstimate(n);
00145
00146
00147 for(unsigned int j=0;j<trackColl.size();j++){
00148 const reco::TrackRef track = reco::TrackRef( trackCollHandle.product(), j );
00149
00150 DeDxHitCollection dedxHits;
00151 vector<DeDxTools::RawHits> hits;
00152
00153
00154
00155 int NClusterSaturating = 0;
00156 for(unsigned int h=0;h<track->recHitsSize();h++){
00157
00158
00159
00160 TrackingRecHit* recHit= (track->recHit(h))->clone();
00161
00162 if(const SiPixelRecHit* pixelHit=dynamic_cast<const SiPixelRecHit*>(recHit)){
00163 if(!usePixel) continue;
00164
00165 unsigned int detid = pixelHit->geographicalId();
00166 stModInfo* MOD = MODsColl[detid];
00167
00168 double cosine = (track->px()*MOD->Normal.x()+track->py()*MOD->Normal.y()+track->pz()*MOD->Normal.z())/track->p();
00169 float pathLen = MOD->Thickness/std::abs(cosine);
00170 float charge = MOD->Normalization*pixelHit->cluster()->charge()*std::abs(cosine);
00171 dedxHits.push_back( DeDxHit( charge, MOD->Distance, pathLen, detid) );
00172
00173 }
00174 delete recHit;
00175 }
00177
00178
00179 sort(dedxHits.begin(),dedxHits.end(),less<DeDxHit>());
00180 std::pair<float,float> val_and_error = m_estimator->dedx(dedxHits);
00181
00182
00183
00184 val_and_error.second = NClusterSaturating;
00185
00186 dedxEstimate[j] = DeDxData(val_and_error.first, val_and_error.second, dedxHits.size() );
00187 }
00188 filler.insert(trackCollHandle, dedxEstimate.begin(), dedxEstimate.end());
00189
00190
00191 filler.fill();
00192
00193 iEvent.put(trackDeDxEstimateAssociation);
00194 }
00195
00196
00197
00198 void DeDxEstimatorProducerPixelTripplet::MakeCalibrationMap()
00199 {
00200 if(!useCalibration)return;
00201
00202 TChain* t1 = new TChain("SiStripCalib/APVGain");
00203 t1->Add(m_calibrationPath.c_str());
00204
00205 unsigned int tree_DetId;
00206 unsigned char tree_APVId;
00207 double tree_Gain;
00208
00209 t1->SetBranchAddress("DetId" ,&tree_DetId );
00210 t1->SetBranchAddress("APVId" ,&tree_APVId );
00211 t1->SetBranchAddress("Gain" ,&tree_Gain );
00212
00213
00214
00215 for (unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
00216 t1->GetEntry(ientry);
00217 stModInfo* MOD = MODsColl[tree_DetId];
00218 MOD->Gain = tree_Gain;
00219 }
00220
00221 delete t1;
00222
00223 }
00224
00225
00226
00227 DEFINE_FWK_MODULE(DeDxEstimatorProducerPixelTripplet);